Skip to content

fix: restore IoU fallback in _get_effective_y_bounds - #614

Open
Jiajun0413 wants to merge 1 commit into
funstory-ai:mainfrom
Jiajun0413:fix/effective-y-bounds-ioU-fallback
Open

fix: restore IoU fallback in _get_effective_y_bounds#614
Jiajun0413 wants to merge 1 commit into
funstory-ai:mainfrom
Jiajun0413:fix/effective-y-bounds-ioU-fallback

Conversation

@Jiajun0413

@Jiajun0413 Jiajun0413 commented Sep 4, 2026

Copy link
Copy Markdown

Summary

Restores a dead-code fallback in ParagraphFinder._get_effective_y_bounds that was already documented in its docstring but silently short-circuited.

Problem

_get_effective_y_bounds (in babeldoc/format/pdf/document_il/midend/paragraph_finder.py) is documented to:

  • use the visual bbox when its IoU with the PDF bbox is >= 0.5, and
  • fall back to the PDF bbox otherwise.

But the implementation had an early return visual_box.y, visual_box.y2 before the fallback, so the fallback branch (pdf_box) was unreachable dead code and the visual bbox was always used.

Downstream symptom

On PDFs whose visual_bbox is systematically shorter than the PDF line box (in one Elsevier single-column paper the visual height is ~6pt vs a ~12pt PDF line height, with >52% of characters having visual_bboxbox IoU < 0.5), the vertical collision histogram in _split_paragraph_into_lines found no gap between adjacent lines, so an entire multi-line paragraph collapsed into a single 43.8pt pseudo-line.

That pseudo-line then made inline math crossing a physical line break (e.g. p > 0.05, δ < 0.04, temperature τ = 0.1, seed s = 123) get grouped into one PdfFormula block whose characters kept their original two-line relative coordinates. After translation the relocate() step re-placed those characters at their original relative offsets, producing scattered / mis-ordered inline formula fragments and dropped decimal points.

Fix

Remove the early return so the intended visual_bbox / pdf_box IoU fallback runs exactly as the docstring describes.

 visual_box = char.visual_bbox.box
-        return visual_box.y, visual_box.y2
 pdf_box = char.box
 if calculate_iou_for_boxes(visual_box, pdf_box) >= 0.5:
     return visual_box.y, visual_box.y2
 return pdf_box.y, pdf_box.y2

This is a restoration of the author's original intent (the fallback branch already existed) rather than new logic.

Verification

  • Confirmed on an affected paper (Elsevier CRFS, single-column DejaVuSerif body): _split_paragraph_into_lines output 1 pseudo-line with 43.8pt vertical span for a paragraph that has 5 physical lines. After the fix the ioU<0.5 characters fall back to the PDF box and the collision histogram recovers the inter-line gaps.
  • No change to normal single-line inline formulas or sub/superscripts (the >= 0.5 branch is unchanged).

Related

I can add a minimal regression test under tests/ if maintainers prefer, but the fix itself is a one-line deletion.


Summary by cubic

Restores the documented IoU fallback in _get_effective_y_bounds so the PDF bbox is used when it doesn't overlap the visual bbox well.

  • The early return forced the visual bbox always, so the fallback branch was unreachable.
  • On PDFs with short visual bboxes, adjacent lines merged into a single pseudo-line during collision detection.
  • That collapsed paragraph made inline math crossing a line break render as scattered fragments after translation.
  • Removing the early return restores the docstring behavior; the >= 0.5 branch is unchanged.

Written for commit 2ab5e2d. Summary will update on new commits.

Review in cubic

The function was meant to use the visual bbox only when its IoU with the
PDF bbox is >= 0.5, and fall back to the PDF bbox otherwise (as stated in
its docstring). An early 'return visual_box.y, visual_box.y2' short-circuited
the fallback, so the visual bbox was always used.

On PDFs where the visual bbox is systematically shorter than the PDF bbox
(e.g. ~6pt visual height vs 12pt PDF line height), the collision histogram
in _split_paragraph_into_lines found no gap between adjacent lines and the
whole paragraph collapsed into a single pseudo-line. This made inline math
spanning a line break get merged into one formula block, which then rendered
scattered after translation.

Restoring the intended fallback fixes the line segmentation.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant