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