pantograph2d 0.4.0 → 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.
@@ -50,7 +50,7 @@ function Q(e, t = 1e-9) {
50
50
  ).values()
51
51
  );
52
52
  }
53
- const qt = Math.PI / 180, I = (e) => `[${e[0]}, ${e[1]}]`, g = ([e, t], [n, s], i = 1e-9) => Math.abs(e - n) <= i && Math.abs(t - s) <= i, A = ([e, t], [n, s]) => [e + n, t + s], y = ([e, t], [n, s]) => [e - n, t - s], z = ([e, t]) => e * e + t * t, _ = ([e, t], n) => [e * n, t * n], Y = ([e, t], [n, s] = [0, 0]) => (e - n) ** 2 + (t - s) ** 2, k = (e, t = [0, 0]) => Math.sqrt(Y(e, t));
53
+ const qt = Math.PI / 180, y = (e) => `[${e[0]}, ${e[1]}]`, g = ([e, t], [n, s], i = 1e-9) => Math.abs(e - n) <= i && Math.abs(t - s) <= i, S = ([e, t], [n, s]) => [e + n, t + s], A = ([e, t], [n, s]) => [e - n, t - s], z = ([e, t]) => e * e + t * t, _ = ([e, t], n) => [e * n, t * n], Y = ([e, t], [n, s] = [0, 0]) => (e - n) ** 2 + (t - s) ** 2, k = (e, t = [0, 0]) => Math.sqrt(Y(e, t));
54
54
  function $([e, t], [n, s]) {
55
55
  return e * s - t * n;
56
56
  }
@@ -83,15 +83,15 @@ function tt(e) {
83
83
  return [e[1], -e[0]];
84
84
  }
85
85
  const T = (e, t) => {
86
- const [n, s, i, r, a, o, u, l, h] = e, [c, f, m, P, w, M, b, x, E] = t;
86
+ const [n, s, i, r, a, o, u, l, h] = e, [c, f, m, P, w, M, v, x, E] = t;
87
87
  return [
88
- n * c + s * P + i * b,
88
+ n * c + s * P + i * v,
89
89
  n * f + s * w + i * x,
90
90
  n * m + s * M + i * E,
91
- r * c + a * P + o * b,
91
+ r * c + a * P + o * v,
92
92
  r * f + a * w + o * x,
93
93
  r * m + a * M + o * E,
94
- u * c + l * P + h * b,
94
+ u * c + l * P + h * v,
95
95
  u * f + l * w + h * x,
96
96
  u * m + l * M + h * E
97
97
  ];
@@ -174,7 +174,7 @@ class It extends K {
174
174
  super(), this.firstPoint = t, this.lastPoint = n, this.precision = 1e-9, this.firstPoint = t, this.lastPoint = n;
175
175
  }
176
176
  get repr() {
177
- return `${this.segmentType} ${I(this.firstPoint)} - ${I(
177
+ return `${this.segmentType} ${y(this.firstPoint)} - ${y(
178
178
  this.lastPoint
179
179
  )}`;
180
180
  }
@@ -194,7 +194,7 @@ class d extends It {
194
194
  return t >= -n && 1 - t >= -n;
195
195
  }
196
196
  paramPoint(t) {
197
- return A(this.firstPoint, _(this.V, t));
197
+ return S(this.firstPoint, _(this.V, t));
198
198
  }
199
199
  get length() {
200
200
  return k(this.firstPoint, this.lastPoint);
@@ -203,10 +203,10 @@ class d extends It {
203
203
  return Y(this.firstPoint, this.lastPoint);
204
204
  }
205
205
  get V() {
206
- return this._V === null && (this._V = y(this.lastPoint, this.firstPoint)), this._V;
206
+ return this._V === null && (this._V = A(this.lastPoint, this.firstPoint)), this._V;
207
207
  }
208
208
  get midPoint() {
209
- return A(this.firstPoint, _(this.V, 0.5));
209
+ return S(this.firstPoint, _(this.V, 0.5));
210
210
  }
211
211
  isSame(t) {
212
212
  return t instanceof d ? g(this.firstPoint, t.firstPoint) && g(this.lastPoint, t.lastPoint) || g(this.lastPoint, t.firstPoint) && g(this.firstPoint, t.lastPoint) : !1;
@@ -226,7 +226,7 @@ class d extends It {
226
226
  )), this._boundingBox;
227
227
  }
228
228
  distanceFrom(t) {
229
- const n = y(t, this.firstPoint), s = st(n, this.V) / this.squareLength;
229
+ const n = A(t, this.firstPoint), s = st(n, this.V) / this.squareLength;
230
230
  if (s < 0)
231
231
  return k(t, this.firstPoint);
232
232
  if (s > 1)
@@ -237,7 +237,7 @@ class d extends It {
237
237
  isOnSegment(t) {
238
238
  if (g(t, this.firstPoint, this.precision))
239
239
  return !0;
240
- const n = y(t, this.firstPoint);
240
+ const n = A(t, this.firstPoint);
241
241
  if (!vt(this.V, n))
242
242
  return !1;
243
243
  const s = st(n, this.V) / this.squareLength;
@@ -264,7 +264,7 @@ class d extends It {
264
264
  Array.isArray(t[0]) ? n = t : n = [t], n.forEach((u) => {
265
265
  if (!this.isOnSegment(u))
266
266
  throw new Error(
267
- `Point ${I(u)} is not on segment ${this.repr}`
267
+ `Point ${y(u)} is not on segment ${this.repr}`
268
268
  );
269
269
  });
270
270
  const s = [this.firstPoint, ...n, this.lastPoint], i = Q(s), r = this.lastPoint[0] - this.firstPoint[0];
@@ -298,7 +298,7 @@ const Z = (e, t, n) => {
298
298
  const s = $(e.V, t.V), i = z(e.V), r = z(t.V), a = n ? n * n : e.precision * t.precision;
299
299
  if (s * s < i * r * a)
300
300
  return "parallel";
301
- const o = y(t.firstPoint, e.firstPoint), u = $(o, t.V) / s, l = $(o, e.V) / s;
301
+ const o = A(t.firstPoint, e.firstPoint), u = $(o, t.V) / s, l = $(o, e.V) / s;
302
302
  return {
303
303
  intersectionParam1: u,
304
304
  intersectionParam2: l
@@ -333,7 +333,7 @@ function _t(e, t, n = !1, s) {
333
333
  return !e.isValidParameter(r) || !t.isValidParameter(a) ? null : e.paramPoint(r);
334
334
  }
335
335
  const j = (e, t) => {
336
- const n = y(e, t);
336
+ const n = A(e, t);
337
337
  return Yt(n);
338
338
  };
339
339
  class p extends It {
@@ -343,14 +343,16 @@ class p extends It {
343
343
  throw new Error("Invalid arc, cannot be a full circle");
344
344
  if (Math.abs(this.radius - k(this.lastPoint, this.center)) > this.precision)
345
345
  throw new Error(
346
- "Invalid arc, radius does not match between start and end"
346
+ `Invalid arc, radius does not match between ${y(
347
+ t
348
+ )} and ${y(n)}} (center ${y(s)})`
347
349
  );
348
350
  }
349
351
  }
350
352
  get info() {
351
- return `ARC(${I(this.firstPoint)}, ${I(
353
+ return `ARC(${y(this.firstPoint)}, ${y(
352
354
  this.lastPoint
353
- )}, ${I(this.center)}, ${this.clockwise ? "CW" : "CCW"})`;
355
+ )}, ${y(this.center)}, ${this.clockwise ? "CW" : "CCW"})`;
354
356
  }
355
357
  isValidParameter(t) {
356
358
  return 1 - t >= -this.precision && t >= -this.precision;
@@ -366,7 +368,7 @@ class p extends It {
366
368
  )), this._angularLength;
367
369
  }
368
370
  paramPoint(t) {
369
- return A(
371
+ return S(
370
372
  this.center,
371
373
  R(
372
374
  this.radius,
@@ -378,12 +380,12 @@ class p extends It {
378
380
  const [n, s] = j(t, this.center);
379
381
  if (Math.abs(n - this.radius) > this.precision)
380
382
  throw new Error(
381
- `Point ${I(t)} is not on segment ${this.repr}`
383
+ `Point ${y(t)} is not on segment ${this.repr}`
382
384
  );
383
385
  const i = this.angleToParam(s);
384
386
  if (!this.isValidParameter(i))
385
387
  throw new Error(
386
- `Point ${I(t)} is not on segment ${this.repr}`
388
+ `Point ${y(t)} is not on segment ${this.repr}`
387
389
  );
388
390
  return i;
389
391
  }
@@ -392,14 +394,14 @@ class p extends It {
392
394
  }
393
395
  get firstAngle() {
394
396
  if (this._firstAngle === null) {
395
- const [t, n] = y(this.firstPoint, this.center);
397
+ const [t, n] = A(this.firstPoint, this.center);
396
398
  this._firstAngle = nt(Math.atan2(n, t));
397
399
  }
398
400
  return this._firstAngle;
399
401
  }
400
402
  get lastAngle() {
401
403
  if (this._lastAngle === null) {
402
- const [t, n] = y(this.lastPoint, this.center);
404
+ const [t, n] = A(this.lastPoint, this.center);
403
405
  this._lastAngle = nt(Math.atan2(n, t));
404
406
  }
405
407
  return this._lastAngle;
@@ -522,13 +524,13 @@ function pn(e, t, n) {
522
524
  if (o === "parallel")
523
525
  throw new Error("Cannot create an arc from three colinear points");
524
526
  const u = $(
525
- y(e, t),
526
- y(n, t)
527
+ A(e, t),
528
+ A(n, t)
527
529
  ) > 0;
528
530
  return new p(
529
531
  e,
530
532
  n,
531
- A(s.midPoint, _(r, o.intersectionParam1)),
533
+ S(s.midPoint, _(r, o.intersectionParam1)),
532
534
  u,
533
535
  { ignoreChecks: !0 }
534
536
  );
@@ -544,19 +546,19 @@ function dn(e, t, n) {
544
546
  );
545
547
  if (r === "parallel")
546
548
  throw new Error("Cannot create an arc from three colinear points");
547
- const a = A(
549
+ const a = S(
548
550
  s.midPoint,
549
551
  _(i, r.intersectionParam1)
550
552
  ), o = $(
551
- y(a, e),
552
- y(a, A(e, n))
553
+ A(a, e),
554
+ A(a, S(e, n))
553
555
  ) < 0;
554
556
  return new p(e, t, a, o, {
555
557
  ignoreChecks: !0
556
558
  });
557
559
  }
558
560
  function Nt(e, t) {
559
- const n = y(t, e.firstPoint), s = st(n, e.V) / e.squareLength;
561
+ const n = A(t, e.firstPoint), s = st(n, e.V) / e.squareLength;
560
562
  return e.paramPoint(s);
561
563
  }
562
564
  function G(e, t, n) {
@@ -569,9 +571,9 @@ function G(e, t, n) {
569
571
  }
570
572
  const a = [], o = Math.sqrt(
571
573
  t.radius * t.radius - r * r
572
- ), u = e.tangentAtFirstPoint, l = A(i, _(u, o));
574
+ ), u = e.tangentAtFirstPoint, l = S(i, _(u, o));
573
575
  e.isOnSegment(l) && t.isOnSegment(l) && a.push(l);
574
- const h = A(i, _(u, -o));
576
+ const h = S(i, _(u, -o));
575
577
  return e.isOnSegment(h) && t.isOnSegment(h) && a.push(h), a;
576
578
  }
577
579
  const Xt = (e) => {
@@ -624,24 +626,24 @@ function kt(e, t, n = !1, s) {
624
626
  return [];
625
627
  if (r < i)
626
628
  return o > i ? [] : n ? Rt(e, t) : [];
627
- const u = B(y(t.center, e.center)), l = r > a - i;
629
+ const u = B(A(t.center, e.center)), l = r > a - i;
628
630
  if (
629
631
  // circles are outside each other
630
632
  l || // circles are inside each other
631
633
  Math.abs(r - o) < i
632
634
  ) {
633
- const b = l || e.radius > t.radius ? 1 : -1, x = A(
635
+ const v = l || e.radius > t.radius ? 1 : -1, x = S(
634
636
  e.center,
635
- _(u, b * e.radius)
637
+ _(u, v * e.radius)
636
638
  );
637
639
  return e.isOnSegment(x) && t.isOnSegment(x) ? [x] : [];
638
640
  }
639
- const h = e.radius * e.radius / (2 * r) - t.radius * t.radius / (2 * r) + r / 2, c = A(
641
+ const h = e.radius * e.radius / (2 * r) - t.radius * t.radius / (2 * r) + r / 2, c = S(
640
642
  e.center,
641
643
  _(u, h)
642
644
  ), f = Math.sqrt(
643
645
  e.radius * e.radius - h * h
644
- ), m = F(u), P = A(c, _(m, f)), w = A(c, _(m, -f)), M = [];
646
+ ), m = F(u), P = S(c, _(m, f)), w = S(c, _(m, -f)), M = [];
645
647
  return e.isOnSegment(P) && t.isOnSegment(P) && M.push(P), e.isOnSegment(w) && t.isOnSegment(w) && M.push(w), M;
646
648
  }
647
649
  function Pn(e, t, n) {
@@ -828,16 +830,16 @@ function Vt(e) {
828
830
  }
829
831
  return t ? n : null;
830
832
  }
831
- class v extends Et {
833
+ class I extends Et {
832
834
  constructor() {
833
835
  super(...arguments), this.strokeType = "STRAND";
834
836
  }
835
837
  reverse() {
836
838
  const t = this.segments.map((n) => n.reverse());
837
- return t.reverse(), new v(t, { ignoreChecks: !0 });
839
+ return t.reverse(), new I(t, { ignoreChecks: !0 });
838
840
  }
839
841
  clone() {
840
- return new v(
842
+ return new I(
841
843
  this.segments.map((t) => t.clone()),
842
844
  { ignoreChecks: !0 }
843
845
  );
@@ -845,14 +847,14 @@ class v extends Et {
845
847
  extend(t) {
846
848
  if (!g(this.lastPoint, t.firstPoint))
847
849
  throw console.error(this.repr, t.repr), new Error("Cannot extend strand: connection point is not the same");
848
- return new v([...this.segments, ...t.segments]);
850
+ return new I([...this.segments, ...t.segments]);
849
851
  }
850
852
  simplify() {
851
853
  const t = Vt(this);
852
- return t ? new v(t, { ignoreChecks: !0 }) : this;
854
+ return t ? new I(t, { ignoreChecks: !0 }) : this;
853
855
  }
854
856
  transform(t) {
855
- return new v(
857
+ return new I(
856
858
  this.segments.map((n) => n.transform(t)),
857
859
  { ignoreChecks: !0 }
858
860
  );
@@ -981,7 +983,7 @@ function Jt(e) {
981
983
  function dt(e) {
982
984
  if (e instanceof V)
983
985
  return Jt(e);
984
- if (e instanceof S)
986
+ if (e instanceof b)
985
987
  return Ot(e);
986
988
  if (e instanceof O)
987
989
  return rt(e);
@@ -1217,12 +1219,12 @@ function Lt(e, t = 1e-7) {
1217
1219
  s.push(o);
1218
1220
  break;
1219
1221
  }
1220
- const [M, b] = w[0];
1221
- o.push(M), i.add(b), u = b;
1222
+ const [M, v] = w[0];
1223
+ o.push(M), i.add(v), u = v;
1222
1224
  }
1223
1225
  }), s;
1224
1226
  }
1225
- class S extends K {
1227
+ class b extends K {
1226
1228
  constructor(t, n = [], { ignoreChecks: s = !1 } = {}) {
1227
1229
  super(), s || tn(t, n), this.contour = t, this.holes = n;
1228
1230
  }
@@ -1236,13 +1238,13 @@ class S extends K {
1236
1238
  return [this.contour, ...this.holes];
1237
1239
  }
1238
1240
  clone() {
1239
- return new S(
1241
+ return new b(
1240
1242
  this.contour.clone(),
1241
1243
  this.holes.map((t) => t.clone())
1242
1244
  );
1243
1245
  }
1244
1246
  transform(t) {
1245
- return new S(
1247
+ return new b(
1246
1248
  this.contour.transform(t),
1247
1249
  this.holes.map((n) => n.transform(t))
1248
1250
  );
@@ -1256,8 +1258,8 @@ class S extends K {
1256
1258
  );
1257
1259
  }
1258
1260
  overlappingStrands(t) {
1259
- const n = t instanceof S ? t.allLoops : [t], s = this.allLoops.flatMap((i) => n.flatMap((r) => i.overlappingSegments(r)));
1260
- return Lt(s).map((i) => new v(i));
1261
+ const n = t instanceof b ? t.allLoops : [t], s = this.allLoops.flatMap((i) => n.flatMap((r) => i.overlappingSegments(r)));
1262
+ return Lt(s).map((i) => new I(i));
1261
1263
  }
1262
1264
  }
1263
1265
  function tn(e, t = []) {
@@ -1306,10 +1308,10 @@ const nn = (e) => {
1306
1308
  function D(e) {
1307
1309
  return nn(e).map(Tt).flatMap(ht).map((n) => {
1308
1310
  if (n.length === 1)
1309
- return new S(n[0].loop);
1311
+ return new b(n[0].loop);
1310
1312
  n.sort((r, a) => r.isIn.length - a.isIn.length);
1311
1313
  const [s, ...i] = n.map(({ loop: r }) => r);
1312
- return new S(s, i);
1314
+ return new b(s, i);
1313
1315
  });
1314
1316
  }
1315
1317
  function rn(e, t) {
@@ -1323,8 +1325,8 @@ function* Mt(e, t, n) {
1323
1325
  const s = (a) => t.some((o) => g(o, a.lastPoint)), i = (a) => n.some((o) => a.isSame(o));
1324
1326
  let r = [];
1325
1327
  for (const a of e)
1326
- s(a) ? (r.push(a), yield new v(r, { ignoreChecks: !0 }), r = []) : i(a) ? (r.length && (yield new v(r, { ignoreChecks: !0 }), r = []), yield new v([a], { ignoreChecks: !0 })) : r.push(a);
1327
- r.length && (yield new v(r, { ignoreChecks: !0 }));
1328
+ s(a) ? (r.push(a), yield new I(r, { ignoreChecks: !0 }), r = []) : i(a) ? (r.length && (yield new I(r, { ignoreChecks: !0 }), r = []), yield new I([a], { ignoreChecks: !0 })) : r.push(a);
1329
+ r.length && (yield new I(r, { ignoreChecks: !0 }));
1328
1330
  }
1329
1331
  const yt = (e, t) => {
1330
1332
  const n = e.findIndex((r) => g(t, r.firstPoint)), s = e.slice(0, n);
@@ -1359,13 +1361,13 @@ function an(e, t, n) {
1359
1361
  const i = [], r = new Array(e.segments.length).fill(0).map(() => []), a = new Array(t.segments.length).fill(0).map(() => []);
1360
1362
  if (e.segments.forEach((f, m) => {
1361
1363
  t.segments.forEach((P, w) => {
1362
- const { intersections: M, overlaps: b } = W(
1364
+ const { intersections: M, overlaps: v } = W(
1363
1365
  f,
1364
1366
  P,
1365
1367
  n
1366
1368
  );
1367
- s.push(...M), r[m].push(...M), a[w].push(...M), i.push(...b);
1368
- const x = b.flatMap((E) => [
1369
+ s.push(...M), r[m].push(...M), a[w].push(...M), i.push(...v);
1370
+ const x = v.flatMap((E) => [
1369
1371
  E.firstPoint,
1370
1372
  E.lastPoint
1371
1373
  ]);
@@ -1418,8 +1420,8 @@ function St(e) {
1418
1420
  t = t.extend(n);
1419
1421
  if (!g(t.firstPoint, t.lastPoint))
1420
1422
  throw console.error(
1421
- I(t.firstPoint),
1422
- I(t.lastPoint)
1423
+ y(t.firstPoint),
1424
+ y(t.lastPoint)
1423
1425
  ), new Error("Bug in the intersection algo on non closing strand");
1424
1426
  return new O(t.segments);
1425
1427
  }
@@ -1544,7 +1546,7 @@ function J(e, t) {
1544
1546
  } else if (t.isFull && !e.contour.intersects(t.contour))
1545
1547
  if (e.contour.contains(t.contour.firstPoint)) {
1546
1548
  const s = U(
1547
- e.holes.map((i) => new S(i)),
1549
+ e.holes.map((i) => new b(i)),
1548
1550
  [t]
1549
1551
  );
1550
1552
  return D([
@@ -1553,9 +1555,9 @@ function J(e, t) {
1553
1555
  ]);
1554
1556
  } else
1555
1557
  return [e];
1556
- let n = J(new S(e.contour), t);
1558
+ let n = J(new b(e.contour), t);
1557
1559
  return e.holes.forEach((s) => {
1558
- n = n.flatMap((i) => J(i, new S(s)));
1560
+ n = n.flatMap((i) => J(i, new b(s)));
1559
1561
  }), n;
1560
1562
  }
1561
1563
  function gn(e, t) {
@@ -1565,10 +1567,10 @@ function gn(e, t) {
1565
1567
  let s = D(n);
1566
1568
  return s = N(
1567
1569
  s,
1568
- e.holes.map((i) => new S(i))
1570
+ e.holes.map((i) => new b(i))
1569
1571
  ), N(
1570
1572
  s,
1571
- t.holes.map((i) => new S(i))
1573
+ t.holes.map((i) => new b(i))
1572
1574
  );
1573
1575
  }
1574
1576
  function U(e, t) {
@@ -1661,20 +1663,20 @@ export {
1661
1663
  Pn as C,
1662
1664
  V as D,
1663
1665
  tt as E,
1664
- S as F,
1666
+ b as F,
1665
1667
  pn as G,
1666
1668
  R as H,
1667
1669
  qt as I,
1668
1670
  O as L,
1669
- v as S,
1671
+ I as S,
1670
1672
  C as T,
1671
1673
  U as a,
1672
1674
  G as b,
1673
1675
  N as c,
1674
1676
  k as d,
1675
- y as e,
1677
+ A as e,
1676
1678
  W as f,
1677
- A as g,
1679
+ S as g,
1678
1680
  _ as h,
1679
1681
  at as i,
1680
1682
  kt as j,
@@ -1682,17 +1684,17 @@ export {
1682
1684
  Z as l,
1683
1685
  d as m,
1684
1686
  B as n,
1685
- g as o,
1687
+ Lt as o,
1686
1688
  Nt as p,
1687
- Lt as q,
1689
+ g as q,
1688
1690
  Q as r,
1689
1691
  Mt as s,
1690
1692
  Y as t,
1691
- $ as u,
1692
- dt as v,
1693
- K as w,
1694
- F as x,
1695
- dn as y,
1693
+ dn as u,
1694
+ $ as v,
1695
+ dt as w,
1696
+ K as x,
1697
+ F as y,
1696
1698
  L as z
1697
1699
  };
1698
- //# sourceMappingURL=Diagram-1c56996e.js.map
1700
+ //# sourceMappingURL=Diagram-9915ed5e.js.map