AngusJohnson / Clipper2

Polygon Clipping and Offsetting - C++, C# and Delphi
Boost Software License 1.0
1.45k stars 266 forks source link

`RectClip` not always preserving orientation #864

Closed reunanen closed 3 months ago

reunanen commented 3 months ago

The documentation states:

RectClip preserves path orientation

Either I've misunderstood something, or here's a counter-example:

TEST(Clipper2Tests, TestRectClipOrientation)
{
    const Rect64 rect(1222, 1323, 3247, 3348);
    const Path64 subject = MakePath({ 375,1680, 1915,4716, 5943,586, 3987,152 });
    RectClip64 clip(rect);
    const auto solution = clip.Execute({ subject });
    ASSERT_EQ(solution.size(), 1);
    EXPECT_EQ(IsPositive(subject), IsPositive(solution.front()));
}

I'm not saying it's not a corner case (literally!):

image

However, this is a simplified version of a much more complex case that I accidentally stumbled upon.

AngusJohnson commented 3 months ago

Thanks Juha. I can confirm that this is an issue. Howver I'm currently occupied with other things so I doubt I'll get a chance to look at this for a few days.

reunanen commented 3 months ago

Not at all urgent from my side – I have a workaround in place already.

reunanen commented 3 months ago

Thank you Angus for fixing this! 🥳🥳🥳

Can confirm that the fix works on my machine as well! 😅