Edge case causing triangulation error due to null reference exception
Hello!
I've been using your code for my thesis project, and came across an edge case where triangulating the mesh for composite shape with holes fails. It happens when the very first hull point meets all the criteria to be the intersection for the hole's bridge point.
Code Error + Possible Fix
Here's the code that keeps failing (Triangulator.cs, line 161):
bool connectToThisDuplicateEdge = holeData.bridgePoint.y > potentialNewBridgeNode.Previous.Value.position.y;
When you are on the first run through the while (currentNode != null) loop, and potentialNewBridgeNode gets set to p0, there is no .Previous so it aborts with a null reference exception.
Based on my understanding of what's going on in the code, I changed it to this, and now everything seems to be working.
bool connectToThisDuplicateEdge = false;
if (potentialNewBridgeNode.Previous != null) {
connectToThisDuplicateEdge = holeData.bridgePoint.y > potentialNewBridgeNode.Previous.Value.position.y;
}
Steps to Reproduce
The image below outlines a simple example that replicates the error. I want to create a composite shape that is rectangular, with a rectangular hole cut out of it. I have the following points, shown as vertices on the left and plotted on the graph in the center. The blue points represent the first shape in my shapeList, and the orange/red represents the second shape. I call (new CompositeShape(shapeList)).getMesh(). The red point marks the bridge point that connects the hole to the rest of the hull. Finally, GenerateVertices() gets called with the Polygon object on the right.

Hopefully this helps you figure out exactly what's going on. My fix seems to work fine for my use case, but I'm not 100% that it doesn't break under other circumstances.
Anyway, thanks for providing this code, along with a video tutorial! It's been super helpful.