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

Combination of within and difference return wrong result #1236

Open
vissarion opened this issue Jan 31, 2024 · 0 comments
Open

Combination of within and difference return wrong result #1236

vissarion opened this issue Jan 31, 2024 · 0 comments

Comments

@vissarion
Copy link
Member

vissarion commented Jan 31, 2024

The following program returns false while it should return true.

#include <boost/geometry.hpp>

int main() {
    using NT = double;
    using Point = boost::geometry::model::d2::point_xy<NT>;
    using Polygon = boost::geometry::model::polygon<Point>;
    using MultiPolygon = boost::geometry::model::multi_polygon<Polygon>;
    
    Polygon star_elem_horizontal; //blue
    Polygon star_elem_vertical;   //yellow
    Polygon star_1;               //red
    Polygon star_2;               //green

    boost::geometry::read_wkt("POLYGON((25 0,0 15,30 15,22 10,25 0))", star_elem_horizontal);
    boost::geometry::read_wkt("POLYGON((5 0,15 25,25 0,15 5,5 0))", star_elem_vertical);
    boost::geometry::read_wkt("POLYGON((5 0,7 10,0 15,10 15,15 25,20 15,30 15,22 10,25 0,15 5,5 0))",
        star_1);
    boost::geometry::read_wkt("POLYGON((15 0,17 10,10 15,20 15,25 25,30 15,40 15,32 10,35 0,25 5,15 0))",
        star_2);

    MultiPolygon mp1;
    boost::geometry::difference(star_elem_horizontal, star_elem_vertical, mp1);

    MultiPolygon mp2;
    boost::geometry::difference(mp1, star_2, mp2);

    MultiPolygon mp3;
    boost::geometry::difference(star_1, star_2, mp3);

    std::cout << boost::geometry::within(mp2, mp3) << std::endl;
    
    return 0;
}

It seems like a numerical precision issue. If we use boost::multiprecision::number<boost::multiprecision::gmp_float<50> > as NT then we get the desired output i.e. true.

Screenshot from 2024-01-26 15-14-47

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