Skip to content

Update y0/y1 when clipping objects - #1393

Open
dylanpulver wants to merge 1 commit into
jsvine:developfrom
dylanpulver:fix-clip-obj-y-coords
Open

dylanpulver wants to merge 1 commit into
jsvine:developfrom
dylanpulver:fix-clip-obj-y-coords

Conversation

@dylanpulver

Copy link
Copy Markdown

utils.clip_obj updates top, bottom, height and doctop but not y0/y1, so an object that straddles a Page.crop(...) boundary keeps its pre-crop bottom-up coordinates.

On tests/pdfs/pdffill-demo.pdf (792pt tall), cropping through the middle of the first char:

before crop  top=117.18 bottom=135.18  y0=656.82 y1=674.82  height=18.0
after  crop  top=126.18 bottom=135.18  y0=656.82 y1=674.82  height=9.0

y1 - y0 is 18.0 while height is 9.0. The README documents y1 as the distance of the object's top from the bottom of the page, i.e. 792 - 126.18 = 665.82.

The two sibling helpers in the same module already handle this: resize_object does y1 -= diff for top and y0 -= diff for bottom, and move_object shifts both. This applies the same convention in clip_obj.

How I found it: reading utils/geometry.py for helpers that maintain the two coordinate systems inconsistently — not from a PDF in hand. clip_obj is the only one of the three that touches top/bottom without touching y0/y1. geometry.py reports 100% line coverage and test_resize_object asserts the y0/y1 behaviour explicitly, but there was no unit test for clip_obj.

Measured: python -m pytest tests/ → 174 passed on this branch, 173 before. Reverting only geometry.py and keeping the new test → 1 failed / 173 passed, differing on y0 and y1. A naive variant that shifts both y0 and y1 by the top delta also fails, on y0.

Not addressed: clip_obj still leaves a curve's pts list uncropped, and curve_to_edges output carries no y0/y1 at all. black, isort, flake8 and mypy --strict are clean; I did not run the notebook examples.

Disclosure: this patch was written with AI assistance (Claude).

`utils.clip_obj` adjusted `top`, `bottom`, `height` and `doctop` but left
`y0`/`y1` at their pre-crop values, so objects that straddle a crop
boundary came back with `y1 - y0 != height`. The sibling helpers
`move_object` and `resize_object` already keep the bottom-up coordinates
in sync; this applies the same convention to `clip_obj`.
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