Skip to content

fix-box-bounding-marginal-over #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pymupdf4llm/pymupdf4llm/helpers/multi_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,20 @@ def is_white(text):
"""Check for relevant text."""
return WHITE.issuperset(text)

def in_bbox(bb, bboxes):
"""Return 1-based number if a bbox contains bb, else return 0."""
def in_bbox(bb, bboxes, threshold=0.95):
for i, bbox in enumerate(bboxes, start=1):
if bb in bbox:
if almost_in_bbox(bb, bbox, threshold):
return i
return 0

def almost_in_bbox(bb, box, threshold):
intersect = bb & box
if intersect.is_empty:
return False

ratio = intersect.get_area() / bb.get_area()
return ratio >= threshold

def intersects_bboxes(bb, bboxes):
"""Return True if a bbox touches bb, else return False."""
for bbox in bboxes:
Expand Down