pantograph2d 0.3.1 → 0.5.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-9915ed5e.js} +567 -536
- package/dist/Diagram-9915ed5e.js.map +1 -0
- package/dist/Diagram-c2ca1c3b.cjs +4 -0
- package/dist/Diagram-c2ca1c3b.cjs.map +1 -0
- package/dist/draw-25b9ed64.cjs +2 -0
- package/dist/draw-25b9ed64.cjs.map +1 -0
- package/dist/draw-cd61ec6b.js +256 -0
- package/dist/draw-cd61ec6b.js.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 +23 -3
- package/dist/pantograph.js +360 -451
- 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
|
-
|
|
1
|
+
import { o as ct, D as b } from "./draw-cd61ec6b.js";
|
|
2
|
+
import { d as _t } from "./draw-cd61ec6b.js";
|
|
3
|
+
import { F as g, L as d, D as p, f as O, r as ut, z as lt, s as pt, a as Pt, c as gt, i as mt, l as wt, d as h, b as dt, p as ht, n as B, e as v, g as St, h as At, j as Mt, k as $t, m as w, A as S, o as H, q as A, t as Lt, u as Ft, v as vt, S as K } from "./Diagram-9915ed5e.js";
|
|
4
|
+
import { w as tn } from "./Diagram-9915ed5e.js";
|
|
5
|
+
function M(t) {
|
|
6
|
+
if (t instanceof g)
|
|
7
|
+
return [t];
|
|
8
|
+
if (t instanceof d)
|
|
9
|
+
return [new g(t)];
|
|
9
10
|
if (t instanceof p)
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
return Tt(t, n);
|
|
13
|
-
throw new Error("Not implemented");
|
|
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 Q(t, n, e = 1e-9) {
|
|
15
|
+
let r = [];
|
|
16
|
+
const o = [], s = new Array(n.segments.length).fill(0).map(() => []);
|
|
17
|
+
n.segments.forEach((a, u) => {
|
|
18
|
+
t.segments.forEach((f) => {
|
|
19
|
+
const { intersections: l, overlaps: m } = O(
|
|
20
|
+
a,
|
|
21
|
+
f,
|
|
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(...l), s[u].push(...l), o.push(...m);
|
|
25
|
+
const P = m.flatMap((c) => [
|
|
26
|
+
c.firstPoint,
|
|
27
|
+
c.lastPoint
|
|
28
|
+
]);
|
|
29
|
+
r.push(...P), s[u].push(...P);
|
|
30
|
+
});
|
|
31
|
+
}), r = ut(r, e);
|
|
32
|
+
const i = lt([n.segments, s]).flatMap(([a, u]) => u.length ? a.splitAt(u) : [a]);
|
|
33
|
+
return Array.from(
|
|
34
|
+
pt(
|
|
35
|
+
i,
|
|
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 C(t, n, e = !1) {
|
|
42
|
+
return Q(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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
47
|
+
function G(t, n, e = !1) {
|
|
48
|
+
return Q(n, t).filter((o) => {
|
|
49
|
+
const s = o.segments[0].midPoint;
|
|
50
|
+
return n.onStroke(s) ? !e : n.contains(s);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function R(t, n, e = !1) {
|
|
54
|
+
const r = C(
|
|
55
|
+
t,
|
|
56
|
+
n.contour,
|
|
57
|
+
e
|
|
58
|
+
), o = n.holes.flatMap(
|
|
59
|
+
(s) => G(t, s, e)
|
|
60
|
+
);
|
|
61
|
+
return [...r, ...o];
|
|
253
62
|
}
|
|
254
|
-
function
|
|
255
|
-
|
|
256
|
-
|
|
63
|
+
function U(t, n, e = !1) {
|
|
64
|
+
let r = G(
|
|
65
|
+
t,
|
|
66
|
+
n.contour,
|
|
67
|
+
e
|
|
68
|
+
);
|
|
69
|
+
return n.holes.forEach((o) => {
|
|
70
|
+
r = r.flatMap(
|
|
71
|
+
(s) => C(s, o, e)
|
|
72
|
+
);
|
|
73
|
+
}), r;
|
|
74
|
+
}
|
|
75
|
+
function Et(t, n) {
|
|
76
|
+
return new p(
|
|
77
|
+
Pt(M(t), M(n))
|
|
257
78
|
);
|
|
258
79
|
}
|
|
259
|
-
function
|
|
80
|
+
function E(t) {
|
|
260
81
|
return t.reduce(
|
|
261
|
-
(n, e) =>
|
|
262
|
-
new
|
|
82
|
+
(n, e) => Et(n, e),
|
|
83
|
+
new p()
|
|
263
84
|
);
|
|
264
85
|
}
|
|
265
|
-
function
|
|
266
|
-
return new
|
|
267
|
-
gt(
|
|
86
|
+
function _(t, n) {
|
|
87
|
+
return new p(
|
|
88
|
+
gt(M(t), M(n))
|
|
268
89
|
);
|
|
269
90
|
}
|
|
270
91
|
function Nt(t, n) {
|
|
271
|
-
return new
|
|
272
|
-
|
|
92
|
+
return new p(
|
|
93
|
+
mt(M(t), M(n))
|
|
273
94
|
);
|
|
274
95
|
}
|
|
275
|
-
function
|
|
96
|
+
function qt(t, n, e = !0) {
|
|
97
|
+
if (n instanceof d)
|
|
98
|
+
return C(t, n, e);
|
|
99
|
+
if (n instanceof g)
|
|
100
|
+
return R(t, n, e);
|
|
101
|
+
let r = [t];
|
|
102
|
+
return n.figures.forEach((o) => {
|
|
103
|
+
r = r.flatMap((s) => R(s, o, e));
|
|
104
|
+
}), r;
|
|
105
|
+
}
|
|
106
|
+
function Jt(t, n, e = !1) {
|
|
107
|
+
if (n instanceof d)
|
|
108
|
+
return G(t, n, e);
|
|
109
|
+
if (n instanceof g)
|
|
110
|
+
return U(t, n, e);
|
|
111
|
+
let r = [t];
|
|
112
|
+
return n.figures.forEach((o) => {
|
|
113
|
+
r = r.flatMap((s) => U(s, o, e));
|
|
114
|
+
}), r;
|
|
115
|
+
}
|
|
116
|
+
function z(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 yt(t, n) {
|
|
127
|
+
const e = wt(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 = z(r), i = z(o);
|
|
134
|
+
if (s === "between" && i === "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" && i !== "between")
|
|
137
|
+
return N(t, n, i);
|
|
138
|
+
if (i === "between" && s !== "between")
|
|
139
|
+
return N(n, t, s);
|
|
140
|
+
if (s === "before" && i === "before")
|
|
141
|
+
return h(t.firstPoint, n.firstPoint);
|
|
142
|
+
if (s === "after" && i === "after")
|
|
143
|
+
return h(t.lastPoint, n.lastPoint);
|
|
144
|
+
if (s === "before" && i === "after")
|
|
145
|
+
return h(t.firstPoint, n.lastPoint);
|
|
146
|
+
if (s === "after" && i === "before")
|
|
147
|
+
return h(t.lastPoint, n.firstPoint);
|
|
307
148
|
throw new Error("Invalid position");
|
|
308
149
|
}
|
|
309
|
-
function
|
|
310
|
-
if (
|
|
150
|
+
function q(t, n) {
|
|
151
|
+
if (dt(t, n).length > 0)
|
|
311
152
|
return 0;
|
|
312
|
-
const e =
|
|
153
|
+
const e = ht(t, n.center);
|
|
313
154
|
if (t.isOnSegment(e)) {
|
|
314
|
-
const r =
|
|
155
|
+
const r = h(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 = B(
|
|
160
|
+
v(e, n.center)
|
|
161
|
+
), s = St(
|
|
321
162
|
n.center,
|
|
322
|
-
|
|
163
|
+
At(o, n.radius)
|
|
323
164
|
);
|
|
324
|
-
if (n.isOnSegment(
|
|
325
|
-
return
|
|
165
|
+
if (n.isOnSegment(s))
|
|
166
|
+
return h(s, e);
|
|
326
167
|
}
|
|
327
168
|
}
|
|
328
169
|
return Math.min(
|
|
@@ -332,277 +173,345 @@ function z(t, n) {
|
|
|
332
173
|
t.distanceFrom(n.lastPoint)
|
|
333
174
|
);
|
|
334
175
|
}
|
|
335
|
-
const
|
|
176
|
+
const It = (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 bt(t, n) {
|
|
184
|
+
if (Mt(t, n, !0).length > 0)
|
|
344
185
|
return 0;
|
|
345
|
-
const e =
|
|
346
|
-
if (e < t.precision &&
|
|
186
|
+
const e = h(t.center, n.center);
|
|
187
|
+
if (e < t.precision && It(t, n))
|
|
347
188
|
return Math.abs(t.radius - n.radius);
|
|
348
|
-
const r =
|
|
349
|
-
let
|
|
350
|
-
|
|
351
|
-
const
|
|
352
|
-
return t.isValidParameter(
|
|
189
|
+
const r = B(v(n.center, t.center)), o = e - Math.abs(t.radius - n.radius) < t.precision;
|
|
190
|
+
let s = $t(r);
|
|
191
|
+
o && n.radius > t.radius && (s += Math.PI);
|
|
192
|
+
const i = o ? s : s + Math.PI, a = t.angleToParam(s), u = n.angleToParam(i);
|
|
193
|
+
return t.isValidParameter(a) && n.isValidParameter(u) ? h(t.paramPoint(a), n.paramPoint(u)) : 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 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)
|
|
200
|
+
function kt(t, n) {
|
|
201
|
+
if (t instanceof w && n instanceof w)
|
|
367
202
|
return yt(t, n);
|
|
203
|
+
if (t instanceof w && n instanceof S)
|
|
204
|
+
return q(t, n);
|
|
205
|
+
if (t instanceof S && n instanceof w)
|
|
206
|
+
return q(n, t);
|
|
207
|
+
if (t instanceof S && n instanceof S)
|
|
208
|
+
return bt(t, n);
|
|
368
209
|
throw new Error("Not implemented");
|
|
369
210
|
}
|
|
370
|
-
const
|
|
371
|
-
function
|
|
372
|
-
const
|
|
373
|
-
offset:
|
|
374
|
-
original:
|
|
375
|
-
})),
|
|
376
|
-
let s = null, i = e.at(-1);
|
|
377
|
-
if (
|
|
378
|
-
return
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
new p(c.offset.firstPoint, c.offset.lastPoint)
|
|
384
|
-
) : r.push(c.offset) : s = c;
|
|
211
|
+
const V = 1e-8;
|
|
212
|
+
function k(t, n, e = !0) {
|
|
213
|
+
const r = t.map((f) => ({
|
|
214
|
+
offset: ct(f, n),
|
|
215
|
+
original: f
|
|
216
|
+
})), o = [];
|
|
217
|
+
let s = e ? null : r.at(-1), i = e ? r.at(-1) : null;
|
|
218
|
+
if (o.length === 1)
|
|
219
|
+
return o;
|
|
220
|
+
const a = (f) => {
|
|
221
|
+
s ? f.offset instanceof b ? A(f.offset.firstPoint, f.offset.lastPoint) || o.push(
|
|
222
|
+
new w(f.offset.firstPoint, f.offset.lastPoint)
|
|
223
|
+
) : o.push(f.offset) : s = f;
|
|
385
224
|
}, u = function* () {
|
|
386
|
-
for (const
|
|
387
|
-
yield
|
|
225
|
+
for (const f of r.slice(0, -1))
|
|
226
|
+
yield f;
|
|
388
227
|
if (!s)
|
|
389
228
|
throw new Error("Bug in the offset algorithm");
|
|
390
229
|
yield s;
|
|
391
230
|
};
|
|
392
|
-
for (const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
o(i), i = c;
|
|
231
|
+
for (const f of u()) {
|
|
232
|
+
if (!i) {
|
|
233
|
+
i = f;
|
|
396
234
|
continue;
|
|
397
235
|
}
|
|
398
|
-
|
|
399
|
-
if (
|
|
400
|
-
|
|
236
|
+
const l = i.offset.lastPoint, m = f.offset.firstPoint;
|
|
237
|
+
if (A(l, m)) {
|
|
238
|
+
a(i), i = f;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
let P = [];
|
|
242
|
+
if (!(i.offset instanceof b) && !(f.offset instanceof b)) {
|
|
243
|
+
const { intersections: $, overlaps: I } = O(
|
|
401
244
|
i.offset,
|
|
402
|
-
|
|
403
|
-
|
|
245
|
+
f.offset,
|
|
246
|
+
V / 100
|
|
404
247
|
);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
...
|
|
248
|
+
P = [
|
|
249
|
+
...$,
|
|
250
|
+
...I.flatMap((L) => [L.firstPoint, L.lastPoint])
|
|
408
251
|
];
|
|
409
252
|
}
|
|
410
|
-
if (
|
|
411
|
-
let
|
|
412
|
-
if (
|
|
413
|
-
const
|
|
414
|
-
(at) =>
|
|
253
|
+
if (P.length > 0) {
|
|
254
|
+
let $ = P[0];
|
|
255
|
+
if (P.length > 1) {
|
|
256
|
+
const ft = i == null ? void 0 : i.original.lastPoint, T = P.map(
|
|
257
|
+
(at) => Lt(at, ft)
|
|
415
258
|
);
|
|
416
|
-
|
|
259
|
+
$ = P[T.indexOf(Math.min(...T))];
|
|
417
260
|
}
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
])[0],
|
|
421
|
-
if (!
|
|
261
|
+
const I = i.offset.splitAt([
|
|
262
|
+
$
|
|
263
|
+
])[0], L = f.offset.splitAt([$]).at(-1);
|
|
264
|
+
if (!L)
|
|
422
265
|
throw new Error("Bug in the splitting algo in offset");
|
|
423
|
-
|
|
424
|
-
offset:
|
|
266
|
+
a({
|
|
267
|
+
offset: I,
|
|
425
268
|
original: i.original
|
|
426
|
-
}), i = { offset:
|
|
269
|
+
}), i = { offset: L, original: f.original };
|
|
427
270
|
continue;
|
|
428
271
|
}
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
) > 0,
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
return
|
|
436
|
-
}
|
|
437
|
-
function
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const s = /* @__PURE__ */ new Map(), i = (a, f) => {
|
|
442
|
-
const l = s.get(a) || [];
|
|
443
|
-
s.set(a, [...l, ...f]);
|
|
272
|
+
const c = i.original.lastPoint, F = vt(
|
|
273
|
+
v(m, c),
|
|
274
|
+
v(l, c)
|
|
275
|
+
) > 0, it = new S(l, m, c, F);
|
|
276
|
+
a(i), o.push(it), i = f;
|
|
277
|
+
}
|
|
278
|
+
return a(i), o;
|
|
279
|
+
}
|
|
280
|
+
function j(t) {
|
|
281
|
+
const n = /* @__PURE__ */ new Map(), e = (r, o) => {
|
|
282
|
+
const s = n.get(r) || [];
|
|
283
|
+
n.set(r, [...s, ...o]);
|
|
444
284
|
};
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const { intersections:
|
|
448
|
-
...
|
|
449
|
-
...
|
|
450
|
-
].filter((
|
|
451
|
-
const
|
|
452
|
-
return !(
|
|
285
|
+
return t.forEach((r, o) => {
|
|
286
|
+
t.slice(o + 1).forEach((s, i) => {
|
|
287
|
+
const { intersections: a, overlaps: u } = O(r, s, V), f = [
|
|
288
|
+
...a,
|
|
289
|
+
...u.flatMap((l) => [l.firstPoint, l.lastPoint])
|
|
290
|
+
].filter((l) => {
|
|
291
|
+
const m = A(l, r.firstPoint) || A(l, r.lastPoint), P = A(l, s.firstPoint) || A(l, s.lastPoint);
|
|
292
|
+
return !(m && P);
|
|
453
293
|
});
|
|
454
|
-
|
|
294
|
+
f.length && (e(o, f), e(i + o + 1, f));
|
|
455
295
|
});
|
|
456
|
-
}),
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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();
|
|
296
|
+
}), n;
|
|
297
|
+
}
|
|
298
|
+
function tt(t, n) {
|
|
299
|
+
return n.flatMap((e, r) => {
|
|
300
|
+
if (!t.has(r))
|
|
301
|
+
return e;
|
|
302
|
+
const o = t.get(r);
|
|
303
|
+
return o ? e.splitAt(o) : e;
|
|
304
|
+
});
|
|
470
305
|
}
|
|
471
|
-
function
|
|
306
|
+
function nt(t, n, e) {
|
|
307
|
+
return t.filter((r) => !n.segments.some((s) => kt(s, r) < Math.abs(e) - V));
|
|
308
|
+
}
|
|
309
|
+
function y(t, n) {
|
|
310
|
+
const e = t.clockwise ? n : -n, r = k(t.segments, e);
|
|
311
|
+
if (r.length < 2)
|
|
312
|
+
return new p();
|
|
313
|
+
const o = j(r);
|
|
314
|
+
if (!o.size) {
|
|
315
|
+
const f = new d(r);
|
|
316
|
+
return new p([new g(f)]);
|
|
317
|
+
}
|
|
318
|
+
const s = tt(
|
|
319
|
+
o,
|
|
320
|
+
r
|
|
321
|
+
), i = nt(s, t, n);
|
|
322
|
+
if (!i.length)
|
|
323
|
+
return new p();
|
|
324
|
+
const u = H(i).filter((f) => f.length > 1).filter((f) => A(f[0].firstPoint, f.at(-1).lastPoint)).map((f) => new d(f));
|
|
325
|
+
return u.length ? new p(u.map((f) => new g(f))) : new p();
|
|
326
|
+
}
|
|
327
|
+
function Dt(t, n, e = "round") {
|
|
328
|
+
const r = n / 2, o = k(t.segments, r, !1), s = k(t.segments, -r, !1).map(
|
|
329
|
+
(c) => c.reverse()
|
|
330
|
+
);
|
|
331
|
+
s.reverse();
|
|
332
|
+
const i = (c, F) => e === "round" ? Ft(
|
|
333
|
+
c.lastPoint,
|
|
334
|
+
F.firstPoint,
|
|
335
|
+
c.tangentAtLastPoint
|
|
336
|
+
) : new w(c.lastPoint, F.firstPoint), a = [
|
|
337
|
+
...o,
|
|
338
|
+
i(
|
|
339
|
+
o[o.length - 1],
|
|
340
|
+
s[0]
|
|
341
|
+
),
|
|
342
|
+
...s,
|
|
343
|
+
i(
|
|
344
|
+
s[s.length - 1],
|
|
345
|
+
o[0]
|
|
346
|
+
)
|
|
347
|
+
], u = j(a);
|
|
348
|
+
if (!u.size) {
|
|
349
|
+
const c = new d(a);
|
|
350
|
+
return new p([new g(c)]);
|
|
351
|
+
}
|
|
352
|
+
const f = tt(
|
|
353
|
+
u,
|
|
354
|
+
a
|
|
355
|
+
), l = nt(f, t, r);
|
|
356
|
+
if (!l.length)
|
|
357
|
+
return new p();
|
|
358
|
+
const P = H(l).filter((c) => c.length > 1).filter((c) => A(c[0].firstPoint, c.at(-1).lastPoint)).map((c) => new d(c));
|
|
359
|
+
return P.length ? new p(P.map((c) => new g(c))) : new p();
|
|
360
|
+
}
|
|
361
|
+
function Ot(t, n) {
|
|
472
362
|
const e = t.map((r) => {
|
|
473
|
-
const
|
|
474
|
-
r.holes.map((
|
|
363
|
+
const o = E(
|
|
364
|
+
r.holes.map((s) => y(s, n))
|
|
475
365
|
);
|
|
476
|
-
return
|
|
366
|
+
return _(y(r.contour, n), o);
|
|
477
367
|
});
|
|
478
|
-
return
|
|
368
|
+
return E(e);
|
|
479
369
|
}
|
|
480
|
-
function
|
|
481
|
-
|
|
370
|
+
function Ct(t, n) {
|
|
371
|
+
const e = Math.abs(n / 2), r = t.map(
|
|
372
|
+
(o) => E(
|
|
373
|
+
o.allLoops.map((s) => _(y(s, e), y(s, -e)))
|
|
374
|
+
)
|
|
375
|
+
);
|
|
376
|
+
return E(r);
|
|
482
377
|
}
|
|
483
|
-
function
|
|
484
|
-
|
|
378
|
+
function Wt(t, n) {
|
|
379
|
+
return Ot(M(t), n);
|
|
380
|
+
}
|
|
381
|
+
function Xt(t, n, { endCap: e = "round" } = {}) {
|
|
382
|
+
return t instanceof K ? Dt(t, n, e) : Ct(M(t), n);
|
|
383
|
+
}
|
|
384
|
+
function x(t) {
|
|
385
|
+
if (t instanceof w)
|
|
485
386
|
return `L ${t.lastPoint.join(" ")}`;
|
|
486
|
-
if (t instanceof
|
|
387
|
+
if (t instanceof S)
|
|
487
388
|
return `A ${t.radius} ${t.radius} 0 ${t.angularLength > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${t.lastPoint.join(" ")}`;
|
|
488
389
|
throw new Error("Unknown segment type");
|
|
489
390
|
}
|
|
490
|
-
function
|
|
491
|
-
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(
|
|
391
|
+
function et(t) {
|
|
392
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(x).join(" ");
|
|
492
393
|
return `${n} ${e} Z`;
|
|
493
394
|
}
|
|
494
|
-
function
|
|
495
|
-
return `<path d="${t.allLoops.map(
|
|
395
|
+
function rt(t) {
|
|
396
|
+
return `<path d="${t.allLoops.map(et).join(" ")}" />`;
|
|
496
397
|
}
|
|
497
|
-
function
|
|
398
|
+
function Gt(t) {
|
|
498
399
|
return `<g>
|
|
499
|
-
${t.figures.map(
|
|
400
|
+
${t.figures.map(rt).join(`
|
|
500
401
|
`)}
|
|
501
402
|
</g>`;
|
|
502
403
|
}
|
|
503
|
-
function
|
|
504
|
-
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(
|
|
404
|
+
function Vt(t) {
|
|
405
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(x).join(" ");
|
|
505
406
|
return `${n} ${e}`;
|
|
506
407
|
}
|
|
507
|
-
function
|
|
408
|
+
function xt(t, n = 1) {
|
|
508
409
|
const e = t.xMin - n, r = t.yMin - n;
|
|
509
410
|
return `${e} ${r} ${t.width + 2 * n} ${t.height + 2 * n}`;
|
|
510
411
|
}
|
|
511
|
-
function J(t, n, e = 1) {
|
|
412
|
+
function J(t, n, e = 1, r) {
|
|
413
|
+
const o = xt(n, e), s = r ? `width="${n.width + 2 * e}${r}" height="${n.height + 2 * e}${r}"` : "";
|
|
512
414
|
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
513
|
-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${
|
|
415
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${o}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke" ${s}>
|
|
514
416
|
${t}
|
|
515
417
|
</svg>`;
|
|
516
418
|
}
|
|
517
|
-
function
|
|
419
|
+
function W(t) {
|
|
420
|
+
if (t instanceof p)
|
|
421
|
+
return Gt(t);
|
|
518
422
|
if (t instanceof g)
|
|
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 P || t instanceof p)
|
|
527
|
-
return `<path d="${`M ${t.firstPoint.join(" ")}`} ${R(
|
|
423
|
+
return rt(t);
|
|
424
|
+
if (t instanceof d)
|
|
425
|
+
return `<path d="${et(t)}" />`;
|
|
426
|
+
if (t instanceof K)
|
|
427
|
+
return `<path d="${Vt(t)}" />`;
|
|
428
|
+
if (t instanceof S || t instanceof w)
|
|
429
|
+
return `<path d="${`M ${t.firstPoint.join(" ")}`} ${x(
|
|
528
430
|
t
|
|
529
431
|
)}" />`;
|
|
530
432
|
throw new Error("Unknown shape type");
|
|
531
433
|
}
|
|
532
|
-
const
|
|
434
|
+
const X = (t) => "shape" in t ? t.shape : t, Y = (t, n) => {
|
|
533
435
|
if (!("shape" in t))
|
|
534
436
|
return n;
|
|
535
437
|
const { color: e } = t;
|
|
536
438
|
return e ? `<g stroke="${e}">${n}</g>` : n;
|
|
537
439
|
};
|
|
538
|
-
function Yt(t,
|
|
440
|
+
function Yt(t, {
|
|
441
|
+
margin: n = 1,
|
|
442
|
+
unit: e = null
|
|
443
|
+
} = {}) {
|
|
539
444
|
if (Array.isArray(t)) {
|
|
540
|
-
const
|
|
541
|
-
`), i =
|
|
542
|
-
return J(s, i);
|
|
445
|
+
const o = t.map((a) => X(a).mirror()), s = o.map((a, u) => Y(t[u], W(a))).join(`
|
|
446
|
+
`), i = o.slice(1).reduce((a, u) => a.merge(u.boundingBox), o[0].boundingBox);
|
|
447
|
+
return J(s, i, n, e);
|
|
543
448
|
}
|
|
544
|
-
const
|
|
449
|
+
const r = X(t).mirror();
|
|
545
450
|
return J(
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
n
|
|
451
|
+
Y(t, W(r)),
|
|
452
|
+
r.boundingBox,
|
|
453
|
+
n,
|
|
454
|
+
e
|
|
549
455
|
);
|
|
550
456
|
}
|
|
551
457
|
const st = (t) => {
|
|
552
458
|
if (t.type === "LINE")
|
|
553
|
-
return new
|
|
459
|
+
return new w(t.firstPoint, t.lastPoint);
|
|
554
460
|
if (t.type === "ARC")
|
|
555
|
-
return new
|
|
461
|
+
return new S(
|
|
556
462
|
t.firstPoint,
|
|
557
463
|
t.lastPoint,
|
|
558
464
|
t.center,
|
|
559
465
|
t.clockwise
|
|
560
466
|
);
|
|
561
467
|
throw new Error("Unknown segment type");
|
|
562
|
-
},
|
|
468
|
+
}, D = (t) => {
|
|
563
469
|
const n = t.segments.map(st);
|
|
564
|
-
return new
|
|
470
|
+
return new d(n);
|
|
565
471
|
}, ot = (t) => {
|
|
566
|
-
const n =
|
|
567
|
-
return new
|
|
568
|
-
},
|
|
472
|
+
const n = D(t.contour), e = t.holes.map(D);
|
|
473
|
+
return new g(n, e);
|
|
474
|
+
}, Tt = (t) => {
|
|
569
475
|
const n = t.figures.map(ot);
|
|
570
|
-
return new
|
|
476
|
+
return new p(n);
|
|
571
477
|
};
|
|
572
|
-
function
|
|
478
|
+
function Zt(t) {
|
|
573
479
|
if (t.type === "DIAGRAM")
|
|
574
|
-
return
|
|
480
|
+
return Tt(t);
|
|
575
481
|
if (t.type === "FIGURE")
|
|
576
482
|
return ot(t);
|
|
577
483
|
if (t.type === "LOOP")
|
|
578
|
-
return
|
|
484
|
+
return D(t);
|
|
579
485
|
if (t.type === "LINE" || t.type === "ARC")
|
|
580
486
|
return st(t);
|
|
581
487
|
throw new Error("Unknown shape type");
|
|
582
488
|
}
|
|
583
|
-
const
|
|
584
|
-
function
|
|
585
|
-
const e = Math.cos(n *
|
|
489
|
+
const Z = Math.PI / 180, Rt = 180 / Math.PI;
|
|
490
|
+
function Bt(t, n) {
|
|
491
|
+
const e = Math.cos(n * Z) * t, r = Math.sin(n * Z) * t;
|
|
586
492
|
return [e, r];
|
|
587
493
|
}
|
|
588
|
-
function
|
|
589
|
-
const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) *
|
|
494
|
+
function Ht([t, n]) {
|
|
495
|
+
const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) * Rt;
|
|
590
496
|
return [e, r];
|
|
591
497
|
}
|
|
592
498
|
export {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
499
|
+
Z as DEG2RAD,
|
|
500
|
+
Rt as RAD2DEG,
|
|
501
|
+
Ht as cartesianToPolar,
|
|
502
|
+
Jt as confineStrand,
|
|
503
|
+
_ as cut,
|
|
504
|
+
_t as draw,
|
|
505
|
+
qt as eraseStrand,
|
|
506
|
+
tn as exportJSON,
|
|
599
507
|
Yt as exportSVG,
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
508
|
+
Et as fuse,
|
|
509
|
+
E as fuseAll,
|
|
510
|
+
Zt as importJSON,
|
|
603
511
|
Nt as intersect,
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
512
|
+
Wt as offset,
|
|
513
|
+
Xt as outlineStroke,
|
|
514
|
+
Bt as polarToCartesian,
|
|
515
|
+
W as svgBody
|
|
607
516
|
};
|
|
608
517
|
//# sourceMappingURL=pantograph.js.map
|