fit-curve.d.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. declare module "fit-curve" {
  2. /** A point in space represented as an array of numbers, 2D by default, but can be any dimension. */
  3. type Point<Arr extends number[]> = Arr;
  4. /** A vector represented as an array of numbers, 2D by default, but can be any dimension. */
  5. type Vector<Arr extends number[]> = Arr;
  6. /** A Bezier curve represented by an array of points with elements [first-point, control-point-1, control-point-2, second-point] */
  7. type Curve<Arr extends number[]> = [
  8. Point<Arr>,
  9. Point<Arr>,
  10. Point<Arr>,
  11. Point<Arr>
  12. ];
  13. /**
  14. * Fit one or more Bezier curves to a set of points.
  15. *
  16. * @param points - Array of digitized points, e.g. [[5,5],[5,50],[110,140],[210,160],[320,110]]
  17. * @param maxError - Tolerance, squared error between points and fitted curve
  18. * @returns Array of Bezier curves, where each element is [first-point, control-point-1, control-point-2, second-point] and points are [x, y]
  19. */
  20. function fitCurve<Arr extends number[] = [number, number]>(
  21. points: Point<Arr>[],
  22. maxError: number
  23. ): Curve<Arr>[];
  24. export default fitCurve;
  25. /**
  26. * Fit a Bezier curve to a (sub)set of digitized points.
  27. * Typically, your code should not call this function directly. Use {@link fitCurve} instead.
  28. *
  29. * @param points - Array of digitized points, e.g. [[5,5],[5,50],[110,140],[210,160],[320,110]]
  30. * @param leftTangent - Unit tangent vector at start point
  31. * @param rightTangent - Unit tangent vector at end point
  32. * @param maxError - Tolerance, squared error between points and fitted curve
  33. * @returns Array of Bezier curves, where each element is [first-point, control-point-1, control-point-2, second-point] and points are [x, y]
  34. */
  35. export function fitCubic<Arr extends number[] = [number, number]>(
  36. points: Point<Arr>[],
  37. leftTangent: Vector<Arr>,
  38. rightTangent: Vector<Arr>,
  39. maxError: number
  40. ): Curve<Arr>[];
  41. /**
  42. * Creates a vector of length 1 which shows the direction from B to A
  43. */
  44. export function createTangent<Arr extends number[] = [number, number]>(
  45. pointA: Point<Arr>,
  46. pointB: Point<Arr>
  47. ): Vector<Arr>;
  48. }