private static void FixWindingOrder(ref SortedVertex edgeV1, ref SortedVertex edgeV2, SortedVertex v1) { var crossProduct = TriangulationHelper.CrossProduct(edgeV2.Vertex - edgeV1.Vertex, v1.Vertex - edgeV2.Vertex); if (crossProduct > 0) { TriangulationHelper.Swap(ref edgeV1, ref edgeV2); } }
public static bool Validate(int leftVertexIndex, int rightVertexIndex, int outerVertexIndex, int innerVertexIndex, IReadOnlyList<SortedVertex> vertices) { var leftVertex = vertices[leftVertexIndex].Vertex; var rightVertex = vertices[rightVertexIndex].Vertex; var outerVertex = vertices[outerVertexIndex].Vertex; var innerVertex = vertices[innerVertexIndex].Vertex; if (outerVertexIndex == innerVertexIndex) { return true; } if (TriangulationHelper.CrossProduct(leftVertex - outerVertex, innerVertex - outerVertex) < 0 || TriangulationHelper.CrossProduct(rightVertex - outerVertex, innerVertex - outerVertex) > 0) { return true; } var sa = (outerVertex.x - rightVertex.x) * (outerVertex.x - leftVertex.x) + (outerVertex.y - rightVertex.y) * (outerVertex.y - leftVertex.y); var sb = (innerVertex.x - rightVertex.x) * (innerVertex.x - leftVertex.x) + (innerVertex.y - rightVertex.y) * (innerVertex.y - leftVertex.y); if (sa > -Eps && sb > -Eps) { return true; } if (sa < 0 && sb < 0) { return false; } var sc = TriangulationHelper.CrossProduct(outerVertex - rightVertex, outerVertex - leftVertex); var sd = TriangulationHelper.CrossProduct(innerVertex - rightVertex, innerVertex - leftVertex); if (sc < 0) sc = -sc; if (sd < 0) sd = -sd; return sc * sb + sa * sd > -Eps; }