Skip to content

Keep rectangle-clipping intersections exactly on the boundary - #1114

Open
Vryuz wants to merge 1 commit into
AngusJohnson:mainfrom
Vryuz:codex/rectclip-boundary-intersections
Open

Vryuz wants to merge 1 commit into
AngusJohnson:mainfrom
Vryuz:codex/rectclip-boundary-intersections

Conversation

@Vryuz

@Vryuz Vryuz commented Oct 7, 2026

Copy link
Copy Markdown

The case in #1095 produces an intersection one integer unit inside the rectangle's right edge, leaving an incorrect sliver in the clipped polygon. Floating-point rounding in the general line-intersection helper can lose the exact boundary coordinate; the same segment also affects RectClipLines.

After a successful intersection with a rectangle side, keep its constrained coordinate equal to that side. The other coordinate keeps the existing rounding behavior. This correction stays local to rectangle clipping and leaves the general GetLineIntersectPt function unchanged.

Fixes #1095.

Validation:

  • Both new polygon/line regressions fail against the original implementation and pass with the fix.
  • 102/102 tests pass, including regular and USINGZ configurations.
  • 14/14 rectangle-clipping tests pass with CLIPPER2_HI_PRECISION enabled.
  • The issue reproducer passes AddressSanitizer and UndefinedBehaviorSanitizer.

Regression cases cover reversed winding, reflections/transposition across all four sides, translated coordinates, exact corner crossings, parallel/collinear segments and empty rectangles. Boundary coordinates and polygon orientation are checked exactly; a one-unit tolerance is allowed only for the unconstrained coordinate.

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.

RectClip produces incorrect result

1 participant