iShapeUnity / Triangulation

Complex polygon triangulation. A fast O(n*log(n)) algorithm based on "Triangulation of monotone polygons". The result can be represented as a Delaunay triangulation.
MIT License
22 stars 3 forks source link

Triangulation freezing #3

Closed EricBeetsOfficial-Opuscope closed 1 year ago

EricBeetsOfficial-Opuscope commented 1 year ago

Hi there,

First of all, thank you for your great job. I have a strange behaviour with a set of data (based on the TriangulationDebug sample). Using those points:

private Vector2[] _points0 = new Vector2[]
    {
        new Vector2(0.736572265625f, -0.095703125f),
        new Vector2(0.73583984375f, -0.0986328125f),
        new Vector2(0.740234375f, -0.1005859375f),
        new Vector2(0.739013671875f, -0.10400390625f),
        new Vector2(0.740234375f, -0.102783203125f),
        new Vector2(0.7412109375f, -0.105224609375f),
        new Vector2(0.732177734375f, -0.1015625f),
        new Vector2(0.736572265625f, -0.1044921875f),
        new Vector2(0.73388671875f, -0.10302734375f),
        new Vector2(0.734619140625f, -0.10595703125f),
        new Vector2(0.730224609375f, -0.105712890625f),
        new Vector2(0.730224609375f, -0.109130859375f),
        new Vector2(0.72509765625f, -0.109619140625f),
        new Vector2(0.725830078125f, -0.10791015625f),
        new Vector2(0.722412109375f, -0.108154296875f),
        new Vector2(0.723876953125f, -0.10546875f),
        new Vector2(0.720947265625f, -0.105712890625f),
        new Vector2(0.72314453125f, -0.104248046875f),
        new Vector2(0.722412109375f, -0.10205078125f),
        new Vector2(0.71533203125f, -0.099853515625f),
        new Vector2(0.714111328125f, -0.10302734375f),
        new Vector2(0.7119140625f, -0.10009765625f),
        new Vector2(0.714599609375f, -0.1005859375f),
        new Vector2(0.715087890625f, -0.097412109375f),
        new Vector2(0.7197265625f, -0.0966796875f),
        new Vector2(0.724853515625f, -0.100341796875f),
        new Vector2(0.734130859375f, -0.099853515625f),
    };

the triangulation freezes but, with those points:

    private Vector2[] _points = new Vector2[]
    {
        new Vector2(0.7365723f, -0.09570313f),
        new Vector2(0.7358398f, -0.09863281f),
        new Vector2(0.7402344f, -0.1005859f),
        new Vector2(0.7390137f, -0.1040039f),
        new Vector2(0.7402344f, -0.1027832f),
        new Vector2(0.7412109f, -0.1052246f),
        new Vector2(0.7365723f, -0.1044922f),
        new Vector2(0.7321777f, -0.1015625f),
        new Vector2(0.7338867f, -0.1030273f),
        new Vector2(0.7346191f, -0.105957f),
        new Vector2(0.7302246f, -0.1057129f),
        new Vector2(0.7302246f, -0.1091309f),
        new Vector2(0.7250977f, -0.1096191f),
        new Vector2(0.7258301f, -0.1079102f),
        new Vector2(0.7224121f, -0.1081543f),
        new Vector2(0.723877f, -0.1054688f),
        new Vector2(0.7209473f, -0.1057129f),
        new Vector2(0.7231445f, -0.104248f),
        new Vector2(0.7224121f, -0.1020508f),
        new Vector2(0.715332f, -0.09985352f),
        new Vector2(0.7141113f, -0.1030273f),
        new Vector2(0.7119141f, -0.1000977f),
        new Vector2(0.7145996f, -0.1005859f),
        new Vector2(0.7150879f, -0.09741211f),
        new Vector2(0.7197266f, -0.09667969f),
        new Vector2(0.7248535f, -0.1003418f),
        new Vector2(0.7341309f, -0.09985352f),
    };

the triangulation works. Its look like a float precision issue ?! What do you think ?

Regards, Eric

NailxSharipov commented 1 year ago

It's look like you found a real bug. It's not in a precision. Something wrong when it break into monotone polygons. I will try to fix this. https://youtu.be/ZFGDQYUiiL8 Thanks for the test.

NailxSharipov commented 1 year ago

That's it. The issue was in tetragon contain method. I supposed that it is only convex case is possible. Now it support both concave and convex. So version 0.0.5 is a new version with this patch. And again thanks for this test case.

EricBeetsOfficial-Opuscope commented 1 year ago

Thanks a lot for the fix, the 0.0.5 works fine !

Thank you again !