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.
@@ -1,328 +1,169 @@
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);
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 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 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
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
- return this.pointer = n, this.firstPoint = n, this;
95
- }
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;
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
- n.firstPoint
233
- ), i = this.pendingSegments.map(
234
- (o) => o.transform(s).reverse()
235
- );
236
- return i.reverse(), N([
237
- ...this.pendingSegments,
238
- ...i
239
- ]);
240
- }
37
+ o
38
+ )
39
+ );
241
40
  }
242
- function Gt(t = [0, 0]) {
243
- return new Et(t);
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 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
- 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 Ft(t, n) {
255
- return new g(
256
- ht(E(t), E(n))
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 U(t) {
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) => Ft(n, e),
262
- new g()
82
+ (n, e) => St(n, e),
83
+ new P()
263
84
  );
264
85
  }
265
86
  function Mt(t, n) {
266
- return new g(
267
- gt(E(t), E(n))
87
+ return new P(
88
+ it(F(t), F(n))
268
89
  );
269
90
  }
270
- function Nt(t, n) {
271
- return new g(
272
- pt(E(t), E(n))
91
+ function xt(t, n) {
92
+ return new P(
93
+ ft(F(t), F(n))
273
94
  );
274
95
  }
275
- function Y(t) {
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 q = (t, n, e) => {
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 bt(t, n) {
286
- const e = mt(t, n);
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: s } = e, i = Y(r), o = Y(s);
293
- if (i === "between" && o === "between")
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 (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);
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 (Pt(t, n).length > 0)
151
+ if (ct(t, n).length > 0)
311
152
  return 0;
312
- const e = wt(t, n.center);
153
+ const e = ut(t, n.center);
313
154
  if (t.isOnSegment(e)) {
314
- const r = S(e, n.center);
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 s = tt(
319
- $(e, n.center)
320
- ), i = L(
159
+ const o = Z(
160
+ E(e, n.center)
161
+ ), s = lt(
321
162
  n.center,
322
- C(s, n.radius)
163
+ pt(o, n.radius)
323
164
  );
324
- if (n.isOnSegment(i))
325
- return S(i, e);
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 $t = (t, n) => {
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 yt(t, n) {
343
- if (dt(t, n, !0).length > 0)
183
+ function $t(t, n) {
184
+ if (Pt(t, n, !0).length > 0)
344
185
  return 0;
345
- const e = S(t.center, n.center);
346
- if (e < t.precision && $t(t, n))
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 = 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(
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 xt(t, n) {
360
- if (t instanceof p && n instanceof p)
361
- return bt(t, n);
362
- if (t instanceof p && n instanceof P)
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 P && n instanceof p)
205
+ if (t instanceof w && n instanceof d)
365
206
  return z(n, t);
366
- if (t instanceof P && n instanceof P)
367
- return yt(t, n);
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 Dt(t, n) {
372
- const e = t.map((c) => ({
373
- offset: k(c, n),
374
- original: c
212
+ function vt(t, n) {
213
+ const e = t.map((i) => ({
214
+ offset: nt(i, n),
215
+ original: i
375
216
  })), r = [];
376
- let s = null, i = e.at(-1);
377
- if (!i)
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 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;
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 c of e.slice(0, -1))
387
- yield c;
388
- if (!s)
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 s;
231
+ yield o;
391
232
  };
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;
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 f = [];
399
- if (!(i.offset instanceof F) && !(c.offset instanceof F)) {
400
- const { intersections: w, overlaps: d } = nt(
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
- f = [
406
- ...w,
407
- ...d.flatMap((h) => [h.firstPoint, h.lastPoint])
246
+ c = [
247
+ ...M,
248
+ ...A.flatMap((p) => [p.firstPoint, p.lastPoint])
408
249
  ];
409
250
  }
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)
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
- w = f[y.indexOf(Math.min(...y))];
257
+ M = c[v.indexOf(Math.min(...v))];
417
258
  }
418
- const d = i.offset.splitAt([
419
- w
420
- ])[0], h = c.offset.splitAt([w]).at(-1);
421
- if (!h)
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
- o({
424
- offset: d,
425
- original: i.original
426
- }), i = { offset: h, original: c.original };
264
+ a({
265
+ offset: A,
266
+ original: s.original
267
+ }), s = { offset: p, original: i.original };
427
268
  continue;
428
269
  }
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;
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 o(i), r;
276
+ return a(s), r;
436
277
  }
437
- function W(t, n) {
438
- const e = t.clockwise ? n : -n, r = Dt(t.segments, e);
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 g();
441
- const s = /* @__PURE__ */ new Map(), i = (a, f) => {
442
- const l = s.get(a) || [];
443
- s.set(a, [...l, ...f]);
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((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);
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
- d.length && (i(f, d), i(v + f + 1, d));
295
+ A.length && (s(c, A), s(S + c + 1, A));
455
296
  });
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));
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 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();
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 kt(t, n) {
312
+ function Et(t, n) {
472
313
  const e = t.map((r) => {
473
- const s = U(
474
- r.holes.map((i) => W(i, n))
314
+ const o = R(
315
+ r.holes.map((s) => q(s, n))
475
316
  );
476
- return Mt(W(r.contour, n), s);
317
+ return Mt(q(r.contour, n), o);
477
318
  });
478
- return U(e);
319
+ return R(e);
479
320
  }
480
- function Ut(t, n) {
481
- return kt(E(t), n);
321
+ function Tt(t, n) {
322
+ return Et(F(t), n);
482
323
  }
483
- function R(t) {
484
- if (t instanceof p)
324
+ function G(t) {
325
+ if (t instanceof d)
485
326
  return `L ${t.lastPoint.join(" ")}`;
486
- if (t instanceof P)
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 rt(t) {
491
- const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(R).join(" ");
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 it(t) {
495
- return `<path d="${t.allLoops.map(rt).join(" ")}" />`;
335
+ function Q(t) {
336
+ return `<path d="${t.allLoops.map(K).join(" ")}" />`;
496
337
  }
497
- function It(t) {
338
+ function yt(t) {
498
339
  return `<g>
499
- ${t.figures.map(it).join(`
340
+ ${t.figures.map(Q).join(`
500
341
  `)}
501
342
  </g>`;
502
343
  }
503
- function Ot(t) {
504
- const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(R).join(" ");
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 Rt(t, n = 1) {
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 J(t, n, e = 1) {
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="${Rt(n, e)}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke">
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 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(
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 Z = (t) => "shape" in t ? t.shape : t, H = (t, n) => {
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 Yt(t, n = 1) {
379
+ function Rt(t, n = 1) {
539
380
  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);
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 = Z(t).mirror();
545
- return J(
546
- H(t, X(e)),
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 st = (t) => {
392
+ const _ = (t) => {
552
393
  if (t.type === "LINE")
553
- return new p(t.firstPoint, t.lastPoint);
394
+ return new d(t.firstPoint, t.lastPoint);
554
395
  if (t.type === "ARC")
555
- return new P(
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
- }, 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);
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 qt(t) {
413
+ function Ut(t) {
573
414
  if (t.type === "DIAGRAM")
574
- return _t(t);
415
+ return It(t);
575
416
  if (t.type === "FIGURE")
576
- return ot(t);
417
+ return j(t);
577
418
  if (t.type === "LOOP")
578
- return O(t);
419
+ return k(t);
579
420
  if (t.type === "LINE" || t.type === "ARC")
580
- return st(t);
421
+ return _(t);
581
422
  throw new Error("Unknown shape type");
582
423
  }
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;
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 Wt([t, n]) {
589
- const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) * Vt;
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
- K as DEG2RAD,
594
- Vt as RAD2DEG,
595
- Wt as cartesianToPolar,
434
+ Y as DEG2RAD,
435
+ kt as RAD2DEG,
436
+ zt as cartesianToPolar,
437
+ Vt as confineStrand,
596
438
  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
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