//void UpdateEdgeLabelPosition(LayerEdge[][] list, int i) { // IntEdge e; // int labelNodeIndex; // if (Engine.GetLabelEdgeAndVirtualNode(list, i, out e, out labelNodeIndex)) { // UpdateLabel(e, labelNodeIndex, db.Anchors); // } //} internal static void UpdateLabel(Edge e, Anchor anchor){ LineSegment labelSide = null; if (anchor.LabelToTheRightOfAnchorCenter){ e.Label.Center = new Point(anchor.X + anchor.RightAnchor/2, anchor.Y); labelSide = new LineSegment(e.LabelBBox.LeftTop, e.LabelBBox.LeftBottom); } else if (anchor.LabelToTheLeftOfAnchorCenter){ e.Label.Center = new Point(anchor.X - anchor.LeftAnchor/2, anchor.Y); labelSide = new LineSegment(e.LabelBBox.RightTop, e.LabelBBox.RightBottom); } ICurve segmentInFrontOfLabel = GetSegmentInFrontOfLabel(e.Curve, e.Label.Center.Y); if (segmentInFrontOfLabel == null) return; if (Curve.GetAllIntersections(e.Curve, Curve.PolyFromBox(e.LabelBBox), false).Count == 0){ Point curveClosestPoint; Point labelSideClosest; if (FindClosestPoints(out curveClosestPoint, out labelSideClosest, segmentInFrontOfLabel, labelSide)){ //shift the label if needed ShiftLabel(e, ref curveClosestPoint, ref labelSideClosest); } else{ //assume that the distance is reached at the ends of labelSideClosest double u = segmentInFrontOfLabel.ClosestParameter(labelSide.Start); double v = segmentInFrontOfLabel.ClosestParameter(labelSide.End); if ((segmentInFrontOfLabel[u] - labelSide.Start).Length < (segmentInFrontOfLabel[v] - labelSide.End).Length){ curveClosestPoint = segmentInFrontOfLabel[u]; labelSideClosest = labelSide.Start; } else{ curveClosestPoint = segmentInFrontOfLabel[v]; labelSideClosest = labelSide.End; } ShiftLabel(e, ref curveClosestPoint, ref labelSideClosest); } } }
static void ExtendPolylineStartToClusterBoundary(Polyline poly, ICurve curve) { var par = curve.ClosestParameter(poly.Start); poly.PrependPoint(curve[par]); }
static void ExtendPolylineEndToClusterBoundary(Polyline poly, ICurve curve) { var par = curve.ClosestParameter(poly.End); poly.AddPoint(curve[par]); }
/// <summary> /// gets the point on the curve that is closest to the given point /// </summary> /// <param name="curve">the curve to examine</param> /// <param name="location">the target point</param> /// <returns>the closest point</returns> public static Point ClosestPoint(ICurve curve, Point location) { ValidateArg.IsNotNull(curve, "curve"); return curve[curve.ClosestParameter(location)]; }
public static double ClosestParameterWithPoint(ICurve curve, Point location, out Point pointOnCurve) { ValidateArg.IsNotNull(curve, "curve"); double t = curve.ClosestParameter(location); pointOnCurve = curve[t]; return t; }