svg-path-commander 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +18 -4
- package/CHANGELOG.md +34 -0
- package/README.md +15 -3
- package/dist/index.d.ts +1085 -97
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +394 -270
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/util.d.ts +525 -58
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +391 -268
- package/dist/util.js.map +1 -1
- package/package.json +14 -19
package/dist/util.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* SVGPathCommander v2.2.
|
|
2
|
+
* SVGPathCommander v2.2.3 (http://thednp.github.io/svg-path-commander)
|
|
3
3
|
* Copyright 2026 © thednp
|
|
4
4
|
* Licensed under MIT (https://github.com/thednp/svg-path-commander/blob/master/LICENSE)
|
|
5
5
|
*/
|
|
6
|
+
import CSSMatrix from "@thednp/dommatrix";
|
|
6
7
|
//#region src/interface.d.ts
|
|
8
|
+
/** The properties of a path segment found by segment lookup utilities. */
|
|
7
9
|
type SegmentProperties = {
|
|
8
10
|
segment: PathSegment;
|
|
9
11
|
index: number;
|
|
10
12
|
length: number;
|
|
11
13
|
lengthAtSegment: number;
|
|
12
14
|
};
|
|
15
|
+
/** The closest point on the path to a given point, with the distance and optional segment. */
|
|
13
16
|
type PointProperties = {
|
|
14
17
|
closest: {
|
|
15
18
|
x: number;
|
|
@@ -18,6 +21,7 @@ type PointProperties = {
|
|
|
18
21
|
distance: number;
|
|
19
22
|
segment?: SegmentProperties;
|
|
20
23
|
};
|
|
24
|
+
/** The attributes of a `<line>` element read by `shapeToPath`. */
|
|
21
25
|
type LineAttr = {
|
|
22
26
|
type: "line";
|
|
23
27
|
x1: number;
|
|
@@ -26,11 +30,13 @@ type LineAttr = {
|
|
|
26
30
|
y2: number;
|
|
27
31
|
[key: string]: string | number;
|
|
28
32
|
};
|
|
33
|
+
/** The attributes of a `<polygon>` or `<polyline>` element read by `shapeToPath`. */
|
|
29
34
|
type PolyAttr = {
|
|
30
35
|
type: "polygon" | "polyline";
|
|
31
36
|
points: string;
|
|
32
37
|
[key: string]: string | number;
|
|
33
38
|
};
|
|
39
|
+
/** The attributes of a `<circle>` element read by `shapeToPath`. */
|
|
34
40
|
type CircleAttr = {
|
|
35
41
|
type: "circle";
|
|
36
42
|
cx: number;
|
|
@@ -38,6 +44,7 @@ type CircleAttr = {
|
|
|
38
44
|
r: number;
|
|
39
45
|
[key: string]: string | number;
|
|
40
46
|
};
|
|
47
|
+
/** The attributes of an `<ellipse>` element read by `shapeToPath`. */
|
|
41
48
|
type EllipseAttr = {
|
|
42
49
|
type: "ellipse";
|
|
43
50
|
cx: number;
|
|
@@ -46,6 +53,7 @@ type EllipseAttr = {
|
|
|
46
53
|
ry?: number;
|
|
47
54
|
[key: string]: string | number | undefined;
|
|
48
55
|
};
|
|
56
|
+
/** The attributes of a `<rect>` element read by `shapeToPath`. */
|
|
49
57
|
type RectAttr = {
|
|
50
58
|
type: "rect";
|
|
51
59
|
width: number;
|
|
@@ -56,11 +64,13 @@ type RectAttr = {
|
|
|
56
64
|
ry?: number;
|
|
57
65
|
[key: string]: string | number | undefined;
|
|
58
66
|
};
|
|
67
|
+
/** The attributes of a `<glyph>` element read by `shapeToPath`. */
|
|
59
68
|
type GlyphAttr = {
|
|
60
69
|
type: "glyph";
|
|
61
70
|
d: string;
|
|
62
71
|
[key: string]: string | number;
|
|
63
72
|
};
|
|
73
|
+
/** The parameter names read from each SVG shape element by `shapeToPath`. */
|
|
64
74
|
type ShapeParams = {
|
|
65
75
|
line: ["x1", "y1", "x2", "y2"];
|
|
66
76
|
circle: ["cx", "cy", "r"];
|
|
@@ -70,6 +80,7 @@ type ShapeParams = {
|
|
|
70
80
|
polyline: ["points"];
|
|
71
81
|
glyph: ["d"];
|
|
72
82
|
};
|
|
83
|
+
/** The current state tracked by the SVG path string parser. */
|
|
73
84
|
type ParserParams = {
|
|
74
85
|
mx: number;
|
|
75
86
|
my: number;
|
|
@@ -82,6 +93,7 @@ type ParserParams = {
|
|
|
82
93
|
qx: number | null;
|
|
83
94
|
qy: number | null;
|
|
84
95
|
};
|
|
96
|
+
/** A transform function object with translate, rotate, scale, skew and origin. */
|
|
85
97
|
type TransformObject = {
|
|
86
98
|
translate: number | number[];
|
|
87
99
|
rotate: number | number[];
|
|
@@ -91,104 +103,191 @@ type TransformObject = {
|
|
|
91
103
|
};
|
|
92
104
|
//#endregion
|
|
93
105
|
//#region src/types.d.ts
|
|
106
|
+
/** Whitespace character codes recognized by the SVG path string tokenizer. */
|
|
94
107
|
type SpaceNumber = 0x1680 | 0x180e | 0x2000 | 0x2001 | 0x2002 | 0x2003 | 0x2004 | 0x2005 | 0x2006 | 0x2007 | 0x2008 | 0x2009 | 0x200a | 0x202f | 0x205f | 0x3000 | 0xfeff | 0x0a | 0x0d | 0x2028 | 0x2029 | 0x20 | 0x09 | 0x0b | 0x0c | 0xa0 | 0x1680;
|
|
108
|
+
/** Character codes of all SVG path command letters. */
|
|
95
109
|
type PathCommandNumber = 0x6d | 0x7a | 0x6c | 0x68 | 0x76 | 0x63 | 0x73 | 0x71 | 0x74 | 0x61;
|
|
110
|
+
/** Character codes of the decimal digits 0-9. */
|
|
96
111
|
type DigitNumber = 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39;
|
|
112
|
+
/** The absolute moveto command letter. */
|
|
97
113
|
type MCommand = "M";
|
|
114
|
+
/** The relative moveto command letter. */
|
|
98
115
|
type mCommand = "m";
|
|
116
|
+
/** The absolute lineto command letter. */
|
|
99
117
|
type LCommand = "L";
|
|
118
|
+
/** The relative lineto command letter. */
|
|
100
119
|
type lCommand = "l";
|
|
120
|
+
/** The absolute vertical lineto command letter. */
|
|
101
121
|
type VCommand = "V";
|
|
122
|
+
/** The relative vertical lineto command letter. */
|
|
102
123
|
type vCommand = "v";
|
|
124
|
+
/** The absolute horizontal lineto command letter. */
|
|
103
125
|
type HCommand = "H";
|
|
126
|
+
/** The relative horizontal lineto command letter. */
|
|
104
127
|
type hCommand = "h";
|
|
128
|
+
/** The absolute closepath command letter. */
|
|
105
129
|
type ZCommand = "Z";
|
|
130
|
+
/** The relative closepath command letter. */
|
|
106
131
|
type zCommand = "z";
|
|
132
|
+
/** The absolute cubic Bezier command letter. */
|
|
107
133
|
type CCommand = "C";
|
|
134
|
+
/** The relative cubic Bezier command letter. */
|
|
108
135
|
type cCommand = "c";
|
|
136
|
+
/** The absolute smooth cubic Bezier command letter. */
|
|
109
137
|
type SCommand = "S";
|
|
138
|
+
/** The relative smooth cubic Bezier command letter. */
|
|
110
139
|
type sCommand = "s";
|
|
140
|
+
/** The absolute quadratic Bezier command letter. */
|
|
111
141
|
type QCommand = "Q";
|
|
142
|
+
/** The relative quadratic Bezier command letter. */
|
|
112
143
|
type qCommand = "q";
|
|
144
|
+
/** The absolute smooth quadratic Bezier command letter. */
|
|
113
145
|
type TCommand = "T";
|
|
146
|
+
/** The relative smooth quadratic Bezier command letter. */
|
|
114
147
|
type tCommand = "t";
|
|
148
|
+
/** The absolute elliptical arc command letter. */
|
|
115
149
|
type ACommand = "A";
|
|
150
|
+
/** The relative elliptical arc command letter. */
|
|
116
151
|
type aCommand = "a";
|
|
152
|
+
/** The union of all absolute path command letters. */
|
|
117
153
|
type AbsoluteCommand = MCommand | LCommand | VCommand | HCommand | ZCommand | CCommand | SCommand | QCommand | TCommand | ACommand;
|
|
154
|
+
/** The union of all relative path command letters. */
|
|
118
155
|
type RelativeCommand = mCommand | lCommand | vCommand | hCommand | zCommand | cCommand | sCommand | qCommand | tCommand | aCommand;
|
|
156
|
+
/** Any SVG path command letter, absolute or relative. */
|
|
119
157
|
type PathCommand = AbsoluteCommand | RelativeCommand;
|
|
158
|
+
/** The absolute moveto segment tuple `[M, x, y]`. */
|
|
120
159
|
type MSegment = [MCommand, number, number];
|
|
160
|
+
/** The relative moveto segment tuple `[m, dx, dy]`. */
|
|
121
161
|
type mSegment = [mCommand, number, number];
|
|
162
|
+
/** The moveto segment, absolute or relative. */
|
|
122
163
|
type MoveSegment = MSegment | mSegment;
|
|
164
|
+
/** The absolute lineto segment tuple `[L, x, y]`. */
|
|
123
165
|
type LSegment = [LCommand, number, number];
|
|
166
|
+
/** The relative lineto segment tuple `[l, dx, dy]`. */
|
|
124
167
|
type lSegment = [lCommand, number, number];
|
|
168
|
+
/** The lineto segment, absolute or relative. */
|
|
125
169
|
type LineSegment = LSegment | lSegment;
|
|
170
|
+
/** The absolute vertical lineto segment tuple `[V, y]`. */
|
|
126
171
|
type VSegment = [VCommand, number];
|
|
172
|
+
/** The relative vertical lineto segment tuple `[v, dy]`. */
|
|
127
173
|
type vSegment = [vCommand, number];
|
|
174
|
+
/** The vertical lineto segment, absolute or relative. */
|
|
128
175
|
type VertLineSegment = vSegment | VSegment;
|
|
176
|
+
/** The absolute horizontal lineto segment tuple `[H, x]`. */
|
|
129
177
|
type HSegment = [HCommand, number];
|
|
178
|
+
/** The relative horizontal lineto segment tuple `[h, dx]`. */
|
|
130
179
|
type hSegment = [hCommand, number];
|
|
180
|
+
/** The horizontal lineto segment, absolute or relative. */
|
|
131
181
|
type HorLineSegment = HSegment | hSegment;
|
|
182
|
+
/** The absolute closepath segment tuple `[Z]`. */
|
|
132
183
|
type ZSegment = [ZCommand];
|
|
184
|
+
/** The relative closepath segment tuple `[z]`. */
|
|
133
185
|
type zSegment = [zCommand];
|
|
186
|
+
/** The closepath segment, absolute or relative. */
|
|
134
187
|
type CloseSegment = ZSegment | zSegment;
|
|
188
|
+
/** The absolute cubic Bezier segment tuple `[C, x1, y1, x2, y2, x, y]`. */
|
|
135
189
|
type CSegment = [CCommand, number, number, number, number, number, number];
|
|
190
|
+
/** The relative cubic Bezier segment tuple `[c, dx1, dy1, dx2, dy2, dx, dy]`. */
|
|
136
191
|
type cSegment = [cCommand, number, number, number, number, number, number];
|
|
192
|
+
/** The cubic Bezier segment, absolute or relative. */
|
|
137
193
|
type CubicSegment = CSegment | cSegment;
|
|
194
|
+
/** The absolute smooth cubic Bezier segment tuple `[S, x2, y2, x, y]`. */
|
|
138
195
|
type SSegment = [SCommand, number, number, number, number];
|
|
196
|
+
/** The relative smooth cubic Bezier segment tuple `[s, dx2, dy2, dx, dy]`. */
|
|
139
197
|
type sSegment = [sCommand, number, number, number, number];
|
|
198
|
+
/** The smooth cubic Bezier segment, absolute or relative. */
|
|
140
199
|
type ShortCubicSegment = SSegment | sSegment;
|
|
200
|
+
/** The absolute quadratic Bezier segment tuple `[Q, x1, y1, x, y]`. */
|
|
141
201
|
type QSegment = [QCommand, number, number, number, number];
|
|
202
|
+
/** The relative quadratic Bezier segment tuple `[q, dx1, dy1, dx, dy]`. */
|
|
142
203
|
type qSegment = [qCommand, number, number, number, number];
|
|
204
|
+
/** The quadratic Bezier segment, absolute or relative. */
|
|
143
205
|
type QuadSegment = QSegment | qSegment;
|
|
206
|
+
/** The absolute smooth quadratic Bezier segment tuple `[T, x, y]`. */
|
|
144
207
|
type TSegment = [TCommand, number, number];
|
|
208
|
+
/** The relative smooth quadratic Bezier segment tuple `[t, dx, dy]`. */
|
|
145
209
|
type tSegment = [tCommand, number, number];
|
|
210
|
+
/** The smooth quadratic Bezier segment, absolute or relative. */
|
|
146
211
|
type ShortQuadSegment = TSegment | tSegment;
|
|
212
|
+
/** The absolute elliptical arc segment tuple `[A, rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y]`. */
|
|
147
213
|
type ASegment = [ACommand, number, number, number, number, number, number, number];
|
|
214
|
+
/** The relative elliptical arc segment tuple `[a, rx, ry, xAxisRotation, largeArcFlag, sweepFlag, dx, dy]`. */
|
|
148
215
|
type aSegment = [aCommand, number, number, number, number, number, number, number];
|
|
216
|
+
/** The elliptical arc segment, absolute or relative. */
|
|
149
217
|
type ArcSegment = ASegment | aSegment;
|
|
218
|
+
/** Any SVG path command segment. */
|
|
150
219
|
type PathSegment = MoveSegment | LineSegment | VertLineSegment | HorLineSegment | CloseSegment | CubicSegment | ShortCubicSegment | QuadSegment | ShortQuadSegment | ArcSegment;
|
|
220
|
+
/** Any shorthand or single-coordinate path segment. */
|
|
151
221
|
type ShortSegment = VertLineSegment | HorLineSegment | ShortCubicSegment | ShortQuadSegment | CloseSegment;
|
|
222
|
+
/** Any absolute path command segment. */
|
|
152
223
|
type AbsoluteSegment = MSegment | LSegment | VSegment | HSegment | CSegment | SSegment | QSegment | TSegment | ASegment | ZSegment;
|
|
224
|
+
/** Any relative path command segment. */
|
|
153
225
|
type RelativeSegment = mSegment | lSegment | vSegment | hSegment | cSegment | sSegment | qSegment | tSegment | aSegment | zSegment;
|
|
226
|
+
/** The path segments used by the normalized form (no shorthand commands). */
|
|
154
227
|
type NormalSegment = MSegment | LSegment | CSegment | QSegment | ASegment | ZSegment;
|
|
228
|
+
/** A parsed SVG path string as an array of path segments. */
|
|
155
229
|
type PathArray = [MSegment | mSegment, ...PathSegment[]];
|
|
230
|
+
/** A `PathArray` with only absolute path segments. */
|
|
156
231
|
type AbsoluteArray = [MSegment, ...AbsoluteSegment[]];
|
|
232
|
+
/** A `PathArray` with only relative path segments. */
|
|
157
233
|
type RelativeArray = [MSegment, ...RelativeSegment[]];
|
|
234
|
+
/** A `PathArray` with only normalized segments (no shorthand commands). */
|
|
158
235
|
type NormalArray = [MSegment, ...NormalSegment[]];
|
|
236
|
+
/** A `PathArray` with only moveto and cubic Bezier segments. */
|
|
159
237
|
type CurveArray = [MSegment, ...CSegment[]];
|
|
238
|
+
/** A `CurveArray` ending with a closepath segment. */
|
|
160
239
|
type ClosedCurveArray = [MSegment, ...CSegment[], ZSegment];
|
|
240
|
+
/** A `PathArray` describing a closed polygon (moveto, lineto and closepath). */
|
|
161
241
|
type PolygonArray = [MSegment, ...LSegment[], ZSegment];
|
|
242
|
+
/** A `PathArray` describing an open polyline (moveto and lineto). */
|
|
162
243
|
type PolylineArray = [MSegment, ...LSegment[]];
|
|
244
|
+
/** The `PathArray` shapes supported by path morphing. */
|
|
163
245
|
type MorphPathArray = PolygonArray | PolylineArray | CurveArray | ClosedCurveArray;
|
|
246
|
+
/** The SVG element types that can be converted to a path. */
|
|
164
247
|
type ShapeTypes = SVGPolylineElement | SVGPolygonElement | SVGLineElement | SVGEllipseElement | SVGCircleElement | SVGRectElement;
|
|
248
|
+
/** The shape attributes mapped to each supported SVG element type. */
|
|
165
249
|
type ShapeOps = LineAttr | PolyAttr | PolyAttr | EllipseAttr | CircleAttr | RectAttr | GlyphAttr;
|
|
250
|
+
/** A `TransformObject` with a required 3D origin. */
|
|
166
251
|
type TransformObjectValues = Partial<TransformObject> & {
|
|
167
252
|
origin: [number, number, number];
|
|
168
253
|
};
|
|
254
|
+
/** A 2D point with `x` and `y` coordinates. */
|
|
169
255
|
type Point = {
|
|
170
256
|
x: number;
|
|
171
257
|
y: number;
|
|
172
258
|
};
|
|
259
|
+
/** A 2D point as a tuple `[x, y]`. */
|
|
173
260
|
type PointTuple = [number, number];
|
|
261
|
+
/** A `Point` with a `t` parameter (a point on a curve at ratio `t`). */
|
|
174
262
|
type DerivedPoint = Point & {
|
|
175
263
|
t: number;
|
|
176
264
|
};
|
|
265
|
+
/** The six points of a quadratic Bezier curve (on-curve and off-curve control points). */
|
|
177
266
|
type QuadPoints = [Point, Point, Point, Point, Point, Point];
|
|
267
|
+
/** The eight points of a cubic Bezier curve (on-curve and off-curve control points). */
|
|
178
268
|
type CubicPoints = [Point, Point, Point, Point, Point, Point, Point, Point];
|
|
269
|
+
/** The six derived points of a quadratic Bezier curve, each with a `t` parameter. */
|
|
179
270
|
type DerivedQuadPoints = [DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint];
|
|
271
|
+
/** The eight derived points of a cubic Bezier curve, each with a `t` parameter. */
|
|
180
272
|
type DerivedCubicPoints = [DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint];
|
|
273
|
+
/** The six coordinates of a quadratic Bezier segment `[x1, y1, cx, cy, x, y]`. */
|
|
181
274
|
type QuadCoordinates = [number, number, number, number, number, number];
|
|
275
|
+
/** The eight coordinates of a cubic Bezier segment. */
|
|
182
276
|
type CubicCoordinates = [number, number, number, number, number, number, number, number];
|
|
277
|
+
/** A function that derives a point on a curve at a given `t` ratio. */
|
|
183
278
|
type DeriveCallback = (t: number) => Point;
|
|
279
|
+
/** A callback invoked for each segment while iterating over a `PathArray`. */
|
|
184
280
|
type IteratorCallback<T extends PathArray, K extends keyof T = number> = (segment: PathSegment & T[K], index: number, lastX: number, lastY: number) => PathSegment | T[K] | false | void | undefined;
|
|
281
|
+
/** The bounding box extremes `[minX, minY, maxX, maxY]`. */
|
|
185
282
|
type BBoxMaxima = [minX: number, minY: number, maxX: number, maxY: number];
|
|
283
|
+
/** An intersection point between two curves, including both `t` ratios. */
|
|
186
284
|
type IntersectionPoint = {
|
|
187
285
|
x: number;
|
|
188
286
|
y: number;
|
|
189
287
|
t1: number;
|
|
190
288
|
t2: number;
|
|
191
289
|
};
|
|
290
|
+
/** Options for equalizing two paths for morphing. */
|
|
192
291
|
interface EqualizationOptions {
|
|
193
292
|
/** @default "auto" */
|
|
194
293
|
mode?: "curve" | "auto";
|
|
@@ -200,85 +299,454 @@ interface EqualizationOptions {
|
|
|
200
299
|
}
|
|
201
300
|
//#endregion
|
|
202
301
|
//#region src/math/arcTools.d.ts
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
302
|
+
/**
|
|
303
|
+
* Returns the signed arc length of an ellipse segment from angle `0` up to
|
|
304
|
+
* the given `theta` angle, by integrating the curve speed
|
|
305
|
+
* `|sqrt(rx^2 * sin^2(phi) + ry^2 * cos^2(phi))|` over the `[0, theta]`
|
|
306
|
+
* interval with Gauss-Legendre quadrature.
|
|
307
|
+
*
|
|
308
|
+
* @param rx radius along X axis
|
|
309
|
+
* @param ry radius along Y axis
|
|
310
|
+
* @param theta the angle in radians
|
|
311
|
+
* @returns the signed arc length
|
|
312
|
+
*/
|
|
313
|
+
declare const arcLengthAtAngle: (rx: number, ry: number, theta: number) => number;
|
|
314
|
+
/**
|
|
315
|
+
* Returns the signed arc length of an ellipse segment between two angles.
|
|
316
|
+
* @param rx radius along X axis
|
|
317
|
+
* @param ry radius along Y axis
|
|
318
|
+
* @param from the start angle in radians
|
|
319
|
+
* @param to the end angle in radians
|
|
320
|
+
* @returns the signed arc length
|
|
321
|
+
*/
|
|
322
|
+
declare const arcLengthBetween: (rx: number, ry: number, from: number, to: number) => number;
|
|
323
|
+
/**
|
|
324
|
+
* Returns the Arc segment length.
|
|
325
|
+
* @param rx radius along X axis
|
|
326
|
+
* @param ry radius along Y axis
|
|
327
|
+
* @param theta the angle in radians
|
|
328
|
+
* @returns the arc length
|
|
329
|
+
*/
|
|
330
|
+
declare const arcLength: (rx: number, ry: number, theta: number) => number;
|
|
331
|
+
/**
|
|
332
|
+
* Find point on ellipse at given angle around ellipse (theta);
|
|
333
|
+
* @param cx the center X
|
|
334
|
+
* @param cy the center Y
|
|
335
|
+
* @param rx the radius X
|
|
336
|
+
* @param ry the radius Y
|
|
337
|
+
* @param alpha the arc rotation angle in radians
|
|
338
|
+
* @param theta the arc sweep angle in radians
|
|
339
|
+
* @returns a point around ellipse at given angle
|
|
340
|
+
*/
|
|
341
|
+
declare const arcPoint: (cx: number, cy: number, rx: number, ry: number, alpha: number, theta: number) => PointTuple;
|
|
342
|
+
/**
|
|
343
|
+
* Returns the angle between two points.
|
|
344
|
+
* @param v0 starting point
|
|
345
|
+
* @param v1 ending point
|
|
346
|
+
* @returns the angle in radian
|
|
347
|
+
*/
|
|
348
|
+
declare const angleBetween: (v0: Point, v1: Point) => number;
|
|
349
|
+
/**
|
|
350
|
+
* Returns the following properties for an Arc segment: center, start angle,
|
|
351
|
+
* end angle, and radiuses on X and Y axis.
|
|
352
|
+
*
|
|
353
|
+
* @param x1 the starting point X
|
|
354
|
+
* @param y1 the starting point Y
|
|
355
|
+
* @param RX the radius on X axis
|
|
356
|
+
* @param RY the radius on Y axis
|
|
357
|
+
* @param angle the ellipse rotation in degrees
|
|
358
|
+
* @param LAF the large arc flag
|
|
359
|
+
* @param SF the sweep flag
|
|
360
|
+
* @param x2 the ending point X
|
|
361
|
+
* @param y2 the ending point Y
|
|
362
|
+
* @returns properties specific to Arc segments
|
|
363
|
+
*/
|
|
364
|
+
declare const getArcProps: (x1: number, y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, x: number, y: number) => {
|
|
365
|
+
rx: number;
|
|
366
|
+
ry: number;
|
|
367
|
+
startAngle: number;
|
|
368
|
+
endAngle: number;
|
|
369
|
+
center: {
|
|
220
370
|
x: number;
|
|
221
371
|
y: number;
|
|
222
372
|
};
|
|
223
373
|
};
|
|
374
|
+
/**
|
|
375
|
+
* Returns the length of an Arc segment.
|
|
376
|
+
*
|
|
377
|
+
* @param x1 the starting point X
|
|
378
|
+
* @param y1 the starting point Y
|
|
379
|
+
* @param c1x the first control point X
|
|
380
|
+
* @param c1y the first control point Y
|
|
381
|
+
* @param c2x the second control point X
|
|
382
|
+
* @param c2y the second control point Y
|
|
383
|
+
* @param x2 the ending point X
|
|
384
|
+
* @param y2 the ending point Y
|
|
385
|
+
* @returns the length of the Arc segment
|
|
386
|
+
*/
|
|
387
|
+
declare const getArcLength: (x1: number, y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, x: number, y: number) => number;
|
|
388
|
+
/**
|
|
389
|
+
* Returns a point along an Arc segment at a given distance.
|
|
390
|
+
*
|
|
391
|
+
* @param x1 the starting point X
|
|
392
|
+
* @param y1 the starting point Y
|
|
393
|
+
* @param RX the radius on X axis
|
|
394
|
+
* @param RY the radius on Y axis
|
|
395
|
+
* @param angle the ellipse rotation in degrees
|
|
396
|
+
* @param LAF the large arc flag
|
|
397
|
+
* @param SF the sweep flag
|
|
398
|
+
* @param x2 the ending point X
|
|
399
|
+
* @param y2 the ending point Y
|
|
400
|
+
* @param distance the distance along the arc
|
|
401
|
+
* @returns a point along the Arc segment
|
|
402
|
+
*/
|
|
403
|
+
declare const getPointAtArcLength: (x1: number, y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, x: number, y: number, distance?: number) => {
|
|
404
|
+
x: number;
|
|
405
|
+
y: number;
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* Returns the extrema for an Arc segment in the following format:
|
|
409
|
+
* [MIN_X, MIN_Y, MAX_X, MAX_Y]
|
|
410
|
+
*
|
|
411
|
+
* @see https://github.com/herrstrietzel/svg-pathdata-getbbox
|
|
412
|
+
*
|
|
413
|
+
* @param x1 the starting point X
|
|
414
|
+
* @param y1 the starting point Y
|
|
415
|
+
* @param RX the radius on X axis
|
|
416
|
+
* @param RY the radius on Y axis
|
|
417
|
+
* @param angle the ellipse rotation in degrees
|
|
418
|
+
* @param LAF the large arc flag
|
|
419
|
+
* @param SF the sweep flag
|
|
420
|
+
* @param x2 the ending point X
|
|
421
|
+
* @param y2 the ending point Y
|
|
422
|
+
* @returns the extrema of the Arc segment
|
|
423
|
+
*/
|
|
424
|
+
declare const getArcBBox: (x1: number, y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, x: number, y: number) => [number, number, number, number];
|
|
425
|
+
/** The tools for elliptical arc computation. */
|
|
426
|
+
declare const arcTools: {
|
|
427
|
+
angleBetween: typeof angleBetween;
|
|
428
|
+
arcLength: typeof arcLength;
|
|
429
|
+
arcLengthAtAngle: typeof arcLengthAtAngle;
|
|
430
|
+
arcLengthBetween: typeof arcLengthBetween;
|
|
431
|
+
arcPoint: typeof arcPoint;
|
|
432
|
+
getArcBBox: typeof getArcBBox;
|
|
433
|
+
getArcLength: typeof getArcLength;
|
|
434
|
+
getArcProps: typeof getArcProps;
|
|
435
|
+
getPointAtArcLength: typeof getPointAtArcLength;
|
|
436
|
+
};
|
|
224
437
|
//#endregion
|
|
225
438
|
//#region src/math/bezier.d.ts
|
|
439
|
+
/**
|
|
440
|
+
* @param points
|
|
441
|
+
* @returns
|
|
442
|
+
*/
|
|
443
|
+
declare const deriveBezier: (points: QuadPoints | CubicPoints) => (DerivedQuadPoints | DerivedCubicPoints)[];
|
|
444
|
+
/**
|
|
445
|
+
* @param points
|
|
446
|
+
* @param t
|
|
447
|
+
*/
|
|
448
|
+
declare const computeBezier: (points: DerivedQuadPoints | DerivedCubicPoints, t: number) => DerivedPoint;
|
|
449
|
+
/**
|
|
450
|
+
* Calculates the speed (derivative magnitude) of a Bezier curve at parameter `t`.
|
|
451
|
+
*
|
|
452
|
+
* @param derivativeFn the curve derivative function
|
|
453
|
+
* @param t the sampled point ratio in `[0-1]`
|
|
454
|
+
* @returns the curve speed at parameter `t`
|
|
455
|
+
*/
|
|
456
|
+
declare const calculateBezier: (derivativeFn: DeriveCallback, t: number) => number;
|
|
457
|
+
/**
|
|
458
|
+
* Returns the total arc length of a Bezier segment.
|
|
459
|
+
*
|
|
460
|
+
* @param derivativeFn the curve derivative function
|
|
461
|
+
* @returns the total arc length
|
|
462
|
+
*/
|
|
463
|
+
declare const bezierLength: (derivativeFn: DeriveCallback) => number;
|
|
464
|
+
/**
|
|
465
|
+
* Returns the arc length of a Bezier segment from its start point
|
|
466
|
+
* up to a given `t` ratio, by integrating the curve speed `|B'(t)|`
|
|
467
|
+
* over the `[0, t]` interval with Gauss-Legendre quadrature.
|
|
468
|
+
*
|
|
469
|
+
* @param derivativeFn the curve derivative function
|
|
470
|
+
* @param t the sampled point ratio in `[0-1]`
|
|
471
|
+
* @returns the arc length up to parameter `t`
|
|
472
|
+
*/
|
|
473
|
+
declare const bezierLengthAtT: (derivativeFn: DeriveCallback, t: number) => number;
|
|
474
|
+
/**
|
|
475
|
+
* Builds the Bezier points array from a curve coordinates array.
|
|
476
|
+
* @param curve cubic / quad bezier segment
|
|
477
|
+
*/
|
|
478
|
+
declare const getBezierPoints: (curve: CubicCoordinates | QuadCoordinates) => CubicPoints | QuadPoints;
|
|
479
|
+
/**
|
|
480
|
+
* Returns the arc length of a Bezier segment from its start point
|
|
481
|
+
* up to a given `t` ratio, for the segment given by its coordinates.
|
|
482
|
+
*
|
|
483
|
+
* @param curve cubic / quad bezier segment
|
|
484
|
+
* @param t the sampled point ratio in `[0-1]`
|
|
485
|
+
* @returns the arc length up to parameter `t`
|
|
486
|
+
*/
|
|
487
|
+
declare const getBezierLengthAtT: (curve: CubicCoordinates | QuadCoordinates, t: number) => number;
|
|
488
|
+
/**
|
|
489
|
+
* Returns the `t` parameter of a Bezier segment at which the cumulative
|
|
490
|
+
* arc length equals the given `distance`, found by interval bisection.
|
|
491
|
+
*
|
|
492
|
+
* @param curve cubic / quad bezier segment
|
|
493
|
+
* @param distance the distance along the segment in `[0, length]`
|
|
494
|
+
* @returns the `t` parameter in `[0-1]`
|
|
495
|
+
*/
|
|
496
|
+
declare const getTAtBezierLength: (curve: CubicCoordinates | QuadCoordinates, distance: number) => number;
|
|
497
|
+
/**
|
|
498
|
+
* Returns the length of CubicBezier / Quad segment.
|
|
499
|
+
* @param curve cubic / quad bezier segment
|
|
500
|
+
*/
|
|
501
|
+
declare const getBezierLength: (curve: CubicCoordinates | QuadCoordinates) => number;
|
|
502
|
+
/**
|
|
503
|
+
* Returns the most extreme points in a Quad Bezier segment.
|
|
504
|
+
* @param A an array which consist of X/Y values
|
|
505
|
+
*/
|
|
506
|
+
declare const minmaxQ: ([v1, cp, v2]: [number, number, number]) => PointTuple;
|
|
507
|
+
/**
|
|
508
|
+
* Returns the most extreme points in a Cubic Bezier segment.
|
|
509
|
+
* @param A an array which consist of X/Y values
|
|
510
|
+
* @see https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L127
|
|
511
|
+
*/
|
|
512
|
+
declare const minmaxC: ([v1, cp1, cp2, v2]: [number, number, number, number]) => PointTuple;
|
|
513
|
+
/** The tools for Bezier curve computation. */
|
|
226
514
|
declare const bezierTools: {
|
|
227
|
-
bezierLength:
|
|
228
|
-
|
|
515
|
+
bezierLength: typeof bezierLength;
|
|
516
|
+
bezierLengthAtT: typeof bezierLengthAtT;
|
|
517
|
+
calculateBezier: typeof calculateBezier;
|
|
229
518
|
CBEZIER_MINMAX_EPSILON: number;
|
|
230
|
-
computeBezier:
|
|
519
|
+
computeBezier: typeof computeBezier;
|
|
231
520
|
Cvalues: number[];
|
|
232
|
-
deriveBezier:
|
|
233
|
-
getBezierLength:
|
|
234
|
-
|
|
235
|
-
|
|
521
|
+
deriveBezier: typeof deriveBezier;
|
|
522
|
+
getBezierLength: typeof getBezierLength;
|
|
523
|
+
getBezierLengthAtT: typeof getBezierLengthAtT;
|
|
524
|
+
getBezierPoints: typeof getBezierPoints;
|
|
525
|
+
getTAtBezierLength: typeof getTAtBezierLength;
|
|
526
|
+
minmaxC: typeof minmaxC;
|
|
527
|
+
minmaxQ: typeof minmaxQ;
|
|
236
528
|
Tvalues: number[];
|
|
237
529
|
};
|
|
238
530
|
//#endregion
|
|
239
531
|
//#region src/math/cubicTools.d.ts
|
|
532
|
+
/**
|
|
533
|
+
* Returns a point at a given length of a CubicBezier segment.
|
|
534
|
+
*
|
|
535
|
+
* @param x1 the starting point X
|
|
536
|
+
* @param y1 the starting point Y
|
|
537
|
+
* @param c1x the first control point X
|
|
538
|
+
* @param c1y the first control point Y
|
|
539
|
+
* @param c2x the second control point X
|
|
540
|
+
* @param c2y the second control point Y
|
|
541
|
+
* @param x2 the ending point X
|
|
542
|
+
* @param y2 the ending point Y
|
|
543
|
+
* @param t a [0-1] ratio
|
|
544
|
+
* @returns the point at cubic-bezier segment length
|
|
545
|
+
*/
|
|
546
|
+
declare const getPointAtCubicSegmentLength: ([x1, y1, c1x, c1y, c2x, c2y, x2, y2]: CubicCoordinates, t: number) => {
|
|
547
|
+
x: number;
|
|
548
|
+
y: number;
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* Returns the length of a CubicBezier segment.
|
|
552
|
+
*
|
|
553
|
+
* @param x1 the starting point X
|
|
554
|
+
* @param y1 the starting point Y
|
|
555
|
+
* @param c1x the first control point X
|
|
556
|
+
* @param c1y the first control point Y
|
|
557
|
+
* @param c2x the second control point X
|
|
558
|
+
* @param c2y the second control point Y
|
|
559
|
+
* @param x2 the ending point X
|
|
560
|
+
* @param y2 the ending point Y
|
|
561
|
+
* @returns the CubicBezier segment length
|
|
562
|
+
*/
|
|
563
|
+
declare const getCubicLength: (x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number) => number;
|
|
564
|
+
/**
|
|
565
|
+
* Returns the point along a CubicBezier segment at a given distance.
|
|
566
|
+
*
|
|
567
|
+
* @param x1 the starting point X
|
|
568
|
+
* @param y1 the starting point Y
|
|
569
|
+
* @param c1x the first control point X
|
|
570
|
+
* @param c1y the first control point Y
|
|
571
|
+
* @param c2x the second control point X
|
|
572
|
+
* @param c2y the second control point Y
|
|
573
|
+
* @param x2 the ending point X
|
|
574
|
+
* @param y2 the ending point Y
|
|
575
|
+
* @param distance the distance to look at
|
|
576
|
+
* @returns the point at CubicBezier length
|
|
577
|
+
*/
|
|
578
|
+
declare const getPointAtCubicLength: (x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number, distance?: number) => {
|
|
579
|
+
x: number;
|
|
580
|
+
y: number;
|
|
581
|
+
};
|
|
582
|
+
/**
|
|
583
|
+
* Returns the bounding box of a CubicBezier segment in the following format:
|
|
584
|
+
* [MIN_X, MIN_Y, MAX_X, MAX_Y]
|
|
585
|
+
*
|
|
586
|
+
* @param x1 the starting point X
|
|
587
|
+
* @param y1 the starting point Y
|
|
588
|
+
* @param c1x the first control point X
|
|
589
|
+
* @param c1y the first control point Y
|
|
590
|
+
* @param c2x the second control point X
|
|
591
|
+
* @param c2y the second control point Y
|
|
592
|
+
* @param x2 the ending point X
|
|
593
|
+
* @param y2 the ending point Y
|
|
594
|
+
* @returns the extrema of the CubicBezier segment
|
|
595
|
+
*/
|
|
596
|
+
declare const getCubicBBox: (x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number) => BBoxMaxima;
|
|
597
|
+
/** The tools for cubic Bezier computation. */
|
|
240
598
|
declare const cubicTools: {
|
|
241
|
-
getCubicBBox:
|
|
242
|
-
getCubicLength:
|
|
243
|
-
getPointAtCubicLength:
|
|
244
|
-
|
|
245
|
-
y: number;
|
|
246
|
-
};
|
|
247
|
-
getPointAtCubicSegmentLength: ([x1, y1, c1x, c1y, c2x, c2y, x2, y2]: CubicCoordinates, t: number) => {
|
|
248
|
-
x: number;
|
|
249
|
-
y: number;
|
|
250
|
-
};
|
|
599
|
+
getCubicBBox: typeof getCubicBBox;
|
|
600
|
+
getCubicLength: typeof getCubicLength;
|
|
601
|
+
getPointAtCubicLength: typeof getPointAtCubicLength;
|
|
602
|
+
getPointAtCubicSegmentLength: typeof getPointAtCubicSegmentLength;
|
|
251
603
|
};
|
|
252
604
|
//#endregion
|
|
253
605
|
//#region src/math/lineTools.d.ts
|
|
606
|
+
/**
|
|
607
|
+
* Returns length for line segments (MoveTo, LineTo).
|
|
608
|
+
*
|
|
609
|
+
* @param x1 the starting point X
|
|
610
|
+
* @param y1 the starting point Y
|
|
611
|
+
* @param x2 the ending point X
|
|
612
|
+
* @param y2 the ending point Y
|
|
613
|
+
* @returns the line segment length
|
|
614
|
+
*/
|
|
615
|
+
declare const getLineLength: (x1: number, y1: number, x2: number, y2: number) => number;
|
|
616
|
+
/**
|
|
617
|
+
* Returns a point along the line segments (MoveTo, LineTo).
|
|
618
|
+
*
|
|
619
|
+
* @param x1 the starting point X
|
|
620
|
+
* @param y1 the starting point Y
|
|
621
|
+
* @param x2 the ending point X
|
|
622
|
+
* @param y2 the ending point Y
|
|
623
|
+
* @param distance the distance to point in [0-1] range
|
|
624
|
+
* @returns the point at length
|
|
625
|
+
*/
|
|
626
|
+
declare const getPointAtLineLength: (x1: number, y1: number, x2: number, y2: number, distance?: number) => {
|
|
627
|
+
x: number;
|
|
628
|
+
y: number;
|
|
629
|
+
};
|
|
630
|
+
/**
|
|
631
|
+
* Returns bounding box for line segments (MoveTo, LineTo).
|
|
632
|
+
*
|
|
633
|
+
* @param x1 the starting point X
|
|
634
|
+
* @param y1 the starting point Y
|
|
635
|
+
* @param x2 the ending point X
|
|
636
|
+
* @param y2 the ending point Y
|
|
637
|
+
* @returns the bounding box for line segments
|
|
638
|
+
*/
|
|
639
|
+
declare const getLineBBox: (x1: number, y1: number, x2: number, y2: number) => [number, number, number, number];
|
|
640
|
+
/** The tools for line segment computation. */
|
|
254
641
|
declare const lineTools: {
|
|
255
|
-
getLineBBox:
|
|
256
|
-
getLineLength:
|
|
257
|
-
getPointAtLineLength:
|
|
258
|
-
x: number;
|
|
259
|
-
y: number;
|
|
260
|
-
};
|
|
642
|
+
getLineBBox: typeof getLineBBox;
|
|
643
|
+
getLineLength: typeof getLineLength;
|
|
644
|
+
getPointAtLineLength: typeof getPointAtLineLength;
|
|
261
645
|
};
|
|
262
646
|
//#endregion
|
|
263
647
|
//#region src/math/quadTools.d.ts
|
|
648
|
+
/**
|
|
649
|
+
* Returns the {x,y} coordinates of a point at a
|
|
650
|
+
* given length of a quadratic-bezier segment.
|
|
651
|
+
*
|
|
652
|
+
* @see https://github.com/substack/point-at-length
|
|
653
|
+
*
|
|
654
|
+
* @param x1 the starting point X
|
|
655
|
+
* @param y1 the starting point Y
|
|
656
|
+
* @param cx the control point X
|
|
657
|
+
* @param cy the control point Y
|
|
658
|
+
* @param x2 the ending point X
|
|
659
|
+
* @param y2 the ending point Y
|
|
660
|
+
* @param t a [0-1] ratio
|
|
661
|
+
* @returns the requested {x,y} coordinates
|
|
662
|
+
*/
|
|
663
|
+
declare const getPointAtQuadSegmentLength: ([x1, y1, cx, cy, x2, y2]: QuadCoordinates, t: number) => {
|
|
664
|
+
x: number;
|
|
665
|
+
y: number;
|
|
666
|
+
};
|
|
667
|
+
/**
|
|
668
|
+
* Returns the length of a QuadraticBezier segment.
|
|
669
|
+
*
|
|
670
|
+
* @param x1 the starting point X
|
|
671
|
+
* @param y1 the starting point Y
|
|
672
|
+
* @param cx the control point X
|
|
673
|
+
* @param cy the control point Y
|
|
674
|
+
* @param x2 the ending point X
|
|
675
|
+
* @param y2 the ending point Y
|
|
676
|
+
* @returns the QuadraticBezier segment length
|
|
677
|
+
*/
|
|
678
|
+
declare const getQuadLength: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => number;
|
|
679
|
+
/**
|
|
680
|
+
* Returns the point along a QuadraticBezier segment at a given distance.
|
|
681
|
+
*
|
|
682
|
+
* @param x1 the starting point X
|
|
683
|
+
* @param y1 the starting point Y
|
|
684
|
+
* @param cx the control point X
|
|
685
|
+
* @param cy the control point Y
|
|
686
|
+
* @param x2 the ending point X
|
|
687
|
+
* @param y2 the ending point Y
|
|
688
|
+
* @param distance the distance to look at
|
|
689
|
+
* @returns the point at QuadraticBezier length
|
|
690
|
+
*/
|
|
691
|
+
declare const getPointAtQuadLength: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number, distance?: number) => {
|
|
692
|
+
x: number;
|
|
693
|
+
y: number;
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* Returns the bounding box of a QuadraticBezier segment in the following format:
|
|
697
|
+
* [MIN_X, MIN_Y, MAX_X, MAX_Y]
|
|
698
|
+
*
|
|
699
|
+
* @param x1 the starting point X
|
|
700
|
+
* @param y1 the starting point Y
|
|
701
|
+
* @param cx the control point X
|
|
702
|
+
* @param cy the control point Y
|
|
703
|
+
* @param x2 the ending point X
|
|
704
|
+
* @param y2 the ending point Y
|
|
705
|
+
* @returns the extrema of the QuadraticBezier segment
|
|
706
|
+
*/
|
|
707
|
+
declare const getQuadBBox: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => [number, number, number, number];
|
|
708
|
+
/** The tools for quadratic Bezier computation. */
|
|
264
709
|
declare const quadTools: {
|
|
265
|
-
getPointAtQuadLength:
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
getPointAtQuadSegmentLength: ([x1, y1, cx, cy, x2, y2]: QuadCoordinates, t: number) => {
|
|
270
|
-
x: number;
|
|
271
|
-
y: number;
|
|
272
|
-
};
|
|
273
|
-
getQuadBBox: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => [number, number, number, number];
|
|
274
|
-
getQuadLength: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => number;
|
|
710
|
+
getPointAtQuadLength: typeof getPointAtQuadLength;
|
|
711
|
+
getPointAtQuadSegmentLength: typeof getPointAtQuadSegmentLength;
|
|
712
|
+
getQuadBBox: typeof getQuadBBox;
|
|
713
|
+
getQuadLength: typeof getQuadLength;
|
|
275
714
|
};
|
|
276
715
|
//#endregion
|
|
277
716
|
//#region src/math/polygonTools.d.ts
|
|
717
|
+
/**
|
|
718
|
+
* d3-polygon-area
|
|
719
|
+
* @see https://github.com/d3/d3-polygon
|
|
720
|
+
*
|
|
721
|
+
* Returns the area of a polygon.
|
|
722
|
+
*
|
|
723
|
+
* @param polygon Array of [x, y]
|
|
724
|
+
* @returns Signed area
|
|
725
|
+
*/
|
|
726
|
+
declare const polygonArea: (polygon: PointTuple[]) => number;
|
|
727
|
+
/**
|
|
728
|
+
* d3-polygon-length
|
|
729
|
+
* https://github.com/d3/d3-polygon
|
|
730
|
+
*
|
|
731
|
+
* Returns the perimeter of a polygon.
|
|
732
|
+
*
|
|
733
|
+
* @param polygon an array of coordinates
|
|
734
|
+
* @returns the polygon length
|
|
735
|
+
*/
|
|
736
|
+
declare const polygonLength: (polygon: PointTuple[]) => number;
|
|
737
|
+
/**
|
|
738
|
+
* Computes the centroid (geometric center) of a polygon.
|
|
739
|
+
* Uses average of all endpoint coordinates (robust for polygons and curves).
|
|
740
|
+
*
|
|
741
|
+
* @param polygon A polygon with consists of [x, y] tuples
|
|
742
|
+
* @returns [x, y] centroid
|
|
743
|
+
*/
|
|
744
|
+
declare const polygonCentroid: (polygon: PointTuple[]) => PointTuple;
|
|
745
|
+
/** The tools for polygon computation. */
|
|
278
746
|
declare const polygonTools: {
|
|
279
|
-
polygonArea:
|
|
280
|
-
polygonLength:
|
|
281
|
-
polygonCentroid:
|
|
747
|
+
polygonArea: typeof polygonArea;
|
|
748
|
+
polygonLength: typeof polygonLength;
|
|
749
|
+
polygonCentroid: typeof polygonCentroid;
|
|
282
750
|
};
|
|
283
751
|
//#endregion
|
|
284
752
|
//#region src/math/distanceSquareRoot.d.ts
|
|
@@ -401,7 +869,6 @@ declare const pathToString: <T extends PathArray>(path: T, roundOption?: number
|
|
|
401
869
|
*
|
|
402
870
|
* If parameter value is already a `PathArray`,
|
|
403
871
|
* return a clone of it.
|
|
404
|
-
|
|
405
872
|
* @example
|
|
406
873
|
* parsePathString("M 0 0L50 50")
|
|
407
874
|
* // => [["M",0,0],["L",50,50]]
|
|
@@ -644,7 +1111,7 @@ declare const getDrawDirection: (path: string | PathArray) => boolean;
|
|
|
644
1111
|
* // => -10000 (counter-clockwise square)
|
|
645
1112
|
* ```
|
|
646
1113
|
*/
|
|
647
|
-
declare const getPathArea: <T extends PathArray>(path: T) => number;
|
|
1114
|
+
declare const getPathArea: <T extends PathArray | string>(path: T) => number;
|
|
648
1115
|
//#endregion
|
|
649
1116
|
//#region src/util/getPointAtLength.d.ts
|
|
650
1117
|
/**
|
|
@@ -884,7 +1351,7 @@ declare const shapeToPathArray: (element: ShapeTypes | ShapeOps) => false | Path
|
|
|
884
1351
|
* // => [['M', 10, 90], ['C', 30, 90, 25, 10, 50, 10], ['C', 75, 10, 70, 90, 90, 90]]
|
|
885
1352
|
* ```
|
|
886
1353
|
*/
|
|
887
|
-
declare const normalizePath:
|
|
1354
|
+
declare const normalizePath: <T extends string | PathArray>(pathInput: T) => NormalArray;
|
|
888
1355
|
//#endregion
|
|
889
1356
|
//#region src/process/optimizePath.d.ts
|
|
890
1357
|
/**
|
|
@@ -902,7 +1369,7 @@ declare const normalizePath: (pathInput: string | PathArray) => NormalArray;
|
|
|
902
1369
|
* // => [['M', 10, 10], ['l', 0, 0], ['l', 80, 80]]
|
|
903
1370
|
* ```
|
|
904
1371
|
*/
|
|
905
|
-
declare const optimizePath: <T extends PathArray>(pathInput: T, roundOption?: number) => PathArray;
|
|
1372
|
+
declare const optimizePath: <T extends string | PathArray>(pathInput: T, roundOption?: number) => PathArray;
|
|
906
1373
|
//#endregion
|
|
907
1374
|
//#region src/process/reversePath.d.ts
|
|
908
1375
|
/**
|