pantograph2d 0.2.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/models.d.ts +4 -0
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +3 -3
- package/dist/pantograph.cjs +7 -7
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.d.ts +20 -3
- package/dist/pantograph.js +522 -200
- package/dist/pantograph.js.map +1 -1
- package/package.json +7 -2
- package/dist/exportJSON-b3e1c256.js +0 -1388
- package/dist/exportJSON-b3e1c256.js.map +0 -1
- package/dist/exportJSON-d9965e73.cjs +0 -4
- package/dist/exportJSON-d9965e73.cjs.map +0 -1
package/dist/pantograph.js
CHANGED
|
@@ -1,286 +1,608 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
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
|
+
);
|
|
21
|
+
}
|
|
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
|
+
);
|
|
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
|
|
10
69
|
];
|
|
11
70
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
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))]);
|
|
14
84
|
}
|
|
15
|
-
class
|
|
16
|
-
constructor(
|
|
17
|
-
this.pointer =
|
|
85
|
+
class Et {
|
|
86
|
+
constructor(n = [0, 0]) {
|
|
87
|
+
this.pointer = n, this.firstPoint = n, this.pendingSegments = [], this._nextCorner = null;
|
|
18
88
|
}
|
|
19
|
-
movePointerTo(
|
|
89
|
+
movePointerTo(n) {
|
|
20
90
|
if (this.pendingSegments.length)
|
|
21
91
|
throw new Error(
|
|
22
92
|
"You can only move the pointer if there is no segment defined"
|
|
23
93
|
);
|
|
24
|
-
return this.pointer =
|
|
94
|
+
return this.pointer = n, this.firstPoint = n, this;
|
|
25
95
|
}
|
|
26
|
-
saveSegment(
|
|
27
|
-
if (
|
|
28
|
-
throw new Error(`Segment has no length, ${
|
|
29
|
-
|
|
96
|
+
saveSegment(n) {
|
|
97
|
+
if (A(n.firstPoint, n.lastPoint))
|
|
98
|
+
throw new Error(`Segment has no length, ${n.repr}`);
|
|
99
|
+
if (!this._nextCorner)
|
|
100
|
+
return this.pendingSegments.push(n), this;
|
|
101
|
+
const e = this.pendingSegments.pop();
|
|
102
|
+
if (!e)
|
|
103
|
+
throw new Error("bug in the custom corner algorithm");
|
|
104
|
+
const r = this._nextCorner.mode === "chamfer" ? G : B;
|
|
105
|
+
return this.pendingSegments.push(
|
|
106
|
+
...r(e, n, this._nextCorner.radius)
|
|
107
|
+
), this._nextCorner = null, this;
|
|
30
108
|
}
|
|
31
|
-
lineTo(
|
|
32
|
-
const
|
|
33
|
-
return this.pointer =
|
|
109
|
+
lineTo(n) {
|
|
110
|
+
const e = new p(this.pointer, n);
|
|
111
|
+
return this.pointer = n, this.saveSegment(e);
|
|
34
112
|
}
|
|
35
|
-
line(
|
|
36
|
-
return this.lineTo([this.pointer[0] +
|
|
113
|
+
line(n, e) {
|
|
114
|
+
return this.lineTo([this.pointer[0] + n, this.pointer[1] + e]);
|
|
37
115
|
}
|
|
38
|
-
vLine(
|
|
39
|
-
return this.line(0,
|
|
116
|
+
vLine(n) {
|
|
117
|
+
return this.line(0, n);
|
|
40
118
|
}
|
|
41
|
-
hLine(
|
|
42
|
-
return this.line(
|
|
119
|
+
hLine(n) {
|
|
120
|
+
return this.line(n, 0);
|
|
43
121
|
}
|
|
44
|
-
vLineTo(
|
|
45
|
-
return this.lineTo([this.pointer[0],
|
|
122
|
+
vLineTo(n) {
|
|
123
|
+
return this.lineTo([this.pointer[0], n]);
|
|
46
124
|
}
|
|
47
|
-
hLineTo(
|
|
48
|
-
return this.lineTo([
|
|
125
|
+
hLineTo(n) {
|
|
126
|
+
return this.lineTo([n, this.pointer[1]]);
|
|
49
127
|
}
|
|
50
|
-
polarLineTo([
|
|
51
|
-
const
|
|
52
|
-
return this.lineTo(
|
|
128
|
+
polarLineTo([n, e]) {
|
|
129
|
+
const r = e * V, s = _(n, r);
|
|
130
|
+
return this.lineTo(s);
|
|
53
131
|
}
|
|
54
|
-
polarLine(
|
|
55
|
-
const
|
|
56
|
-
return this.line(
|
|
132
|
+
polarLine(n, e) {
|
|
133
|
+
const r = e * V, [s, i] = _(n, r);
|
|
134
|
+
return this.line(s, i);
|
|
57
135
|
}
|
|
58
|
-
tangentLine(
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
136
|
+
tangentLine(n) {
|
|
137
|
+
const e = this.pendingSegments.at(-1);
|
|
138
|
+
if (!e)
|
|
61
139
|
throw new Error("You need a previous segment to sketch a tangent line");
|
|
62
|
-
const [
|
|
63
|
-
return this.line(
|
|
140
|
+
const [r, s] = e.tangentAtLastPoint;
|
|
141
|
+
return this.line(r * n, s * n);
|
|
64
142
|
}
|
|
65
|
-
threePointsArcTo(
|
|
66
|
-
return this.saveSegment(
|
|
143
|
+
threePointsArcTo(n, e) {
|
|
144
|
+
return this.saveSegment(ut(this.pointer, e, n)), this.pointer = n, this;
|
|
67
145
|
}
|
|
68
|
-
threePointsArc(
|
|
69
|
-
const [
|
|
146
|
+
threePointsArc(n, e, r, s) {
|
|
147
|
+
const [i, o] = this.pointer;
|
|
70
148
|
return this.threePointsArcTo(
|
|
71
|
-
[
|
|
72
|
-
[
|
|
149
|
+
[i + n, o + e],
|
|
150
|
+
[i + r, o + s]
|
|
73
151
|
);
|
|
74
152
|
}
|
|
75
|
-
sagittaArcTo(
|
|
76
|
-
if (!
|
|
77
|
-
return this.lineTo(
|
|
78
|
-
const
|
|
79
|
-
return this.threePointsArcTo(
|
|
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);
|
|
80
158
|
}
|
|
81
|
-
sagittaArc(
|
|
159
|
+
sagittaArc(n, e, r) {
|
|
82
160
|
return this.sagittaArcTo(
|
|
83
|
-
[
|
|
84
|
-
|
|
161
|
+
[n + this.pointer[0], e + this.pointer[1]],
|
|
162
|
+
r
|
|
85
163
|
);
|
|
86
164
|
}
|
|
87
|
-
vSagittaArc(
|
|
88
|
-
return this.sagittaArc(0,
|
|
165
|
+
vSagittaArc(n, e) {
|
|
166
|
+
return this.sagittaArc(0, n, e);
|
|
89
167
|
}
|
|
90
|
-
hSagittaArc(
|
|
91
|
-
return this.sagittaArc(
|
|
168
|
+
hSagittaArc(n, e) {
|
|
169
|
+
return this.sagittaArc(n, 0, e);
|
|
92
170
|
}
|
|
93
|
-
bulgeArcTo(
|
|
94
|
-
if (!
|
|
95
|
-
return this.lineTo(
|
|
96
|
-
const
|
|
97
|
-
return this.sagittaArcTo(
|
|
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);
|
|
98
176
|
}
|
|
99
|
-
bulgeArc(
|
|
177
|
+
bulgeArc(n, e, r) {
|
|
100
178
|
return this.bulgeArcTo(
|
|
101
|
-
[
|
|
102
|
-
|
|
179
|
+
[n + this.pointer[0], e + this.pointer[1]],
|
|
180
|
+
r
|
|
103
181
|
);
|
|
104
182
|
}
|
|
105
|
-
vBulgeArc(
|
|
106
|
-
return this.bulgeArc(0,
|
|
183
|
+
vBulgeArc(n, e) {
|
|
184
|
+
return this.bulgeArc(0, n, e);
|
|
107
185
|
}
|
|
108
|
-
hBulgeArc(
|
|
109
|
-
return this.bulgeArc(
|
|
186
|
+
hBulgeArc(n, e) {
|
|
187
|
+
return this.bulgeArc(n, 0, e);
|
|
110
188
|
}
|
|
111
|
-
tangentArcTo(
|
|
112
|
-
const
|
|
113
|
-
if (!
|
|
189
|
+
tangentArcTo(n) {
|
|
190
|
+
const e = this.pendingSegments.at(-1);
|
|
191
|
+
if (!e)
|
|
114
192
|
throw new Error("You need a previous curve to sketch a tangent arc");
|
|
115
193
|
return this.saveSegment(
|
|
116
|
-
|
|
117
|
-
), this.pointer =
|
|
194
|
+
Q(this.pointer, n, e.tangentAtLastPoint)
|
|
195
|
+
), this.pointer = n, this;
|
|
118
196
|
}
|
|
119
|
-
tangentArc(
|
|
120
|
-
const [
|
|
121
|
-
return this.tangentArcTo([
|
|
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));
|
|
122
214
|
}
|
|
123
215
|
close() {
|
|
124
|
-
|
|
125
|
-
|
|
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);
|
|
126
223
|
}
|
|
127
224
|
closeWithMirror() {
|
|
128
225
|
if (!this.pendingSegments.length)
|
|
129
226
|
throw new Error("No segments to close");
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
),
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
),
|
|
137
|
-
(
|
|
227
|
+
const n = this.pendingSegments[0], e = this.pendingSegments.at(-1), r = $(
|
|
228
|
+
e.lastPoint,
|
|
229
|
+
n.firstPoint
|
|
230
|
+
), s = new lt().mirrorLine(
|
|
231
|
+
r,
|
|
232
|
+
n.firstPoint
|
|
233
|
+
), i = this.pendingSegments.map(
|
|
234
|
+
(o) => o.transform(s).reverse()
|
|
138
235
|
);
|
|
139
|
-
return
|
|
236
|
+
return i.reverse(), N([
|
|
140
237
|
...this.pendingSegments,
|
|
141
|
-
...
|
|
238
|
+
...i
|
|
142
239
|
]);
|
|
143
240
|
}
|
|
144
241
|
}
|
|
145
|
-
function
|
|
146
|
-
return new
|
|
242
|
+
function Gt(t = [0, 0]) {
|
|
243
|
+
return new Et(t);
|
|
147
244
|
}
|
|
148
|
-
function
|
|
149
|
-
if (
|
|
150
|
-
return [
|
|
151
|
-
if (
|
|
152
|
-
return [new
|
|
153
|
-
if (
|
|
154
|
-
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;
|
|
155
252
|
throw new Error("Unknown shape");
|
|
156
253
|
}
|
|
157
|
-
function
|
|
158
|
-
return new
|
|
159
|
-
|
|
254
|
+
function Ft(t, n) {
|
|
255
|
+
return new g(
|
|
256
|
+
ht(E(t), E(n))
|
|
160
257
|
);
|
|
161
258
|
}
|
|
162
|
-
function
|
|
163
|
-
return
|
|
164
|
-
(
|
|
165
|
-
new
|
|
259
|
+
function U(t) {
|
|
260
|
+
return t.reduce(
|
|
261
|
+
(n, e) => Ft(n, e),
|
|
262
|
+
new g()
|
|
166
263
|
);
|
|
167
264
|
}
|
|
168
|
-
function
|
|
169
|
-
return new
|
|
170
|
-
|
|
265
|
+
function Mt(t, n) {
|
|
266
|
+
return new g(
|
|
267
|
+
gt(E(t), E(n))
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
function Nt(t, n) {
|
|
271
|
+
return new g(
|
|
272
|
+
pt(E(t), E(n))
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
function Y(t) {
|
|
276
|
+
return t < 0 ? "before" : t > 1 ? "after" : "between";
|
|
277
|
+
}
|
|
278
|
+
const q = (t, n, e) => {
|
|
279
|
+
if (e === "before")
|
|
280
|
+
return t.distanceFrom(n.firstPoint);
|
|
281
|
+
if (e === "after")
|
|
282
|
+
return t.distanceFrom(n.lastPoint);
|
|
283
|
+
throw new Error("Invalid position");
|
|
284
|
+
};
|
|
285
|
+
function bt(t, n) {
|
|
286
|
+
const e = mt(t, n);
|
|
287
|
+
if (e === "parallel")
|
|
288
|
+
return Math.min(
|
|
289
|
+
t.distanceFrom(n.firstPoint),
|
|
290
|
+
t.distanceFrom(n.lastPoint)
|
|
291
|
+
);
|
|
292
|
+
const { intersectionParam1: r, intersectionParam2: s } = e, i = Y(r), o = Y(s);
|
|
293
|
+
if (i === "between" && o === "between")
|
|
294
|
+
return 0;
|
|
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
|
+
throw new Error("Invalid position");
|
|
308
|
+
}
|
|
309
|
+
function z(t, n) {
|
|
310
|
+
if (Pt(t, n).length > 0)
|
|
311
|
+
return 0;
|
|
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
|
+
return 0;
|
|
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
|
+
);
|
|
324
|
+
if (n.isOnSegment(i))
|
|
325
|
+
return S(i, e);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return Math.min(
|
|
329
|
+
n.distanceFrom(t.firstPoint),
|
|
330
|
+
n.distanceFrom(t.lastPoint),
|
|
331
|
+
t.distanceFrom(n.firstPoint),
|
|
332
|
+
t.distanceFrom(n.lastPoint)
|
|
171
333
|
);
|
|
172
334
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
335
|
+
const $t = (t, n) => {
|
|
336
|
+
const e = t.angleToParam(n.firstAngle);
|
|
337
|
+
if (t.isValidParameter(e))
|
|
338
|
+
return !0;
|
|
339
|
+
const r = t.angleToParam(n.lastAngle);
|
|
340
|
+
return !!t.isValidParameter(r);
|
|
341
|
+
};
|
|
342
|
+
function yt(t, n) {
|
|
343
|
+
if (dt(t, n, !0).length > 0)
|
|
344
|
+
return 0;
|
|
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(
|
|
353
|
+
t.distanceFrom(n.firstPoint),
|
|
354
|
+
t.distanceFrom(n.lastPoint),
|
|
355
|
+
n.distanceFrom(t.firstPoint),
|
|
356
|
+
n.distanceFrom(t.lastPoint)
|
|
176
357
|
);
|
|
177
358
|
}
|
|
178
|
-
function
|
|
179
|
-
if (n instanceof
|
|
180
|
-
return
|
|
181
|
-
if (n instanceof
|
|
182
|
-
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
|
+
throw new Error("Not implemented");
|
|
369
|
+
}
|
|
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)
|
|
378
|
+
return [];
|
|
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)
|
|
389
|
+
throw new Error("Bug in the offset algorithm");
|
|
390
|
+
yield s;
|
|
391
|
+
};
|
|
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;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
let f = [];
|
|
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
|
|
404
|
+
);
|
|
405
|
+
f = [
|
|
406
|
+
...w,
|
|
407
|
+
...d.flatMap((h) => [h.firstPoint, h.lastPoint])
|
|
408
|
+
];
|
|
409
|
+
}
|
|
410
|
+
if (f.length > 0) {
|
|
411
|
+
let w = f[0];
|
|
412
|
+
if (f.length > 1) {
|
|
413
|
+
const x = i == null ? void 0 : i.original.lastPoint, y = f.map(
|
|
414
|
+
(at) => vt(at, x)
|
|
415
|
+
);
|
|
416
|
+
w = f[y.indexOf(Math.min(...y))];
|
|
417
|
+
}
|
|
418
|
+
const d = i.offset.splitAt([
|
|
419
|
+
w
|
|
420
|
+
])[0], h = c.offset.splitAt([w]).at(-1);
|
|
421
|
+
if (!h)
|
|
422
|
+
throw new Error("Bug in the splitting algo in offset");
|
|
423
|
+
o({
|
|
424
|
+
offset: d,
|
|
425
|
+
original: i.original
|
|
426
|
+
}), i = { offset: h, original: c.original };
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
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]);
|
|
444
|
+
};
|
|
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);
|
|
453
|
+
});
|
|
454
|
+
d.length && (i(f, d), i(v + f + 1, d));
|
|
455
|
+
});
|
|
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))
|
|
475
|
+
);
|
|
476
|
+
return Mt(W(r.contour, n), s);
|
|
477
|
+
});
|
|
478
|
+
return U(e);
|
|
479
|
+
}
|
|
480
|
+
function Ut(t, n) {
|
|
481
|
+
return kt(E(t), n);
|
|
482
|
+
}
|
|
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(" ")}`;
|
|
183
488
|
throw new Error("Unknown segment type");
|
|
184
489
|
}
|
|
185
|
-
function
|
|
186
|
-
const
|
|
187
|
-
return `${
|
|
490
|
+
function rt(t) {
|
|
491
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(R).join(" ");
|
|
492
|
+
return `${n} ${e} Z`;
|
|
188
493
|
}
|
|
189
|
-
function
|
|
190
|
-
return `<path d="${
|
|
494
|
+
function it(t) {
|
|
495
|
+
return `<path d="${t.allLoops.map(rt).join(" ")}" />`;
|
|
191
496
|
}
|
|
192
|
-
function
|
|
497
|
+
function It(t) {
|
|
193
498
|
return `<g>
|
|
194
|
-
${
|
|
499
|
+
${t.figures.map(it).join(`
|
|
195
500
|
`)}
|
|
196
501
|
</g>`;
|
|
197
502
|
}
|
|
198
|
-
function
|
|
199
|
-
const
|
|
200
|
-
return `${
|
|
503
|
+
function Ot(t) {
|
|
504
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(R).join(" ");
|
|
505
|
+
return `${n} ${e}`;
|
|
201
506
|
}
|
|
202
|
-
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) {
|
|
203
512
|
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
204
|
-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${
|
|
205
|
-
${
|
|
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}
|
|
206
515
|
</svg>`;
|
|
207
516
|
}
|
|
208
|
-
function
|
|
209
|
-
if (
|
|
210
|
-
return
|
|
211
|
-
if (
|
|
212
|
-
return
|
|
213
|
-
if (
|
|
214
|
-
return `<path d="${
|
|
215
|
-
if (
|
|
216
|
-
return `<path d="${
|
|
217
|
-
|
|
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
|
|
218
529
|
)}" />`;
|
|
219
530
|
throw new Error("Unknown shape type");
|
|
220
531
|
}
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
|
239
560
|
);
|
|
240
561
|
throw new Error("Unknown segment type");
|
|
241
|
-
},
|
|
242
|
-
const
|
|
243
|
-
return new
|
|
244
|
-
},
|
|
245
|
-
const
|
|
246
|
-
return new
|
|
247
|
-
},
|
|
248
|
-
const
|
|
249
|
-
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);
|
|
250
571
|
};
|
|
251
|
-
function
|
|
252
|
-
if (
|
|
253
|
-
return
|
|
254
|
-
if (
|
|
255
|
-
return
|
|
256
|
-
if (
|
|
257
|
-
return
|
|
258
|
-
if (
|
|
259
|
-
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);
|
|
260
581
|
throw new Error("Unknown shape type");
|
|
261
582
|
}
|
|
262
|
-
const
|
|
263
|
-
function
|
|
264
|
-
const
|
|
265
|
-
return [
|
|
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];
|
|
266
587
|
}
|
|
267
|
-
function
|
|
268
|
-
const
|
|
269
|
-
return [
|
|
588
|
+
function Wt([t, n]) {
|
|
589
|
+
const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) * Vt;
|
|
590
|
+
return [e, r];
|
|
270
591
|
}
|
|
271
592
|
export {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
|
285
607
|
};
|
|
286
608
|
//# sourceMappingURL=pantograph.js.map
|