Skip to main content

sort_layout_boxes

Function sort_layout_boxes 

Source
pub fn sort_layout_boxes(
    elements: &[LayoutBox],
    image_width: f32,
) -> Vec<LayoutBox>
Expand description

Sort layout boxes in reading order with column detection.

This function sorts layout boxes from top to bottom, left to right, with special handling for two-column layouts. Boxes are first sorted by y-coordinate, then separated into left and right columns based on their x-coordinate.

The algorithm:

  1. Sort boxes by (y, x) coordinates
  2. Identify left column boxes (x1 < w/4 and x2 < 3w/5)
  3. Identify right column boxes (x1 > 2w/5)
  4. Other boxes are considered full-width
  5. Within each column, sort by y-coordinate

This follows standard layout sorting implementation.

§Arguments

  • elements - Slice of layout boxes to sort
  • image_width - Width of the image for column detection

§Returns

A vector of sorted layout boxes