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

Some inputs causing infinite recursion #3

Open
rproepp opened this issue Feb 13, 2021 · 1 comment
Open

Some inputs causing infinite recursion #3

rproepp opened this issue Feb 13, 2021 · 1 comment

Comments

@rproepp
Copy link

rproepp commented Feb 13, 2021

Hi, the following input causes an infinite recursion, resulting in a stack overflow:

#include "ConcavePolygon.h"

int main()
{
    std::vector<cxd::Vertex > vertices =
    {
        cxd::Vec2({0.500000000000, 0.500000000000}),
        cxd::Vec2({0.500000000000, -0.498161792755}),
        cxd::Vec2({-0.497167110443, -0.498161792755}),
        cxd::Vec2({-0.497167110443, 0.277573525906}),
        cxd::Vec2({-0.415014147758, 0.273897051811}),
        cxd::Vec2({-0.349858343601, 0.297794103622}),
        cxd::Vec2({-0.168555259705, 0.435661762953}),
        cxd::Vec2({-0.151558041573, 0.465073525906}),
        cxd::Vec2({-0.151558041573, 0.500000000000}),
        cxd::Vec2({-0.072237968445, 0.500000000000}),
        cxd::Vec2({-0.043909311295, 0.430147051811}),
        cxd::Vec2({-0.024079322815, 0.408088237047}),
        cxd::Vec2({0.038243621588, 0.376838237047}),
        cxd::Vec2({0.109065175056, 0.367647051811}),
        cxd::Vec2({0.160056650639, 0.369485288858}),
        cxd::Vec2({0.245042502880, 0.393382370472}),
        cxd::Vec2({0.301699697971, 0.441176474094}),
        cxd::Vec2({0.332861185074, 0.500000000000})
    };

    cxd::ConcavePolygon concavePoly(vertices);
    concavePoly.convexDecomp(0);

    std::vector<cxd::ConcavePolygon> subPolygonList;
    concavePoly.returnLowestLevelPolys(subPolygonList);

    std::cout << "Num Polys: " << subPolygonList.size() << std::endl;

    return 0;
}
@rproepp
Copy link
Author

rproepp commented Feb 21, 2021

I looked into this a bit more. The vertices mentioned above reduce to the following list before entering the infinite recursion:

    std::vector<cxd::Vertex> vertices =
    {
        cxd::Vec2({ 0.25093948401191, 0.3727616036061424 }),
        cxd::Vec2({ 0.109065175056, 0.367647051811 }),
        cxd::Vec2({ 0.06879750720276288, 0.3615178925897086 }),
        cxd::Vec2({ -0.024079322815, 0.408088237047 }),
        cxd::Vec2({ -0.043909311295, 0.430147051811 }),
        cxd::Vec2({ -0.07223796844499999, 0.5 }),
        cxd::Vec2({ -0.151558041573, 0.5 }),
        cxd::Vec2({ -0.151558041573, 0.465073525906 }),
        cxd::Vec2({ -0.168555259705, 0.435661762953 }),
        cxd::Vec2({ -0.349858343601, 0.297794103622 }),
        cxd::Vec2({ -0.415014147758, 0.273897051811 }),
        cxd::Vec2({ -0.497167110443, 0.277573525906 }),
        cxd::Vec2({ -0.497167110443, -0.498161792755 }),
        cxd::Vec2({ 0.5, -0.4981617927550001 })
    }

Some of the points are almost collinear, so I reduced the tolerance value in LineSegment::intersects() to 1e-5, that got rid of the problem for this case.

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