object GetPointFeatureOnHierarchies(PolylinePoint pp) { var hitNode = SiteHierarchy.FirstHitNode(pp.Point); return hitNode != null ? hitNode.UserData : GetFirstTriangleFeatureNotSite(pp); }
internal LeftIntersectionEvent(ConeLeftSide coneLeftSide, Point intersectionPoint, PolylinePoint endVertex) { this.coneLeftSide = coneLeftSide; this.intersectionPoint = intersectionPoint; this.endVertex = endVertex; }
//TODO Set<PolylinePoint> GetOrCreatePassingPathsSet(PolylinePoint pp) { Set<PolylinePoint> set; if (pathsThroughPoints.TryGetValue(pp.Point, out set)) return set; pathsThroughPoints[pp.Point] = set = new Set<PolylinePoint>(); return set; }
object GetFirstTriangleFeatureNotSite(PolylinePoint pp) { foreach (var triangle in TriangleHierarchy.AllHitItems(pp.Point)) { var feature = TryCreateFeatureWhichIsNotSite(pp, triangle); if (feature != null) return feature; } return OutsideOfTriangulation; }
internal BasicObstacleSide(Obstacle obstacle, PolylinePoint startVertex, ScanDirection scanDir, bool traverseClockwise) : base(startVertex) { Obstacle = obstacle; endVertex = traverseClockwise ? startVertex.NextOnPolyline : startVertex.PrevOnPolyline; if (!scanDir.IsPerpendicular(startVertex.Point, endVertex.Point)) { Slope = StaticGraphUtility.Slope(startVertex.Point, endVertex.Point, scanDir); SlopeInverse = 1.0 / Slope; } }
static Polyline Merge(PolylinePoint p0, PolylinePoint p1) { PolylinePoint s0 = p0; PolylinePoint s1 = p1; Polyline ret = new Polyline(); while (true) { ret.AddPoint(p0.Point + p1.Point); PickNextVertex(ref p0, ref p1); if (p0 == s0 && p1 == s1) { break; } } ret.Closed = true; return(ret); }
/// <summary> /// left derivative at t /// </summary> /// <param name="t">the parameter where the derivative is calculated</param> /// <returns></returns> public Point LeftDerivative(double t) { if (NeedToInit) { Init(); } PolylinePoint pp = TryToGetPolylinePointCorrespondingToT(t); if (pp == null) { return(Derivative(t)); } PolylinePoint prev = TryToGetPrevPointToPolylinePoint(pp); if (prev != null) { return(pp.Point - prev.Point); } return(pp.Next.Point - pp.Point); }
/// <summary> /// right derivative at t /// </summary> /// <param name="t">the parameter where the derivative is calculated</param> /// <returns></returns> public Point RightDerivative(double t) { if (NeedToInit) { Init(); } var pp = TryToGetPolylinePointCorrespondingToT(t); if (pp == null) { return(Derivative(t)); } PolylinePoint next = TryToGetNextPointToPolylinePoint(pp); if (next != null) { return(next.Point - pp.Point); } return(pp.Point - pp.Prev.Point); }
///<summary> ///adds a point to the polyline ///</summary> ///<param name="point"></param> public void AddPoint(Point point) { var pp = new PolylinePoint(point) { Polyline = this }; if (EndPoint != null) { // if (!ApproximateComparer.Close(point, EndPoint.Point)) { EndPoint.Next = pp; pp.Prev = EndPoint; EndPoint = pp; // } } else { StartPoint = EndPoint = pp; } RequireInit(); }
static PolylinePoint GetMostLeftLow(Polyline poly) { PolylinePoint ret = poly.StartPoint; for (PolylinePoint p = ret.Next; p != null; p = p.Next) { if (p.Point.X < ret.Point.X) { ret = p; } else if (p.Point.X == ret.Point.X) { if (p.Point.Y < ret.Point.Y) { ret = p; } } } return(ret); }
internal void PrependPoint(Point p) { Debug.Assert(EndPoint == null || !ApproximateComparer.Close(p, EndPoint.Point)); var pp = new PolylinePoint(p) { Polyline = this }; if (StartPoint != null) { if (!ApproximateComparer.Close(p, StartPoint.Point)) { StartPoint.Prev = pp; pp.Next = StartPoint; StartPoint = pp; } } else { StartPoint = EndPoint = pp; } RequireInit(); }
static public Point PenetrationDepthForPolylines(Polyline poly0, Polyline poly1) { ValidateArg.IsNotNull(poly0, "poly0"); ValidateArg.IsNotNull(poly1, "poly1"); System.Diagnostics.Debug.Assert( Point.GetTriangleOrientation(poly0[0], poly0[1], poly0[2]) == TriangleOrientation.Clockwise && Point.GetTriangleOrientation(poly1[0], poly1[1], poly1[2]) == TriangleOrientation.Clockwise); poly0 = FlipPolyline(poly0); PolylinePoint p0 = GetMostLeftLow(poly0); PolylinePoint p1 = GetMostLeftLow(poly1); Polyline minkovski = Merge(p0, p1); Point origin = new Point(); PolylinePoint pp = minkovski.StartPoint; double d = double.PositiveInfinity; Point ret = new Point(); do { PolylinePoint pn = pp.Polyline.Next(pp); if (Point.GetTriangleOrientation(origin, pp.Point, pn.Point) != TriangleOrientation.Clockwise) { return(new Point()); } double t; double dist = Point.DistToLineSegment(origin, pp.Point, pn.Point, out t); if (dist < d) { d = dist; ret = (1 - t) * pp.Point + t * pn.Point; } pp = pn; } while (pp != minkovski.StartPoint); return(ret); }
internal RelaxedPolylinePoint(PolylinePoint polylinePoint, Point originalPosition) { this.PolylinePoint = polylinePoint; this.OriginalPosition = originalPosition; }
void CreateOrientedSegsOnLineVertex(Metroline line, PolylinePoint polyPoint) { Station u = metroGraphData.PointToStations[polyPoint.Prev.Point]; Station v = metroGraphData.PointToStations[polyPoint.Point]; Station w = metroGraphData.PointToStations[polyPoint.Next.Point]; BundleBase h0 = v.BundleBases[u]; BundleBase h1 = v.BundleBases[w]; int j0 = metroOrdering.GetLineIndexInOrder(u, v, line); int j1 = metroOrdering.GetLineIndexInOrder(w, v, line); var seg = bundlingSettings.UseCubicBezierSegmentsInsideOfHubs ? StandardBezier(h0.Points[j0], h0.Tangents[j0], h1.Points[j1], h1.Tangents[j1]) : BiArc(h0.Points[j0], h0.Tangents[j0], h1.Points[j1], h1.Tangents[j1]); h0.OrientedHubSegments[j0].Segment = seg; h1.OrientedHubSegments[j1].Segment = seg; }
PolylinePoint Next(PolylinePoint p, bool forwardOrder) { return forwardOrder ? p.Next : p.Prev; }
void System.Collections.IEnumerator.Reset() { currentPolyPoint = null; }
internal PolylinePoint Prev(PolylinePoint a) { return(a.Prev ?? (Closed ? EndPoint : null)); }
PolylinePoint TraversePolylineForEvents(PolylinePoint polyPoint) { // When loading scanline events, we'll go clockwise for horizontal scan, where the // scanline-parallel coordinate increases to the right, or counterclockwise for vertical // scan, where the scanline-parallel coordinate increases to the left. if (ScanDirection.IsHorizontal) { return polyPoint.NextOnPolyline; } return polyPoint.PrevOnPolyline; }
static PolylinePoint GetIncomingSide(PolylinePoint v) { return v.PrevOnPolyline; }
void ChangePolylineSegment(PolylinePoint aFirst, PolylinePoint aLast, bool forwardOrderA, List<PolylinePoint> intermediateBPoints) { PolylinePoint curA = aFirst; foreach (PolylinePoint b in intermediateBPoints) { var newp = new PolylinePoint(b.Point) { Polyline = curA.Polyline }; if (forwardOrderA) { newp.Prev = curA; curA.Next = newp; } else { newp.Next = curA; curA.Prev = newp; } curA = newp; } if (forwardOrderA) { curA.Next = aLast; aLast.Prev = curA; } else { curA.Prev = aLast; aLast.Next = curA; } }
void FindPointsOnPolyline(Polyline polyline, Point first, Point last, out PolylinePoint ppFirst, out PolylinePoint ppLast, out bool forwardOrder) { ppFirst = ppLast = null; forwardOrder = false; for (PolylinePoint pp = polyline.StartPoint; pp != null; pp = pp.Next) { if (pp.Point == first) ppFirst = pp; if (pp.Point == last) ppLast = pp; if (ppFirst != null && ppLast == null) forwardOrder = true; if (ppFirst == null && ppLast != null) forwardOrder = false; } Debug.Assert(ppFirst != null && ppLast != null); }
int PolylinesIntersect(PolylinePoint a0, PolylinePoint b0, PolylinePoint a1, PolylinePoint b1, bool forwardOrderA, bool forwardOrderB) { PolylinePoint a0p = Prev(a0, forwardOrderA); PolylinePoint a0n = Next(a0, forwardOrderA); PolylinePoint a1n = Next(a1, forwardOrderA); PolylinePoint a1p = Prev(a1, forwardOrderA); PolylinePoint b0n = Next(b0, forwardOrderB); PolylinePoint b1p = Prev(b1, forwardOrderB); if (a0.Point == a1.Point) { Point bs = a0.Point; int left0 = Point.GetOrientationOf3Vectors(a1p.Point - bs, b1p.Point - bs, a0n.Point - bs); int left1 = Point.GetOrientationOf3Vectors(a1p.Point - bs, b0n.Point - bs, a0n.Point - bs); /* if (left0 == 0 || left1 ==0) { List<DebugCurve> dc = new List<DebugCurve>(); Polyline pl = new Polyline(a0.Polyline); Point sh = new Point(3, 0); pl.Shift(sh); dc.Add(new DebugCurve(100,1,"blue", a0.Polyline)); dc.Add(new DebugCurve(100,1,"black", b0.Polyline)); dc.Add(new DebugCurve("blue", CurveFactory.CreateCircle(3, bs))); dc.Add(new DebugCurve(100,0.5, "blue", new LineSegment(a0p.Point, bs))); dc.Add(new DebugCurve("red", CurveFactory.CreateCircle(5, b0.Point))); dc.Add(new DebugCurve("red", CurveFactory.CreateCircle(10, b1.Point))); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(dc); } */ Debug.Assert(left0 != 0 && left1 != 0); return left0 == left1 ? 1 : 2; } else { int left0 = Point.GetOrientationOf3Vectors(a0p.Point - a0.Point, a0n.Point - a0.Point, b0n.Point - a0.Point); int left1 = Point.GetOrientationOf3Vectors(a1n.Point - a1.Point, b1p.Point - a1.Point, a1p.Point - a1.Point); Debug.Assert(left0 != 0 && left1 != 0); return left0 == left1 ? 1 : 2; } }
void Swap(PolylinePoint aFirst, PolylinePoint bFirst, PolylinePoint aLast, PolylinePoint bLast, bool forwardOrderA, bool forwardOrderB) { List<PolylinePoint> intermediateAPoints = GetRangeOnPolyline(Next(aFirst, forwardOrderA), aLast, forwardOrderA); List<PolylinePoint> intermediateBPoints = GetRangeOnPolyline(Next(bFirst, forwardOrderB), bLast, forwardOrderB); //changing a ChangePolylineSegment(aFirst, aLast, forwardOrderA, intermediateBPoints); //changing b ChangePolylineSegment(bFirst, bLast, forwardOrderB, intermediateAPoints); //resulting polylines might have cycles PathFixer.RemoveSelfCyclesFromPolyline(aFirst.Polyline); Debug.Assert(PolylineIsOK(aFirst.Polyline)); PathFixer.RemoveSelfCyclesFromPolyline(bFirst.Polyline); Debug.Assert(PolylineIsOK(bFirst.Polyline)); }
int FindRelationOnLastPoint(PolylinePoint aLast, PolylinePoint bLast, bool forwardOrderA, bool forwardOrderB) { Debug.Assert(aLast.Point == bLast.Point); PolylinePoint a0 = aLast; PolylinePoint b0 = bLast; while (true) { PolylinePoint nextA = Next(aLast, forwardOrderA); PolylinePoint nextB = Next(bLast, forwardOrderB); if (nextA == null || nextB == null) { Debug.Assert(nextA == null && nextB == null); return 0; } if (nextA.Point != nextB.Point) break; aLast = nextA; bLast = nextB; } while (Next(aLast, forwardOrderA).Point == Prev(bLast, forwardOrderB).Point) { aLast = Next(aLast, forwardOrderA); bLast = Prev(bLast, forwardOrderB); } return PolylinesIntersect(aLast, bLast, a0, b0, forwardOrderA, forwardOrderB); }
int FindRelationOnFirstPoint(PolylinePoint aFirst, PolylinePoint bFirst, bool forwardOrderA, bool forwardOrderB) { Debug.Assert(aFirst.Point == bFirst.Point); PolylinePoint a0 = aFirst; PolylinePoint b0 = bFirst; while (true) { PolylinePoint prevA = Prev(aFirst, forwardOrderA); PolylinePoint prevB = Prev(bFirst, forwardOrderB); if (prevA == null || prevB == null) { Debug.Assert(prevA == null && prevB == null); return 0; } if (prevA.Point != prevB.Point) break; aFirst = prevA; bFirst = prevB; } return PolylinesIntersect(a0, b0, aFirst, bFirst, forwardOrderA, forwardOrderB); }
PolylinePoint Prev(PolylinePoint p, bool forwardOrder) { return forwardOrder ? p.Prev : p.Next; }
void CreateOrientedSegsOnLineVertex(Metroline line, PolylinePoint polyPoint) { Station u = metroGraphData.PointToStations[polyPoint.Prev.Point]; Station v = metroGraphData.PointToStations[polyPoint.Point]; Station w = metroGraphData.PointToStations[polyPoint.Next.Point]; BundleBase h0 = v.BundleBases[u]; BundleBase h1 = v.BundleBases[w]; int j0 = metroOrdering.GetLineIndexInOrder(u, v, line); int j1 = metroOrdering.GetLineIndexInOrder(w, v, line); OrientedHubSegment or0 = h0.OrientedHubSegments[j0] = new OrientedHubSegment(null, false, j0, h0); OrientedHubSegment or1 = h1.OrientedHubSegments[j1] = new OrientedHubSegment(null, true, j1, h1); or1.Other = or0; or0.Other = or1; }
void FillDepartedOnPrev(Dictionary<Polyline, PolylinePoint> departed, PolylinePoint pp) { Point prevPoint = pp.Prev.Point; foreach (PolylinePoint polyPoint in pathsThroughPoints[prevPoint]) { if (!IsNeighbor(polyPoint, pp)) { Debug.Assert(!departed.ContainsKey(polyPoint.Polyline)); departed[polyPoint.Polyline] = polyPoint; } } }
internal LeftVertexEvent(PolylinePoint p) : base(p) { }
bool IsNeighbor(PolylinePoint a, PolylinePoint b) { return a.Prev != null && a.Prev.Point == b.Point || a.Next != null && a.Next.Point == b.Point; }
bool HoleSideIsVisibleFromQ(Polyline hole, PolylinePoint b) { return Point.SignedDoubledTriangleArea(q, b.Point, hole.Next(b).Point) >= -ApproximateComparer.SquareOfDistanceEpsilon; }
void RegisterPolylinePointInPathsThrough(PolylinePoint pp) { CollectionUtilities.AddToMap(pathsThroughPoints, pp.Point, pp); }
PolylinePoint GetOutgoingSide(PolylinePoint v) { Stem visibleStem = visibleBoundaries[v.Polyline]; if (v == visibleStem.End) return null; return v; }
void UnregisterPolylinePointInPathsThrough(PolylinePoint pp) { CollectionUtilities.RemoveFromMap(pathsThroughPoints, pp.Point, pp); }
internal PolylinePoint Next(PolylinePoint a) { return(a.Next ?? (Closed ? StartPoint : null)); }
internal LeftObstacleSide(PolylinePoint startVertex) : base(startVertex) { end = startVertex.NextOnPolyline.Point; }
static ICurve SegOnLineVertex(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroOrdering, Metroline line, PolylinePoint i) { Station u = metroGraphData.PointToStations[i.Prev.Point]; Station v = metroGraphData.PointToStations[i.Point]; BundleBase h0 = v.BundleBases[u]; int j0 = metroOrdering.GetLineIndexInOrder(u, v, line); if (h0.OrientedHubSegments[j0] == null || h0.OrientedHubSegments[j0].Segment == null) { var w = metroGraphData.PointToStations[i.Next.Point]; var otherBase = v.BundleBases[w]; var j1 = metroOrdering.GetLineIndexInOrder(w, v, line); return new LineSegment(h0.Points[j0], otherBase.Points[j1]); } return h0.OrientedHubSegments[j0].Segment; }
internal RightObstacleSide(PolylinePoint startVertex) : base(startVertex) { this.end = startVertex.PrevOnPolyline.Point; }
List<PolylinePoint> GetRangeOnPolyline(PolylinePoint start, PolylinePoint end, bool forwardOrder) { List<PolylinePoint> res = new List<PolylinePoint>(); for (PolylinePoint pp = start; pp != end; pp = Next(pp, forwardOrder)) res.Add(pp); return res; }
bool PolylinePointsAreInForwardOrder(PolylinePoint u, PolylinePoint v) { Debug.Assert(u.Polyline == v.Polyline); for (PolylinePoint p = u; p != null; p = p.Next) if (p == v) return true; return false; }