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

boost::geometry::intersection wrong result #1211

Open
mjagodicblackshark opened this issue Oct 25, 2023 · 4 comments
Open

boost::geometry::intersection wrong result #1211

mjagodicblackshark opened this issue Oct 25, 2023 · 4 comments
Assignees

Comments

@mjagodicblackshark
Copy link

On version 1.82 without special defines. I have found a test case that gives unexpectedly wrong results.

Here is the test case to prove the problem. The correct result is close to the float precision limit, but the actual result is almost the same as one of the input polygons and therefore very wrong. Empty or even degenerate results would be fine for our use case. Possibly related to #1201

using Point = boost::geometry::model::d2::point_xy<float>;
using BoostPolygonType = boost::geometry::model::polygon<Point, false, false>;
using BoostMultiPolygonType = boost::geometry::model::multi_polygon<BoostPolygonType>;
BoostPolygonType polygon1;
boost::geometry::read_wkt("POLYGON((0.875 0.4375, 0.875 0.375, 0.9375 0.375))", polygon1);
BoostPolygonType polygon2;
boost::geometry::read_wkt("POLYGON((1. 0., 1. 0.581662834, 0.824054539 0.))", polygon2);

BoostMultiPolygonType result;
boost::geometry::intersection(polygon1, polygon2, result);

EXPECT_EQ(result.size(), 1);

EXPECT_LT(boost::geometry::area(result), 0.01);

for (auto& intersection : result)
{
    EXPECT_EQ(intersection.outer().size(), 3);
}

polygon1-orange, polygon2-red
image
the result of the intersection
image

@jdmarsh
Copy link

jdmarsh commented Oct 25, 2023

I've had this issue crop up as well (1.82 and 1.83). It's not quite the same but I've added a repro of my problem here:
https://godbolt.org/z/W1s7YEczP
with the points plotted here:
https://www.desmos.com/calculator/zrytxj5d8u
The output line should be very small as it only intersects at a corner, but the output seems to be much much larger going outside of the bounds of the polygon.

@vissarion
Copy link
Member

I can reproduce the issue. Probably a numerical issue. With double instead of float the results are as expected.

@jdmarsh
Copy link

jdmarsh commented Dec 5, 2023

I've had this issue using float and double. I only managed to solve it by moving to cpp_bin_float_quad in boost multiprecision but that's crazy slow and I can't guarantee that the issue isn't still going to crop up there as well, I just haven't seen it yet.

@vissarion
Copy link
Member

@jdmarsh could you please open a new issue with your example and data?

@barendgehrels barendgehrels self-assigned this Nov 24, 2024
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

4 participants