boostorg / boostorg/geometry

boost::geometry::intersection wrong result

Open
#1,211 4 comments 0 reactions 1 assignee Claimed by @barendgehrels View on GitHub
Dominant language
C++
Stars
517
Forks
232
PR merge metrics
No merged PRs in 30d

Description

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

```C++
using Point = boost::geometry::model::d2::point_xy;
using BoostPolygonType = boost::geometry::model::polygon;
using BoostMultiPolygonType = boost::geometry::model::multi_polygon;
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](https://github.com/boostorg/geometry/assets/92168821/394ee974-fe9d-4182-b704-4aab158d96c4)
the result of the intersection
![image](https://github.com/boostorg/geometry/assets/92168821/fd690dba-f5f1-4668-9767-08adad0bbe2e)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.