pantograph2d 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exportJSON-944c662d.cjs +4 -0
- package/dist/exportJSON-944c662d.cjs.map +1 -0
- package/dist/{exportJSON-b3e1c256.js → exportJSON-c42ca4ac.js} +436 -397
- package/dist/exportJSON-c42ca4ac.js.map +1 -0
- package/dist/models.d.ts +4 -0
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +3 -3
- package/dist/pantograph.cjs +6 -6
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.d.ts +13 -1
- package/dist/pantograph.js +698 -159
- package/dist/pantograph.js.map +1 -1
- package/package.json +7 -2
- package/dist/exportJSON-b3e1c256.js.map +0 -1
- package/dist/exportJSON-d9965e73.cjs +0 -4
- package/dist/exportJSON-d9965e73.cjs.map +0 -1
package/dist/pantograph.js
CHANGED
|
@@ -1,20 +1,90 @@
|
|
|
1
|
-
import { s as v,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { L as A, A as y, a as F, s as v, p as $, t as nt, c as et, f as ut, b as pt, d as _, e as dt, g as S, h as L, T as gt, D as P, F as b, i as I, j as Y, k as R, l as mt, m as wt, n as Pt, o as At, q as xt, r as yt, u as it, v as _t, w as St, x as st, y as Ft } from "./exportJSON-c42ca4ac.js";
|
|
2
|
+
import { z as tn } from "./exportJSON-c42ca4ac.js";
|
|
3
|
+
class T {
|
|
4
|
+
constructor(t, e) {
|
|
5
|
+
this.firstPoint = t, this.lastPoint = e;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function D(n, t) {
|
|
9
|
+
if (n instanceof A)
|
|
10
|
+
return vt(n, t);
|
|
11
|
+
if (n instanceof y)
|
|
12
|
+
return bt(n, t);
|
|
13
|
+
throw new Error("Not implemented");
|
|
14
|
+
}
|
|
15
|
+
function vt(n, t) {
|
|
16
|
+
const { firstPoint: e, lastPoint: i } = n, r = n.normalVector;
|
|
17
|
+
return new A(
|
|
18
|
+
F(e, v(r, t)),
|
|
19
|
+
F(i, v(r, t))
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function bt(n, t) {
|
|
23
|
+
const e = F(
|
|
24
|
+
n.firstPoint,
|
|
25
|
+
v($(n.tangentAtFirstPoint), t)
|
|
26
|
+
), i = F(
|
|
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
|
|
36
|
+
);
|
|
37
|
+
if (Math.abs(i) < 1e-10)
|
|
38
|
+
return null;
|
|
39
|
+
const r = i > 0 ? 1 : -1, s = Math.abs(e) * r, o = D(n, s), a = D(t, s);
|
|
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
|
|
10
69
|
];
|
|
11
70
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
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];
|
|
14
81
|
}
|
|
15
|
-
|
|
82
|
+
function X(n) {
|
|
83
|
+
return new P([new b(new I(n))]);
|
|
84
|
+
}
|
|
85
|
+
class Et {
|
|
16
86
|
constructor(t = [0, 0]) {
|
|
17
|
-
this.pointer = t, this.firstPoint = t, this.pendingSegments = [];
|
|
87
|
+
this.pointer = t, this.firstPoint = t, this.pendingSegments = [], this._nextCorner = null;
|
|
18
88
|
}
|
|
19
89
|
movePointerTo(t) {
|
|
20
90
|
if (this.pendingSegments.length)
|
|
@@ -24,16 +94,24 @@ class N {
|
|
|
24
94
|
return this.pointer = t, this.firstPoint = t, this;
|
|
25
95
|
}
|
|
26
96
|
saveSegment(t) {
|
|
27
|
-
if (
|
|
97
|
+
if (_(t.firstPoint, t.lastPoint))
|
|
28
98
|
throw new Error(`Segment has no length, ${t.repr}`);
|
|
29
|
-
|
|
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;
|
|
30
108
|
}
|
|
31
109
|
lineTo(t) {
|
|
32
|
-
const
|
|
33
|
-
return this.pointer = t, this.saveSegment(
|
|
110
|
+
const e = new A(this.pointer, t);
|
|
111
|
+
return this.pointer = t, this.saveSegment(e);
|
|
34
112
|
}
|
|
35
|
-
line(t,
|
|
36
|
-
return this.lineTo([this.pointer[0] + t, this.pointer[1] +
|
|
113
|
+
line(t, e) {
|
|
114
|
+
return this.lineTo([this.pointer[0] + t, this.pointer[1] + e]);
|
|
37
115
|
}
|
|
38
116
|
vLine(t) {
|
|
39
117
|
return this.line(0, t);
|
|
@@ -47,240 +125,701 @@ class N {
|
|
|
47
125
|
hLineTo(t) {
|
|
48
126
|
return this.lineTo([t, this.pointer[1]]);
|
|
49
127
|
}
|
|
50
|
-
polarLineTo([t,
|
|
51
|
-
const
|
|
52
|
-
return this.lineTo(
|
|
128
|
+
polarLineTo([t, e]) {
|
|
129
|
+
const i = e * R, r = Y(t, i);
|
|
130
|
+
return this.lineTo(r);
|
|
53
131
|
}
|
|
54
|
-
polarLine(t,
|
|
55
|
-
const
|
|
56
|
-
return this.line(
|
|
132
|
+
polarLine(t, e) {
|
|
133
|
+
const i = e * R, [r, s] = Y(t, i);
|
|
134
|
+
return this.line(r, s);
|
|
57
135
|
}
|
|
58
136
|
tangentLine(t) {
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
137
|
+
const e = this.pendingSegments.at(-1);
|
|
138
|
+
if (!e)
|
|
61
139
|
throw new Error("You need a previous segment to sketch a tangent line");
|
|
62
|
-
const [
|
|
63
|
-
return this.line(
|
|
140
|
+
const [i, r] = e.tangentAtLastPoint;
|
|
141
|
+
return this.line(i * t, r * t);
|
|
64
142
|
}
|
|
65
|
-
threePointsArcTo(t,
|
|
66
|
-
return this.saveSegment(
|
|
143
|
+
threePointsArcTo(t, e) {
|
|
144
|
+
return this.saveSegment(dt(this.pointer, e, t)), this.pointer = t, this;
|
|
67
145
|
}
|
|
68
|
-
threePointsArc(t,
|
|
69
|
-
const [
|
|
146
|
+
threePointsArc(t, e, i, r) {
|
|
147
|
+
const [s, o] = this.pointer;
|
|
70
148
|
return this.threePointsArcTo(
|
|
71
|
-
[
|
|
72
|
-
[
|
|
149
|
+
[s + t, o + e],
|
|
150
|
+
[s + i, o + r]
|
|
73
151
|
);
|
|
74
152
|
}
|
|
75
|
-
sagittaArcTo(t,
|
|
76
|
-
if (!
|
|
153
|
+
sagittaArcTo(t, e) {
|
|
154
|
+
if (!e)
|
|
77
155
|
return this.lineTo(t);
|
|
78
|
-
const
|
|
79
|
-
return this.threePointsArcTo(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);
|
|
80
158
|
}
|
|
81
|
-
sagittaArc(t,
|
|
159
|
+
sagittaArc(t, e, i) {
|
|
82
160
|
return this.sagittaArcTo(
|
|
83
|
-
[t + this.pointer[0],
|
|
84
|
-
|
|
161
|
+
[t + this.pointer[0], e + this.pointer[1]],
|
|
162
|
+
i
|
|
85
163
|
);
|
|
86
164
|
}
|
|
87
|
-
vSagittaArc(t,
|
|
88
|
-
return this.sagittaArc(0, t,
|
|
165
|
+
vSagittaArc(t, e) {
|
|
166
|
+
return this.sagittaArc(0, t, e);
|
|
89
167
|
}
|
|
90
|
-
hSagittaArc(t,
|
|
91
|
-
return this.sagittaArc(t, 0,
|
|
168
|
+
hSagittaArc(t, e) {
|
|
169
|
+
return this.sagittaArc(t, 0, e);
|
|
92
170
|
}
|
|
93
|
-
bulgeArcTo(t,
|
|
94
|
-
if (!
|
|
171
|
+
bulgeArcTo(t, e) {
|
|
172
|
+
if (!e)
|
|
95
173
|
return this.lineTo(t);
|
|
96
|
-
const
|
|
97
|
-
return this.sagittaArcTo(t,
|
|
174
|
+
const i = S(this.pointer, t) / 2, r = -e * i;
|
|
175
|
+
return this.sagittaArcTo(t, r);
|
|
98
176
|
}
|
|
99
|
-
bulgeArc(t,
|
|
177
|
+
bulgeArc(t, e, i) {
|
|
100
178
|
return this.bulgeArcTo(
|
|
101
|
-
[t + this.pointer[0],
|
|
102
|
-
|
|
179
|
+
[t + this.pointer[0], e + this.pointer[1]],
|
|
180
|
+
i
|
|
103
181
|
);
|
|
104
182
|
}
|
|
105
|
-
vBulgeArc(t,
|
|
106
|
-
return this.bulgeArc(0, t,
|
|
183
|
+
vBulgeArc(t, e) {
|
|
184
|
+
return this.bulgeArc(0, t, e);
|
|
107
185
|
}
|
|
108
|
-
hBulgeArc(t,
|
|
109
|
-
return this.bulgeArc(t, 0,
|
|
186
|
+
hBulgeArc(t, e) {
|
|
187
|
+
return this.bulgeArc(t, 0, e);
|
|
110
188
|
}
|
|
111
189
|
tangentArcTo(t) {
|
|
112
|
-
const
|
|
113
|
-
if (!
|
|
190
|
+
const e = this.pendingSegments.at(-1);
|
|
191
|
+
if (!e)
|
|
114
192
|
throw new Error("You need a previous curve to sketch a tangent arc");
|
|
115
193
|
return this.saveSegment(
|
|
116
|
-
|
|
194
|
+
nt(this.pointer, t, e.tangentAtLastPoint)
|
|
117
195
|
), this.pointer = t, this;
|
|
118
196
|
}
|
|
119
|
-
tangentArc(t,
|
|
120
|
-
const [
|
|
121
|
-
return this.tangentArcTo([t +
|
|
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));
|
|
122
214
|
}
|
|
123
215
|
close() {
|
|
124
|
-
|
|
125
|
-
|
|
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);
|
|
126
223
|
}
|
|
127
224
|
closeWithMirror() {
|
|
128
225
|
if (!this.pendingSegments.length)
|
|
129
226
|
throw new Error("No segments to close");
|
|
130
|
-
const t = this.pendingSegments[0],
|
|
131
|
-
|
|
227
|
+
const t = this.pendingSegments[0], e = this.pendingSegments.at(-1), i = L(
|
|
228
|
+
e.lastPoint,
|
|
132
229
|
t.firstPoint
|
|
133
|
-
),
|
|
134
|
-
|
|
230
|
+
), r = new gt().mirrorLine(
|
|
231
|
+
i,
|
|
135
232
|
t.firstPoint
|
|
136
|
-
),
|
|
137
|
-
(
|
|
233
|
+
), s = this.pendingSegments.map(
|
|
234
|
+
(o) => o.transform(r).reverse()
|
|
138
235
|
);
|
|
139
|
-
return
|
|
236
|
+
return s.reverse(), X([
|
|
140
237
|
...this.pendingSegments,
|
|
141
|
-
...
|
|
238
|
+
...s
|
|
142
239
|
]);
|
|
143
240
|
}
|
|
144
241
|
}
|
|
145
|
-
function
|
|
146
|
-
return new
|
|
242
|
+
function qt(n = [0, 0]) {
|
|
243
|
+
return new Et(n);
|
|
147
244
|
}
|
|
148
|
-
function
|
|
149
|
-
if (n instanceof
|
|
245
|
+
function E(n) {
|
|
246
|
+
if (n instanceof b)
|
|
150
247
|
return [n];
|
|
151
|
-
if (n instanceof
|
|
152
|
-
return [new
|
|
153
|
-
if (n instanceof
|
|
248
|
+
if (n instanceof I)
|
|
249
|
+
return [new b(n)];
|
|
250
|
+
if (n instanceof P)
|
|
154
251
|
return n.figures;
|
|
155
252
|
throw new Error("Unknown shape");
|
|
156
253
|
}
|
|
157
|
-
function
|
|
158
|
-
return new
|
|
159
|
-
|
|
254
|
+
function Mt(n, t) {
|
|
255
|
+
return new P(
|
|
256
|
+
mt(E(n), E(t))
|
|
160
257
|
);
|
|
161
258
|
}
|
|
162
|
-
function
|
|
259
|
+
function G(n) {
|
|
163
260
|
return n.reduce(
|
|
164
|
-
(t,
|
|
165
|
-
new
|
|
261
|
+
(t, e) => Mt(t, e),
|
|
262
|
+
new P()
|
|
166
263
|
);
|
|
167
264
|
}
|
|
168
|
-
function
|
|
169
|
-
return new
|
|
170
|
-
|
|
265
|
+
function Tt(n, t) {
|
|
266
|
+
return new P(
|
|
267
|
+
wt(E(n), E(t))
|
|
171
268
|
);
|
|
172
269
|
}
|
|
173
|
-
function
|
|
174
|
-
return new
|
|
175
|
-
|
|
270
|
+
function zt(n, t) {
|
|
271
|
+
return new P(
|
|
272
|
+
Pt(E(n), E(t))
|
|
176
273
|
);
|
|
177
274
|
}
|
|
178
|
-
function
|
|
179
|
-
|
|
275
|
+
function q(n) {
|
|
276
|
+
return n < 0 ? "before" : n > 1 ? "after" : "between";
|
|
277
|
+
}
|
|
278
|
+
const z = (n, t, e) => {
|
|
279
|
+
if (e === "before")
|
|
280
|
+
return n.distanceFrom(t.firstPoint);
|
|
281
|
+
if (e === "after")
|
|
282
|
+
return n.distanceFrom(t.lastPoint);
|
|
283
|
+
throw new Error("Invalid position");
|
|
284
|
+
};
|
|
285
|
+
function It(n, t) {
|
|
286
|
+
const e = At(n, t);
|
|
287
|
+
if (e === "parallel")
|
|
288
|
+
return Math.min(
|
|
289
|
+
n.distanceFrom(t.firstPoint),
|
|
290
|
+
n.distanceFrom(t.lastPoint)
|
|
291
|
+
);
|
|
292
|
+
const { intersectionParam1: i, intersectionParam2: r } = e, s = q(i), o = q(r);
|
|
293
|
+
if (s === "between" && o === "between")
|
|
294
|
+
return 0;
|
|
295
|
+
if (s === "between" && o !== "between")
|
|
296
|
+
return z(n, t, o);
|
|
297
|
+
if (o === "between" && s !== "between")
|
|
298
|
+
return z(t, n, s);
|
|
299
|
+
if (s === "before" && o === "before")
|
|
300
|
+
return S(n.firstPoint, t.firstPoint);
|
|
301
|
+
if (s === "after" && o === "after")
|
|
302
|
+
return S(n.lastPoint, t.lastPoint);
|
|
303
|
+
if (s === "before" && o === "after")
|
|
304
|
+
return S(n.firstPoint, t.lastPoint);
|
|
305
|
+
if (s === "after" && o === "before")
|
|
306
|
+
return S(n.lastPoint, t.firstPoint);
|
|
307
|
+
throw new Error("Invalid position");
|
|
308
|
+
}
|
|
309
|
+
function W(n, t) {
|
|
310
|
+
if (xt(n, t).length > 0)
|
|
311
|
+
return 0;
|
|
312
|
+
const e = yt(n, t.center);
|
|
313
|
+
if (n.isOnSegment(e)) {
|
|
314
|
+
const i = S(e, t.center);
|
|
315
|
+
if (Math.abs(i - t.radius) < n.precision && t.isOnSegment(e))
|
|
316
|
+
return 0;
|
|
317
|
+
if (i - t.radius > n.precision) {
|
|
318
|
+
const r = it(
|
|
319
|
+
L(e, t.center)
|
|
320
|
+
), s = F(
|
|
321
|
+
t.center,
|
|
322
|
+
v(r, t.radius)
|
|
323
|
+
);
|
|
324
|
+
if (t.isOnSegment(s))
|
|
325
|
+
return S(s, e);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return Math.min(
|
|
329
|
+
t.distanceFrom(n.firstPoint),
|
|
330
|
+
t.distanceFrom(n.lastPoint),
|
|
331
|
+
n.distanceFrom(t.firstPoint),
|
|
332
|
+
n.distanceFrom(t.lastPoint)
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
const Lt = (n, t) => {
|
|
336
|
+
const e = n.angleToParam(t.firstAngle);
|
|
337
|
+
if (n.isValidParameter(e))
|
|
338
|
+
return !0;
|
|
339
|
+
const i = n.angleToParam(t.lastAngle);
|
|
340
|
+
return !!n.isValidParameter(i);
|
|
341
|
+
};
|
|
342
|
+
function Ct(n, t) {
|
|
343
|
+
if (_t(n, t, !0).length > 0)
|
|
344
|
+
return 0;
|
|
345
|
+
const e = S(n.center, t.center);
|
|
346
|
+
if (e < n.precision && Lt(n, t))
|
|
347
|
+
return Math.abs(n.radius - t.radius);
|
|
348
|
+
const i = it(L(t.center, n.center)), r = e - Math.abs(n.radius - t.radius) < n.precision;
|
|
349
|
+
let s = St(i);
|
|
350
|
+
r && t.radius > n.radius && (s += Math.PI);
|
|
351
|
+
const o = r ? s : s + Math.PI, a = n.angleToParam(s), h = t.angleToParam(o);
|
|
352
|
+
return n.isValidParameter(a) && t.isValidParameter(h) ? S(n.paramPoint(a), t.paramPoint(h)) : Math.min(
|
|
353
|
+
n.distanceFrom(t.firstPoint),
|
|
354
|
+
n.distanceFrom(t.lastPoint),
|
|
355
|
+
t.distanceFrom(n.firstPoint),
|
|
356
|
+
t.distanceFrom(n.lastPoint)
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
function $t(n, t) {
|
|
360
|
+
if (n instanceof A && t instanceof A)
|
|
361
|
+
return It(n, t);
|
|
362
|
+
if (n instanceof A && t instanceof y)
|
|
363
|
+
return W(n, t);
|
|
364
|
+
if (n instanceof y && t instanceof A)
|
|
365
|
+
return W(t, n);
|
|
366
|
+
if (n instanceof y && t instanceof y)
|
|
367
|
+
return Ct(n, t);
|
|
368
|
+
throw new Error("Not implemented");
|
|
369
|
+
}
|
|
370
|
+
class Dt {
|
|
371
|
+
constructor() {
|
|
372
|
+
this.ids = [], this.values = [], this.length = 0;
|
|
373
|
+
}
|
|
374
|
+
clear() {
|
|
375
|
+
this.length = 0;
|
|
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);
|
|
610
|
+
if (!s)
|
|
611
|
+
return [];
|
|
612
|
+
if (i.length === 1)
|
|
613
|
+
return i;
|
|
614
|
+
const o = (h) => {
|
|
615
|
+
r ? h.offset instanceof T ? _(h.offset.firstPoint, h.offset.lastPoint) || i.push(
|
|
616
|
+
new A(h.offset.firstPoint, h.offset.lastPoint)
|
|
617
|
+
) : i.push(h.offset) : r = h;
|
|
618
|
+
}, a = function* () {
|
|
619
|
+
for (const h of e.slice(0, -1))
|
|
620
|
+
yield h;
|
|
621
|
+
if (!r)
|
|
622
|
+
throw new Error("Bug in the offset algorithm");
|
|
623
|
+
yield r;
|
|
624
|
+
};
|
|
625
|
+
for (const h of a()) {
|
|
626
|
+
const l = s.offset.lastPoint, c = h.offset.firstPoint;
|
|
627
|
+
if (_(l, c)) {
|
|
628
|
+
o(s), s = h;
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
let f = [];
|
|
632
|
+
if (!(s.offset instanceof T) && !(h.offset instanceof T)) {
|
|
633
|
+
const { intersections: m, overlaps: x } = st(
|
|
634
|
+
s.offset,
|
|
635
|
+
h.offset,
|
|
636
|
+
B / 100
|
|
637
|
+
);
|
|
638
|
+
f = [
|
|
639
|
+
...m,
|
|
640
|
+
...x.flatMap((d) => [d.firstPoint, d.lastPoint])
|
|
641
|
+
];
|
|
642
|
+
}
|
|
643
|
+
if (f.length > 0) {
|
|
644
|
+
let m = f[0];
|
|
645
|
+
if (f.length > 1) {
|
|
646
|
+
const w = s == null ? void 0 : s.original.lastPoint, M = f.map(
|
|
647
|
+
(lt) => Ft(lt, w)
|
|
648
|
+
);
|
|
649
|
+
m = f[M.indexOf(Math.min(...M))];
|
|
650
|
+
}
|
|
651
|
+
const x = s.offset.splitAt([
|
|
652
|
+
m
|
|
653
|
+
])[0], d = h.offset.splitAt([m]).at(-1);
|
|
654
|
+
if (!d)
|
|
655
|
+
throw new Error("Bug in the splitting algo in offset");
|
|
656
|
+
o({
|
|
657
|
+
offset: x,
|
|
658
|
+
original: s.original
|
|
659
|
+
}), s = { offset: d, original: h.original };
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
const u = s.original.lastPoint, p = et(
|
|
663
|
+
L(c, u),
|
|
664
|
+
L(l, u)
|
|
665
|
+
) > 0, g = new y(l, c, u, p);
|
|
666
|
+
o(s), i.push(g), s = h;
|
|
667
|
+
}
|
|
668
|
+
return o(s), i;
|
|
669
|
+
}
|
|
670
|
+
function H(n, t) {
|
|
671
|
+
const e = n.clockwise ? t : -t, i = Ut(n.segments, e);
|
|
672
|
+
if (i.length < 2)
|
|
673
|
+
return new P();
|
|
674
|
+
const r = /* @__PURE__ */ new Map(), s = (c, f) => {
|
|
675
|
+
const u = r.get(c) || [];
|
|
676
|
+
r.set(c, [...u, ...f]);
|
|
677
|
+
};
|
|
678
|
+
if (i.forEach((c, f) => {
|
|
679
|
+
i.slice(f + 1).forEach((u, p) => {
|
|
680
|
+
const { intersections: g, overlaps: m } = st(c, u, B), x = [
|
|
681
|
+
...g,
|
|
682
|
+
...m.flatMap((d) => [d.firstPoint, d.lastPoint])
|
|
683
|
+
].filter((d) => {
|
|
684
|
+
const w = _(d, c.firstPoint) || _(d, c.lastPoint), M = _(d, u.firstPoint) || _(d, u.lastPoint);
|
|
685
|
+
return !(w && M);
|
|
686
|
+
});
|
|
687
|
+
x.length && (s(f, x), s(p + f + 1, x));
|
|
688
|
+
});
|
|
689
|
+
}), !r.size) {
|
|
690
|
+
const c = new I(i);
|
|
691
|
+
return new P([new b(c)]);
|
|
692
|
+
}
|
|
693
|
+
const a = i.flatMap((c, f) => {
|
|
694
|
+
if (!r.has(f))
|
|
695
|
+
return c;
|
|
696
|
+
const u = r.get(f) || [];
|
|
697
|
+
return c.splitAt(u);
|
|
698
|
+
}).filter((c) => !n.segments.some((u) => $t(u, c) < Math.abs(t) - B));
|
|
699
|
+
if (!a.length)
|
|
700
|
+
return new P();
|
|
701
|
+
const l = Ot(a).filter((c) => c.length > 1).filter((c) => _(c[0].firstPoint, c.at(-1).lastPoint)).map((c) => new I(c));
|
|
702
|
+
return l.length ? new P(l.map((c) => new b(c))) : new P();
|
|
703
|
+
}
|
|
704
|
+
function Yt(n, t) {
|
|
705
|
+
const e = n.map((i) => {
|
|
706
|
+
const r = G(
|
|
707
|
+
i.holes.map((s) => H(s, t))
|
|
708
|
+
);
|
|
709
|
+
return Tt(H(i.contour, t), r);
|
|
710
|
+
});
|
|
711
|
+
return G(e);
|
|
712
|
+
}
|
|
713
|
+
function Wt(n, t) {
|
|
714
|
+
return Yt(E(n), t);
|
|
715
|
+
}
|
|
716
|
+
function ot(n) {
|
|
717
|
+
if (n instanceof A)
|
|
180
718
|
return `L ${n.lastPoint.join(" ")}`;
|
|
181
|
-
if (n instanceof
|
|
719
|
+
if (n instanceof y)
|
|
182
720
|
return `A ${n.radius} ${n.radius} 0 ${n.angularLength > Math.PI ? "1" : "0"} ${n.clockwise ? "0" : "1"} ${n.lastPoint.join(" ")}`;
|
|
183
721
|
throw new Error("Unknown segment type");
|
|
184
722
|
}
|
|
185
|
-
function
|
|
186
|
-
const t = `M ${n.firstPoint.join(" ")}`,
|
|
187
|
-
return `${t} ${
|
|
723
|
+
function at(n) {
|
|
724
|
+
const t = `M ${n.firstPoint.join(" ")}`, e = n.segments.map(ot).join(" ");
|
|
725
|
+
return `${t} ${e} Z`;
|
|
188
726
|
}
|
|
189
|
-
function
|
|
190
|
-
return `<path d="${n.allLoops.map(
|
|
727
|
+
function ht(n) {
|
|
728
|
+
return `<path d="${n.allLoops.map(at).join(" ")}" />`;
|
|
191
729
|
}
|
|
192
|
-
function
|
|
730
|
+
function Rt(n) {
|
|
193
731
|
return `<g>
|
|
194
|
-
${n.figures.map(
|
|
732
|
+
${n.figures.map(ht).join(`
|
|
195
733
|
`)}
|
|
196
734
|
</g>`;
|
|
197
735
|
}
|
|
198
|
-
function
|
|
199
|
-
const
|
|
200
|
-
return `${
|
|
736
|
+
function Vt(n, t = 1) {
|
|
737
|
+
const e = n.xMin - t, i = n.yMin - t;
|
|
738
|
+
return `${e} ${i} ${n.width + 2 * t} ${n.height + 2 * t}`;
|
|
201
739
|
}
|
|
202
|
-
function
|
|
740
|
+
function K(n, t, e = 1) {
|
|
203
741
|
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
204
|
-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${
|
|
742
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${Vt(t, e)}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke">
|
|
205
743
|
${n}
|
|
206
744
|
</svg>`;
|
|
207
745
|
}
|
|
208
|
-
function
|
|
209
|
-
if (n instanceof
|
|
210
|
-
return
|
|
211
|
-
if (n instanceof
|
|
212
|
-
return
|
|
213
|
-
if (n instanceof
|
|
214
|
-
return `<path d="${
|
|
215
|
-
if (n instanceof
|
|
216
|
-
return `<path d="${`M ${n.firstPoint.join(" ")}`} ${
|
|
746
|
+
function j(n) {
|
|
747
|
+
if (n instanceof P)
|
|
748
|
+
return Rt(n);
|
|
749
|
+
if (n instanceof b)
|
|
750
|
+
return ht(n);
|
|
751
|
+
if (n instanceof I)
|
|
752
|
+
return `<path d="${at(n)}" />`;
|
|
753
|
+
if (n instanceof y || n instanceof A)
|
|
754
|
+
return `<path d="${`M ${n.firstPoint.join(" ")}`} ${ot(
|
|
217
755
|
n
|
|
218
756
|
)}" />`;
|
|
219
757
|
throw new Error("Unknown shape type");
|
|
220
758
|
}
|
|
221
|
-
function
|
|
759
|
+
function Jt(n, t = 1) {
|
|
222
760
|
if (Array.isArray(n)) {
|
|
223
|
-
const
|
|
224
|
-
`),
|
|
225
|
-
return
|
|
761
|
+
const i = n.map((o) => o.mirror()), r = i.map((o) => j(o)).join(`
|
|
762
|
+
`), s = i.slice(1).reduce((o, a) => o.merge(a.boundingBox), i[0].boundingBox);
|
|
763
|
+
return K(r, s);
|
|
226
764
|
}
|
|
227
|
-
const
|
|
228
|
-
return
|
|
765
|
+
const e = n.mirror();
|
|
766
|
+
return K(j(e), e.boundingBox, t);
|
|
229
767
|
}
|
|
230
|
-
const
|
|
768
|
+
const ct = (n) => {
|
|
231
769
|
if (n.type === "LINE")
|
|
232
|
-
return new
|
|
770
|
+
return new A(n.firstPoint, n.lastPoint);
|
|
233
771
|
if (n.type === "ARC")
|
|
234
|
-
return new
|
|
772
|
+
return new y(
|
|
235
773
|
n.firstPoint,
|
|
236
774
|
n.lastPoint,
|
|
237
775
|
n.center,
|
|
238
776
|
n.clockwise
|
|
239
777
|
);
|
|
240
778
|
throw new Error("Unknown segment type");
|
|
241
|
-
},
|
|
242
|
-
const t = n.segments.map(
|
|
243
|
-
return new
|
|
244
|
-
},
|
|
245
|
-
const t =
|
|
246
|
-
return new
|
|
247
|
-
},
|
|
248
|
-
const t = n.figures.map(
|
|
249
|
-
return new
|
|
779
|
+
}, O = (n) => {
|
|
780
|
+
const t = n.segments.map(ct);
|
|
781
|
+
return new I(t);
|
|
782
|
+
}, ft = (n) => {
|
|
783
|
+
const t = O(n.contour), e = n.holes.map(O);
|
|
784
|
+
return new b(t, e);
|
|
785
|
+
}, Nt = (n) => {
|
|
786
|
+
const t = n.figures.map(ft);
|
|
787
|
+
return new P(t);
|
|
250
788
|
};
|
|
251
|
-
function
|
|
789
|
+
function Qt(n) {
|
|
252
790
|
if (n.type === "DIAGRAM")
|
|
253
|
-
return
|
|
791
|
+
return Nt(n);
|
|
254
792
|
if (n.type === "FIGURE")
|
|
255
|
-
return
|
|
793
|
+
return ft(n);
|
|
256
794
|
if (n.type === "LOOP")
|
|
257
|
-
return
|
|
795
|
+
return O(n);
|
|
258
796
|
if (n.type === "LINE" || n.type === "ARC")
|
|
259
|
-
return
|
|
797
|
+
return ct(n);
|
|
260
798
|
throw new Error("Unknown shape type");
|
|
261
799
|
}
|
|
262
|
-
const
|
|
263
|
-
function
|
|
264
|
-
const
|
|
265
|
-
return [
|
|
800
|
+
const tt = Math.PI / 180, Xt = 180 / Math.PI;
|
|
801
|
+
function Zt(n, t) {
|
|
802
|
+
const e = Math.cos(t * tt) * n, i = Math.sin(t * tt) * n;
|
|
803
|
+
return [e, i];
|
|
266
804
|
}
|
|
267
|
-
function
|
|
268
|
-
const
|
|
269
|
-
return [
|
|
805
|
+
function Ht([n, t]) {
|
|
806
|
+
const e = Math.sqrt(n * n + t * t), i = Math.atan2(t, n) * Xt;
|
|
807
|
+
return [e, i];
|
|
270
808
|
}
|
|
271
809
|
export {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
810
|
+
tt as DEG2RAD,
|
|
811
|
+
Xt as RAD2DEG,
|
|
812
|
+
Ht as cartesianToPolar,
|
|
813
|
+
Tt as cut,
|
|
814
|
+
qt as draw,
|
|
815
|
+
tn as exportJSON,
|
|
816
|
+
Jt as exportSVG,
|
|
817
|
+
Mt as fuse,
|
|
818
|
+
G as fuseAll,
|
|
819
|
+
Qt as importJSON,
|
|
820
|
+
zt as intersect,
|
|
821
|
+
Wt as offset,
|
|
822
|
+
Zt as polarToCartesian,
|
|
823
|
+
j as svgBody
|
|
285
824
|
};
|
|
286
825
|
//# sourceMappingURL=pantograph.js.map
|