void FindMoreRemovedFromFrontElements() { foreach (var triangle in removedTriangles) { foreach (var e in triangle.Edges) { if (e.CcwTriangle == null && e.CwTriangle == null) { var site = e.upperSite.Point.X < e.lowerSite.Point.X ? e.upperSite : e.lowerSite; var frontNode = CdtSweeper.FindNodeInFrontBySite(front, site); if (frontNode.Item.Edge == e) { elementsToBeRemovedFromFront.Add(frontNode.Item); } } } } }
void Init() { // if (CdtSweeper.D) // CdtSweeper.ShowFront(triangles, front, new[] {new LineSegment(a.Point, b.Point)},null); //new[] {new LineSegment(piercedEdge.upperSite.Point, piercedEdge.lowerSite.Point)}); var frontElemNodeRightOfA = CdtSweeper.FindNodeInFrontBySite(front, a); var frontElemNodeLeftOfA = front.Previous(frontElemNodeRightOfA); if (Point.PointToTheLeftOfLine(b.Point, frontElemNodeLeftOfA.Item.LeftSite.Point, frontElemNodeLeftOfA.Item.RightSite.Point)) { piercedToTheLeftFrontElemNode = frontElemNodeLeftOfA; } else if (Point.PointToTheRightOfLine(b.Point, frontElemNodeRightOfA.Item.RightSite.Point, frontElemNodeRightOfA.Item.LeftSite.Point)) { piercedToTheRightFrontElemNode = frontElemNodeRightOfA; } else { foreach (var e in a.Edges) { var t = e.CcwTriangle; if (t == null) { continue; } if (Point.PointToTheLeftOfLine(b.Point, e.lowerSite.Point, e.upperSite.Point)) { continue; } var eIndex = t.Edges.Index(e); var site = t.Sites[eIndex + 2]; if (Point.PointToTheLeftOfLineOrOnLine(b.Point, site.Point, e.upperSite.Point)) { piercedEdge = t.Edges[eIndex + 1]; piercedTriangle = t; // CdtSweeper.ShowFront(triangles, front, new[] { new LineSegment(e.upperSite.Point, e.lowerSite.Point) }, // new[] { new LineSegment(piercedEdge.upperSite.Point, piercedEdge.lowerSite.Point) }); break; } } } }
void PrepareNextStateAfterPiercedEdge() { var t = piercedEdge.CwTriangle ?? piercedEdge.CcwTriangle; var eIndex = t.Edges.Index(piercedEdge); for (int i = 1; i <= 2; i++) { var e = t.Edges[i + eIndex]; var signedArea0 = ApproximateComparer.Sign(Point.SignedDoubledTriangleArea(e.lowerSite.Point, a.Point, b.Point)); var signedArea1 = ApproximateComparer.Sign(Point.SignedDoubledTriangleArea(e.upperSite.Point, a.Point, b.Point)); if (signedArea1 * signedArea0 <= 0) { if (e.CwTriangle != null && e.CcwTriangle != null) { piercedTriangle = t; piercedEdge = e; break; } //e has to belong to the front, and its triangle has to be removed piercedTriangle = null; piercedEdge = null; var leftSite = e.upperSite.Point.X < e.lowerSite.Point.X ? e.upperSite : e.lowerSite; var frontElem = CdtSweeper.FindNodeInFrontBySite(front, leftSite); Debug.Assert(frontElem != null); if (leftSite.Point.X < a.Point.X) { piercedToTheLeftFrontElemNode = frontElem; } else { piercedToTheRightFrontElemNode = frontElem; } RemovePiercedTriangle(e.CwTriangle ?? e.CcwTriangle); break; } } }
void SweepAndFinalize() { sweeper = new CdtSweeper(allInputSites, P1, P2, GetOrCreateEdge); sweeper.Run(); }
static bool LocalInCircle(CdtSite v, CdtSite a, CdtSite b, CdtSite c, bool reverseTrangleWhenCompare) { return(reverseTrangleWhenCompare ? CdtSweeper.InCircle(v, a, c, b) : CdtSweeper.InCircle(v, a, b, c)); }