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