Skip to content

Union result goes around twice. #1109

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

Closed
Mitsuhiko-Matsukawa opened this issue Jan 24, 2023 · 3 comments · Fixed by #1113
Closed

Union result goes around twice. #1109

Mitsuhiko-Matsukawa opened this issue Jan 24, 2023 · 3 comments · Fixed by #1113
Assignees
Labels

Comments

@Mitsuhiko-Matsukawa
Copy link
Contributor

boost1.81.0
Visual Studio 2019. x64 debug

image

void Test()
{
    namespace bg = boost::geometry;
    using point = bg::model::point<double, 2, bg::cs::cartesian>;
    using ring = bg::model::ring<point>;
    using multi_polygon = bg::model::multi_polygon<bg::model::polygon<point>>;
    multi_polygon input0;
    ring input1;

    constexpr double ng_y = -115.4;
    //constexpr double ng_y = -115.5;

    input0.resize(2);
    // green
    input0[0].outer().assign({
        {-63,-88},
        {0,ng_y},
        {0,-124},
        {-63,-124},
        {-63,-88}
    });
    // blue
    input0[1].outer().assign({
        {0,-150},
        {0,-124},
        {13,-124},
        {13,-121},
        {0,ng_y},
        {0,-88},
        {40,-88},
        {40,-150},
        {0,-150}
    });
    // red
    input1.assign({
        {0,-88},
        {0,ng_y},
        {-10,-88},
        {0,-88}
    });

    assert(bg::is_valid(input0));
    assert(bg::is_valid(input1));
    multi_polygon output;
    bg::union_(input0, input1, output);

    for (size_t i = 0; i < output.size(); ++i) {
        std::cout << "====polygon " << i << std::endl;
        for (auto& point : output[i].outer()) {
            std::cout << point.get<0>() << "," << point.get<1>() << std::endl;
        }
    }

    auto area_in = bg::area(input0) + bg::area(input1);
    auto area_out = bg::area(output);
    assert(area_in >= area_out);
}

result

====polygon 0
0,-115.4
0,-124
-63,-124
-63,-88
-4.35207e-13,-115.4
0,-115.4
0,-124
-63,-124
-63,-88
0,-115.4
====polygon 1
0,-115.4
-10,-88
0,-88
40,-88
40,-150
0,-150
0,-124
13,-124
13,-121
-4.35207e-13,-115.4
0,-115.4
0,-88
40,-88
40,-150
0,-150
0,-124
13,-124
13,-121
0,-115.4

If ng_y is not -111.4 but -111.5, it works well.

@barendgehrels barendgehrels self-assigned this Jan 25, 2023
@barendgehrels
Copy link
Collaborator

Thanks for the report. I can reproduce it on Linux / clang

@barendgehrels
Copy link
Collaborator

Related to #1108

@barendgehrels
Copy link
Collaborator

Fixed by mentioned PR

barendgehrels added a commit to barendgehrels/geometry that referenced this issue Feb 22, 2023
barendgehrels added a commit to barendgehrels/geometry that referenced this issue Feb 22, 2023
Mitsuhiko-Matsukawa pushed a commit to Mitsuhiko-Matsukawa/geometry that referenced this issue Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants