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,1700 +0,0 @@
1
- function X(e, t, n, s) {
2
- return e <= s && t >= n;
3
- }
4
- class q {
5
- constructor(t = 1 / 0, n = 1 / 0, s = -1 / 0, i = -1 / 0) {
6
- this.xMin = t, this.yMin = n, this.xMax = s, this.yMax = i;
7
- }
8
- get width() {
9
- return this.xMax - this.xMin;
10
- }
11
- get height() {
12
- return this.yMax - this.yMin;
13
- }
14
- contains(t) {
15
- const [n, s] = t;
16
- return X(this.xMin, this.xMax, n, n) && X(this.yMin, this.yMax, s, s);
17
- }
18
- overlaps(t) {
19
- return X(this.xMin, this.xMax, t.xMin, t.xMax) && X(this.yMin, this.yMax, t.yMin, t.yMax);
20
- }
21
- addPoint(t) {
22
- const [n, s] = t;
23
- return new q(
24
- Math.min(this.xMin, n),
25
- Math.min(this.yMin, s),
26
- Math.max(this.xMax, n),
27
- Math.max(this.yMax, s)
28
- );
29
- }
30
- merge(t) {
31
- return new q(
32
- Math.min(this.xMin, t.xMin),
33
- Math.min(this.yMin, t.yMin),
34
- Math.max(this.xMax, t.xMax),
35
- Math.max(this.yMax, t.yMax)
36
- );
37
- }
38
- }
39
- const ft = (e, t = 1e-9) => {
40
- let n = e;
41
- return Math.abs(e) < t && (n = 0), n.toFixed(-Math.log10(t));
42
- };
43
- function Q(e, t = 1e-9) {
44
- return Array.from(
45
- new Map(
46
- e.map(([n, s]) => [
47
- `[${ft(n, t)},${ft(s, t)}]`,
48
- [n, s]
49
- ])
50
- ).values()
51
- );
52
- }
53
- const qt = Math.PI / 180, y = (e) => `[${e[0]}, ${e[1]}]`, g = ([e, t], [n, s], i = 1e-9) => Math.abs(e - n) <= i && Math.abs(t - s) <= i, S = ([e, t], [n, s]) => [e + n, t + s], A = ([e, t], [n, s]) => [e - n, t - s], z = ([e, t]) => e * e + t * t, _ = ([e, t], n) => [e * n, t * n], Y = ([e, t], [n, s] = [0, 0]) => (e - n) ** 2 + (t - s) ** 2, k = (e, t = [0, 0]) => Math.sqrt(Y(e, t));
54
- function $([e, t], [n, s]) {
55
- return e * s - t * n;
56
- }
57
- function st([e, t], [n, s]) {
58
- return e * n + t * s;
59
- }
60
- function B([e, t]) {
61
- const n = k([e, t]);
62
- return [e / n, t / n];
63
- }
64
- function R(e, t) {
65
- const n = Math.cos(t) * e, s = Math.sin(t) * e;
66
- return [n, s];
67
- }
68
- function Dt([e, t]) {
69
- return Math.atan2(t, e);
70
- }
71
- function Yt(e) {
72
- const t = k(e), n = Dt(e);
73
- return [t, n];
74
- }
75
- function vt(e, t, n = 1e-9) {
76
- const s = $(e, t), i = z(e), r = z(t);
77
- return s * s < i * r * n * n;
78
- }
79
- function F(e) {
80
- return [-e[1], e[0]];
81
- }
82
- function tt(e) {
83
- return [e[1], -e[0]];
84
- }
85
- const T = (e, t) => {
86
- const [n, s, i, r, a, o, u, l, h] = e, [c, f, m, P, w, M, v, x, E] = t;
87
- return [
88
- n * c + s * P + i * v,
89
- n * f + s * w + i * x,
90
- n * m + s * M + i * E,
91
- r * c + a * P + o * v,
92
- r * f + a * w + o * x,
93
- r * m + a * M + o * E,
94
- u * c + l * P + h * v,
95
- u * f + l * w + h * x,
96
- u * m + l * M + h * E
97
- ];
98
- };
99
- class C {
100
- constructor() {
101
- this._matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1];
102
- }
103
- translate(t, n) {
104
- return this._matrix = T(this._matrix, [1, 0, t, 0, 1, n, 0, 0, 1]), this;
105
- }
106
- rotate(t, n) {
107
- const s = Math.cos(t), i = Math.sin(t), r = [s, -i, 0, i, s, 0, 0, 0, 1];
108
- return n && this.translate(n[0], n[1]), this._matrix = T(this._matrix, r), n && this.translate(-n[0], -n[1]), this;
109
- }
110
- mirrorX() {
111
- return this._matrix = T(this._matrix, [1, 0, 0, 0, -1, 0, 0, 0, 1]), this;
112
- }
113
- mirrorY() {
114
- return this._matrix = T(this._matrix, [-1, 0, 0, 0, 1, 0, 0, 0, 1]), this;
115
- }
116
- mirrorLine(t, n) {
117
- const [s, i] = t, r = Math.atan2(i, s);
118
- return n && this.translate(n[0], n[1]), this.rotate(r), this.mirrorX(), this.rotate(-r), n && this.translate(-n[0], -n[1]), this;
119
- }
120
- mirrorCenter(t) {
121
- return t && this.translate(t[0], t[1]), this._matrix = T(this._matrix, [-1, 0, 0, 0, -1, 0, 0, 0, 1]), t && this.translate(-t[0], -t[1]), this;
122
- }
123
- scale(t, n) {
124
- return n && this.translate(n[0], n[1]), this._matrix = T(this._matrix, [t, 0, 0, 0, t, 0, 0, 0, 1]), n && this.translate(-n[0], -n[1]), this;
125
- }
126
- transform(t) {
127
- const [n, s] = t, [i, r, a, o, u, l] = this._matrix;
128
- return [i * n + r * s + a, o * n + u * s + l];
129
- }
130
- keepsOrientation() {
131
- const [t, , , , n] = this._matrix;
132
- return t * n > 0;
133
- }
134
- }
135
- class K {
136
- translateX(t) {
137
- const n = new C().translate(t, 0);
138
- return this.transform(n);
139
- }
140
- translateY(t) {
141
- const n = new C().translate(0, t);
142
- return this.transform(n);
143
- }
144
- translate(t, n) {
145
- const s = new C().translate(t, n);
146
- return this.transform(s);
147
- }
148
- translateTo([t, n]) {
149
- const s = new C().translate(t, n);
150
- return this.transform(s);
151
- }
152
- rotate(t, n) {
153
- const s = new C().rotate(
154
- t * qt,
155
- n
156
- );
157
- return this.transform(s);
158
- }
159
- scale(t, n) {
160
- const s = new C().scale(t, n);
161
- return this.transform(s);
162
- }
163
- mirrorCenter(t) {
164
- const n = new C().mirrorCenter(t);
165
- return this.transform(n);
166
- }
167
- mirror(t = "x", n) {
168
- const s = new C();
169
- return t === "x" ? s.mirrorX() : t === "y" ? s.mirrorY() : s.mirrorLine(t, n), this.transform(s);
170
- }
171
- }
172
- class It extends K {
173
- constructor(t, n) {
174
- super(), this.firstPoint = t, this.lastPoint = n, this.precision = 1e-9, this.firstPoint = t, this.lastPoint = n;
175
- }
176
- get repr() {
177
- return `${this.segmentType} ${y(this.firstPoint)} - ${y(
178
- this.lastPoint
179
- )}`;
180
- }
181
- get info() {
182
- return this.repr;
183
- }
184
- [Symbol.for("nodejs.util.inspect.custom")]() {
185
- return this.repr;
186
- }
187
- }
188
- class d extends It {
189
- constructor() {
190
- super(...arguments), this.segmentType = "LINE", this._V = null, this._boundingBox = null;
191
- }
192
- isValidParameter(t) {
193
- const n = this.length * this.precision;
194
- return t >= -n && 1 - t >= -n;
195
- }
196
- paramPoint(t) {
197
- return S(this.firstPoint, _(this.V, t));
198
- }
199
- get length() {
200
- return k(this.firstPoint, this.lastPoint);
201
- }
202
- get squareLength() {
203
- return Y(this.firstPoint, this.lastPoint);
204
- }
205
- get V() {
206
- return this._V === null && (this._V = A(this.lastPoint, this.firstPoint)), this._V;
207
- }
208
- get midPoint() {
209
- return S(this.firstPoint, _(this.V, 0.5));
210
- }
211
- isSame(t) {
212
- return t instanceof d ? g(this.firstPoint, t.firstPoint) && g(this.lastPoint, t.lastPoint) || g(this.lastPoint, t.firstPoint) && g(this.firstPoint, t.lastPoint) : !1;
213
- }
214
- clone() {
215
- return new d(this.firstPoint, this.lastPoint);
216
- }
217
- reverse() {
218
- return new d(this.lastPoint, this.firstPoint);
219
- }
220
- get boundingBox() {
221
- return this._boundingBox === null && (this._boundingBox = new q(
222
- Math.min(this.firstPoint[0], this.lastPoint[0]) - this.precision,
223
- Math.min(this.firstPoint[1], this.lastPoint[1]) - this.precision,
224
- Math.max(this.firstPoint[0], this.lastPoint[0]) + this.precision,
225
- Math.max(this.firstPoint[1], this.lastPoint[1]) + this.precision
226
- )), this._boundingBox;
227
- }
228
- distanceFrom(t) {
229
- const n = A(t, this.firstPoint), s = st(n, this.V) / this.squareLength;
230
- if (s < 0)
231
- return k(t, this.firstPoint);
232
- if (s > 1)
233
- return k(t, this.lastPoint);
234
- const i = this.paramPoint(s);
235
- return k(t, i);
236
- }
237
- isOnSegment(t) {
238
- if (g(t, this.firstPoint, this.precision))
239
- return !0;
240
- const n = A(t, this.firstPoint);
241
- if (!vt(this.V, n))
242
- return !1;
243
- const s = st(n, this.V) / this.squareLength;
244
- return this.isValidParameter(s);
245
- }
246
- tangentAt(t) {
247
- if (!this.isOnSegment(t))
248
- throw new Error("Point is not on segment");
249
- return B(this.V);
250
- }
251
- get normalVector() {
252
- return F(B(this.V));
253
- }
254
- get tangentAtFirstPoint() {
255
- return B(this.V);
256
- }
257
- get tangentAtLastPoint() {
258
- return B(this.V);
259
- }
260
- splitAt(t) {
261
- let n;
262
- if (Array.isArray(t) && t.length === 0)
263
- return [this];
264
- Array.isArray(t[0]) ? n = t : n = [t], n.forEach((u) => {
265
- if (!this.isOnSegment(u))
266
- throw new Error(
267
- `Point ${y(u)} is not on segment ${this.repr}`
268
- );
269
- });
270
- const s = [this.firstPoint, ...n, this.lastPoint], i = Q(s), r = this.lastPoint[0] - this.firstPoint[0];
271
- let a = Math.sign(r), o = 0;
272
- return Math.abs(r) < this.precision && (a = Math.sign(this.lastPoint[1] - this.firstPoint[1]), o = 1), i.sort(
273
- (u, l) => a * (u[o] - l[o])
274
- ), i.flatMap((u, l) => l === i.length - 1 ? [] : new d(u, i[l + 1]));
275
- }
276
- transform(t) {
277
- return new d(
278
- t.transform(this.firstPoint),
279
- t.transform(this.lastPoint)
280
- );
281
- }
282
- }
283
- function Ut(e) {
284
- return Array.from(Array(e).keys());
285
- }
286
- function L(e) {
287
- const t = Math.min(...e.map((n) => n.length));
288
- return Ut(t).map((n) => e.map((s) => s[n]));
289
- }
290
- function nt(e, t = 1e-9) {
291
- return e < 0 ? e + 2 * Math.PI : e >= 2 * Math.PI ? e % (2 * Math.PI) : e > 2 * Math.PI - t ? 0 : e;
292
- }
293
- function gt(e, t, n, s = 1e-9) {
294
- let i = t - e;
295
- return n && (i = -i), i < 0 && (i += 2 * Math.PI), i > 2 * Math.PI - s ? 0 : i;
296
- }
297
- const Z = (e, t, n) => {
298
- const s = $(e.V, t.V), i = z(e.V), r = z(t.V), a = n ? n * n : e.precision * t.precision;
299
- if (s * s < i * r * a)
300
- return "parallel";
301
- const o = A(t.firstPoint, e.firstPoint), u = $(o, t.V) / s, l = $(o, e.V) / s;
302
- return {
303
- intersectionParam1: u,
304
- intersectionParam2: l
305
- };
306
- };
307
- function _t(e, t, n = !1, s) {
308
- const i = Z(e, t, s);
309
- if (i === "parallel") {
310
- if (!n)
311
- return null;
312
- if (e.isSame(t))
313
- return e;
314
- const o = Q(
315
- [
316
- t.isOnSegment(e.firstPoint) ? e.firstPoint : null,
317
- t.isOnSegment(e.lastPoint) ? e.lastPoint : null,
318
- e.isOnSegment(t.firstPoint) ? t.firstPoint : null,
319
- e.isOnSegment(t.lastPoint) ? t.lastPoint : null
320
- ].filter((u) => u !== null)
321
- ).sort((u, l) => u[0] - l[0]);
322
- if (o.length === 0)
323
- return null;
324
- if (o.length === 1)
325
- return null;
326
- if (o.length === 2)
327
- return new d(o[0], o[1]);
328
- throw console.error(o), new Error(
329
- "Unexpected number of points while intersecting parallel lines"
330
- );
331
- }
332
- const { intersectionParam1: r, intersectionParam2: a } = i;
333
- return !e.isValidParameter(r) || !t.isValidParameter(a) ? null : e.paramPoint(r);
334
- }
335
- const j = (e, t) => {
336
- const n = A(e, t);
337
- return Yt(n);
338
- };
339
- class p extends It {
340
- constructor(t, n, s, i = !1, { ignoreChecks: r = !1 } = {}) {
341
- if (super(t, n), this.segmentType = "ARC", this._angularLength = null, this._radius = null, this._firstAngle = null, this._lastAngle = null, this._boundingBox = null, this.center = s, this.clockwise = i, !r) {
342
- if (g(t, n))
343
- throw new Error("Invalid arc, cannot be a full circle");
344
- if (Math.abs(this.radius - k(this.lastPoint, this.center)) > this.precision)
345
- throw new Error(
346
- `Invalid arc, radius does not match between ${y(
347
- t
348
- )} and ${y(n)}} (center ${y(s)})`
349
- );
350
- }
351
- }
352
- get info() {
353
- return `ARC(${y(this.firstPoint)}, ${y(
354
- this.lastPoint
355
- )}, ${y(this.center)}, ${this.clockwise ? "CW" : "CCW"})`;
356
- }
357
- isValidParameter(t) {
358
- return 1 - t >= -this.precision && t >= -this.precision;
359
- }
360
- angleToParam(t) {
361
- return gt(this.firstAngle, nt(t), this.clockwise) / this.angularLength;
362
- }
363
- get angularLength() {
364
- return this._angularLength || (this._angularLength = gt(
365
- this.firstAngle,
366
- this.lastAngle,
367
- this.clockwise
368
- )), this._angularLength;
369
- }
370
- paramPoint(t) {
371
- return S(
372
- this.center,
373
- R(
374
- this.radius,
375
- this.firstAngle + t * this.angularLength * (this.clockwise ? -1 : 1)
376
- )
377
- );
378
- }
379
- pointToParam(t) {
380
- const [n, s] = j(t, this.center);
381
- if (Math.abs(n - this.radius) > this.precision)
382
- throw new Error(
383
- `Point ${y(t)} is not on segment ${this.repr}`
384
- );
385
- const i = this.angleToParam(s);
386
- if (!this.isValidParameter(i))
387
- throw new Error(
388
- `Point ${y(t)} is not on segment ${this.repr}`
389
- );
390
- return i;
391
- }
392
- get radius() {
393
- return this._radius === null && (this._radius = k(this.firstPoint, this.center)), this._radius;
394
- }
395
- get firstAngle() {
396
- if (this._firstAngle === null) {
397
- const [t, n] = A(this.firstPoint, this.center);
398
- this._firstAngle = nt(Math.atan2(n, t));
399
- }
400
- return this._firstAngle;
401
- }
402
- get lastAngle() {
403
- if (this._lastAngle === null) {
404
- const [t, n] = A(this.lastPoint, this.center);
405
- this._lastAngle = nt(Math.atan2(n, t));
406
- }
407
- return this._lastAngle;
408
- }
409
- get length() {
410
- return this.radius * this.angularLength;
411
- }
412
- get squareLength() {
413
- return this.length * this.length;
414
- }
415
- get midPoint() {
416
- return this.paramPoint(0.5);
417
- }
418
- isSame(t) {
419
- return !(t instanceof p) || !g(this.center, t.center) ? !1 : g(this.firstPoint, t.firstPoint) && g(this.lastPoint, t.lastPoint) && this.clockwise === t.clockwise || g(this.lastPoint, t.firstPoint) && g(this.firstPoint, t.lastPoint) && this.clockwise === !t.clockwise;
420
- }
421
- clone() {
422
- return new p(
423
- this.firstPoint,
424
- this.lastPoint,
425
- this.center,
426
- this.clockwise
427
- );
428
- }
429
- reverse() {
430
- return new p(
431
- this.lastPoint,
432
- this.firstPoint,
433
- this.center,
434
- !this.clockwise
435
- );
436
- }
437
- get boundingBox() {
438
- if (this._boundingBox === null) {
439
- const t = this.radius + this.precision, n = (s) => this.isValidParameter(this.angleToParam(s));
440
- this._boundingBox = new q(
441
- n(Math.PI) ? this.center[0] - t : Math.min(this.firstPoint[0], this.lastPoint[0]) - this.precision,
442
- n(Math.PI * 1.5) ? this.center[1] - t : Math.min(this.firstPoint[1], this.lastPoint[1]) - this.precision,
443
- n(0) ? this.center[0] + t : Math.max(this.firstPoint[0], this.lastPoint[0]) + this.precision,
444
- n(Math.PI / 2) ? this.center[1] + t : Math.max(this.firstPoint[1], this.lastPoint[1]) + this.precision
445
- );
446
- }
447
- return this._boundingBox;
448
- }
449
- distanceFrom(t) {
450
- const [n, s] = j(t, this.center);
451
- return this.isValidParameter(this.angleToParam(s)) ? Math.abs(n - this.radius) : Math.sqrt(
452
- Math.min(
453
- Y(t, this.firstPoint),
454
- Y(t, this.lastPoint)
455
- )
456
- );
457
- }
458
- isOnSegment(t) {
459
- if (g(t, this.firstPoint) || g(t, this.lastPoint))
460
- return !0;
461
- const [n, s] = j(t, this.center);
462
- if (Math.abs(n - this.radius) > this.precision)
463
- return !1;
464
- const i = this.angleToParam(s);
465
- return this.isValidParameter(i);
466
- }
467
- tangentAt(t) {
468
- const [n, s] = j(t, this.center);
469
- if (Math.abs(n - this.radius) > this.precision)
470
- throw new Error("Point is not on the arc");
471
- const i = this.angleToParam(s);
472
- if (!this.isValidParameter(i))
473
- throw new Error("Point is not on the arc");
474
- const r = R(1, s);
475
- return (this.clockwise ? tt : F)(B(r));
476
- }
477
- get tangentAtFirstPoint() {
478
- const t = R(1, this.firstAngle);
479
- return (this.clockwise ? tt : F)(B(t));
480
- }
481
- get tangentAtLastPoint() {
482
- const t = R(1, this.lastAngle);
483
- return (this.clockwise ? tt : F)(B(t));
484
- }
485
- splitAt(t) {
486
- let n;
487
- if (Array.isArray(t) && t.length === 0)
488
- return [this];
489
- Array.isArray(t[0]) ? n = t : n = [t];
490
- const i = [0, 1, ...n.map((o) => this.pointToParam(o))], r = new Map(
491
- L([i, [this.firstPoint, this.lastPoint, ...n]])
492
- );
493
- i.sort((o, u) => o - u);
494
- let a = null;
495
- return i.flatMap((o, u) => {
496
- if (u === i.length - 1)
497
- return [];
498
- const l = i[u + 1];
499
- if (l - o < this.precision)
500
- return a === null && (a = o), [];
501
- const h = a === null ? o : a, c = new p(
502
- r.get(h) || this.paramPoint(h),
503
- r.get(l) || this.paramPoint(l),
504
- this.center,
505
- this.clockwise
506
- );
507
- return a = null, c;
508
- });
509
- }
510
- transform(t) {
511
- return new p(
512
- t.transform(this.firstPoint),
513
- t.transform(this.lastPoint),
514
- t.transform(this.center),
515
- t.keepsOrientation() ? this.clockwise : !this.clockwise
516
- );
517
- }
518
- }
519
- function pn(e, t, n) {
520
- const s = new d(t, e), i = new d(t, n), r = F(s.tangentAtFirstPoint), a = F(i.tangentAtLastPoint), o = Z(
521
- { firstPoint: s.midPoint, V: r, precision: 1e-9 },
522
- { firstPoint: i.midPoint, V: a, precision: 1e-9 }
523
- );
524
- if (o === "parallel")
525
- throw new Error("Cannot create an arc from three colinear points");
526
- const u = $(
527
- A(e, t),
528
- A(n, t)
529
- ) > 0;
530
- return new p(
531
- e,
532
- n,
533
- S(s.midPoint, _(r, o.intersectionParam1)),
534
- u,
535
- { ignoreChecks: !0 }
536
- );
537
- }
538
- function dn(e, t, n) {
539
- const s = new d(t, e), i = F(s.tangentAtFirstPoint), r = Z(
540
- { firstPoint: s.midPoint, V: i, precision: 1e-9 },
541
- {
542
- firstPoint: e,
543
- V: F(n),
544
- precision: 1e-9
545
- }
546
- );
547
- if (r === "parallel")
548
- throw new Error("Cannot create an arc from three colinear points");
549
- const a = S(
550
- s.midPoint,
551
- _(i, r.intersectionParam1)
552
- ), o = $(
553
- A(a, e),
554
- A(a, S(e, n))
555
- ) < 0;
556
- return new p(e, t, a, o, {
557
- ignoreChecks: !0
558
- });
559
- }
560
- function Nt(e, t) {
561
- const n = A(t, e.firstPoint), s = st(n, e.V) / e.squareLength;
562
- return e.paramPoint(s);
563
- }
564
- function G(e, t, n) {
565
- const s = n || e.precision, i = Nt(e, t.center), r = k(i, t.center);
566
- if (r > t.radius + s)
567
- return [];
568
- if (Math.abs(r - t.radius) < s) {
569
- const c = i;
570
- return e.isOnSegment(c) && t.isOnSegment(c) ? [c] : [];
571
- }
572
- const a = [], o = Math.sqrt(
573
- t.radius * t.radius - r * r
574
- ), u = e.tangentAtFirstPoint, l = S(i, _(u, o));
575
- e.isOnSegment(l) && t.isOnSegment(l) && a.push(l);
576
- const h = S(i, _(u, -o));
577
- return e.isOnSegment(h) && t.isOnSegment(h) && a.push(h), a;
578
- }
579
- const Xt = (e) => {
580
- const { firstPoint: t, lastPoint: n, center: s, clockwise: i } = e;
581
- return new p(n, t, s, i, {
582
- ignoreChecks: !0
583
- });
584
- }, Rt = (e, t) => {
585
- if (e.isSame(t))
586
- return [e];
587
- const n = Q(
588
- [
589
- t.isOnSegment(e.firstPoint) ? e.firstPoint : null,
590
- t.isOnSegment(e.lastPoint) ? e.lastPoint : null,
591
- e.isOnSegment(t.firstPoint) ? t.firstPoint : null,
592
- e.isOnSegment(t.lastPoint) ? t.lastPoint : null
593
- ].filter((s) => s !== null)
594
- // We sort by the param value of the first arc. This means that the points
595
- // will be sorted with the same orientation than arc1
596
- ).sort((s, i) => e.pointToParam(s) - e.pointToParam(i));
597
- if (n.length === 0)
598
- return [];
599
- if (n.length === 1)
600
- return [];
601
- if (n.length === 2)
602
- return e.isSame(Xt(t)) ? [] : [new p(n[0], n[1], e.center, e.clockwise)];
603
- if (n.length === 3) {
604
- const s = g(n[0], t.lastPoint) || g(n[0], t.firstPoint) ? 1 : 0;
605
- return [
606
- new p(
607
- n[0 + s],
608
- n[1 + s],
609
- e.center,
610
- e.clockwise
611
- )
612
- ];
613
- } else if (n.length === 4)
614
- return [
615
- new p(n[0], n[1], e.center, e.clockwise),
616
- new p(n[2], n[3], e.center, e.clockwise)
617
- ];
618
- throw new Error("Bug in the arc arc overlap algorithm");
619
- };
620
- function kt(e, t, n = !1, s) {
621
- const i = s || e.precision, r = k(e.center, t.center), a = e.radius + t.radius;
622
- if (r > a + i)
623
- return [];
624
- const o = Math.abs(e.radius - t.radius);
625
- if (r < o - i)
626
- return [];
627
- if (r < i)
628
- return o > i ? [] : n ? Rt(e, t) : [];
629
- const u = B(A(t.center, e.center)), l = r > a - i;
630
- if (
631
- // circles are outside each other
632
- l || // circles are inside each other
633
- Math.abs(r - o) < i
634
- ) {
635
- const v = l || e.radius > t.radius ? 1 : -1, x = S(
636
- e.center,
637
- _(u, v * e.radius)
638
- );
639
- return e.isOnSegment(x) && t.isOnSegment(x) ? [x] : [];
640
- }
641
- const h = e.radius * e.radius / (2 * r) - t.radius * t.radius / (2 * r) + r / 2, c = S(
642
- e.center,
643
- _(u, h)
644
- ), f = Math.sqrt(
645
- e.radius * e.radius - h * h
646
- ), m = F(u), P = S(c, _(m, f)), w = S(c, _(m, -f)), M = [];
647
- return e.isOnSegment(P) && t.isOnSegment(P) && M.push(P), e.isOnSegment(w) && t.isOnSegment(w) && M.push(w), M;
648
- }
649
- function Pn(e, t, n) {
650
- if (e instanceof d && t instanceof d) {
651
- const s = _t(
652
- e,
653
- t,
654
- !1,
655
- n
656
- );
657
- return s === null ? [] : [s];
658
- }
659
- if (e instanceof d && t instanceof p)
660
- return G(e, t, n);
661
- if (e instanceof p && t instanceof d)
662
- return G(t, e, n);
663
- if (e instanceof p && t instanceof p)
664
- return kt(e, t, !1, n);
665
- throw new Error("Not implemented");
666
- }
667
- function W(e, t, n) {
668
- if (e instanceof d && t instanceof d) {
669
- const s = _t(
670
- e,
671
- t,
672
- !0,
673
- n
674
- );
675
- return s === null ? { intersections: [], overlaps: [], count: 0 } : s instanceof d ? { intersections: [], overlaps: [s], count: 1 } : { intersections: [s], overlaps: [], count: 1 };
676
- }
677
- if (!e.boundingBox.overlaps(t.boundingBox))
678
- return { intersections: [], overlaps: [], count: 0 };
679
- if (e instanceof d && t instanceof p) {
680
- const s = G(e, t, n);
681
- return { intersections: s, overlaps: [], count: s.length };
682
- }
683
- if (e instanceof p && t instanceof d) {
684
- const s = G(t, e, n);
685
- return { intersections: s, overlaps: [], count: s.length };
686
- }
687
- if (e instanceof p && t instanceof p) {
688
- const s = kt(
689
- e,
690
- t,
691
- !0,
692
- n
693
- );
694
- return s.length ? s[0] instanceof p ? {
695
- intersections: [],
696
- overlaps: s,
697
- count: s.length
698
- } : {
699
- intersections: s,
700
- overlaps: [],
701
- count: s.length
702
- } : { intersections: [], overlaps: [], count: 0 };
703
- }
704
- throw new Error("Not implemented");
705
- }
706
- function Ft(e) {
707
- const t = [];
708
- for (let n = 0; n < e; n++)
709
- for (let s = 0; s <= n; s++)
710
- t.push([n, s]);
711
- return t;
712
- }
713
- function* it(e) {
714
- for (const [t, n] of Ft(e.length))
715
- t !== n && (yield [e[t], e[n]]);
716
- }
717
- class Et extends K {
718
- constructor(t, { ignoreChecks: n = !1 } = {}) {
719
- super(), this._boundingBox = null, n || Ct(t), this.segments = t;
720
- }
721
- get repr() {
722
- return this.segments.map((t) => t.repr).join(`
723
- `) + `
724
- `;
725
- }
726
- get info() {
727
- return this.repr;
728
- }
729
- get firstPoint() {
730
- return this.segments[0].firstPoint;
731
- }
732
- get lastPoint() {
733
- return this.segments[this.segments.length - 1].lastPoint;
734
- }
735
- get segmentsCount() {
736
- return this.segments.length;
737
- }
738
- onStroke(t) {
739
- return this.segments.some((n) => n.isOnSegment(t));
740
- }
741
- intersects(t) {
742
- return this.boundingBox.overlaps(t.boundingBox) ? this.segments.some(
743
- (n) => t.segments.some(
744
- (s) => W(n, s).count > 0
745
- )
746
- ) : !1;
747
- }
748
- overlappingSegments(t) {
749
- return this.segments.flatMap((n) => t.segments.flatMap((s) => n.boundingBox.overlaps(s.boundingBox) ? W(n, s).overlaps : []));
750
- }
751
- get boundingBox() {
752
- if (this._boundingBox === null) {
753
- let t = this.segments[0].boundingBox;
754
- this.segments.slice(1).forEach((n) => {
755
- t = t.merge(n.boundingBox);
756
- }), this._boundingBox = t;
757
- }
758
- return this._boundingBox;
759
- }
760
- [Symbol.for("nodejs.util.inspect.custom")]() {
761
- return this.repr;
762
- }
763
- }
764
- function jt(e, t = "Stroke") {
765
- Ft(e.length).forEach(
766
- ([n, s]) => {
767
- if (n === s)
768
- return;
769
- const i = e[n], r = e[s], a = W(i, r);
770
- if (a.count !== 0) {
771
- if (a.count === 1 && !a.overlaps.length) {
772
- const o = n - s, u = a.intersections[0];
773
- if (o === 1 && g(i.firstPoint, u) || o === -1 && g(i.lastPoint, u) || o === e.length - 1 && g(i.lastPoint, u) && g(r.firstPoint, u) || -o === e.length - 1 && g(i.firstPoint, u) && g(r.lastPoint, u))
774
- return;
775
- }
776
- throw new Error(
777
- `${t} segments must not intersect, but segments ${i.info} and ${r.info} do at ${JSON.stringify(
778
- a.intersections
779
- )}`
780
- );
781
- }
782
- }
783
- );
784
- }
785
- function Ct(e, t = "Stroke") {
786
- if (e.length === 0)
787
- throw new Error(`${t} must have at least one segment`);
788
- L([e.slice(0, -1), e.slice(1)]).forEach(
789
- ([n, s]) => {
790
- if (!g(n.lastPoint, s.firstPoint))
791
- throw new Error(
792
- `${t} segments must be connected, but ${n.info} and ${s.info} are not`
793
- );
794
- }
795
- ), jt(e, t);
796
- }
797
- function mt(e, t) {
798
- return !!(e instanceof d && t instanceof d && vt(e.V, t.V) || e instanceof p && t instanceof p && g(e.center, t.center) && e.radius - t.radius < e.precision);
799
- }
800
- function pt(e, t) {
801
- if (e instanceof d && t instanceof d)
802
- return new d(e.firstPoint, t.lastPoint);
803
- if (e instanceof p && t instanceof p)
804
- return new p(
805
- e.firstPoint,
806
- t.lastPoint,
807
- e.center,
808
- e.clockwise
809
- );
810
- throw new Error("Not implemented");
811
- }
812
- function Vt(e) {
813
- let t = !1;
814
- const n = [];
815
- for (const s of e.segments) {
816
- if (n.length === 0) {
817
- n.push(s);
818
- continue;
819
- }
820
- const i = n[n.length - 1];
821
- mt(i, s) ? (t = !0, n.pop(), n.push(pt(i, s))) : n.push(s);
822
- }
823
- if (g(e.firstPoint, e.lastPoint) && mt(
824
- n[0],
825
- n[n.length - 1]
826
- )) {
827
- t = !0;
828
- const s = n.pop();
829
- n[0] = pt(s, n[0]);
830
- }
831
- return t ? n : null;
832
- }
833
- class I extends Et {
834
- constructor() {
835
- super(...arguments), this.strokeType = "STRAND";
836
- }
837
- reverse() {
838
- const t = this.segments.map((n) => n.reverse());
839
- return t.reverse(), new I(t, { ignoreChecks: !0 });
840
- }
841
- clone() {
842
- return new I(
843
- this.segments.map((t) => t.clone()),
844
- { ignoreChecks: !0 }
845
- );
846
- }
847
- extend(t) {
848
- if (!g(this.lastPoint, t.firstPoint))
849
- throw console.error(this.repr, t.repr), new Error("Cannot extend strand: connection point is not the same");
850
- return new I([...this.segments, ...t.segments]);
851
- }
852
- simplify() {
853
- const t = Vt(this);
854
- return t ? new I(t, { ignoreChecks: !0 }) : this;
855
- }
856
- transform(t) {
857
- return new I(
858
- this.segments.map((n) => n.transform(t)),
859
- { ignoreChecks: !0 }
860
- );
861
- }
862
- }
863
- const zt = (e, t) => {
864
- const n = Z(t, {
865
- V: [1, 0],
866
- firstPoint: e,
867
- precision: t.precision
868
- });
869
- if (n === "parallel")
870
- return 0;
871
- const { intersectionParam1: s, intersectionParam2: i } = n;
872
- if (!t.isValidParameter(s) || i <= -t.precision)
873
- return 0;
874
- if (Math.abs(s) < t.precision || Math.abs(s - 1) < t.precision) {
875
- const [, r] = t.midPoint;
876
- return e[1] - r < 0 ? 1 : 0;
877
- }
878
- return 1;
879
- }, Gt = (e, t) => {
880
- const n = t.precision, s = Math.abs(e[1] - t.center[1]);
881
- if (s > t.radius + n)
882
- return 0;
883
- const i = Y(e, t.center), r = t.radius * t.radius, a = n * n;
884
- if (Math.abs(i - r) < a && t.isOnSegment(e))
885
- return 0;
886
- const o = i - r > a;
887
- if (o && t.center[0] < e[0])
888
- return 0;
889
- const u = Math.sqrt(
890
- t.radius * t.radius - s * s
891
- );
892
- let l = 0;
893
- const h = (c) => {
894
- t.isOnSegment(c) && (g(c, t.firstPoint) ? l += t.tangentAtFirstPoint[1] > 0 ? 1 : 0 : g(c, t.lastPoint) ? l += t.tangentAtLastPoint[1] > 0 ? 0 : 1 : l += 1);
895
- };
896
- return h([t.center[0] + u, e[1]]), o && h([t.center[0] - u, e[1]]), l;
897
- };
898
- function Wt(e, t) {
899
- if (t instanceof d)
900
- return zt(e, t);
901
- if (t instanceof p)
902
- return Gt(e, t);
903
- throw new Error("Not implemented");
904
- }
905
- class O extends Et {
906
- constructor(t, { ignoreChecks: n = !1 } = {}) {
907
- super(t, { ignoreChecks: !0 }), this.strokeType = "LOOP", this._clockwise = null, n || Ht(t);
908
- }
909
- get clockwise() {
910
- if (this._clockwise === null) {
911
- const t = this.segments.flatMap((s) => s instanceof d ? [s.firstPoint] : [s.firstPoint, s.paramPoint(0.5)]), n = t.map((s, i) => {
912
- const r = t[(i + 1) % t.length];
913
- return (r[0] - s[0]) * (r[1] + s[1]);
914
- }).reduce((s, i) => s + i, 0);
915
- this._clockwise = n > 0;
916
- }
917
- return this._clockwise;
918
- }
919
- clone() {
920
- return new O(
921
- this.segments.map((t) => t.clone()),
922
- { ignoreChecks: !0 }
923
- );
924
- }
925
- reverse() {
926
- const t = this.segments.map((n) => n.reverse());
927
- return t.reverse(), new O(t, { ignoreChecks: !0 });
928
- }
929
- transform(t) {
930
- return new O(
931
- this.segments.map((n) => n.transform(t)),
932
- { ignoreChecks: !0 }
933
- );
934
- }
935
- contains(t) {
936
- return this.onStroke(t) || !this.boundingBox.contains(t) ? !1 : this.segments.reduce((s, i) => s + Wt(t, i), 0) % 2 === 1;
937
- }
938
- simplify() {
939
- const t = Vt(this);
940
- return t ? new O(t, { ignoreChecks: !0 }) : this;
941
- }
942
- }
943
- function Ht(e) {
944
- if (Ct(e, "Loop"), !g(e[0].firstPoint, e[e.length - 1].lastPoint))
945
- throw new Error("Loop segment must be closed");
946
- }
947
- function Bt(e) {
948
- if (e instanceof d)
949
- return {
950
- type: e.segmentType,
951
- firstPoint: e.firstPoint,
952
- lastPoint: e.lastPoint
953
- };
954
- if (e instanceof p)
955
- return {
956
- type: e.segmentType,
957
- firstPoint: e.firstPoint,
958
- lastPoint: e.lastPoint,
959
- center: e.center,
960
- clockwise: e.clockwise
961
- };
962
- throw new Error("Unknown segment type");
963
- }
964
- function rt(e) {
965
- return {
966
- type: "LOOP",
967
- segments: e.segments.map(Bt)
968
- };
969
- }
970
- function Ot(e) {
971
- return {
972
- type: "FIGURE",
973
- contour: rt(e.contour),
974
- holes: e.holes.map(rt)
975
- };
976
- }
977
- function Jt(e) {
978
- return {
979
- type: "DIAGRAM",
980
- figures: e.figures.map(Ot)
981
- };
982
- }
983
- function dt(e) {
984
- if (e instanceof V)
985
- return Jt(e);
986
- if (e instanceof b)
987
- return Ot(e);
988
- if (e instanceof O)
989
- return rt(e);
990
- if (e instanceof p || e instanceof d)
991
- return Bt(e);
992
- throw new Error("Unknown shape type");
993
- }
994
- class Qt {
995
- constructor() {
996
- this.ids = [], this.values = [], this.length = 0;
997
- }
998
- clear() {
999
- this.length = 0;
1000
- }
1001
- push(t, n) {
1002
- let s = this.length++;
1003
- for (; s > 0; ) {
1004
- const i = s - 1 >> 1, r = this.values[i];
1005
- if (n >= r)
1006
- break;
1007
- this.ids[s] = this.ids[i], this.values[s] = r, s = i;
1008
- }
1009
- this.ids[s] = t, this.values[s] = n;
1010
- }
1011
- pop() {
1012
- if (this.length === 0)
1013
- return;
1014
- const t = this.ids[0];
1015
- if (this.length--, this.length > 0) {
1016
- const n = this.ids[0] = this.ids[this.length], s = this.values[0] = this.values[this.length], i = this.length >> 1;
1017
- let r = 0;
1018
- for (; r < i; ) {
1019
- let a = (r << 1) + 1;
1020
- const o = a + 1;
1021
- let u = this.ids[a], l = this.values[a];
1022
- const h = this.values[o];
1023
- if (o < this.length && h < l && (a = o, u = this.ids[o], l = h), l >= s)
1024
- break;
1025
- this.ids[r] = u, this.values[r] = l, r = a;
1026
- }
1027
- this.ids[r] = n, this.values[r] = s;
1028
- }
1029
- return t;
1030
- }
1031
- peek() {
1032
- if (this.length !== 0)
1033
- return this.ids[0];
1034
- }
1035
- peekValue() {
1036
- if (this.length !== 0)
1037
- return this.values[0];
1038
- }
1039
- shrink() {
1040
- this.ids.length = this.values.length = this.length;
1041
- }
1042
- }
1043
- const Pt = [
1044
- Int8Array,
1045
- Uint8Array,
1046
- Uint8ClampedArray,
1047
- Int16Array,
1048
- Uint16Array,
1049
- Int32Array,
1050
- Uint32Array,
1051
- Float32Array,
1052
- Float64Array
1053
- ], et = 3;
1054
- class ut {
1055
- static from(t) {
1056
- if (!t || t.byteLength === void 0 || t.buffer)
1057
- throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");
1058
- const [n, s] = new Uint8Array(t, 0, 2);
1059
- if (n !== 251)
1060
- throw new Error("Data does not appear to be in a Flatbush format.");
1061
- if (s >> 4 !== et)
1062
- throw new Error(`Got v${s >> 4} data when expected v${et}.`);
1063
- const [i] = new Uint16Array(t, 2, 1), [r] = new Uint32Array(t, 4, 1);
1064
- return new ut(r, i, Pt[s & 15], void 0, t);
1065
- }
1066
- constructor(t, n = 16, s = Float64Array, i = ArrayBuffer, r) {
1067
- if (t === void 0)
1068
- throw new Error("Missing required argument: numItems.");
1069
- if (isNaN(t) || t <= 0)
1070
- throw new Error(`Unexpected numItems value: ${t}.`);
1071
- this.numItems = +t, this.nodeSize = Math.min(Math.max(+n, 2), 65535);
1072
- let a = t, o = a;
1073
- this._levelBounds = [a * 4];
1074
- do
1075
- a = Math.ceil(a / this.nodeSize), o += a, this._levelBounds.push(o * 4);
1076
- while (a !== 1);
1077
- this.ArrayType = s || Float64Array, this.IndexArrayType = o < 16384 ? Uint16Array : Uint32Array;
1078
- const u = Pt.indexOf(this.ArrayType), l = o * 4 * this.ArrayType.BYTES_PER_ELEMENT;
1079
- if (u < 0)
1080
- throw new Error(`Unexpected typed array class: ${s}.`);
1081
- r && r.byteLength !== void 0 && !r.buffer ? (this.data = r, this._boxes = new this.ArrayType(this.data, 8, o * 4), this._indices = new this.IndexArrayType(this.data, 8 + l, o), this._pos = o * 4, this.minX = this._boxes[this._pos - 4], this.minY = this._boxes[this._pos - 3], this.maxX = this._boxes[this._pos - 2], this.maxY = this._boxes[this._pos - 1]) : (this.data = new i(8 + l + o * this.IndexArrayType.BYTES_PER_ELEMENT), this._boxes = new this.ArrayType(this.data, 8, o * 4), this._indices = new this.IndexArrayType(this.data, 8 + l, o), this._pos = 0, this.minX = 1 / 0, this.minY = 1 / 0, this.maxX = -1 / 0, this.maxY = -1 / 0, new Uint8Array(this.data, 0, 2).set([251, (et << 4) + u]), new Uint16Array(this.data, 2, 1)[0] = n, new Uint32Array(this.data, 4, 1)[0] = t), this._queue = new Qt();
1082
- }
1083
- add(t, n, s, i) {
1084
- const r = this._pos >> 2, a = this._boxes;
1085
- return this._indices[r] = r, a[this._pos++] = t, a[this._pos++] = n, a[this._pos++] = s, a[this._pos++] = i, t < this.minX && (this.minX = t), n < this.minY && (this.minY = n), s > this.maxX && (this.maxX = s), i > this.maxY && (this.maxY = i), r;
1086
- }
1087
- finish() {
1088
- if (this._pos >> 2 !== this.numItems)
1089
- throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
1090
- const t = this._boxes;
1091
- if (this.numItems <= this.nodeSize) {
1092
- t[this._pos++] = this.minX, t[this._pos++] = this.minY, t[this._pos++] = this.maxX, t[this._pos++] = this.maxY;
1093
- return;
1094
- }
1095
- const n = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, i = new Uint32Array(this.numItems), r = (1 << 16) - 1;
1096
- for (let a = 0, o = 0; a < this.numItems; a++) {
1097
- const u = t[o++], l = t[o++], h = t[o++], c = t[o++], f = Math.floor(r * ((u + h) / 2 - this.minX) / n), m = Math.floor(r * ((l + c) / 2 - this.minY) / s);
1098
- i[a] = Zt(f, m);
1099
- }
1100
- ot(i, t, this._indices, 0, this.numItems - 1, this.nodeSize);
1101
- for (let a = 0, o = 0; a < this._levelBounds.length - 1; a++) {
1102
- const u = this._levelBounds[a];
1103
- for (; o < u; ) {
1104
- const l = o;
1105
- let h = t[o++], c = t[o++], f = t[o++], m = t[o++];
1106
- for (let P = 1; P < this.nodeSize && o < u; P++)
1107
- h = Math.min(h, t[o++]), c = Math.min(c, t[o++]), f = Math.max(f, t[o++]), m = Math.max(m, t[o++]);
1108
- this._indices[this._pos >> 2] = l, t[this._pos++] = h, t[this._pos++] = c, t[this._pos++] = f, t[this._pos++] = m;
1109
- }
1110
- }
1111
- }
1112
- search(t, n, s, i, r) {
1113
- if (this._pos !== this._boxes.length)
1114
- throw new Error("Data not yet indexed - call index.finish().");
1115
- let a = this._boxes.length - 4;
1116
- const o = [], u = [];
1117
- for (; a !== void 0; ) {
1118
- const l = Math.min(a + this.nodeSize * 4, xt(a, this._levelBounds));
1119
- for (let h = a; h < l; h += 4) {
1120
- if (s < this._boxes[h] || i < this._boxes[h + 1] || t > this._boxes[h + 2] || n > this._boxes[h + 3])
1121
- continue;
1122
- const c = this._indices[h >> 2] | 0;
1123
- a >= this.numItems * 4 ? o.push(c) : (r === void 0 || r(c)) && u.push(c);
1124
- }
1125
- a = o.pop();
1126
- }
1127
- return u;
1128
- }
1129
- neighbors(t, n, s = 1 / 0, i = 1 / 0, r) {
1130
- if (this._pos !== this._boxes.length)
1131
- throw new Error("Data not yet indexed - call index.finish().");
1132
- let a = this._boxes.length - 4;
1133
- const o = this._queue, u = [], l = i * i;
1134
- for (; a !== void 0; ) {
1135
- const h = Math.min(a + this.nodeSize * 4, xt(a, this._levelBounds));
1136
- for (let c = a; c < h; c += 4) {
1137
- const f = this._indices[c >> 2] | 0, m = wt(t, this._boxes[c], this._boxes[c + 2]), P = wt(n, this._boxes[c + 1], this._boxes[c + 3]), w = m * m + P * P;
1138
- a >= this.numItems * 4 ? o.push(f << 1, w) : (r === void 0 || r(f)) && o.push((f << 1) + 1, w);
1139
- }
1140
- for (; o.length && o.peek() & 1; )
1141
- if (o.peekValue() > l || (u.push(o.pop() >> 1), u.length === s))
1142
- return o.clear(), u;
1143
- a = o.pop() >> 1;
1144
- }
1145
- return o.clear(), u;
1146
- }
1147
- }
1148
- function wt(e, t, n) {
1149
- return e < t ? t - e : e <= n ? 0 : e - n;
1150
- }
1151
- function xt(e, t) {
1152
- let n = 0, s = t.length - 1;
1153
- for (; n < s; ) {
1154
- const i = n + s >> 1;
1155
- t[i] > e ? s = i : n = i + 1;
1156
- }
1157
- return t[n];
1158
- }
1159
- function ot(e, t, n, s, i, r) {
1160
- if (Math.floor(s / r) >= Math.floor(i / r))
1161
- return;
1162
- const a = e[s + i >> 1];
1163
- let o = s - 1, u = i + 1;
1164
- for (; ; ) {
1165
- do
1166
- o++;
1167
- while (e[o] < a);
1168
- do
1169
- u--;
1170
- while (e[u] > a);
1171
- if (o >= u)
1172
- break;
1173
- Kt(e, t, n, o, u);
1174
- }
1175
- ot(e, t, n, s, u, r), ot(e, t, n, u + 1, i, r);
1176
- }
1177
- function Kt(e, t, n, s, i) {
1178
- const r = e[s];
1179
- e[s] = e[i], e[i] = r;
1180
- const a = 4 * s, o = 4 * i, u = t[a], l = t[a + 1], h = t[a + 2], c = t[a + 3];
1181
- t[a] = t[o], t[a + 1] = t[o + 1], t[a + 2] = t[o + 2], t[a + 3] = t[o + 3], t[o] = u, t[o + 1] = l, t[o + 2] = h, t[o + 3] = c;
1182
- const f = n[s];
1183
- n[s] = n[i], n[i] = f;
1184
- }
1185
- function Zt(e, t) {
1186
- let n = e ^ t, s = 65535 ^ n, i = 65535 ^ (e | t), r = e & (t ^ 65535), a = n | s >> 1, o = n >> 1 ^ n, u = i >> 1 ^ s & r >> 1 ^ i, l = n & i >> 1 ^ r >> 1 ^ r;
1187
- n = a, s = o, i = u, r = l, a = n & n >> 2 ^ s & s >> 2, o = n & s >> 2 ^ s & (n ^ s) >> 2, u ^= n & i >> 2 ^ s & r >> 2, l ^= s & i >> 2 ^ (n ^ s) & r >> 2, n = a, s = o, i = u, r = l, a = n & n >> 4 ^ s & s >> 4, o = n & s >> 4 ^ s & (n ^ s) >> 4, u ^= n & i >> 4 ^ s & r >> 4, l ^= s & i >> 4 ^ (n ^ s) & r >> 4, n = a, s = o, i = u, r = l, u ^= n & i >> 8 ^ s & r >> 8, l ^= s & i >> 8 ^ (n ^ s) & r >> 8, n = u ^ u >> 1, s = l ^ l >> 1;
1188
- let h = e ^ t, c = s | 65535 ^ (h | n);
1189
- return h = (h | h << 8) & 16711935, h = (h | h << 4) & 252645135, h = (h | h << 2) & 858993459, h = (h | h << 1) & 1431655765, c = (c | c << 8) & 16711935, c = (c | c << 4) & 252645135, c = (c | c << 2) & 858993459, c = (c | c << 1) & 1431655765, (c << 1 | h) >>> 0;
1190
- }
1191
- function Lt(e, t = 1e-7) {
1192
- const n = new ut(e.length);
1193
- e.forEach((r) => {
1194
- const [a, o] = r.firstPoint;
1195
- n.add(a - t, o - t, a + t, o + t);
1196
- }), n.finish();
1197
- const s = [], i = /* @__PURE__ */ new Set();
1198
- return e.forEach((r, a) => {
1199
- if (i.has(a))
1200
- return;
1201
- const o = [r];
1202
- let u = a;
1203
- i.add(a);
1204
- let l = e.length;
1205
- for (; ; ) {
1206
- if (l-- < 0)
1207
- throw new Error("Infinite loop detected");
1208
- const h = o[o.length - 1].lastPoint, [c, f] = h, m = n.search(
1209
- c - t,
1210
- f - t,
1211
- c + t,
1212
- f + t
1213
- ), P = (x) => Math.abs((u - x) % e.length), w = m.filter((x) => !i.has(x)).map((x) => [
1214
- e[x],
1215
- x,
1216
- P(x)
1217
- ]).sort(([, , x], [, , E]) => P(x) - P(E));
1218
- if (w.length === 0) {
1219
- s.push(o);
1220
- break;
1221
- }
1222
- const [M, v] = w[0];
1223
- o.push(M), i.add(v), u = v;
1224
- }
1225
- }), s;
1226
- }
1227
- class b extends K {
1228
- constructor(t, n = [], { ignoreChecks: s = !1 } = {}) {
1229
- super(), s || tn(t, n), this.contour = t, this.holes = n;
1230
- }
1231
- get boundingBox() {
1232
- return this.contour.boundingBox;
1233
- }
1234
- get isFull() {
1235
- return this.holes.length === 0;
1236
- }
1237
- get allLoops() {
1238
- return [this.contour, ...this.holes];
1239
- }
1240
- clone() {
1241
- return new b(
1242
- this.contour.clone(),
1243
- this.holes.map((t) => t.clone())
1244
- );
1245
- }
1246
- transform(t) {
1247
- return new b(
1248
- this.contour.transform(t),
1249
- this.holes.map((n) => n.transform(t))
1250
- );
1251
- }
1252
- contains(t) {
1253
- return this.contour.contains(t) && !this.holes.some((n) => n.contains(t));
1254
- }
1255
- intersects(t) {
1256
- return this.allLoops.some(
1257
- (n) => t.allLoops.some((s) => n.intersects(s))
1258
- );
1259
- }
1260
- overlappingStrands(t) {
1261
- const n = t instanceof b ? t.allLoops : [t], s = this.allLoops.flatMap((i) => n.flatMap((r) => i.overlappingSegments(r)));
1262
- return Lt(s).map((i) => new I(i));
1263
- }
1264
- }
1265
- function tn(e, t = []) {
1266
- if (!e)
1267
- throw new Error("Figure must have a contour");
1268
- for (const [n, s] of it([e, ...t]))
1269
- if (n.intersects(s))
1270
- throw new Error("Loops in a figure must not intersect");
1271
- if (t.some(
1272
- (n) => !e.contains(n.firstPoint) && !e.onStroke(n.firstPoint)
1273
- ))
1274
- throw new Error("Holes must be inside the contour");
1275
- for (const [n, s] of it(t))
1276
- if (n.contains(s.firstPoint))
1277
- throw console.error(dt(n), dt(s)), new Error("Holes must not be inside other holes");
1278
- }
1279
- const nn = (e) => {
1280
- const t = e.map((i, r) => e.slice(r + 1).map((a, o) => [o + r + 1, a]).filter(([, a]) => i.boundingBox.overlaps(a.boundingBox)).map(([a]) => a)), n = [], s = Array(t.length);
1281
- return t.forEach((i, r) => {
1282
- let a = s[r];
1283
- a || (a = [], n.push(a)), a.push(e[r]), i.length && i.forEach((o) => {
1284
- s[o] = a;
1285
- });
1286
- }), n;
1287
- }, Tt = (e) => e.map((t, n) => {
1288
- const i = t.segments[0].midPoint, r = e.filter((a, o) => n === o ? !1 : a.contains(i));
1289
- return {
1290
- loop: t,
1291
- isIn: r
1292
- };
1293
- }), en = (e, t) => e.flatMap(({ loop: n }) => ht(
1294
- t.filter(
1295
- ({ loop: s, isIn: i }) => s === n || i.indexOf(n) !== -1
1296
- )
1297
- )), sn = (e, t) => {
1298
- const n = t.filter(({ isIn: i }) => i.length <= 1), s = ht(
1299
- Tt(e.map(({ loop: i }) => i))
1300
- );
1301
- return [n, ...s];
1302
- }, ht = (e) => {
1303
- if (!e.length)
1304
- return [];
1305
- const t = e.filter(({ isIn: s }) => !s.length), n = e.filter(({ isIn: s }) => s.length > 1);
1306
- return t.length === 1 && n.length === 0 ? [e] : t.length > 1 ? en(t, e) : sn(n, e);
1307
- };
1308
- function D(e) {
1309
- return nn(e).map(Tt).flatMap(ht).map((n) => {
1310
- if (n.length === 1)
1311
- return new b(n[0].loop);
1312
- n.sort((r, a) => r.isIn.length - a.isIn.length);
1313
- const [s, ...i] = n.map(({ loop: r }) => r);
1314
- return new b(s, i);
1315
- });
1316
- }
1317
- function rn(e, t) {
1318
- const n = [];
1319
- for (const s of e)
1320
- for (const i of t)
1321
- n.push([s, i]);
1322
- return n;
1323
- }
1324
- function* Mt(e, t, n) {
1325
- const s = (a) => t.some((o) => g(o, a.lastPoint)), i = (a) => n.some((o) => a.isSame(o));
1326
- let r = [];
1327
- for (const a of e)
1328
- s(a) ? (r.push(a), yield new I(r, { ignoreChecks: !0 }), r = []) : i(a) ? (r.length && (yield new I(r, { ignoreChecks: !0 }), r = []), yield new I([a], { ignoreChecks: !0 })) : r.push(a);
1329
- r.length && (yield new I(r, { ignoreChecks: !0 }));
1330
- }
1331
- const yt = (e, t) => {
1332
- const n = e.findIndex((r) => g(t, r.firstPoint)), s = e.slice(0, n);
1333
- return e.slice(n).concat(s);
1334
- }, At = (e, t) => {
1335
- let n = e;
1336
- const s = (o) => g(o.firstPoint, t.firstPoint) && g(o.lastPoint, t.lastPoint);
1337
- let i = e.findIndex(s);
1338
- if (i === -1) {
1339
- const o = e.map((u) => u.reverse());
1340
- if (o.reverse(), i = o.findIndex(s), i === -1)
1341
- throw console.error(
1342
- o.map((u) => u.repr),
1343
- t.repr
1344
- ), new Error("Failed to rotate to segment start");
1345
- n = o;
1346
- }
1347
- const r = n.slice(0, i);
1348
- return n.slice(i).concat(r);
1349
- };
1350
- function on(e, t, n) {
1351
- return e.filter((s) => {
1352
- const i = t.filter((o) => g(o.firstPoint, s) || g(o.lastPoint, s));
1353
- if (i.length % 2)
1354
- throw new Error("Bug in the intersection algo on non crossing point");
1355
- const r = i.map((o) => n.contains(o.midPoint));
1356
- return !(r.every((o) => o) || !r.some((o) => o));
1357
- });
1358
- }
1359
- function an(e, t, n) {
1360
- let s = [];
1361
- const i = [], r = new Array(e.segments.length).fill(0).map(() => []), a = new Array(t.segments.length).fill(0).map(() => []);
1362
- if (e.segments.forEach((f, m) => {
1363
- t.segments.forEach((P, w) => {
1364
- const { intersections: M, overlaps: v } = W(
1365
- f,
1366
- P,
1367
- n
1368
- );
1369
- s.push(...M), r[m].push(...M), a[w].push(...M), i.push(...v);
1370
- const x = v.flatMap((E) => [
1371
- E.firstPoint,
1372
- E.lastPoint
1373
- ]);
1374
- s.push(...x), r[m].push(...x), a[w].push(...x);
1375
- });
1376
- }), s = Q(s, n), !s.length || s.length === 1)
1377
- return null;
1378
- const o = ([f, m]) => m.length ? f.splitAt(m) : [f];
1379
- let u = L([e.segments, r]).flatMap(o), l = L([t.segments, a]).flatMap(o);
1380
- if (s = on(
1381
- s,
1382
- u,
1383
- t
1384
- ), !s.length && !i.length)
1385
- return null;
1386
- if (i.length) {
1387
- const f = i[0];
1388
- u = At(
1389
- u,
1390
- f
1391
- ), l = At(
1392
- l,
1393
- f
1394
- );
1395
- } else {
1396
- const f = s[0];
1397
- u = yt(u, f), l = yt(l, f);
1398
- }
1399
- let h = Array.from(
1400
- Mt(
1401
- u,
1402
- s,
1403
- i
1404
- )
1405
- ), c = Array.from(
1406
- Mt(
1407
- l,
1408
- s,
1409
- i
1410
- )
1411
- );
1412
- return (!g(
1413
- c[0].lastPoint,
1414
- h[0].lastPoint
1415
- ) || i.length > 0 && c[0].segmentsCount !== 1) && (c = c.map((f) => f.reverse()).reverse(), g(c[0].lastPoint, h[0].lastPoint) || (h = h.map((f) => f.reverse()).reverse())), L([h, c]).map(([f, m]) => f.segmentsCount === 1 && i.some((P) => f.segments[0].isSame(P)) ? [f, "same"] : [f, m]);
1416
- }
1417
- function St(e) {
1418
- let t = e[0];
1419
- for (const n of e.slice(1))
1420
- t = t.extend(n);
1421
- if (!g(t.firstPoint, t.lastPoint))
1422
- throw console.error(
1423
- y(t.firstPoint),
1424
- y(t.lastPoint)
1425
- ), new Error("Bug in the intersection algo on non closing strand");
1426
- return new O(t.segments);
1427
- }
1428
- function un(e, t) {
1429
- const n = L([
1430
- t.slice(0, -1),
1431
- t.slice(1)
1432
- ]).map(([i, r]) => St(e.slice(i, r)));
1433
- let s = e.slice(
1434
- t[t.length - 1]
1435
- );
1436
- return t[0] !== 0 && (s = s.concat(e.slice(0, t[0]))), n.push(St(s)), n;
1437
- }
1438
- function hn(e) {
1439
- if (!e.length)
1440
- return [];
1441
- const t = e.map((i) => i.firstPoint);
1442
- let n = e.map((i) => i.lastPoint);
1443
- n = n.slice(-1).concat(n.slice(0, -1));
1444
- const s = L([t, n]).flatMap(
1445
- ([i, r], a) => g(i, r) ? [] : a
1446
- );
1447
- try {
1448
- return un(e, s);
1449
- } catch {
1450
- return Lt(e.flatMap((r) => r.segments)).filter((r) => r.length > 1).filter((r) => g(r[0].firstPoint, r.at(-1).lastPoint)).map((r) => new O(r));
1451
- }
1452
- }
1453
- const bt = (e, t) => {
1454
- if (e.length === 0)
1455
- return [t];
1456
- const n = e.at(-1);
1457
- return g(n.lastPoint, t.firstPoint) ? e.slice(0, -1).concat([n.extend(t)]) : g(n.lastPoint, t.lastPoint) ? e.slice(0, -1).concat([n.extend(t.reverse())]) : e.concat([t]);
1458
- }, ln = (e, t) => e.length === 0 ? [t] : g(e[0].firstPoint, t.lastPoint) ? [t.extend(e[0])].concat(e.slice(1)) : [t].concat(e);
1459
- function lt(e, t, {
1460
- firstInside: n,
1461
- secondInside: s
1462
- }) {
1463
- const i = an(e, t);
1464
- if (!i) {
1465
- const u = e.segments[0].midPoint, l = t.contains(u), h = t.segments[0].midPoint, c = e.contains(h);
1466
- return {
1467
- identical: !1,
1468
- firstCurveInSecond: l,
1469
- secondCurveInFirst: c
1470
- };
1471
- }
1472
- if (i.every(([, u]) => u === "same"))
1473
- return { identical: !0 };
1474
- let r = null, a = null;
1475
- const o = i.flatMap(([u, l]) => {
1476
- let h = [], c = 0;
1477
- if (l === "same")
1478
- return a === 1 ? (a = 1, u) : a === 2 || a === 0 ? (a = null, []) : a === null ? (r ? r = r.extend(u) : r = u, []) : (console.error("weird situation"), []);
1479
- const f = u.segments[0].midPoint, m = t.contains(f);
1480
- (n === "keep" && m || n === "remove" && !m) && (c += 1, h = bt(h, u));
1481
- const P = l.segments[0].midPoint, w = e.contains(P);
1482
- if (s === "keep" && w || s === "remove" && !w) {
1483
- const M = l;
1484
- c += 1, c === 2 && h.length ? (h = bt(h, M), r = null) : h = [M];
1485
- }
1486
- return a === null && c === 1 && r && (h = ln(h, r)), c === 1 && (a = c, r = null), h.length ? h : (r = null, []);
1487
- });
1488
- return hn(o);
1489
- }
1490
- const cn = (e, t) => {
1491
- const n = lt(e, t, {
1492
- firstInside: "remove",
1493
- secondInside: "remove"
1494
- });
1495
- return Array.isArray(n) ? n : n.identical ? [e] : n.firstCurveInSecond ? [t] : n.secondCurveInFirst ? [e] : [e, t];
1496
- }, H = (e, t) => {
1497
- const n = lt(e, t, {
1498
- firstInside: "remove",
1499
- secondInside: "keep"
1500
- });
1501
- return Array.isArray(n) ? n : n.identical ? [] : n.firstCurveInSecond ? [] : n.secondCurveInFirst ? [e, t] : [e];
1502
- }, ct = (e, t) => {
1503
- const n = lt(e, t, {
1504
- firstInside: "keep",
1505
- secondInside: "keep"
1506
- });
1507
- return Array.isArray(n) ? n : n.identical ? [e] : n.firstCurveInSecond ? [e] : n.secondCurveInFirst ? [t] : [];
1508
- };
1509
- function fn(e) {
1510
- const t = /* @__PURE__ */ new Map(), n = [];
1511
- return e.forEach((s, i) => {
1512
- let r;
1513
- t.has(i) ? r = t.get(i) : (r = { current: [s], fusedWith: /* @__PURE__ */ new Set([i]) }, n.push(r)), e.slice(i + 1).forEach((a, o) => {
1514
- const u = r.current, l = i + o + 1;
1515
- if (r.fusedWith.has(l))
1516
- return;
1517
- let h = [a], c = !1;
1518
- if (t.has(l) && (h = t.get(l).current, c = !0), !u.some(
1519
- (P) => h.some((w) => P.intersects(w))
1520
- ))
1521
- return;
1522
- let m;
1523
- u.length > 1 || h.length > 1 ? m = U(u, h) : m = $t(u[0], h[0]), r.fusedWith.add(l), r.current = m, c || t.set(l, r);
1524
- });
1525
- }), n.flatMap(({ current: s }) => s);
1526
- }
1527
- function $t(e, t) {
1528
- const n = cn(e.contour, t.contour), s = t.holes.flatMap((a) => H(a, e.contour)), i = e.holes.flatMap((a) => H(a, t.contour)), r = rn(e.holes, t.holes).flatMap(
1529
- ([a, o]) => ct(a, o)
1530
- );
1531
- return D([
1532
- ...n,
1533
- ...s,
1534
- ...i,
1535
- ...r
1536
- ]);
1537
- }
1538
- function J(e, t) {
1539
- if (e.isFull && t.isFull)
1540
- return D(H(e.contour, t.contour));
1541
- if (e.isFull) {
1542
- const s = H(e.contour, t.contour), i = t.holes.flatMap(
1543
- (r) => ct(r, e.contour)
1544
- );
1545
- return D([...s, ...i]);
1546
- } else if (t.isFull && !e.contour.intersects(t.contour))
1547
- if (e.contour.contains(t.contour.firstPoint)) {
1548
- const s = U(
1549
- e.holes.map((i) => new b(i)),
1550
- [t]
1551
- );
1552
- return D([
1553
- e.contour,
1554
- ...s.flatMap((i) => i.allLoops)
1555
- ]);
1556
- } else
1557
- return [e];
1558
- let n = J(new b(e.contour), t);
1559
- return e.holes.forEach((s) => {
1560
- n = n.flatMap((i) => J(i, new b(s)));
1561
- }), n;
1562
- }
1563
- function gn(e, t) {
1564
- const n = ct(e.contour, t.contour);
1565
- if (!n.length)
1566
- return [];
1567
- let s = D(n);
1568
- return s = N(
1569
- s,
1570
- e.holes.map((i) => new b(i))
1571
- ), N(
1572
- s,
1573
- t.holes.map((i) => new b(i))
1574
- );
1575
- }
1576
- function U(e, t) {
1577
- if (!e.length)
1578
- return t;
1579
- if (!t.length)
1580
- return e;
1581
- if (e.length === 1 && t.length > 1 || t.length === 1 && e.length > 1)
1582
- return fn([...e, ...t]);
1583
- if (e.length > 1 && t.length > 1) {
1584
- let n = U([e[0]], t);
1585
- return e.slice(1).forEach((s) => {
1586
- n = U([s], n);
1587
- }), n;
1588
- }
1589
- return e.length === 1 && t.length === 1 ? $t(e[0], t[0]) : [];
1590
- }
1591
- function N(e, t) {
1592
- if (!e.length)
1593
- return [];
1594
- if (!t.length)
1595
- return e;
1596
- if (e.length === 1 && t.length === 1)
1597
- return J(e[0], t[0]);
1598
- if (e.length > 1)
1599
- return e.flatMap((s) => N([s], t));
1600
- let n = J(e[0], t[0]);
1601
- return t.slice(1).forEach((s) => {
1602
- n = N(n, [s]);
1603
- }), n;
1604
- }
1605
- function at(e, t) {
1606
- return !e.length || !t.length ? [] : e.length === 1 && t.length === 1 ? gn(e[0], t[0]) : e.length > 1 ? e.flatMap((n) => at([n], t)) : t.flatMap((n) => at(e, [n]));
1607
- }
1608
- class V extends K {
1609
- constructor(t = [], { ignoreChecks: n = !1 } = {}) {
1610
- super(), this._boundingBox = null, n || mn(t), this.figures = t;
1611
- }
1612
- get isEmpty() {
1613
- return this.figures.length === 0;
1614
- }
1615
- get boundingBox() {
1616
- if (this.isEmpty)
1617
- return new q();
1618
- if (this._boundingBox === null) {
1619
- let t = this.figures[0].boundingBox;
1620
- for (const n of this.figures.slice(1))
1621
- t = t.merge(n.boundingBox);
1622
- this._boundingBox = t;
1623
- }
1624
- return this._boundingBox;
1625
- }
1626
- clone() {
1627
- return new V(this.figures.map((t) => t.clone()));
1628
- }
1629
- transform(t) {
1630
- return new V(this.figures.map((n) => n.transform(t)));
1631
- }
1632
- contains(t) {
1633
- return this.figures.some((n) => n.contains(t));
1634
- }
1635
- intersects(t) {
1636
- return this.figures.some(
1637
- (n) => t.figures.some((s) => n.intersects(s))
1638
- );
1639
- }
1640
- overlappingStrands(t) {
1641
- return this.figures.flatMap((n) => t instanceof V ? t.figures.flatMap(
1642
- (s) => n.overlappingStrands(s)
1643
- ) : n.overlappingStrands(t));
1644
- }
1645
- fuse(t) {
1646
- return new V(U(this.figures, t.figures));
1647
- }
1648
- cut(t) {
1649
- return new V(N(this.figures, t.figures));
1650
- }
1651
- intersect(t) {
1652
- return new V(at(this.figures, t.figures));
1653
- }
1654
- }
1655
- function mn(e) {
1656
- for (const [t, n] of it(e))
1657
- if (t.intersects(n))
1658
- throw new Error("Diagram figures must not intersect");
1659
- }
1660
- export {
1661
- p as A,
1662
- q as B,
1663
- Pn as C,
1664
- V as D,
1665
- tt as E,
1666
- b as F,
1667
- pn as G,
1668
- R as H,
1669
- qt as I,
1670
- O as L,
1671
- I as S,
1672
- C as T,
1673
- U as a,
1674
- G as b,
1675
- N as c,
1676
- k as d,
1677
- A as e,
1678
- W as f,
1679
- S as g,
1680
- _ as h,
1681
- at as i,
1682
- kt as j,
1683
- Dt as k,
1684
- Z as l,
1685
- d as m,
1686
- B as n,
1687
- Lt as o,
1688
- Nt as p,
1689
- g as q,
1690
- Q as r,
1691
- Mt as s,
1692
- Y as t,
1693
- dn as u,
1694
- $ as v,
1695
- dt as w,
1696
- K as x,
1697
- F as y,
1698
- L as z
1699
- };
1700
- //# sourceMappingURL=Diagram-9915ed5e.js.map