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

sym_difference with rectilinear integer coordinate polygons produces wrong result. #1222

Open
tinko92 opened this issue Dec 8, 2023 · 0 comments

Comments

@tinko92
Copy link
Contributor

tinko92 commented Dec 8, 2023

For the sym_difference of
MULTIPOLYGON(((2 4,2 2,0 2,0 4,2 4)),((6 4,4 4,2 4,2 6,0 6,0 10,6 10,6 4)))
and
MULTIPOLYGON(((4 4,4 2,2 2,2 4,4 4)),((4 8,4 6,2 6,2 8,4 8))),
I get:
MULTIPOLYGON(((4 4,4 2,2 2,0 2,0 4,4 4)))

I expect:
MULTIPOLYGON(((6 4,4 4,4 2,2 2,0 2,0 4,2 4,2 6,0 6,0 10,6 10,6 4),(2 6,4 6,4 8,2 8,2 6)))

It occurs with integer coordinates and rectilinear shapes, so it does not look like it should be a numerical issue.

Here is minimal code to reproduce the issue:

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>

namespace bg = boost::geometry;

using point = bg::model::point<int, 2, bg::cs::cartesian>;
using polygon = bg::model::polygon<point>;
using multipoly = bg::model::multi_polygon<polygon>;


int main() {
    auto p1 = bg::from_wkt<multipoly>("MULTIPOLYGON(((2 4,2 2,0 2,0 4,2 4)),((6 4,4 4,2 4,2 6,0 6,0 10,6 10,6 4)))");
    auto p2 = bg::from_wkt<multipoly>("MULTIPOLYGON(((4 4,4 2,2 2,2 4,4 4)),((4 8,4 6,2 6,2 8,4 8)))");
    multipoly p3;
    bg::sym_difference(p1, p2, p3);
    std::cout << bg::wkt(p3) << "\n";
    return 0;
}

In case, it is of any use, here is the code that was used to find a minimal example: https://gist.github.com/tinko92/ca944c0665dcdc15a6dc7bac147b088f

Here is a picture of the two input sets, drawn with 30% opacity in red and blue.
screenshot2

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

1 participant