boostorg / geometry

Boost.Geometry - Generic Geometry Library | Requires C++14 since Boost 1.75
http://boost.org/libs/geometry
Boost Software License 1.0
457 stars 216 forks source link

Intersection gives incorrect result for polygon and line #1253

Open jdmarsh opened 8 months ago

jdmarsh commented 8 months ago

I have a polygon and line which intersects at the very corner, the intersection result is much larger than it should be. The godbolt repro is here: https://godbolt.org/z/TEEaqvcT1

Polygon(red) and line(green) image

Intersection result(blue) goes way outside of the red triangle, down to the bottom left image

I don't really care whether the actual result is super accurate or not, I don't need a high level of precision, I just need the result to be somewhat sensible and not creating huge lines outside the boundaries of the polygons I'm using to intersect.

vissarion commented 7 months ago

I can reproduce the issue. Thanks.

The algorithm incorrectly generates the intersection segments using the computed intersection points and the original endpoints of the input segment. Note that if you compute the intersection points (instead of intersection segments) you will get a good approximation. i.e. std::vector<Point2D> intersections