pantograph2d 0.10.1 → 0.11.1
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/{QuadraticBezier-DCa0WGs0.js → QuadraticBezier-BeY2TXKH.js} +464 -433
- package/dist/QuadraticBezier-BeY2TXKH.js.map +1 -0
- package/dist/{QuadraticBezier-CuRsIP_D.cjs → QuadraticBezier-eSR75IzC.cjs} +9 -9
- package/dist/QuadraticBezier-eSR75IzC.cjs.map +1 -0
- package/dist/draw-BmJ8wIc9.cjs +2 -0
- package/dist/draw-BmJ8wIc9.cjs.map +1 -0
- package/dist/{draw-CJWiicbK.js → draw-DzKVhurb.js} +94 -89
- package/dist/draw-DzKVhurb.js.map +1 -0
- package/dist/{models-CFd5lRKc.js → models-BHeLX0dj.js} +544 -527
- package/dist/models-BHeLX0dj.js.map +1 -0
- package/dist/models-Fv9xfQBT.cjs +4 -0
- package/dist/models-Fv9xfQBT.cjs.map +1 -0
- package/dist/pantograph/drawShape.cjs +1 -1
- package/dist/pantograph/drawShape.js +2 -2
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +2 -2
- package/dist/pantograph/svg.cjs +1 -1
- package/dist/pantograph/svg.js +1 -1
- package/dist/pantograph.cjs +2 -2
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.js +677 -571
- package/dist/pantograph.js.map +1 -1
- package/dist/svg-BTO7h1ix.js +62 -0
- package/dist/svg-BTO7h1ix.js.map +1 -0
- package/dist/svg-b6SOnbda.cjs +8 -0
- package/dist/svg-b6SOnbda.cjs.map +1 -0
- package/dist/types/src/algorithms/offsets/offsetSegment.d.ts +1 -0
- package/dist/types/src/algorithms/tesselate/tesselateSegment.d.ts +7 -0
- package/dist/types/src/main.d.ts +1 -1
- package/dist/types/src/models/BoundingBox.d.ts +1 -0
- package/dist/types/src/models/Diagram.d.ts +1 -0
- package/dist/types/src/models/Figure.d.ts +1 -0
- package/dist/types/src/models/Loop.d.ts +1 -0
- package/dist/types/src/models/Strand.d.ts +5 -0
- package/dist/types/src/models/TransformationMatrix.d.ts +1 -0
- package/dist/types/src/models/segments/Arc.d.ts +1 -0
- package/dist/types/src/models/segments/CubicBezier.d.ts +1 -0
- package/dist/types/src/models/segments/EllipseArc.d.ts +1 -0
- package/dist/types/src/models/segments/Line.d.ts +2 -0
- package/dist/types/src/models/segments/QuadraticBezier.d.ts +1 -0
- package/dist/types/src/operations.d.ts +1 -0
- package/dist/types/src/tesselationOperations.d.ts +15 -0
- package/package.json +2 -2
- package/dist/QuadraticBezier-CuRsIP_D.cjs.map +0 -1
- package/dist/QuadraticBezier-DCa0WGs0.js.map +0 -1
- package/dist/draw-9Elv4xz6.cjs +0 -2
- package/dist/draw-9Elv4xz6.cjs.map +0 -1
- package/dist/draw-CJWiicbK.js.map +0 -1
- package/dist/models-CFd5lRKc.js.map +0 -1
- package/dist/models-LHGiMarC.cjs +0 -4
- package/dist/models-LHGiMarC.cjs.map +0 -1
- package/dist/svg-BzloQ9l1.cjs +0 -8
- package/dist/svg-BzloQ9l1.cjs.map +0 -1
- package/dist/svg-CD4q2GBE.js +0 -62
- package/dist/svg-CD4q2GBE.js.map +0 -1
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { b as k, d as
|
|
5
|
-
function
|
|
6
|
-
const e = k(n, t.firstPoint), s =
|
|
1
|
+
var on = Object.defineProperty;
|
|
2
|
+
var ln = (t, n, e) => n in t ? on(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
|
|
3
|
+
var b = (t, n, e) => ln(t, typeof n != "symbol" ? n + "" : n, e);
|
|
4
|
+
import { b as k, d as un, e as Dt, a as z, s as N, n as cn, p as Rt, l as j, A as x, g as P, w as Nt, E as C, T as an, x as fn, Q as M, y as $, C as A, c as hn, v as pn, L as y, F as Vt, G as ut, z as V, H as dn, m as mn, q as gn, I as mt, B as Pn } from "./QuadraticBezier-BeY2TXKH.js";
|
|
5
|
+
function In(t, n) {
|
|
6
|
+
const e = k(n, t.firstPoint), s = un(e, t.V) / t.squareLength;
|
|
7
7
|
return t.paramPoint(s);
|
|
8
8
|
}
|
|
9
9
|
function K(t, n, e) {
|
|
10
|
-
const s = e || t.precision, i =
|
|
11
|
-
if (
|
|
12
|
-
if (Math.abs(
|
|
10
|
+
const s = e || t.precision, i = In(t, n.center), r = Dt(i, n.center);
|
|
11
|
+
if (r > n.radius + s) return [];
|
|
12
|
+
if (Math.abs(r - n.radius) < s) {
|
|
13
13
|
const c = i;
|
|
14
14
|
return t.isOnSegment(c) && n.isOnSegment(c) ? [c] : [];
|
|
15
15
|
}
|
|
16
|
-
const l = [],
|
|
17
|
-
n.radius * n.radius -
|
|
18
|
-
), u = t.tangentAtFirstPoint, a = z(i,
|
|
16
|
+
const l = [], o = Math.sqrt(
|
|
17
|
+
n.radius * n.radius - r * r
|
|
18
|
+
), u = t.tangentAtFirstPoint, a = z(i, N(u, o));
|
|
19
19
|
t.isOnSegment(a) && n.isOnSegment(a) && l.push(a);
|
|
20
|
-
const f = z(i,
|
|
20
|
+
const f = z(i, N(u, -o));
|
|
21
21
|
return t.isOnSegment(f) && n.isOnSegment(f) && l.push(f), l;
|
|
22
22
|
}
|
|
23
|
-
const
|
|
23
|
+
const wn = (t) => {
|
|
24
24
|
const { firstPoint: n, lastPoint: e, center: s, clockwise: i } = t;
|
|
25
|
-
return new
|
|
25
|
+
return new x(e, n, s, i, {
|
|
26
26
|
ignoreChecks: !0
|
|
27
27
|
});
|
|
28
|
-
},
|
|
28
|
+
}, xn = (t, n) => {
|
|
29
29
|
if (t.isSame(n))
|
|
30
30
|
return [t];
|
|
31
|
-
const e =
|
|
31
|
+
const e = j(
|
|
32
32
|
[
|
|
33
33
|
n.isOnSegment(t.firstPoint) ? t.firstPoint : null,
|
|
34
34
|
n.isOnSegment(t.lastPoint) ? t.lastPoint : null,
|
|
@@ -41,11 +41,11 @@ const mn = (t) => {
|
|
|
41
41
|
if (e.length === 0) return [];
|
|
42
42
|
if (e.length === 1) return [];
|
|
43
43
|
if (e.length === 2)
|
|
44
|
-
return t.isSame(
|
|
44
|
+
return t.isSame(wn(n)) ? [] : [new x(e[0], e[1], t.center, t.clockwise)];
|
|
45
45
|
if (e.length === 3) {
|
|
46
46
|
const s = P(e[0], n.lastPoint) || P(e[0], n.firstPoint) ? 1 : 0;
|
|
47
47
|
return [
|
|
48
|
-
new
|
|
48
|
+
new x(
|
|
49
49
|
e[0 + s],
|
|
50
50
|
e[1 + s],
|
|
51
51
|
t.center,
|
|
@@ -54,133 +54,133 @@ const mn = (t) => {
|
|
|
54
54
|
];
|
|
55
55
|
} else if (e.length === 4)
|
|
56
56
|
return [
|
|
57
|
-
new
|
|
58
|
-
new
|
|
57
|
+
new x(e[0], e[1], t.center, t.clockwise),
|
|
58
|
+
new x(e[2], e[3], t.center, t.clockwise)
|
|
59
59
|
];
|
|
60
60
|
throw new Error("Bug in the arc arc overlap algorithm");
|
|
61
61
|
};
|
|
62
|
-
function
|
|
63
|
-
const i = s || t.precision,
|
|
64
|
-
if (
|
|
62
|
+
function jt(t, n, e = !1, s) {
|
|
63
|
+
const i = s || t.precision, r = Dt(t.center, n.center), l = t.radius + n.radius;
|
|
64
|
+
if (r > l + i)
|
|
65
65
|
return [];
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
66
|
+
const o = Math.abs(t.radius - n.radius);
|
|
67
|
+
if (r < o - i)
|
|
68
68
|
return [];
|
|
69
|
-
if (
|
|
70
|
-
return
|
|
71
|
-
const u =
|
|
69
|
+
if (r < i)
|
|
70
|
+
return o > i ? [] : e ? xn(t, n) : [];
|
|
71
|
+
const u = cn(k(n.center, t.center)), a = r > l - i;
|
|
72
72
|
if (
|
|
73
73
|
// circles are outside each other
|
|
74
74
|
a || // circles are inside each other
|
|
75
|
-
Math.abs(
|
|
75
|
+
Math.abs(r - o) < i
|
|
76
76
|
) {
|
|
77
|
-
const g = a || t.radius > n.radius ? 1 : -1,
|
|
77
|
+
const g = a || t.radius > n.radius ? 1 : -1, I = z(
|
|
78
78
|
t.center,
|
|
79
|
-
|
|
79
|
+
N(u, g * t.radius)
|
|
80
80
|
);
|
|
81
|
-
return t.isOnSegment(
|
|
81
|
+
return t.isOnSegment(I) && n.isOnSegment(I) ? [I] : [];
|
|
82
82
|
}
|
|
83
|
-
const f = t.radius * t.radius / (2 *
|
|
83
|
+
const f = t.radius * t.radius / (2 * r) - n.radius * n.radius / (2 * r) + r / 2, c = z(
|
|
84
84
|
t.center,
|
|
85
|
-
|
|
85
|
+
N(u, f)
|
|
86
86
|
), h = Math.sqrt(
|
|
87
87
|
t.radius * t.radius - f * f
|
|
88
|
-
), p =
|
|
89
|
-
return t.isOnSegment(d) && n.isOnSegment(d) &&
|
|
88
|
+
), p = Rt(u), d = z(c, N(p, h)), m = z(c, N(p, -h)), w = [];
|
|
89
|
+
return t.isOnSegment(d) && n.isOnSegment(d) && w.push(d), t.isOnSegment(m) && n.isOnSegment(m) && w.push(m), w;
|
|
90
90
|
}
|
|
91
91
|
function st(t, n, e = 1e-9) {
|
|
92
|
-
const s = t.transform(n.ellipseReferenceFrameTransform), i = s.slope,
|
|
93
|
-
(
|
|
94
|
-
).filter((
|
|
92
|
+
const s = t.transform(n.ellipseReferenceFrameTransform), i = s.slope, r = s.yIntercept, l = n.majorRadius * n.majorRadius, o = n.minorRadius * n.minorRadius, u = n.majorRadius * n.minorRadius, a = s.slope * s.slope, f = s.yIntercept * s.yIntercept, c = (g) => g.map(
|
|
93
|
+
(I) => n.reverseEllipseReferenceFrameTransform.transform(I)
|
|
94
|
+
).filter((I) => t.isOnSegment(I) && n.isOnSegment(I));
|
|
95
95
|
if (!Number.isFinite(i)) {
|
|
96
96
|
const g = s.firstPoint[0];
|
|
97
97
|
if (Math.abs(g) - n.majorRadius > e) return [];
|
|
98
98
|
if (Math.abs(Math.abs(g) - n.majorRadius) < e)
|
|
99
99
|
return c([[g, 0]]);
|
|
100
|
-
const
|
|
101
|
-
return c([F,
|
|
100
|
+
const I = n.minorRadius * Math.sqrt(1 - g * g / l), F = [g, I], S = [g, -I];
|
|
101
|
+
return c([F, S]);
|
|
102
102
|
}
|
|
103
|
-
const h = l * a +
|
|
103
|
+
const h = l * a + o - f;
|
|
104
104
|
if (h < -e)
|
|
105
105
|
return [];
|
|
106
|
-
const p = l * a +
|
|
106
|
+
const p = l * a + o;
|
|
107
107
|
if (Math.abs(h) < e) {
|
|
108
|
-
const g = -(l * i *
|
|
109
|
-
return c([[g,
|
|
108
|
+
const g = -(l * i * r) / p, I = o * r / p;
|
|
109
|
+
return c([[g, I]]);
|
|
110
110
|
}
|
|
111
111
|
const d = Math.sqrt(h), m = [
|
|
112
|
-
-(l * i *
|
|
113
|
-
(
|
|
114
|
-
],
|
|
115
|
-
-(l * i *
|
|
116
|
-
(
|
|
112
|
+
-(l * i * r + u * d) / p,
|
|
113
|
+
(o * r - u * i * d) / p
|
|
114
|
+
], w = [
|
|
115
|
+
-(l * i * r - u * d) / p,
|
|
116
|
+
(o * r + u * i * d) / p
|
|
117
117
|
];
|
|
118
|
-
return c([m,
|
|
119
|
-
}
|
|
120
|
-
function
|
|
121
|
-
const e = Math.max(t.precision, n.precision), s = t.coefficients, i = s.x2,
|
|
122
|
-
z0: a * i * d * d + i * i *
|
|
123
|
-
z1: m *
|
|
124
|
-
z2: m * m * i * i + 2 * p *
|
|
125
|
-
z3: -2 * i * c * l * m + m * c *
|
|
126
|
-
z4: i * i * p * p - 2 * i * p * c * l + c * c * l * l -
|
|
127
|
-
}, F =
|
|
118
|
+
return c([m, w]);
|
|
119
|
+
}
|
|
120
|
+
function Ut(t, n) {
|
|
121
|
+
const e = Math.max(t.precision, n.precision), s = t.coefficients, i = s.x2, r = s.xy, l = s.y2, o = s.x, u = s.y, a = s.c, f = n.coefficients, c = f.x2, h = f.xy, p = f.y2, d = f.x, m = f.y, w = f.c, g = {
|
|
122
|
+
z0: a * i * d * d + i * i * w * w - o * i * d * w + c * c * a * a - 2 * i * w * c * a - o * d * c * a + c * o * o * w,
|
|
123
|
+
z1: m * o * o * c - w * d * i * r - 2 * i * w * c * u - a * c * h * o + 2 * d * h * i * a + 2 * m * w * i * i + d * d * i * u - m * d * i * o - 2 * i * m * c * a - a * c * d * r + 2 * a * u * c * c - w * h * i * o - u * c * d * o + 2 * w * r * c * o,
|
|
124
|
+
z2: m * m * i * i + 2 * p * w * i * i - u * c * d * r + w * c * r * r - u * c * h * o - w * h * i * r - 2 * i * m * c * u + 2 * d * h * i * u - p * d * i * o - 2 * i * p * c * a + h * h * i * a + 2 * m * r * c * o + u * u * c * c - l * c * d * o - m * h * i * o + 2 * a * l * c * c - a * c * h * r + p * o * o * c + d * d * i * l - m * d * i * r - 2 * i * w * c * l,
|
|
125
|
+
z3: -2 * i * c * l * m + m * c * r * r + 2 * p * r * c * o - l * c * h * o + h * h * i * u - m * h * i * r - 2 * i * p * c * u - u * c * h * r - p * h * i * o + 2 * m * p * i * i + 2 * u * l * c * c - l * c * d * r + 2 * d * h * i * l - p * d * i * r,
|
|
126
|
+
z4: i * i * p * p - 2 * i * p * c * l + c * c * l * l - r * i * h * p - r * h * c * l + r * r * c * p + l * i * h * h
|
|
127
|
+
}, F = Nt(
|
|
128
128
|
[g.z0, g.z1, g.z2, g.z3, g.z4],
|
|
129
129
|
e
|
|
130
|
-
).flatMap((
|
|
131
|
-
const R = i * h *
|
|
130
|
+
).flatMap((S) => {
|
|
131
|
+
const R = i * h * S + i * d - c * r * S - c * o;
|
|
132
132
|
if (R)
|
|
133
|
-
return [[-(i *
|
|
134
|
-
const T =
|
|
133
|
+
return [[-(i * w + i * p * S * S - c * l * S * S + i * m * S - c * u * S - c * a) / R, S]];
|
|
134
|
+
const T = r * S + o, L = -T / (2 * i), U = l * S * S + u * S + a, q = T * T / (4 * i * i) - U / i;
|
|
135
135
|
if (Math.abs(q) < e)
|
|
136
|
-
return [[L,
|
|
136
|
+
return [[L, S]];
|
|
137
137
|
if (q > 0) {
|
|
138
138
|
const H = Math.sqrt(q);
|
|
139
|
-
return [[L + H,
|
|
139
|
+
return [[L + H, S], [L - H, S]];
|
|
140
140
|
}
|
|
141
141
|
return [];
|
|
142
142
|
});
|
|
143
|
-
return
|
|
143
|
+
return j(F, e);
|
|
144
144
|
}
|
|
145
145
|
function gt(t, n) {
|
|
146
|
-
return
|
|
146
|
+
return Ut(t, n).filter((s) => t.isOnSegment(s) && n.isOnSegment(s));
|
|
147
147
|
}
|
|
148
|
-
const
|
|
148
|
+
const Sn = (t) => {
|
|
149
149
|
const {
|
|
150
150
|
firstPoint: n,
|
|
151
151
|
lastPoint: e,
|
|
152
152
|
center: s,
|
|
153
153
|
majorRadius: i,
|
|
154
|
-
minorRadius:
|
|
154
|
+
minorRadius: r,
|
|
155
155
|
tiltAngle: l,
|
|
156
|
-
clockwise:
|
|
156
|
+
clockwise: o
|
|
157
157
|
} = t;
|
|
158
|
-
return new
|
|
158
|
+
return new C(
|
|
159
159
|
e,
|
|
160
160
|
n,
|
|
161
161
|
s,
|
|
162
162
|
i,
|
|
163
|
-
o,
|
|
164
|
-
l,
|
|
165
163
|
r,
|
|
164
|
+
l,
|
|
165
|
+
o,
|
|
166
166
|
{
|
|
167
167
|
ignoreChecks: !0,
|
|
168
168
|
angleUnits: "rad"
|
|
169
169
|
}
|
|
170
170
|
);
|
|
171
|
-
},
|
|
171
|
+
}, yn = (t, n) => {
|
|
172
172
|
if (t.isSame(n))
|
|
173
173
|
return [t];
|
|
174
|
-
const e = (i,
|
|
174
|
+
const e = (i, r) => new C(
|
|
175
175
|
i,
|
|
176
|
-
|
|
176
|
+
r,
|
|
177
177
|
t.center,
|
|
178
178
|
t.majorRadius,
|
|
179
179
|
t.minorRadius,
|
|
180
180
|
t.tiltAngle,
|
|
181
181
|
t.clockwise,
|
|
182
182
|
{ ignoreChecks: !0, angleUnits: "rad" }
|
|
183
|
-
), s =
|
|
183
|
+
), s = j(
|
|
184
184
|
[
|
|
185
185
|
n.isOnSegment(t.firstPoint) ? t.firstPoint : null,
|
|
186
186
|
n.isOnSegment(t.lastPoint) ? t.lastPoint : null,
|
|
@@ -189,11 +189,11 @@ const Pn = (t) => {
|
|
|
189
189
|
].filter((i) => i !== null)
|
|
190
190
|
// We sort by the param value of the first arc. This means that the points
|
|
191
191
|
// will be sorted with the same orientation than arc1
|
|
192
|
-
).sort((i,
|
|
192
|
+
).sort((i, r) => t.pointToParam(i) - t.pointToParam(r));
|
|
193
193
|
if (s.length === 0) return [];
|
|
194
194
|
if (s.length === 1) return [];
|
|
195
195
|
if (s.length === 2)
|
|
196
|
-
return t.isSame(
|
|
196
|
+
return t.isSame(Sn(n)) ? [] : [e(s[0], s[1])];
|
|
197
197
|
if (s.length === 3) {
|
|
198
198
|
const i = P(s[0], n.lastPoint) || P(s[0], n.firstPoint) ? 1 : 0;
|
|
199
199
|
return [e(s[0 + i], s[1 + i])];
|
|
@@ -201,42 +201,42 @@ const Pn = (t) => {
|
|
|
201
201
|
return [e(s[0], s[1]), e(s[2], s[3])];
|
|
202
202
|
throw new Error("Bug in the ellipse arc ellipse arc overlap algorithm");
|
|
203
203
|
};
|
|
204
|
-
function
|
|
204
|
+
function bn(t, n, e = !1) {
|
|
205
205
|
const s = Math.max(t.precision, n.precision);
|
|
206
|
-
return P(t.center, n.center) && Math.abs(t.majorRadius - n.majorRadius) < s && Math.abs(t.minorRadius - n.minorRadius) < s && (Math.abs(t.tiltAngle - n.tiltAngle) < s || Math.abs(Math.abs(t.tiltAngle - n.tiltAngle) - Math.PI) < s) ? e ?
|
|
206
|
+
return P(t.center, n.center) && Math.abs(t.majorRadius - n.majorRadius) < s && Math.abs(t.minorRadius - n.minorRadius) < s && (Math.abs(t.tiltAngle - n.tiltAngle) < s || Math.abs(Math.abs(t.tiltAngle - n.tiltAngle) - Math.PI) < s) ? e ? yn(t, n) : [] : Ut(t, n).filter((l) => t.isOnSegment(l) && n.isOnSegment(l));
|
|
207
207
|
}
|
|
208
208
|
function Pt(t, n) {
|
|
209
|
-
const [e, s] = t.firstPoint, [i,
|
|
210
|
-
return u.paramsAtY(0).map((a) => u.paramPoint(a)).map((a) =>
|
|
209
|
+
const [e, s] = t.firstPoint, [i, r] = t.lastPoint, l = new an().translate(-e, -s).rotate(-Math.atan2(r - s, i - e)), o = l.clone().inverse(), u = n.transform(l);
|
|
210
|
+
return u.paramsAtY(0).map((a) => u.paramPoint(a)).map((a) => o.transform(a)).filter((a) => t.isOnSegment(a));
|
|
211
211
|
}
|
|
212
|
-
const
|
|
212
|
+
const Cn = (t, n = 1e-9) => {
|
|
213
213
|
let e = t;
|
|
214
214
|
return Math.abs(t) < n && (e = 0), e.toFixed(-Math.log10(n));
|
|
215
215
|
};
|
|
216
|
-
function
|
|
216
|
+
function Ht(t, n = 1e-9) {
|
|
217
217
|
return Array.from(
|
|
218
|
-
new Map(t.map((e) => [
|
|
218
|
+
new Map(t.map((e) => [Cn(e, n), e])).values()
|
|
219
219
|
);
|
|
220
220
|
}
|
|
221
|
-
const
|
|
222
|
-
const [[e, s, i,
|
|
223
|
-
return [q, H,
|
|
221
|
+
const Mn = (t, n) => {
|
|
222
|
+
const [[e, s, i, r], [l, o, u, a]] = n.polynomialCoefficients, f = t.coefficients, c = f.x2, h = f.xy, p = f.y2, d = f.x, m = f.y, w = f.c, g = e * e, I = s * s, F = i * i, S = r * r, R = l * l, T = o * o, L = u * u, U = a * a, q = w + d * e + c * g + m * l + h * e * l + p * R, H = d * s + 2 * c * e * s + h * s * l + m * o + h * e * o + 2 * p * l * o, tn = c * I + d * i + 2 * c * e * i + h * i * l + h * s * o + p * T + m * u + h * e * u + 2 * p * l * u, nn = 2 * c * s * i + d * r + 2 * c * e * r + h * r * l + h * i * o + h * s * u + 2 * p * o * u + m * a + h * e * a + 2 * p * l * a, en = c * F + 2 * c * s * r + h * r * o + h * i * u + p * L + h * s * a + 2 * p * o * a, sn = 2 * c * i * r + h * r * u + h * i * a + 2 * p * u * a, rn = c * S + h * r * a + p * U;
|
|
223
|
+
return [q, H, tn, nn, en, sn, rn];
|
|
224
224
|
};
|
|
225
|
-
function
|
|
226
|
-
const e = Math.max(t.precision, n.precision), s =
|
|
227
|
-
return
|
|
225
|
+
function It(t, n) {
|
|
226
|
+
const e = Math.max(t.precision, n.precision), s = Mn(t, n), i = Nt(s, e).filter((r) => r >= -n.precision && r <= 1 + n.precision);
|
|
227
|
+
return Ht(i, e).map((r) => n.paramPoint(r)).filter((r) => t.isOnSegment(r));
|
|
228
228
|
}
|
|
229
|
-
const
|
|
230
|
-
const [[e, s, i], [
|
|
231
|
-
return [R, T, L,
|
|
229
|
+
const An = (t, n) => {
|
|
230
|
+
const [[e, s, i], [r, l, o]] = n.polynomialCoefficients, u = t.coefficients, a = u.x2, f = u.xy, c = u.y2, h = u.x, p = u.y, d = u.c, m = e * e, w = s * s, g = i * i, I = r * r, F = l * l, S = o * o, R = a * m + f * e * r + c * I + h * e + p * r + d, T = 2 * a * e * s + f * e * l + f * s * r + 2 * c * r * l + h * s + p * l, L = 2 * a * e * i + a * w + f * e * o + f * s * l + f * i * r + 2 * c * r * o + c * F + h * i + p * o, U = 2 * a * s * i + f * s * o + f * i * l + 2 * c * l * o, q = a * g + f * i * o + c * S;
|
|
231
|
+
return [R, T, L, U, q];
|
|
232
232
|
};
|
|
233
|
-
function
|
|
234
|
-
const e = Math.max(t.precision, n.precision), s =
|
|
235
|
-
return
|
|
233
|
+
function wt(t, n) {
|
|
234
|
+
const e = Math.max(t.precision, n.precision), s = An(t, n), i = fn(...s).filter((r) => r >= -n.precision && r <= 1 + n.precision);
|
|
235
|
+
return Ht(i, e).map((r) => n.paramPoint(r)).filter((r) => t.isOnSegment(r));
|
|
236
236
|
}
|
|
237
237
|
function E(t, { firstPoint: n, lastPoint: e }, s = 1e-9) {
|
|
238
238
|
const i = k(e, n);
|
|
239
|
-
return Math.abs(i[0]) < s ? i[1] > 0 ? n[0] - t[0] : t[0] - n[0] : Math.abs(i[1]) < s ? i[0] > 0 ? t[1] - n[1] : n[1] - t[1] :
|
|
239
|
+
return Math.abs(i[0]) < s ? i[1] > 0 ? n[0] - t[0] : t[0] - n[0] : Math.abs(i[1]) < s ? i[0] > 0 ? t[1] - n[1] : n[1] - t[1] : hn(i, k(t, n)) / pn(i);
|
|
240
240
|
}
|
|
241
241
|
class ct {
|
|
242
242
|
constructor(n, e, s, i) {
|
|
@@ -246,9 +246,9 @@ class ct {
|
|
|
246
246
|
return this.positiveThickness - this.negativeThickness;
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
const
|
|
250
|
-
function
|
|
251
|
-
const n = E(t.firstControlPoint, t), e = E(t.lastControlPoint, t), s = n * e > 0 ?
|
|
249
|
+
const En = 3 / 4, Fn = 4 / 9;
|
|
250
|
+
function vn(t) {
|
|
251
|
+
const n = E(t.firstControlPoint, t), e = E(t.lastControlPoint, t), s = n * e > 0 ? En : Fn;
|
|
252
252
|
return new ct(
|
|
253
253
|
t.firstPoint,
|
|
254
254
|
t.lastPoint,
|
|
@@ -256,7 +256,7 @@ function In(t) {
|
|
|
256
256
|
s * Math.max(0, n, e)
|
|
257
257
|
);
|
|
258
258
|
}
|
|
259
|
-
function
|
|
259
|
+
function Bn(t) {
|
|
260
260
|
const n = E(t.controlPoint, t);
|
|
261
261
|
return new ct(
|
|
262
262
|
t.firstPoint,
|
|
@@ -265,32 +265,32 @@ function An(t) {
|
|
|
265
265
|
Math.max(0, n / 2)
|
|
266
266
|
);
|
|
267
267
|
}
|
|
268
|
-
function
|
|
269
|
-
if (t
|
|
270
|
-
return
|
|
271
|
-
if (t
|
|
272
|
-
return
|
|
268
|
+
function kn(t) {
|
|
269
|
+
if (A.isInstance(t))
|
|
270
|
+
return vn(t);
|
|
271
|
+
if (M.isInstance(t))
|
|
272
|
+
return Bn(t);
|
|
273
273
|
throw new Error("Not implemented");
|
|
274
274
|
}
|
|
275
|
-
function
|
|
276
|
-
const n = t.paramPoint(0.5), e =
|
|
275
|
+
function On(t) {
|
|
276
|
+
const n = t.paramPoint(0.5), e = Rt(k(n, t.firstPoint)), s = z(n, e), i = {
|
|
277
277
|
firstPoint: n,
|
|
278
278
|
lastPoint: s
|
|
279
|
-
},
|
|
279
|
+
}, r = [
|
|
280
280
|
E(t.firstPoint, i),
|
|
281
281
|
E(t.lastPoint, i)
|
|
282
282
|
];
|
|
283
|
-
return t
|
|
283
|
+
return A.isInstance(t) ? r.push(
|
|
284
284
|
E(t.firstControlPoint, i),
|
|
285
285
|
E(t.lastControlPoint, i)
|
|
286
|
-
) : t
|
|
286
|
+
) : M.isInstance(t) && r.push(E(t.controlPoint, i)), new ct(
|
|
287
287
|
n,
|
|
288
288
|
s,
|
|
289
|
-
Math.min(...
|
|
290
|
-
Math.max(...
|
|
289
|
+
Math.min(...r),
|
|
290
|
+
Math.max(...r)
|
|
291
291
|
);
|
|
292
292
|
}
|
|
293
|
-
function
|
|
293
|
+
function xt(t, n) {
|
|
294
294
|
const e = [];
|
|
295
295
|
for (let s = 1; s < t.length; s++) {
|
|
296
296
|
const i = t[s];
|
|
@@ -298,10 +298,10 @@ function St(t, n) {
|
|
|
298
298
|
e.push(i[0]);
|
|
299
299
|
continue;
|
|
300
300
|
}
|
|
301
|
-
const
|
|
302
|
-
if (l *
|
|
301
|
+
const r = t[s - 1], l = n - r[1], o = n - i[1];
|
|
302
|
+
if (l * o < 0) {
|
|
303
303
|
e.push(
|
|
304
|
-
|
|
304
|
+
r[0] + (n - r[1]) * (i[0] - r[0]) / (i[1] - r[1])
|
|
305
305
|
);
|
|
306
306
|
continue;
|
|
307
307
|
}
|
|
@@ -319,29 +319,29 @@ class Y {
|
|
|
319
319
|
return this.from === "start" ? this.to === "end" ? n : n.splitAtParameters([this.to])[0] : this.to === "end" ? n.splitAtParameters([this.from])[1] : n.splitAtParameters([this.from, this.to])[1];
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
-
function
|
|
323
|
-
if (t
|
|
324
|
-
return new
|
|
322
|
+
function _n(t, n) {
|
|
323
|
+
if (A.isInstance(t))
|
|
324
|
+
return new Ln([
|
|
325
325
|
E(t.firstPoint, n),
|
|
326
326
|
E(t.firstControlPoint, n),
|
|
327
327
|
E(t.lastControlPoint, n),
|
|
328
328
|
E(t.lastPoint, n)
|
|
329
329
|
]);
|
|
330
|
-
if (t
|
|
331
|
-
return new
|
|
330
|
+
if (M.isInstance(t))
|
|
331
|
+
return new Tn([
|
|
332
332
|
E(t.firstPoint, n),
|
|
333
333
|
E(t.controlPoint, n),
|
|
334
334
|
E(t.lastPoint, n)
|
|
335
335
|
]);
|
|
336
336
|
throw new Error("Not implemented");
|
|
337
337
|
}
|
|
338
|
-
class
|
|
338
|
+
class Tn {
|
|
339
339
|
constructor(n) {
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
b(this, "topHull", []);
|
|
341
|
+
b(this, "bottomHull", []);
|
|
342
342
|
this.distances = n;
|
|
343
|
-
const [e, s, i] = n,
|
|
344
|
-
s - (u * (1 / 2) + a) > 0 ? (this.topHull = [
|
|
343
|
+
const [e, s, i] = n, r = [0, e], l = [1 / 2, s], o = [1, i], u = i - e, a = e;
|
|
344
|
+
s - (u * (1 / 2) + a) > 0 ? (this.topHull = [r, l, o], this.bottomHull = [r, o]) : (this.topHull = [r, o], this.bottomHull = [r, l, o]);
|
|
345
345
|
}
|
|
346
346
|
get startDistance() {
|
|
347
347
|
return this.distances[0];
|
|
@@ -350,18 +350,18 @@ class Bn {
|
|
|
350
350
|
return this.distances[2];
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
|
-
class
|
|
353
|
+
class Ln {
|
|
354
354
|
constructor(n) {
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
b(this, "topHull", []);
|
|
356
|
+
b(this, "bottomHull", []);
|
|
357
357
|
this.distances = n;
|
|
358
|
-
const [e, s, i,
|
|
358
|
+
const [e, s, i, r] = n, l = [0, e], o = [1 / 3, s], u = [2 / 3, i], a = [1, r], f = r - e, c = e, h = s - (f * (1 / 3) + c), p = i - (f * (2 / 3) + c);
|
|
359
359
|
let d = null, m = null;
|
|
360
360
|
if (h * p < 0)
|
|
361
|
-
d = [l,
|
|
361
|
+
d = [l, o, a], m = [l, u, a];
|
|
362
362
|
else {
|
|
363
363
|
const g = h / p;
|
|
364
|
-
g >= 2 ? (d = [l,
|
|
364
|
+
g >= 2 ? (d = [l, o, a], m = [l, a]) : g <= 0.5 ? (d = [l, u, a], m = [l, a]) : (d = [l, o, u, a], m = [l, a]);
|
|
365
365
|
}
|
|
366
366
|
h < 0 && ([d, m] = [m, d]), this.topHull = d, this.bottomHull = m;
|
|
367
367
|
}
|
|
@@ -372,16 +372,16 @@ class kn {
|
|
|
372
372
|
return this.distances[3];
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
|
-
function
|
|
376
|
-
const e =
|
|
375
|
+
function St(t, n) {
|
|
376
|
+
const e = _n(n, t), s = xt(
|
|
377
377
|
e.topHull,
|
|
378
378
|
t.negativeThickness
|
|
379
|
-
), i =
|
|
379
|
+
), i = xt(
|
|
380
380
|
e.bottomHull,
|
|
381
381
|
t.positiveThickness
|
|
382
|
-
),
|
|
382
|
+
), r = e.endDistance >= t.negativeThickness && e.endDistance <= t.positiveThickness;
|
|
383
383
|
if (!s.length && !i.length)
|
|
384
|
-
return
|
|
384
|
+
return r ? new Y("start", "end") : null;
|
|
385
385
|
if (s.length === 1 && i.length === 1)
|
|
386
386
|
return new Y(s[0], i[0]);
|
|
387
387
|
if (s.length === 2 && i.length === 2)
|
|
@@ -389,26 +389,26 @@ function yt(t, n) {
|
|
|
389
389
|
"Bug in the clipping algorithm, unexpected number of crossing points"
|
|
390
390
|
);
|
|
391
391
|
const l = s.length ? s : i;
|
|
392
|
-
return l.length === 2 ? new Y(l[0], l[1]) :
|
|
392
|
+
return l.length === 2 ? new Y(l[0], l[1]) : r ? new Y(l[0], "end") : new Y("start", l[0]);
|
|
393
393
|
}
|
|
394
|
-
function
|
|
395
|
-
const e =
|
|
394
|
+
function yt(t, n) {
|
|
395
|
+
const e = kn(t), s = St(e, n);
|
|
396
396
|
if (!s)
|
|
397
397
|
return null;
|
|
398
|
-
const i =
|
|
398
|
+
const i = On(t), r = St(
|
|
399
399
|
i,
|
|
400
400
|
n
|
|
401
401
|
);
|
|
402
|
-
return
|
|
402
|
+
return r ? s.size > r.size ? r.clipCurve(n) : s.clipCurve(n) : null;
|
|
403
403
|
}
|
|
404
|
-
const W = (t) => t
|
|
404
|
+
const W = (t) => M.isInstance(t) ? $(k(t.controlPoint, t.firstPoint)) + $(k(t.controlPoint, t.lastPoint)) : $(k(t.firstControlPoint, t.firstPoint)) + $(k(t.lastControlPoint, t.firstControlPoint)) + $(k(t.lastControlPoint, t.lastPoint));
|
|
405
405
|
function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
|
|
406
406
|
const i = Math.max(e * e, Number.EPSILON * 10);
|
|
407
|
-
let
|
|
407
|
+
let r = t, l = n, o = W(r), u = W(l);
|
|
408
408
|
for (let a = 0; a < s; a++) {
|
|
409
|
-
const f =
|
|
409
|
+
const f = o > i ? yt(l, r) : r;
|
|
410
410
|
if (!f) return [];
|
|
411
|
-
const c = W(f), h = u > i ?
|
|
411
|
+
const c = W(f), h = u > i ? yt(f, l) : l;
|
|
412
412
|
if (!h) return [];
|
|
413
413
|
const p = W(h);
|
|
414
414
|
if (c <= i && p <= i)
|
|
@@ -419,12 +419,12 @@ function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
|
|
|
419
419
|
return [f.firstPoint];
|
|
420
420
|
if (P(h.firstPoint, h.lastPoint) && f.isOnSegment(h.firstPoint))
|
|
421
421
|
return [h.firstPoint];
|
|
422
|
-
if (c > 0.8 *
|
|
423
|
-
if (c /
|
|
422
|
+
if (c > 0.8 * o && p > 0.8 * u)
|
|
423
|
+
if (c / o > p / u) {
|
|
424
424
|
const [d, m] = f.splitAtParameters([
|
|
425
425
|
0.5
|
|
426
426
|
]);
|
|
427
|
-
return
|
|
427
|
+
return j(
|
|
428
428
|
[
|
|
429
429
|
...D(d, h, e, {
|
|
430
430
|
maxIterations: s - a
|
|
@@ -439,7 +439,7 @@ function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
|
|
|
439
439
|
const [d, m] = h.splitAtParameters([
|
|
440
440
|
0.5
|
|
441
441
|
]);
|
|
442
|
-
return
|
|
442
|
+
return j(
|
|
443
443
|
[
|
|
444
444
|
...D(f, d, e, {
|
|
445
445
|
maxIterations: s - a
|
|
@@ -451,19 +451,19 @@ function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
|
|
|
451
451
|
e
|
|
452
452
|
);
|
|
453
453
|
}
|
|
454
|
-
|
|
454
|
+
r = f, l = h, o = c, u = p;
|
|
455
455
|
}
|
|
456
456
|
throw new Error("Bézier clip: Maximum number of iterations reached");
|
|
457
457
|
}
|
|
458
|
-
function
|
|
458
|
+
function qn(t, n) {
|
|
459
459
|
const e = [];
|
|
460
460
|
if ([
|
|
461
461
|
[t.firstPoint, n],
|
|
462
462
|
[t.lastPoint, n],
|
|
463
463
|
[n.firstPoint, t],
|
|
464
464
|
[n.lastPoint, t]
|
|
465
|
-
].forEach(([i,
|
|
466
|
-
|
|
465
|
+
].forEach(([i, r]) => {
|
|
466
|
+
r.isOnSegment(i) && e.push(i);
|
|
467
467
|
}), e.length < 2)
|
|
468
468
|
return null;
|
|
469
469
|
if (e.length === 2)
|
|
@@ -473,24 +473,24 @@ function On(t, n) {
|
|
|
473
473
|
if (e.length === 4)
|
|
474
474
|
return [t];
|
|
475
475
|
}
|
|
476
|
-
function
|
|
476
|
+
function zn(t, n, e = !1) {
|
|
477
477
|
const s = Math.max(t.precision, n.precision);
|
|
478
478
|
if (e) {
|
|
479
|
-
const i =
|
|
479
|
+
const i = qn(t, n);
|
|
480
480
|
if (i)
|
|
481
481
|
return i;
|
|
482
482
|
}
|
|
483
483
|
return D(t, n, s);
|
|
484
484
|
}
|
|
485
|
-
function
|
|
485
|
+
function Dn(t, n) {
|
|
486
486
|
const e = [];
|
|
487
487
|
if ([
|
|
488
488
|
[t.firstPoint, n],
|
|
489
489
|
[t.lastPoint, n],
|
|
490
490
|
[n.firstPoint, t],
|
|
491
491
|
[n.lastPoint, t]
|
|
492
|
-
].forEach(([i,
|
|
493
|
-
|
|
492
|
+
].forEach(([i, r]) => {
|
|
493
|
+
r.isOnSegment(i) && e.push(i);
|
|
494
494
|
}), e.length < 2)
|
|
495
495
|
return null;
|
|
496
496
|
if (e.length === 2)
|
|
@@ -500,18 +500,18 @@ function Tn(t, n) {
|
|
|
500
500
|
if (e.length === 4)
|
|
501
501
|
return [t];
|
|
502
502
|
}
|
|
503
|
-
function
|
|
503
|
+
function Rn(t, n, e = !1) {
|
|
504
504
|
const s = Math.max(t.precision, n.precision);
|
|
505
505
|
if (e) {
|
|
506
|
-
const i =
|
|
506
|
+
const i = Dn(t, n);
|
|
507
507
|
if (i)
|
|
508
508
|
return i;
|
|
509
509
|
}
|
|
510
510
|
return D(t, n, s);
|
|
511
511
|
}
|
|
512
|
-
function
|
|
513
|
-
if (t
|
|
514
|
-
const s =
|
|
512
|
+
function Ie(t, n, e) {
|
|
513
|
+
if (y.isInstance(t) && y.isInstance(n)) {
|
|
514
|
+
const s = Vt(
|
|
515
515
|
t,
|
|
516
516
|
n,
|
|
517
517
|
!1,
|
|
@@ -519,42 +519,42 @@ function de(t, n, e) {
|
|
|
519
519
|
);
|
|
520
520
|
return s === null ? [] : [s];
|
|
521
521
|
}
|
|
522
|
-
if (t
|
|
522
|
+
if (y.isInstance(t) && x.isInstance(n))
|
|
523
523
|
return K(t, n, e);
|
|
524
|
-
if (t
|
|
524
|
+
if (x.isInstance(t) && y.isInstance(n))
|
|
525
525
|
return K(n, t, e);
|
|
526
|
-
if (t
|
|
527
|
-
return
|
|
526
|
+
if (x.isInstance(t) && x.isInstance(n))
|
|
527
|
+
return jt(t, n, !1, e);
|
|
528
528
|
throw new Error("Not implemented");
|
|
529
529
|
}
|
|
530
530
|
function Z(t, n, e) {
|
|
531
|
-
if (t
|
|
532
|
-
const s =
|
|
531
|
+
if (y.isInstance(t) && y.isInstance(n)) {
|
|
532
|
+
const s = Vt(
|
|
533
533
|
t,
|
|
534
534
|
n,
|
|
535
535
|
!0,
|
|
536
536
|
e
|
|
537
537
|
);
|
|
538
|
-
return s === null ? { intersections: [], overlaps: [], count: 0 } : s
|
|
538
|
+
return s === null ? { intersections: [], overlaps: [], count: 0 } : y.isInstance(s) ? { intersections: [], overlaps: [s], count: 1 } : { intersections: [s], overlaps: [], count: 1 };
|
|
539
539
|
}
|
|
540
540
|
if (!t.boundingBox.overlaps(n.boundingBox))
|
|
541
541
|
return { intersections: [], overlaps: [], count: 0 };
|
|
542
|
-
if (t
|
|
542
|
+
if (y.isInstance(t) && x.isInstance(n)) {
|
|
543
543
|
const s = K(t, n, e);
|
|
544
544
|
return { intersections: s, overlaps: [], count: s.length };
|
|
545
545
|
}
|
|
546
|
-
if (t
|
|
546
|
+
if (x.isInstance(t) && y.isInstance(n)) {
|
|
547
547
|
const s = K(n, t, e);
|
|
548
548
|
return { intersections: s, overlaps: [], count: s.length };
|
|
549
549
|
}
|
|
550
|
-
if (t
|
|
551
|
-
const s =
|
|
550
|
+
if (x.isInstance(t) && x.isInstance(n)) {
|
|
551
|
+
const s = jt(
|
|
552
552
|
t,
|
|
553
553
|
n,
|
|
554
554
|
!0,
|
|
555
555
|
e
|
|
556
556
|
);
|
|
557
|
-
return s.length ? s[0]
|
|
557
|
+
return s.length ? x.isInstance(s[0]) ? {
|
|
558
558
|
intersections: [],
|
|
559
559
|
overlaps: s,
|
|
560
560
|
count: s.length
|
|
@@ -564,7 +564,7 @@ function Z(t, n, e) {
|
|
|
564
564
|
count: s.length
|
|
565
565
|
} : { intersections: [], overlaps: [], count: 0 };
|
|
566
566
|
}
|
|
567
|
-
if (t
|
|
567
|
+
if (y.isInstance(t) && C.isInstance(n)) {
|
|
568
568
|
const s = st(
|
|
569
569
|
t,
|
|
570
570
|
n,
|
|
@@ -572,7 +572,7 @@ function Z(t, n, e) {
|
|
|
572
572
|
);
|
|
573
573
|
return { intersections: s, overlaps: [], count: s.length };
|
|
574
574
|
}
|
|
575
|
-
if (n
|
|
575
|
+
if (y.isInstance(n) && C.isInstance(t)) {
|
|
576
576
|
const s = st(
|
|
577
577
|
n,
|
|
578
578
|
t,
|
|
@@ -580,21 +580,21 @@ function Z(t, n, e) {
|
|
|
580
580
|
);
|
|
581
581
|
return { intersections: s, overlaps: [], count: s.length };
|
|
582
582
|
}
|
|
583
|
-
if (t
|
|
583
|
+
if (x.isInstance(t) && C.isInstance(n)) {
|
|
584
584
|
const s = gt(t, n);
|
|
585
585
|
return { intersections: s, overlaps: [], count: s.length };
|
|
586
586
|
}
|
|
587
|
-
if (n
|
|
587
|
+
if (x.isInstance(n) && C.isInstance(t)) {
|
|
588
588
|
const s = gt(n, t);
|
|
589
589
|
return { intersections: s, overlaps: [], count: s.length };
|
|
590
590
|
}
|
|
591
|
-
if (t
|
|
592
|
-
const s =
|
|
591
|
+
if (C.isInstance(t) && C.isInstance(n)) {
|
|
592
|
+
const s = bn(
|
|
593
593
|
t,
|
|
594
594
|
n,
|
|
595
595
|
!0
|
|
596
596
|
);
|
|
597
|
-
return s.length ? s[0]
|
|
597
|
+
return s.length ? C.isInstance(s[0]) ? {
|
|
598
598
|
intersections: [],
|
|
599
599
|
overlaps: s,
|
|
600
600
|
count: s.length
|
|
@@ -604,36 +604,36 @@ function Z(t, n, e) {
|
|
|
604
604
|
count: s.length
|
|
605
605
|
} : { intersections: [], overlaps: [], count: 0 };
|
|
606
606
|
}
|
|
607
|
-
if (t
|
|
607
|
+
if (y.isInstance(t) && (A.isInstance(n) || M.isInstance(n))) {
|
|
608
608
|
const s = Pt(t, n);
|
|
609
609
|
return { intersections: s, overlaps: [], count: s.length };
|
|
610
610
|
}
|
|
611
|
-
if (n
|
|
611
|
+
if (y.isInstance(n) && (A.isInstance(t) || M.isInstance(t))) {
|
|
612
612
|
const s = Pt(n, t);
|
|
613
613
|
return { intersections: s, overlaps: [], count: s.length };
|
|
614
614
|
}
|
|
615
|
-
if ((t
|
|
616
|
-
const s =
|
|
615
|
+
if ((x.isInstance(t) || C.isInstance(t)) && M.isInstance(n)) {
|
|
616
|
+
const s = wt(t, n);
|
|
617
617
|
return { intersections: s, overlaps: [], count: s.length };
|
|
618
618
|
}
|
|
619
|
-
if ((n
|
|
620
|
-
const s =
|
|
619
|
+
if ((x.isInstance(n) || C.isInstance(n)) && M.isInstance(t)) {
|
|
620
|
+
const s = wt(n, t);
|
|
621
621
|
return { intersections: s, overlaps: [], count: s.length };
|
|
622
622
|
}
|
|
623
|
-
if ((t
|
|
624
|
-
const s =
|
|
623
|
+
if ((x.isInstance(t) || C.isInstance(t)) && A.isInstance(n)) {
|
|
624
|
+
const s = It(t, n);
|
|
625
625
|
return { intersections: s, overlaps: [], count: s.length };
|
|
626
626
|
}
|
|
627
|
-
if ((n
|
|
628
|
-
const s =
|
|
627
|
+
if ((x.isInstance(n) || C.isInstance(n)) && A.isInstance(t)) {
|
|
628
|
+
const s = It(n, t);
|
|
629
629
|
return { intersections: s, overlaps: [], count: s.length };
|
|
630
630
|
}
|
|
631
|
-
if (t
|
|
632
|
-
const s =
|
|
631
|
+
if (M.isInstance(t) && M.isInstance(n)) {
|
|
632
|
+
const s = Rn(
|
|
633
633
|
t,
|
|
634
634
|
n
|
|
635
635
|
);
|
|
636
|
-
return s.length ? s[0]
|
|
636
|
+
return s.length ? M.isInstance(s[0]) ? {
|
|
637
637
|
intersections: [],
|
|
638
638
|
overlaps: s,
|
|
639
639
|
count: s.length
|
|
@@ -643,16 +643,16 @@ function Z(t, n, e) {
|
|
|
643
643
|
count: s.length
|
|
644
644
|
} : { intersections: [], overlaps: [], count: 0 };
|
|
645
645
|
}
|
|
646
|
-
if (t
|
|
646
|
+
if (M.isInstance(t) && A.isInstance(n) || M.isInstance(n) && A.isInstance(t)) {
|
|
647
647
|
const s = D(t, n);
|
|
648
648
|
return { intersections: s, overlaps: [], count: s.length };
|
|
649
649
|
}
|
|
650
|
-
if (t
|
|
651
|
-
const s =
|
|
650
|
+
if (A.isInstance(t) && A.isInstance(n)) {
|
|
651
|
+
const s = zn(
|
|
652
652
|
t,
|
|
653
653
|
n
|
|
654
654
|
);
|
|
655
|
-
return s.length ? s[0]
|
|
655
|
+
return s.length ? A.isInstance(s[0]) ? {
|
|
656
656
|
intersections: [],
|
|
657
657
|
overlaps: s,
|
|
658
658
|
count: s.length
|
|
@@ -664,7 +664,7 @@ function Z(t, n, e) {
|
|
|
664
664
|
}
|
|
665
665
|
throw new Error("Not implemented");
|
|
666
666
|
}
|
|
667
|
-
function
|
|
667
|
+
function $t(t) {
|
|
668
668
|
const n = [];
|
|
669
669
|
for (let e = 0; e < t; e++)
|
|
670
670
|
for (let s = 0; s <= e; s++)
|
|
@@ -672,15 +672,15 @@ function Nt(t) {
|
|
|
672
672
|
return n;
|
|
673
673
|
}
|
|
674
674
|
function* it(t) {
|
|
675
|
-
for (const [n, e] of
|
|
675
|
+
for (const [n, e] of $t(t.length))
|
|
676
676
|
n !== e && (yield [t[n], t[e]]);
|
|
677
677
|
}
|
|
678
|
-
class
|
|
678
|
+
class Yt extends ut {
|
|
679
679
|
constructor(e, { ignoreChecks: s = !1 } = {}) {
|
|
680
680
|
super();
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
s ||
|
|
681
|
+
b(this, "segments");
|
|
682
|
+
b(this, "_boundingBox", null);
|
|
683
|
+
s || Xt(e), this.segments = e;
|
|
684
684
|
}
|
|
685
685
|
get repr() {
|
|
686
686
|
return this.segments.map((e) => e.repr).join(`
|
|
@@ -725,36 +725,36 @@ class Ut extends ut {
|
|
|
725
725
|
return this.repr;
|
|
726
726
|
}
|
|
727
727
|
}
|
|
728
|
-
function
|
|
729
|
-
|
|
728
|
+
function Nn(t, n = "Stroke") {
|
|
729
|
+
$t(t.length).forEach(
|
|
730
730
|
([e, s]) => {
|
|
731
731
|
if (e === s) return;
|
|
732
|
-
const i = t[e],
|
|
732
|
+
const i = t[e], r = t[s], l = Z(i, r), o = Math.max(i.precision, r.precision);
|
|
733
733
|
if (l.count !== 0) {
|
|
734
734
|
if (l.count === 1 && !l.overlaps.length) {
|
|
735
735
|
const u = e - s, a = l.intersections[0];
|
|
736
|
-
if (u === 1 && P(i.firstPoint, a,
|
|
736
|
+
if (u === 1 && P(i.firstPoint, a, o) || u === -1 && P(i.lastPoint, a, o) || u === t.length - 1 && P(i.lastPoint, a, o) && P(r.firstPoint, a, o) || -u === t.length - 1 && P(i.firstPoint, a, o) && P(r.lastPoint, a, o))
|
|
737
737
|
return;
|
|
738
738
|
}
|
|
739
739
|
if (!(l.count === 2 && t.length === 2 && (P(
|
|
740
740
|
i.firstPoint,
|
|
741
741
|
l.intersections[0],
|
|
742
|
-
|
|
742
|
+
o
|
|
743
743
|
) && P(
|
|
744
744
|
i.lastPoint,
|
|
745
745
|
l.intersections[1],
|
|
746
|
-
|
|
746
|
+
o
|
|
747
747
|
) || P(
|
|
748
748
|
i.firstPoint,
|
|
749
749
|
l.intersections[1],
|
|
750
|
-
|
|
750
|
+
o
|
|
751
751
|
) && P(
|
|
752
752
|
i.lastPoint,
|
|
753
753
|
l.intersections[0],
|
|
754
|
-
|
|
754
|
+
o
|
|
755
755
|
))))
|
|
756
756
|
throw new Error(
|
|
757
|
-
`${n} segments must not intersect, but segments ${i.info} and ${
|
|
757
|
+
`${n} segments must not intersect, but segments ${i.info} and ${r.info} do at ${JSON.stringify(
|
|
758
758
|
l.intersections
|
|
759
759
|
)}`
|
|
760
760
|
);
|
|
@@ -762,26 +762,26 @@ function qn(t, n = "Stroke") {
|
|
|
762
762
|
}
|
|
763
763
|
);
|
|
764
764
|
}
|
|
765
|
-
function
|
|
765
|
+
function Xt(t, n = "Stroke") {
|
|
766
766
|
if (t.length === 0)
|
|
767
767
|
throw new Error(`${n} must have at least one segment`);
|
|
768
|
-
|
|
768
|
+
V([t.slice(0, -1), t.slice(1)]).forEach(
|
|
769
769
|
([e, s]) => {
|
|
770
770
|
if (!P(e.lastPoint, s.firstPoint))
|
|
771
771
|
throw new Error(
|
|
772
772
|
`${n} segments must be connected, but ${e.info} and ${s.info} are not`
|
|
773
773
|
);
|
|
774
774
|
}
|
|
775
|
-
),
|
|
775
|
+
), Nn(t, n);
|
|
776
776
|
}
|
|
777
|
-
function
|
|
778
|
-
return !!(t
|
|
777
|
+
function bt(t, n) {
|
|
778
|
+
return !!(y.isInstance(t) && y.isInstance(n) && dn(t.V, n.V) || x.isInstance(t) && x.isInstance(n) && P(t.center, n.center) && t.radius - n.radius < t.precision);
|
|
779
779
|
}
|
|
780
|
-
function
|
|
781
|
-
if (t
|
|
782
|
-
return new
|
|
783
|
-
if (t
|
|
784
|
-
return new
|
|
780
|
+
function Ct(t, n) {
|
|
781
|
+
if (y.isInstance(t) && y.isInstance(n))
|
|
782
|
+
return new y(t.firstPoint, n.lastPoint);
|
|
783
|
+
if (x.isInstance(t) && x.isInstance(n))
|
|
784
|
+
return new x(
|
|
785
785
|
t.firstPoint,
|
|
786
786
|
n.lastPoint,
|
|
787
787
|
t.center,
|
|
@@ -789,7 +789,7 @@ function Mt(t, n) {
|
|
|
789
789
|
);
|
|
790
790
|
throw new Error("Not implemented");
|
|
791
791
|
}
|
|
792
|
-
function
|
|
792
|
+
function Gt(t) {
|
|
793
793
|
let n = !1;
|
|
794
794
|
const e = [];
|
|
795
795
|
for (const s of t.segments) {
|
|
@@ -798,22 +798,27 @@ function Ht(t) {
|
|
|
798
798
|
continue;
|
|
799
799
|
}
|
|
800
800
|
const i = e[e.length - 1];
|
|
801
|
-
|
|
801
|
+
bt(i, s) ? (n = !0, e.pop(), e.push(Ct(i, s))) : e.push(s);
|
|
802
802
|
}
|
|
803
|
-
if (P(t.firstPoint, t.lastPoint) &&
|
|
803
|
+
if (P(t.firstPoint, t.lastPoint) && bt(
|
|
804
804
|
e[0],
|
|
805
805
|
e[e.length - 1]
|
|
806
806
|
)) {
|
|
807
807
|
n = !0;
|
|
808
808
|
const s = e.pop();
|
|
809
|
-
e[0] =
|
|
809
|
+
e[0] = Ct(s, e[0]);
|
|
810
810
|
}
|
|
811
811
|
return n ? e : null;
|
|
812
812
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
813
|
+
const Mt = Symbol.for("pantograph:Strand");
|
|
814
|
+
class B extends Yt {
|
|
815
|
+
constructor(e, { ignoreChecks: s = !1 } = {}) {
|
|
816
|
+
super(e, { ignoreChecks: s });
|
|
817
|
+
b(this, "strokeType", "STRAND");
|
|
818
|
+
Object.defineProperty(this, Mt, { value: !0 });
|
|
819
|
+
}
|
|
820
|
+
static isInstance(e) {
|
|
821
|
+
return !!e && e[Mt] === !0;
|
|
817
822
|
}
|
|
818
823
|
reverse() {
|
|
819
824
|
const e = this.segments.map((s) => s.reverse());
|
|
@@ -831,7 +836,7 @@ class B extends Ut {
|
|
|
831
836
|
return new B([...this.segments, ...e.segments]);
|
|
832
837
|
}
|
|
833
838
|
simplify() {
|
|
834
|
-
const e =
|
|
839
|
+
const e = Gt(this);
|
|
835
840
|
return e ? new B(e, { ignoreChecks: !0 }) : this;
|
|
836
841
|
}
|
|
837
842
|
transform(e) {
|
|
@@ -841,8 +846,8 @@ class B extends Ut {
|
|
|
841
846
|
);
|
|
842
847
|
}
|
|
843
848
|
}
|
|
844
|
-
const
|
|
845
|
-
const e =
|
|
849
|
+
const Vn = (t, n) => {
|
|
850
|
+
const e = mn(n, {
|
|
846
851
|
V: [1, 0],
|
|
847
852
|
firstPoint: t,
|
|
848
853
|
precision: n.precision
|
|
@@ -852,15 +857,15 @@ const zn = (t, n) => {
|
|
|
852
857
|
const { intersectionParam1: s, intersectionParam2: i } = e;
|
|
853
858
|
if (!n.isValidParameter(s) || i <= -n.precision) return 0;
|
|
854
859
|
if (Math.abs(s) < n.precision || Math.abs(s - 1) < n.precision) {
|
|
855
|
-
const [,
|
|
856
|
-
return t[1] -
|
|
860
|
+
const [, r] = n.midPoint;
|
|
861
|
+
return t[1] - r < 0 ? 1 : 0;
|
|
857
862
|
}
|
|
858
863
|
return 1;
|
|
859
864
|
};
|
|
860
865
|
class at {
|
|
861
866
|
constructor(n) {
|
|
862
|
-
|
|
863
|
-
|
|
867
|
+
b(this, "_count", 0);
|
|
868
|
+
b(this, "segment");
|
|
864
869
|
this.segment = n;
|
|
865
870
|
}
|
|
866
871
|
update(n, e = !1) {
|
|
@@ -870,24 +875,24 @@ class at {
|
|
|
870
875
|
return this._count;
|
|
871
876
|
}
|
|
872
877
|
}
|
|
873
|
-
const
|
|
878
|
+
const jn = (t, n) => {
|
|
874
879
|
const e = n.precision, s = Math.abs(t[1] - n.center[1]);
|
|
875
880
|
if (s > n.radius + e) return 0;
|
|
876
|
-
const i =
|
|
877
|
-
if (Math.abs(i -
|
|
881
|
+
const i = gn(t, n.center), r = n.radius * n.radius, l = e * e;
|
|
882
|
+
if (Math.abs(i - r) < l && n.isOnSegment(t))
|
|
878
883
|
return 0;
|
|
879
|
-
const
|
|
880
|
-
if (
|
|
884
|
+
const o = i - r > l;
|
|
885
|
+
if (o && n.center[0] < t[0]) return 0;
|
|
881
886
|
const u = Math.sqrt(
|
|
882
887
|
n.radius * n.radius - s * s
|
|
883
888
|
), a = new at(n);
|
|
884
|
-
return a.update([n.center[0] + u, t[1]]),
|
|
885
|
-
},
|
|
886
|
-
const e = n.boundingBox.xMax + n.boundingBox.width / 2, s = new
|
|
887
|
-
return st(s, n).forEach((
|
|
888
|
-
i.update(
|
|
889
|
+
return a.update([n.center[0] + u, t[1]]), o && a.update([n.center[0] - u, t[1]]), a.count;
|
|
890
|
+
}, Un = (t, n) => {
|
|
891
|
+
const e = n.boundingBox.xMax + n.boundingBox.width / 2, s = new y(t, [e, t[1]]), i = new at(n);
|
|
892
|
+
return st(s, n).forEach((r) => {
|
|
893
|
+
i.update(r, !0);
|
|
889
894
|
}), i.count;
|
|
890
|
-
},
|
|
895
|
+
}, Hn = (t, n) => {
|
|
891
896
|
const e = new at(n);
|
|
892
897
|
return n.paramsAtY(t[1]).map((s) => {
|
|
893
898
|
try {
|
|
@@ -902,30 +907,34 @@ const Dn = (t, n) => {
|
|
|
902
907
|
e.update(s, !0);
|
|
903
908
|
}), e.count;
|
|
904
909
|
};
|
|
905
|
-
function
|
|
906
|
-
if (n
|
|
907
|
-
return zn(t, n);
|
|
908
|
-
if (n instanceof S)
|
|
909
|
-
return Dn(t, n);
|
|
910
|
-
if (n instanceof M)
|
|
911
|
-
return Rn(t, n);
|
|
912
|
-
if (n instanceof A || n instanceof I)
|
|
910
|
+
function $n(t, n) {
|
|
911
|
+
if (y.isInstance(n))
|
|
913
912
|
return Vn(t, n);
|
|
913
|
+
if (x.isInstance(n))
|
|
914
|
+
return jn(t, n);
|
|
915
|
+
if (C.isInstance(n))
|
|
916
|
+
return Un(t, n);
|
|
917
|
+
if (A.isInstance(n) || M.isInstance(n))
|
|
918
|
+
return Hn(t, n);
|
|
914
919
|
throw new Error("Not implemented");
|
|
915
920
|
}
|
|
916
|
-
|
|
921
|
+
const At = Symbol.for("pantograph:Loop");
|
|
922
|
+
class _ extends Yt {
|
|
917
923
|
constructor(e, { ignoreChecks: s = !1 } = {}) {
|
|
918
924
|
super(e, { ignoreChecks: !0 });
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
s ||
|
|
925
|
+
b(this, "strokeType", "LOOP");
|
|
926
|
+
b(this, "_clockwise", null);
|
|
927
|
+
Object.defineProperty(this, At, { value: !0 }), s || Yn(e);
|
|
928
|
+
}
|
|
929
|
+
static isInstance(e) {
|
|
930
|
+
return !!e && e[At] === !0;
|
|
922
931
|
}
|
|
923
932
|
get clockwise() {
|
|
924
933
|
if (this._clockwise === null) {
|
|
925
|
-
const e = this.segments.flatMap((i) => i
|
|
926
|
-
const l = e[(
|
|
934
|
+
const e = this.segments.flatMap((i) => y.isInstance(i) ? [i.firstPoint] : [i.firstPoint, i.paramPoint(0.5)]), s = e.map((i, r) => {
|
|
935
|
+
const l = e[(r + 1) % e.length];
|
|
927
936
|
return (l[0] - i[0]) * (l[1] + i[1]);
|
|
928
|
-
}).reduce((i,
|
|
937
|
+
}).reduce((i, r) => i + r, 0);
|
|
929
938
|
this._clockwise = s > 0;
|
|
930
939
|
}
|
|
931
940
|
return this._clockwise;
|
|
@@ -947,35 +956,35 @@ class _ extends Ut {
|
|
|
947
956
|
);
|
|
948
957
|
}
|
|
949
958
|
contains(e, { strokeIsInside: s = !1 } = {}) {
|
|
950
|
-
return this.onStroke(e) ? s : this.boundingBox.contains(e) ? this.segments.reduce((
|
|
959
|
+
return this.onStroke(e) ? s : this.boundingBox.contains(e) ? this.segments.reduce((r, l) => r + $n(e, l), 0) % 2 === 1 : !1;
|
|
951
960
|
}
|
|
952
961
|
simplify() {
|
|
953
|
-
const e =
|
|
962
|
+
const e = Gt(this);
|
|
954
963
|
return e ? new _(e, { ignoreChecks: !0 }) : this;
|
|
955
964
|
}
|
|
956
965
|
}
|
|
957
|
-
function
|
|
958
|
-
if (
|
|
966
|
+
function Yn(t) {
|
|
967
|
+
if (Xt(t, "Loop"), !P(t[0].firstPoint, t[t.length - 1].lastPoint))
|
|
959
968
|
throw new Error("Loop segment must be closed");
|
|
960
969
|
}
|
|
961
|
-
const
|
|
962
|
-
|
|
963
|
-
|
|
970
|
+
const Xn = [
|
|
971
|
+
y,
|
|
972
|
+
x,
|
|
973
|
+
C,
|
|
964
974
|
M,
|
|
965
|
-
I,
|
|
966
975
|
A
|
|
967
976
|
];
|
|
968
|
-
function
|
|
969
|
-
return
|
|
977
|
+
function Gn(t) {
|
|
978
|
+
return Xn.some((n) => n.isInstance(t));
|
|
970
979
|
}
|
|
971
|
-
function
|
|
972
|
-
if (t
|
|
980
|
+
function Qt(t) {
|
|
981
|
+
if (y.isInstance(t))
|
|
973
982
|
return {
|
|
974
983
|
type: t.segmentType,
|
|
975
984
|
firstPoint: t.firstPoint,
|
|
976
985
|
lastPoint: t.lastPoint
|
|
977
986
|
};
|
|
978
|
-
if (t
|
|
987
|
+
if (x.isInstance(t))
|
|
979
988
|
return {
|
|
980
989
|
type: t.segmentType,
|
|
981
990
|
firstPoint: t.firstPoint,
|
|
@@ -983,7 +992,7 @@ function $t(t) {
|
|
|
983
992
|
center: t.center,
|
|
984
993
|
clockwise: t.clockwise
|
|
985
994
|
};
|
|
986
|
-
if (t
|
|
995
|
+
if (C.isInstance(t))
|
|
987
996
|
return {
|
|
988
997
|
type: t.segmentType,
|
|
989
998
|
firstPoint: t.firstPoint,
|
|
@@ -994,14 +1003,14 @@ function $t(t) {
|
|
|
994
1003
|
minorRadius: t.minorRadius,
|
|
995
1004
|
tiltAngle: t.tiltAngle
|
|
996
1005
|
};
|
|
997
|
-
if (t
|
|
1006
|
+
if (M.isInstance(t))
|
|
998
1007
|
return {
|
|
999
1008
|
type: t.segmentType,
|
|
1000
1009
|
firstPoint: t.firstPoint,
|
|
1001
1010
|
lastPoint: t.lastPoint,
|
|
1002
1011
|
controlPoint: t.controlPoint
|
|
1003
1012
|
};
|
|
1004
|
-
if (t
|
|
1013
|
+
if (A.isInstance(t))
|
|
1005
1014
|
return {
|
|
1006
1015
|
type: t.segmentType,
|
|
1007
1016
|
firstPoint: t.firstPoint,
|
|
@@ -1011,37 +1020,37 @@ function $t(t) {
|
|
|
1011
1020
|
};
|
|
1012
1021
|
throw new Error("Unknown segment type");
|
|
1013
1022
|
}
|
|
1014
|
-
function
|
|
1023
|
+
function rt(t) {
|
|
1015
1024
|
return {
|
|
1016
1025
|
type: "LOOP",
|
|
1017
|
-
segments: t.segments.map(
|
|
1026
|
+
segments: t.segments.map(Qt)
|
|
1018
1027
|
};
|
|
1019
1028
|
}
|
|
1020
|
-
function
|
|
1029
|
+
function Wt(t) {
|
|
1021
1030
|
return {
|
|
1022
1031
|
type: "FIGURE",
|
|
1023
|
-
contour:
|
|
1024
|
-
holes: t.holes.map(
|
|
1032
|
+
contour: rt(t.contour),
|
|
1033
|
+
holes: t.holes.map(rt)
|
|
1025
1034
|
};
|
|
1026
1035
|
}
|
|
1027
|
-
function
|
|
1036
|
+
function Qn(t) {
|
|
1028
1037
|
return {
|
|
1029
1038
|
type: "DIAGRAM",
|
|
1030
|
-
figures: t.figures.map(
|
|
1039
|
+
figures: t.figures.map(Wt)
|
|
1031
1040
|
};
|
|
1032
1041
|
}
|
|
1033
|
-
function
|
|
1034
|
-
if (t
|
|
1035
|
-
return
|
|
1036
|
-
if (t
|
|
1037
|
-
return
|
|
1038
|
-
if (t
|
|
1039
|
-
return
|
|
1040
|
-
if (
|
|
1041
|
-
return
|
|
1042
|
+
function Et(t) {
|
|
1043
|
+
if (O.isInstance(t))
|
|
1044
|
+
return Qn(t);
|
|
1045
|
+
if (v.isInstance(t))
|
|
1046
|
+
return Wt(t);
|
|
1047
|
+
if (_.isInstance(t))
|
|
1048
|
+
return rt(t);
|
|
1049
|
+
if (Gn(t))
|
|
1050
|
+
return Qt(t);
|
|
1042
1051
|
throw new Error("Unknown shape type");
|
|
1043
1052
|
}
|
|
1044
|
-
class
|
|
1053
|
+
class Wn {
|
|
1045
1054
|
constructor() {
|
|
1046
1055
|
this.ids = [], this.values = [], this.length = 0;
|
|
1047
1056
|
}
|
|
@@ -1051,9 +1060,9 @@ class Yn {
|
|
|
1051
1060
|
push(n, e) {
|
|
1052
1061
|
let s = this.length++;
|
|
1053
1062
|
for (; s > 0; ) {
|
|
1054
|
-
const i = s - 1 >> 1,
|
|
1055
|
-
if (e >=
|
|
1056
|
-
this.ids[s] = this.ids[i], this.values[s] =
|
|
1063
|
+
const i = s - 1 >> 1, r = this.values[i];
|
|
1064
|
+
if (e >= r) break;
|
|
1065
|
+
this.ids[s] = this.ids[i], this.values[s] = r, s = i;
|
|
1057
1066
|
}
|
|
1058
1067
|
this.ids[s] = n, this.values[s] = e;
|
|
1059
1068
|
}
|
|
@@ -1062,16 +1071,16 @@ class Yn {
|
|
|
1062
1071
|
const n = this.ids[0];
|
|
1063
1072
|
if (this.length--, this.length > 0) {
|
|
1064
1073
|
const e = this.ids[0] = this.ids[this.length], s = this.values[0] = this.values[this.length], i = this.length >> 1;
|
|
1065
|
-
let
|
|
1066
|
-
for (;
|
|
1067
|
-
let l = (
|
|
1068
|
-
const
|
|
1074
|
+
let r = 0;
|
|
1075
|
+
for (; r < i; ) {
|
|
1076
|
+
let l = (r << 1) + 1;
|
|
1077
|
+
const o = l + 1;
|
|
1069
1078
|
let u = this.ids[l], a = this.values[l];
|
|
1070
|
-
const f = this.values[
|
|
1071
|
-
if (
|
|
1072
|
-
this.ids[
|
|
1079
|
+
const f = this.values[o];
|
|
1080
|
+
if (o < this.length && f < a && (l = o, u = this.ids[o], a = f), a >= s) break;
|
|
1081
|
+
this.ids[r] = u, this.values[r] = a, r = l;
|
|
1073
1082
|
}
|
|
1074
|
-
this.ids[
|
|
1083
|
+
this.ids[r] = e, this.values[r] = s;
|
|
1075
1084
|
}
|
|
1076
1085
|
return n;
|
|
1077
1086
|
}
|
|
@@ -1087,7 +1096,7 @@ class Yn {
|
|
|
1087
1096
|
this.ids.length = this.values.length = this.length;
|
|
1088
1097
|
}
|
|
1089
1098
|
}
|
|
1090
|
-
const
|
|
1099
|
+
const Ft = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array], et = 3;
|
|
1091
1100
|
class ft {
|
|
1092
1101
|
/**
|
|
1093
1102
|
* Recreate a Flatbush index from raw `ArrayBuffer` or `SharedArrayBuffer` data.
|
|
@@ -1103,14 +1112,14 @@ class ft {
|
|
|
1103
1112
|
const [s, i] = new Uint8Array(n, e + 0, 2);
|
|
1104
1113
|
if (s !== 251)
|
|
1105
1114
|
throw new Error("Data does not appear to be in a Flatbush format.");
|
|
1106
|
-
const
|
|
1107
|
-
if (
|
|
1108
|
-
throw new Error(`Got v${
|
|
1109
|
-
const l =
|
|
1115
|
+
const r = i >> 4;
|
|
1116
|
+
if (r !== et)
|
|
1117
|
+
throw new Error(`Got v${r} data when expected v${et}.`);
|
|
1118
|
+
const l = Ft[i & 15];
|
|
1110
1119
|
if (!l)
|
|
1111
1120
|
throw new Error("Unrecognized array type.");
|
|
1112
|
-
const [
|
|
1113
|
-
return new ft(u,
|
|
1121
|
+
const [o] = new Uint16Array(n, e + 2, 1), [u] = new Uint32Array(n, e + 4, 1);
|
|
1122
|
+
return new ft(u, o, l, void 0, n, e);
|
|
1114
1123
|
}
|
|
1115
1124
|
/**
|
|
1116
1125
|
* Create a Flatbush index that will hold a given number of items.
|
|
@@ -1121,20 +1130,20 @@ class ft {
|
|
|
1121
1130
|
* @param {ArrayBuffer | SharedArrayBuffer} [data] (Only used internally)
|
|
1122
1131
|
* @param {number} [byteOffset=0] (Only used internally)
|
|
1123
1132
|
*/
|
|
1124
|
-
constructor(n, e = 16, s = Float64Array, i = ArrayBuffer,
|
|
1133
|
+
constructor(n, e = 16, s = Float64Array, i = ArrayBuffer, r, l = 0) {
|
|
1125
1134
|
if (n === void 0) throw new Error("Missing required argument: numItems.");
|
|
1126
1135
|
if (isNaN(n) || n <= 0) throw new Error(`Unexpected numItems value: ${n}.`);
|
|
1127
1136
|
this.numItems = +n, this.nodeSize = Math.min(Math.max(+e, 2), 65535), this.byteOffset = l;
|
|
1128
|
-
let
|
|
1129
|
-
this._levelBounds = [
|
|
1137
|
+
let o = n, u = o;
|
|
1138
|
+
this._levelBounds = [o * 4];
|
|
1130
1139
|
do
|
|
1131
|
-
|
|
1132
|
-
while (
|
|
1140
|
+
o = Math.ceil(o / this.nodeSize), u += o, this._levelBounds.push(u * 4);
|
|
1141
|
+
while (o !== 1);
|
|
1133
1142
|
this.ArrayType = s, this.IndexArrayType = u < 16384 ? Uint16Array : Uint32Array;
|
|
1134
|
-
const a =
|
|
1143
|
+
const a = Ft.indexOf(this.ArrayType), f = u * 4 * this.ArrayType.BYTES_PER_ELEMENT;
|
|
1135
1144
|
if (a < 0)
|
|
1136
1145
|
throw new Error(`Unexpected typed array class: ${s}.`);
|
|
1137
|
-
|
|
1146
|
+
r && r.byteLength !== void 0 && !r.buffer ? (this.data = r, this._boxes = new this.ArrayType(this.data, l + 8, u * 4), this._indices = new this.IndexArrayType(this.data, l + 8 + f, u), this._pos = u * 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 + f + u * this.IndexArrayType.BYTES_PER_ELEMENT), this._boxes = new this.ArrayType(this.data, 8, u * 4), this._indices = new this.IndexArrayType(this.data, 8 + f, u), 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) + a]), new Uint16Array(this.data, 2, 1)[0] = e, new Uint32Array(this.data, 4, 1)[0] = n), this._queue = new Wn();
|
|
1138
1147
|
}
|
|
1139
1148
|
/**
|
|
1140
1149
|
* Add a given rectangle to the index.
|
|
@@ -1145,8 +1154,8 @@ class ft {
|
|
|
1145
1154
|
* @returns {number} A zero-based, incremental number that represents the newly added rectangle.
|
|
1146
1155
|
*/
|
|
1147
1156
|
add(n, e, s = n, i = e) {
|
|
1148
|
-
const
|
|
1149
|
-
return this._indices[
|
|
1157
|
+
const r = this._pos >> 2, l = this._boxes;
|
|
1158
|
+
return this._indices[r] = r, l[this._pos++] = n, l[this._pos++] = e, l[this._pos++] = s, l[this._pos++] = i, n < this.minX && (this.minX = n), e < this.minY && (this.minY = e), s > this.maxX && (this.maxX = s), i > this.maxY && (this.maxY = i), r;
|
|
1150
1159
|
}
|
|
1151
1160
|
/** Perform indexing of the added rectangles. */
|
|
1152
1161
|
finish() {
|
|
@@ -1157,19 +1166,19 @@ class ft {
|
|
|
1157
1166
|
n[this._pos++] = this.minX, n[this._pos++] = this.minY, n[this._pos++] = this.maxX, n[this._pos++] = this.maxY;
|
|
1158
1167
|
return;
|
|
1159
1168
|
}
|
|
1160
|
-
const e = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, i = new Uint32Array(this.numItems),
|
|
1161
|
-
for (let l = 0,
|
|
1162
|
-
const u = n[
|
|
1163
|
-
i[l] =
|
|
1169
|
+
const e = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, i = new Uint32Array(this.numItems), r = 65535;
|
|
1170
|
+
for (let l = 0, o = 0; l < this.numItems; l++) {
|
|
1171
|
+
const u = n[o++], a = n[o++], f = n[o++], c = n[o++], h = Math.floor(r * ((u + f) / 2 - this.minX) / e), p = Math.floor(r * ((a + c) / 2 - this.minY) / s);
|
|
1172
|
+
i[l] = Kn(h, p);
|
|
1164
1173
|
}
|
|
1165
|
-
|
|
1166
|
-
for (let l = 0,
|
|
1174
|
+
ot(i, n, this._indices, 0, this.numItems - 1, this.nodeSize);
|
|
1175
|
+
for (let l = 0, o = 0; l < this._levelBounds.length - 1; l++) {
|
|
1167
1176
|
const u = this._levelBounds[l];
|
|
1168
|
-
for (;
|
|
1169
|
-
const a =
|
|
1170
|
-
let f = n[
|
|
1171
|
-
for (let d = 1; d < this.nodeSize &&
|
|
1172
|
-
f = Math.min(f, n[
|
|
1177
|
+
for (; o < u; ) {
|
|
1178
|
+
const a = o;
|
|
1179
|
+
let f = n[o++], c = n[o++], h = n[o++], p = n[o++];
|
|
1180
|
+
for (let d = 1; d < this.nodeSize && o < u; d++)
|
|
1181
|
+
f = Math.min(f, n[o++]), c = Math.min(c, n[o++]), h = Math.max(h, n[o++]), p = Math.max(p, n[o++]);
|
|
1173
1182
|
this._indices[this._pos >> 2] = a, n[this._pos++] = f, n[this._pos++] = c, n[this._pos++] = h, n[this._pos++] = p;
|
|
1174
1183
|
}
|
|
1175
1184
|
}
|
|
@@ -1183,19 +1192,19 @@ class ft {
|
|
|
1183
1192
|
* @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.
|
|
1184
1193
|
* @returns {number[]} An array of indices of items intersecting or touching the given bounding box.
|
|
1185
1194
|
*/
|
|
1186
|
-
search(n, e, s, i,
|
|
1195
|
+
search(n, e, s, i, r) {
|
|
1187
1196
|
if (this._pos !== this._boxes.length)
|
|
1188
1197
|
throw new Error("Data not yet indexed - call index.finish().");
|
|
1189
1198
|
let l = this._boxes.length - 4;
|
|
1190
|
-
const
|
|
1199
|
+
const o = [], u = [];
|
|
1191
1200
|
for (; l !== void 0; ) {
|
|
1192
|
-
const a = Math.min(l + this.nodeSize * 4,
|
|
1201
|
+
const a = Math.min(l + this.nodeSize * 4, Bt(l, this._levelBounds));
|
|
1193
1202
|
for (let f = l; f < a; f += 4) {
|
|
1194
1203
|
if (s < this._boxes[f] || i < this._boxes[f + 1] || n > this._boxes[f + 2] || e > this._boxes[f + 3]) continue;
|
|
1195
1204
|
const c = this._indices[f >> 2] | 0;
|
|
1196
|
-
l >= this.numItems * 4 ?
|
|
1205
|
+
l >= this.numItems * 4 ? o.push(c) : (r === void 0 || r(c)) && u.push(c);
|
|
1197
1206
|
}
|
|
1198
|
-
l =
|
|
1207
|
+
l = o.pop();
|
|
1199
1208
|
}
|
|
1200
1209
|
return u;
|
|
1201
1210
|
}
|
|
@@ -1208,28 +1217,28 @@ class ft {
|
|
|
1208
1217
|
* @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.
|
|
1209
1218
|
* @returns {number[]} An array of indices of items found.
|
|
1210
1219
|
*/
|
|
1211
|
-
neighbors(n, e, s = 1 / 0, i = 1 / 0,
|
|
1220
|
+
neighbors(n, e, s = 1 / 0, i = 1 / 0, r) {
|
|
1212
1221
|
if (this._pos !== this._boxes.length)
|
|
1213
1222
|
throw new Error("Data not yet indexed - call index.finish().");
|
|
1214
1223
|
let l = this._boxes.length - 4;
|
|
1215
|
-
const
|
|
1224
|
+
const o = this._queue, u = [], a = i * i;
|
|
1216
1225
|
t: for (; l !== void 0; ) {
|
|
1217
|
-
const f = Math.min(l + this.nodeSize * 4,
|
|
1226
|
+
const f = Math.min(l + this.nodeSize * 4, Bt(l, this._levelBounds));
|
|
1218
1227
|
for (let c = l; c < f; c += 4) {
|
|
1219
|
-
const h = this._indices[c >> 2] | 0, p =
|
|
1220
|
-
m > a || (l >= this.numItems * 4 ?
|
|
1228
|
+
const h = this._indices[c >> 2] | 0, p = vt(n, this._boxes[c], this._boxes[c + 2]), d = vt(e, this._boxes[c + 1], this._boxes[c + 3]), m = p * p + d * d;
|
|
1229
|
+
m > a || (l >= this.numItems * 4 ? o.push(h << 1, m) : (r === void 0 || r(h)) && o.push((h << 1) + 1, m));
|
|
1221
1230
|
}
|
|
1222
|
-
for (;
|
|
1223
|
-
if (
|
|
1224
|
-
l =
|
|
1231
|
+
for (; o.length && o.peek() & 1; )
|
|
1232
|
+
if (o.peekValue() > a || (u.push(o.pop() >> 1), u.length === s)) break t;
|
|
1233
|
+
l = o.length ? o.pop() >> 1 : void 0;
|
|
1225
1234
|
}
|
|
1226
|
-
return
|
|
1235
|
+
return o.clear(), u;
|
|
1227
1236
|
}
|
|
1228
1237
|
}
|
|
1229
|
-
function
|
|
1238
|
+
function vt(t, n, e) {
|
|
1230
1239
|
return t < n ? n - t : t <= e ? 0 : t - e;
|
|
1231
1240
|
}
|
|
1232
|
-
function
|
|
1241
|
+
function Bt(t, n) {
|
|
1233
1242
|
let e = 0, s = n.length - 1;
|
|
1234
1243
|
for (; e < s; ) {
|
|
1235
1244
|
const i = e + s >> 1;
|
|
@@ -1237,79 +1246,83 @@ function Ft(t, n) {
|
|
|
1237
1246
|
}
|
|
1238
1247
|
return n[e];
|
|
1239
1248
|
}
|
|
1240
|
-
function
|
|
1241
|
-
if (Math.floor(s /
|
|
1249
|
+
function ot(t, n, e, s, i, r) {
|
|
1250
|
+
if (Math.floor(s / r) >= Math.floor(i / r)) return;
|
|
1242
1251
|
const l = t[s + i >> 1];
|
|
1243
|
-
let
|
|
1252
|
+
let o = s - 1, u = i + 1;
|
|
1244
1253
|
for (; ; ) {
|
|
1245
1254
|
do
|
|
1246
|
-
|
|
1247
|
-
while (t[
|
|
1255
|
+
o++;
|
|
1256
|
+
while (t[o] < l);
|
|
1248
1257
|
do
|
|
1249
1258
|
u--;
|
|
1250
1259
|
while (t[u] > l);
|
|
1251
|
-
if (
|
|
1252
|
-
|
|
1260
|
+
if (o >= u) break;
|
|
1261
|
+
Jn(t, n, e, o, u);
|
|
1253
1262
|
}
|
|
1254
|
-
|
|
1263
|
+
ot(t, n, e, s, u, r), ot(t, n, e, u + 1, i, r);
|
|
1255
1264
|
}
|
|
1256
|
-
function
|
|
1257
|
-
const
|
|
1258
|
-
t[s] = t[i], t[i] =
|
|
1259
|
-
const l = 4 * s,
|
|
1260
|
-
n[l] = n[
|
|
1265
|
+
function Jn(t, n, e, s, i) {
|
|
1266
|
+
const r = t[s];
|
|
1267
|
+
t[s] = t[i], t[i] = r;
|
|
1268
|
+
const l = 4 * s, o = 4 * i, u = n[l], a = n[l + 1], f = n[l + 2], c = n[l + 3];
|
|
1269
|
+
n[l] = n[o], n[l + 1] = n[o + 1], n[l + 2] = n[o + 2], n[l + 3] = n[o + 3], n[o] = u, n[o + 1] = a, n[o + 2] = f, n[o + 3] = c;
|
|
1261
1270
|
const h = e[s];
|
|
1262
1271
|
e[s] = e[i], e[i] = h;
|
|
1263
1272
|
}
|
|
1264
|
-
function
|
|
1265
|
-
let e = t ^ n, s = 65535 ^ e, i = 65535 ^ (t | n),
|
|
1266
|
-
e = l, s =
|
|
1273
|
+
function Kn(t, n) {
|
|
1274
|
+
let e = t ^ n, s = 65535 ^ e, i = 65535 ^ (t | n), r = t & (n ^ 65535), l = e | s >> 1, o = e >> 1 ^ e, u = i >> 1 ^ s & r >> 1 ^ i, a = e & i >> 1 ^ r >> 1 ^ r;
|
|
1275
|
+
e = l, s = o, i = u, r = a, l = e & e >> 2 ^ s & s >> 2, o = e & s >> 2 ^ s & (e ^ s) >> 2, u ^= e & i >> 2 ^ s & r >> 2, a ^= s & i >> 2 ^ (e ^ s) & r >> 2, e = l, s = o, i = u, r = a, l = e & e >> 4 ^ s & s >> 4, o = e & s >> 4 ^ s & (e ^ s) >> 4, u ^= e & i >> 4 ^ s & r >> 4, a ^= s & i >> 4 ^ (e ^ s) & r >> 4, e = l, s = o, i = u, r = a, u ^= e & i >> 8 ^ s & r >> 8, a ^= s & i >> 8 ^ (e ^ s) & r >> 8, e = u ^ u >> 1, s = a ^ a >> 1;
|
|
1267
1276
|
let f = t ^ n, c = s | 65535 ^ (f | e);
|
|
1268
1277
|
return f = (f | f << 8) & 16711935, f = (f | f << 4) & 252645135, f = (f | f << 2) & 858993459, f = (f | f << 1) & 1431655765, c = (c | c << 8) & 16711935, c = (c | c << 4) & 252645135, c = (c | c << 2) & 858993459, c = (c | c << 1) & 1431655765, (c << 1 | f) >>> 0;
|
|
1269
1278
|
}
|
|
1270
|
-
function
|
|
1279
|
+
function Jt(t, n = 1e-7) {
|
|
1271
1280
|
if (t.length === 0) return [];
|
|
1272
1281
|
if (t.length === 1) return [t];
|
|
1273
1282
|
const e = new ft(t.length);
|
|
1274
|
-
t.forEach((
|
|
1275
|
-
const [l,
|
|
1276
|
-
e.add(l - n,
|
|
1283
|
+
t.forEach((r) => {
|
|
1284
|
+
const [l, o] = r.firstPoint;
|
|
1285
|
+
e.add(l - n, o - n, l + n, o + n);
|
|
1277
1286
|
}), e.finish();
|
|
1278
1287
|
const s = [], i = /* @__PURE__ */ new Set();
|
|
1279
|
-
return t.forEach((
|
|
1288
|
+
return t.forEach((r, l) => {
|
|
1280
1289
|
if (i.has(l)) return;
|
|
1281
|
-
const
|
|
1290
|
+
const o = [r];
|
|
1282
1291
|
let u = l;
|
|
1283
1292
|
i.add(l);
|
|
1284
1293
|
let a = t.length;
|
|
1285
1294
|
for (; ; ) {
|
|
1286
1295
|
if (a-- < 0)
|
|
1287
1296
|
throw new Error("Infinite loop detected");
|
|
1288
|
-
const f =
|
|
1297
|
+
const f = o[o.length - 1].lastPoint, [c, h] = f, p = e.search(
|
|
1289
1298
|
c - n,
|
|
1290
1299
|
h - n,
|
|
1291
1300
|
c + n,
|
|
1292
1301
|
h + n
|
|
1293
|
-
), d = (
|
|
1294
|
-
t[
|
|
1295
|
-
|
|
1296
|
-
d(
|
|
1297
|
-
]).sort(([, ,
|
|
1302
|
+
), d = (I) => Math.abs((u - I) % t.length), m = p.filter((I) => !i.has(I)).map((I) => [
|
|
1303
|
+
t[I],
|
|
1304
|
+
I,
|
|
1305
|
+
d(I)
|
|
1306
|
+
]).sort(([, , I], [, , F]) => d(I) - d(F));
|
|
1298
1307
|
if (m.length === 0) {
|
|
1299
|
-
s.push(
|
|
1308
|
+
s.push(o);
|
|
1300
1309
|
break;
|
|
1301
1310
|
}
|
|
1302
|
-
const [
|
|
1303
|
-
|
|
1311
|
+
const [w, g] = m[0];
|
|
1312
|
+
o.push(w), i.add(g), u = g;
|
|
1304
1313
|
}
|
|
1305
1314
|
}), s;
|
|
1306
1315
|
}
|
|
1316
|
+
const kt = Symbol.for("pantograph:Figure");
|
|
1307
1317
|
class v extends ut {
|
|
1308
1318
|
constructor(e, s = [], { ignoreChecks: i = !1 } = {}) {
|
|
1309
1319
|
super();
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
i ||
|
|
1320
|
+
b(this, "contour");
|
|
1321
|
+
b(this, "holes");
|
|
1322
|
+
Object.defineProperty(this, kt, { value: !0 }), i || Zn(e, s), this.contour = e, this.holes = s;
|
|
1323
|
+
}
|
|
1324
|
+
static isInstance(e) {
|
|
1325
|
+
return !!e && e[kt] === !0;
|
|
1313
1326
|
}
|
|
1314
1327
|
get boundingBox() {
|
|
1315
1328
|
return this.contour.boundingBox;
|
|
@@ -1341,11 +1354,11 @@ class v extends ut {
|
|
|
1341
1354
|
);
|
|
1342
1355
|
}
|
|
1343
1356
|
overlappingStrands(e) {
|
|
1344
|
-
const s = e
|
|
1345
|
-
return
|
|
1357
|
+
const s = v.isInstance(e) ? e.allLoops : [e], i = this.allLoops.flatMap((r) => s.flatMap((l) => r.overlappingSegments(l)));
|
|
1358
|
+
return Jt(i).map((r) => new B(r));
|
|
1346
1359
|
}
|
|
1347
1360
|
}
|
|
1348
|
-
function
|
|
1361
|
+
function Zn(t, n = []) {
|
|
1349
1362
|
if (!t) throw new Error("Figure must have a contour");
|
|
1350
1363
|
for (const [e, s] of it([t, ...n]))
|
|
1351
1364
|
if (e.intersects(s))
|
|
@@ -1356,176 +1369,176 @@ function Qn(t, n = []) {
|
|
|
1356
1369
|
throw new Error("Holes must be inside the contour");
|
|
1357
1370
|
for (const [e, s] of it(n))
|
|
1358
1371
|
if (e.contains(s.firstPoint))
|
|
1359
|
-
throw console.error(
|
|
1372
|
+
throw console.error(Et(e), Et(s)), new Error("Holes must not be inside other holes");
|
|
1360
1373
|
}
|
|
1361
|
-
const J = (t, n, e = 1e-7) => Math.abs(t - n) <= e,
|
|
1374
|
+
const J = (t, n, e = 1e-7) => Math.abs(t - n) <= e, te = (t, n) => {
|
|
1362
1375
|
const e = t.boundingBox, s = n.boundingBox;
|
|
1363
1376
|
return J(e.xMin, s.xMin) && J(e.yMin, s.yMin) && J(e.xMax, s.xMax) && J(e.yMax, s.yMax);
|
|
1364
|
-
},
|
|
1365
|
-
if (t.segmentsCount !== n.segmentsCount || !
|
|
1366
|
-
const e = t.segments, s = n.segments, i = e.length,
|
|
1377
|
+
}, ne = (t, n) => {
|
|
1378
|
+
if (t.segmentsCount !== n.segmentsCount || !te(t, n)) return !1;
|
|
1379
|
+
const e = t.segments, s = n.segments, i = e.length, r = (l, o) => {
|
|
1367
1380
|
for (let u = 0; u < i; u += 1) {
|
|
1368
|
-
const a = (l +
|
|
1381
|
+
const a = (l + o * u + i) % i;
|
|
1369
1382
|
if (!e[u].isSame(s[a])) return !1;
|
|
1370
1383
|
}
|
|
1371
1384
|
return !0;
|
|
1372
1385
|
};
|
|
1373
1386
|
for (let l = 0; l < i; l += 1)
|
|
1374
|
-
if (e[0].isSame(s[l]) && (
|
|
1387
|
+
if (e[0].isSame(s[l]) && (r(l, 1) || r(l, -1)))
|
|
1375
1388
|
return !0;
|
|
1376
1389
|
return !1;
|
|
1377
|
-
},
|
|
1390
|
+
}, ee = (t) => {
|
|
1378
1391
|
const n = [];
|
|
1379
1392
|
return t.forEach((e) => {
|
|
1380
|
-
n.some((s) =>
|
|
1393
|
+
n.some((s) => ne(e, s)) || n.push(e);
|
|
1381
1394
|
}), n;
|
|
1382
|
-
},
|
|
1383
|
-
const n = t.map((i,
|
|
1384
|
-
return n.forEach((i,
|
|
1385
|
-
let l = s[
|
|
1386
|
-
l || (l = [], e.push(l)), l.push(t[
|
|
1387
|
-
s[
|
|
1395
|
+
}, se = (t) => {
|
|
1396
|
+
const n = t.map((i, r) => t.slice(r + 1).map((l, o) => [o + r + 1, l]).filter(([, l]) => i.boundingBox.overlaps(l.boundingBox)).map(([l]) => l)), e = [], s = Array(n.length);
|
|
1397
|
+
return n.forEach((i, r) => {
|
|
1398
|
+
let l = s[r];
|
|
1399
|
+
l || (l = [], e.push(l)), l.push(t[r]), i.length && i.forEach((o) => {
|
|
1400
|
+
s[o] = l;
|
|
1388
1401
|
});
|
|
1389
1402
|
}), e;
|
|
1390
|
-
},
|
|
1391
|
-
const i = n.segments[0].midPoint,
|
|
1403
|
+
}, Kt = (t) => t.map((n, e) => {
|
|
1404
|
+
const i = n.segments[0].midPoint, r = t.filter((l, o) => e === o ? !1 : l.contains(i));
|
|
1392
1405
|
return {
|
|
1393
1406
|
loop: n,
|
|
1394
|
-
isIn:
|
|
1407
|
+
isIn: r
|
|
1395
1408
|
};
|
|
1396
|
-
}),
|
|
1409
|
+
}), ie = (t, n) => t.flatMap(({ loop: e }) => ht(
|
|
1397
1410
|
n.filter(
|
|
1398
1411
|
({ loop: s, isIn: i }) => s === e || i.indexOf(e) !== -1
|
|
1399
1412
|
)
|
|
1400
|
-
)),
|
|
1413
|
+
)), re = (t, n) => {
|
|
1401
1414
|
const e = n.filter(({ isIn: i }) => i.length <= 1), s = ht(
|
|
1402
|
-
|
|
1415
|
+
Kt(t.map(({ loop: i }) => i))
|
|
1403
1416
|
);
|
|
1404
1417
|
return [e, ...s];
|
|
1405
1418
|
}, ht = (t) => {
|
|
1406
1419
|
if (!t.length) return [];
|
|
1407
1420
|
const n = t.filter(({ isIn: s }) => !s.length), e = t.filter(({ isIn: s }) => s.length > 1);
|
|
1408
|
-
return n.length === 1 && e.length === 0 ? [t] : n.length > 1 ?
|
|
1421
|
+
return n.length === 1 && e.length === 0 ? [t] : n.length > 1 ? ie(n, t) : re(e, t);
|
|
1409
1422
|
};
|
|
1410
1423
|
function X(t) {
|
|
1411
|
-
const n =
|
|
1412
|
-
return
|
|
1424
|
+
const n = ee(t);
|
|
1425
|
+
return se(n).map(Kt).flatMap(ht).map((s) => {
|
|
1413
1426
|
if (s.length === 1) return new v(s[0].loop);
|
|
1414
|
-
s.sort((l,
|
|
1415
|
-
const [i, ...
|
|
1416
|
-
return new v(i,
|
|
1427
|
+
s.sort((l, o) => l.isIn.length - o.isIn.length);
|
|
1428
|
+
const [i, ...r] = s.map(({ loop: l }) => l);
|
|
1429
|
+
return new v(i, r);
|
|
1417
1430
|
});
|
|
1418
1431
|
}
|
|
1419
|
-
function
|
|
1432
|
+
function oe(t, n) {
|
|
1420
1433
|
const e = [];
|
|
1421
1434
|
for (const s of t)
|
|
1422
1435
|
for (const i of n)
|
|
1423
1436
|
e.push([s, i]);
|
|
1424
1437
|
return e;
|
|
1425
1438
|
}
|
|
1426
|
-
function*
|
|
1427
|
-
const s = (
|
|
1439
|
+
function* Ot(t, n, e) {
|
|
1440
|
+
const s = (o) => n.some((u) => P(u, o.lastPoint)), i = (o, u) => o.segmentType !== u.segmentType || !u.isOnSegment(o.firstPoint) || !u.isOnSegment(o.lastPoint) ? !1 : o.segmentType !== "LINE" ? u.isOnSegment(o.midPoint) : !0, r = (o) => e.some((u) => o.isSame(u) || i(o, u));
|
|
1428
1441
|
let l = [];
|
|
1429
|
-
for (const
|
|
1430
|
-
s(
|
|
1442
|
+
for (const o of t)
|
|
1443
|
+
s(o) ? (l.push(o), yield new B(l, { ignoreChecks: !0 }), l = []) : r(o) ? (l.length && (yield new B(l, { ignoreChecks: !0 }), l = []), yield new B([o], { ignoreChecks: !0 })) : l.push(o);
|
|
1431
1444
|
l.length && (yield new B(l, { ignoreChecks: !0 }));
|
|
1432
1445
|
}
|
|
1433
|
-
const
|
|
1434
|
-
const e = t.findIndex((
|
|
1446
|
+
const _t = (t, n) => {
|
|
1447
|
+
const e = t.findIndex((r) => P(n, r.firstPoint)), s = t.slice(0, e);
|
|
1435
1448
|
return t.slice(e).concat(s);
|
|
1436
|
-
},
|
|
1449
|
+
}, Tt = (t, n) => {
|
|
1437
1450
|
let e = t;
|
|
1438
|
-
const s = (
|
|
1451
|
+
const s = (o) => P(o.firstPoint, n.firstPoint) && P(o.lastPoint, n.lastPoint);
|
|
1439
1452
|
let i = t.findIndex(s);
|
|
1440
1453
|
if (i === -1) {
|
|
1441
|
-
const
|
|
1442
|
-
if (
|
|
1454
|
+
const o = t.map((u) => u.reverse());
|
|
1455
|
+
if (o.reverse(), i = o.findIndex(s), i === -1)
|
|
1443
1456
|
throw console.error(
|
|
1444
|
-
|
|
1457
|
+
o.map((u) => u.repr),
|
|
1445
1458
|
n.repr
|
|
1446
1459
|
), new Error("Failed to rotate to segment start");
|
|
1447
|
-
e =
|
|
1460
|
+
e = o;
|
|
1448
1461
|
}
|
|
1449
|
-
const
|
|
1450
|
-
return e.slice(i).concat(
|
|
1462
|
+
const r = e.slice(0, i);
|
|
1463
|
+
return e.slice(i).concat(r);
|
|
1451
1464
|
};
|
|
1452
|
-
function
|
|
1465
|
+
function le(t, n, e) {
|
|
1453
1466
|
return t.filter((s) => {
|
|
1454
|
-
const i = n.filter((
|
|
1467
|
+
const i = n.filter((o) => P(o.firstPoint, s) || P(o.lastPoint, s));
|
|
1455
1468
|
if (i.length % 2)
|
|
1456
1469
|
throw new Error("Bug in the intersection algo on non crossing point");
|
|
1457
|
-
const
|
|
1458
|
-
return !(
|
|
1470
|
+
const r = i.map((o) => e.contains(o.midPoint));
|
|
1471
|
+
return !(r.every((o) => o) || !r.some((o) => o));
|
|
1459
1472
|
});
|
|
1460
1473
|
}
|
|
1461
|
-
function
|
|
1474
|
+
function ue(t, n, e, s = !1) {
|
|
1462
1475
|
let i = [];
|
|
1463
|
-
const
|
|
1476
|
+
const r = [], l = new Array(t.segments.length).fill(0).map(() => []), o = new Array(n.segments.length).fill(0).map(() => []);
|
|
1464
1477
|
if (t.segments.forEach((p, d) => {
|
|
1465
|
-
n.segments.forEach((m,
|
|
1466
|
-
const { intersections: g, overlaps:
|
|
1478
|
+
n.segments.forEach((m, w) => {
|
|
1479
|
+
const { intersections: g, overlaps: I } = Z(
|
|
1467
1480
|
p,
|
|
1468
1481
|
m,
|
|
1469
1482
|
e
|
|
1470
1483
|
);
|
|
1471
|
-
i.push(...g), l[d].push(...g),
|
|
1472
|
-
const F =
|
|
1473
|
-
|
|
1474
|
-
|
|
1484
|
+
i.push(...g), l[d].push(...g), o[w].push(...g), r.push(...I);
|
|
1485
|
+
const F = I.flatMap((S) => [
|
|
1486
|
+
S.firstPoint,
|
|
1487
|
+
S.lastPoint
|
|
1475
1488
|
]);
|
|
1476
|
-
i.push(...F), l[d].push(...F),
|
|
1489
|
+
i.push(...F), l[d].push(...F), o[w].push(...F);
|
|
1477
1490
|
});
|
|
1478
|
-
}), i =
|
|
1491
|
+
}), i = j(i, e), !i.length || i.length === 1) return null;
|
|
1479
1492
|
const u = ([p, d]) => d.length ? p.splitAt(d) : [p];
|
|
1480
|
-
let a =
|
|
1481
|
-
if (i =
|
|
1493
|
+
let a = V([t.segments, l]).flatMap(u), f = V([n.segments, o]).flatMap(u);
|
|
1494
|
+
if (i = le(
|
|
1482
1495
|
i,
|
|
1483
1496
|
a,
|
|
1484
1497
|
n
|
|
1485
|
-
), !i.length && !
|
|
1486
|
-
if (
|
|
1487
|
-
const p =
|
|
1488
|
-
a =
|
|
1498
|
+
), !i.length && !r.length) return null;
|
|
1499
|
+
if (r.length) {
|
|
1500
|
+
const p = r[0];
|
|
1501
|
+
a = Tt(
|
|
1489
1502
|
a,
|
|
1490
1503
|
p
|
|
1491
|
-
), f =
|
|
1504
|
+
), f = Tt(
|
|
1492
1505
|
f,
|
|
1493
1506
|
p
|
|
1494
1507
|
);
|
|
1495
1508
|
} else {
|
|
1496
1509
|
const p = i[0];
|
|
1497
|
-
a =
|
|
1510
|
+
a = _t(a, p), f = _t(f, p);
|
|
1498
1511
|
}
|
|
1499
1512
|
let c = Array.from(
|
|
1500
|
-
|
|
1513
|
+
Ot(
|
|
1501
1514
|
a,
|
|
1502
1515
|
i,
|
|
1503
|
-
|
|
1516
|
+
r
|
|
1504
1517
|
)
|
|
1505
1518
|
), h = Array.from(
|
|
1506
|
-
|
|
1519
|
+
Ot(
|
|
1507
1520
|
f,
|
|
1508
1521
|
i,
|
|
1509
|
-
|
|
1522
|
+
r
|
|
1510
1523
|
)
|
|
1511
1524
|
);
|
|
1512
1525
|
return (!P(
|
|
1513
1526
|
h[0].lastPoint,
|
|
1514
1527
|
c[0].lastPoint
|
|
1515
|
-
) ||
|
|
1528
|
+
) || r.length > 0 && h[0].segmentsCount !== 1) && (h = h.map((p) => p.reverse()).reverse(), P(h[0].lastPoint, c[0].lastPoint) || (c = c.map((p) => p.reverse()).reverse())), V([c, h]).map(([p, d]) => {
|
|
1516
1529
|
if (s) {
|
|
1517
|
-
if (((
|
|
1518
|
-
(g) =>
|
|
1519
|
-
(
|
|
1530
|
+
if (((w) => w.segments.every(
|
|
1531
|
+
(g) => r.some(
|
|
1532
|
+
(I) => g.isSame(I) || g.segmentType === I.segmentType && I.isOnSegment(g.firstPoint) && I.isOnSegment(g.lastPoint) && (g.segmentType === "LINE" || I.isOnSegment(g.midPoint))
|
|
1520
1533
|
)
|
|
1521
1534
|
))(p))
|
|
1522
1535
|
return [p, "same"];
|
|
1523
|
-
} else if (p.segmentsCount === 1 &&
|
|
1536
|
+
} else if (p.segmentsCount === 1 && r.some((m) => p.segments[0].isSame(m)))
|
|
1524
1537
|
return [p, "same"];
|
|
1525
1538
|
return [p, d];
|
|
1526
1539
|
});
|
|
1527
1540
|
}
|
|
1528
|
-
function
|
|
1541
|
+
function Lt(t) {
|
|
1529
1542
|
let n = t[0];
|
|
1530
1543
|
for (const e of t.slice(1))
|
|
1531
1544
|
n = n.extend(e);
|
|
@@ -1536,50 +1549,50 @@ function Ot(t) {
|
|
|
1536
1549
|
), new Error("Bug in the intersection algo on non closing strand");
|
|
1537
1550
|
return new _(n.segments);
|
|
1538
1551
|
}
|
|
1539
|
-
function
|
|
1540
|
-
const e =
|
|
1552
|
+
function ce(t, n) {
|
|
1553
|
+
const e = V([
|
|
1541
1554
|
n.slice(0, -1),
|
|
1542
1555
|
n.slice(1)
|
|
1543
|
-
]).map(([i,
|
|
1556
|
+
]).map(([i, r]) => Lt(t.slice(i, r)));
|
|
1544
1557
|
let s = t.slice(
|
|
1545
1558
|
n[n.length - 1]
|
|
1546
1559
|
);
|
|
1547
|
-
return n[0] !== 0 && (s = s.concat(t.slice(0, n[0]))), e.push(
|
|
1560
|
+
return n[0] !== 0 && (s = s.concat(t.slice(0, n[0]))), e.push(Lt(s)), e;
|
|
1548
1561
|
}
|
|
1549
|
-
function
|
|
1562
|
+
function ae(t) {
|
|
1550
1563
|
if (!t.length) return [];
|
|
1551
1564
|
const n = t.map((i) => i.firstPoint);
|
|
1552
1565
|
let e = t.map((i) => i.lastPoint);
|
|
1553
1566
|
e = e.slice(-1).concat(e.slice(0, -1));
|
|
1554
|
-
const s =
|
|
1555
|
-
([i,
|
|
1567
|
+
const s = V([n, e]).flatMap(
|
|
1568
|
+
([i, r], l) => P(i, r) ? [] : l
|
|
1556
1569
|
);
|
|
1557
1570
|
try {
|
|
1558
|
-
return
|
|
1571
|
+
return ce(t, s);
|
|
1559
1572
|
} catch {
|
|
1560
|
-
return
|
|
1573
|
+
return Jt(t.flatMap((r) => r.segments)).filter((r) => r.length > 1).filter((r) => P(r[0].firstPoint, r.at(-1).lastPoint)).map((r) => new _(r));
|
|
1561
1574
|
}
|
|
1562
1575
|
}
|
|
1563
|
-
const
|
|
1576
|
+
const qt = (t, n) => {
|
|
1564
1577
|
if (t.length === 0) return [n];
|
|
1565
1578
|
const e = t.at(-1);
|
|
1566
1579
|
return P(e.lastPoint, n.firstPoint) ? t.slice(0, -1).concat([e.extend(n)]) : P(e.lastPoint, n.lastPoint) ? t.slice(0, -1).concat([e.extend(n.reverse())]) : t.concat([n]);
|
|
1567
|
-
},
|
|
1580
|
+
}, fe = (t, n) => t.length === 0 ? [n] : P(t[0].firstPoint, n.lastPoint) ? [n.extend(t[0])].concat(t.slice(1)) : [n].concat(t);
|
|
1568
1581
|
function pt(t, n, {
|
|
1569
1582
|
firstInside: e,
|
|
1570
1583
|
secondInside: s,
|
|
1571
1584
|
firstBoundaryInside: i = !1,
|
|
1572
|
-
secondBoundaryInside:
|
|
1585
|
+
secondBoundaryInside: r = !1
|
|
1573
1586
|
}) {
|
|
1574
|
-
const l =
|
|
1587
|
+
const l = ue(
|
|
1575
1588
|
t,
|
|
1576
1589
|
n,
|
|
1577
1590
|
void 0,
|
|
1578
|
-
i ||
|
|
1591
|
+
i || r
|
|
1579
1592
|
);
|
|
1580
1593
|
if (!l) {
|
|
1581
1594
|
const f = t.segments[0].midPoint, c = n.contains(f, {
|
|
1582
|
-
strokeIsInside:
|
|
1595
|
+
strokeIsInside: r
|
|
1583
1596
|
}), h = n.segments[0].midPoint, p = t.contains(h, {
|
|
1584
1597
|
strokeIsInside: i
|
|
1585
1598
|
});
|
|
@@ -1591,27 +1604,27 @@ function pt(t, n, {
|
|
|
1591
1604
|
}
|
|
1592
1605
|
if (l.every(([, f]) => f === "same"))
|
|
1593
1606
|
return { identical: !0 };
|
|
1594
|
-
let
|
|
1607
|
+
let o = null, u = null;
|
|
1595
1608
|
const a = l.flatMap(([f, c]) => {
|
|
1596
1609
|
let h = [], p = 0;
|
|
1597
1610
|
if (c === "same")
|
|
1598
|
-
return u === 1 ? (u = 1, f) : u === 2 || u === 0 ? (u = null, []) : u === null ? (
|
|
1611
|
+
return u === 1 ? (u = 1, f) : u === 2 || u === 0 ? (u = null, []) : u === null ? (o ? o = o.extend(f) : o = f, []) : (console.error("weird situation"), []);
|
|
1599
1612
|
const d = f.segments[0].midPoint, m = n.contains(d, {
|
|
1600
|
-
strokeIsInside:
|
|
1613
|
+
strokeIsInside: r
|
|
1601
1614
|
});
|
|
1602
|
-
(e === "keep" && m || e === "remove" && !m) && (p += 1, h =
|
|
1603
|
-
const
|
|
1615
|
+
(e === "keep" && m || e === "remove" && !m) && (p += 1, h = qt(h, f));
|
|
1616
|
+
const w = c.segments[0].midPoint, g = t.contains(w, {
|
|
1604
1617
|
strokeIsInside: i
|
|
1605
1618
|
});
|
|
1606
1619
|
if (s === "keep" && g || s === "remove" && !g) {
|
|
1607
|
-
const
|
|
1608
|
-
p += 1, p === 2 && h.length ? (h =
|
|
1620
|
+
const I = c;
|
|
1621
|
+
p += 1, p === 2 && h.length ? (h = qt(h, I), o = null) : h = [I];
|
|
1609
1622
|
}
|
|
1610
|
-
return u === null && p === 1 &&
|
|
1623
|
+
return u === null && p === 1 && o && (h = fe(h, o)), p === 1 && (u = p, o = null), h.length ? h : (o = null, []);
|
|
1611
1624
|
});
|
|
1612
|
-
return
|
|
1625
|
+
return ae(a);
|
|
1613
1626
|
}
|
|
1614
|
-
const
|
|
1627
|
+
const he = (t, n, e) => {
|
|
1615
1628
|
const s = pt(t, n, {
|
|
1616
1629
|
firstInside: "remove",
|
|
1617
1630
|
secondInside: "remove",
|
|
@@ -1626,47 +1639,47 @@ const ue = (t, n, e) => {
|
|
|
1626
1639
|
});
|
|
1627
1640
|
return Array.isArray(s) ? s : s.identical ? [] : s.firstCurveInSecond ? [] : s.secondCurveInFirst ? [t, n] : [t];
|
|
1628
1641
|
}, dt = (t, n, e) => {
|
|
1629
|
-
const s = (e == null ? void 0 : e.firstBoundaryInside) ?? !1, i = (e == null ? void 0 : e.secondBoundaryInside) ?? !1,
|
|
1642
|
+
const s = (e == null ? void 0 : e.firstBoundaryInside) ?? !1, i = (e == null ? void 0 : e.secondBoundaryInside) ?? !1, r = s || i, l = (u, a, f) => u.segments.every(
|
|
1630
1643
|
(c) => a.contains(c.midPoint, { strokeIsInside: f })
|
|
1631
1644
|
);
|
|
1632
|
-
if (
|
|
1645
|
+
if (r) {
|
|
1633
1646
|
if (l(t, n, i))
|
|
1634
1647
|
return [t];
|
|
1635
1648
|
if (l(n, t, s))
|
|
1636
1649
|
return [n];
|
|
1637
1650
|
}
|
|
1638
|
-
const
|
|
1651
|
+
const o = pt(t, n, {
|
|
1639
1652
|
firstInside: "keep",
|
|
1640
1653
|
secondInside: "keep",
|
|
1641
1654
|
...e
|
|
1642
1655
|
});
|
|
1643
|
-
return Array.isArray(
|
|
1656
|
+
return Array.isArray(o) ? o : o.identical ? [t] : o.firstCurveInSecond ? [t] : o.secondCurveInFirst ? [n] : [];
|
|
1644
1657
|
};
|
|
1645
|
-
function
|
|
1658
|
+
function pe(t) {
|
|
1646
1659
|
const n = /* @__PURE__ */ new Map(), e = [];
|
|
1647
1660
|
return t.forEach((s, i) => {
|
|
1648
|
-
let
|
|
1649
|
-
n.has(i) ?
|
|
1650
|
-
const u =
|
|
1651
|
-
if (
|
|
1661
|
+
let r;
|
|
1662
|
+
n.has(i) ? r = n.get(i) : (r = { current: [s], fusedWith: /* @__PURE__ */ new Set([i]) }, e.push(r)), t.slice(i + 1).forEach((l, o) => {
|
|
1663
|
+
const u = r.current, a = i + o + 1;
|
|
1664
|
+
if (r.fusedWith.has(a)) return;
|
|
1652
1665
|
let f = [l], c = !1;
|
|
1653
1666
|
if (n.has(a) && (f = n.get(a).current, c = !0), !u.some(
|
|
1654
1667
|
(d) => f.some((m) => d.intersects(m))
|
|
1655
1668
|
)) return;
|
|
1656
1669
|
let p;
|
|
1657
|
-
u.length > 1 || f.length > 1 ? p = G(u, f) : p =
|
|
1670
|
+
u.length > 1 || f.length > 1 ? p = G(u, f) : p = Zt(u[0], f[0]), r.fusedWith.add(a), r.current = p, c || n.set(a, r);
|
|
1658
1671
|
});
|
|
1659
1672
|
}), e.flatMap(({ current: s }) => s);
|
|
1660
1673
|
}
|
|
1661
|
-
function
|
|
1662
|
-
const e =
|
|
1663
|
-
([l,
|
|
1674
|
+
function Zt(t, n) {
|
|
1675
|
+
const e = he(t.contour, n.contour), s = n.holes.flatMap((l) => tt(l, t.contour)), i = t.holes.flatMap((l) => tt(l, n.contour)), r = oe(t.holes, n.holes).flatMap(
|
|
1676
|
+
([l, o]) => dt(l, o)
|
|
1664
1677
|
);
|
|
1665
1678
|
return X([
|
|
1666
1679
|
...e,
|
|
1667
1680
|
...s,
|
|
1668
1681
|
...i,
|
|
1669
|
-
...
|
|
1682
|
+
...r
|
|
1670
1683
|
]);
|
|
1671
1684
|
}
|
|
1672
1685
|
function nt(t, n) {
|
|
@@ -1674,7 +1687,7 @@ function nt(t, n) {
|
|
|
1674
1687
|
return X(tt(t.contour, n.contour));
|
|
1675
1688
|
if (t.isFull) {
|
|
1676
1689
|
const s = tt(t.contour, n.contour), i = n.holes.flatMap(
|
|
1677
|
-
(
|
|
1690
|
+
(r) => dt(r, t.contour, { firstBoundaryInside: !0 })
|
|
1678
1691
|
);
|
|
1679
1692
|
return X([...s, ...i]);
|
|
1680
1693
|
} else if (n.isFull && !t.contour.intersects(n.contour))
|
|
@@ -1694,7 +1707,7 @@ function nt(t, n) {
|
|
|
1694
1707
|
e = e.flatMap((i) => nt(i, new v(s)));
|
|
1695
1708
|
}), e;
|
|
1696
1709
|
}
|
|
1697
|
-
function
|
|
1710
|
+
function de(t, n) {
|
|
1698
1711
|
const e = dt(t.contour, n.contour);
|
|
1699
1712
|
if (!e.length) return [];
|
|
1700
1713
|
let s = X(e);
|
|
@@ -1710,14 +1723,14 @@ function G(t, n) {
|
|
|
1710
1723
|
if (!t.length) return n;
|
|
1711
1724
|
if (!n.length) return t;
|
|
1712
1725
|
if (t.length === 1 && n.length > 1 || n.length === 1 && t.length > 1)
|
|
1713
|
-
return
|
|
1726
|
+
return pe([...t, ...n]);
|
|
1714
1727
|
if (t.length > 1 && n.length > 1) {
|
|
1715
1728
|
let e = G([t[0]], n);
|
|
1716
1729
|
return t.slice(1).forEach((s) => {
|
|
1717
1730
|
e = G([s], e);
|
|
1718
1731
|
}), e;
|
|
1719
1732
|
}
|
|
1720
|
-
return t.length === 1 && n.length === 1 ?
|
|
1733
|
+
return t.length === 1 && n.length === 1 ? Zt(t[0], n[0]) : [];
|
|
1721
1734
|
}
|
|
1722
1735
|
function Q(t, n) {
|
|
1723
1736
|
if (!t.length) return [];
|
|
@@ -1732,20 +1745,24 @@ function Q(t, n) {
|
|
|
1732
1745
|
}), e;
|
|
1733
1746
|
}
|
|
1734
1747
|
function lt(t, n) {
|
|
1735
|
-
return !t.length || !n.length ? [] : t.length === 1 && n.length === 1 ?
|
|
1748
|
+
return !t.length || !n.length ? [] : t.length === 1 && n.length === 1 ? de(t[0], n[0]) : t.length > 1 ? t.flatMap((e) => lt([e], n)) : n.flatMap((e) => lt(t, [e]));
|
|
1736
1749
|
}
|
|
1750
|
+
const zt = Symbol.for("pantograph:Diagram");
|
|
1737
1751
|
class O extends ut {
|
|
1738
1752
|
constructor(e = [], { ignoreChecks: s = !1 } = {}) {
|
|
1739
1753
|
super();
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
s ||
|
|
1754
|
+
b(this, "figures");
|
|
1755
|
+
b(this, "_boundingBox", null);
|
|
1756
|
+
Object.defineProperty(this, zt, { value: !0 }), s || me(e), this.figures = e;
|
|
1757
|
+
}
|
|
1758
|
+
static isInstance(e) {
|
|
1759
|
+
return !!e && e[zt] === !0;
|
|
1743
1760
|
}
|
|
1744
1761
|
get isEmpty() {
|
|
1745
1762
|
return this.figures.length === 0;
|
|
1746
1763
|
}
|
|
1747
1764
|
get boundingBox() {
|
|
1748
|
-
if (this.isEmpty) return new
|
|
1765
|
+
if (this.isEmpty) return new Pn();
|
|
1749
1766
|
if (this._boundingBox === null) {
|
|
1750
1767
|
let e = this.figures[0].boundingBox;
|
|
1751
1768
|
for (const s of this.figures.slice(1))
|
|
@@ -1771,7 +1788,7 @@ class O extends ut {
|
|
|
1771
1788
|
);
|
|
1772
1789
|
}
|
|
1773
1790
|
overlappingStrands(e) {
|
|
1774
|
-
return this.figures.flatMap((s) => e
|
|
1791
|
+
return this.figures.flatMap((s) => O.isInstance(e) ? e.figures.flatMap(
|
|
1775
1792
|
(i) => s.overlappingStrands(i)
|
|
1776
1793
|
) : s.overlappingStrands(e));
|
|
1777
1794
|
}
|
|
@@ -1785,7 +1802,7 @@ class O extends ut {
|
|
|
1785
1802
|
return new O(lt(this.figures, e.figures));
|
|
1786
1803
|
}
|
|
1787
1804
|
}
|
|
1788
|
-
function
|
|
1805
|
+
function me(t) {
|
|
1789
1806
|
for (const [n, e] of it(t))
|
|
1790
1807
|
if (n.intersects(e))
|
|
1791
1808
|
throw new Error("Diagram figures must not intersect");
|
|
@@ -1798,14 +1815,14 @@ export {
|
|
|
1798
1815
|
Z as a,
|
|
1799
1816
|
G as b,
|
|
1800
1817
|
Q as c,
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1818
|
+
jt as d,
|
|
1819
|
+
Jt as e,
|
|
1820
|
+
Ie as f,
|
|
1821
|
+
Gn as g,
|
|
1822
|
+
Et as h,
|
|
1806
1823
|
lt as i,
|
|
1807
1824
|
K as l,
|
|
1808
|
-
|
|
1809
|
-
|
|
1825
|
+
In as p,
|
|
1826
|
+
Ot as s
|
|
1810
1827
|
};
|
|
1811
|
-
//# sourceMappingURL=models-
|
|
1828
|
+
//# sourceMappingURL=models-BHeLX0dj.js.map
|