MarchLocation.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections.Generic;
  2. using System.Windows;
  3. namespace HandyControl.Expression.Drawing;
  4. internal class MarchLocation
  5. {
  6. public double After { get; private set; }
  7. public double Before { get; private set; }
  8. public int Index { get; private set; }
  9. public double Ratio { get; private set; }
  10. public MarchStopReason Reason { get; private set; }
  11. public double Remain { get; private set; }
  12. public static MarchLocation Create(MarchStopReason reason, int index, double before, double after,
  13. double remain)
  14. {
  15. var num = before + after;
  16. return new MarchLocation
  17. {
  18. Reason = reason,
  19. Index = index,
  20. Remain = remain,
  21. Before = MathHelper.EnsureRange(before, 0.0, num),
  22. After = MathHelper.EnsureRange(after, 0.0, num),
  23. Ratio = MathHelper.EnsureRange(MathHelper.SafeDivide(before, num, 0.0), 0.0, 1.0)
  24. };
  25. }
  26. public double GetArcLength(IList<double> accumulatedLengths)
  27. {
  28. return MathHelper.Lerp(accumulatedLengths[Index], accumulatedLengths[Index + 1], Ratio);
  29. }
  30. public Vector GetNormal(PolylineData polyline, double cornerRadius = 0.0)
  31. {
  32. return polyline.SmoothNormal(Index, Ratio, cornerRadius);
  33. }
  34. public Point GetPoint(IList<Point> points)
  35. {
  36. return GeometryHelper.Lerp(points[Index], points[Index + 1], Ratio);
  37. }
  38. }