boostorg / boostorg/geometry

intersection produces invalid polygon (is_valid fails) with (nearly) duplicated point

Open
#852 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
517
Forks
232
PR merge metrics
No merged PRs in 30d

Description

```cpp
#include

#include

int main() {
using Point = boost::geometry::model::d2::point_xy;
using Polygon = boost::geometry::model::polygon;

Polygon l{{
{0.33333327000590729, 0.33333344706803125},
{0.50967067548140821, 0},
{0, 0},
{0, 0.93199284523078707},
{0.33333327000590729, 0.33333344706803125},
}};
Polygon r{{
{0, 0.8554426406197928},
{0, 1},
{1, 0},
{0.54614530500375813, 0},
{0, 0.8554426406197928},
}};
assert(boost::geometry::is_valid(l));
assert(boost::geometry::is_valid(r));
std::vector out;
boost::geometry::intersection(l, r, out);
for (const Polygon &p : out) {
std::cout << boost::geometry::wkt(p) << std::endl;
assert(boost::geometry::is_valid(p)); // fails!
}
}
```
Fails with:
```
POLYGON((0.333333 0.333333,0 0.855443,0 0.931993,0.333333 0.333333,0.333333 0.333333))
a.out: temp.cpp:29: int main(): Assertion `boost::geometry::is_valid(p)' failed.
[1] 2691824 abort (core dumped) ./a.out
```
This reproduces with 1.75 and the develop branch of this repo.
Note that the 2 points which are very close to (1/3, 1/3) as output by wkt are not equal - they are just very close.

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.