Repository: tesseract-ocr/tesseract
File: src/textord/colfind.cpp (C++)

Code before:
    block->rotate(reskew_);
    // Copy the right_to_left flag to the created block.
    block->set_right_to_left(input_is_rtl);
    // Save the skew angle in the block for baseline computations.
    block->set_skew(reskew_);
    block->pdblk.set_index(block_index++);
    FCOORD blob_rotation = ComputeBlockAndClassifyRotation(block);
    // Rotate all the blobs if needed and recompute the bounding boxes.
    // Compute the block median blob width and height as we go.
    STATS widths(0, block->pdblk.bounding_box().width());
    STATS heights(0, block->pdblk.bounding_box().height());
    RotateAndExplodeBlobList(blob_rotation, &to_block->blobs, &widths, &heights);
    TO_ROW_IT row_it(to_block->get_rows());
    for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
      TO_ROW *row = row_it.data();
      RotateAndExplodeBlobList(blob_rotation, row->blob_list(), &widths, &heights);
    }
    block->set_median_size(static_cast<int>(widths.median() + 0.5),
                           static_cast<int>(heights.median() + 0.5));
    if (textord_debug_tabfind >= 2)
      tprintf("Block median size = (%d, %d)\n", block->median_size().x(), block->median_size().y());
  }
}

// Computes the rotations for the block (to make textlines horizontal) and
// for the blobs (for classification) and sets the appropriate members
// of the given block.
// Returns the rotation that needs to be applied to the blobs to make
// them sit in the rotated block.
FCOORD ColumnFinder::ComputeBlockAndClassifyRotation(BLOCK *block) {
  // The text_rotation_ tells us the gross page text rotation that needs
  // to be applied for classification
  // TODO(rays) find block-level classify rotation by orientation detection.
  // In the mean time, assume that "up" for text printed in the minority
  // direction (PT_VERTICAL_TEXT) is perpendicular to the line of reading.
  // Accomplish this by zero-ing out the text rotation.  This covers the
  // common cases of image credits in documents written in Latin scripts
  // and page headings for predominantly vertically written CJK books.
  FCOORD classify_rotation(text_rotation_);
  FCOORD block_rotation(1.0f, 0.0f);
  if (block->pdblk.poly_block()->isA() == PT_VERTICAL_TEXT) {
    // Vertical text needs to be 90 degrees rotated relative to the rest.
    // If the rest has a 90 degree rotation already, use the inverse, making
    // the vertical text the original way up. Otherwise use 90 degrees
    // clockwise.
    if (rerotate_.x() == 0.0f)
      block_rotation = rerotate_;
    else
      block_rotation = FCOORD(0.0f, -1.0f);
    block->rotate(block_rotation);
    classify_rotation = FCOORD(1.0f, 0.0f);

Review comment (suggestion):
this and prev line and whole PR - use more `auto`s.

Code after:
    }
    block->rotate(reskew_);
    // Copy the right_to_left flag to the created block.
    block->set_right_to_left(input_is_rtl);
    // Save the skew angle in the block for baseline computations.
    block->set_skew(reskew_);
    block->pdblk.set_index(block_index++);
    FCOORD blob_rotation = ComputeBlockAndClassifyRotation(block);
    // Rotate all the blobs if needed and recompute the bounding boxes.
    // Compute the block median blob width and height as we go.
    STATS widths(0, block->pdblk.bounding_box().width());
    STATS heights(0, block->pdblk.bounding_box().height());
    RotateAndExplodeBlobList(blob_rotation, &to_block->blobs, &widths, &heights);
    TO_ROW_IT row_it(to_block->get_rows());
    for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
      TO_ROW *row = row_it.data();
      RotateAndExplodeBlobList(blob_rotation, row->blob_list(), &widths, &heights);
    }
    block->set_median_size(static_cast<int>(widths.median() + 0.5),
                           static_cast<int>(heights.median() + 0.5));
    if (textord_debug_tabfind >= 2)
      tprintf("Block median size = (%d, %d)\n", block->median_size().x(), block->median_size().y());
  }
 
  std::vector<TessTable>& tables = uniqueInstance<std::vector<TessTable>>();
  for(TessTable& mt: tables)
    mt.box.rotate_large(reskew_);
}

// Computes the rotations for the block (to make textlines horizontal) and
// for the blobs (for classification) and sets the appropriate members
// of the given block.
// Returns the rotation that needs to be applied to the blobs to make
// them sit in the rotated block.
FCOORD ColumnFinder::ComputeBlockAndClassifyRotation(BLOCK *block) {
  // The text_rotation_ tells us the gross page text rotation that needs
  // to be applied for classification
  // TODO(rays) find block-level classify rotation by orientation detection.
  // In the mean time, assume that "up" for text printed in the minority
  // direction (PT_VERTICAL_TEXT) is perpendicular to the line of reading.
  // Accomplish this by zero-ing out the text rotation.  This covers the
  // common cases of image credits in documents written in Latin scripts
  // and page headings for predominantly vertically written CJK books.
  FCOORD classify_rotation(text_rotation_);
  FCOORD block_rotation(1.0f, 0.0f);
  if (block->pdblk.poly_block()->isA() == PT_VERTICAL_TEXT) {
    // Vertical text needs to be 90 degrees rotated relative to the rest.
    // If the rest has a 90 degree rotation already, use the inverse, making
    // the vertical text the original way up. Otherwise use 90 degrees
    // clockwise.
    if (rerotate_.x() == 0.0f)