static bool FindTrimEndForArrowheadAtTarget(ICurve lineCurve, Arrowhead tarArrowhead, out double p) { //Debug.Assert((edgeGeometry.Curve.End - edgeGeometry.Curve.Start).LengthSquared > eps); p = lineCurve.ParEnd; if (tarArrowhead == null || tarArrowhead.Length <= ApproximateComparer.DistanceEpsilon) { return(true); } var eps = ApproximateComparer.DistanceEpsilon * ApproximateComparer.DistanceEpsilon; var curve = lineCurve; var arrowheadLength = tarArrowhead.Length; Point newCurveEnd; IList <IntersectionInfo> intersections; int reps = 10; do { reps--; if (reps == 0) { return(false); } intersections = GetIntersectionsWithArrowheadCircle(curve, arrowheadLength, curve.End); p = intersections.Count != 0 ? intersections.Max(x => x.Par1) : curve.ParEnd; newCurveEnd = lineCurve[p]; arrowheadLength /= 2; } while (((newCurveEnd - curve.Start).LengthSquared < eps || intersections.Count == 0)); //we would like to have at least something left from the curve return(true); }
static bool FindTrimStartForArrowheadAtSource(ICurve lineCurve, Arrowhead srcArrowhead, out double p) { p = 0; //does not matter if (srcArrowhead == null || srcArrowhead.Length <= ApproximateComparer.DistanceEpsilon) { return(true); } var eps = ApproximateComparer.DistanceEpsilon * ApproximateComparer.DistanceEpsilon; Debug.Assert((lineCurve.End - lineCurve.Start).LengthSquared > eps); var arrowheadLength = srcArrowhead.Length; Point newStart; var curve = lineCurve; IList <IntersectionInfo> intersections; int reps = 10; do { reps--; if (reps == 0) { return(false); } intersections = GetIntersectionsWithArrowheadCircle(curve, arrowheadLength, curve.Start); p = intersections.Count != 0 ? intersections.Min(x => x.Par1) : curve.ParStart; newStart = curve[p]; arrowheadLength /= 2; } while ((newStart - curve.End).LengthSquared < eps || intersections.Count == 0); //we are checkng that something will be left from the curve return(true); }
public static bool CalculateArrowheads(ref ICurve lineCurve, Arrowhead srcArrowhead, Arrowhead tarArrowhead) { //ValidateArg.IsNotNull(edgeGeometry, "edgeGeometry"); if (srcArrowhead == null && tarArrowhead == null) { return(true); } double parStart, parEnd; if (!FindTrimStartForArrowheadAtSource(lineCurve, srcArrowhead, out parStart)) { return(false); } if (!FindTrimEndForArrowheadAtTarget(lineCurve, tarArrowhead, out parEnd)) { return(false); } if (parStart > parEnd - ApproximateComparer.IntersectionEpsilon || ApproximateComparer.CloseIntersections(lineCurve[parStart], lineCurve[parEnd])) { return(false); //after the trim nothing would be left of the curve } var c = lineCurve.Trim(parStart, parEnd); if (c == null) { return(false); } if (srcArrowhead != null) { srcArrowhead.TipPosition = PlaceTip(c.Start, lineCurve.Start, srcArrowhead.Offset); } if (tarArrowhead != null) { tarArrowhead.TipPosition = PlaceTip(c.End, lineCurve.End, tarArrowhead.Offset); } lineCurve = c; return(true); }