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