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