Skip to content
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

Unexpected RectClip output #597

Closed
EternalXY opened this issue Jul 21, 2023 · 5 comments
Closed

Unexpected RectClip output #597

EternalXY opened this issue Jul 21, 2023 · 5 comments

Comments

@EternalXY
Copy link

I see an unexpected spike when clipping a long and narrow rectangle:

        Clipper2Lib::Rect64 rect(54690, 0, 65628, 6000);
        Clipper2Lib::Paths64 poly{
        {
                {700000, 6000},
                {0, 6000},
                {0, 5925},
                {700000, 5925},
        }
        };
        Clipper2Lib::Paths64 solution = Clipper2Lib::RectClip(rect, poly);

This outputs the following points:

65628, 5925
65628, 6000
54689, 6000
54690, 0
54689, 5925

Input rectangle in red (clipped to fit the screen) and result in black:

image

The size of the spike seems related to the size of the clipping rectangle somehow, any idea what is going on here?

@EternalXY
Copy link
Author

EternalXY commented Jul 21, 2023

Small update: the spike is gone when rounding in GetIntersectPoint():

      ip.x = std::llround(static_cast<double>(ln1a.x) + t * dx1);
      ip.y = std::llround(static_cast<double>(ln1a.y) + t * dy1);

@EternalXY
Copy link
Author

EternalXY commented Aug 4, 2023

Another update: also fixed by sorting the input points of GetIntersectPoint/SegmentsIntersect since they seem to round differently if segments or segment points are swapped, and RectClip expects the intersect points to be identical.

@AngusJohnson
Copy link
Owner

Change:

if (crossing_prev != Location::Inside)
AddCorner(crossing_prev, loc);

to:

        if (crossing_prev != Location::Inside && crossing_prev != loc)
          AddCorner(crossing_prev, loc);

AngusJohnson added a commit that referenced this issue Aug 6, 2023
Fixed a minor bug in merging solution polygons (#606)
@AngusJohnson
Copy link
Owner

Hopefully fixed now.

@EternalXY
Copy link
Author

Thanks, works wonderfully now 👍 Also no longer seeing 1-point polygons in the output.

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

No branches or pull requests

2 participants