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