modern-path2d 0.0.2 → 0.0.4

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/dist/index.cjs CHANGED
@@ -5,6 +5,12 @@ class Point2D {
5
5
  this.x = x;
6
6
  this.y = y;
7
7
  }
8
+ static get MAX() {
9
+ return new Point2D(Infinity, Infinity);
10
+ }
11
+ static get MIN() {
12
+ return new Point2D(-Infinity, -Infinity);
13
+ }
8
14
  set(x, y) {
9
15
  this.x = x;
10
16
  this.y = y;
@@ -77,6 +83,9 @@ class Curve {
77
83
  __publicField$5(this, "_cacheArcLengths");
78
84
  __publicField$5(this, "_needsUpdate", false);
79
85
  }
86
+ getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
87
+ return { min, max };
88
+ }
80
89
  getDivisions(divisions) {
81
90
  return divisions;
82
91
  }
@@ -172,6 +181,26 @@ class Curve {
172
181
  getTangentAt(u, output = new Point2D()) {
173
182
  return this.getTangent(this.getUtoTmapping(u), output);
174
183
  }
184
+ getData() {
185
+ return this.getCommands().map((cmd) => {
186
+ switch (cmd.type) {
187
+ case "M":
188
+ return `M ${cmd.x} ${cmd.y}`;
189
+ case "L":
190
+ return `L ${cmd.x} ${cmd.y}`;
191
+ case "C":
192
+ return `C ${cmd.x1} ${cmd.y1} ${cmd.x2} ${cmd.y2} ${cmd.x} ${cmd.y}`;
193
+ case "Q":
194
+ return `Q ${cmd.x1} ${cmd.y1} ${cmd.x} ${cmd.y}`;
195
+ case "A":
196
+ return `A ${cmd.rx} ${cmd.ry} ${cmd.xAxisRotation} ${cmd.largeArcFlag} ${cmd.sweepFlag} ${cmd.x} ${cmd.y}`;
197
+ case "Z":
198
+ return "Z";
199
+ default:
200
+ return "";
201
+ }
202
+ }).join(" ");
203
+ }
175
204
  clone() {
176
205
  return new this.constructor().copy(this);
177
206
  }
@@ -189,26 +218,27 @@ class CircleCurve extends Curve {
189
218
  this.start = start;
190
219
  this.end = end;
191
220
  }
192
- getPole(min, max) {
221
+ getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
193
222
  min.x = Math.min(min.x, this.center.x - this.radius);
194
223
  min.y = Math.min(min.y, this.center.y - this.radius);
195
224
  max.x = Math.max(max.x, this.center.x + this.radius);
196
225
  max.y = Math.max(max.y, this.center.y + this.radius);
226
+ return { min, max };
197
227
  }
198
- getPoint(index) {
228
+ getPoint(t) {
199
229
  const { radius, center } = this;
200
- return center.clone().add(this.getNormal(index).clone().multiplyScalar(radius));
230
+ return center.clone().add(this.getNormal(t).clone().multiplyScalar(radius));
201
231
  }
202
- getTangent(index) {
203
- const { x, y } = this.getNormal(index);
232
+ getTangent(t) {
233
+ const { x, y } = this.getNormal(t);
204
234
  return new Point2D(-y, x);
205
235
  }
206
- getNormal(index) {
236
+ getNormal(t) {
207
237
  const { start, end } = this;
208
- const t = index * (end - start) + start - 0.5 * Math.PI;
209
- return new Point2D(Math.cos(t), Math.sin(t));
238
+ const _t = t * (end - start) + start - 0.5 * Math.PI;
239
+ return new Point2D(Math.cos(_t), Math.sin(_t));
210
240
  }
211
- toPathCommands() {
241
+ getCommands() {
212
242
  return [];
213
243
  }
214
244
  drawTo(_ctx) {
@@ -269,8 +299,20 @@ class CubicBezierCurve extends Curve {
269
299
  );
270
300
  return output;
271
301
  }
272
- toPathCommands() {
273
- return [];
302
+ getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
303
+ const { v0, v1, v2, v3 } = this;
304
+ min.x = Math.min(min.x, v0.x, v1.x, v2.x, v3.x);
305
+ min.y = Math.min(min.y, v0.y, v1.y, v2.y, v3.y);
306
+ max.x = Math.max(max.x, v0.x, v1.x, v2.x, v3.x);
307
+ max.y = Math.max(max.y, v0.y, v1.y, v2.y, v3.y);
308
+ return { min, max };
309
+ }
310
+ getCommands() {
311
+ const { v0, v1, v2, v3 } = this;
312
+ return [
313
+ { type: "M", x: v0.x, y: v0.y },
314
+ { type: "C", x1: v1.x, y1: v1.y, x2: v2.x, y2: v2.y, x: v3.x, y: v3.y }
315
+ ];
274
316
  }
275
317
  drawTo(ctx) {
276
318
  const { v0, v1, v2, v3 } = this;
@@ -337,18 +379,30 @@ class EllipseCurve extends Curve {
337
379
  }
338
380
  return output.set(_x, _y);
339
381
  }
340
- toPathCommands() {
382
+ getCommands() {
341
383
  const { x, y, rx, ry, startAngle, endAngle, clockwise } = this;
384
+ const anticlockwise = !clockwise;
342
385
  const startX = x + rx * Math.cos(startAngle);
343
386
  const startY = y + ry * Math.sin(startAngle);
344
387
  const endX = x + rx * Math.cos(endAngle);
345
388
  const endY = y + ry * Math.sin(endAngle);
346
- const largeArcFlag = (endAngle - startAngle) % (2 * Math.PI) > Math.PI ? 1 : 0;
347
- const sweepFlag = clockwise ? 0 : 1;
348
- return [
349
- { type: "M", x: startX, y: startY },
350
- { type: "A", rx, ry, xAxisRotation: 0, largeArcFlag, sweepFlag, x: endX, y: endY }
351
- ];
389
+ const angleDiff = Math.abs(startAngle - endAngle);
390
+ const largeArcFlag = angleDiff > Math.PI ? 1 : 0;
391
+ const sweepFlag = anticlockwise ? 0 : 1;
392
+ const midX = x + rx * Math.cos(startAngle + (endAngle - startAngle) / 2);
393
+ const midY = y + ry * Math.sin(startAngle + (endAngle - startAngle) / 2);
394
+ if (angleDiff >= 2 * Math.PI) {
395
+ return [
396
+ { type: "M", x: startX, y: startY },
397
+ { type: "A", rx, ry, xAxisRotation: 0, largeArcFlag: 1, sweepFlag, x: midX, y: midY },
398
+ { type: "A", rx, ry, xAxisRotation: 0, largeArcFlag: 1, sweepFlag, x: startX, y: startY }
399
+ ];
400
+ } else {
401
+ return [
402
+ { type: "M", x: startX, y: startY },
403
+ { type: "A", rx, ry, xAxisRotation: 0, largeArcFlag, sweepFlag, x: endX, y: endY }
404
+ ];
405
+ }
352
406
  }
353
407
  drawTo(ctx) {
354
408
  const { x, y, rx, ry, startAngle } = this;
@@ -405,12 +459,21 @@ class LineCurve extends Curve {
405
459
  getTangentAt(u, output = new Point2D()) {
406
460
  return this.getTangent(u, output);
407
461
  }
408
- toPathCommands() {
462
+ getCommands() {
463
+ const { v1, v2 } = this;
409
464
  return [
410
- { type: "M", x: this.v1.x, y: this.v1.y },
411
- { type: "L", x: this.v2.x, y: this.v2.y }
465
+ { type: "M", x: v1.x, y: v1.y },
466
+ { type: "L", x: v2.x, y: v2.y }
412
467
  ];
413
468
  }
469
+ getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
470
+ const { v1, v2 } = this;
471
+ min.x = Math.min(min.x, v1.x, v2.x);
472
+ min.y = Math.min(min.y, v1.y, v2.y);
473
+ max.x = Math.max(max.x, v1.x, v2.x);
474
+ max.y = Math.max(max.y, v1.y, v2.y);
475
+ return { min, max };
476
+ }
414
477
  drawTo(ctx) {
415
478
  const { v1, v2 } = this;
416
479
  ctx.moveTo(v1.x, v1.y);
@@ -492,8 +555,8 @@ class HeartCurve extends Curve {
492
555
  const line = this.getCurrentLine(value);
493
556
  return new Point2D(line.v2.y - line.v1.y, -(line.v2.x - line.v1.x)).normalize();
494
557
  }
495
- toPathCommands() {
496
- return this.curves.flatMap((curve) => curve.toPathCommands());
558
+ getCommands() {
559
+ return this.curves.flatMap((curve) => curve.getCommands());
497
560
  }
498
561
  drawTo(ctx) {
499
562
  this.curves.forEach((curve) => curve.drawTo(ctx));
@@ -550,8 +613,12 @@ class PloygonCurve extends Curve {
550
613
  const line = this.getCurrentLine(value);
551
614
  return new Point2D(line.v2.y - line.v1.y, -(line.v2.x - line.v1.x)).normalize();
552
615
  }
553
- toPathCommands() {
554
- return this.curves.flatMap((curve) => curve.toPathCommands());
616
+ getCommands() {
617
+ return this.curves.flatMap((curve) => curve.getCommands());
618
+ }
619
+ getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
620
+ this.curves.forEach((curve) => curve.getMinMax(min, max));
621
+ return { min, max };
555
622
  }
556
623
  drawTo(ctx) {
557
624
  this.curves.forEach((curve) => curve.drawTo(ctx));
@@ -573,8 +640,24 @@ class QuadraticBezierCurve extends Curve {
573
640
  );
574
641
  return output;
575
642
  }
576
- toPathCommands() {
577
- return [];
643
+ getCommands() {
644
+ const { v0, v1, v2 } = this;
645
+ return [
646
+ { type: "M", x: v0.x, y: v0.y },
647
+ { type: "Q", x1: v1.x, y1: v1.y, x: v2.x, y: v2.y }
648
+ ];
649
+ }
650
+ getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
651
+ const { v0, v1, v2 } = this;
652
+ const x1 = 0.5 * (v0.x + v1.x);
653
+ const y1 = 0.5 * (v0.y + v1.y);
654
+ const x2 = 0.5 * (v0.x + v2.x);
655
+ const y2 = 0.5 * (v0.y + v2.y);
656
+ min.x = Math.min(min.x, v0.x, v2.x, x1, x2);
657
+ min.y = Math.min(min.y, v0.y, v2.y, y1, y2);
658
+ max.x = Math.max(max.x, v0.x, v2.x, x1, x2);
659
+ max.y = Math.max(max.y, v0.y, v2.y, y1, y2);
660
+ return { min, max };
578
661
  }
579
662
  drawTo(ctx) {
580
663
  const { v0, v1, v2 } = this;
@@ -664,8 +747,12 @@ class RectangularCurve extends Curve {
664
747
  const { v1, v2 } = this.getCurrentLine(value);
665
748
  return new Point2D(v2.y - v1.y, -(v2.x - v1.x)).normalize();
666
749
  }
667
- toPathCommands() {
668
- return this.curves.flatMap((curve) => curve.toPathCommands());
750
+ getCommands() {
751
+ return this.curves.flatMap((curve) => curve.getCommands());
752
+ }
753
+ getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
754
+ this.curves.forEach((curve) => curve.getMinMax(min, max));
755
+ return { min, max };
669
756
  }
670
757
  drawTo(ctx) {
671
758
  this.curves.forEach((curve) => curve.drawTo(ctx));
@@ -695,7 +782,7 @@ class SplineCurve extends Curve {
695
782
  );
696
783
  return output;
697
784
  }
698
- toPathCommands() {
785
+ getCommands() {
699
786
  return [];
700
787
  }
701
788
  drawTo(_ctx) {
@@ -703,9 +790,8 @@ class SplineCurve extends Curve {
703
790
  copy(source) {
704
791
  super.copy(source);
705
792
  this.points = [];
706
- for (let i = 0, l = source.points.length; i < l; i++) {
707
- const point = source.points[i];
708
- this.points.push(point.clone());
793
+ for (let i = 0, len = source.points.length; i < len; i++) {
794
+ this.points.push(source.points[i].clone());
709
795
  }
710
796
  return this;
711
797
  }
@@ -889,8 +975,12 @@ class CurvePath extends Curve {
889
975
  this.currentPoint.copy(curve.getPoint(1));
890
976
  return this;
891
977
  }
892
- toPathCommands() {
893
- return this.curves.flatMap((curve) => curve.toPathCommands());
978
+ getCommands() {
979
+ return this.curves.flatMap((curve) => curve.getCommands());
980
+ }
981
+ getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
982
+ this.curves.forEach((curve) => curve.getMinMax(min, max));
983
+ return { min, max };
894
984
  }
895
985
  drawTo(ctx) {
896
986
  this.curves.forEach((curve) => curve.drawTo(ctx));
@@ -919,16 +1009,12 @@ class Path2D {
919
1009
  __publicField(this, "currentPath", new CurvePath());
920
1010
  __publicField(this, "paths", [this.currentPath]);
921
1011
  }
922
- arc(x, y, radius, startAngle, endAngle, counterclockwise) {
923
- this.currentPath.absarc(x, y, radius, startAngle, endAngle, !counterclockwise);
924
- return this;
925
- }
926
- bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
927
- this.currentPath.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1012
+ addPath(path) {
1013
+ this.paths.push(...path.paths.map((v) => v.clone()));
928
1014
  return this;
929
1015
  }
930
- lineTo(x, y) {
931
- this.currentPath.lineTo(x, y);
1016
+ closePath() {
1017
+ this.currentPath.closePath();
932
1018
  return this;
933
1019
  }
934
1020
  moveTo(x, y) {
@@ -937,10 +1023,56 @@ class Path2D {
937
1023
  this.currentPath.moveTo(x, y);
938
1024
  return this;
939
1025
  }
1026
+ lineTo(x, y) {
1027
+ this.currentPath.lineTo(x, y);
1028
+ return this;
1029
+ }
1030
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
1031
+ this.currentPath.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1032
+ return this;
1033
+ }
940
1034
  quadraticCurveTo(cpx, cpy, x, y) {
941
1035
  this.currentPath.quadraticCurveTo(cpx, cpy, x, y);
942
1036
  return this;
943
1037
  }
1038
+ arc(x, y, radius, startAngle, endAngle, counterclockwise) {
1039
+ this.currentPath.absarc(x, y, radius, startAngle, endAngle, !counterclockwise);
1040
+ return this;
1041
+ }
1042
+ arcTo(x1, y1, x2, y2, radius) {
1043
+ const point = this.currentPath.currentPoint;
1044
+ const currentX = point.x;
1045
+ const currentY = point.y;
1046
+ const dx1 = x1 - currentX;
1047
+ const dy1 = y1 - currentY;
1048
+ const dx2 = x2 - x1;
1049
+ const dy2 = y2 - y1;
1050
+ const len1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
1051
+ const len2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
1052
+ if (len1 < radius || len2 < radius) {
1053
+ this.lineTo(x2, y2);
1054
+ return this;
1055
+ }
1056
+ const unitV1 = { x: dx1 / len1, y: dy1 / len1 };
1057
+ const unitV2 = { x: dx2 / len2, y: dy2 / len2 };
1058
+ const centerX = x1 - unitV1.y * radius;
1059
+ const centerY = y1 + unitV1.x * radius;
1060
+ const startAngle = Math.atan2(unitV1.y, unitV1.x);
1061
+ const endAngle = Math.atan2(unitV2.y, unitV2.x);
1062
+ let angleDiff = endAngle - startAngle;
1063
+ if (angleDiff > Math.PI) {
1064
+ angleDiff -= 2 * Math.PI;
1065
+ } else if (angleDiff < -Math.PI) {
1066
+ angleDiff += 2 * Math.PI;
1067
+ }
1068
+ this.arc(centerX, centerY, radius, startAngle, startAngle + angleDiff, false);
1069
+ this.lineTo(x2, y2);
1070
+ return this;
1071
+ }
1072
+ ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
1073
+ this.currentPath.absellipse(x, y, radiusX, radiusY, startAngle, endAngle, !counterclockwise, rotation);
1074
+ return this;
1075
+ }
944
1076
  rect(x, y, w, h) {
945
1077
  this.currentPath.rect(x, y, w, h);
946
1078
  return this;
@@ -949,8 +1081,33 @@ class Path2D {
949
1081
  this.currentPath.splineThru(points);
950
1082
  return this;
951
1083
  }
952
- toPathCommands() {
953
- return this.paths.flatMap((path) => path.curves.flatMap((curve) => curve.toPathCommands()));
1084
+ getMinMax(min = new Point2D(), max = new Point2D()) {
1085
+ this.paths.forEach((path) => path.curves.forEach((curve) => curve.getMinMax(min, max)));
1086
+ return { min, max };
1087
+ }
1088
+ getCommands() {
1089
+ return this.paths.flatMap((path) => path.curves.flatMap((curve) => curve.getCommands()));
1090
+ }
1091
+ getData() {
1092
+ return this.paths.map((path) => path.getData()).join(" ");
1093
+ }
1094
+ getBoundingBox() {
1095
+ const min = Point2D.MAX;
1096
+ const max = Point2D.MIN;
1097
+ this.paths.forEach((path) => path.getMinMax(min, max));
1098
+ return {
1099
+ x: min.x,
1100
+ y: min.y,
1101
+ width: max.x - min.x,
1102
+ height: max.y - min.y
1103
+ };
1104
+ }
1105
+ getSvgString() {
1106
+ const { x, y, width, height } = this.getBoundingBox();
1107
+ return `<svg viewBox="${x} ${y} ${width} ${height}" xmlns="http://www.w3.org/2000/svg"><path fill="none" stroke="currentColor" d="${this.getData()}"></path></svg>`;
1108
+ }
1109
+ getSvgDataUri() {
1110
+ return `data:image/svg+xml;base64,${btoa(this.getSvgString())}`;
954
1111
  }
955
1112
  drawTo(ctx) {
956
1113
  this.paths.forEach((path) => {
package/dist/index.d.cts CHANGED
@@ -36,6 +36,8 @@ type PathCommand = {
36
36
  declare class Point2D {
37
37
  x: number;
38
38
  y: number;
39
+ static get MAX(): Point2D;
40
+ static get MIN(): Point2D;
39
41
  constructor(x?: number, y?: number);
40
42
  set(x: number, y: number): this;
41
43
  add(point: Point2D): this;
@@ -58,8 +60,12 @@ declare abstract class Curve {
58
60
  protected _cacheArcLengths?: number[];
59
61
  protected _needsUpdate: boolean;
60
62
  abstract getPoint(t: number, output?: Point2D): Point2D;
61
- abstract toPathCommands(): PathCommand[];
63
+ abstract getCommands(): PathCommand[];
62
64
  abstract drawTo(ctx: CanvasRenderingContext2D): void;
65
+ getMinMax(min?: Point2D, max?: Point2D): {
66
+ min: Point2D;
67
+ max: Point2D;
68
+ };
63
69
  getDivisions(divisions: number): number;
64
70
  getPointAt(u: number, output?: Point2D): Point2D;
65
71
  getPoints(divisions?: number): Point2D[];
@@ -70,6 +76,7 @@ declare abstract class Curve {
70
76
  getUtoTmapping(u: number, distance?: number): number;
71
77
  getTangent(t: number, output?: Point2D): Point2D;
72
78
  getTangentAt(u: number, output?: Point2D): Point2D;
79
+ getData(): string;
73
80
  clone(): this;
74
81
  copy(source: Curve): this;
75
82
  }
@@ -99,7 +106,11 @@ declare class CurvePath extends Curve {
99
106
  absarc(x: number, y: number, radius: number, startAngle: number, endAngle: number, clockwise?: boolean): this;
100
107
  ellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
101
108
  absellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
102
- toPathCommands(): PathCommand[];
109
+ getCommands(): PathCommand[];
110
+ getMinMax(min?: Point2D, max?: Point2D): {
111
+ min: Point2D;
112
+ max: Point2D;
113
+ };
103
114
  drawTo(ctx: CanvasRenderingContext2D): void;
104
115
  copy(source: CurvePath): this;
105
116
  }
@@ -110,11 +121,14 @@ declare class CircleCurve extends Curve {
110
121
  start: number;
111
122
  end: number;
112
123
  constructor(center: Point2D, radius: number, start?: number, end?: number);
113
- getPole(min: Point2D, max: Point2D): void;
114
- getPoint(index: number): Point2D;
115
- getTangent(index: number): Point2D;
116
- getNormal(index: number): Point2D;
117
- toPathCommands(): PathCommand[];
124
+ getMinMax(min?: Point2D, max?: Point2D): {
125
+ min: Point2D;
126
+ max: Point2D;
127
+ };
128
+ getPoint(t: number): Point2D;
129
+ getTangent(t: number): Point2D;
130
+ getNormal(t: number): Point2D;
131
+ getCommands(): PathCommand[];
118
132
  drawTo(_ctx: CanvasRenderingContext2D): void;
119
133
  }
120
134
 
@@ -125,7 +139,11 @@ declare class CubicBezierCurve extends Curve {
125
139
  v3: Point2D;
126
140
  constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D, v3?: Point2D);
127
141
  getPoint(t: number, output?: Point2D): Point2D;
128
- toPathCommands(): PathCommand[];
142
+ getMinMax(min?: Point2D, max?: Point2D): {
143
+ min: Point2D;
144
+ max: Point2D;
145
+ };
146
+ getCommands(): PathCommand[];
129
147
  drawTo(ctx: CanvasRenderingContext2D): void;
130
148
  copy(source: CubicBezierCurve): this;
131
149
  }
@@ -142,7 +160,7 @@ declare class EllipseCurve extends Curve {
142
160
  constructor(x?: number, y?: number, rx?: number, ry?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number);
143
161
  getDivisions(divisions?: number): number;
144
162
  getPoint(t: number, output?: Point2D): Point2D;
145
- toPathCommands(): PathCommand[];
163
+ getCommands(): PathCommand[];
146
164
  drawTo(ctx: CanvasRenderingContext2D): void;
147
165
  copy(source: EllipseCurve): this;
148
166
  }
@@ -160,7 +178,7 @@ declare class HeartCurve extends Curve {
160
178
  getCurrentLine(value: number): Curve;
161
179
  getTangent(value: number): Point2D;
162
180
  getNormal(value: number): Point2D;
163
- toPathCommands(): PathCommand[];
181
+ getCommands(): PathCommand[];
164
182
  drawTo(ctx: CanvasRenderingContext2D): void;
165
183
  }
166
184
 
@@ -173,7 +191,11 @@ declare class LineCurve extends Curve {
173
191
  getPointAt(u: number, output?: Point2D): Point2D;
174
192
  getTangent(t: number, output?: Point2D): Point2D;
175
193
  getTangentAt(u: number, output?: Point2D): Point2D;
176
- toPathCommands(): PathCommand[];
194
+ getCommands(): PathCommand[];
195
+ getMinMax(min?: Point2D, max?: Point2D): {
196
+ min: Point2D;
197
+ max: Point2D;
198
+ };
177
199
  drawTo(ctx: CanvasRenderingContext2D): void;
178
200
  copy(source: LineCurve): this;
179
201
  }
@@ -194,7 +216,11 @@ declare class PloygonCurve extends Curve {
194
216
  getCurrentLine(value: number): LineCurve;
195
217
  getTangent(value: number): Point2D;
196
218
  getNormal(value: number): Point2D;
197
- toPathCommands(): PathCommand[];
219
+ getCommands(): PathCommand[];
220
+ getMinMax(min?: Point2D, max?: Point2D): {
221
+ min: Point2D;
222
+ max: Point2D;
223
+ };
198
224
  drawTo(ctx: CanvasRenderingContext2D): void;
199
225
  }
200
226
 
@@ -204,7 +230,11 @@ declare class QuadraticBezierCurve extends Curve {
204
230
  v2: Point2D;
205
231
  constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D);
206
232
  getPoint(t: number, output?: Point2D): Point2D;
207
- toPathCommands(): PathCommand[];
233
+ getCommands(): PathCommand[];
234
+ getMinMax(min?: Point2D, max?: Point2D): {
235
+ min: Point2D;
236
+ max: Point2D;
237
+ };
208
238
  drawTo(ctx: CanvasRenderingContext2D): void;
209
239
  copy(source: QuadraticBezierCurve): this;
210
240
  }
@@ -227,7 +257,11 @@ declare class RectangularCurve extends Curve {
227
257
  getCurrentLine(t: number): LineCurve;
228
258
  getTangent(t: number): Point2D;
229
259
  getNormal(value: number): Point2D;
230
- toPathCommands(): PathCommand[];
260
+ getCommands(): PathCommand[];
261
+ getMinMax(min?: Point2D, max?: Point2D): {
262
+ min: Point2D;
263
+ max: Point2D;
264
+ };
231
265
  drawTo(ctx: CanvasRenderingContext2D): void;
232
266
  }
233
267
 
@@ -236,7 +270,7 @@ declare class SplineCurve extends Curve {
236
270
  constructor(points?: Point2D[]);
237
271
  getDivisions(divisions?: number): number;
238
272
  getPoint(t: number, output?: Point2D): Point2D;
239
- toPathCommands(): PathCommand[];
273
+ getCommands(): PathCommand[];
240
274
  drawTo(_ctx: CanvasRenderingContext2D): void;
241
275
  copy(source: SplineCurve): this;
242
276
  }
@@ -247,14 +281,31 @@ declare class SplineCurve extends Curve {
247
281
  declare class Path2D {
248
282
  currentPath: CurvePath;
249
283
  paths: CurvePath[];
250
- arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
251
- bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
252
- lineTo(x: number, y: number): this;
284
+ addPath(path: Path2D): this;
285
+ closePath(): this;
253
286
  moveTo(x: number, y: number): this;
287
+ lineTo(x: number, y: number): this;
288
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
254
289
  quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
290
+ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
291
+ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): this;
292
+ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise: number): this;
255
293
  rect(x: number, y: number, w: number, h: number): this;
256
294
  splineThru(points: Point2D[]): this;
257
- toPathCommands(): PathCommand[];
295
+ getMinMax(min?: Point2D, max?: Point2D): {
296
+ min: Point2D;
297
+ max: Point2D;
298
+ };
299
+ getCommands(): PathCommand[];
300
+ getData(): string;
301
+ getBoundingBox(): {
302
+ x: number;
303
+ y: number;
304
+ width: number;
305
+ height: number;
306
+ };
307
+ getSvgString(): string;
308
+ getSvgDataUri(): string;
258
309
  drawTo(ctx: CanvasRenderingContext2D): void;
259
310
  strokeTo(ctx: CanvasRenderingContext2D): void;
260
311
  fillTo(ctx: CanvasRenderingContext2D): void;