private static bool Legalize(DTSweepContext tcx, DelaunayTriangle t) { bool result; for (int i = 0; i < 3; i++) { bool flag = t.EdgeIsDelaunay[i]; if (!flag) { DelaunayTriangle delaunayTriangle = t.Neighbors[i]; bool flag2 = delaunayTriangle != null; if (flag2) { TriangulationPoint triangulationPoint = t.Points[i]; TriangulationPoint triangulationPoint2 = delaunayTriangle.OppositePoint(t, triangulationPoint); int index = delaunayTriangle.IndexOf(triangulationPoint2); bool flag3 = delaunayTriangle.EdgeIsConstrained[index] || delaunayTriangle.EdgeIsDelaunay[index]; if (flag3) { t.EdgeIsConstrained[i] = delaunayTriangle.EdgeIsConstrained[index]; } else { bool flag4 = TriangulationUtil.SmartIncircle(triangulationPoint, t.PointCCW(triangulationPoint), t.PointCW(triangulationPoint), triangulationPoint2); bool flag5 = flag4; if (flag5) { t.EdgeIsDelaunay[i] = true; delaunayTriangle.EdgeIsDelaunay[index] = true; DTSweep.RotateTrianglePair(t, triangulationPoint, delaunayTriangle, triangulationPoint2); bool flag6 = !DTSweep.Legalize(tcx, t); bool flag7 = flag6; if (flag7) { tcx.MapTriangleToNodes(t); } flag6 = !DTSweep.Legalize(tcx, delaunayTriangle); bool flag8 = flag6; if (flag8) { tcx.MapTriangleToNodes(delaunayTriangle); } t.EdgeIsDelaunay[i] = false; delaunayTriangle.EdgeIsDelaunay[index] = false; result = true; return(result); } } } } } result = false; return(result); }
/// <summary> /// Returns true if triangle was legalized /// </summary> private static bool Legalize(DTSweepContext tcx, DelaunayTriangle t) { // To legalize a triangle we start by finding if any of the three edges // violate the Delaunay condition for (int i = 0; i < 3; i++) { // TODO: fix so that cEdge is always valid when creating new triangles then we can check it here // instead of below with ot if (t.EdgeIsDelaunay[i]) { continue; } DelaunayTriangle ot = t.Neighbors[i]; if (ot != null) { TriangulationPoint p = t.Points[i]; TriangulationPoint op = ot.OppositePoint(t, p); int oi = ot.IndexOf(op); // If this is a Constrained Edge or a Delaunay Edge(only during recursive legalization) // then we should not try to legalize if (ot.EdgeIsConstrained[oi] || ot.EdgeIsDelaunay[oi]) { t.EdgeIsConstrained[i] = ot.EdgeIsConstrained[oi]; // XXX: have no good way of setting this property when creating new triangles so lets set it here continue; } bool inside = TriangulationUtil.SmartIncircle(p, t.PointCCW(p), t.PointCW(p), op); if (inside) { // Lets mark this shared edge as Delaunay t.EdgeIsDelaunay[i] = true; ot.EdgeIsDelaunay[oi] = true; // Lets rotate shared edge one vertex CW to legalize it RotateTrianglePair(t, p, ot, op); // We now got one valid Delaunay Edge shared by two triangles // This gives us 4 new edges to check for Delaunay // Make sure that triangle to node mapping is done only one time for a specific triangle bool notLegalized = !Legalize(tcx, t); if (notLegalized) { tcx.MapTriangleToNodes(t); } notLegalized = !Legalize(tcx, ot); if (notLegalized) { tcx.MapTriangleToNodes(ot); } // Reset the Delaunay edges, since they only are valid Delaunay edges // until we add a new triangle or point. // XXX: need to think about this. Can these edges be tried after we // return to previous recursive level? t.EdgeIsDelaunay[i] = false; ot.EdgeIsDelaunay[oi] = false; // If triangle have been legalized no need to check the other edges since // the recursive legalization will handles those so we can end here. return(true); } } } return(false); }