public double GetLength(double t, IStopper stop) { if (t <= t_start) { return(0); } else if (t >= t_finish) { return(comp.GetLength(t_finish, stop) - comp.GetLength(t_start, stop)); } else { return(comp.GetLength(t, stop) - comp.GetLength(t_start, stop)); } }
/// <summary> /// Flattens the specified curve. See <see cref="ICurve{TParam, TPoint}.Flatten"/>. /// </summary> /// <remarks> /// This method cannot be used for curves that contain gaps! /// </remarks> internal static void Flatten(ICurve <float, Vector3> curve, ICollection <Vector3> points, int maxNumberOfIterations, float tolerance) { if (tolerance <= 0) { throw new ArgumentOutOfRangeException("tolerance", "The tolerance must be greater than zero."); } float totalLength = curve.GetLength(0, 1, maxNumberOfIterations, tolerance); // No line segments if the curve has zero length. if (totalLength == 0) { return; } // A single line segment if the curve's length is less than the tolerance. if (totalLength < tolerance) { points.Add(curve.GetPoint(0)); points.Add(curve.GetPoint(1)); return; } var list = ResourcePools <Vector3> .Lists.Obtain(); Flatten(curve, list, 0, 1, curve.GetPoint(0), curve.GetPoint(1), 0, totalLength, 1, maxNumberOfIterations, tolerance); foreach (var point in list) { points.Add(point); } ResourcePools <Vector3> .Lists.Recycle(list); }
/// <summary> /// Flattens the specified curve. See <see cref="ICurve{TParam, TPoint}.Flatten"/>. /// </summary> /// <remarks> /// This method cannot be used for curves that contain gaps! /// </remarks> internal static void Flatten(ICurve<float, Vector3F> curve, ICollection<Vector3F> points, int maxNumberOfIterations, float tolerance) { if (tolerance <= 0) throw new ArgumentOutOfRangeException("tolerance", "The tolerance must be greater than zero."); float totalLength = curve.GetLength(0, 1, maxNumberOfIterations, tolerance); // No line segments if the curve has zero length. if (totalLength == 0) return; // A single line segment if the curve's length is less than the tolerance. if (totalLength < tolerance) { points.Add(curve.GetPoint(0)); points.Add(curve.GetPoint(1)); return; } var list = ResourcePools<Vector3F>.Lists.Obtain(); Flatten(curve, list, 0, 1, curve.GetPoint(0), curve.GetPoint(1), 0, totalLength, 1, maxNumberOfIterations, tolerance); foreach (var point in list) points.Add(point); ResourcePools<Vector3F>.Lists.Recycle(list); }
private static void Flatten(ICurve <float, Vector3> curve, List <Vector3> points, float p0, float p1, Vector3 point0, Vector3 point1, float length0, float length1, int iteration, int maxNumberOfIterations, float tolerance) { if (iteration >= maxNumberOfIterations || Math.Abs((length1 - length0) - (point1 - point0).Length) < tolerance) { points.Add(point0); points.Add(point1); return; } // Subdivide. var pMiddle = (p0 + p1) / 2; var pointMiddle = curve.GetPoint(pMiddle); var lengthMiddle = length0 + curve.GetLength(p0, pMiddle, maxNumberOfIterations, tolerance / 10); Flatten(curve, points, p0, pMiddle, point0, pointMiddle, length0, lengthMiddle, iteration + 1, maxNumberOfIterations, tolerance); Flatten(curve, points, pMiddle, p1, pointMiddle, point1, lengthMiddle, length1, iteration + 1, maxNumberOfIterations, tolerance); }
private float GetLength(float parameter) { return(_curve.GetLength(0, parameter, _maxNumberOfIterations, _tolerance / 10)); }
public double GetLength(double t, IStopper stop) { return(curve.GetLength(t, stop)); }
private static void Flatten(ICurve<float, Vector3F> curve, List<Vector3F> points, float p0, float p1, Vector3F point0, Vector3F point1, float length0, float length1, int iteration, int maxNumberOfIterations, float tolerance) { if (iteration >= maxNumberOfIterations || Math.Abs((length1 - length0) - (point1 - point0).Length) < tolerance) { points.Add(point0); points.Add(point1); return; } // Subdivide. var pMiddle = (p0 + p1) / 2; var pointMiddle = curve.GetPoint(pMiddle); var lengthMiddle = length0 + curve.GetLength(p0, pMiddle, maxNumberOfIterations, tolerance / 10); Flatten(curve, points, p0, pMiddle, point0, pointMiddle, length0, lengthMiddle, iteration + 1, maxNumberOfIterations, tolerance); Flatten(curve, points, pMiddle, p1, pointMiddle, point1, lengthMiddle, length1, iteration + 1, maxNumberOfIterations, tolerance); }