pantograph2d 0.3.1 → 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/{exportJSON-26bb92ef.js → Diagram-1c56996e.js} +544 -515
- 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 +5 -5
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.d.ts +13 -2
- package/dist/pantograph.js +292 -449
- package/dist/pantograph.js.map +1 -1
- package/package.json +6 -2
- package/dist/exportJSON-26bb92ef.js.map +0 -1
- package/dist/exportJSON-3b325312.cjs +0 -4
- package/dist/exportJSON-3b325312.cjs.map +0 -1
package/dist/pantograph.js
CHANGED
|
@@ -1,328 +1,169 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return Ct(t, n);
|
|
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)];
|
|
11
10
|
if (t instanceof P)
|
|
12
|
-
return
|
|
13
|
-
throw new Error("
|
|
14
|
-
}
|
|
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
|
-
);
|
|
11
|
+
return t.figures;
|
|
12
|
+
throw new Error("Unknown shape");
|
|
21
13
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
function et(t, n, e) {
|
|
33
|
-
const r = j(
|
|
34
|
-
t.tangentAtLastPoint,
|
|
35
|
-
n.tangentAtFirstPoint
|
|
36
|
-
);
|
|
37
|
-
if (Math.abs(r) < 1e-10)
|
|
38
|
-
return null;
|
|
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
|
-
return null;
|
|
42
|
-
let c;
|
|
43
|
-
try {
|
|
44
|
-
c = ct(o, u, 1e-9).at(-1);
|
|
45
|
-
} catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
if (!c)
|
|
49
|
-
return null;
|
|
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
|
-
return console.warn(
|
|
60
|
-
"Cannot fillet between segments",
|
|
61
|
-
t.repr,
|
|
62
|
-
n.repr
|
|
63
|
-
), [t, n];
|
|
64
|
-
const { first: s, second: i } = r;
|
|
65
|
-
return [
|
|
66
|
-
s,
|
|
67
|
-
Q(s.lastPoint, i.firstPoint, s.tangentAtLastPoint),
|
|
68
|
-
i
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
function G(t, n, e) {
|
|
72
|
-
const r = et(t, n, e);
|
|
73
|
-
if (!r)
|
|
74
|
-
return console.warn(
|
|
75
|
-
"Cannot chamfer between segments",
|
|
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
|
-
}
|
|
82
|
-
function N(t) {
|
|
83
|
-
return new g([new T(new M(t))]);
|
|
84
|
-
}
|
|
85
|
-
class Et {
|
|
86
|
-
constructor(n = [0, 0]) {
|
|
87
|
-
this.pointer = n, this.firstPoint = n, this.pendingSegments = [], this._nextCorner = null;
|
|
88
|
-
}
|
|
89
|
-
movePointerTo(n) {
|
|
90
|
-
if (this.pendingSegments.length)
|
|
91
|
-
throw new Error(
|
|
92
|
-
"You can only move the pointer if there is no segment defined"
|
|
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
|
|
93
23
|
);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
...r(e, n, this._nextCorner.radius)
|
|
107
|
-
), this._nextCorner = null, this;
|
|
108
|
-
}
|
|
109
|
-
lineTo(n) {
|
|
110
|
-
const e = new p(this.pointer, n);
|
|
111
|
-
return this.pointer = n, this.saveSegment(e);
|
|
112
|
-
}
|
|
113
|
-
line(n, e) {
|
|
114
|
-
return this.lineTo([this.pointer[0] + n, this.pointer[1] + e]);
|
|
115
|
-
}
|
|
116
|
-
vLine(n) {
|
|
117
|
-
return this.line(0, n);
|
|
118
|
-
}
|
|
119
|
-
hLine(n) {
|
|
120
|
-
return this.line(n, 0);
|
|
121
|
-
}
|
|
122
|
-
vLineTo(n) {
|
|
123
|
-
return this.lineTo([this.pointer[0], n]);
|
|
124
|
-
}
|
|
125
|
-
hLineTo(n) {
|
|
126
|
-
return this.lineTo([n, this.pointer[1]]);
|
|
127
|
-
}
|
|
128
|
-
polarLineTo([n, e]) {
|
|
129
|
-
const r = e * V, s = _(n, r);
|
|
130
|
-
return this.lineTo(s);
|
|
131
|
-
}
|
|
132
|
-
polarLine(n, e) {
|
|
133
|
-
const r = e * V, [s, i] = _(n, r);
|
|
134
|
-
return this.line(s, i);
|
|
135
|
-
}
|
|
136
|
-
tangentLine(n) {
|
|
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 [r, s] = e.tangentAtLastPoint;
|
|
141
|
-
return this.line(r * n, s * n);
|
|
142
|
-
}
|
|
143
|
-
threePointsArcTo(n, e) {
|
|
144
|
-
return this.saveSegment(ut(this.pointer, e, n)), this.pointer = n, this;
|
|
145
|
-
}
|
|
146
|
-
threePointsArc(n, e, r, s) {
|
|
147
|
-
const [i, o] = this.pointer;
|
|
148
|
-
return this.threePointsArcTo(
|
|
149
|
-
[i + n, o + e],
|
|
150
|
-
[i + r, o + s]
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
sagittaArcTo(n, e) {
|
|
154
|
-
if (!e)
|
|
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
|
-
}
|
|
159
|
-
sagittaArc(n, e, r) {
|
|
160
|
-
return this.sagittaArcTo(
|
|
161
|
-
[n + this.pointer[0], e + this.pointer[1]],
|
|
162
|
-
r
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
vSagittaArc(n, e) {
|
|
166
|
-
return this.sagittaArc(0, n, e);
|
|
167
|
-
}
|
|
168
|
-
hSagittaArc(n, e) {
|
|
169
|
-
return this.sagittaArc(n, 0, e);
|
|
170
|
-
}
|
|
171
|
-
bulgeArcTo(n, e) {
|
|
172
|
-
if (!e)
|
|
173
|
-
return this.lineTo(n);
|
|
174
|
-
const r = S(this.pointer, n) / 2, s = -e * r;
|
|
175
|
-
return this.sagittaArcTo(n, s);
|
|
176
|
-
}
|
|
177
|
-
bulgeArc(n, e, r) {
|
|
178
|
-
return this.bulgeArcTo(
|
|
179
|
-
[n + this.pointer[0], e + this.pointer[1]],
|
|
180
|
-
r
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
vBulgeArc(n, e) {
|
|
184
|
-
return this.bulgeArc(0, n, e);
|
|
185
|
-
}
|
|
186
|
-
hBulgeArc(n, e) {
|
|
187
|
-
return this.bulgeArc(n, 0, e);
|
|
188
|
-
}
|
|
189
|
-
tangentArcTo(n) {
|
|
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
|
-
Q(this.pointer, n, e.tangentAtLastPoint)
|
|
195
|
-
), this.pointer = n, this;
|
|
196
|
-
}
|
|
197
|
-
tangentArc(n, e) {
|
|
198
|
-
const [r, s] = this.pointer;
|
|
199
|
-
return this.tangentArcTo([n + r, e + s]);
|
|
200
|
-
}
|
|
201
|
-
customCorner(n, 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: n }, this;
|
|
205
|
-
}
|
|
206
|
-
_customCornerLastWithFirst(n, e = "fillet") {
|
|
207
|
-
if (!n)
|
|
208
|
-
return;
|
|
209
|
-
const r = this.pendingSegments.pop(), s = this.pendingSegments.shift();
|
|
210
|
-
if (!r || !s)
|
|
211
|
-
throw new Error("Not enough curves to close and fillet");
|
|
212
|
-
const i = e === "chamfer" ? G : B;
|
|
213
|
-
this.pendingSegments.push(...i(r, s, n));
|
|
214
|
-
}
|
|
215
|
-
close() {
|
|
216
|
-
if (!this.pendingSegments.length)
|
|
217
|
-
throw new Error("No segments to close");
|
|
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
|
-
this._nextCorner.radius,
|
|
221
|
-
this._nextCorner.mode
|
|
222
|
-
), this._nextCorner = null), N(this.pendingSegments);
|
|
223
|
-
}
|
|
224
|
-
closeWithMirror() {
|
|
225
|
-
if (!this.pendingSegments.length)
|
|
226
|
-
throw new Error("No segments to close");
|
|
227
|
-
const n = this.pendingSegments[0], e = this.pendingSegments.at(-1), r = $(
|
|
228
|
-
e.lastPoint,
|
|
229
|
-
n.firstPoint
|
|
230
|
-
), s = new lt().mirrorLine(
|
|
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,
|
|
231
36
|
r,
|
|
232
|
-
|
|
233
|
-
)
|
|
234
|
-
|
|
235
|
-
);
|
|
236
|
-
return i.reverse(), N([
|
|
237
|
-
...this.pendingSegments,
|
|
238
|
-
...i
|
|
239
|
-
]);
|
|
240
|
-
}
|
|
37
|
+
o
|
|
38
|
+
)
|
|
39
|
+
);
|
|
241
40
|
}
|
|
242
|
-
function
|
|
243
|
-
return
|
|
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
|
+
});
|
|
244
46
|
}
|
|
245
|
-
function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (t instanceof g)
|
|
251
|
-
return t.figures;
|
|
252
|
-
throw new Error("Unknown shape");
|
|
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
|
+
});
|
|
253
52
|
}
|
|
254
|
-
function
|
|
255
|
-
|
|
256
|
-
|
|
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)
|
|
257
60
|
);
|
|
61
|
+
return [...r, ...o];
|
|
258
62
|
}
|
|
259
|
-
function
|
|
63
|
+
function T(t, n, e = !1) {
|
|
64
|
+
let r = x(
|
|
65
|
+
t,
|
|
66
|
+
n.contour,
|
|
67
|
+
e
|
|
68
|
+
);
|
|
69
|
+
return n.holes.forEach((o) => {
|
|
70
|
+
r = r.flatMap(
|
|
71
|
+
(s) => O(s, o, e)
|
|
72
|
+
);
|
|
73
|
+
}), r;
|
|
74
|
+
}
|
|
75
|
+
function St(t, n) {
|
|
76
|
+
return new P(
|
|
77
|
+
ot(F(t), F(n))
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
function R(t) {
|
|
260
81
|
return t.reduce(
|
|
261
|
-
(n, e) =>
|
|
262
|
-
new
|
|
82
|
+
(n, e) => St(n, e),
|
|
83
|
+
new P()
|
|
263
84
|
);
|
|
264
85
|
}
|
|
265
86
|
function Mt(t, n) {
|
|
266
|
-
return new
|
|
267
|
-
|
|
87
|
+
return new P(
|
|
88
|
+
it(F(t), F(n))
|
|
268
89
|
);
|
|
269
90
|
}
|
|
270
|
-
function
|
|
271
|
-
return new
|
|
272
|
-
|
|
91
|
+
function xt(t, n) {
|
|
92
|
+
return new P(
|
|
93
|
+
ft(F(t), F(n))
|
|
273
94
|
);
|
|
274
95
|
}
|
|
275
|
-
function
|
|
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) {
|
|
276
117
|
return t < 0 ? "before" : t > 1 ? "after" : "between";
|
|
277
118
|
}
|
|
278
|
-
const
|
|
119
|
+
const N = (t, n, e) => {
|
|
279
120
|
if (e === "before")
|
|
280
121
|
return t.distanceFrom(n.firstPoint);
|
|
281
122
|
if (e === "after")
|
|
282
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
130
|
t.distanceFrom(n.firstPoint),
|
|
290
131
|
t.distanceFrom(n.lastPoint)
|
|
291
132
|
);
|
|
292
|
-
const { intersectionParam1: r, intersectionParam2:
|
|
293
|
-
if (
|
|
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 (
|
|
296
|
-
return
|
|
297
|
-
if (
|
|
298
|
-
return
|
|
299
|
-
if (
|
|
300
|
-
return
|
|
301
|
-
if (
|
|
302
|
-
return
|
|
303
|
-
if (
|
|
304
|
-
return
|
|
305
|
-
if (
|
|
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
150
|
function z(t, n) {
|
|
310
|
-
if (
|
|
151
|
+
if (ct(t, n).length > 0)
|
|
311
152
|
return 0;
|
|
312
|
-
const e =
|
|
153
|
+
const e = ut(t, n.center);
|
|
313
154
|
if (t.isOnSegment(e)) {
|
|
314
|
-
const r =
|
|
155
|
+
const r = g(e, n.center);
|
|
315
156
|
if (Math.abs(r - n.radius) < t.precision && n.isOnSegment(e))
|
|
316
157
|
return 0;
|
|
317
158
|
if (r - n.radius > t.precision) {
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
),
|
|
159
|
+
const o = Z(
|
|
160
|
+
E(e, n.center)
|
|
161
|
+
), s = lt(
|
|
321
162
|
n.center,
|
|
322
|
-
|
|
163
|
+
pt(o, n.radius)
|
|
323
164
|
);
|
|
324
|
-
if (n.isOnSegment(
|
|
325
|
-
return
|
|
165
|
+
if (n.isOnSegment(s))
|
|
166
|
+
return g(s, e);
|
|
326
167
|
}
|
|
327
168
|
}
|
|
328
169
|
return Math.min(
|
|
@@ -332,277 +173,279 @@ function z(t, n) {
|
|
|
332
173
|
t.distanceFrom(n.lastPoint)
|
|
333
174
|
);
|
|
334
175
|
}
|
|
335
|
-
const
|
|
176
|
+
const Lt = (t, n) => {
|
|
336
177
|
const e = t.angleToParam(n.firstAngle);
|
|
337
178
|
if (t.isValidParameter(e))
|
|
338
179
|
return !0;
|
|
339
180
|
const r = t.angleToParam(n.lastAngle);
|
|
340
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 < t.precision &&
|
|
186
|
+
const e = g(t.center, n.center);
|
|
187
|
+
if (e < t.precision && Lt(t, n))
|
|
347
188
|
return Math.abs(t.radius - n.radius);
|
|
348
|
-
const r =
|
|
349
|
-
let
|
|
350
|
-
|
|
351
|
-
const
|
|
352
|
-
return t.isValidParameter(u) && n.isValidParameter(
|
|
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(
|
|
353
194
|
t.distanceFrom(n.firstPoint),
|
|
354
195
|
t.distanceFrom(n.lastPoint),
|
|
355
196
|
n.distanceFrom(t.firstPoint),
|
|
356
197
|
n.distanceFrom(t.lastPoint)
|
|
357
198
|
);
|
|
358
199
|
}
|
|
359
|
-
function
|
|
360
|
-
if (t instanceof
|
|
361
|
-
return
|
|
362
|
-
if (t instanceof
|
|
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)
|
|
363
204
|
return z(t, n);
|
|
364
|
-
if (t instanceof
|
|
205
|
+
if (t instanceof w && n instanceof d)
|
|
365
206
|
return z(n, t);
|
|
366
|
-
if (t instanceof
|
|
367
|
-
return
|
|
207
|
+
if (t instanceof w && n instanceof w)
|
|
208
|
+
return $t(t, n);
|
|
368
209
|
throw new Error("Not implemented");
|
|
369
210
|
}
|
|
370
211
|
const I = 1e-8;
|
|
371
|
-
function
|
|
372
|
-
const e = t.map((
|
|
373
|
-
offset:
|
|
374
|
-
original:
|
|
212
|
+
function vt(t, n) {
|
|
213
|
+
const e = t.map((i) => ({
|
|
214
|
+
offset: nt(i, n),
|
|
215
|
+
original: i
|
|
375
216
|
})), r = [];
|
|
376
|
-
let
|
|
377
|
-
if (!
|
|
217
|
+
let o = null, s = e.at(-1);
|
|
218
|
+
if (!s)
|
|
378
219
|
return [];
|
|
379
220
|
if (r.length === 1)
|
|
380
221
|
return r;
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
new
|
|
384
|
-
) : r.push(
|
|
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;
|
|
385
226
|
}, u = function* () {
|
|
386
|
-
for (const
|
|
387
|
-
yield
|
|
388
|
-
if (!
|
|
227
|
+
for (const i of e.slice(0, -1))
|
|
228
|
+
yield i;
|
|
229
|
+
if (!o)
|
|
389
230
|
throw new Error("Bug in the offset algorithm");
|
|
390
|
-
yield
|
|
231
|
+
yield o;
|
|
391
232
|
};
|
|
392
|
-
for (const
|
|
393
|
-
const m =
|
|
394
|
-
if (
|
|
395
|
-
|
|
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;
|
|
396
237
|
continue;
|
|
397
238
|
}
|
|
398
|
-
let
|
|
399
|
-
if (!(
|
|
400
|
-
const { intersections:
|
|
239
|
+
let c = [];
|
|
240
|
+
if (!(s.offset instanceof D) && !(i.offset instanceof D)) {
|
|
241
|
+
const { intersections: M, overlaps: A } = C(
|
|
242
|
+
s.offset,
|
|
401
243
|
i.offset,
|
|
402
|
-
c.offset,
|
|
403
244
|
I / 100
|
|
404
245
|
);
|
|
405
|
-
|
|
406
|
-
...
|
|
407
|
-
...
|
|
246
|
+
c = [
|
|
247
|
+
...M,
|
|
248
|
+
...A.flatMap((p) => [p.firstPoint, p.lastPoint])
|
|
408
249
|
];
|
|
409
250
|
}
|
|
410
|
-
if (
|
|
411
|
-
let
|
|
412
|
-
if (
|
|
413
|
-
const
|
|
414
|
-
(
|
|
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)
|
|
415
256
|
);
|
|
416
|
-
|
|
257
|
+
M = c[v.indexOf(Math.min(...v))];
|
|
417
258
|
}
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
])[0],
|
|
421
|
-
if (!
|
|
259
|
+
const A = s.offset.splitAt([
|
|
260
|
+
M
|
|
261
|
+
])[0], p = i.offset.splitAt([M]).at(-1);
|
|
262
|
+
if (!p)
|
|
422
263
|
throw new Error("Bug in the splitting algo in offset");
|
|
423
|
-
|
|
424
|
-
offset:
|
|
425
|
-
original:
|
|
426
|
-
}),
|
|
264
|
+
a({
|
|
265
|
+
offset: A,
|
|
266
|
+
original: s.original
|
|
267
|
+
}), s = { offset: p, original: i.original };
|
|
427
268
|
continue;
|
|
428
269
|
}
|
|
429
|
-
const l =
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
) > 0,
|
|
433
|
-
|
|
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;
|
|
434
275
|
}
|
|
435
|
-
return
|
|
276
|
+
return a(s), r;
|
|
436
277
|
}
|
|
437
|
-
function
|
|
438
|
-
const e = t.clockwise ? n : -n, r =
|
|
278
|
+
function q(t, n) {
|
|
279
|
+
const e = t.clockwise ? n : -n, r = vt(t.segments, e);
|
|
439
280
|
if (r.length < 2)
|
|
440
|
-
return new
|
|
441
|
-
const
|
|
442
|
-
const l =
|
|
443
|
-
|
|
281
|
+
return new P();
|
|
282
|
+
const o = /* @__PURE__ */ new Map(), s = (f, c) => {
|
|
283
|
+
const l = o.get(f) || [];
|
|
284
|
+
o.set(f, [...l, ...c]);
|
|
444
285
|
};
|
|
445
|
-
if (r.forEach((
|
|
446
|
-
r.slice(
|
|
447
|
-
const { intersections:
|
|
448
|
-
...
|
|
449
|
-
...
|
|
450
|
-
].filter((
|
|
451
|
-
const
|
|
452
|
-
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);
|
|
453
294
|
});
|
|
454
|
-
|
|
295
|
+
A.length && (s(c, A), s(S + c + 1, A));
|
|
455
296
|
});
|
|
456
|
-
}), !
|
|
457
|
-
const
|
|
458
|
-
return new
|
|
459
|
-
}
|
|
460
|
-
const u = r.flatMap((
|
|
461
|
-
if (!
|
|
462
|
-
return
|
|
463
|
-
const l =
|
|
464
|
-
return
|
|
465
|
-
}).filter((
|
|
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));
|
|
466
307
|
if (!u.length)
|
|
467
|
-
return new
|
|
468
|
-
const m =
|
|
469
|
-
return m.length ? new
|
|
308
|
+
return new P();
|
|
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();
|
|
470
311
|
}
|
|
471
|
-
function
|
|
312
|
+
function Et(t, n) {
|
|
472
313
|
const e = t.map((r) => {
|
|
473
|
-
const
|
|
474
|
-
r.holes.map((
|
|
314
|
+
const o = R(
|
|
315
|
+
r.holes.map((s) => q(s, n))
|
|
475
316
|
);
|
|
476
|
-
return Mt(
|
|
317
|
+
return Mt(q(r.contour, n), o);
|
|
477
318
|
});
|
|
478
|
-
return
|
|
319
|
+
return R(e);
|
|
479
320
|
}
|
|
480
|
-
function
|
|
481
|
-
return
|
|
321
|
+
function Tt(t, n) {
|
|
322
|
+
return Et(F(t), n);
|
|
482
323
|
}
|
|
483
|
-
function
|
|
484
|
-
if (t instanceof
|
|
324
|
+
function G(t) {
|
|
325
|
+
if (t instanceof d)
|
|
485
326
|
return `L ${t.lastPoint.join(" ")}`;
|
|
486
|
-
if (t instanceof
|
|
327
|
+
if (t instanceof w)
|
|
487
328
|
return `A ${t.radius} ${t.radius} 0 ${t.angularLength > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${t.lastPoint.join(" ")}`;
|
|
488
329
|
throw new Error("Unknown segment type");
|
|
489
330
|
}
|
|
490
|
-
function
|
|
491
|
-
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(
|
|
331
|
+
function K(t) {
|
|
332
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(G).join(" ");
|
|
492
333
|
return `${n} ${e} Z`;
|
|
493
334
|
}
|
|
494
|
-
function
|
|
495
|
-
return `<path d="${t.allLoops.map(
|
|
335
|
+
function Q(t) {
|
|
336
|
+
return `<path d="${t.allLoops.map(K).join(" ")}" />`;
|
|
496
337
|
}
|
|
497
|
-
function
|
|
338
|
+
function yt(t) {
|
|
498
339
|
return `<g>
|
|
499
|
-
${t.figures.map(
|
|
340
|
+
${t.figures.map(Q).join(`
|
|
500
341
|
`)}
|
|
501
342
|
</g>`;
|
|
502
343
|
}
|
|
503
|
-
function
|
|
504
|
-
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(
|
|
344
|
+
function bt(t) {
|
|
345
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(G).join(" ");
|
|
505
346
|
return `${n} ${e}`;
|
|
506
347
|
}
|
|
507
|
-
function
|
|
348
|
+
function Dt(t, n = 1) {
|
|
508
349
|
const e = t.xMin - n, r = t.yMin - n;
|
|
509
350
|
return `${e} ${r} ${t.width + 2 * n} ${t.height + 2 * n}`;
|
|
510
351
|
}
|
|
511
|
-
function
|
|
352
|
+
function B(t, n, e = 1) {
|
|
512
353
|
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
513
|
-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${
|
|
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">
|
|
514
355
|
${t}
|
|
515
356
|
</svg>`;
|
|
516
357
|
}
|
|
517
|
-
function
|
|
518
|
-
if (t instanceof
|
|
519
|
-
return
|
|
520
|
-
if (t instanceof
|
|
521
|
-
return
|
|
522
|
-
if (t instanceof
|
|
523
|
-
return `<path d="${
|
|
524
|
-
if (t instanceof
|
|
525
|
-
return `<path d="${
|
|
526
|
-
if (t instanceof
|
|
527
|
-
return `<path d="${`M ${t.firstPoint.join(" ")}`} ${
|
|
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(
|
|
528
369
|
t
|
|
529
370
|
)}" />`;
|
|
530
371
|
throw new Error("Unknown shape type");
|
|
531
372
|
}
|
|
532
|
-
const
|
|
373
|
+
const W = (t) => "shape" in t ? t.shape : t, X = (t, n) => {
|
|
533
374
|
if (!("shape" in t))
|
|
534
375
|
return n;
|
|
535
376
|
const { color: e } = t;
|
|
536
377
|
return e ? `<g stroke="${e}">${n}</g>` : n;
|
|
537
378
|
};
|
|
538
|
-
function
|
|
379
|
+
function Rt(t, n = 1) {
|
|
539
380
|
if (Array.isArray(t)) {
|
|
540
|
-
const r = t.map((
|
|
541
|
-
`),
|
|
542
|
-
return
|
|
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);
|
|
543
384
|
}
|
|
544
|
-
const e =
|
|
545
|
-
return
|
|
546
|
-
|
|
385
|
+
const e = W(t).mirror();
|
|
386
|
+
return B(
|
|
387
|
+
X(t, J(e)),
|
|
547
388
|
e.boundingBox,
|
|
548
389
|
n
|
|
549
390
|
);
|
|
550
391
|
}
|
|
551
|
-
const
|
|
392
|
+
const _ = (t) => {
|
|
552
393
|
if (t.type === "LINE")
|
|
553
|
-
return new
|
|
394
|
+
return new d(t.firstPoint, t.lastPoint);
|
|
554
395
|
if (t.type === "ARC")
|
|
555
|
-
return new
|
|
396
|
+
return new w(
|
|
556
397
|
t.firstPoint,
|
|
557
398
|
t.lastPoint,
|
|
558
399
|
t.center,
|
|
559
400
|
t.clockwise
|
|
560
401
|
);
|
|
561
402
|
throw new Error("Unknown segment type");
|
|
562
|
-
},
|
|
563
|
-
const n = t.segments.map(
|
|
564
|
-
return new
|
|
565
|
-
},
|
|
566
|
-
const n =
|
|
567
|
-
return new
|
|
568
|
-
},
|
|
569
|
-
const n = t.figures.map(
|
|
570
|
-
return new
|
|
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);
|
|
571
412
|
};
|
|
572
|
-
function
|
|
413
|
+
function Ut(t) {
|
|
573
414
|
if (t.type === "DIAGRAM")
|
|
574
|
-
return
|
|
415
|
+
return It(t);
|
|
575
416
|
if (t.type === "FIGURE")
|
|
576
|
-
return
|
|
417
|
+
return j(t);
|
|
577
418
|
if (t.type === "LOOP")
|
|
578
|
-
return
|
|
419
|
+
return k(t);
|
|
579
420
|
if (t.type === "LINE" || t.type === "ARC")
|
|
580
|
-
return
|
|
421
|
+
return _(t);
|
|
581
422
|
throw new Error("Unknown shape type");
|
|
582
423
|
}
|
|
583
|
-
const
|
|
584
|
-
function
|
|
585
|
-
const e = Math.cos(n *
|
|
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;
|
|
586
427
|
return [e, r];
|
|
587
428
|
}
|
|
588
|
-
function
|
|
589
|
-
const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) *
|
|
429
|
+
function zt([t, n]) {
|
|
430
|
+
const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) * kt;
|
|
590
431
|
return [e, r];
|
|
591
432
|
}
|
|
592
433
|
export {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
434
|
+
Y as DEG2RAD,
|
|
435
|
+
kt as RAD2DEG,
|
|
436
|
+
zt as cartesianToPolar,
|
|
437
|
+
Vt as confineStrand,
|
|
596
438
|
Mt as cut,
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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
|
|
607
450
|
};
|
|
608
451
|
//# sourceMappingURL=pantograph.js.map
|