src/textord/colpartitiongrid.cpp
static bool OKMergeCandidate(const ColPartition *part,
                             const ColPartition *candidate, bool debug) {
  const TBOX &part_box = part->bounding_box();
  if (candidate == part) {
    return false; // Ignore itself.
  }
  if (!part->TypesMatch(*candidate) || candidate->IsUnMergeableType()) {
    return false; // Don't mix inappropriate types.
  }

  const TBOX &c_box = candidate->bounding_box();
  if (debug) {
    tprintf("Examining merge candidate:");
    c_box.print();
  }
  // Candidates must be within a reasonable distance.
  if (candidate->IsVerticalType() || part->IsVerticalType()) {
    int h_dist = -part->HCoreOverlap(*candidate);
    if (h_dist >= std::max(part_box.width(), c_box.width()) / 2) {
      if (debug) {
        tprintf("Too far away: h_dist = %d\n", h_dist);
      }
      return false;
    }
  } else {
    // Coarse filter by vertical distance between partitions.
    int v_dist = -part->VCoreOverlap(*candidate);
    if (v_dist >= std::max(part_box.height(), c_box.height()) / 2) {
      if (debug) {
        tprintf("Too far away: v_dist = %d\n", v_dist);
      }
      return false;
    }
    // Candidates must either overlap in median y,
    // or part or candidate must be an acceptable diacritic.
    if (!part->VSignificantCoreOverlap(*candidate) &&
        !part->OKDiacriticMerge(*candidate, debug) &&
        !candidate->OKDiacriticMerge(*part, debug)) {
      if (debug) {
        tprintf("Candidate fails overlap and diacritic tests!\n");
      }
      return false;
    }
  }
  return true;
}
// Returns true if the given part and merge candidate might believably
// be part of a single text line according to the default rules.
// In general we only want to merge partitions that look like they
// are on the same text line, ie their median limits overlap, but we have
// to make exceptions for diacritics and stray punctuation.
Returns true if the given part and merge candidate might believably
be part of a single text line according to the default rules.
In general we only want to merge partitions that look like they
are on the same text line, ie their median limits overlap, but we have
to make exceptions for diacritics and stray punctuation.
Returns true if the given part and merge candidate might believably be part of a single text line according to the default rules . In general we only want to merge partitions that look like they are on the same text line ie their median limits overlap but we have to make exceptions for diacritics and stray punctuation .
static bool OKMergeCandidate(const ColPartition *part,
                             const ColPartition *candidate, bool debug) {
  const TBOX &part_box = part->bounding_box();
  if (candidate == part) {
    return false; 
  }
  if (!part->TypesMatch(*candidate) || candidate->IsUnMergeableType()) {
    return false; 
  }
  const TBOX &c_box = candidate->bounding_box();
  if (debug) {
    tprintf("Examining merge candidate:");
    c_box.print();
  }
  if (candidate->IsVerticalType() || part->IsVerticalType()) {
    int h_dist = -part->HCoreOverlap(*candidate);
    if (h_dist >= std::max(part_box.width(), c_box.width()) / 2) {
      if (debug) {
        tprintf("Too far away: h_dist = %d\n", h_dist);
      }
      return false;
    }
  } else {
    int v_dist = -part->VCoreOverlap(*candidate);
    if (v_dist >= std::max(part_box.height(), c_box.height()) / 2) {
      if (debug) {
        tprintf("Too far away: v_dist = %d\n", v_dist);
      }
      return false;
    }
    if (!part->VSignificantCoreOverlap(*candidate) &&
        !part->OKDiacriticMerge(*candidate, debug) &&
        !candidate->OKDiacriticMerge(*part, debug)) {
      if (debug) {
        tprintf("Candidate fails overlap and diacritic tests!\n");
      }
      return false;
    }
  }
  return true;
}
static bool OKMergeCandidate ( const ColPartition * part , const ColPartition * candidate , bool debug ) { const TBOX & part_box = part -> bounding_box ( ) ; if ( candidate == part ) { return false ; } if ( ! part -> TypesMatch ( * candidate ) || candidate -> IsUnMergeableType ( ) ) { return false ; } const TBOX & c_box = candidate -> bounding_box ( ) ; if ( debug ) { tprintf ( " " ) ; c_box . print ( ) ; } if ( candidate -> IsVerticalType ( ) || part -> IsVerticalType ( ) ) { int h_dist = - part -> HCoreOverlap ( * candidate ) ; if ( h_dist >= std :: max ( part_box . width ( ) , c_box . width ( ) ) / 2 ) { if ( debug ) { tprintf ( " \n " , h_dist ) ; } return false ; } } else { int v_dist = - part -> VCoreOverlap ( * candidate ) ; if ( v_dist >= std :: max ( part_box . height ( ) , c_box . height ( ) ) / 2 ) { if ( debug ) { tprintf ( " \n " , v_dist ) ; } return false ; } if ( ! part -> VSignificantCoreOverlap ( * candidate ) && ! part -> OKDiacriticMerge ( * candidate , debug ) && ! candidate -> OKDiacriticMerge ( * part , debug ) ) { if ( debug ) { tprintf ( " \n " ) ; } return false ; } } return true ; }
Returns true if the given part and merge candidate might believably
be part of a single text line according to the default rules.
Returns true if the given part and merge candidate might believably be part of a single text line according to the default rules .
// Ignore itself. // Don't mix inappropriate types. // Candidates must be within a reasonable distance. // Coarse filter by vertical distance between partitions. // Candidates must either overlap in median y, // or part or candidate must be an acceptable diacritic.