pantograph2d 0.4.0 → 0.6.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.
Files changed (105) hide show
  1. package/dist/Diagram-ab93c8b7.cjs +11 -0
  2. package/dist/Diagram-ab93c8b7.cjs.map +1 -0
  3. package/dist/Diagram-d848c815.js +4252 -0
  4. package/dist/Diagram-d848c815.js.map +1 -0
  5. package/dist/draw-0f591ea4.cjs +2 -0
  6. package/dist/draw-0f591ea4.cjs.map +1 -0
  7. package/dist/draw-a830827a.js +288 -0
  8. package/dist/draw-a830827a.js.map +1 -0
  9. package/dist/pantograph/drawShape.cjs +1 -1
  10. package/dist/pantograph/drawShape.cjs.map +1 -1
  11. package/dist/pantograph/drawShape.js +13 -17
  12. package/dist/pantograph/drawShape.js.map +1 -1
  13. package/dist/pantograph/models.cjs +1 -1
  14. package/dist/pantograph/models.js +5 -5
  15. package/dist/pantograph.cjs +6 -6
  16. package/dist/pantograph.cjs.map +1 -1
  17. package/dist/pantograph.js +501 -294
  18. package/dist/pantograph.js.map +1 -1
  19. package/dist/types/algorithms/boolean/figureBooleans.d.ts +8 -0
  20. package/dist/types/algorithms/boolean/loopBooleans.d.ts +14 -0
  21. package/dist/types/algorithms/boolean/strandBoolean.d.ts +8 -0
  22. package/dist/types/algorithms/boolean/strandsBetweenIntersections.d.ts +4 -0
  23. package/dist/types/algorithms/distances/arcArcDistance.d.ts +2 -0
  24. package/dist/types/algorithms/distances/genericDistance.d.ts +6 -0
  25. package/dist/types/algorithms/distances/index.d.ts +2 -0
  26. package/dist/types/algorithms/distances/lineArcDistance.d.ts +3 -0
  27. package/dist/types/algorithms/distances/lineLineDistance.d.ts +2 -0
  28. package/dist/types/algorithms/filletSegments.d.ts +3 -0
  29. package/dist/types/algorithms/intersections/arcArcIntersection.d.ts +3 -0
  30. package/dist/types/algorithms/intersections/arcEllipseArcIntersection.d.ts +3 -0
  31. package/dist/types/algorithms/intersections/ellipseArcEllipseArcIntersection.d.ts +3 -0
  32. package/dist/types/algorithms/intersections/ellipseEllipseIntersection.d.ts +4 -0
  33. package/dist/types/algorithms/intersections/index.d.ts +8 -0
  34. package/dist/types/algorithms/intersections/lineArcIntersection.d.ts +4 -0
  35. package/dist/types/algorithms/intersections/lineEllipseArcIntersection.d.ts +4 -0
  36. package/dist/types/algorithms/intersections/lineLineIntersection.d.ts +28 -0
  37. package/dist/types/algorithms/intersections/rayIntersections.d.ts +3 -0
  38. package/dist/types/algorithms/offsets/offsetFigure.d.ts +4 -0
  39. package/dist/types/algorithms/offsets/offsetSegment.d.ts +12 -0
  40. package/dist/types/algorithms/offsets/offsetStroke.d.ts +9 -0
  41. package/dist/types/algorithms/optimisation/DiRect.d.ts +45 -0
  42. package/dist/types/algorithms/organiseLoops.d.ts +9 -0
  43. package/dist/types/algorithms/simplify.d.ts +3 -0
  44. package/dist/types/algorithms/solvers/solvePolynomials.d.ts +4 -0
  45. package/dist/types/algorithms/stitchSegments.d.ts +2 -0
  46. package/dist/types/api/drawShape.d.ts +2 -0
  47. package/dist/types/api/models.d.ts +1 -0
  48. package/dist/types/booleanOperations.d.ts +11 -0
  49. package/dist/types/definitions.d.ts +2 -0
  50. package/dist/types/draw.d.ts +47 -0
  51. package/dist/types/drawShape/drawCircle.d.ts +2 -0
  52. package/dist/types/drawShape/drawRect.d.ts +5 -0
  53. package/dist/types/export/json/exportJSON.d.ts +196 -0
  54. package/dist/types/export/json/jsonDiagram.d.ts +69 -0
  55. package/dist/types/export/json/jsonFigure.d.ts +66 -0
  56. package/dist/types/export/json/jsonLoop.d.ts +32 -0
  57. package/dist/types/export/json/jsonSegment.d.ts +29 -0
  58. package/dist/types/export/svg/exportSVG.d.ts +18 -0
  59. package/dist/types/export/svg/svgDiagram.d.ts +2 -0
  60. package/dist/types/export/svg/svgFigure.d.ts +2 -0
  61. package/dist/types/export/svg/svgLoop.d.ts +2 -0
  62. package/dist/types/export/svg/svgSegment.d.ts +2 -0
  63. package/dist/types/export/svg/svgStrand.d.ts +2 -0
  64. package/dist/types/export/svg/wrapSVG.d.ts +4 -0
  65. package/dist/types/import/json/importJSON.d.ts +7 -0
  66. package/dist/types/main.d.ts +12 -0
  67. package/dist/types/models/BoundingBox.d.ts +15 -0
  68. package/dist/types/models/Diagram.d.ts +25 -0
  69. package/dist/types/models/Figure.d.ts +23 -0
  70. package/dist/types/models/Loop.d.ts +18 -0
  71. package/dist/types/models/Strand.d.ts +10 -0
  72. package/dist/types/models/Stroke.d.ts +29 -0
  73. package/dist/types/models/TransformationMatrix.d.ts +31 -0
  74. package/dist/types/models/exports.d.ts +11 -0
  75. package/dist/types/models/segments/Arc.d.ts +52 -0
  76. package/dist/types/models/segments/EllipseArc.d.ts +70 -0
  77. package/dist/types/models/segments/Line.d.ts +32 -0
  78. package/dist/types/models/segments/Segment.d.ts +28 -0
  79. package/dist/types/models/utils/Transformable.d.ts +14 -0
  80. package/dist/types/offsetOperations.d.ts +8 -0
  81. package/dist/types/operations.d.ts +2 -0
  82. package/dist/types/utils/allCombinations.d.ts +2 -0
  83. package/dist/types/utils/allPairs.d.ts +1 -0
  84. package/dist/types/utils/angularDistance.d.ts +1 -0
  85. package/dist/types/utils/listOfFigures.d.ts +4 -0
  86. package/dist/types/utils/projectPointOnLine.d.ts +3 -0
  87. package/dist/types/utils/range.d.ts +1 -0
  88. package/dist/types/utils/removeDuplicatePoints.d.ts +2 -0
  89. package/dist/types/utils/unitAngle.d.ts +1 -0
  90. package/dist/types/utils/zip.d.ts +3 -0
  91. package/dist/types/vectorOperations.d.ts +23 -0
  92. package/package.json +29 -10
  93. package/dist/Diagram-1c56996e.js +0 -1698
  94. package/dist/Diagram-1c56996e.js.map +0 -1
  95. package/dist/Diagram-4fa55d2b.cjs +0 -4
  96. package/dist/Diagram-4fa55d2b.cjs.map +0 -1
  97. package/dist/draw-44dd36a9.js +0 -256
  98. package/dist/draw-44dd36a9.js.map +0 -1
  99. package/dist/draw-8c69c65f.cjs +0 -2
  100. package/dist/draw-8c69c65f.cjs.map +0 -1
  101. package/dist/drawShape.d.ts +0 -153
  102. package/dist/models.d.ts +0 -210
  103. package/dist/pantograph/drawShape.d.ts +0 -1
  104. package/dist/pantograph/models.d.ts +0 -1
  105. package/dist/pantograph.d.ts +0 -388
@@ -1,169 +1,169 @@
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)
1
+ import { o as ht, D } from "./draw-a830827a.js";
2
+ import { d as fn } from "./draw-a830827a.js";
3
+ import { F as p, L as P, D as h, f as C, r as gt, z as pt, s as dt, a as wt, c as Pt, i as mt, S as y, l as Mt, d as m, b as vt, p as St, n as K, e as $, g as It, h as Lt, j as kt, k as At, m as Q, o as w, A as M, q as j, t as v, u as $t, v as bt, E as O, R as Et } from "./Diagram-d848c815.js";
4
+ import { w as un } from "./Diagram-d848c815.js";
5
+ function S(t) {
6
+ if (t instanceof p)
7
7
  return [t];
8
- if (t instanceof $)
9
- return [new h(t)];
10
8
  if (t instanceof P)
9
+ return [new p(t)];
10
+ if (t instanceof h)
11
11
  return t.figures;
12
12
  throw new Error("Unknown shape");
13
13
  }
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,
14
+ function tt(t, n, e = 1e-9) {
15
+ let s = [];
16
+ const r = [], i = new Array(n.segments.length).fill(0).map(() => []);
17
+ n.segments.forEach((c, f) => {
18
+ t.segments.forEach((a) => {
19
+ const { intersections: u, overlaps: d } = C(
20
+ c,
21
+ a,
22
22
  e
23
23
  );
24
- r.push(...f), s[i].push(...f), o.push(...c);
25
- const l = c.flatMap((S) => [
26
- S.firstPoint,
27
- S.lastPoint
24
+ s.push(...u), i[f].push(...u), r.push(...d);
25
+ const g = d.flatMap((l) => [
26
+ l.firstPoint,
27
+ l.lastPoint
28
28
  ]);
29
- r.push(...l), s[i].push(...l);
29
+ s.push(...g), i[f].push(...g);
30
30
  });
31
- }), r = et(r, e);
32
- const a = st([n.segments, s]).flatMap(([u, i]) => i.length ? u.splitAt(i) : [u]);
31
+ }), s = gt(s, e);
32
+ const o = pt([n.segments, i]).flatMap(([c, f]) => f.length ? c.splitAt(f) : [c]);
33
33
  return Array.from(
34
- rt(
35
- a,
36
- r,
37
- o
34
+ dt(
35
+ o,
36
+ s,
37
+ r
38
38
  )
39
39
  );
40
40
  }
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);
41
+ function G(t, n, e = !1) {
42
+ return tt(n, t).filter((r) => {
43
+ const i = r.segments[0].midPoint;
44
+ return n.onStroke(i) ? !e : !n.contains(i);
45
45
  });
46
46
  }
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);
47
+ function T(t, n, e = !1) {
48
+ return tt(n, t).filter((r) => {
49
+ const i = r.segments[0].midPoint;
50
+ return n.onStroke(i) ? !e : n.contains(i);
51
51
  });
52
52
  }
53
- function V(t, n, e = !1) {
54
- const r = O(
53
+ function z(t, n, e = !1) {
54
+ const s = G(
55
55
  t,
56
56
  n.contour,
57
57
  e
58
- ), o = n.holes.flatMap(
59
- (s) => x(t, s, e)
58
+ ), r = n.holes.flatMap(
59
+ (i) => T(t, i, e)
60
60
  );
61
- return [...r, ...o];
61
+ return [...s, ...r];
62
62
  }
63
- function T(t, n, e = !1) {
64
- let r = x(
63
+ function q(t, n, e = !1) {
64
+ let s = T(
65
65
  t,
66
66
  n.contour,
67
67
  e
68
68
  );
69
- return n.holes.forEach((o) => {
70
- r = r.flatMap(
71
- (s) => O(s, o, e)
69
+ return n.holes.forEach((r) => {
70
+ s = s.flatMap(
71
+ (i) => G(i, r, e)
72
72
  );
73
- }), r;
73
+ }), s;
74
74
  }
75
- function St(t, n) {
76
- return new P(
77
- ot(F(t), F(n))
75
+ function yt(t, n) {
76
+ return new h(
77
+ wt(S(t), S(n))
78
78
  );
79
79
  }
80
- function R(t) {
80
+ function b(t) {
81
81
  return t.reduce(
82
- (n, e) => St(n, e),
83
- new P()
82
+ (n, e) => yt(n, e),
83
+ new h()
84
84
  );
85
85
  }
86
- function Mt(t, n) {
87
- return new P(
88
- it(F(t), F(n))
86
+ function nt(t, n) {
87
+ return new h(
88
+ Pt(S(t), S(n))
89
89
  );
90
90
  }
91
- function xt(t, n) {
92
- return new P(
93
- ft(F(t), F(n))
91
+ function Kt(t, n) {
92
+ return new h(
93
+ mt(S(t), S(n))
94
94
  );
95
95
  }
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)
96
+ function Qt(t, n, e = !0) {
97
+ if (n instanceof P)
98
+ return G(t, n, e);
99
+ if (n instanceof p)
100
+ return z(t, n, e);
101
+ let s = [new y([...t.segments])];
102
+ return n.figures.forEach((r) => {
103
+ s = s.flatMap((i) => z(i, r, e));
104
+ }), s;
105
+ }
106
+ function jt(t, n, e = !1) {
107
+ if (n instanceof P)
110
108
  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) {
109
+ if (n instanceof p)
110
+ return q(t, n, e);
111
+ let s = [new y([...t.segments])];
112
+ return n.figures.forEach((r) => {
113
+ s = s.flatMap((i) => q(i, r, e));
114
+ }), s;
115
+ }
116
+ function N(t) {
117
117
  return t < 0 ? "before" : t > 1 ? "after" : "between";
118
118
  }
119
- const N = (t, n, e) => {
119
+ const _ = (t, n, e) => {
120
120
  if (e === "before")
121
121
  return t.distanceFrom(n.firstPoint);
122
122
  if (e === "after")
123
123
  return t.distanceFrom(n.lastPoint);
124
124
  throw new Error("Invalid position");
125
125
  };
126
- function At(t, n) {
127
- const e = at(t, n);
126
+ function Ft(t, n) {
127
+ const e = Mt(t, n);
128
128
  if (e === "parallel")
129
129
  return Math.min(
130
130
  t.distanceFrom(n.firstPoint),
131
131
  t.distanceFrom(n.lastPoint)
132
132
  );
133
- const { intersectionParam1: r, intersectionParam2: o } = e, s = U(r), a = U(o);
134
- if (s === "between" && a === "between")
133
+ const { intersectionParam1: s, intersectionParam2: r } = e, i = N(s), o = N(r);
134
+ if (i === "between" && o === "between")
135
135
  return 0;
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);
136
+ if (i === "between" && o !== "between")
137
+ return _(t, n, o);
138
+ if (o === "between" && i !== "between")
139
+ return _(n, t, i);
140
+ if (i === "before" && o === "before")
141
+ return m(t.firstPoint, n.firstPoint);
142
+ if (i === "after" && o === "after")
143
+ return m(t.lastPoint, n.lastPoint);
144
+ if (i === "before" && o === "after")
145
+ return m(t.firstPoint, n.lastPoint);
146
+ if (i === "after" && o === "before")
147
+ return m(t.lastPoint, n.firstPoint);
148
148
  throw new Error("Invalid position");
149
149
  }
150
- function z(t, n) {
151
- if (ct(t, n).length > 0)
150
+ function J(t, n) {
151
+ if (vt(t, n).length > 0)
152
152
  return 0;
153
- const e = ut(t, n.center);
153
+ const e = St(t, n.center);
154
154
  if (t.isOnSegment(e)) {
155
- const r = g(e, n.center);
156
- if (Math.abs(r - n.radius) < t.precision && n.isOnSegment(e))
155
+ const s = m(e, n.center);
156
+ if (Math.abs(s - n.radius) < t.precision && n.isOnSegment(e))
157
157
  return 0;
158
- if (r - n.radius > t.precision) {
159
- const o = Z(
160
- E(e, n.center)
161
- ), s = lt(
158
+ if (s - n.radius > t.precision) {
159
+ const r = K(
160
+ $(e, n.center)
161
+ ), i = It(
162
162
  n.center,
163
- pt(o, n.radius)
163
+ Lt(r, n.radius)
164
164
  );
165
- if (n.isOnSegment(s))
166
- return g(s, e);
165
+ if (n.isOnSegment(i))
166
+ return m(i, e);
167
167
  }
168
168
  }
169
169
  return Math.min(
@@ -173,279 +173,486 @@ function z(t, n) {
173
173
  t.distanceFrom(n.lastPoint)
174
174
  );
175
175
  }
176
- const Lt = (t, n) => {
176
+ const Dt = (t, n) => {
177
177
  const e = t.angleToParam(n.firstAngle);
178
178
  if (t.isValidParameter(e))
179
179
  return !0;
180
- const r = t.angleToParam(n.lastAngle);
181
- return !!t.isValidParameter(r);
180
+ const s = t.angleToParam(n.lastAngle);
181
+ return !!t.isValidParameter(s);
182
182
  };
183
- function $t(t, n) {
184
- if (Pt(t, n, !0).length > 0)
183
+ function xt(t, n) {
184
+ if (kt(t, n, !0).length > 0)
185
185
  return 0;
186
- const e = g(t.center, n.center);
187
- if (e < t.precision && Lt(t, n))
186
+ const e = m(t.center, n.center);
187
+ if (e < t.precision && Dt(t, n))
188
188
  return Math.abs(t.radius - n.radius);
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(
189
+ const s = K($(n.center, t.center)), r = e - Math.abs(t.radius - n.radius) < t.precision;
190
+ let i = At(s);
191
+ r && n.radius > t.radius && (i += Math.PI);
192
+ const o = r ? i : i + Math.PI, c = t.angleToParam(i), f = n.angleToParam(o);
193
+ return t.isValidParameter(c) && n.isValidParameter(f) ? m(t.paramPoint(c), n.paramPoint(f)) : Math.min(
194
194
  t.distanceFrom(n.firstPoint),
195
195
  t.distanceFrom(n.lastPoint),
196
196
  n.distanceFrom(t.firstPoint),
197
197
  n.distanceFrom(t.lastPoint)
198
198
  );
199
199
  }
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)
204
- return z(t, n);
205
- if (t instanceof w && n instanceof d)
206
- return z(n, t);
207
- if (t instanceof w && n instanceof w)
208
- return $t(t, n);
209
- throw new Error("Not implemented");
210
- }
211
- const I = 1e-8;
212
- function vt(t, n) {
213
- const e = t.map((i) => ({
214
- offset: nt(i, n),
215
- original: i
200
+ function Rt(t, n, e) {
201
+ let s = 0, r = t.length - 1;
202
+ for (; s <= r; ) {
203
+ const i = Math.floor((s + r) / 2), o = e(t[i], n);
204
+ if (o < 0)
205
+ s = i + 1;
206
+ else if (o > 0)
207
+ r = i - 1;
208
+ else
209
+ return i;
210
+ }
211
+ return -(s + 1);
212
+ }
213
+ function Ct(t, n, e) {
214
+ const s = Rt(t, n, e);
215
+ s < 0 ? t.splice(-(s + 1), 0, n) : t.splice(s, 0, n);
216
+ }
217
+ class Ot {
218
+ constructor() {
219
+ this.buckets = [];
220
+ }
221
+ addInterval(n) {
222
+ const e = this.buckets[n.rectangle.diagonalBucketIndex];
223
+ e === void 0 ? this.buckets[n.rectangle.diagonalBucketIndex] = [n] : Ct(e, n, (s, r) => s.value - r.value);
224
+ }
225
+ removeInterval(n) {
226
+ const e = this.buckets[n.rectangle.diagonalBucketIndex];
227
+ if (e === void 0)
228
+ throw new Error("Interval not found");
229
+ e.shift();
230
+ }
231
+ getBottomRightHullIntervals() {
232
+ const n = [];
233
+ for (let e = this.buckets.length - 1; e >= 0; e--) {
234
+ const s = this.buckets[e];
235
+ if (!s === void 0)
236
+ continue;
237
+ const r = s[0];
238
+ if (r !== void 0) {
239
+ if (!n.length) {
240
+ n.push(r);
241
+ continue;
242
+ }
243
+ for (; n.length && n[n.length - 1].value >= r.value; )
244
+ n.pop();
245
+ for (; n.length >= 2; ) {
246
+ const i = n[n.length - 1], o = n[n.length - 2], c = (r.value - o.value) / ((r.rectangle.diagonal - o.rectangle.diagonal) * 2);
247
+ if (o.value + (i.rectangle.diagonal - o.rectangle.diagonal) / 2 * c < i.value)
248
+ n.pop();
249
+ else
250
+ break;
251
+ }
252
+ n.push(r);
253
+ }
254
+ }
255
+ return n;
256
+ }
257
+ }
258
+ class Gt {
259
+ constructor(n, e) {
260
+ this.x = n, this.y = e, this.xLength = Math.pow(3, -n), this.yLength = Math.pow(3, -e), this.diagonal = Math.sqrt(
261
+ this.xLength * this.xLength + this.yLength * this.yLength
262
+ ), this.diagonalBucketIndex = n + e, this.index = `${n},${e}`;
263
+ }
264
+ }
265
+ class Tt {
266
+ constructor(n, e = 1e-8, s = 1e3, r = 1e-6) {
267
+ this.fcn = n, this.endTolerance = e, this.maxIterations = s, this.epsilon = r, this.fcn = n, this.epsilon = r, this.endTolerance = e, this.maxIterations = s, this.rectangles = /* @__PURE__ */ new Map(), this.buckets = new Ot();
268
+ const i = [0.5, 0.5], o = this.rect(0, 0), c = this.fcn(i);
269
+ this.buckets.addInterval(new A(i, c, o)), this.fMin = c, this.argMin = i, this.tol = o.diagonal;
270
+ }
271
+ registerInterval(n) {
272
+ this.buckets.addInterval(n), n.value <= this.fMin && (this.fMin = n.value, this.argMin = n.center, this.tol = n.rectangle.diagonal);
273
+ }
274
+ rect(n, e) {
275
+ const s = `${n},${e}`;
276
+ return this.rectangles.has(s) || this.rectangles.set(s, new Gt(n, e)), this.rectangles.get(s);
277
+ }
278
+ splitInterval(n) {
279
+ let e, s, r;
280
+ const [i, o] = n.center;
281
+ return n.rectangle.x <= n.rectangle.y ? (e = this.rect(n.rectangle.x + 1, n.rectangle.y), s = [i - e.xLength, o], r = [i + e.xLength, o]) : (e = this.rect(n.rectangle.x, n.rectangle.y + 1), s = [i, o - e.yLength], r = [i, o + e.yLength]), [
282
+ new A(s, this.fcn(s), e),
283
+ new A(n.center, n.value, e),
284
+ new A(r, this.fcn(r), e)
285
+ ];
286
+ }
287
+ single_iteration() {
288
+ const n = this.buckets.getBottomRightHullIntervals();
289
+ for (; n.length >= 2; ) {
290
+ const e = n[0], s = n[1], r = (s.value - e.value) / ((s.rectangle.diagonal - e.rectangle.diagonal) / 2), i = e.value - r * s.value / 2;
291
+ if ((this.fMin - i) / Math.abs(this.fMin) < this.epsilon)
292
+ n.shift();
293
+ else
294
+ break;
295
+ }
296
+ n.forEach((e) => {
297
+ this.buckets.removeInterval(e);
298
+ });
299
+ for (const e of n) {
300
+ const [s, r, i] = this.splitInterval(e);
301
+ this.registerInterval(s), this.registerInterval(r), this.registerInterval(i);
302
+ }
303
+ }
304
+ run() {
305
+ let n = 0;
306
+ for (; this.tol > this.endTolerance / 2 && (this.single_iteration(), n++, !(n > this.maxIterations)); )
307
+ ;
308
+ return {
309
+ fMin: this.fMin,
310
+ argMin: this.argMin,
311
+ tol: this.tol,
312
+ iterations: n
313
+ };
314
+ }
315
+ }
316
+ class A {
317
+ constructor(n, e, s) {
318
+ this.center = n, this.value = e, this.rectangle = s;
319
+ }
320
+ }
321
+ function Vt(t, n = 1e-8, e = 1e3, s = 1e-6) {
322
+ return new Tt(
323
+ t,
324
+ n,
325
+ e,
326
+ s
327
+ ).run();
328
+ }
329
+ function Ut(t, n, e = 1e-9) {
330
+ const s = Vt((r) => {
331
+ const i = t.paramPoint(r[0]), o = n.paramPoint(r[1]);
332
+ return Q(i, o);
333
+ }, e);
334
+ return Math.sqrt(s.fMin);
335
+ }
336
+ function Bt(t, n) {
337
+ return t instanceof w && n instanceof w ? Ft(t, n) : t instanceof w && n instanceof M ? J(t, n) : t instanceof M && n instanceof w ? J(n, t) : t instanceof M && n instanceof M ? xt(t, n) : Ut(t, n);
338
+ }
339
+ const V = 1e-8;
340
+ function x(t, n, e = !0) {
341
+ const s = t.map((a) => ({
342
+ offset: ht(a, n),
343
+ original: a
216
344
  })), r = [];
217
- let o = null, s = e.at(-1);
218
- if (!s)
219
- return [];
345
+ let i = e ? null : s.at(-1), o = e ? s.at(-1) : null;
220
346
  if (r.length === 1)
221
347
  return r;
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;
226
- }, u = function* () {
227
- for (const i of e.slice(0, -1))
228
- yield i;
229
- if (!o)
348
+ const c = (a) => {
349
+ i ? a.offset instanceof D ? v(a.offset.firstPoint, a.offset.lastPoint) || r.push(
350
+ new w(a.offset.firstPoint, a.offset.lastPoint)
351
+ ) : r.push(a.offset) : i = a;
352
+ }, f = function* () {
353
+ for (const a of s.slice(0, -1))
354
+ yield a;
355
+ if (!i)
230
356
  throw new Error("Bug in the offset algorithm");
231
- yield o;
357
+ yield i;
232
358
  };
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;
359
+ for (const a of f()) {
360
+ if (!o) {
361
+ o = a;
362
+ continue;
363
+ }
364
+ const u = o.offset.lastPoint, d = a.offset.firstPoint;
365
+ if (v(u, d)) {
366
+ c(o), o = a;
237
367
  continue;
238
368
  }
239
- let c = [];
240
- if (!(s.offset instanceof D) && !(i.offset instanceof D)) {
241
- const { intersections: M, overlaps: A } = C(
242
- s.offset,
243
- i.offset,
244
- I / 100
369
+ let g = [];
370
+ if (!(o.offset instanceof D) && !(a.offset instanceof D)) {
371
+ const { intersections: I, overlaps: F } = C(
372
+ o.offset,
373
+ a.offset,
374
+ V / 100
245
375
  );
246
- c = [
247
- ...M,
248
- ...A.flatMap((p) => [p.firstPoint, p.lastPoint])
376
+ g = [
377
+ ...I,
378
+ ...F.flatMap((L) => [L.firstPoint, L.lastPoint])
249
379
  ];
250
380
  }
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)
381
+ if (g.length > 0) {
382
+ let I = g[0];
383
+ if (g.length > 1) {
384
+ const lt = o == null ? void 0 : o.original.lastPoint, B = g.map(
385
+ (ut) => Q(ut, lt)
256
386
  );
257
- M = c[v.indexOf(Math.min(...v))];
387
+ I = g[B.indexOf(Math.min(...B))];
258
388
  }
259
- const A = s.offset.splitAt([
260
- M
261
- ])[0], p = i.offset.splitAt([M]).at(-1);
262
- if (!p)
389
+ const F = o.offset.splitAt([
390
+ I
391
+ ])[0], L = a.offset.splitAt([I]).at(-1);
392
+ if (!L)
263
393
  throw new Error("Bug in the splitting algo in offset");
264
- a({
265
- offset: A,
266
- original: s.original
267
- }), s = { offset: p, original: i.original };
394
+ c({
395
+ offset: F,
396
+ original: o.original
397
+ }), o = { offset: L, original: a.original };
268
398
  continue;
269
399
  }
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;
400
+ const l = o.original.lastPoint, k = bt(
401
+ $(d, l),
402
+ $(u, l)
403
+ ) > 0, ft = new M(u, d, l, k);
404
+ c(o), r.push(ft), o = a;
275
405
  }
276
- return a(s), r;
277
- }
278
- function q(t, n) {
279
- const e = t.clockwise ? n : -n, r = vt(t.segments, e);
280
- if (r.length < 2)
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]);
406
+ return o && c(o), r;
407
+ }
408
+ function et(t) {
409
+ const n = /* @__PURE__ */ new Map(), e = (s, r) => {
410
+ const i = n.get(s) || [];
411
+ n.set(s, [...i, ...r]);
285
412
  };
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);
413
+ return t.forEach((s, r) => {
414
+ t.slice(r + 1).forEach((i, o) => {
415
+ const { intersections: c, overlaps: f } = C(s, i, V), a = [
416
+ ...c,
417
+ ...f.flatMap((u) => [u.firstPoint, u.lastPoint])
418
+ ].filter((u) => {
419
+ const d = v(u, s.firstPoint) || v(u, s.lastPoint), g = v(u, i.firstPoint) || v(u, i.lastPoint);
420
+ return !(d && g);
294
421
  });
295
- A.length && (s(c, A), s(S + c + 1, A));
422
+ a.length && (e(r, a), e(o + r + 1, a));
296
423
  });
297
- }), !o.size) {
298
- const f = new $(r);
299
- return new P([new h(f)]);
424
+ }), n;
425
+ }
426
+ function st(t, n) {
427
+ return n.flatMap((e, s) => {
428
+ if (!t.has(s))
429
+ return e;
430
+ const r = t.get(s);
431
+ return r ? e.splitAt(r) : e;
432
+ });
433
+ }
434
+ function it(t, n, e) {
435
+ return t.filter((s) => !n.segments.some((i) => Bt(i, s) < Math.abs(e) - V));
436
+ }
437
+ function E(t, n) {
438
+ const e = t.clockwise ? n : -n, s = x(t.segments, e);
439
+ if (s.length < 2)
440
+ return new h();
441
+ const r = et(s);
442
+ if (!r.size) {
443
+ const a = new P(s);
444
+ return new h([new p(a)]);
300
445
  }
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));
446
+ const i = st(
447
+ r,
448
+ s
449
+ ), o = it(i, t, n);
450
+ if (!o.length)
451
+ return new h();
452
+ const f = j(o).filter((a) => a.length > 1).filter((a) => v(a[0].firstPoint, a.at(-1).lastPoint)).map((a) => new P(a));
453
+ return f.length ? new h(f.map((a) => new p(a))) : new h();
454
+ }
455
+ function zt(t, n, e = "round") {
456
+ const s = n / 2, r = x(t.segments, s, !1), i = x(t.segments, -s, !1).map(
457
+ (l) => l.reverse()
458
+ );
459
+ i.reverse();
460
+ const o = (l, k) => e === "round" ? $t(
461
+ l.lastPoint,
462
+ k.firstPoint,
463
+ l.tangentAtLastPoint
464
+ ) : new w(l.lastPoint, k.firstPoint), c = [
465
+ ...r,
466
+ o(
467
+ r[r.length - 1],
468
+ i[0]
469
+ ),
470
+ ...i,
471
+ o(
472
+ i[i.length - 1],
473
+ r[0]
474
+ )
475
+ ], f = et(c);
476
+ if (!f.size) {
477
+ const l = new P(c);
478
+ return new h([new p(l)]);
479
+ }
480
+ const a = st(
481
+ f,
482
+ c
483
+ ), u = it(a, t, s);
307
484
  if (!u.length)
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();
311
- }
312
- function Et(t, n) {
313
- const e = t.map((r) => {
314
- const o = R(
315
- r.holes.map((s) => q(s, n))
485
+ return new h();
486
+ const g = j(u).filter((l) => l.length > 1).filter((l) => v(l[0].firstPoint, l.at(-1).lastPoint)).map((l) => new P(l));
487
+ return g.length ? new h(g.map((l) => new p(l))) : new h();
488
+ }
489
+ function qt(t, n) {
490
+ const e = t.map((s) => {
491
+ const r = b(
492
+ s.holes.map((i) => E(i, n))
316
493
  );
317
- return Mt(q(r.contour, n), o);
494
+ return nt(E(s.contour, n), r);
318
495
  });
319
- return R(e);
496
+ return b(e);
497
+ }
498
+ function Nt(t, n) {
499
+ const e = Math.abs(n / 2), s = t.map(
500
+ (r) => b(
501
+ r.allLoops.map((i) => nt(E(i, e), E(i, -e)))
502
+ )
503
+ );
504
+ return b(s);
320
505
  }
321
- function Tt(t, n) {
322
- return Et(F(t), n);
506
+ function tn(t, n) {
507
+ return qt(S(t), n);
323
508
  }
324
- function G(t) {
325
- if (t instanceof d)
326
- return `L ${t.lastPoint.join(" ")}`;
509
+ function nn(t, n, { endCap: e = "round" } = {}) {
510
+ return t instanceof y ? zt(t, n, e) : Nt(S(t), n);
511
+ }
512
+ function U(t) {
327
513
  if (t instanceof w)
514
+ return `L ${t.lastPoint.join(" ")}`;
515
+ if (t instanceof M)
328
516
  return `A ${t.radius} ${t.radius} 0 ${t.angularLength > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${t.lastPoint.join(" ")}`;
517
+ if (t instanceof O)
518
+ return `A ${t.majorRadius} ${t.minorRadius} ${t.tiltAngle * Et} ${t.deltaAngle > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${t.lastPoint.join(" ")}`;
329
519
  throw new Error("Unknown segment type");
330
520
  }
331
- function K(t) {
332
- const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(G).join(" ");
521
+ function rt(t) {
522
+ const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(U).join(" ");
333
523
  return `${n} ${e} Z`;
334
524
  }
335
- function Q(t) {
336
- return `<path d="${t.allLoops.map(K).join(" ")}" />`;
525
+ function ot(t) {
526
+ return `<path d="${t.allLoops.map(rt).join(" ")}" />`;
337
527
  }
338
- function yt(t) {
528
+ function _t(t) {
339
529
  return `<g>
340
- ${t.figures.map(Q).join(`
530
+ ${t.figures.map(ot).join(`
341
531
  `)}
342
532
  </g>`;
343
533
  }
344
- function bt(t) {
345
- const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(G).join(" ");
534
+ function Jt(t) {
535
+ const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(U).join(" ");
346
536
  return `${n} ${e}`;
347
537
  }
348
- function Dt(t, n = 1) {
349
- const e = t.xMin - n, r = t.yMin - n;
350
- return `${e} ${r} ${t.width + 2 * n} ${t.height + 2 * n}`;
538
+ function Ht(t, n = 1) {
539
+ const e = t.xMin - n, s = t.yMin - n;
540
+ return `${e} ${s} ${t.width + 2 * n} ${t.height + 2 * n}`;
351
541
  }
352
- function B(t, n, e = 1) {
542
+ function H(t, n, e = 1, s) {
543
+ const r = Ht(n, e), i = s ? `width="${n.width + 2 * e}${s}" height="${n.height + 2 * e}${s}"` : "";
353
544
  return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
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">
545
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${r}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke" ${i}>
355
546
  ${t}
356
547
  </svg>`;
357
548
  }
358
- function J(t) {
359
- if (t instanceof P)
360
- return yt(t);
549
+ function W(t) {
361
550
  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(
551
+ return _t(t);
552
+ if (t instanceof p)
553
+ return ot(t);
554
+ if (t instanceof P)
555
+ return `<path d="${rt(t)}" />`;
556
+ if (t instanceof y)
557
+ return `<path d="${Jt(t)}" />`;
558
+ if (t instanceof M || t instanceof w || t instanceof O)
559
+ return `<path d="${`M ${t.firstPoint.join(" ")}`} ${U(
369
560
  t
370
561
  )}" />`;
371
562
  throw new Error("Unknown shape type");
372
563
  }
373
- const W = (t) => "shape" in t ? t.shape : t, X = (t, n) => {
564
+ const X = (t) => "shape" in t ? t.shape : t, Y = (t, n) => {
374
565
  if (!("shape" in t))
375
566
  return n;
376
567
  const { color: e } = t;
377
568
  return e ? `<g stroke="${e}">${n}</g>` : n;
378
569
  };
379
- function Rt(t, n = 1) {
570
+ function en(t, {
571
+ margin: n = 1,
572
+ unit: e = null
573
+ } = {}) {
380
574
  if (Array.isArray(t)) {
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);
575
+ const r = t.map((c) => X(c).mirror()), i = r.map((c, f) => Y(t[f], W(c))).join(`
576
+ `), o = r.slice(1).reduce((c, f) => c.merge(f.boundingBox), r[0].boundingBox);
577
+ return H(i, o, n, e);
384
578
  }
385
- const e = W(t).mirror();
386
- return B(
387
- X(t, J(e)),
388
- e.boundingBox,
389
- n
579
+ const s = X(t).mirror();
580
+ return H(
581
+ Y(t, W(s)),
582
+ s.boundingBox,
583
+ n,
584
+ e
390
585
  );
391
586
  }
392
- const _ = (t) => {
587
+ const at = (t) => {
393
588
  if (t.type === "LINE")
394
- return new d(t.firstPoint, t.lastPoint);
589
+ return new w(t.firstPoint, t.lastPoint);
395
590
  if (t.type === "ARC")
396
- return new w(
591
+ return new M(
397
592
  t.firstPoint,
398
593
  t.lastPoint,
399
594
  t.center,
400
595
  t.clockwise
401
596
  );
597
+ if (t.type === "ELLIPSE_ARC")
598
+ return new O(
599
+ t.firstPoint,
600
+ t.lastPoint,
601
+ t.center,
602
+ t.majorRadius,
603
+ t.minorRadius,
604
+ t.tiltAngle,
605
+ t.clockwise,
606
+ { angleUnits: "rad" }
607
+ );
402
608
  throw new Error("Unknown segment type");
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);
609
+ }, R = (t) => {
610
+ const n = t.segments.map(at);
411
611
  return new P(n);
612
+ }, ct = (t) => {
613
+ const n = R(t.contour), e = t.holes.map(R);
614
+ return new p(n, e);
615
+ }, Wt = (t) => {
616
+ const n = t.figures.map(ct);
617
+ return new h(n);
412
618
  };
413
- function Ut(t) {
619
+ function sn(t) {
414
620
  if (t.type === "DIAGRAM")
415
- return It(t);
621
+ return Wt(t);
416
622
  if (t.type === "FIGURE")
417
- return j(t);
623
+ return ct(t);
418
624
  if (t.type === "LOOP")
419
- return k(t);
420
- if (t.type === "LINE" || t.type === "ARC")
421
- return _(t);
625
+ return R(t);
626
+ if (t.type === "LINE" || t.type === "ARC" || t.type === "ELLIPSE_ARC")
627
+ return at(t);
422
628
  throw new Error("Unknown shape type");
423
629
  }
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;
427
- return [e, r];
630
+ const Z = Math.PI / 180, Xt = 180 / Math.PI;
631
+ function rn(t, n) {
632
+ const e = Math.cos(n * Z) * t, s = Math.sin(n * Z) * t;
633
+ return [e, s];
428
634
  }
429
- function zt([t, n]) {
430
- const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) * kt;
431
- return [e, r];
635
+ function on([t, n]) {
636
+ const e = Math.sqrt(t * t + n * n), s = Math.atan2(n, t) * Xt;
637
+ return [e, s];
432
638
  }
433
639
  export {
434
- Y as DEG2RAD,
435
- kt as RAD2DEG,
436
- zt as cartesianToPolar,
437
- Vt as confineStrand,
438
- Mt as cut,
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
640
+ Z as DEG2RAD,
641
+ Xt as RAD2DEG,
642
+ on as cartesianToPolar,
643
+ jt as confineStrand,
644
+ nt as cut,
645
+ fn as draw,
646
+ Qt as eraseStrand,
647
+ un as exportJSON,
648
+ en as exportSVG,
649
+ yt as fuse,
650
+ b as fuseAll,
651
+ sn as importJSON,
652
+ Kt as intersect,
653
+ tn as offset,
654
+ nn as outlineStroke,
655
+ rn as polarToCartesian,
656
+ W as svgBody
450
657
  };
451
658
  //# sourceMappingURL=pantograph.js.map