pantograph2d 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Diagram-1c56996e.js +1698 -0
- package/dist/Diagram-1c56996e.js.map +1 -0
- package/dist/Diagram-4fa55d2b.cjs +4 -0
- package/dist/Diagram-4fa55d2b.cjs.map +1 -0
- package/dist/draw-44dd36a9.js +256 -0
- package/dist/draw-44dd36a9.js.map +1 -0
- package/dist/draw-8c69c65f.cjs +2 -0
- package/dist/draw-8c69c65f.cjs.map +1 -0
- package/dist/drawShape.d.ts +153 -0
- package/dist/models.d.ts +7 -1
- package/dist/pantograph/drawShape.cjs +2 -0
- package/dist/pantograph/drawShape.cjs.map +1 -0
- package/dist/pantograph/drawShape.d.ts +1 -0
- package/dist/pantograph/drawShape.js +24 -0
- package/dist/pantograph/drawShape.js.map +1 -0
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +7 -6
- package/dist/pantograph.cjs +7 -7
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.d.ts +20 -4
- package/dist/pantograph.js +352 -726
- package/dist/pantograph.js.map +1 -1
- package/package.json +6 -2
- package/dist/exportJSON-944c662d.cjs +0 -4
- package/dist/exportJSON-944c662d.cjs.map +0 -1
- package/dist/exportJSON-c42ca4ac.js +0 -1427
- package/dist/exportJSON-c42ca4ac.js.map +0 -1
package/dist/pantograph.js
CHANGED
|
@@ -1,825 +1,451 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { o as nt, D } from "./draw-44dd36a9.js";
|
|
2
|
+
import { d as Jt } from "./draw-44dd36a9.js";
|
|
3
|
+
import { F as h, L as $, D as P, f as C, r as et, z as st, s as rt, a as ot, c as it, i as ft, l as at, d as g, b as ct, p as ut, n as Z, e as E, g as lt, h as pt, j as Pt, k as mt, m as d, A as w, o as L, q as gt, t as dt, u as wt, S as ht } from "./Diagram-1c56996e.js";
|
|
4
|
+
import { v as Xt } from "./Diagram-1c56996e.js";
|
|
5
|
+
function F(t) {
|
|
6
|
+
if (t instanceof h)
|
|
7
|
+
return [t];
|
|
8
|
+
if (t instanceof $)
|
|
9
|
+
return [new h(t)];
|
|
10
|
+
if (t instanceof P)
|
|
11
|
+
return t.figures;
|
|
12
|
+
throw new Error("Unknown shape");
|
|
7
13
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
function H(t, n, e = 1e-9) {
|
|
15
|
+
let r = [];
|
|
16
|
+
const o = [], s = new Array(n.segments.length).fill(0).map(() => []);
|
|
17
|
+
n.segments.forEach((u, i) => {
|
|
18
|
+
t.segments.forEach((m) => {
|
|
19
|
+
const { intersections: f, overlaps: c } = C(
|
|
20
|
+
u,
|
|
21
|
+
m,
|
|
22
|
+
e
|
|
23
|
+
);
|
|
24
|
+
r.push(...f), s[i].push(...f), o.push(...c);
|
|
25
|
+
const l = c.flatMap((S) => [
|
|
26
|
+
S.firstPoint,
|
|
27
|
+
S.lastPoint
|
|
28
|
+
]);
|
|
29
|
+
r.push(...l), s[i].push(...l);
|
|
30
|
+
});
|
|
31
|
+
}), r = et(r, e);
|
|
32
|
+
const a = st([n.segments, s]).flatMap(([u, i]) => i.length ? u.splitAt(i) : [u]);
|
|
33
|
+
return Array.from(
|
|
34
|
+
rt(
|
|
35
|
+
a,
|
|
36
|
+
r,
|
|
37
|
+
o
|
|
38
|
+
)
|
|
39
|
+
);
|
|
14
40
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
41
|
+
function O(t, n, e = !1) {
|
|
42
|
+
return H(n, t).filter((o) => {
|
|
43
|
+
const s = o.segments[0].midPoint;
|
|
44
|
+
return n.onStroke(s) ? !e : !n.contains(s);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function x(t, n, e = !1) {
|
|
48
|
+
return H(n, t).filter((o) => {
|
|
49
|
+
const s = o.segments[0].midPoint;
|
|
50
|
+
return n.onStroke(s) ? !e : n.contains(s);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function V(t, n, e = !1) {
|
|
54
|
+
const r = O(
|
|
55
|
+
t,
|
|
56
|
+
n.contour,
|
|
57
|
+
e
|
|
58
|
+
), o = n.holes.flatMap(
|
|
59
|
+
(s) => x(t, s, e)
|
|
20
60
|
);
|
|
61
|
+
return [...r, ...o];
|
|
21
62
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
n.lastPoint,
|
|
28
|
-
v($(n.tangentAtLastPoint), t)
|
|
29
|
-
), r = t * (n.clockwise ? 1 : -1);
|
|
30
|
-
return n.radius + r < n.precision ? new T(e, i) : new y(e, i, n.center, n.clockwise);
|
|
31
|
-
}
|
|
32
|
-
function rt(n, t, e) {
|
|
33
|
-
const i = et(
|
|
34
|
-
n.tangentAtLastPoint,
|
|
35
|
-
t.tangentAtFirstPoint
|
|
63
|
+
function T(t, n, e = !1) {
|
|
64
|
+
let r = x(
|
|
65
|
+
t,
|
|
66
|
+
n.contour,
|
|
67
|
+
e
|
|
36
68
|
);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (o instanceof T || a instanceof T)
|
|
41
|
-
return null;
|
|
42
|
-
let h;
|
|
43
|
-
try {
|
|
44
|
-
h = ut(o, a, 1e-9).at(-1);
|
|
45
|
-
} catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
if (!h)
|
|
49
|
-
return null;
|
|
50
|
-
const l = h, c = (p, g) => {
|
|
51
|
-
const m = g.tangentAt(l), x = pt(m), d = F(l, v(x, s));
|
|
52
|
-
return p.splitAt(d);
|
|
53
|
-
}, [f] = c(n, o), [, u] = c(t, a);
|
|
54
|
-
return { first: f, second: u, center: l };
|
|
55
|
-
}
|
|
56
|
-
function V(n, t, e) {
|
|
57
|
-
const i = rt(n, t, e);
|
|
58
|
-
if (!i)
|
|
59
|
-
return console.warn(
|
|
60
|
-
"Cannot fillet between segments",
|
|
61
|
-
n.repr,
|
|
62
|
-
t.repr
|
|
63
|
-
), [n, t];
|
|
64
|
-
const { first: r, second: s } = i;
|
|
65
|
-
return [
|
|
66
|
-
r,
|
|
67
|
-
nt(r.lastPoint, s.firstPoint, r.tangentAtLastPoint),
|
|
68
|
-
s
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
function N(n, t, e) {
|
|
72
|
-
const i = rt(n, t, e);
|
|
73
|
-
if (!i)
|
|
74
|
-
return console.warn(
|
|
75
|
-
"Cannot chamfer between segments",
|
|
76
|
-
n.repr,
|
|
77
|
-
t.repr
|
|
78
|
-
), [n, t];
|
|
79
|
-
const { first: r, second: s } = i;
|
|
80
|
-
return [r, new A(r.lastPoint, s.firstPoint), s];
|
|
81
|
-
}
|
|
82
|
-
function X(n) {
|
|
83
|
-
return new P([new b(new I(n))]);
|
|
84
|
-
}
|
|
85
|
-
class Et {
|
|
86
|
-
constructor(t = [0, 0]) {
|
|
87
|
-
this.pointer = t, this.firstPoint = t, this.pendingSegments = [], this._nextCorner = null;
|
|
88
|
-
}
|
|
89
|
-
movePointerTo(t) {
|
|
90
|
-
if (this.pendingSegments.length)
|
|
91
|
-
throw new Error(
|
|
92
|
-
"You can only move the pointer if there is no segment defined"
|
|
93
|
-
);
|
|
94
|
-
return this.pointer = t, this.firstPoint = t, this;
|
|
95
|
-
}
|
|
96
|
-
saveSegment(t) {
|
|
97
|
-
if (_(t.firstPoint, t.lastPoint))
|
|
98
|
-
throw new Error(`Segment has no length, ${t.repr}`);
|
|
99
|
-
if (!this._nextCorner)
|
|
100
|
-
return this.pendingSegments.push(t), this;
|
|
101
|
-
const e = this.pendingSegments.pop();
|
|
102
|
-
if (!e)
|
|
103
|
-
throw new Error("bug in the custom corner algorithm");
|
|
104
|
-
const i = this._nextCorner.mode === "chamfer" ? N : V;
|
|
105
|
-
return this.pendingSegments.push(
|
|
106
|
-
...i(e, t, this._nextCorner.radius)
|
|
107
|
-
), this._nextCorner = null, this;
|
|
108
|
-
}
|
|
109
|
-
lineTo(t) {
|
|
110
|
-
const e = new A(this.pointer, t);
|
|
111
|
-
return this.pointer = t, this.saveSegment(e);
|
|
112
|
-
}
|
|
113
|
-
line(t, e) {
|
|
114
|
-
return this.lineTo([this.pointer[0] + t, this.pointer[1] + e]);
|
|
115
|
-
}
|
|
116
|
-
vLine(t) {
|
|
117
|
-
return this.line(0, t);
|
|
118
|
-
}
|
|
119
|
-
hLine(t) {
|
|
120
|
-
return this.line(t, 0);
|
|
121
|
-
}
|
|
122
|
-
vLineTo(t) {
|
|
123
|
-
return this.lineTo([this.pointer[0], t]);
|
|
124
|
-
}
|
|
125
|
-
hLineTo(t) {
|
|
126
|
-
return this.lineTo([t, this.pointer[1]]);
|
|
127
|
-
}
|
|
128
|
-
polarLineTo([t, e]) {
|
|
129
|
-
const i = e * R, r = Y(t, i);
|
|
130
|
-
return this.lineTo(r);
|
|
131
|
-
}
|
|
132
|
-
polarLine(t, e) {
|
|
133
|
-
const i = e * R, [r, s] = Y(t, i);
|
|
134
|
-
return this.line(r, s);
|
|
135
|
-
}
|
|
136
|
-
tangentLine(t) {
|
|
137
|
-
const e = this.pendingSegments.at(-1);
|
|
138
|
-
if (!e)
|
|
139
|
-
throw new Error("You need a previous segment to sketch a tangent line");
|
|
140
|
-
const [i, r] = e.tangentAtLastPoint;
|
|
141
|
-
return this.line(i * t, r * t);
|
|
142
|
-
}
|
|
143
|
-
threePointsArcTo(t, e) {
|
|
144
|
-
return this.saveSegment(dt(this.pointer, e, t)), this.pointer = t, this;
|
|
145
|
-
}
|
|
146
|
-
threePointsArc(t, e, i, r) {
|
|
147
|
-
const [s, o] = this.pointer;
|
|
148
|
-
return this.threePointsArcTo(
|
|
149
|
-
[s + t, o + e],
|
|
150
|
-
[s + i, o + r]
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
sagittaArcTo(t, e) {
|
|
154
|
-
if (!e)
|
|
155
|
-
return this.lineTo(t);
|
|
156
|
-
const i = new A(this.pointer, t), r = $(i.tangentAtFirstPoint), s = F(i.midPoint, v(r, e));
|
|
157
|
-
return this.threePointsArcTo(t, s);
|
|
158
|
-
}
|
|
159
|
-
sagittaArc(t, e, i) {
|
|
160
|
-
return this.sagittaArcTo(
|
|
161
|
-
[t + this.pointer[0], e + this.pointer[1]],
|
|
162
|
-
i
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
vSagittaArc(t, e) {
|
|
166
|
-
return this.sagittaArc(0, t, e);
|
|
167
|
-
}
|
|
168
|
-
hSagittaArc(t, e) {
|
|
169
|
-
return this.sagittaArc(t, 0, e);
|
|
170
|
-
}
|
|
171
|
-
bulgeArcTo(t, e) {
|
|
172
|
-
if (!e)
|
|
173
|
-
return this.lineTo(t);
|
|
174
|
-
const i = S(this.pointer, t) / 2, r = -e * i;
|
|
175
|
-
return this.sagittaArcTo(t, r);
|
|
176
|
-
}
|
|
177
|
-
bulgeArc(t, e, i) {
|
|
178
|
-
return this.bulgeArcTo(
|
|
179
|
-
[t + this.pointer[0], e + this.pointer[1]],
|
|
180
|
-
i
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
vBulgeArc(t, e) {
|
|
184
|
-
return this.bulgeArc(0, t, e);
|
|
185
|
-
}
|
|
186
|
-
hBulgeArc(t, e) {
|
|
187
|
-
return this.bulgeArc(t, 0, e);
|
|
188
|
-
}
|
|
189
|
-
tangentArcTo(t) {
|
|
190
|
-
const e = this.pendingSegments.at(-1);
|
|
191
|
-
if (!e)
|
|
192
|
-
throw new Error("You need a previous curve to sketch a tangent arc");
|
|
193
|
-
return this.saveSegment(
|
|
194
|
-
nt(this.pointer, t, e.tangentAtLastPoint)
|
|
195
|
-
), this.pointer = t, this;
|
|
196
|
-
}
|
|
197
|
-
tangentArc(t, e) {
|
|
198
|
-
const [i, r] = this.pointer;
|
|
199
|
-
return this.tangentArcTo([t + i, e + r]);
|
|
200
|
-
}
|
|
201
|
-
customCorner(t, e = "fillet") {
|
|
202
|
-
if (!this.pendingSegments.length)
|
|
203
|
-
throw new Error("You need a segment defined to fillet the angle");
|
|
204
|
-
return this._nextCorner = { mode: e, radius: t }, this;
|
|
205
|
-
}
|
|
206
|
-
_customCornerLastWithFirst(t, e = "fillet") {
|
|
207
|
-
if (!t)
|
|
208
|
-
return;
|
|
209
|
-
const i = this.pendingSegments.pop(), r = this.pendingSegments.shift();
|
|
210
|
-
if (!i || !r)
|
|
211
|
-
throw new Error("Not enough curves to close and fillet");
|
|
212
|
-
const s = e === "chamfer" ? N : V;
|
|
213
|
-
this.pendingSegments.push(...s(i, r, t));
|
|
214
|
-
}
|
|
215
|
-
close() {
|
|
216
|
-
if (!this.pendingSegments.length)
|
|
217
|
-
throw new Error("No segments to close");
|
|
218
|
-
const t = this.pendingSegments[0], e = this.pendingSegments.at(-1);
|
|
219
|
-
return _(t.firstPoint, e.lastPoint) || this.lineTo(t.firstPoint), this._nextCorner !== null && (this._customCornerLastWithFirst(
|
|
220
|
-
this._nextCorner.radius,
|
|
221
|
-
this._nextCorner.mode
|
|
222
|
-
), this._nextCorner = null), X(this.pendingSegments);
|
|
223
|
-
}
|
|
224
|
-
closeWithMirror() {
|
|
225
|
-
if (!this.pendingSegments.length)
|
|
226
|
-
throw new Error("No segments to close");
|
|
227
|
-
const t = this.pendingSegments[0], e = this.pendingSegments.at(-1), i = L(
|
|
228
|
-
e.lastPoint,
|
|
229
|
-
t.firstPoint
|
|
230
|
-
), r = new gt().mirrorLine(
|
|
231
|
-
i,
|
|
232
|
-
t.firstPoint
|
|
233
|
-
), s = this.pendingSegments.map(
|
|
234
|
-
(o) => o.transform(r).reverse()
|
|
69
|
+
return n.holes.forEach((o) => {
|
|
70
|
+
r = r.flatMap(
|
|
71
|
+
(s) => O(s, o, e)
|
|
235
72
|
);
|
|
236
|
-
|
|
237
|
-
...this.pendingSegments,
|
|
238
|
-
...s
|
|
239
|
-
]);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function qt(n = [0, 0]) {
|
|
243
|
-
return new Et(n);
|
|
244
|
-
}
|
|
245
|
-
function E(n) {
|
|
246
|
-
if (n instanceof b)
|
|
247
|
-
return [n];
|
|
248
|
-
if (n instanceof I)
|
|
249
|
-
return [new b(n)];
|
|
250
|
-
if (n instanceof P)
|
|
251
|
-
return n.figures;
|
|
252
|
-
throw new Error("Unknown shape");
|
|
73
|
+
}), r;
|
|
253
74
|
}
|
|
254
|
-
function
|
|
75
|
+
function St(t, n) {
|
|
255
76
|
return new P(
|
|
256
|
-
|
|
77
|
+
ot(F(t), F(n))
|
|
257
78
|
);
|
|
258
79
|
}
|
|
259
|
-
function
|
|
260
|
-
return
|
|
261
|
-
(
|
|
80
|
+
function R(t) {
|
|
81
|
+
return t.reduce(
|
|
82
|
+
(n, e) => St(n, e),
|
|
262
83
|
new P()
|
|
263
84
|
);
|
|
264
85
|
}
|
|
265
|
-
function
|
|
86
|
+
function Mt(t, n) {
|
|
266
87
|
return new P(
|
|
267
|
-
|
|
88
|
+
it(F(t), F(n))
|
|
268
89
|
);
|
|
269
90
|
}
|
|
270
|
-
function
|
|
91
|
+
function xt(t, n) {
|
|
271
92
|
return new P(
|
|
272
|
-
|
|
93
|
+
ft(F(t), F(n))
|
|
273
94
|
);
|
|
274
95
|
}
|
|
275
|
-
function
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
96
|
+
function Gt(t, n, e = !0) {
|
|
97
|
+
if (n instanceof $)
|
|
98
|
+
return O(t, n, e);
|
|
99
|
+
if (n instanceof h)
|
|
100
|
+
return V(t, n, e);
|
|
101
|
+
let r = [t];
|
|
102
|
+
return n.figures.forEach((o) => {
|
|
103
|
+
r = r.flatMap((s) => V(s, o, e));
|
|
104
|
+
}), r;
|
|
105
|
+
}
|
|
106
|
+
function Vt(t, n, e = !1) {
|
|
107
|
+
if (n instanceof $)
|
|
108
|
+
return x(t, n, e);
|
|
109
|
+
if (n instanceof h)
|
|
110
|
+
return T(t, n, e);
|
|
111
|
+
let r = [t];
|
|
112
|
+
return n.figures.forEach((o) => {
|
|
113
|
+
r = r.flatMap((s) => T(s, o, e));
|
|
114
|
+
}), r;
|
|
115
|
+
}
|
|
116
|
+
function U(t) {
|
|
117
|
+
return t < 0 ? "before" : t > 1 ? "after" : "between";
|
|
118
|
+
}
|
|
119
|
+
const N = (t, n, e) => {
|
|
279
120
|
if (e === "before")
|
|
280
|
-
return
|
|
121
|
+
return t.distanceFrom(n.firstPoint);
|
|
281
122
|
if (e === "after")
|
|
282
|
-
return
|
|
123
|
+
return t.distanceFrom(n.lastPoint);
|
|
283
124
|
throw new Error("Invalid position");
|
|
284
125
|
};
|
|
285
|
-
function
|
|
286
|
-
const e =
|
|
126
|
+
function At(t, n) {
|
|
127
|
+
const e = at(t, n);
|
|
287
128
|
if (e === "parallel")
|
|
288
129
|
return Math.min(
|
|
289
|
-
|
|
290
|
-
|
|
130
|
+
t.distanceFrom(n.firstPoint),
|
|
131
|
+
t.distanceFrom(n.lastPoint)
|
|
291
132
|
);
|
|
292
|
-
const { intersectionParam1:
|
|
293
|
-
if (s === "between" &&
|
|
133
|
+
const { intersectionParam1: r, intersectionParam2: o } = e, s = U(r), a = U(o);
|
|
134
|
+
if (s === "between" && a === "between")
|
|
294
135
|
return 0;
|
|
295
|
-
if (s === "between" &&
|
|
296
|
-
return
|
|
297
|
-
if (
|
|
298
|
-
return
|
|
299
|
-
if (s === "before" &&
|
|
300
|
-
return
|
|
301
|
-
if (s === "after" &&
|
|
302
|
-
return
|
|
303
|
-
if (s === "before" &&
|
|
304
|
-
return
|
|
305
|
-
if (s === "after" &&
|
|
306
|
-
return
|
|
136
|
+
if (s === "between" && a !== "between")
|
|
137
|
+
return N(t, n, a);
|
|
138
|
+
if (a === "between" && s !== "between")
|
|
139
|
+
return N(n, t, s);
|
|
140
|
+
if (s === "before" && a === "before")
|
|
141
|
+
return g(t.firstPoint, n.firstPoint);
|
|
142
|
+
if (s === "after" && a === "after")
|
|
143
|
+
return g(t.lastPoint, n.lastPoint);
|
|
144
|
+
if (s === "before" && a === "after")
|
|
145
|
+
return g(t.firstPoint, n.lastPoint);
|
|
146
|
+
if (s === "after" && a === "before")
|
|
147
|
+
return g(t.lastPoint, n.firstPoint);
|
|
307
148
|
throw new Error("Invalid position");
|
|
308
149
|
}
|
|
309
|
-
function
|
|
310
|
-
if (
|
|
150
|
+
function z(t, n) {
|
|
151
|
+
if (ct(t, n).length > 0)
|
|
311
152
|
return 0;
|
|
312
|
-
const e =
|
|
313
|
-
if (
|
|
314
|
-
const
|
|
315
|
-
if (Math.abs(
|
|
153
|
+
const e = ut(t, n.center);
|
|
154
|
+
if (t.isOnSegment(e)) {
|
|
155
|
+
const r = g(e, n.center);
|
|
156
|
+
if (Math.abs(r - n.radius) < t.precision && n.isOnSegment(e))
|
|
316
157
|
return 0;
|
|
317
|
-
if (
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
), s =
|
|
321
|
-
|
|
322
|
-
|
|
158
|
+
if (r - n.radius > t.precision) {
|
|
159
|
+
const o = Z(
|
|
160
|
+
E(e, n.center)
|
|
161
|
+
), s = lt(
|
|
162
|
+
n.center,
|
|
163
|
+
pt(o, n.radius)
|
|
323
164
|
);
|
|
324
|
-
if (
|
|
325
|
-
return
|
|
165
|
+
if (n.isOnSegment(s))
|
|
166
|
+
return g(s, e);
|
|
326
167
|
}
|
|
327
168
|
}
|
|
328
169
|
return Math.min(
|
|
329
|
-
t.distanceFrom(n.firstPoint),
|
|
330
|
-
t.distanceFrom(n.lastPoint),
|
|
331
170
|
n.distanceFrom(t.firstPoint),
|
|
332
|
-
n.distanceFrom(t.lastPoint)
|
|
171
|
+
n.distanceFrom(t.lastPoint),
|
|
172
|
+
t.distanceFrom(n.firstPoint),
|
|
173
|
+
t.distanceFrom(n.lastPoint)
|
|
333
174
|
);
|
|
334
175
|
}
|
|
335
|
-
const Lt = (
|
|
336
|
-
const e =
|
|
337
|
-
if (
|
|
176
|
+
const Lt = (t, n) => {
|
|
177
|
+
const e = t.angleToParam(n.firstAngle);
|
|
178
|
+
if (t.isValidParameter(e))
|
|
338
179
|
return !0;
|
|
339
|
-
const
|
|
340
|
-
return !!
|
|
180
|
+
const r = t.angleToParam(n.lastAngle);
|
|
181
|
+
return !!t.isValidParameter(r);
|
|
341
182
|
};
|
|
342
|
-
function
|
|
343
|
-
if (
|
|
183
|
+
function $t(t, n) {
|
|
184
|
+
if (Pt(t, n, !0).length > 0)
|
|
344
185
|
return 0;
|
|
345
|
-
const e =
|
|
346
|
-
if (e <
|
|
347
|
-
return Math.abs(
|
|
348
|
-
const
|
|
349
|
-
let s =
|
|
350
|
-
|
|
351
|
-
const
|
|
352
|
-
return
|
|
353
|
-
n.distanceFrom(t.firstPoint),
|
|
354
|
-
n.distanceFrom(t.lastPoint),
|
|
186
|
+
const e = g(t.center, n.center);
|
|
187
|
+
if (e < t.precision && Lt(t, n))
|
|
188
|
+
return Math.abs(t.radius - n.radius);
|
|
189
|
+
const r = Z(E(n.center, t.center)), o = e - Math.abs(t.radius - n.radius) < t.precision;
|
|
190
|
+
let s = mt(r);
|
|
191
|
+
o && n.radius > t.radius && (s += Math.PI);
|
|
192
|
+
const a = o ? s : s + Math.PI, u = t.angleToParam(s), i = n.angleToParam(a);
|
|
193
|
+
return t.isValidParameter(u) && n.isValidParameter(i) ? g(t.paramPoint(u), n.paramPoint(i)) : Math.min(
|
|
355
194
|
t.distanceFrom(n.firstPoint),
|
|
356
|
-
t.distanceFrom(n.lastPoint)
|
|
195
|
+
t.distanceFrom(n.lastPoint),
|
|
196
|
+
n.distanceFrom(t.firstPoint),
|
|
197
|
+
n.distanceFrom(t.lastPoint)
|
|
357
198
|
);
|
|
358
199
|
}
|
|
359
|
-
function
|
|
360
|
-
if (
|
|
361
|
-
return
|
|
362
|
-
if (
|
|
363
|
-
return
|
|
364
|
-
if (
|
|
365
|
-
return
|
|
366
|
-
if (
|
|
367
|
-
return
|
|
200
|
+
function Ft(t, n) {
|
|
201
|
+
if (t instanceof d && n instanceof d)
|
|
202
|
+
return At(t, n);
|
|
203
|
+
if (t instanceof d && n instanceof w)
|
|
204
|
+
return z(t, n);
|
|
205
|
+
if (t instanceof w && n instanceof d)
|
|
206
|
+
return z(n, t);
|
|
207
|
+
if (t instanceof w && n instanceof w)
|
|
208
|
+
return $t(t, n);
|
|
368
209
|
throw new Error("Not implemented");
|
|
369
210
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
push(t, e) {
|
|
378
|
-
let i = this.length++;
|
|
379
|
-
for (; i > 0; ) {
|
|
380
|
-
const r = i - 1 >> 1, s = this.values[r];
|
|
381
|
-
if (e >= s)
|
|
382
|
-
break;
|
|
383
|
-
this.ids[i] = this.ids[r], this.values[i] = s, i = r;
|
|
384
|
-
}
|
|
385
|
-
this.ids[i] = t, this.values[i] = e;
|
|
386
|
-
}
|
|
387
|
-
pop() {
|
|
388
|
-
if (this.length === 0)
|
|
389
|
-
return;
|
|
390
|
-
const t = this.ids[0];
|
|
391
|
-
if (this.length--, this.length > 0) {
|
|
392
|
-
const e = this.ids[0] = this.ids[this.length], i = this.values[0] = this.values[this.length], r = this.length >> 1;
|
|
393
|
-
let s = 0;
|
|
394
|
-
for (; s < r; ) {
|
|
395
|
-
let o = (s << 1) + 1;
|
|
396
|
-
const a = o + 1;
|
|
397
|
-
let h = this.ids[o], l = this.values[o];
|
|
398
|
-
const c = this.values[a];
|
|
399
|
-
if (a < this.length && c < l && (o = a, h = this.ids[a], l = c), l >= i)
|
|
400
|
-
break;
|
|
401
|
-
this.ids[s] = h, this.values[s] = l, s = o;
|
|
402
|
-
}
|
|
403
|
-
this.ids[s] = e, this.values[s] = i;
|
|
404
|
-
}
|
|
405
|
-
return t;
|
|
406
|
-
}
|
|
407
|
-
peek() {
|
|
408
|
-
if (this.length !== 0)
|
|
409
|
-
return this.ids[0];
|
|
410
|
-
}
|
|
411
|
-
peekValue() {
|
|
412
|
-
if (this.length !== 0)
|
|
413
|
-
return this.values[0];
|
|
414
|
-
}
|
|
415
|
-
shrink() {
|
|
416
|
-
this.ids.length = this.values.length = this.length;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
const J = [
|
|
420
|
-
Int8Array,
|
|
421
|
-
Uint8Array,
|
|
422
|
-
Uint8ClampedArray,
|
|
423
|
-
Int16Array,
|
|
424
|
-
Uint16Array,
|
|
425
|
-
Int32Array,
|
|
426
|
-
Uint32Array,
|
|
427
|
-
Float32Array,
|
|
428
|
-
Float64Array
|
|
429
|
-
], C = 3;
|
|
430
|
-
class U {
|
|
431
|
-
static from(t) {
|
|
432
|
-
if (!t || t.byteLength === void 0 || t.buffer)
|
|
433
|
-
throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");
|
|
434
|
-
const [e, i] = new Uint8Array(t, 0, 2);
|
|
435
|
-
if (e !== 251)
|
|
436
|
-
throw new Error("Data does not appear to be in a Flatbush format.");
|
|
437
|
-
if (i >> 4 !== C)
|
|
438
|
-
throw new Error(`Got v${i >> 4} data when expected v${C}.`);
|
|
439
|
-
const [r] = new Uint16Array(t, 2, 1), [s] = new Uint32Array(t, 4, 1);
|
|
440
|
-
return new U(s, r, J[i & 15], void 0, t);
|
|
441
|
-
}
|
|
442
|
-
constructor(t, e = 16, i = Float64Array, r = ArrayBuffer, s) {
|
|
443
|
-
if (t === void 0)
|
|
444
|
-
throw new Error("Missing required argument: numItems.");
|
|
445
|
-
if (isNaN(t) || t <= 0)
|
|
446
|
-
throw new Error(`Unexpected numItems value: ${t}.`);
|
|
447
|
-
this.numItems = +t, this.nodeSize = Math.min(Math.max(+e, 2), 65535);
|
|
448
|
-
let o = t, a = o;
|
|
449
|
-
this._levelBounds = [o * 4];
|
|
450
|
-
do
|
|
451
|
-
o = Math.ceil(o / this.nodeSize), a += o, this._levelBounds.push(a * 4);
|
|
452
|
-
while (o !== 1);
|
|
453
|
-
this.ArrayType = i || Float64Array, this.IndexArrayType = a < 16384 ? Uint16Array : Uint32Array;
|
|
454
|
-
const h = J.indexOf(this.ArrayType), l = a * 4 * this.ArrayType.BYTES_PER_ELEMENT;
|
|
455
|
-
if (h < 0)
|
|
456
|
-
throw new Error(`Unexpected typed array class: ${i}.`);
|
|
457
|
-
s && s.byteLength !== void 0 && !s.buffer ? (this.data = s, this._boxes = new this.ArrayType(this.data, 8, a * 4), this._indices = new this.IndexArrayType(this.data, 8 + l, a), this._pos = a * 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 r(8 + l + a * this.IndexArrayType.BYTES_PER_ELEMENT), this._boxes = new this.ArrayType(this.data, 8, a * 4), this._indices = new this.IndexArrayType(this.data, 8 + l, a), 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, (C << 4) + h]), new Uint16Array(this.data, 2, 1)[0] = e, new Uint32Array(this.data, 4, 1)[0] = t), this._queue = new Dt();
|
|
458
|
-
}
|
|
459
|
-
add(t, e, i, r) {
|
|
460
|
-
const s = this._pos >> 2, o = this._boxes;
|
|
461
|
-
return this._indices[s] = s, o[this._pos++] = t, o[this._pos++] = e, o[this._pos++] = i, o[this._pos++] = r, t < this.minX && (this.minX = t), e < this.minY && (this.minY = e), i > this.maxX && (this.maxX = i), r > this.maxY && (this.maxY = r), s;
|
|
462
|
-
}
|
|
463
|
-
finish() {
|
|
464
|
-
if (this._pos >> 2 !== this.numItems)
|
|
465
|
-
throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
|
|
466
|
-
const t = this._boxes;
|
|
467
|
-
if (this.numItems <= this.nodeSize) {
|
|
468
|
-
t[this._pos++] = this.minX, t[this._pos++] = this.minY, t[this._pos++] = this.maxX, t[this._pos++] = this.maxY;
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
const e = this.maxX - this.minX || 1, i = this.maxY - this.minY || 1, r = new Uint32Array(this.numItems), s = (1 << 16) - 1;
|
|
472
|
-
for (let o = 0, a = 0; o < this.numItems; o++) {
|
|
473
|
-
const h = t[a++], l = t[a++], c = t[a++], f = t[a++], u = Math.floor(s * ((h + c) / 2 - this.minX) / e), p = Math.floor(s * ((l + f) / 2 - this.minY) / i);
|
|
474
|
-
r[o] = Bt(u, p);
|
|
475
|
-
}
|
|
476
|
-
k(r, t, this._indices, 0, this.numItems - 1, this.nodeSize);
|
|
477
|
-
for (let o = 0, a = 0; o < this._levelBounds.length - 1; o++) {
|
|
478
|
-
const h = this._levelBounds[o];
|
|
479
|
-
for (; a < h; ) {
|
|
480
|
-
const l = a;
|
|
481
|
-
let c = t[a++], f = t[a++], u = t[a++], p = t[a++];
|
|
482
|
-
for (let g = 1; g < this.nodeSize && a < h; g++)
|
|
483
|
-
c = Math.min(c, t[a++]), f = Math.min(f, t[a++]), u = Math.max(u, t[a++]), p = Math.max(p, t[a++]);
|
|
484
|
-
this._indices[this._pos >> 2] = l, t[this._pos++] = c, t[this._pos++] = f, t[this._pos++] = u, t[this._pos++] = p;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
search(t, e, i, r, s) {
|
|
489
|
-
if (this._pos !== this._boxes.length)
|
|
490
|
-
throw new Error("Data not yet indexed - call index.finish().");
|
|
491
|
-
let o = this._boxes.length - 4;
|
|
492
|
-
const a = [], h = [];
|
|
493
|
-
for (; o !== void 0; ) {
|
|
494
|
-
const l = Math.min(o + this.nodeSize * 4, Z(o, this._levelBounds));
|
|
495
|
-
for (let c = o; c < l; c += 4) {
|
|
496
|
-
if (i < this._boxes[c] || r < this._boxes[c + 1] || t > this._boxes[c + 2] || e > this._boxes[c + 3])
|
|
497
|
-
continue;
|
|
498
|
-
const f = this._indices[c >> 2] | 0;
|
|
499
|
-
o >= this.numItems * 4 ? a.push(f) : (s === void 0 || s(f)) && h.push(f);
|
|
500
|
-
}
|
|
501
|
-
o = a.pop();
|
|
502
|
-
}
|
|
503
|
-
return h;
|
|
504
|
-
}
|
|
505
|
-
neighbors(t, e, i = 1 / 0, r = 1 / 0, s) {
|
|
506
|
-
if (this._pos !== this._boxes.length)
|
|
507
|
-
throw new Error("Data not yet indexed - call index.finish().");
|
|
508
|
-
let o = this._boxes.length - 4;
|
|
509
|
-
const a = this._queue, h = [], l = r * r;
|
|
510
|
-
for (; o !== void 0; ) {
|
|
511
|
-
const c = Math.min(o + this.nodeSize * 4, Z(o, this._levelBounds));
|
|
512
|
-
for (let f = o; f < c; f += 4) {
|
|
513
|
-
const u = this._indices[f >> 2] | 0, p = Q(t, this._boxes[f], this._boxes[f + 2]), g = Q(e, this._boxes[f + 1], this._boxes[f + 3]), m = p * p + g * g;
|
|
514
|
-
o >= this.numItems * 4 ? a.push(u << 1, m) : (s === void 0 || s(u)) && a.push((u << 1) + 1, m);
|
|
515
|
-
}
|
|
516
|
-
for (; a.length && a.peek() & 1; )
|
|
517
|
-
if (a.peekValue() > l || (h.push(a.pop() >> 1), h.length === i))
|
|
518
|
-
return a.clear(), h;
|
|
519
|
-
o = a.pop() >> 1;
|
|
520
|
-
}
|
|
521
|
-
return a.clear(), h;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
function Q(n, t, e) {
|
|
525
|
-
return n < t ? t - n : n <= e ? 0 : n - e;
|
|
526
|
-
}
|
|
527
|
-
function Z(n, t) {
|
|
528
|
-
let e = 0, i = t.length - 1;
|
|
529
|
-
for (; e < i; ) {
|
|
530
|
-
const r = e + i >> 1;
|
|
531
|
-
t[r] > n ? i = r : e = r + 1;
|
|
532
|
-
}
|
|
533
|
-
return t[e];
|
|
534
|
-
}
|
|
535
|
-
function k(n, t, e, i, r, s) {
|
|
536
|
-
if (Math.floor(i / s) >= Math.floor(r / s))
|
|
537
|
-
return;
|
|
538
|
-
const o = n[i + r >> 1];
|
|
539
|
-
let a = i - 1, h = r + 1;
|
|
540
|
-
for (; ; ) {
|
|
541
|
-
do
|
|
542
|
-
a++;
|
|
543
|
-
while (n[a] < o);
|
|
544
|
-
do
|
|
545
|
-
h--;
|
|
546
|
-
while (n[h] > o);
|
|
547
|
-
if (a >= h)
|
|
548
|
-
break;
|
|
549
|
-
kt(n, t, e, a, h);
|
|
550
|
-
}
|
|
551
|
-
k(n, t, e, i, h, s), k(n, t, e, h + 1, r, s);
|
|
552
|
-
}
|
|
553
|
-
function kt(n, t, e, i, r) {
|
|
554
|
-
const s = n[i];
|
|
555
|
-
n[i] = n[r], n[r] = s;
|
|
556
|
-
const o = 4 * i, a = 4 * r, h = t[o], l = t[o + 1], c = t[o + 2], f = t[o + 3];
|
|
557
|
-
t[o] = t[a], t[o + 1] = t[a + 1], t[o + 2] = t[a + 2], t[o + 3] = t[a + 3], t[a] = h, t[a + 1] = l, t[a + 2] = c, t[a + 3] = f;
|
|
558
|
-
const u = e[i];
|
|
559
|
-
e[i] = e[r], e[r] = u;
|
|
560
|
-
}
|
|
561
|
-
function Bt(n, t) {
|
|
562
|
-
let e = n ^ t, i = 65535 ^ e, r = 65535 ^ (n | t), s = n & (t ^ 65535), o = e | i >> 1, a = e >> 1 ^ e, h = r >> 1 ^ i & s >> 1 ^ r, l = e & r >> 1 ^ s >> 1 ^ s;
|
|
563
|
-
e = o, i = a, r = h, s = l, o = e & e >> 2 ^ i & i >> 2, a = e & i >> 2 ^ i & (e ^ i) >> 2, h ^= e & r >> 2 ^ i & s >> 2, l ^= i & r >> 2 ^ (e ^ i) & s >> 2, e = o, i = a, r = h, s = l, o = e & e >> 4 ^ i & i >> 4, a = e & i >> 4 ^ i & (e ^ i) >> 4, h ^= e & r >> 4 ^ i & s >> 4, l ^= i & r >> 4 ^ (e ^ i) & s >> 4, e = o, i = a, r = h, s = l, h ^= e & r >> 8 ^ i & s >> 8, l ^= i & r >> 8 ^ (e ^ i) & s >> 8, e = h ^ h >> 1, i = l ^ l >> 1;
|
|
564
|
-
let c = n ^ t, f = i | 65535 ^ (c | e);
|
|
565
|
-
return c = (c | c << 8) & 16711935, c = (c | c << 4) & 252645135, c = (c | c << 2) & 858993459, c = (c | c << 1) & 1431655765, f = (f | f << 8) & 16711935, f = (f | f << 4) & 252645135, f = (f | f << 2) & 858993459, f = (f | f << 1) & 1431655765, (f << 1 | c) >>> 0;
|
|
566
|
-
}
|
|
567
|
-
function Ot(n, t = 1e-7) {
|
|
568
|
-
const e = new U(n.length);
|
|
569
|
-
n.forEach((s) => {
|
|
570
|
-
const [o, a] = s.firstPoint;
|
|
571
|
-
e.add(o - t, a - t, o + t, a + t);
|
|
572
|
-
}), e.finish();
|
|
573
|
-
const i = [], r = /* @__PURE__ */ new Set();
|
|
574
|
-
return n.forEach((s, o) => {
|
|
575
|
-
if (r.has(o))
|
|
576
|
-
return;
|
|
577
|
-
const a = [s];
|
|
578
|
-
let h = o;
|
|
579
|
-
r.add(o);
|
|
580
|
-
let l = n.length;
|
|
581
|
-
for (; ; ) {
|
|
582
|
-
if (l-- < 0)
|
|
583
|
-
throw new Error("Infinite loop detected");
|
|
584
|
-
const c = a[a.length - 1].lastPoint, [f, u] = c, p = e.search(
|
|
585
|
-
f - t,
|
|
586
|
-
u - t,
|
|
587
|
-
f + t,
|
|
588
|
-
u + t
|
|
589
|
-
), g = (w) => Math.abs((h - w) % n.length), m = p.filter((w) => !r.has(w)).map((w) => [
|
|
590
|
-
n[w],
|
|
591
|
-
w,
|
|
592
|
-
g(w)
|
|
593
|
-
]).sort(([, , w], [, , M]) => g(w) - g(M));
|
|
594
|
-
if (m.length === 0) {
|
|
595
|
-
i.push(a);
|
|
596
|
-
break;
|
|
597
|
-
}
|
|
598
|
-
const [x, d] = m[0];
|
|
599
|
-
a.push(x), r.add(d), h = d;
|
|
600
|
-
}
|
|
601
|
-
}), i;
|
|
602
|
-
}
|
|
603
|
-
const B = 1e-8;
|
|
604
|
-
function Ut(n, t) {
|
|
605
|
-
const e = n.map((h) => ({
|
|
606
|
-
offset: D(h, t),
|
|
607
|
-
original: h
|
|
608
|
-
})), i = [];
|
|
609
|
-
let r = null, s = e.at(-1);
|
|
211
|
+
const I = 1e-8;
|
|
212
|
+
function vt(t, n) {
|
|
213
|
+
const e = t.map((i) => ({
|
|
214
|
+
offset: nt(i, n),
|
|
215
|
+
original: i
|
|
216
|
+
})), r = [];
|
|
217
|
+
let o = null, s = e.at(-1);
|
|
610
218
|
if (!s)
|
|
611
219
|
return [];
|
|
612
|
-
if (
|
|
613
|
-
return
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
new
|
|
617
|
-
) :
|
|
618
|
-
},
|
|
619
|
-
for (const
|
|
620
|
-
yield
|
|
621
|
-
if (!
|
|
220
|
+
if (r.length === 1)
|
|
221
|
+
return r;
|
|
222
|
+
const a = (i) => {
|
|
223
|
+
o ? i.offset instanceof D ? L(i.offset.firstPoint, i.offset.lastPoint) || r.push(
|
|
224
|
+
new d(i.offset.firstPoint, i.offset.lastPoint)
|
|
225
|
+
) : r.push(i.offset) : o = i;
|
|
226
|
+
}, u = function* () {
|
|
227
|
+
for (const i of e.slice(0, -1))
|
|
228
|
+
yield i;
|
|
229
|
+
if (!o)
|
|
622
230
|
throw new Error("Bug in the offset algorithm");
|
|
623
|
-
yield
|
|
231
|
+
yield o;
|
|
624
232
|
};
|
|
625
|
-
for (const
|
|
626
|
-
const
|
|
627
|
-
if (
|
|
628
|
-
|
|
233
|
+
for (const i of u()) {
|
|
234
|
+
const m = s.offset.lastPoint, f = i.offset.firstPoint;
|
|
235
|
+
if (L(m, f)) {
|
|
236
|
+
a(s), s = i;
|
|
629
237
|
continue;
|
|
630
238
|
}
|
|
631
|
-
let
|
|
632
|
-
if (!(s.offset instanceof
|
|
633
|
-
const { intersections:
|
|
239
|
+
let c = [];
|
|
240
|
+
if (!(s.offset instanceof D) && !(i.offset instanceof D)) {
|
|
241
|
+
const { intersections: M, overlaps: A } = C(
|
|
634
242
|
s.offset,
|
|
635
|
-
|
|
636
|
-
|
|
243
|
+
i.offset,
|
|
244
|
+
I / 100
|
|
637
245
|
);
|
|
638
|
-
|
|
639
|
-
...
|
|
640
|
-
...
|
|
246
|
+
c = [
|
|
247
|
+
...M,
|
|
248
|
+
...A.flatMap((p) => [p.firstPoint, p.lastPoint])
|
|
641
249
|
];
|
|
642
250
|
}
|
|
643
|
-
if (
|
|
644
|
-
let
|
|
645
|
-
if (
|
|
646
|
-
const
|
|
647
|
-
(
|
|
251
|
+
if (c.length > 0) {
|
|
252
|
+
let M = c[0];
|
|
253
|
+
if (c.length > 1) {
|
|
254
|
+
const b = s == null ? void 0 : s.original.lastPoint, v = c.map(
|
|
255
|
+
(tt) => dt(tt, b)
|
|
648
256
|
);
|
|
649
|
-
|
|
257
|
+
M = c[v.indexOf(Math.min(...v))];
|
|
650
258
|
}
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
])[0],
|
|
654
|
-
if (!
|
|
259
|
+
const A = s.offset.splitAt([
|
|
260
|
+
M
|
|
261
|
+
])[0], p = i.offset.splitAt([M]).at(-1);
|
|
262
|
+
if (!p)
|
|
655
263
|
throw new Error("Bug in the splitting algo in offset");
|
|
656
|
-
|
|
657
|
-
offset:
|
|
264
|
+
a({
|
|
265
|
+
offset: A,
|
|
658
266
|
original: s.original
|
|
659
|
-
}), s = { offset:
|
|
267
|
+
}), s = { offset: p, original: i.original };
|
|
660
268
|
continue;
|
|
661
269
|
}
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
) > 0,
|
|
666
|
-
|
|
270
|
+
const l = s.original.lastPoint, S = wt(
|
|
271
|
+
E(f, l),
|
|
272
|
+
E(m, l)
|
|
273
|
+
) > 0, y = new w(m, f, l, S);
|
|
274
|
+
a(s), r.push(y), s = i;
|
|
667
275
|
}
|
|
668
|
-
return
|
|
276
|
+
return a(s), r;
|
|
669
277
|
}
|
|
670
|
-
function
|
|
671
|
-
const e =
|
|
672
|
-
if (
|
|
278
|
+
function q(t, n) {
|
|
279
|
+
const e = t.clockwise ? n : -n, r = vt(t.segments, e);
|
|
280
|
+
if (r.length < 2)
|
|
673
281
|
return new P();
|
|
674
|
-
const
|
|
675
|
-
const
|
|
676
|
-
|
|
282
|
+
const o = /* @__PURE__ */ new Map(), s = (f, c) => {
|
|
283
|
+
const l = o.get(f) || [];
|
|
284
|
+
o.set(f, [...l, ...c]);
|
|
677
285
|
};
|
|
678
|
-
if (
|
|
679
|
-
|
|
680
|
-
const { intersections:
|
|
681
|
-
...
|
|
682
|
-
...
|
|
683
|
-
].filter((
|
|
684
|
-
const
|
|
685
|
-
return !(
|
|
286
|
+
if (r.forEach((f, c) => {
|
|
287
|
+
r.slice(c + 1).forEach((l, S) => {
|
|
288
|
+
const { intersections: y, overlaps: M } = C(f, l, I), A = [
|
|
289
|
+
...y,
|
|
290
|
+
...M.flatMap((p) => [p.firstPoint, p.lastPoint])
|
|
291
|
+
].filter((p) => {
|
|
292
|
+
const b = L(p, f.firstPoint) || L(p, f.lastPoint), v = L(p, l.firstPoint) || L(p, l.lastPoint);
|
|
293
|
+
return !(b && v);
|
|
686
294
|
});
|
|
687
|
-
|
|
295
|
+
A.length && (s(c, A), s(S + c + 1, A));
|
|
688
296
|
});
|
|
689
|
-
}), !
|
|
690
|
-
const
|
|
691
|
-
return new P([new
|
|
692
|
-
}
|
|
693
|
-
const
|
|
694
|
-
if (!
|
|
695
|
-
return
|
|
696
|
-
const
|
|
697
|
-
return
|
|
698
|
-
}).filter((
|
|
699
|
-
if (!
|
|
297
|
+
}), !o.size) {
|
|
298
|
+
const f = new $(r);
|
|
299
|
+
return new P([new h(f)]);
|
|
300
|
+
}
|
|
301
|
+
const u = r.flatMap((f, c) => {
|
|
302
|
+
if (!o.has(c))
|
|
303
|
+
return f;
|
|
304
|
+
const l = o.get(c) || [];
|
|
305
|
+
return f.splitAt(l);
|
|
306
|
+
}).filter((f) => !t.segments.some((l) => Ft(l, f) < Math.abs(n) - I));
|
|
307
|
+
if (!u.length)
|
|
700
308
|
return new P();
|
|
701
|
-
const
|
|
702
|
-
return
|
|
309
|
+
const m = gt(u).filter((f) => f.length > 1).filter((f) => L(f[0].firstPoint, f.at(-1).lastPoint)).map((f) => new $(f));
|
|
310
|
+
return m.length ? new P(m.map((f) => new h(f))) : new P();
|
|
703
311
|
}
|
|
704
|
-
function
|
|
705
|
-
const e =
|
|
706
|
-
const
|
|
707
|
-
|
|
312
|
+
function Et(t, n) {
|
|
313
|
+
const e = t.map((r) => {
|
|
314
|
+
const o = R(
|
|
315
|
+
r.holes.map((s) => q(s, n))
|
|
708
316
|
);
|
|
709
|
-
return
|
|
317
|
+
return Mt(q(r.contour, n), o);
|
|
710
318
|
});
|
|
711
|
-
return
|
|
319
|
+
return R(e);
|
|
712
320
|
}
|
|
713
|
-
function
|
|
714
|
-
return
|
|
321
|
+
function Tt(t, n) {
|
|
322
|
+
return Et(F(t), n);
|
|
715
323
|
}
|
|
716
|
-
function
|
|
717
|
-
if (
|
|
718
|
-
return `L ${
|
|
719
|
-
if (
|
|
720
|
-
return `A ${
|
|
324
|
+
function G(t) {
|
|
325
|
+
if (t instanceof d)
|
|
326
|
+
return `L ${t.lastPoint.join(" ")}`;
|
|
327
|
+
if (t instanceof w)
|
|
328
|
+
return `A ${t.radius} ${t.radius} 0 ${t.angularLength > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${t.lastPoint.join(" ")}`;
|
|
721
329
|
throw new Error("Unknown segment type");
|
|
722
330
|
}
|
|
723
|
-
function
|
|
724
|
-
const
|
|
725
|
-
return `${
|
|
331
|
+
function K(t) {
|
|
332
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(G).join(" ");
|
|
333
|
+
return `${n} ${e} Z`;
|
|
726
334
|
}
|
|
727
|
-
function
|
|
728
|
-
return `<path d="${
|
|
335
|
+
function Q(t) {
|
|
336
|
+
return `<path d="${t.allLoops.map(K).join(" ")}" />`;
|
|
729
337
|
}
|
|
730
|
-
function
|
|
338
|
+
function yt(t) {
|
|
731
339
|
return `<g>
|
|
732
|
-
${
|
|
340
|
+
${t.figures.map(Q).join(`
|
|
733
341
|
`)}
|
|
734
342
|
</g>`;
|
|
735
343
|
}
|
|
736
|
-
function
|
|
737
|
-
const
|
|
738
|
-
return `${
|
|
344
|
+
function bt(t) {
|
|
345
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(G).join(" ");
|
|
346
|
+
return `${n} ${e}`;
|
|
347
|
+
}
|
|
348
|
+
function Dt(t, n = 1) {
|
|
349
|
+
const e = t.xMin - n, r = t.yMin - n;
|
|
350
|
+
return `${e} ${r} ${t.width + 2 * n} ${t.height + 2 * n}`;
|
|
739
351
|
}
|
|
740
|
-
function
|
|
352
|
+
function B(t, n, e = 1) {
|
|
741
353
|
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
742
|
-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${
|
|
743
|
-
${
|
|
354
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${Dt(n, e)}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke">
|
|
355
|
+
${t}
|
|
744
356
|
</svg>`;
|
|
745
357
|
}
|
|
746
|
-
function
|
|
747
|
-
if (
|
|
748
|
-
return
|
|
749
|
-
if (
|
|
750
|
-
return
|
|
751
|
-
if (
|
|
752
|
-
return `<path d="${
|
|
753
|
-
if (
|
|
754
|
-
return `<path d="${
|
|
755
|
-
|
|
358
|
+
function J(t) {
|
|
359
|
+
if (t instanceof P)
|
|
360
|
+
return yt(t);
|
|
361
|
+
if (t instanceof h)
|
|
362
|
+
return Q(t);
|
|
363
|
+
if (t instanceof $)
|
|
364
|
+
return `<path d="${K(t)}" />`;
|
|
365
|
+
if (t instanceof ht)
|
|
366
|
+
return `<path d="${bt(t)}" />`;
|
|
367
|
+
if (t instanceof w || t instanceof d)
|
|
368
|
+
return `<path d="${`M ${t.firstPoint.join(" ")}`} ${G(
|
|
369
|
+
t
|
|
756
370
|
)}" />`;
|
|
757
371
|
throw new Error("Unknown shape type");
|
|
758
372
|
}
|
|
759
|
-
|
|
760
|
-
if (
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
373
|
+
const W = (t) => "shape" in t ? t.shape : t, X = (t, n) => {
|
|
374
|
+
if (!("shape" in t))
|
|
375
|
+
return n;
|
|
376
|
+
const { color: e } = t;
|
|
377
|
+
return e ? `<g stroke="${e}">${n}</g>` : n;
|
|
378
|
+
};
|
|
379
|
+
function Rt(t, n = 1) {
|
|
380
|
+
if (Array.isArray(t)) {
|
|
381
|
+
const r = t.map((a) => W(a).mirror()), o = r.map((a, u) => X(t[u], J(a))).join(`
|
|
382
|
+
`), s = r.slice(1).reduce((a, u) => a.merge(u.boundingBox), r[0].boundingBox);
|
|
383
|
+
return B(o, s);
|
|
384
|
+
}
|
|
385
|
+
const e = W(t).mirror();
|
|
386
|
+
return B(
|
|
387
|
+
X(t, J(e)),
|
|
388
|
+
e.boundingBox,
|
|
389
|
+
n
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
const _ = (t) => {
|
|
393
|
+
if (t.type === "LINE")
|
|
394
|
+
return new d(t.firstPoint, t.lastPoint);
|
|
395
|
+
if (t.type === "ARC")
|
|
396
|
+
return new w(
|
|
397
|
+
t.firstPoint,
|
|
398
|
+
t.lastPoint,
|
|
399
|
+
t.center,
|
|
400
|
+
t.clockwise
|
|
777
401
|
);
|
|
778
402
|
throw new Error("Unknown segment type");
|
|
779
|
-
},
|
|
780
|
-
const
|
|
781
|
-
return new
|
|
782
|
-
},
|
|
783
|
-
const
|
|
784
|
-
return new
|
|
785
|
-
},
|
|
786
|
-
const
|
|
787
|
-
return new P(
|
|
403
|
+
}, k = (t) => {
|
|
404
|
+
const n = t.segments.map(_);
|
|
405
|
+
return new $(n);
|
|
406
|
+
}, j = (t) => {
|
|
407
|
+
const n = k(t.contour), e = t.holes.map(k);
|
|
408
|
+
return new h(n, e);
|
|
409
|
+
}, It = (t) => {
|
|
410
|
+
const n = t.figures.map(j);
|
|
411
|
+
return new P(n);
|
|
788
412
|
};
|
|
789
|
-
function
|
|
790
|
-
if (
|
|
791
|
-
return
|
|
792
|
-
if (
|
|
793
|
-
return
|
|
794
|
-
if (
|
|
795
|
-
return
|
|
796
|
-
if (
|
|
797
|
-
return
|
|
413
|
+
function Ut(t) {
|
|
414
|
+
if (t.type === "DIAGRAM")
|
|
415
|
+
return It(t);
|
|
416
|
+
if (t.type === "FIGURE")
|
|
417
|
+
return j(t);
|
|
418
|
+
if (t.type === "LOOP")
|
|
419
|
+
return k(t);
|
|
420
|
+
if (t.type === "LINE" || t.type === "ARC")
|
|
421
|
+
return _(t);
|
|
798
422
|
throw new Error("Unknown shape type");
|
|
799
423
|
}
|
|
800
|
-
const
|
|
801
|
-
function
|
|
802
|
-
const e = Math.cos(
|
|
803
|
-
return [e,
|
|
424
|
+
const Y = Math.PI / 180, kt = 180 / Math.PI;
|
|
425
|
+
function Nt(t, n) {
|
|
426
|
+
const e = Math.cos(n * Y) * t, r = Math.sin(n * Y) * t;
|
|
427
|
+
return [e, r];
|
|
804
428
|
}
|
|
805
|
-
function
|
|
806
|
-
const e = Math.sqrt(
|
|
807
|
-
return [e,
|
|
429
|
+
function zt([t, n]) {
|
|
430
|
+
const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) * kt;
|
|
431
|
+
return [e, r];
|
|
808
432
|
}
|
|
809
433
|
export {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
434
|
+
Y as DEG2RAD,
|
|
435
|
+
kt as RAD2DEG,
|
|
436
|
+
zt as cartesianToPolar,
|
|
437
|
+
Vt as confineStrand,
|
|
438
|
+
Mt as cut,
|
|
439
|
+
Jt as draw,
|
|
440
|
+
Gt as eraseStrand,
|
|
441
|
+
Xt as exportJSON,
|
|
442
|
+
Rt as exportSVG,
|
|
443
|
+
St as fuse,
|
|
444
|
+
R as fuseAll,
|
|
445
|
+
Ut as importJSON,
|
|
446
|
+
xt as intersect,
|
|
447
|
+
Tt as offset,
|
|
448
|
+
Nt as polarToCartesian,
|
|
449
|
+
J as svgBody
|
|
824
450
|
};
|
|
825
451
|
//# sourceMappingURL=pantograph.js.map
|