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