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

bg::union_(ring,ring) returns wrong result #1076

Closed
Mitsuhiko-Matsukawa opened this issue Oct 21, 2022 · 4 comments · Fixed by #1086
Closed

bg::union_(ring,ring) returns wrong result #1076

Mitsuhiko-Matsukawa opened this issue Oct 21, 2022 · 4 comments · Fixed by #1086
Assignees
Labels

Comments

@Mitsuhiko-Matsukawa
Copy link
Contributor

Mitsuhiko-Matsukawa commented Oct 21, 2022

boost1.80, Visual Studio 2017

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

#if 0
    //correct result
    bg::model::ring<point> ring0 = {
        { 981,98 },
        { 927,0 },
        { 970,98 },
        { 981,98 }
    };

    bg::model::ring<point> ring1 = {
        { 927,0 },
        { 981,98 },
        { 995,98 },
        { 927,0 }
    };
#else
    //wrong result
    bg::model::ring<point> ring0 = {
        { 981.792858339935151,98 },
        { 927.152135631899114,0 },
        { 970,98 },
        { 981.792858339935151,98 }
    };

    bg::model::ring<point> ring1 = {
        { 927.152135631899114,0 },
        { 981.792858339935151,98 },
        { 995,98 },
        { 927.152135631899114,0 }
    };
#endif

    bg::model::multi_polygon<bg::model::polygon<point>> result;
    bg::union_(ring0, ring1, result);

    auto area0 = bg::area(ring0);
    auto area1 = bg::area(ring1);
    auto area_result = bg::area(result);
    assert(std::max(area0, area1) < area_result );
}
@Mitsuhiko-Matsukawa
Copy link
Contributor Author

Mitsuhiko-Matsukawa commented Oct 21, 2022

If I input the above data, get_distance_measure is called at these parameters.

p1=(927.15213563189911, 0.0000000000000000);
p2=(981.79285833993515, 98.000000000000000);
p=(981.79285833993515, 98.000000000000000);

If p is equal to p1 or p2, the distance should be 0. However, it returns 1.4551915228366852e-11.
If I fix this function and return 0, the result will be correct.

c1b8dbb

Mitsuhiko-Matsukawa added a commit to Mitsuhiko-Matsukawa/geometry that referenced this issue Oct 21, 2022
@Mitsuhiko-Matsukawa
Copy link
Contributor Author

It might be better to fix handle_imperfect_touch .
We need a tolerance.

Mitsuhiko-Matsukawa added a commit to Mitsuhiko-Matsukawa/geometry that referenced this issue Oct 24, 2022
(cherry picked from commit c1b8dbb)
@barendgehrels barendgehrels self-assigned this Nov 9, 2022
@barendgehrels
Copy link
Collaborator

Thanks for the report. I can reproduce it and I am considering your solution.

@barendgehrels
Copy link
Collaborator

It is fixed in a similar way as your fix, but slightly different to avoid regressions elsewhere.
Thanks again for the report and the analysis.

barendgehrels added a commit to barendgehrels/geometry that referenced this issue Nov 9, 2022
barendgehrels added a commit to barendgehrels/geometry that referenced this issue Nov 16, 2022
barendgehrels added a commit to barendgehrels/geometry that referenced this issue Nov 16, 2022
vissarion pushed a commit that referenced this issue Dec 1, 2022
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