Skip to content

Fix ImageDraw translation invariance for negative coordinates - #10229

Open
Eryx-Z wants to merge 2 commits into
python-pillow:mainfrom
Eryx-Z:fix/imagedraw-floor-negative-coords
Open

Eryx-Z wants to merge 2 commits into
python-pillow:mainfrom
Eryx-Z:fix/imagedraw-floor-negative-coords

Conversation

@Eryx-Z

@Eryx-Z Eryx-Z commented Oct 16, 2026

Copy link
Copy Markdown

Summary

ImageDraw converted float coordinates with a C cast (truncate toward zero) and used sign-symmetric ROUND_UP/ROUND_DOWN. Geometry that extends past the left or top edge of an image therefore rendered differently than the same shapes drawn after a positive pixel shift and crop.

This change uses floor for coordinate conversion in draw_lines / draw_polygon, and defines ROUND_UP/ROUND_DOWN as floor(f+0.5) / ceil(f-0.5) so edge rounding is translation-invariant across the origin.

Fixes #10228

Test plan

  • Added test_draw_translation_invariant_negative_coords covering the four shapes from the issue
  • Local pytest for that test passes

Eryx-Z and others added 2 commits October 17, 2026 06:41
Use floor when converting float coordinates to ints in draw_lines and
draw_polygon, and make ROUND_UP/ROUND_DOWN translation-invariant across
the origin. Geometry that extends past the left or top edge of an image
now matches a shifted-and-cropped render of the same shapes.

Fixes python-pillow#10228

This branch has not been deployed

No deployments
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.

ImageDraw is not translation-invariant for negative coordinates (truncation toward zero instead of floor)

1 participant