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

Multipolygon intersection incorrect for rectangles with rather specific collinear points #1044

Open
thmshnz opened this issue Jul 25, 2022 · 4 comments
Assignees

Comments

@thmshnz
Copy link

thmshnz commented Jul 25, 2022

The source files in the attached archive bug.zip demonstrate an intersection bug that is present in version 1.79.0. Given two intersecting rectangles each with collinear points represented as two multi_polygons, for specific choices of those points, boost::geometry::intersection produces an incorrect result.

nonbug.cpp produces the following output where the second part of the output refers to a case with the y-coordinates of the points on the second rectangle being perturbed ever so slightly. As expected, the output is the same in both cases.

Valid (mpoly1): 1
Valid (mpoly2): 1
Valid (mpoly3): 1
Area:           0.09
Bounding box:   ((-5.8, 5), (-5.5, 5.3))

Valid (mpoly1): 1
Valid (mpoly2): 1
Valid (mpoly3): 1
Area:           0.09
Bounding box:   ((-5.8, 5), (-5.5, 5.3))

However, bug.cpp produces the following output where the first part indicates the bug. After perturbing the y-coordinates of the points on the second rectangle, the problem vanishes.

Valid (mpoly1): 1
Valid (mpoly2): 1
Valid (mpoly3): 1
Area:           0.24
Bounding box:   ((-5.8, 5), (-5, 5.3))

Valid (mpoly1): 1
Valid (mpoly2): 1
Valid (mpoly3): 1
Area:           0.09
Bounding box:   ((-5.8, 5), (-5.5, 5.3))

Note that the difference between both files is as follows.

--- nonbug.cpp  2022-07-21 13:00:55.168046300 +0200
+++ bug.cpp     2022-07-25 11:00:54.132520800 +0200
@@ -165,8 +165,8 @@ double r2[][2] = {
     {-5.54, 5.3},
     {-5.53, 5.3},
     {-5.52, 5.3},
-    {-5.51, 5.3},
-    {-5.5, 5.3},
+    {-5.51, 5.299999999999998},
+    {-5.5, 5.299999999999998},
     {-5.49, 5.3},
     {-5.48, 5.3},
     {-5.47, 5.3},
@barendgehrels barendgehrels self-assigned this Jul 27, 2022
@barendgehrels
Copy link
Collaborator

Thanks for the report! I'll have a look next week.

@thmshnz
Copy link
Author

thmshnz commented Aug 11, 2022

Looking at boost versions 1.76 - 1.80, I noted that the bug is present in version 1.79 and the latest 1.80 release. It is not present in versions 1.76 - 1.78.

@barendgehrels
Copy link
Collaborator

Sorry, it's a few weeks later already.
It's a numerical issue. Using long double fixes this particular example.
Boost 1.79 is different from the versions before, because we stopped using rescaling (which caused several other issues).
I will look later if this issue can be fixed in a generic way, but that will not be soon.

@barendgehrels
Copy link
Collaborator

Not fixed on latest branch or on PR #1343

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