modern-path2d 0.1.8 → 0.1.10

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <h1 align="center">[WIP] modern-path2d</h1>
1
+ <h1 align="center">modern-path2d</h1>
2
2
 
3
3
  <p align="center">
4
4
  <a href="https://unpkg.com/modern-path2d">
package/dist/index.cjs CHANGED
@@ -384,221 +384,175 @@ function parseArcCommand(path, rx, ry, xAxisRotation, largeArcFlag, sweepFlag, s
384
384
  const cy = Math.sin(xAxisRotation) * cxp + Math.cos(xAxisRotation) * cyp + (start.y + end.y) / 2;
385
385
  const theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
386
386
  const delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
387
- path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweepFlag === 0, xAxisRotation);
387
+ path.ellipse(cx, cy, rx, ry, xAxisRotation, theta, theta + delta, sweepFlag === 1);
388
388
  }
389
389
 
390
390
  function getReflection(a, b) {
391
391
  return a - (b - a);
392
392
  }
393
393
  function addPathCommandsToPath2D(commands, path) {
394
- const point = new Vector2();
394
+ const current = new Vector2();
395
395
  const control = new Vector2();
396
- const firstPoint = new Vector2();
397
- let isFirstPoint = true;
398
- let doSetFirstPoint = false;
399
396
  for (let i = 0, l = commands.length; i < l; i++) {
400
- const command = commands[i];
401
- if (isFirstPoint) {
402
- doSetFirstPoint = true;
403
- isFirstPoint = false;
404
- }
405
- if (command.type === "m" || command.type === "M") {
406
- if (command.type === "m") {
407
- point.x += command.x;
408
- point.y += command.y;
397
+ const cmd = commands[i];
398
+ if (cmd.type === "m" || cmd.type === "M") {
399
+ if (cmd.type === "m") {
400
+ current.add(cmd);
409
401
  } else {
410
- point.x = command.x;
411
- point.y = command.y;
402
+ current.copy(cmd);
412
403
  }
413
- control.x = point.x;
414
- control.y = point.y;
415
- path.moveTo(point.x, point.y);
416
- firstPoint.copy(point);
417
- } else if (command.type === "h" || command.type === "H") {
418
- if (command.type === "h") {
419
- point.x += command.x;
404
+ path.moveTo(current.x, current.y);
405
+ control.copy(current);
406
+ } else if (cmd.type === "h" || cmd.type === "H") {
407
+ if (cmd.type === "h") {
408
+ current.x += cmd.x;
420
409
  } else {
421
- point.x = command.x;
410
+ current.x = cmd.x;
422
411
  }
423
- control.x = point.x;
424
- control.y = point.y;
425
- path.lineTo(point.x, point.y);
426
- if (doSetFirstPoint)
427
- firstPoint.copy(point);
428
- } else if (command.type === "v" || command.type === "V") {
429
- if (command.type === "v") {
430
- point.y += command.y;
412
+ path.lineTo(current.x, current.y);
413
+ control.copy(current);
414
+ } else if (cmd.type === "v" || cmd.type === "V") {
415
+ if (cmd.type === "v") {
416
+ current.y += cmd.y;
431
417
  } else {
432
- point.y = command.y;
418
+ current.y = cmd.y;
433
419
  }
434
- control.x = point.x;
435
- control.y = point.y;
436
- path.lineTo(point.x, point.y);
437
- if (doSetFirstPoint)
438
- firstPoint.copy(point);
439
- } else if (command.type === "l" || command.type === "L") {
440
- if (command.type === "l") {
441
- point.x += command.x;
442
- point.y += command.y;
420
+ path.lineTo(current.x, current.y);
421
+ control.copy(current);
422
+ } else if (cmd.type === "l" || cmd.type === "L") {
423
+ if (cmd.type === "l") {
424
+ current.add(cmd);
443
425
  } else {
444
- point.x = command.x;
445
- point.y = command.y;
426
+ current.copy(cmd);
446
427
  }
447
- control.x = point.x;
448
- control.y = point.y;
449
- path.lineTo(point.x, point.y);
450
- if (doSetFirstPoint)
451
- firstPoint.copy(point);
452
- } else if (command.type === "c" || command.type === "C") {
453
- if (command.type === "c") {
428
+ path.lineTo(current.x, current.y);
429
+ control.copy(current);
430
+ } else if (cmd.type === "c" || cmd.type === "C") {
431
+ if (cmd.type === "c") {
454
432
  path.bezierCurveTo(
455
- point.x + command.x1,
456
- point.y + command.y1,
457
- point.x + command.x2,
458
- point.y + command.y2,
459
- point.x + command.x,
460
- point.y + command.y
433
+ current.x + cmd.x1,
434
+ current.y + cmd.y1,
435
+ current.x + cmd.x2,
436
+ current.y + cmd.y2,
437
+ current.x + cmd.x,
438
+ current.y + cmd.y
461
439
  );
462
- control.x = point.x + command.x2;
463
- control.y = point.y + command.y2;
464
- point.x += command.x;
465
- point.y += command.y;
440
+ control.x = current.x + cmd.x2;
441
+ control.y = current.y + cmd.y2;
442
+ current.add(cmd);
466
443
  } else {
467
444
  path.bezierCurveTo(
468
- command.x1,
469
- command.y1,
470
- command.x2,
471
- command.y2,
472
- command.x,
473
- command.y
445
+ cmd.x1,
446
+ cmd.y1,
447
+ cmd.x2,
448
+ cmd.y2,
449
+ cmd.x,
450
+ cmd.y
474
451
  );
475
- control.x = command.x2;
476
- control.y = command.y2;
477
- point.x = command.x;
478
- point.y = command.y;
452
+ control.x = cmd.x2;
453
+ control.y = cmd.y2;
454
+ current.copy(cmd);
479
455
  }
480
- if (doSetFirstPoint)
481
- firstPoint.copy(point);
482
- } else if (command.type === "s" || command.type === "S") {
483
- if (command.type === "s") {
456
+ } else if (cmd.type === "s" || cmd.type === "S") {
457
+ if (cmd.type === "s") {
484
458
  path.bezierCurveTo(
485
- getReflection(point.x, control.x),
486
- getReflection(point.y, control.y),
487
- point.x + command.x2,
488
- point.y + command.y2,
489
- point.x + command.x,
490
- point.y + command.y
459
+ getReflection(current.x, control.x),
460
+ getReflection(current.y, control.y),
461
+ current.x + cmd.x2,
462
+ current.y + cmd.y2,
463
+ current.x + cmd.x,
464
+ current.y + cmd.y
491
465
  );
492
- control.x = point.x + command.x2;
493
- control.y = point.y + command.y2;
494
- point.x += command.x;
495
- point.y += command.y;
466
+ control.x = current.x + cmd.x2;
467
+ control.y = current.y + cmd.y2;
468
+ current.add(cmd);
496
469
  } else {
497
470
  path.bezierCurveTo(
498
- getReflection(point.x, control.x),
499
- getReflection(point.y, control.y),
500
- command.x2,
501
- command.y2,
502
- command.x,
503
- command.y
471
+ getReflection(current.x, control.x),
472
+ getReflection(current.y, control.y),
473
+ cmd.x2,
474
+ cmd.y2,
475
+ cmd.x,
476
+ cmd.y
504
477
  );
505
- control.x = command.x2;
506
- control.y = command.y2;
507
- point.x = command.x;
508
- point.y = command.y;
478
+ control.x = cmd.x2;
479
+ control.y = cmd.y2;
480
+ current.copy(cmd);
509
481
  }
510
- if (doSetFirstPoint)
511
- firstPoint.copy(point);
512
- } else if (command.type === "q" || command.type === "Q") {
513
- if (command.type === "q") {
482
+ } else if (cmd.type === "q" || cmd.type === "Q") {
483
+ if (cmd.type === "q") {
514
484
  path.quadraticCurveTo(
515
- point.x + command.x1,
516
- point.y + command.y1,
517
- point.x + command.x,
518
- point.y + command.y
485
+ current.x + cmd.x1,
486
+ current.y + cmd.y1,
487
+ current.x + cmd.x,
488
+ current.y + cmd.y
519
489
  );
520
- control.x = point.x + command.x1;
521
- control.y = point.y + command.y1;
522
- point.x += command.x;
523
- point.y += command.y;
490
+ control.x = current.x + cmd.x1;
491
+ control.y = current.y + cmd.y1;
492
+ current.add(cmd);
524
493
  } else {
525
494
  path.quadraticCurveTo(
526
- command.x1,
527
- command.y1,
528
- command.x,
529
- command.y
495
+ cmd.x1,
496
+ cmd.y1,
497
+ cmd.x,
498
+ cmd.y
530
499
  );
531
- control.x = command.x1;
532
- control.y = command.y1;
533
- point.x = command.x;
534
- point.y = command.y;
500
+ control.x = cmd.x1;
501
+ control.y = cmd.y1;
502
+ current.copy(cmd);
535
503
  }
536
- if (doSetFirstPoint)
537
- firstPoint.copy(point);
538
- } else if (command.type === "t" || command.type === "T") {
539
- const rx = getReflection(point.x, control.x);
540
- const ry = getReflection(point.y, control.y);
504
+ } else if (cmd.type === "t" || cmd.type === "T") {
505
+ const rx = getReflection(current.x, control.x);
506
+ const ry = getReflection(current.y, control.y);
541
507
  control.x = rx;
542
508
  control.y = ry;
543
- if (command.type === "t") {
509
+ if (cmd.type === "t") {
544
510
  path.quadraticCurveTo(
545
511
  rx,
546
512
  ry,
547
- point.x + command.x,
548
- point.y + command.y
513
+ current.x + cmd.x,
514
+ current.y + cmd.y
549
515
  );
550
- point.x += command.x;
551
- point.y += command.y;
516
+ current.add(cmd);
552
517
  } else {
553
518
  path.quadraticCurveTo(
554
519
  rx,
555
520
  ry,
556
- command.x,
557
- command.y
521
+ cmd.x,
522
+ cmd.y
558
523
  );
559
- point.x = command.x;
560
- point.y = command.y;
524
+ current.copy(cmd);
561
525
  }
562
- if (doSetFirstPoint)
563
- firstPoint.copy(point);
564
- } else if (command.type === "a" || command.type === "A") {
565
- if (command.type === "a") {
566
- if (command.x === 0 && command.y === 0)
526
+ } else if (cmd.type === "a" || cmd.type === "A") {
527
+ const start = current.clone();
528
+ if (cmd.type === "a") {
529
+ if (cmd.x === 0 && cmd.y === 0)
567
530
  continue;
568
- point.x += command.x;
569
- point.y += command.y;
531
+ current.add(cmd);
570
532
  } else {
571
- if (command.x === point.x && command.y === point.y)
533
+ if (current.equals(cmd))
572
534
  continue;
573
- point.x = command.x;
574
- point.y = command.y;
535
+ current.copy(cmd);
575
536
  }
576
- const start = point.clone();
577
- control.x = point.x;
578
- control.y = point.y;
537
+ control.copy(current);
579
538
  parseArcCommand(
580
539
  path,
581
- command.rx,
582
- command.ry,
583
- command.angle,
584
- command.largeArcFlag,
585
- command.sweepFlag,
540
+ cmd.rx,
541
+ cmd.ry,
542
+ cmd.angle,
543
+ cmd.largeArcFlag,
544
+ cmd.sweepFlag,
586
545
  start,
587
- point
546
+ current
588
547
  );
589
- if (doSetFirstPoint)
590
- firstPoint.copy(point);
591
- } else if (command.type === "z" || command.type === "Z") {
592
- path.currentPath.autoClose = true;
593
- if (path.currentPath.curves.length > 0) {
594
- point.copy(firstPoint);
595
- path.currentPath.currentPoint.copy(point);
596
- isFirstPoint = true;
548
+ } else if (cmd.type === "z" || cmd.type === "Z") {
549
+ if (path.startPoint) {
550
+ current.copy(path.startPoint);
597
551
  }
552
+ path.closePath();
598
553
  } else {
599
- console.warn("Unsupported commands", command);
554
+ console.warn("Unsupported commands", cmd);
600
555
  }
601
- doSetFirstPoint = false;
602
556
  }
603
557
  }
604
558
 
@@ -1189,15 +1143,15 @@ const tempTransform1$1 = new Matrix3();
1189
1143
  const tempTransform2$1 = new Matrix3();
1190
1144
  const tempV2 = new Vector2();
1191
1145
  class EllipseCurve extends Curve {
1192
- constructor(center = new Vector2(), radiusX = 1, radiusY = 1, startAngle = 0, endAngle = Math.PI * 2, clockwise = false, rotation = 0) {
1146
+ constructor(center = new Vector2(), radiusX = 1, radiusY = 1, rotation = 0, startAngle = 0, endAngle = Math.PI * 2, clockwise = false) {
1193
1147
  super();
1194
1148
  this.center = center;
1195
1149
  this.radiusX = radiusX;
1196
1150
  this.radiusY = radiusY;
1151
+ this.rotation = rotation;
1197
1152
  this.startAngle = startAngle;
1198
1153
  this.endAngle = endAngle;
1199
1154
  this.clockwise = clockwise;
1200
- this.rotation = rotation;
1201
1155
  }
1202
1156
  getPoint(t, output = new Vector2()) {
1203
1157
  const twoPi = Math.PI * 2;
@@ -1881,27 +1835,36 @@ class CurvePath extends Curve {
1881
1835
  constructor(points) {
1882
1836
  super();
1883
1837
  __publicField$1(this, "curves", []);
1838
+ __publicField$1(this, "startPoint");
1884
1839
  __publicField$1(this, "currentPoint", new Vector2());
1885
1840
  __publicField$1(this, "autoClose", false);
1886
1841
  __publicField$1(this, "_cacheLengths", []);
1887
1842
  if (points) {
1888
- this.setFromPoints(points);
1843
+ this.addPoints(points);
1889
1844
  }
1890
1845
  }
1891
1846
  addCurve(curve) {
1892
1847
  this.curves.push(curve);
1893
1848
  return this;
1894
1849
  }
1895
- closePath() {
1896
- const start = this.curves[0].getPoint(0);
1897
- const end = this.curves[this.curves.length - 1].getPoint(1);
1898
- if (!start.equals(end)) {
1899
- this.curves.push(new LineCurve(end, start));
1850
+ addPoints(points) {
1851
+ this.moveTo(points[0].x, points[0].y);
1852
+ for (let i = 1, len = points.length; i < len; i++) {
1853
+ const { x, y } = points[i];
1854
+ this.lineTo(x, y);
1900
1855
  }
1901
1856
  return this;
1902
1857
  }
1903
- getPoint(position, output = new Vector2()) {
1904
- const d = position * this.getLength();
1858
+ addCommands(commands) {
1859
+ addPathCommandsToPath2D(commands, this);
1860
+ return this;
1861
+ }
1862
+ addData(data) {
1863
+ this.addCommands(pathDataToPathCommands(data));
1864
+ return this;
1865
+ }
1866
+ getPoint(t, output = new Vector2()) {
1867
+ const d = t * this.getLength();
1905
1868
  const curveLengths = this.getCurveLengths();
1906
1869
  let i = 0;
1907
1870
  while (i < curveLengths.length) {
@@ -1966,23 +1929,28 @@ class CurvePath extends Curve {
1966
1929
  }
1967
1930
  return points;
1968
1931
  }
1969
- setFromPoints(points) {
1970
- this.moveTo(points[0].x, points[0].y);
1971
- for (let i = 1, l = points.length; i < l; i++) {
1972
- this.lineTo(points[i].x, points[i].y);
1932
+ _setCurrentPoint(point) {
1933
+ this.currentPoint.copy(point);
1934
+ if (!this.startPoint) {
1935
+ this.startPoint = this.currentPoint.clone();
1973
1936
  }
1974
1937
  return this;
1975
1938
  }
1976
- bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
1977
- this.curves.push(
1978
- new CubicBezierCurve(
1979
- this.currentPoint.clone(),
1980
- new Vector2(cp1x, cp1y),
1981
- new Vector2(cp2x, cp2y),
1982
- new Vector2(x, y)
1983
- )
1984
- );
1939
+ closePath() {
1940
+ const start = this.startPoint;
1941
+ if (start) {
1942
+ const end = this.currentPoint;
1943
+ if (!start.equals(end)) {
1944
+ this.curves.push(new LineCurve(end, start));
1945
+ this.currentPoint.copy(start);
1946
+ }
1947
+ this.startPoint = void 0;
1948
+ }
1949
+ return this;
1950
+ }
1951
+ moveTo(x, y) {
1985
1952
  this.currentPoint.set(x, y);
1953
+ this.startPoint = this.currentPoint.clone();
1986
1954
  return this;
1987
1955
  }
1988
1956
  lineTo(x, y) {
@@ -1992,64 +1960,56 @@ class CurvePath extends Curve {
1992
1960
  new Vector2(x, y)
1993
1961
  )
1994
1962
  );
1995
- this.currentPoint.set(x, y);
1963
+ this._setCurrentPoint({ x, y });
1996
1964
  return this;
1997
1965
  }
1998
- moveTo(x, y) {
1999
- this.currentPoint.set(x, y);
2000
- return this;
2001
- }
2002
- quadraticCurveTo(cpx, cpy, x, y) {
1966
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
2003
1967
  this.curves.push(
2004
- new QuadraticBezierCurve(
1968
+ new CubicBezierCurve(
2005
1969
  this.currentPoint.clone(),
2006
- new Vector2(cpx, cpy),
1970
+ new Vector2(cp1x, cp1y),
1971
+ new Vector2(cp2x, cp2y),
2007
1972
  new Vector2(x, y)
2008
1973
  )
2009
1974
  );
2010
- this.currentPoint.set(x, y);
1975
+ this._setCurrentPoint({ x, y });
2011
1976
  return this;
2012
1977
  }
2013
- rect(x, y, w, h) {
1978
+ quadraticCurveTo(cpx, cpy, x, y) {
2014
1979
  this.curves.push(
2015
- new RectangularCurve(
2016
- new Vector2(x + w / 2, y + h / 2),
2017
- w / 2,
2018
- w / h
1980
+ new QuadraticBezierCurve(
1981
+ this.currentPoint.clone(),
1982
+ new Vector2(cpx, cpy),
1983
+ new Vector2(x, y)
2019
1984
  )
2020
1985
  );
2021
- this.currentPoint.set(x, y);
1986
+ this._setCurrentPoint({ x, y });
2022
1987
  return this;
2023
1988
  }
2024
- splineThru(points) {
2025
- const npts = [this.currentPoint.clone()].concat(points);
2026
- this.curves.push(new SplineCurve(npts));
2027
- this.currentPoint.copy(points[points.length - 1]);
1989
+ arc(x, y, radius, startAngle, endAngle, counterclockwise) {
1990
+ this.ellipse(x, y, radius, radius, 0, startAngle, endAngle, counterclockwise);
2028
1991
  return this;
2029
1992
  }
2030
- arc(x, y, radius, startAngle, endAngle, clockwise = false) {
1993
+ relativeArc(x, y, radius, startAngle, endAngle, counterclockwise) {
2031
1994
  const point = this.currentPoint;
2032
- this.absarc(x + point.x, y + point.y, radius, startAngle, endAngle, clockwise);
2033
- return this;
2034
- }
2035
- absarc(x, y, radius, startAngle, endAngle, clockwise = false) {
2036
- this.absellipse(x, y, radius, radius, startAngle, endAngle, clockwise);
1995
+ this.arc(x + point.x, y + point.y, radius, startAngle, endAngle, counterclockwise);
2037
1996
  return this;
2038
1997
  }
2039
- ellipse(x, y, radiusX, radiusY, startAngle, endAngle, clockwise = false, rotation = 0) {
2040
- const point = this.currentPoint;
2041
- this.absellipse(x + point.x, y + point.y, radiusX, radiusY, startAngle, endAngle, clockwise, rotation);
1998
+ // TODO
1999
+ // eslint-disable-next-line unused-imports/no-unused-vars
2000
+ arcTo(x1, y1, x2, y2, radius) {
2001
+ console.warn("Method arcTo not supported yet");
2042
2002
  return this;
2043
2003
  }
2044
- absellipse(x, y, radiusX, radiusY, startAngle, endAngle, clockwise = false, rotation = 0) {
2004
+ ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise = true) {
2045
2005
  const curve = new EllipseCurve(
2046
2006
  new Vector2(x, y),
2047
2007
  radiusX,
2048
2008
  radiusY,
2009
+ rotation,
2049
2010
  startAngle,
2050
2011
  endAngle,
2051
- clockwise,
2052
- rotation
2012
+ !counterclockwise
2053
2013
  );
2054
2014
  if (this.curves.length > 0) {
2055
2015
  const first = curve.getPoint(0);
@@ -2058,16 +2018,45 @@ class CurvePath extends Curve {
2058
2018
  }
2059
2019
  }
2060
2020
  this.curves.push(curve);
2061
- this.currentPoint.copy(curve.getPoint(1));
2021
+ this._setCurrentPoint(curve.getPoint(1));
2062
2022
  return this;
2063
2023
  }
2064
- getCommands() {
2065
- return this.curves.flatMap((curve) => curve.getCommands());
2024
+ relativeEllipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
2025
+ const point = this.currentPoint;
2026
+ this.ellipse(x + point.x, y + point.y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
2027
+ return this;
2028
+ }
2029
+ rect(x, y, w, h) {
2030
+ this.curves.push(
2031
+ new RectangularCurve(
2032
+ new Vector2(x + w / 2, y + h / 2),
2033
+ w / 2,
2034
+ w / h
2035
+ )
2036
+ );
2037
+ this._setCurrentPoint({ x, y });
2038
+ return this;
2039
+ }
2040
+ splineThru(points) {
2041
+ this.curves.push(new SplineCurve([this.currentPoint.clone()].concat(points)));
2042
+ this._setCurrentPoint(points[points.length - 1]);
2043
+ return this;
2044
+ }
2045
+ transformPoint(cb) {
2046
+ this.curves.forEach((curve) => curve.transformPoint(cb));
2047
+ return this;
2066
2048
  }
2067
2049
  getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
2068
2050
  this.curves.forEach((curve) => curve.getMinMax(min, max));
2069
2051
  return { min, max };
2070
2052
  }
2053
+ getBoundingBox() {
2054
+ const { min, max } = this.getMinMax();
2055
+ return new BoundingBox(min.x, min.y, max.x - min.x, max.y - min.y);
2056
+ }
2057
+ getCommands() {
2058
+ return this.curves.flatMap((curve) => curve.getCommands());
2059
+ }
2071
2060
  drawTo(ctx) {
2072
2061
  const point = this.curves[0]?.getPoint(0);
2073
2062
  if (point) {
@@ -2112,6 +2101,12 @@ class Path2D {
2112
2101
  }
2113
2102
  }
2114
2103
  }
2104
+ get startPoint() {
2105
+ return this.currentPath.startPoint;
2106
+ }
2107
+ get currentPoint() {
2108
+ return this.currentPath.currentPoint;
2109
+ }
2115
2110
  addPath(path) {
2116
2111
  if (path instanceof Path2D) {
2117
2112
  this.paths.push(...path.paths.map((v) => v.clone()));
@@ -2121,12 +2116,19 @@ class Path2D {
2121
2116
  return this;
2122
2117
  }
2123
2118
  closePath() {
2124
- this.currentPath.closePath();
2119
+ const startPoint = this.startPoint;
2120
+ if (startPoint) {
2121
+ this.currentPath.closePath();
2122
+ if (this.currentPath.curves.length > 0) {
2123
+ this.currentPath = new CurvePath().moveTo(startPoint.x, startPoint.y);
2124
+ this.paths.push(this.currentPath);
2125
+ }
2126
+ }
2125
2127
  return this;
2126
2128
  }
2127
2129
  moveTo(x, y) {
2128
2130
  const { currentPoint, curves } = this.currentPath;
2129
- if (currentPoint.x !== x || currentPoint.y !== y) {
2131
+ if (!currentPoint.equals({ x, y })) {
2130
2132
  if (curves.length) {
2131
2133
  this.currentPath = new CurvePath().moveTo(x, y);
2132
2134
  this.paths.push(this.currentPath);
@@ -2149,17 +2151,15 @@ class Path2D {
2149
2151
  return this;
2150
2152
  }
2151
2153
  arc(x, y, radius, startAngle, endAngle, counterclockwise) {
2152
- this.currentPath.absarc(x, y, radius, startAngle, endAngle, !counterclockwise);
2154
+ this.currentPath.arc(x, y, radius, startAngle, endAngle, counterclockwise);
2153
2155
  return this;
2154
2156
  }
2155
- // TODO
2156
- // eslint-disable-next-line unused-imports/no-unused-vars
2157
2157
  arcTo(x1, y1, x2, y2, radius) {
2158
- console.warn("Method arcTo not supported yet");
2158
+ this.currentPath.arcTo(x1, y1, x2, y2, radius);
2159
2159
  return this;
2160
2160
  }
2161
2161
  ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
2162
- this.currentPath.absellipse(x, y, radiusX, radiusY, startAngle, endAngle, !counterclockwise, rotation);
2162
+ this.currentPath.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
2163
2163
  return this;
2164
2164
  }
2165
2165
  rect(x, y, w, h) {
@@ -2199,7 +2199,7 @@ class Path2D {
2199
2199
  return new BoundingBox(min.x, min.y, max.x - min.x, max.y - min.y);
2200
2200
  }
2201
2201
  getCommands() {
2202
- return this.paths.flatMap((path) => path.curves.flatMap((curve) => curve.getCommands()));
2202
+ return this.paths.flatMap((path) => path.getCommands());
2203
2203
  }
2204
2204
  getData() {
2205
2205
  return this.paths.map((path) => path.getData()).join(" ");
@@ -2452,7 +2452,7 @@ function parseNodeTransform(node) {
2452
2452
 
2453
2453
  function parseCircleNode(node) {
2454
2454
  return new Path2D().addPath(
2455
- new CurvePath().absarc(
2455
+ new CurvePath().arc(
2456
2456
  parseFloatWithUnits(node.getAttribute("cx") || 0),
2457
2457
  parseFloatWithUnits(node.getAttribute("cy") || 0),
2458
2458
  parseFloatWithUnits(node.getAttribute("r") || 0),
@@ -2484,12 +2484,13 @@ function parseCSSStylesheet(node, stylesheets) {
2484
2484
 
2485
2485
  function parseEllipseNode(node) {
2486
2486
  return new Path2D().addPath(
2487
- new CurvePath().absellipse(
2487
+ new CurvePath().ellipse(
2488
2488
  parseFloatWithUnits(node.getAttribute("cx") || 0),
2489
2489
  parseFloatWithUnits(node.getAttribute("cy") || 0),
2490
2490
  parseFloatWithUnits(node.getAttribute("rx") || 0),
2491
2491
  parseFloatWithUnits(node.getAttribute("ry") || 0),
2492
2492
  0,
2493
+ 0,
2493
2494
  Math.PI * 2
2494
2495
  )
2495
2496
  );