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 getting stuck in infinite loop #5

Closed Dsearle2 closed 6 months ago

Dsearle2 commented 9 months ago

I am using Triangulation to convert some contours to meshes and I frequently seem to run into situations where the application freezes. I have attached an image of a contour that causes this freezing, if needed I'll try and extract the points used as well but it seems to occur in many cases. I've tried adding limit counters to the while loops to break out of them but the application still freezes so I'm not sure where the problem occurs.

Image of contour that causes freeze (contour in red): image

Dsearle2 commented 9 months ago

On further investigation it seems that this is related to issue the previous issue mentioned by EricBeetsOfficial-Opuscope. The infinite loop seems to occur in PlainShape.Split.

Dsearle2 commented 9 months ago

Here are a set of points that cause a freeze:

private Vector2[] _points = new Vector2[] { new Vector2(-0.42f, -0.38f) new Vector2(-0.44f, -0.36f) new Vector2(-0.44f, -0.32f) new Vector2(-0.46f, -0.3f) new Vector2(-0.46f, -0.28f) new Vector2(-0.48f, -0.26f) new Vector2(-0.48f, -0.24f) new Vector2(-0.5f, -0.22f) new Vector2(-0.5f, -0.2f) new Vector2(-0.48f, -0.2f) new Vector2(-0.46f, -0.22f) new Vector2(-0.42f, -0.22f) new Vector2(-0.4f, -0.24f) new Vector2(-0.36f, -0.24f) new Vector2(-0.34f, -0.26f) new Vector2(-0.34f, -0.28f) new Vector2(-0.38f, -0.32f) new Vector2(-0.38f, -0.34f) };

NailxSharipov commented 9 months ago

Hello.

Thanks for your test.

Do you know a debugging project for this library? Debug Project

I added your test case and it works fine.

You know that this algorithm under the hood uses integer math, so there may be an accuracy problem when running the same data (tests) on different processors. This is because the algorithm for rounding a floating point number to an integer may vary slightly across different cpu architectures. And also you should say what kind of IntGeom object do you have? Is this by default or not? This object has some properties that can affect the float to int convertation process.

It will be better if you give me an array of IntVector. In this case the triangulation will be deterministic in any cpu and I can easily detect a problem.

And Yes this library is not ideal because it in some degenerate cases and self intersections it's not working.

Right now I managed all this problems in other my triangulation library which will be more power full. But for now it's only available for swift.