boostorg / boostorg/geometry

Wrong result in difference of linestrings

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

Description

The program

```cpp
#include

int main() {

using Point = boost::geometry::model::d2::point_xy;
using Polygon = boost::geometry::model::polygon;
using Linestring = boost::geometry::model::linestring;
using MultiPolygon = boost::geometry::model::multi_polygon;
using MultiLinestring = boost::geometry::model::multi_linestring;

Linestring l1;
boost::geometry::read_wkt("LINESTRING(5 -8,-7 -6,-3 6,-3 1,-5 4,-1 0,8 5,5 1,-2 3, 1 10,8 5,6 2,7 4)", l1);

MultiLinestring ml1, ml2;
boost::geometry::read_wkt("MULTILINESTRING((1.9375 1.875,1.7441860465116283 1.9302325581395348,-0.7692307692307692 2.6483516483516487,-2 3,-1.0071942446043165 5.316546762589928))", ml1);

boost::geometry::difference(l1, ml1, ml2);

std::cout << boost::geometry::wkt(ml2) << std::endl;

std::cout << boost::geometry::is_valid(l1) << std::endl;
std::cout << boost::geometry::is_valid(ml1) << std::endl;
std::cout << boost::geometry::is_valid(ml2) << std::endl;

std::cout << boost::geometry::length(l1) << std::endl;
std::cout << boost::geometry::length(ml1) << std::endl;
std::cout << boost::geometry::length(ml2) << std::endl;

}
```

returns
```
MULTILINESTRING((5 -8,-7 -6,-3 6,-3 1,-5 4,-1 0,8 5,5 1,1.9375 1.875))
1
1
1
83.7125
6.61539
57.5577
```
in boost 1.84, which is wrong.

In boost 1.77 it throws an Inconsistent Turns exception.

![Screenshot from 2024-01-26 14-50-17](https://github.com/boostorg/geometry/assets/3660366/a3975f2e-12f2-4c5b-b8eb-f00861c0af2e)
in figure `ml1` is red, `ml2` is green and the union of red-green-purple is `l1`

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.