pantograph2d 0.7.0 → 0.8.1

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.
Files changed (154) hide show
  1. package/LICENSE +4 -658
  2. package/dist/QuadraticBezier-BAVasVfu.cjs +9 -0
  3. package/dist/QuadraticBezier-BAVasVfu.cjs.map +1 -0
  4. package/dist/QuadraticBezier-BzVqiExF.js +4736 -0
  5. package/dist/QuadraticBezier-BzVqiExF.js.map +1 -0
  6. package/dist/draw-DqsKIWJD.js +337 -0
  7. package/dist/draw-DqsKIWJD.js.map +1 -0
  8. package/dist/draw-NcYfDZjT.cjs +2 -0
  9. package/dist/draw-NcYfDZjT.cjs.map +1 -0
  10. package/dist/models-Dxwusy3i.cjs +4 -0
  11. package/dist/models-Dxwusy3i.cjs.map +1 -0
  12. package/dist/models-WQ-B7GSL.js +1749 -0
  13. package/dist/models-WQ-B7GSL.js.map +1 -0
  14. package/dist/pantograph/drawShape.cjs +1 -1
  15. package/dist/pantograph/drawShape.cjs.map +1 -1
  16. package/dist/pantograph/drawShape.js +12 -13
  17. package/dist/pantograph/drawShape.js.map +1 -1
  18. package/dist/pantograph/models.cjs +1 -1
  19. package/dist/pantograph/models.js +15 -12
  20. package/dist/pantograph/models.js.map +1 -1
  21. package/dist/pantograph/svg.cjs +2 -0
  22. package/dist/pantograph/svg.cjs.map +1 -0
  23. package/dist/pantograph/svg.js +10 -0
  24. package/dist/pantograph/svg.js.map +1 -0
  25. package/dist/pantograph.cjs +2 -8
  26. package/dist/pantograph.cjs.map +1 -1
  27. package/dist/pantograph.js +406 -452
  28. package/dist/pantograph.js.map +1 -1
  29. package/dist/svg-BylQQgsL.js +62 -0
  30. package/dist/svg-BylQQgsL.js.map +1 -0
  31. package/dist/svg-D0nYyMk7.cjs +8 -0
  32. package/dist/svg-D0nYyMk7.cjs.map +1 -0
  33. package/dist/types/examples/importSVG.d.ts +4 -0
  34. package/dist/types/{algorithms → src/algorithms}/boolean/figureBooleans.d.ts +1 -1
  35. package/dist/types/{algorithms → src/algorithms}/boolean/loopBooleans.d.ts +1 -1
  36. package/dist/types/{algorithms → src/algorithms}/boolean/strandBoolean.d.ts +4 -4
  37. package/dist/types/{algorithms → src/algorithms}/boolean/strandsBetweenIntersections.d.ts +3 -3
  38. package/dist/types/{algorithms → src/algorithms}/distances/arcArcDistance.d.ts +1 -1
  39. package/dist/types/{algorithms → src/algorithms}/distances/genericDistance.d.ts +1 -1
  40. package/dist/types/{algorithms → src/algorithms}/distances/index.d.ts +1 -1
  41. package/dist/types/src/algorithms/distances/lineArcDistance.d.ts +3 -0
  42. package/dist/types/{algorithms → src/algorithms}/distances/lineLineDistance.d.ts +1 -1
  43. package/dist/types/{algorithms → src/algorithms}/filletSegments.d.ts +1 -1
  44. package/dist/types/{algorithms → src/algorithms}/intersections/arcArcIntersection.d.ts +2 -2
  45. package/dist/types/src/algorithms/intersections/arcEllipseArcIntersection.d.ts +3 -0
  46. package/dist/types/src/algorithms/intersections/arcsCubicBezierIntersection.d.ts +5 -0
  47. package/dist/types/src/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +5 -0
  48. package/dist/types/{algorithms → src/algorithms}/intersections/bezierClip.d.ts +3 -3
  49. package/dist/types/{algorithms → src/algorithms}/intersections/cubicBezierCubicBezierIntersection.d.ts +2 -2
  50. package/dist/types/{algorithms → src/algorithms}/intersections/ellipseArcEllipseArcIntersection.d.ts +2 -2
  51. package/dist/types/src/algorithms/intersections/ellipseEllipseIntersection.d.ts +4 -0
  52. package/dist/types/{algorithms → src/algorithms}/intersections/index.d.ts +2 -2
  53. package/dist/types/src/algorithms/intersections/lineArcIntersection.d.ts +4 -0
  54. package/dist/types/src/algorithms/intersections/lineBezierIntersection.d.ts +5 -0
  55. package/dist/types/src/algorithms/intersections/lineEllipseArcIntersection.d.ts +4 -0
  56. package/dist/types/{algorithms → src/algorithms}/intersections/lineLineIntersection.d.ts +4 -4
  57. package/dist/types/{algorithms → src/algorithms}/intersections/quadraticBezierQuadraticBezierIntersection.d.ts +2 -2
  58. package/dist/types/src/algorithms/intersections/rayIntersections.d.ts +3 -0
  59. package/dist/types/{algorithms → src/algorithms}/offsets/offsetFigure.d.ts +2 -2
  60. package/dist/types/{algorithms → src/algorithms}/offsets/offsetSegment.d.ts +4 -4
  61. package/dist/types/{algorithms → src/algorithms}/offsets/offsetStroke.d.ts +5 -5
  62. package/dist/types/{algorithms → src/algorithms}/organiseLoops.d.ts +2 -2
  63. package/dist/types/src/algorithms/simplify.d.ts +3 -0
  64. package/dist/types/src/algorithms/solvers/findZeroViaNewton.d.ts +1 -0
  65. package/dist/types/src/algorithms/solvers/zeroViaNewton.d.ts +1 -0
  66. package/dist/types/{algorithms → src/algorithms}/stitchSegments.d.ts +1 -1
  67. package/dist/types/src/api/drawShape.d.ts +2 -0
  68. package/dist/types/src/api/models.d.ts +1 -0
  69. package/dist/types/src/api/svg.d.ts +1 -0
  70. package/dist/types/{booleanOperations.d.ts → src/booleanOperations.d.ts} +5 -5
  71. package/dist/types/{draw.d.ts → src/draw.d.ts} +4 -4
  72. package/dist/types/{drawShape → src/drawShape}/drawCircle.d.ts +1 -1
  73. package/dist/types/src/drawShape/drawEllipse.d.ts +2 -0
  74. package/dist/types/{drawShape → src/drawShape}/drawRect.d.ts +1 -1
  75. package/dist/types/src/drawShape/drawSVGPath.d.ts +2 -0
  76. package/dist/types/src/drawShape/index.d.ts +4 -0
  77. package/dist/types/{export → src/export}/json/exportJSON.d.ts +94 -94
  78. package/dist/types/{export → src/export}/json/jsonDiagram.d.ts +31 -31
  79. package/dist/types/{export → src/export}/json/jsonFigure.d.ts +31 -31
  80. package/dist/types/{export → src/export}/json/jsonLoop.d.ts +16 -16
  81. package/dist/types/{export → src/export}/json/jsonSegment.d.ts +16 -16
  82. package/dist/types/src/export/svg/api.d.ts +6 -0
  83. package/dist/types/{export → src/export}/svg/exportSVG.d.ts +6 -6
  84. package/dist/types/{export → src/export}/svg/svgDiagram.d.ts +1 -1
  85. package/dist/types/{export → src/export}/svg/svgFigure.d.ts +1 -1
  86. package/dist/types/{export → src/export}/svg/svgLoop.d.ts +1 -1
  87. package/dist/types/{export → src/export}/svg/svgSegment.d.ts +1 -1
  88. package/dist/types/{export → src/export}/svg/svgStrand.d.ts +1 -1
  89. package/dist/types/{export → src/export}/svg/wrapSVG.d.ts +2 -2
  90. package/dist/types/src/import/json/importJSON.d.ts +9 -0
  91. package/dist/types/{main.d.ts → src/main.d.ts} +7 -7
  92. package/dist/types/{models → src/models}/BoundingBox.d.ts +1 -1
  93. package/dist/types/{models → src/models}/Diagram.d.ts +7 -7
  94. package/dist/types/{models → src/models}/Figure.d.ts +7 -7
  95. package/dist/types/{models → src/models}/Loop.d.ts +4 -4
  96. package/dist/types/{models → src/models}/Strand.d.ts +2 -2
  97. package/dist/types/{models → src/models}/Stroke.d.ts +5 -5
  98. package/dist/types/{models → src/models}/TransformationMatrix.d.ts +1 -1
  99. package/dist/types/src/models/exports.d.ts +15 -0
  100. package/dist/types/src/models/segments/AbstractSegment.d.ts +25 -0
  101. package/dist/types/{models → src/models}/segments/Arc.d.ts +4 -4
  102. package/dist/types/{models → src/models}/segments/CubicBezier.d.ts +4 -4
  103. package/dist/types/{models → src/models}/segments/EllipseArc.d.ts +5 -5
  104. package/dist/types/{models → src/models}/segments/Line.d.ts +4 -4
  105. package/dist/types/{models → src/models}/segments/QuadraticBezier.d.ts +4 -4
  106. package/dist/types/{models → src/models}/segments/Segment.d.ts +4 -4
  107. package/dist/types/{models → src/models}/segments/utils/deCasteljau.d.ts +1 -1
  108. package/dist/types/src/models/segments/utils/isSegment.d.ts +8 -0
  109. package/dist/types/{models → src/models}/utils/Transformable.d.ts +2 -2
  110. package/dist/types/{offsetOperations.d.ts → src/offsetOperations.d.ts} +4 -4
  111. package/dist/types/src/operations.d.ts +2 -0
  112. package/dist/types/src/utils/applyMixins.d.ts +1 -0
  113. package/dist/types/src/utils/listOfFigures.d.ts +4 -0
  114. package/dist/types/src/utils/projectPointOnLine.d.ts +3 -0
  115. package/dist/types/{utils → src/utils}/removeDuplicatePoints.d.ts +1 -1
  116. package/dist/types/{vectorOperations.d.ts → src/vectorOperations.d.ts} +1 -1
  117. package/package.json +33 -25
  118. package/dist/Diagram-8c3c5e1b.js +0 -5301
  119. package/dist/Diagram-8c3c5e1b.js.map +0 -1
  120. package/dist/Diagram-d8288579.cjs +0 -11
  121. package/dist/Diagram-d8288579.cjs.map +0 -1
  122. package/dist/draw-3ee546c3.cjs +0 -2
  123. package/dist/draw-3ee546c3.cjs.map +0 -1
  124. package/dist/draw-825692f1.js +0 -336
  125. package/dist/draw-825692f1.js.map +0 -1
  126. package/dist/types/algorithms/distances/lineArcDistance.d.ts +0 -3
  127. package/dist/types/algorithms/intersections/arcEllipseArcIntersection.d.ts +0 -3
  128. package/dist/types/algorithms/intersections/arcsCubicBezierIntersection.d.ts +0 -5
  129. package/dist/types/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +0 -5
  130. package/dist/types/algorithms/intersections/ellipseEllipseIntersection.d.ts +0 -4
  131. package/dist/types/algorithms/intersections/lineArcIntersection.d.ts +0 -4
  132. package/dist/types/algorithms/intersections/lineBezierIntersection.d.ts +0 -5
  133. package/dist/types/algorithms/intersections/lineEllipseArcIntersection.d.ts +0 -4
  134. package/dist/types/algorithms/intersections/rayIntersections.d.ts +0 -3
  135. package/dist/types/algorithms/simplify.d.ts +0 -3
  136. package/dist/types/api/drawShape.d.ts +0 -2
  137. package/dist/types/api/models.d.ts +0 -1
  138. package/dist/types/import/json/importJSON.d.ts +0 -9
  139. package/dist/types/models/exports.d.ts +0 -13
  140. package/dist/types/models/segments/utils/isSegment.d.ts +0 -8
  141. package/dist/types/operations.d.ts +0 -2
  142. package/dist/types/utils/listOfFigures.d.ts +0 -4
  143. package/dist/types/utils/projectPointOnLine.d.ts +0 -3
  144. /package/dist/types/{algorithms → src/algorithms}/optimisation/Brent.d.ts +0 -0
  145. /package/dist/types/{algorithms → src/algorithms}/optimisation/DiRect.d.ts +0 -0
  146. /package/dist/types/{algorithms → src/algorithms}/solvers/solvePolynomials.d.ts +0 -0
  147. /package/dist/types/{definitions.d.ts → src/definitions.d.ts} +0 -0
  148. /package/dist/types/{utils → src/utils}/allCombinations.d.ts +0 -0
  149. /package/dist/types/{utils → src/utils}/allPairs.d.ts +0 -0
  150. /package/dist/types/{utils → src/utils}/angularDistance.d.ts +0 -0
  151. /package/dist/types/{utils → src/utils}/range.d.ts +0 -0
  152. /package/dist/types/{utils → src/utils}/removeDuplicateValues.d.ts +0 -0
  153. /package/dist/types/{utils → src/utils}/unitAngle.d.ts +0 -0
  154. /package/dist/types/{utils → src/utils}/zip.d.ts +0 -0
@@ -1,616 +1,570 @@
1
- import { o as Pt, D } from "./draw-825692f1.js";
2
- import { d as dn } from "./draw-825692f1.js";
3
- import { F as p, L as P, D as h, f as O, r as wt, z as mt, s as Mt, a as It, c as St, i as vt, S as C, l as $t, d as m, b as At, p as Lt, n as K, e as E, g as kt, h as Et, j as bt, k as yt, m as j, o as M, A as v, q as tt, t as I, u as Ct, v as Ft, E as nt, R as Dt, Q as et, C as it, w as xt, B as Rt } from "./Diagram-8c3c5e1b.js";
4
- import { x as wn } from "./Diagram-8c3c5e1b.js";
5
- function S(t) {
6
- if (t instanceof p)
1
+ var lt = Object.defineProperty;
2
+ var ut = (t, e, n) => e in t ? lt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var p = (t, e, n) => ut(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { o as gt, D } from "./draw-DqsKIWJD.js";
5
+ import { d as Pe } from "./draw-DqsKIWJD.js";
6
+ import { F as d, L as P, D as g, a as B, s as ht, b as pt, c as dt, i as mt, S as C, l as Pt, p as wt, d as Mt, e as X, g as It } from "./models-WQ-B7GSL.js";
7
+ import { h as Me } from "./models-WQ-B7GSL.js";
8
+ import { r as St, z as bt, l as Lt, f as w, n as Y, i as E, a as vt, s as kt, k as At, m as j, L as S, A as b, d as M, t as Et, c as yt, B as Ft, E as Ct, Q as xt, C as Dt } from "./QuadraticBezier-BzVqiExF.js";
9
+ import { s as Rt, a as Ot, b as Bt, c as $t, d as Gt, w as z } from "./svg-BylQQgsL.js";
10
+ function I(t) {
11
+ if (t instanceof d)
7
12
  return [t];
8
13
  if (t instanceof P)
9
- return [new p(t)];
10
- if (t instanceof h)
14
+ return [new d(t)];
15
+ if (t instanceof g)
11
16
  return t.figures;
12
17
  throw new Error("Unknown shape");
13
18
  }
14
- function st(t, n, e = 1e-9) {
15
- let i = [];
16
- const r = [], s = new Array(n.segments.length).fill(0).map(() => []);
17
- n.segments.forEach((c, f) => {
19
+ function tt(t, e, n = 1e-9) {
20
+ let s = [];
21
+ const r = [], i = new Array(e.segments.length).fill(0).map(() => []);
22
+ e.segments.forEach((c, f) => {
18
23
  t.segments.forEach((a) => {
19
- const { intersections: u, overlaps: d } = O(
24
+ const { intersections: u, overlaps: m } = B(
20
25
  c,
21
26
  a,
22
- e
27
+ n
23
28
  );
24
- i.push(...u), s[f].push(...u), r.push(...d);
25
- const g = d.flatMap((l) => [
29
+ s.push(...u), i[f].push(...u), r.push(...m);
30
+ const h = m.flatMap((l) => [
26
31
  l.firstPoint,
27
32
  l.lastPoint
28
33
  ]);
29
- i.push(...g), s[f].push(...g);
34
+ s.push(...h), i[f].push(...h);
30
35
  });
31
- }), i = wt(i, e);
32
- const o = mt([n.segments, s]).flatMap(([c, f]) => f.length ? c.splitAt(f) : [c]);
36
+ }), s = St(s, n);
37
+ const o = bt([e.segments, i]).flatMap(([c, f]) => f.length ? c.splitAt(f) : [c]);
33
38
  return Array.from(
34
- Mt(
39
+ ht(
35
40
  o,
36
- i,
41
+ s,
37
42
  r
38
43
  )
39
44
  );
40
45
  }
41
- function B(t, n, e = !1) {
42
- return st(n, t).filter((r) => {
43
- const s = r.segments[0].midPoint;
44
- return n.onStroke(s) ? !e : !n.contains(s);
46
+ function $(t, e, n = !1) {
47
+ return tt(e, t).filter((r) => {
48
+ const i = r.segments[0].midPoint;
49
+ return e.onStroke(i) ? !n : !e.contains(i);
45
50
  });
46
51
  }
47
- function G(t, n, e = !1) {
48
- return st(n, t).filter((r) => {
49
- const s = r.segments[0].midPoint;
50
- return n.onStroke(s) ? !e : n.contains(s);
52
+ function G(t, e, n = !1) {
53
+ return tt(e, t).filter((r) => {
54
+ const i = r.segments[0].midPoint;
55
+ return e.onStroke(i) ? !n : e.contains(i);
51
56
  });
52
57
  }
53
- function z(t, n, e = !1) {
54
- const i = B(
58
+ function V(t, e, n = !1) {
59
+ const s = $(
55
60
  t,
56
- n.contour,
57
- e
58
- ), r = n.holes.flatMap(
59
- (s) => G(t, s, e)
61
+ e.contour,
62
+ n
63
+ ), r = e.holes.flatMap(
64
+ (i) => G(t, i, n)
60
65
  );
61
- return [...i, ...r];
66
+ return [...s, ...r];
62
67
  }
63
- function _(t, n, e = !1) {
64
- let i = G(
68
+ function _(t, e, n = !1) {
69
+ let s = G(
65
70
  t,
66
- n.contour,
67
- e
71
+ e.contour,
72
+ n
68
73
  );
69
- return n.holes.forEach((r) => {
70
- i = i.flatMap(
71
- (s) => B(s, r, e)
74
+ return e.holes.forEach((r) => {
75
+ s = s.flatMap(
76
+ (i) => $(i, r, n)
72
77
  );
73
- }), i;
78
+ }), s;
74
79
  }
75
- function Ot(t, n) {
76
- return new h(
77
- It(S(t), S(n))
80
+ function Tt(t, e) {
81
+ return new g(
82
+ pt(I(t), I(e))
78
83
  );
79
84
  }
80
- function b(t) {
85
+ function y(t) {
81
86
  return t.reduce(
82
- (n, e) => Ot(n, e),
83
- new h()
87
+ (e, n) => Tt(e, n),
88
+ new g()
84
89
  );
85
90
  }
86
- function rt(t, n) {
87
- return new h(
88
- St(S(t), S(n))
91
+ function et(t, e) {
92
+ return new g(
93
+ dt(I(t), I(e))
89
94
  );
90
95
  }
91
- function sn(t, n) {
92
- return new h(
93
- vt(S(t), S(n))
96
+ function oe(t, e) {
97
+ return new g(
98
+ mt(I(t), I(e))
94
99
  );
95
100
  }
96
- function rn(t, n, e = !0) {
97
- if (n instanceof P)
98
- return B(t, n, e);
99
- if (n instanceof p)
100
- return z(t, n, e);
101
- let i = [new C([...t.segments])];
102
- return n.figures.forEach((r) => {
103
- i = i.flatMap((s) => z(s, r, e));
104
- }), i;
105
- }
106
- function on(t, n, e = !1) {
107
- if (n instanceof P)
108
- return G(t, n, e);
109
- if (n instanceof p)
110
- return _(t, n, e);
111
- let i = [new C([...t.segments])];
112
- return n.figures.forEach((r) => {
113
- i = i.flatMap((s) => _(s, r, e));
114
- }), i;
115
- }
116
- function q(t) {
101
+ function ae(t, e, n = !0) {
102
+ if (e instanceof P)
103
+ return $(t, e, n);
104
+ if (e instanceof d)
105
+ return V(t, e, n);
106
+ let s = [new C([...t.segments])];
107
+ return e.figures.forEach((r) => {
108
+ s = s.flatMap((i) => V(i, r, n));
109
+ }), s;
110
+ }
111
+ function ce(t, e, n = !1) {
112
+ if (e instanceof P)
113
+ return G(t, e, n);
114
+ if (e instanceof d)
115
+ return _(t, e, n);
116
+ let s = [new C([...t.segments])];
117
+ return e.figures.forEach((r) => {
118
+ s = s.flatMap((i) => _(i, r, n));
119
+ }), s;
120
+ }
121
+ function N(t) {
117
122
  return t < 0 ? "before" : t > 1 ? "after" : "between";
118
123
  }
119
- const N = (t, n, e) => {
120
- if (e === "before")
121
- return t.distanceFrom(n.firstPoint);
122
- if (e === "after")
123
- return t.distanceFrom(n.lastPoint);
124
+ const q = (t, e, n) => {
125
+ if (n === "before")
126
+ return t.distanceFrom(e.firstPoint);
127
+ if (n === "after")
128
+ return t.distanceFrom(e.lastPoint);
124
129
  throw new Error("Invalid position");
125
130
  };
126
- function Bt(t, n) {
127
- const e = $t(t, n);
128
- if (e === "parallel")
131
+ function Ut(t, e) {
132
+ const n = Lt(t, e);
133
+ if (n === "parallel")
129
134
  return Math.min(
130
- t.distanceFrom(n.firstPoint),
131
- t.distanceFrom(n.lastPoint)
135
+ t.distanceFrom(e.firstPoint),
136
+ t.distanceFrom(e.lastPoint)
132
137
  );
133
- const { intersectionParam1: i, intersectionParam2: r } = e, s = q(i), o = q(r);
134
- if (s === "between" && o === "between")
138
+ const { intersectionParam1: s, intersectionParam2: r } = n, i = N(s), o = N(r);
139
+ if (i === "between" && o === "between")
135
140
  return 0;
136
- if (s === "between" && o !== "between")
137
- return N(t, n, o);
138
- if (o === "between" && s !== "between")
139
- return N(n, t, s);
140
- if (s === "before" && o === "before")
141
- return m(t.firstPoint, n.firstPoint);
142
- if (s === "after" && o === "after")
143
- return m(t.lastPoint, n.lastPoint);
144
- if (s === "before" && o === "after")
145
- return m(t.firstPoint, n.lastPoint);
146
- if (s === "after" && o === "before")
147
- return m(t.lastPoint, n.firstPoint);
141
+ if (i === "between" && o !== "between")
142
+ return q(t, e, o);
143
+ if (o === "between" && i !== "between")
144
+ return q(e, t, i);
145
+ if (i === "before" && o === "before")
146
+ return w(t.firstPoint, e.firstPoint);
147
+ if (i === "after" && o === "after")
148
+ return w(t.lastPoint, e.lastPoint);
149
+ if (i === "before" && o === "after")
150
+ return w(t.firstPoint, e.lastPoint);
151
+ if (i === "after" && o === "before")
152
+ return w(t.lastPoint, e.firstPoint);
148
153
  throw new Error("Invalid position");
149
154
  }
150
- function Q(t, n) {
151
- if (At(t, n).length > 0)
155
+ function J(t, e) {
156
+ if (Pt(t, e).length > 0)
152
157
  return 0;
153
- const e = Lt(t, n.center);
154
- if (t.isOnSegment(e)) {
155
- const i = m(e, n.center);
156
- if (Math.abs(i - n.radius) < t.precision && n.isOnSegment(e))
158
+ const n = wt(t, e.center);
159
+ if (t.isOnSegment(n)) {
160
+ const s = w(n, e.center);
161
+ if (Math.abs(s - e.radius) < t.precision && e.isOnSegment(n))
157
162
  return 0;
158
- if (i - n.radius > t.precision) {
159
- const r = K(
160
- E(e, n.center)
161
- ), s = kt(
162
- n.center,
163
- Et(r, n.radius)
163
+ if (s - e.radius > t.precision) {
164
+ const r = Y(
165
+ E(n, e.center)
166
+ ), i = vt(
167
+ e.center,
168
+ kt(r, e.radius)
164
169
  );
165
- if (n.isOnSegment(s))
166
- return m(s, e);
170
+ if (e.isOnSegment(i))
171
+ return w(i, n);
167
172
  }
168
173
  }
169
174
  return Math.min(
170
- n.distanceFrom(t.firstPoint),
171
- n.distanceFrom(t.lastPoint),
172
- t.distanceFrom(n.firstPoint),
173
- t.distanceFrom(n.lastPoint)
175
+ e.distanceFrom(t.firstPoint),
176
+ e.distanceFrom(t.lastPoint),
177
+ t.distanceFrom(e.firstPoint),
178
+ t.distanceFrom(e.lastPoint)
174
179
  );
175
180
  }
176
- const Gt = (t, n) => {
177
- const e = t.angleToParam(n.firstAngle);
178
- if (t.isValidParameter(e))
179
- return !0;
180
- const i = t.angleToParam(n.lastAngle);
181
- return !!t.isValidParameter(i);
181
+ const zt = (t, e) => {
182
+ const n = t.angleToParam(e.firstAngle);
183
+ if (t.isValidParameter(n)) return !0;
184
+ const s = t.angleToParam(e.lastAngle);
185
+ return !!t.isValidParameter(s);
182
186
  };
183
- function Tt(t, n) {
184
- if (bt(t, n, !0).length > 0)
185
- return 0;
186
- const e = m(t.center, n.center);
187
- if (e < t.precision && Gt(t, n))
188
- return Math.abs(t.radius - n.radius);
189
- const i = K(E(n.center, t.center)), r = e - Math.abs(t.radius - n.radius) < t.precision;
190
- let s = yt(i);
191
- r && n.radius > t.radius && (s += Math.PI);
192
- const o = r ? s : s + Math.PI, c = t.angleToParam(s), f = n.angleToParam(o);
193
- return t.isValidParameter(c) && n.isValidParameter(f) ? m(t.paramPoint(c), n.paramPoint(f)) : Math.min(
194
- t.distanceFrom(n.firstPoint),
195
- t.distanceFrom(n.lastPoint),
196
- n.distanceFrom(t.firstPoint),
197
- n.distanceFrom(t.lastPoint)
187
+ function Vt(t, e) {
188
+ if (Mt(t, e, !0).length > 0) return 0;
189
+ const n = w(t.center, e.center);
190
+ if (n < t.precision && zt(t, e))
191
+ return Math.abs(t.radius - e.radius);
192
+ const s = Y(E(e.center, t.center)), r = n - Math.abs(t.radius - e.radius) < t.precision;
193
+ let i = At(s);
194
+ r && e.radius > t.radius && (i += Math.PI);
195
+ const o = r ? i : i + Math.PI, c = t.angleToParam(i), f = e.angleToParam(o);
196
+ return t.isValidParameter(c) && e.isValidParameter(f) ? w(t.paramPoint(c), e.paramPoint(f)) : Math.min(
197
+ t.distanceFrom(e.firstPoint),
198
+ t.distanceFrom(e.lastPoint),
199
+ e.distanceFrom(t.firstPoint),
200
+ e.distanceFrom(t.lastPoint)
198
201
  );
199
202
  }
200
- function Ut(t, n, e) {
201
- let i = 0, r = t.length - 1;
202
- for (; i <= r; ) {
203
- const s = Math.floor((i + r) / 2), o = e(t[s], n);
203
+ function _t(t, e, n) {
204
+ let s = 0, r = t.length - 1;
205
+ for (; s <= r; ) {
206
+ const i = Math.floor((s + r) / 2), o = n(t[i], e);
204
207
  if (o < 0)
205
- i = s + 1;
208
+ s = i + 1;
206
209
  else if (o > 0)
207
- r = s - 1;
210
+ r = i - 1;
208
211
  else
209
- return s;
212
+ return i;
210
213
  }
211
- return -(i + 1);
214
+ return -(s + 1);
212
215
  }
213
- function Vt(t, n, e) {
214
- const i = Ut(t, n, e);
215
- i < 0 ? t.splice(-(i + 1), 0, n) : t.splice(i, 0, n);
216
+ function Nt(t, e, n) {
217
+ const s = _t(t, e, n);
218
+ s < 0 ? t.splice(-(s + 1), 0, e) : t.splice(s, 0, e);
216
219
  }
217
- class zt {
220
+ class qt {
218
221
  constructor() {
222
+ p(this, "buckets");
219
223
  this.buckets = [];
220
224
  }
221
- addInterval(n) {
222
- const e = this.buckets[n.rectangle.diagonalBucketIndex];
223
- e === void 0 ? this.buckets[n.rectangle.diagonalBucketIndex] = [n] : Vt(e, n, (i, r) => i.value - r.value);
225
+ addInterval(e) {
226
+ const n = this.buckets[e.rectangle.diagonalBucketIndex];
227
+ n === void 0 ? this.buckets[e.rectangle.diagonalBucketIndex] = [e] : Nt(n, e, (s, r) => s.value - r.value);
224
228
  }
225
- removeInterval(n) {
226
- const e = this.buckets[n.rectangle.diagonalBucketIndex];
227
- if (e === void 0)
229
+ removeInterval(e) {
230
+ const n = this.buckets[e.rectangle.diagonalBucketIndex];
231
+ if (n === void 0)
228
232
  throw new Error("Interval not found");
229
- e.shift();
233
+ n.shift();
230
234
  }
231
235
  getBottomRightHullIntervals() {
232
- const n = [];
233
- for (let e = this.buckets.length - 1; e >= 0; e--) {
234
- const i = this.buckets[e];
235
- if (!i === void 0)
236
- continue;
237
- const r = i[0];
236
+ const e = [];
237
+ for (let n = this.buckets.length - 1; n >= 0; n--) {
238
+ const s = this.buckets[n];
239
+ if (!s === void 0) continue;
240
+ const r = s[0];
238
241
  if (r !== void 0) {
239
- if (!n.length) {
240
- n.push(r);
242
+ if (!e.length) {
243
+ e.push(r);
241
244
  continue;
242
245
  }
243
- for (; n.length && n[n.length - 1].value >= r.value; )
244
- n.pop();
245
- for (; n.length >= 2; ) {
246
- const s = n[n.length - 1], o = n[n.length - 2], c = (r.value - o.value) / ((r.rectangle.diagonal - o.rectangle.diagonal) * 2);
247
- if (o.value + (s.rectangle.diagonal - o.rectangle.diagonal) / 2 * c < s.value)
248
- n.pop();
246
+ for (; e.length && e[e.length - 1].value >= r.value; )
247
+ e.pop();
248
+ for (; e.length >= 2; ) {
249
+ const i = e[e.length - 1], o = e[e.length - 2], c = (r.value - o.value) / ((r.rectangle.diagonal - o.rectangle.diagonal) * 2);
250
+ if (o.value + (i.rectangle.diagonal - o.rectangle.diagonal) / 2 * c < i.value)
251
+ e.pop();
249
252
  else
250
253
  break;
251
254
  }
252
- n.push(r);
255
+ e.push(r);
253
256
  }
254
257
  }
255
- return n;
258
+ return e;
256
259
  }
257
260
  }
258
- class _t {
259
- constructor(n, e) {
260
- this.x = n, this.y = e, this.xLength = Math.pow(3, -n), this.yLength = Math.pow(3, -e), this.diagonal = Math.sqrt(
261
+ class Jt {
262
+ constructor(e, n) {
263
+ p(this, "diagonal");
264
+ p(this, "diagonalBucketIndex");
265
+ p(this, "xLength");
266
+ p(this, "yLength");
267
+ p(this, "index");
268
+ this.x = e, this.y = n, this.xLength = Math.pow(3, -e), this.yLength = Math.pow(3, -n), this.diagonal = Math.sqrt(
261
269
  this.xLength * this.xLength + this.yLength * this.yLength
262
- ), this.diagonalBucketIndex = n + e, this.index = `${n},${e}`;
270
+ ), this.diagonalBucketIndex = e + n, this.index = `${e},${n}`;
263
271
  }
264
272
  }
265
- class qt {
266
- constructor(n, e = 1e-8, i = 1e3, r = 1e-6) {
267
- this.fcn = n, this.endTolerance = e, this.maxIterations = i, this.epsilon = r, this.fcn = n, this.epsilon = r, this.endTolerance = e, this.maxIterations = i, this.rectangles = /* @__PURE__ */ new Map(), this.buckets = new zt();
268
- const s = [0.5, 0.5], o = this.rect(0, 0), c = this.fcn(s);
269
- this.buckets.addInterval(new k(s, c, o)), this.fMin = c, this.argMin = s, this.tol = o.diagonal;
273
+ class Qt {
274
+ constructor(e, n = 1e-8, s = 1e3, r = 1e-6) {
275
+ p(this, "rectangles");
276
+ p(this, "buckets");
277
+ p(this, "fMin");
278
+ p(this, "argMin");
279
+ p(this, "tol");
280
+ this.fcn = e, this.endTolerance = n, this.maxIterations = s, this.epsilon = r, this.fcn = e, this.epsilon = r, this.endTolerance = n, this.maxIterations = s, this.rectangles = /* @__PURE__ */ new Map(), this.buckets = new qt();
281
+ const i = [0.5, 0.5], o = this.rect(0, 0), c = this.fcn(i);
282
+ this.buckets.addInterval(new A(i, c, o)), this.fMin = c, this.argMin = i, this.tol = o.diagonal;
270
283
  }
271
- registerInterval(n) {
272
- this.buckets.addInterval(n), n.value <= this.fMin && (this.fMin = n.value, this.argMin = n.center, this.tol = n.rectangle.diagonal);
284
+ registerInterval(e) {
285
+ this.buckets.addInterval(e), e.value <= this.fMin && (this.fMin = e.value, this.argMin = e.center, this.tol = e.rectangle.diagonal);
273
286
  }
274
- rect(n, e) {
275
- const i = `${n},${e}`;
276
- return this.rectangles.has(i) || this.rectangles.set(i, new _t(n, e)), this.rectangles.get(i);
287
+ rect(e, n) {
288
+ const s = `${e},${n}`;
289
+ return this.rectangles.has(s) || this.rectangles.set(s, new Jt(e, n)), this.rectangles.get(s);
277
290
  }
278
- splitInterval(n) {
279
- let e, i, r;
280
- const [s, o] = n.center;
281
- return n.rectangle.x <= n.rectangle.y ? (e = this.rect(n.rectangle.x + 1, n.rectangle.y), i = [s - e.xLength, o], r = [s + e.xLength, o]) : (e = this.rect(n.rectangle.x, n.rectangle.y + 1), i = [s, o - e.yLength], r = [s, o + e.yLength]), [
282
- new k(i, this.fcn(i), e),
283
- new k(n.center, n.value, e),
284
- new k(r, this.fcn(r), e)
291
+ splitInterval(e) {
292
+ let n, s, r;
293
+ const [i, o] = e.center;
294
+ return e.rectangle.x <= e.rectangle.y ? (n = this.rect(e.rectangle.x + 1, e.rectangle.y), s = [i - n.xLength, o], r = [i + n.xLength, o]) : (n = this.rect(e.rectangle.x, e.rectangle.y + 1), s = [i, o - n.yLength], r = [i, o + n.yLength]), [
295
+ new A(s, this.fcn(s), n),
296
+ new A(e.center, e.value, n),
297
+ new A(r, this.fcn(r), n)
285
298
  ];
286
299
  }
287
300
  single_iteration() {
288
- const n = this.buckets.getBottomRightHullIntervals();
289
- for (; n.length >= 2; ) {
290
- const e = n[0], i = n[1], r = (i.value - e.value) / ((i.rectangle.diagonal - e.rectangle.diagonal) / 2), s = e.value - r * i.value / 2;
291
- if ((this.fMin - s) / Math.abs(this.fMin) < this.epsilon)
292
- n.shift();
301
+ const e = this.buckets.getBottomRightHullIntervals();
302
+ for (; e.length >= 2; ) {
303
+ const n = e[0], s = e[1], r = (s.value - n.value) / ((s.rectangle.diagonal - n.rectangle.diagonal) / 2), i = n.value - r * s.value / 2;
304
+ if ((this.fMin - i) / Math.abs(this.fMin) < this.epsilon)
305
+ e.shift();
293
306
  else
294
307
  break;
295
308
  }
296
- n.forEach((e) => {
297
- this.buckets.removeInterval(e);
309
+ e.forEach((n) => {
310
+ this.buckets.removeInterval(n);
298
311
  });
299
- for (const e of n) {
300
- const [i, r, s] = this.splitInterval(e);
301
- this.registerInterval(i), this.registerInterval(r), this.registerInterval(s);
312
+ for (const n of e) {
313
+ const [s, r, i] = this.splitInterval(n);
314
+ this.registerInterval(s), this.registerInterval(r), this.registerInterval(i);
302
315
  }
303
316
  }
304
317
  run() {
305
- let n = 0;
306
- for (; this.tol > this.endTolerance / 2 && (this.single_iteration(), n++, !(n > this.maxIterations)); )
318
+ let e = 0;
319
+ for (; this.tol > this.endTolerance / 2 && (this.single_iteration(), e++, !(e > this.maxIterations)); )
307
320
  ;
308
321
  return {
309
322
  fMin: this.fMin,
310
323
  argMin: this.argMin,
311
324
  tol: this.tol,
312
- iterations: n
325
+ iterations: e
313
326
  };
314
327
  }
315
328
  }
316
- class k {
317
- constructor(n, e, i) {
318
- this.center = n, this.value = e, this.rectangle = i;
329
+ class A {
330
+ constructor(e, n, s) {
331
+ this.center = e, this.value = n, this.rectangle = s;
319
332
  }
320
333
  }
321
- function Nt(t, n = 1e-8, e = 1e3, i = 1e-6) {
322
- return new qt(
334
+ function Zt(t, e = 1e-8, n = 1e3, s = 1e-6) {
335
+ return new Qt(
323
336
  t,
324
- n,
325
337
  e,
326
- i
338
+ n,
339
+ s
327
340
  ).run();
328
341
  }
329
- function Qt(t, n, e = 1e-9) {
330
- const i = Nt((r) => {
331
- const s = t.paramPoint(r[0]), o = n.paramPoint(r[1]);
332
- return j(s, o);
333
- }, e);
334
- return Math.sqrt(i.fMin);
342
+ function Ht(t, e, n = 1e-9) {
343
+ const s = Zt((r) => {
344
+ const i = t.paramPoint(r[0]), o = e.paramPoint(r[1]);
345
+ return j(i, o);
346
+ }, n);
347
+ return Math.sqrt(s.fMin);
335
348
  }
336
- function Zt(t, n) {
337
- return t instanceof M && n instanceof M ? Bt(t, n) : t instanceof M && n instanceof v ? Q(t, n) : t instanceof v && n instanceof M ? Q(n, t) : t instanceof v && n instanceof v ? Tt(t, n) : Qt(t, n);
349
+ function Wt(t, e) {
350
+ return t instanceof S && e instanceof S ? Ut(t, e) : t instanceof S && e instanceof b ? J(t, e) : t instanceof b && e instanceof S ? J(e, t) : t instanceof b && e instanceof b ? Vt(t, e) : Ht(t, e);
338
351
  }
339
352
  const T = 1e-8;
340
- function x(t, n, e = !0) {
341
- const i = t.map((a) => ({
342
- offset: Pt(a, n),
353
+ function R(t, e, n = !0) {
354
+ const s = t.map((a) => ({
355
+ offset: gt(a, e),
343
356
  original: a
344
357
  })), r = [];
345
- let s = e ? null : i.at(-1), o = e ? i.at(-1) : null;
346
- if (r.length === 1)
347
- return r;
358
+ let i = n ? null : s.at(-1), o = n ? s.at(-1) : null;
359
+ if (r.length === 1) return r;
348
360
  const c = (a) => {
349
- s ? a.offset instanceof D ? I(a.offset.firstPoint, a.offset.lastPoint) || r.push(
350
- new M(a.offset.firstPoint, a.offset.lastPoint)
351
- ) : r.push(a.offset) : s = a;
361
+ i ? a.offset instanceof D ? M(a.offset.firstPoint, a.offset.lastPoint) || r.push(
362
+ new S(a.offset.firstPoint, a.offset.lastPoint)
363
+ ) : r.push(a.offset) : i = a;
352
364
  }, f = function* () {
353
- for (const a of i.slice(0, -1))
365
+ for (const a of s.slice(0, -1))
354
366
  yield a;
355
- if (!s)
356
- throw new Error("Bug in the offset algorithm");
357
- yield s;
367
+ if (!i) throw new Error("Bug in the offset algorithm");
368
+ yield i;
358
369
  };
359
370
  for (const a of f()) {
360
371
  if (!o) {
361
372
  o = a;
362
373
  continue;
363
374
  }
364
- const u = o.offset.lastPoint, d = a.offset.firstPoint;
365
- if (I(u, d)) {
375
+ const u = o.offset.lastPoint, m = a.offset.firstPoint;
376
+ if (M(u, m)) {
366
377
  c(o), o = a;
367
378
  continue;
368
379
  }
369
- let g = [];
380
+ let h = [];
370
381
  if (!(o.offset instanceof D) && !(a.offset instanceof D)) {
371
- const { intersections: $, overlaps: F } = O(
382
+ const { intersections: L, overlaps: x } = B(
372
383
  o.offset,
373
384
  a.offset,
374
385
  T / 100
375
386
  );
376
- g = [
377
- ...$,
378
- ...F.flatMap((A) => [A.firstPoint, A.lastPoint])
387
+ h = [
388
+ ...L,
389
+ ...x.flatMap((v) => [v.firstPoint, v.lastPoint])
379
390
  ];
380
391
  }
381
- if (g.length > 0) {
382
- let $ = g[0];
383
- if (g.length > 1) {
384
- const pt = o == null ? void 0 : o.original.lastPoint, V = g.map(
385
- (dt) => j(dt, pt)
392
+ if (h.length > 0) {
393
+ let L = h[0];
394
+ if (h.length > 1) {
395
+ const ct = o == null ? void 0 : o.original.lastPoint, U = h.map(
396
+ (ft) => j(ft, ct)
386
397
  );
387
- $ = g[V.indexOf(Math.min(...V))];
398
+ L = h[U.indexOf(Math.min(...U))];
388
399
  }
389
- const F = o.offset.splitAt([
390
- $
391
- ])[0], A = a.offset.splitAt([$]).at(-1);
392
- if (!A)
393
- throw new Error("Bug in the splitting algo in offset");
400
+ const x = o.offset.splitAt([
401
+ L
402
+ ])[0], v = a.offset.splitAt([L]).at(-1);
403
+ if (!v) throw new Error("Bug in the splitting algo in offset");
394
404
  c({
395
- offset: F,
405
+ offset: x,
396
406
  original: o.original
397
- }), o = { offset: A, original: a.original };
407
+ }), o = { offset: v, original: a.original };
398
408
  continue;
399
409
  }
400
- const l = o.original.lastPoint, L = Ft(
401
- E(d, l),
410
+ const l = o.original.lastPoint, k = yt(
411
+ E(m, l),
402
412
  E(u, l)
403
- ) > 0, gt = new v(u, d, l, L);
404
- c(o), r.push(gt), o = a;
413
+ ) > 0, at = new b(u, m, l, k);
414
+ c(o), r.push(at), o = a;
405
415
  }
406
416
  return o && c(o), r;
407
417
  }
408
- function ot(t) {
409
- const n = /* @__PURE__ */ new Map(), e = (i, r) => {
410
- const s = n.get(i) || [];
411
- n.set(i, [...s, ...r]);
418
+ function nt(t) {
419
+ const e = /* @__PURE__ */ new Map(), n = (s, r) => {
420
+ const i = e.get(s) || [];
421
+ e.set(s, [...i, ...r]);
412
422
  };
413
- return t.forEach((i, r) => {
414
- t.slice(r + 1).forEach((s, o) => {
415
- const { intersections: c, overlaps: f } = O(i, s, T), a = [
423
+ return t.forEach((s, r) => {
424
+ t.slice(r + 1).forEach((i, o) => {
425
+ const { intersections: c, overlaps: f } = B(s, i, T), a = [
416
426
  ...c,
417
427
  ...f.flatMap((u) => [u.firstPoint, u.lastPoint])
418
428
  ].filter((u) => {
419
- const d = I(u, i.firstPoint) || I(u, i.lastPoint), g = I(u, s.firstPoint) || I(u, s.lastPoint);
420
- return !(d && g);
429
+ const m = M(u, s.firstPoint) || M(u, s.lastPoint), h = M(u, i.firstPoint) || M(u, i.lastPoint);
430
+ return !(m && h);
421
431
  });
422
- a.length && (e(r, a), e(o + r + 1, a));
432
+ a.length && (n(r, a), n(o + r + 1, a));
423
433
  });
424
- }), n;
425
- }
426
- function at(t, n) {
427
- return n.flatMap((e, i) => {
428
- if (!t.has(i))
429
- return e;
430
- const r = t.get(i);
431
- return r ? e.splitAt(r) : e;
434
+ }), e;
435
+ }
436
+ function st(t, e) {
437
+ return e.flatMap((n, s) => {
438
+ if (!t.has(s)) return n;
439
+ const r = t.get(s);
440
+ return r ? n.splitAt(r) : n;
432
441
  });
433
442
  }
434
- function ct(t, n, e) {
435
- return t.filter((i) => !n.segments.some((s) => Zt(s, i) < Math.abs(e) - T));
443
+ function it(t, e, n) {
444
+ return t.filter((s) => !e.segments.some((i) => Wt(i, s) < Math.abs(n) - T));
436
445
  }
437
- function y(t, n) {
438
- const e = t.clockwise ? n : -n, i = x(t.segments, e);
439
- if (i.length < 2)
440
- return new h();
441
- const r = ot(i);
446
+ function F(t, e) {
447
+ const n = t.clockwise ? e : -e, s = R(t.segments, n);
448
+ if (s.length < 2) return new g();
449
+ const r = nt(s);
442
450
  if (!r.size) {
443
- const a = new P(i);
444
- return new h([new p(a)]);
451
+ const a = new P(s);
452
+ return new g([new d(a)]);
445
453
  }
446
- const s = at(
454
+ const i = st(
447
455
  r,
448
- i
449
- ), o = ct(s, t, n);
450
- if (!o.length)
451
- return new h();
452
- const f = tt(o).filter((a) => a.length > 1).filter((a) => I(a[0].firstPoint, a.at(-1).lastPoint)).map((a) => new P(a));
453
- return f.length ? new h(f.map((a) => new p(a))) : new h();
454
- }
455
- function Jt(t, n, e = "round") {
456
- const i = n / 2, r = x(t.segments, i, !1), s = x(t.segments, -i, !1).map(
456
+ s
457
+ ), o = it(i, t, e);
458
+ if (!o.length) return new g();
459
+ const f = X(o).filter((a) => a.length > 1).filter((a) => M(a[0].firstPoint, a.at(-1).lastPoint)).map((a) => new P(a));
460
+ return f.length ? new g(f.map((a) => new d(a))) : new g();
461
+ }
462
+ function Kt(t, e, n = "round") {
463
+ const s = e / 2, r = R(t.segments, s, !1), i = R(t.segments, -s, !1).map(
457
464
  (l) => l.reverse()
458
465
  );
459
- s.reverse();
460
- const o = (l, L) => e === "round" ? Ct(
466
+ i.reverse();
467
+ const o = (l, k) => n === "round" ? Et(
461
468
  l.lastPoint,
462
- L.firstPoint,
469
+ k.firstPoint,
463
470
  l.tangentAtLastPoint
464
- ) : new M(l.lastPoint, L.firstPoint), c = [
471
+ ) : new S(l.lastPoint, k.firstPoint), c = [
465
472
  ...r,
466
473
  o(
467
474
  r[r.length - 1],
468
- s[0]
475
+ i[0]
469
476
  ),
470
- ...s,
477
+ ...i,
471
478
  o(
472
- s[s.length - 1],
479
+ i[i.length - 1],
473
480
  r[0]
474
481
  )
475
- ], f = ot(c);
482
+ ], f = nt(c);
476
483
  if (!f.size) {
477
484
  const l = new P(c);
478
- return new h([new p(l)]);
485
+ return new g([new d(l)]);
479
486
  }
480
- const a = at(
487
+ const a = st(
481
488
  f,
482
489
  c
483
- ), u = ct(a, t, i);
484
- if (!u.length)
485
- return new h();
486
- const g = tt(u).filter((l) => l.length > 1).filter((l) => I(l[0].firstPoint, l.at(-1).lastPoint)).map((l) => new P(l));
487
- return g.length ? new h(g.map((l) => new p(l))) : new h();
488
- }
489
- function Ht(t, n) {
490
- const e = t.map((i) => {
491
- const r = b(
492
- i.holes.map((s) => y(s, n))
490
+ ), u = it(a, t, s);
491
+ if (!u.length) return new g();
492
+ const h = X(u).filter((l) => l.length > 1).filter((l) => M(l[0].firstPoint, l.at(-1).lastPoint)).map((l) => new P(l));
493
+ return h.length ? new g(h.map((l) => new d(l))) : new g();
494
+ }
495
+ function Xt(t, e) {
496
+ const n = t.map((s) => {
497
+ const r = y(
498
+ s.holes.map((i) => F(i, e))
493
499
  );
494
- return rt(y(i.contour, n), r);
500
+ return et(F(s.contour, e), r);
495
501
  });
496
- return b(e);
502
+ return y(n);
497
503
  }
498
- function Wt(t, n) {
499
- const e = Math.abs(n / 2), i = t.map(
500
- (r) => b(
501
- r.allLoops.map((s) => rt(y(s, e), y(s, -e)))
504
+ function Yt(t, e) {
505
+ const n = Math.abs(e / 2), s = t.map(
506
+ (r) => y(
507
+ r.allLoops.map((i) => et(F(i, n), F(i, -n)))
502
508
  )
503
509
  );
504
- return b(i);
505
- }
506
- function an(t, n) {
507
- return Ht(S(t), n);
508
- }
509
- function cn(t, n, { endCap: e = "round" } = {}) {
510
- return t instanceof C ? Jt(t, n, e) : Wt(S(t), n);
511
- }
512
- function w([t, n]) {
513
- return `${t} ${n}`;
514
- }
515
- function U(t) {
516
- if (t instanceof M)
517
- return `L ${w(t.lastPoint)}`;
518
- if (t instanceof v)
519
- return `A ${t.radius} ${t.radius} 0 ${t.angularLength > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${w(t.lastPoint)}`;
520
- if (t instanceof nt)
521
- return `A ${t.majorRadius} ${t.minorRadius} ${t.tiltAngle * Dt} ${t.deltaAngle > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${w(t.lastPoint)}`;
522
- if (t instanceof et)
523
- return `Q ${[
524
- w(t.controlPoint),
525
- w(t.lastPoint)
526
- ].join(" ")}`;
527
- if (t instanceof it)
528
- return `C ${[
529
- w(t.firstControlPoint),
530
- w(t.lastControlPoint),
531
- w(t.lastPoint)
532
- ].join(" ")}`;
533
- throw new Error("Unknown segment type");
510
+ return y(s);
511
+ }
512
+ function fe(t, e) {
513
+ return Xt(I(t), e);
514
+ }
515
+ function le(t, e, { endCap: n = "round" } = {}) {
516
+ return t instanceof C ? Kt(t, e, n) : Yt(I(t), e);
534
517
  }
535
- function ft(t) {
536
- const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(U).join(" ");
537
- return `${n} ${e} Z`;
538
- }
539
- function lt(t) {
540
- return `<path d="${t.allLoops.map(ft).join(" ")}" />`;
541
- }
542
- function Xt(t) {
543
- return `<g>
544
- ${t.figures.map(lt).join(`
545
- `)}
546
- </g>`;
547
- }
548
- function Yt(t) {
549
- const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(U).join(" ");
550
- return `${n} ${e}`;
551
- }
552
- function Kt(t, n = 1) {
553
- const e = t.xMin - n, i = t.yMin - n;
554
- return `${e} ${i} ${t.width + 2 * n} ${t.height + 2 * n}`;
555
- }
556
- function Z(t, n, e = 1, i) {
557
- const r = Kt(n, e), s = i ? `width="${n.width + 2 * e}${i}" height="${n.height + 2 * e}${i}"` : "";
558
- return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
559
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${r}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke" ${s}>
560
- ${t}
561
- </svg>`;
562
- }
563
- function J(t) {
564
- if (t instanceof h)
565
- return Xt(t);
566
- if (t instanceof p)
567
- return lt(t);
518
+ function Q(t) {
519
+ if (t instanceof g)
520
+ return Rt(t);
521
+ if (t instanceof d)
522
+ return Ot(t);
568
523
  if (t instanceof P)
569
- return `<path d="${ft(t)}" />`;
524
+ return `<path d="${Bt(t)}" />`;
570
525
  if (t instanceof C)
571
- return `<path d="${Yt(t)}" />`;
572
- if (xt(t))
573
- return `<path d="${`M ${t.firstPoint.join(" ")}`} ${U(
526
+ return `<path d="${$t(t)}" />`;
527
+ if (It(t))
528
+ return `<path d="${`M ${t.firstPoint.join(" ")}`} ${Gt(
574
529
  t
575
530
  )}" />`;
576
531
  throw new Error("Unknown shape type");
577
532
  }
578
- const H = (t) => "shape" in t ? t.shape : t, W = (t, n) => {
579
- if (!("shape" in t))
580
- return n;
581
- const { color: e } = t;
582
- return e ? `<g stroke="${e}">${n}</g>` : n;
583
- }, X = (t) => new Rt(t.xMin, -t.yMax, t.xMax, -t.yMin);
584
- function fn(t, {
585
- margin: n = 1,
586
- unit: e = null,
587
- viewBox: i
533
+ const Z = (t) => "shape" in t ? t.shape : t, H = (t, e) => {
534
+ if (!("shape" in t)) return e;
535
+ const { color: n } = t;
536
+ return n ? `<g stroke="${n}">${e}</g>` : e;
537
+ }, W = (t) => new Ft(t.xMin, -t.yMax, t.xMax, -t.yMin);
538
+ function ue(t, {
539
+ margin: e = 1,
540
+ unit: n = null,
541
+ viewBox: s
588
542
  } = {}) {
589
543
  if (Array.isArray(t)) {
590
- const s = t.map((f) => H(f).mirror()), o = s.map((f, a) => W(t[a], J(f))).join(`
591
- `), c = s.slice(1).reduce((f, a) => f.merge(a.boundingBox), s[0].boundingBox);
592
- return Z(o, i ? X(i) : c, n, e);
544
+ const i = t.map((f) => Z(f).mirror()), o = i.map((f, a) => H(t[a], Q(f))).join(`
545
+ `), c = i.slice(1).reduce((f, a) => f.merge(a.boundingBox), i[0].boundingBox);
546
+ return z(o, s ? W(s) : c, e, n);
593
547
  }
594
- const r = H(t).mirror();
595
- return Z(
596
- W(t, J(r)),
597
- i ? X(i) : r.boundingBox,
598
- n,
599
- e
548
+ const r = Z(t).mirror();
549
+ return z(
550
+ H(t, Q(r)),
551
+ s ? W(s) : r.boundingBox,
552
+ e,
553
+ n
600
554
  );
601
555
  }
602
- const ut = (t) => {
556
+ const rt = (t) => {
603
557
  if (t.type === "LINE")
604
- return new M(t.firstPoint, t.lastPoint);
558
+ return new S(t.firstPoint, t.lastPoint);
605
559
  if (t.type === "ARC")
606
- return new v(
560
+ return new b(
607
561
  t.firstPoint,
608
562
  t.lastPoint,
609
563
  t.center,
610
564
  t.clockwise
611
565
  );
612
566
  if (t.type === "ELLIPSE_ARC")
613
- return new nt(
567
+ return new Ct(
614
568
  t.firstPoint,
615
569
  t.lastPoint,
616
570
  t.center,
@@ -621,66 +575,66 @@ const ut = (t) => {
621
575
  { angleUnits: "rad" }
622
576
  );
623
577
  if (t.type === "QUADRATIC_BEZIER")
624
- return new et(
578
+ return new xt(
625
579
  t.firstPoint,
626
580
  t.lastPoint,
627
581
  t.controlPoint
628
582
  );
629
583
  if (t.type === "CUBIC_BEZIER")
630
- return new it(
584
+ return new Dt(
631
585
  t.firstPoint,
632
586
  t.lastPoint,
633
587
  t.firstControlPoint,
634
588
  t.lastControlPoint
635
589
  );
636
590
  throw new Error("Unknown segment type");
637
- }, R = (t) => {
638
- const n = t.segments.map(ut);
639
- return new P(n);
640
- }, ht = (t) => {
641
- const n = R(t.contour), e = t.holes.map(R);
642
- return new p(n, e);
591
+ }, O = (t) => {
592
+ const e = t.segments.map(rt);
593
+ return new P(e);
594
+ }, ot = (t) => {
595
+ const e = O(t.contour), n = t.holes.map(O);
596
+ return new d(e, n);
643
597
  }, jt = (t) => {
644
- const n = t.figures.map(ht);
645
- return new h(n);
598
+ const e = t.figures.map(ot);
599
+ return new g(e);
646
600
  };
647
- function ln(t) {
601
+ function ge(t) {
648
602
  if (t.type === "DIAGRAM")
649
603
  return jt(t);
650
604
  if (t.type === "FIGURE")
651
- return ht(t);
605
+ return ot(t);
652
606
  if (t.type === "LOOP")
653
- return R(t);
607
+ return O(t);
654
608
  if (t.type === "LINE" || t.type === "ARC" || t.type === "ELLIPSE_ARC" || t.type === "CUBIC_BEZIER")
655
- return ut(t);
609
+ return rt(t);
656
610
  throw new Error("Unknown shape type");
657
611
  }
658
- const Y = Math.PI / 180, tn = 180 / Math.PI;
659
- function un(t, n) {
660
- const e = Math.cos(n * Y) * t, i = Math.sin(n * Y) * t;
661
- return [e, i];
612
+ const K = Math.PI / 180, te = 180 / Math.PI;
613
+ function he(t, e) {
614
+ const n = Math.cos(e * K) * t, s = Math.sin(e * K) * t;
615
+ return [n, s];
662
616
  }
663
- function hn([t, n]) {
664
- const e = Math.sqrt(t * t + n * n), i = Math.atan2(n, t) * tn;
665
- return [e, i];
617
+ function pe([t, e]) {
618
+ const n = Math.sqrt(t * t + e * e), s = Math.atan2(e, t) * te;
619
+ return [n, s];
666
620
  }
667
621
  export {
668
- Y as DEG2RAD,
669
- tn as RAD2DEG,
670
- hn as cartesianToPolar,
671
- on as confineStrand,
672
- rt as cut,
673
- dn as draw,
674
- rn as eraseStrand,
675
- wn as exportJSON,
676
- fn as exportSVG,
677
- Ot as fuse,
678
- b as fuseAll,
679
- ln as importJSON,
680
- sn as intersect,
681
- an as offset,
682
- cn as outlineStroke,
683
- un as polarToCartesian,
684
- J as svgBody
622
+ K as DEG2RAD,
623
+ te as RAD2DEG,
624
+ pe as cartesianToPolar,
625
+ ce as confineStrand,
626
+ et as cut,
627
+ Pe as draw,
628
+ ae as eraseStrand,
629
+ Me as exportJSON,
630
+ ue as exportSVG,
631
+ Tt as fuse,
632
+ y as fuseAll,
633
+ ge as importJSON,
634
+ oe as intersect,
635
+ fe as offset,
636
+ le as outlineStroke,
637
+ he as polarToCartesian,
638
+ Q as svgBody
685
639
  };
686
640
  //# sourceMappingURL=pantograph.js.map