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