forked from Pomax/bezierjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bezier.d.ts
202 lines (200 loc) · 6.85 KB
/
bezier.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
A javascript Bezier curve library by Pomax.
Based on http://pomax.github.io/bezierinfo
This code is MIT licensed.
**/
declare module BezierJs {
interface Point {
x: number;
y: number;
z?: number;
}
interface Projection extends Point {
t?: number;
d?: number;
}
interface Inflection {
x: number[];
y: number[];
z?: number[];
values: number[];
}
interface Offset extends Point {
c: Point;
n: Point;
}
interface Pair {
left: Bezier;
right: Bezier;
}
interface Split extends Pair {
span: Point[];
_t1?: number;
_t2?: number;
}
interface MinMax {
min: number;
mid?: number;
max: number;
size?: number;
}
interface BBox {
x: MinMax;
y: MinMax;
z?: MinMax;
}
interface Line {
p1: Point;
p2: Point;
}
interface Arc extends Point {
e: number;
r: number;
s: number;
}
interface Shape {
startcap: BezierCap;
forward: Bezier;
back: Bezier;
endcap: BezierCap;
bbox: BBox;
intersections: (shape: Shape) => string[][] | number[][];
}
interface ABC {
A: Point;
B: Point;
C: Point;
}
interface Closest {
mdist: number;
mpos: number;
}
/**
* Bezier curve constructor. The constructor argument can be one of three things:
*
* 1. array/4 of {x:..., y:..., z:...}, z optional
* 2. numerical array/8 ordered x1,y1,x2,y2,x3,y3,x4,y4
* 3. numerical array/12 ordered x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4
*
*/
class Bezier {
private _linear;
clockwise: boolean;
_3d: boolean;
_t1: number;
_t2: number;
_lut: Point[];
dpoints: Point[][];
order: number;
points: Point[];
dims: string[];
dimlen: number;
constructor(points: Point[]);
constructor(coords: number[]);
constructor(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4?: number, y4?: number);
constructor(p1: Point, p2: Point, p3: Point, p4?: Point);
static fromSVG(svgString: string): Bezier;
static getABC(n: number, S: Point, B: Point, E: Point, t: number): ABC;
static quadraticFromPoints(p1: Point, p2: Point, p3: Point, t: number): Bezier;
static cubicFromPoints(S: Point, B: Point, E: Point, t: number, d1: number): Bezier;
static getUtils(): typeof utils;
getUtils(): typeof utils;
valueOf(): string;
toString(): string;
toSVG(): string;
update(): void;
computedirection(): void;
length(): number;
getLUT(steps?: number): Point[];
on(point: Point, error: number): number;
project(point: Point): Projection;
get(t: number): Point;
point(idx: number): Point;
compute(t: number): Point;
raise(): Bezier;
derivative(t: number): Point;
inflections(): number[];
normal(t: number): Point;
private __normal2(t);
private __normal3(t);
private __normal(t);
hull(t: number): Point[];
split(t1: number): Split;
split(t1: number, t2: number): Bezier;
extrema(): Inflection;
bbox(): BBox;
overlaps(curve: Bezier): boolean;
offset(t: number, d?: number): Offset | Bezier[];
simple(): boolean;
reduce(): Bezier[];
scale(d: Function): Bezier;
scale(d: number): Bezier;
outline(d1: number, d2?: number, d3?: number, d4?: number): PolyBezier;
outlineshapes(d1: number, d2: number, curveIntersectionThreshold?: number): Shape[];
intersects(curve: Bezier, curveIntersectionThreshold?: number): string[] | number[];
intersects(curve: Line): string[] | number[];
lineIntersects(line: Line): number[];
selfintersects(curveIntersectionThreshold?: number): string[];
curveintersects(c1: Bezier[], c2: Bezier[], curveIntersectionThreshold?: number): string[];
arcs(errorThreshold?: number): Arc[];
private _error(pc, np1, s, e);
private _iterate(errorThreshold, circles);
}
class BezierCap extends Bezier {
virtual: boolean;
}
}
declare module BezierJs.utils {
var Tvalues: number[];
var Cvalues: number[];
function arcfn(t: number, derivativeFn: Function): number;
function between(v: number, m: number, M: number): boolean;
function approximately(a: number, b: number, precision?: number): boolean;
function length(derivativeFn: Function): number;
function map(v: number, ds: number, de: number, ts: number, te: number): number;
function lerp(r: number, v1: Point, v2: Point): Point;
function pointToString(p: Point): string;
function pointsToString(points: Point[]): string;
function copy(obj: Object): any;
function angle(o: Point, v1: Point, v2: Point): number;
function round(v: number, d: number): number;
function dist(p1: Point, p2: Point): number;
function closest(LUT: Point[], point: Point): Closest;
function abcratio(t: number, n: number): number;
function projectionratio(t: number, n: number): number;
function lli8(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): Point;
function lli4(p1: Point, p2: Point, p3: Point, p4: Point): Point;
function lli(v1: Offset, v2: Offset): Point;
function makeline(p1: Point, p2: Point): Bezier;
function findbbox(sections: Bezier[]): BBox;
function shapeintersections(s1: Shape, bbox1: BBox, s2: Shape, bbox2: BBox, curveIntersectionThreshold?: number): string[][] | number[][];
function makeshape(forward: Bezier, back: Bezier, curveIntersectionThreshold?: number): Shape;
function getminmax(curve: Bezier, d: string, list: number[]): MinMax;
function align(points: Point[], line: Line): Point[];
function roots(points: Point[], line: Line): number[];
function droots(p: number[]): number[];
function inflections(points: Point[]): number[];
function bboxoverlap(b1: BBox, b2: BBox): boolean;
function expandbox(bbox: BBox, _bbox: BBox): void;
function pairiteration(c1: Bezier, c2: Bezier, curveIntersectionThreshold?: number): string[];
function getccenter(p1: Point, p2: Point, p3: Point): Arc;
}
declare module BezierJs {
/**
* Poly Bezier
* @param {[type]} curves [description]
*/
class PolyBezier {
curves: Bezier[];
private _3d;
points: Point[];
constructor(curves: Bezier[]);
valueOf(): string;
toString(): string;
addCurve(curve: Bezier): void;
length(): number;
curve(idx: number): Bezier;
bbox(): BBox;
offset(d: number): PolyBezier;
}
}