private static void FillLeftAboveEdgeEvent(DTSweepContext tcx, DTSweepConstraint edge, AdvancingFrontNode node) { while (node.Prev.Point.X > edge.P.X) { // Check if next node is below the edge var o1 = TriangulationUtil.Orient2d(edge.Q, node.Prev.Point, edge.P); if (o1 == Orientation.CW) { FillLeftBelowEdgeEvent(tcx, edge, node); } else { node = node.Prev; } } }
private static void FillLeftBelowEdgeEvent(DTSweepContext tcx, DTSweepConstraint edge, AdvancingFrontNode node) { if (node.Point.X > edge.P.X) { if (TriangulationUtil.Orient2d(node.Point, node.Prev.Point, node.Prev.Prev.Point) == Orientation.CW) { // Concave FillLeftConcaveEdgeEvent(tcx, edge, node); } else { // Convex FillLeftConvexEdgeEvent(tcx, edge, node); // Retry this one FillLeftBelowEdgeEvent(tcx, edge, node); } } }
private static void FillEdgeEvent(DTSweepContext tcx, DTSweepConstraint edge, AdvancingFrontNode node) { if (tcx.EdgeEvent.Right) { FillRightAboveEdgeEvent(tcx, edge, node); } else { FillLeftAboveEdgeEvent(tcx, edge, node); } }
private static void FillLeftConvexEdgeEvent(DTSweepContext tcx, DTSweepConstraint edge, AdvancingFrontNode node) { // Next concave or convex? if (TriangulationUtil.Orient2d(node.Prev.Point, node.Prev.Prev.Point, node.Prev.Prev.Prev.Point) == Orientation.CW) { // Concave FillLeftConcaveEdgeEvent(tcx, edge, node.Prev); } else { // Convex // Next above or below edge? if (TriangulationUtil.Orient2d(edge.Q, node.Prev.Prev.Point, edge.P) == Orientation.CW) { // Below FillLeftConvexEdgeEvent(tcx, edge, node.Prev); } else { // Above } } }
/// <summary> /// We will traverse the entire advancing front and fill it to form a convex hull. /// </summary> private static void TurnAdvancingFrontConvex(DTSweepContext tcx, AdvancingFrontNode b, AdvancingFrontNode c) { var first = b; while (c != tcx.aFront.Tail) { if (TriangulationUtil.Orient2d(b.Point, c.Point, c.Next.Point) == Orientation.CCW) { // [b,c,d] Concave - fill around c Fill(tcx, c); c = c.Next; } else { // [b,c,d] Convex if (b != first && TriangulationUtil.Orient2d(b.Prev.Point, b.Point, c.Point) == Orientation.CCW) { // [a,b,c] Concave - fill around b Fill(tcx, b); b = b.Prev; } else { // [a,b,c] Convex - nothing to fill b = c; c = c.Next; } } } }