pantograph2d 0.8.0 → 0.9.0

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