Clipper2 icon indicating copy to clipboard operation
Clipper2 copied to clipboard

Regression when removing type casting in IsCollinear()

Open here-abarany opened this issue 1 year ago • 3 comments

When updating to the latest revision of Clipper2, we encountered a regression due to #825 for removing the type casting in IsCollinear().

In this test case, we have four points that cross over in an hourglass shape. We call Execute(Union, EvenOdd) to "repair" this invalid polygon into a pair of triangles that touch at a point.

These values, which are intended for single-precision floats, work as intended:

Input (with AddSubject()):

-536870912, -536870912
536870912, -536870912
-536870912, 536870912
536870912, 536870912

Output (2 paths):

0, 0
-536870912, 536870912
536870912, 536870912

536870912, -536870912
-536870912, -536870912
0, 0

However, these values, which are intended for doubles, break with #825:

-1125899906842624, -1125899906842624
1125899906842624, -1125899906842624
-1125899906842624, 1125899906842624
1125899906842624, 1125899906842624

With the latest revision, the call to Execute() gives an empty result rather than two paths similar to the smaller integer values.

here-abarany avatar May 08 '24 21:05 here-abarany

Aaron, thank you for your very clear and concise bug report. I'll check it out and hopefully have a fix soon (<24hrs).

AngusJohnson avatar May 08 '24 21:05 AngusJohnson

Thanks. I should also clarify that I am using the C++ library.

here-abarany avatar May 08 '24 22:05 here-abarany

Can reproduce. Yeah, with these inputs (which are exactly ±0x4000000000000) and using integer math, a*b wraps to 0, as does c*d. So perhaps an error in this direction is more critical than an error in the other direction after all (see the comment here).

reunanen avatar May 09 '24 04:05 reunanen

This has been fixed in the latest repository revision.

AngusJohnson avatar May 12 '24 01:05 AngusJohnson