jhasse / poly2tri

2D constrained Delaunay triangulation library
BSD 3-Clause "New" or "Revised" License
429 stars 89 forks source link

Incorrect output for self-intersecting polygon #48

Open sergeyvin opened 1 year ago

sergeyvin commented 1 year ago

Brief intro. My original shape boundaries are polylines (arcs + line segments) . Then shapes are split to positive/negative arc segments + polygon. Arc segments are handled separately. Polygon is triangulated by poly2tri. The problem is sometimes polygon can be self-intersecting because of cutting arc segments. It happens pretty rare, self-intersection check has the same complexity as triangulation so it is faster to try to triangulate and fail rather than check polygon before. In most cases poly2tri generates exceptions for self-intersecting polygons.

But there are few cases when triangulation completes successfully but there are triangle even of original polygon. There is workaround to check for polygon bbox but would be great if poly2tri can generate exception in this case as well Recently reproduced it with very simple example - just one arc path and 11 points. 2987.63 2259.05 2987.63 2254.95 2997.62 2254.95 3006.56 2250.48 3019.17 2244.17 3025.48 2231.56 3029.95 2222.62 3029.95 2212.63 3034.05 2212.63 3029.15 2233.39 3008.39 2254.15

bad_triangulation