Invalid polygon triangulation
I am trying to create a progress bar in a custom polygon shape, as seen below. The polygon in blue fills up to indicate the durability of a shield.
However, at certain point configurations, I am getting the following error:
Invalid polygon triangulation - no convex edges found. Your polygon is likely self-intersecting.
Failed point set:
[1]: Reflex
[3]: Reflex
[4]: Reflex
[6]: Reflex
[7]: Reflex
[9]: Reflex
[10]: Reflex
This comes about when the points are set as follows - the y-position between the first set of points (0.04505) is very close to the second set of points (0.045):
If I modulate the y-position of the first set of points, then values about y = 0.0451316 render fine without creating the invalid polygon triangulation error. I can create a hack in my code to clamp y-values to this threshold, but it seems like a bug in the triangulation code?
this is a side effect of floating point precision and making polygons that are very close to degenerate, which is what you have in your case. Well, there are two issues - first, you have two identical points after each other, this will always lead to triangulation errors, but even if you remove the duplicate point (point #3), it still fails to triangulate. Fixing this issue on my end is difficult, because it will almost certainly make the algorithm much slower for more valid cases too, not just the near-degenerate cases like this one.
I would recommend not altering the vertices for this progress bar, but instead you can always show the full polygon, using the linear fill gradient to indicate progress. This is also much faster from a performance point of view