pantograph2d 0.5.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 +3 -3
  15. package/dist/pantograph.cjs +6 -6
  16. package/dist/pantograph.cjs.map +1 -1
  17. package/dist/pantograph.js +475 -334
  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-9915ed5e.js +0 -1700
  94. package/dist/Diagram-9915ed5e.js.map +0 -1
  95. package/dist/Diagram-c2ca1c3b.cjs +0 -4
  96. package/dist/Diagram-c2ca1c3b.cjs.map +0 -1
  97. package/dist/draw-25b9ed64.cjs +0 -2
  98. package/dist/draw-25b9ed64.cjs.map +0 -1
  99. package/dist/draw-cd61ec6b.js +0 -256
  100. package/dist/draw-cd61ec6b.js.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 -397
@@ -0,0 +1,4252 @@
1
+ function yt(i, t, n, e) {
2
+ return i <= e && t >= n;
3
+ }
4
+ class it {
5
+ constructor(t = 1 / 0, n = 1 / 0, e = -1 / 0, s = -1 / 0) {
6
+ this.xMin = t, this.yMin = n, this.xMax = e, this.yMax = s;
7
+ }
8
+ get width() {
9
+ return this.xMax - this.xMin;
10
+ }
11
+ get height() {
12
+ return this.yMax - this.yMin;
13
+ }
14
+ contains(t) {
15
+ const [n, e] = t;
16
+ return yt(this.xMin, this.xMax, n, n) && yt(this.yMin, this.yMax, e, e);
17
+ }
18
+ overlaps(t) {
19
+ return yt(this.xMin, this.xMax, t.xMin, t.xMax) && yt(this.yMin, this.yMax, t.yMin, t.yMax);
20
+ }
21
+ addPoint(t) {
22
+ const [n, e] = t;
23
+ return new it(
24
+ Math.min(this.xMin, n),
25
+ Math.min(this.yMin, e),
26
+ Math.max(this.xMax, n),
27
+ Math.max(this.yMax, e)
28
+ );
29
+ }
30
+ merge(t) {
31
+ return new it(
32
+ Math.min(this.xMin, t.xMin),
33
+ Math.min(this.yMin, t.yMin),
34
+ Math.max(this.xMax, t.xMax),
35
+ Math.max(this.yMax, t.yMax)
36
+ );
37
+ }
38
+ }
39
+ function De(i) {
40
+ return i.reduce((t, n) => t.addPoint(n), new it());
41
+ }
42
+ const Jt = (i, t = 1e-9) => {
43
+ let n = i;
44
+ return Math.abs(i) < t && (n = 0), n.toFixed(-Math.log10(t));
45
+ };
46
+ function ct(i, t = 1e-9) {
47
+ return Array.from(
48
+ new Map(
49
+ i.map(([n, e]) => [
50
+ `[${Jt(n, t)},${Jt(e, t)}]`,
51
+ [n, e]
52
+ ])
53
+ ).values()
54
+ );
55
+ }
56
+ const Lt = Math.PI / 180, Ue = 180 / Math.PI, T = (i) => `[${i[0]}, ${i[1]}]`, E = ([i, t], [n, e], s = 1e-9) => Math.abs(i - n) <= s && Math.abs(t - e) <= s, O = ([i, t], [n, e]) => [i + n, t + e], A = ([i, t], [n, e]) => [i - n, t - e], jt = ([i, t]) => i * i + t * t, D = ([i, t], n) => [i * n, t * n], mt = ([i, t], [n, e] = [0, 0]) => (i - n) ** 2 + (t - e) ** 2, q = (i, t = [0, 0]) => Math.sqrt(mt(i, t));
57
+ function at([i, t], [n, e]) {
58
+ return i * e - t * n;
59
+ }
60
+ function $t([i, t], [n, e]) {
61
+ return i * n + t * e;
62
+ }
63
+ function W([i, t]) {
64
+ const n = q([i, t]);
65
+ return [i / n, t / n];
66
+ }
67
+ function ft(i, t) {
68
+ const n = Math.cos(t) * i, e = Math.sin(t) * i;
69
+ return [n, e];
70
+ }
71
+ function Ye([i, t]) {
72
+ return Math.atan2(t, i);
73
+ }
74
+ function Xe(i) {
75
+ const t = q(i), n = Ye(i);
76
+ return [t, n];
77
+ }
78
+ function Vt(i, t, n = 1e-9) {
79
+ const e = at(i, t), s = jt(i), r = jt(t);
80
+ return e * e < s * r * n * n;
81
+ }
82
+ function J(i) {
83
+ return [-i[1], i[0]];
84
+ }
85
+ function bt(i) {
86
+ return [i[1], -i[0]];
87
+ }
88
+ function Ge(i, t, n) {
89
+ return E(n, i) || Vt(A(n, i), t);
90
+ }
91
+ const ot = (i, t) => {
92
+ const [n, e, s, r, o, h, u, l, c] = i, [a, g, w, m, d, P, f, p, y] = t;
93
+ return [
94
+ n * a + e * m + s * f,
95
+ n * g + e * d + s * p,
96
+ n * w + e * P + s * y,
97
+ r * a + o * m + h * f,
98
+ r * g + o * d + h * p,
99
+ r * w + o * P + h * y,
100
+ u * a + l * m + c * f,
101
+ u * g + l * d + c * p,
102
+ u * w + l * P + c * y
103
+ ];
104
+ }, We = (i) => {
105
+ const [t, n, e, s, r, o, h, u, l] = i, c = t * (r * l - o * u) - n * (s * l - o * h) + e * (s * u - r * h);
106
+ return [
107
+ (r * l - o * u) / c,
108
+ (e * u - n * l) / c,
109
+ (n * o - e * r) / c,
110
+ (o * h - s * l) / c,
111
+ (t * l - e * h) / c,
112
+ (e * s - t * o) / c,
113
+ (s * u - r * h) / c,
114
+ (n * h - t * u) / c,
115
+ (t * r - n * s) / c
116
+ ];
117
+ }, Je = (i) => {
118
+ const [t, n, e, s, r, o, h, u, l] = i;
119
+ return [t, s, h, n, r, u, e, o, l];
120
+ };
121
+ class V {
122
+ constructor(t) {
123
+ this._matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1], t && (this._matrix = [...t]);
124
+ }
125
+ clone() {
126
+ return new V(this._matrix);
127
+ }
128
+ transpose() {
129
+ return this._matrix = Je(this._matrix), this;
130
+ }
131
+ inverse() {
132
+ return this._matrix = We(this._matrix), this;
133
+ }
134
+ translate(t, n) {
135
+ return this._matrix = ot(this._matrix, [1, 0, t, 0, 1, n, 0, 0, 1]), this;
136
+ }
137
+ rotate(t, n) {
138
+ const e = Math.cos(t), s = Math.sin(t), r = [e, -s, 0, s, e, 0, 0, 0, 1];
139
+ return n && this.translate(n[0], n[1]), this._matrix = ot(this._matrix, r), n && this.translate(-n[0], -n[1]), this;
140
+ }
141
+ mirrorX() {
142
+ return this._matrix = ot(this._matrix, [1, 0, 0, 0, -1, 0, 0, 0, 1]), this;
143
+ }
144
+ mirrorY() {
145
+ return this._matrix = ot(this._matrix, [-1, 0, 0, 0, 1, 0, 0, 0, 1]), this;
146
+ }
147
+ mirrorLine(t, n) {
148
+ const [e, s] = t, r = Math.atan2(s, e);
149
+ return n && this.translate(n[0], n[1]), this.rotate(r), this.mirrorX(), this.rotate(-r), n && this.translate(-n[0], -n[1]), this;
150
+ }
151
+ mirrorCenter(t) {
152
+ return t && this.translate(t[0], t[1]), this._matrix = ot(this._matrix, [-1, 0, 0, 0, -1, 0, 0, 0, 1]), t && this.translate(-t[0], -t[1]), this;
153
+ }
154
+ scale(t, n) {
155
+ return n && this.translate(n[0], n[1]), this._matrix = ot(this._matrix, [t, 0, 0, 0, t, 0, 0, 0, 1]), n && this.translate(-n[0], -n[1]), this;
156
+ }
157
+ transform(t) {
158
+ const [n, e] = t, [s, r, o, h, u, l] = this._matrix;
159
+ return [s * n + r * e + o, h * n + u * e + l];
160
+ }
161
+ transformAngle(t) {
162
+ const [n, e] = this.transform([Math.cos(t), Math.sin(t)]), [s, r] = this.transform([0, 0]);
163
+ return Math.atan2(e - r, n - s);
164
+ }
165
+ keepsOrientation() {
166
+ const [t, , , , n] = this._matrix;
167
+ return t * n > 0;
168
+ }
169
+ scaleFactor() {
170
+ const [t, , , n] = this._matrix;
171
+ return Math.sqrt(t * t + n * n);
172
+ }
173
+ }
174
+ class _t {
175
+ translateX(t) {
176
+ const n = new V().translate(t, 0);
177
+ return this.transform(n);
178
+ }
179
+ translateY(t) {
180
+ const n = new V().translate(0, t);
181
+ return this.transform(n);
182
+ }
183
+ translate(t, n) {
184
+ const e = new V().translate(t, n);
185
+ return this.transform(e);
186
+ }
187
+ translateTo([t, n]) {
188
+ const e = new V().translate(t, n);
189
+ return this.transform(e);
190
+ }
191
+ rotate(t, n) {
192
+ const e = new V().rotate(
193
+ t * Lt,
194
+ n
195
+ );
196
+ return this.transform(e);
197
+ }
198
+ scale(t, n) {
199
+ const e = new V().scale(t, n);
200
+ return this.transform(e);
201
+ }
202
+ mirrorCenter(t) {
203
+ const n = new V().mirrorCenter(t);
204
+ return this.transform(n);
205
+ }
206
+ mirror(t = "x", n) {
207
+ const e = new V();
208
+ return t === "x" ? e.mirrorX() : t === "y" ? e.mirrorY() : e.mirrorLine(t, n), this.transform(e);
209
+ }
210
+ }
211
+ class zt extends _t {
212
+ constructor(t, n) {
213
+ super(), this.firstPoint = t, this.lastPoint = n, this.precision = 1e-9, this.firstPoint = t, this.lastPoint = n;
214
+ }
215
+ get repr() {
216
+ return `${this.segmentType} ${T(this.firstPoint)} - ${T(
217
+ this.lastPoint
218
+ )}`;
219
+ }
220
+ get info() {
221
+ return this.repr;
222
+ }
223
+ [Symbol.for("nodejs.util.inspect.custom")]() {
224
+ return this.repr;
225
+ }
226
+ }
227
+ class R extends zt {
228
+ constructor() {
229
+ super(...arguments), this.segmentType = "LINE", this._V = null, this._slope = null, this._yIntercept = null, this._boundingBox = null;
230
+ }
231
+ isValidParameter(t) {
232
+ const n = this.length * this.precision;
233
+ return t >= -n && 1 - t >= -n;
234
+ }
235
+ paramPoint(t) {
236
+ return O(this.firstPoint, D(this.V, t));
237
+ }
238
+ get length() {
239
+ return q(this.firstPoint, this.lastPoint);
240
+ }
241
+ get squareLength() {
242
+ return mt(this.firstPoint, this.lastPoint);
243
+ }
244
+ get V() {
245
+ return this._V === null && (this._V = A(this.lastPoint, this.firstPoint)), this._V;
246
+ }
247
+ get slope() {
248
+ if (this._slope === null) {
249
+ const [t, n] = this.V;
250
+ this._slope = n / t;
251
+ }
252
+ return this._slope;
253
+ }
254
+ get yIntercept() {
255
+ return this._yIntercept === null && (this._yIntercept = this.firstPoint[1] - this.slope * this.firstPoint[0]), this._yIntercept;
256
+ }
257
+ get midPoint() {
258
+ return O(this.firstPoint, D(this.V, 0.5));
259
+ }
260
+ isSame(t) {
261
+ return t instanceof R ? E(this.firstPoint, t.firstPoint) && E(this.lastPoint, t.lastPoint) || E(this.lastPoint, t.firstPoint) && E(this.firstPoint, t.lastPoint) : !1;
262
+ }
263
+ clone() {
264
+ return new R(this.firstPoint, this.lastPoint);
265
+ }
266
+ reverse() {
267
+ return new R(this.lastPoint, this.firstPoint);
268
+ }
269
+ get boundingBox() {
270
+ return this._boundingBox === null && (this._boundingBox = new it(
271
+ Math.min(this.firstPoint[0], this.lastPoint[0]) - this.precision,
272
+ Math.min(this.firstPoint[1], this.lastPoint[1]) - this.precision,
273
+ Math.max(this.firstPoint[0], this.lastPoint[0]) + this.precision,
274
+ Math.max(this.firstPoint[1], this.lastPoint[1]) + this.precision
275
+ )), this._boundingBox;
276
+ }
277
+ distanceFrom(t) {
278
+ const n = A(t, this.firstPoint), e = $t(n, this.V) / this.squareLength;
279
+ if (e < 0)
280
+ return q(t, this.firstPoint);
281
+ if (e > 1)
282
+ return q(t, this.lastPoint);
283
+ const s = this.paramPoint(e);
284
+ return q(t, s);
285
+ }
286
+ isOnSegment(t) {
287
+ if (E(t, this.firstPoint, this.precision))
288
+ return !0;
289
+ const n = A(t, this.firstPoint);
290
+ if (!Vt(this.V, n))
291
+ return !1;
292
+ const e = $t(n, this.V) / this.squareLength;
293
+ return this.isValidParameter(e);
294
+ }
295
+ gradientAt(t) {
296
+ return this.V;
297
+ }
298
+ tangentAt(t) {
299
+ if (!this.isOnSegment(t))
300
+ throw new Error("Point is not on segment");
301
+ return W(this.V);
302
+ }
303
+ get normalVector() {
304
+ return J(W(this.V));
305
+ }
306
+ get tangentAtFirstPoint() {
307
+ return W(this.V);
308
+ }
309
+ get tangentAtLastPoint() {
310
+ return W(this.V);
311
+ }
312
+ splitAt(t) {
313
+ let n;
314
+ if (Array.isArray(t) && t.length === 0)
315
+ return [this];
316
+ Array.isArray(t[0]) ? n = t : n = [t], n.forEach((u) => {
317
+ if (!this.isOnSegment(u))
318
+ throw new Error(
319
+ `Point ${T(u)} is not on segment ${this.repr}`
320
+ );
321
+ });
322
+ const e = [this.firstPoint, ...n, this.lastPoint], s = ct(e), r = this.lastPoint[0] - this.firstPoint[0];
323
+ let o = Math.sign(r), h = 0;
324
+ return Math.abs(r) < this.precision && (o = Math.sign(this.lastPoint[1] - this.firstPoint[1]), h = 1), s.sort(
325
+ (u, l) => o * (u[h] - l[h])
326
+ ), s.flatMap((u, l) => l === s.length - 1 ? [] : new R(u, s[l + 1]));
327
+ }
328
+ transform(t) {
329
+ return new R(
330
+ t.transform(this.firstPoint),
331
+ t.transform(this.lastPoint)
332
+ );
333
+ }
334
+ }
335
+ function Ke(i) {
336
+ return Array.from(Array(i).keys());
337
+ }
338
+ function nt(i) {
339
+ const t = Math.min(...i.map((n) => n.length));
340
+ return Ke(t).map((n) => i.map((e) => e[n]));
341
+ }
342
+ function st(i, t = 1e-9) {
343
+ return i < 0 ? i + 2 * Math.PI : i >= 2 * Math.PI ? i % (2 * Math.PI) : i > 2 * Math.PI - t ? 0 : i;
344
+ }
345
+ function vt(i, t, n, e = 1e-9) {
346
+ let s = t - i;
347
+ return n && (s = -s), s < 0 && (s += 2 * Math.PI), s > 2 * Math.PI - e ? 0 : s;
348
+ }
349
+ const Ft = (i, t, n) => {
350
+ const e = at(i.V, t.V), s = jt(i.V), r = jt(t.V), o = n ? n * n : i.precision * t.precision;
351
+ if (e * e < s * r * o)
352
+ return "parallel";
353
+ const h = A(t.firstPoint, i.firstPoint), u = at(h, t.V) / e, l = at(h, i.V) / e;
354
+ return {
355
+ intersectionParam1: u,
356
+ intersectionParam2: l
357
+ };
358
+ };
359
+ function ge(i, t, n = !1, e) {
360
+ const s = Ft(i, t, e);
361
+ if (s === "parallel") {
362
+ if (!n)
363
+ return null;
364
+ if (i.isSame(t))
365
+ return i;
366
+ const h = ct(
367
+ [
368
+ t.isOnSegment(i.firstPoint) ? i.firstPoint : null,
369
+ t.isOnSegment(i.lastPoint) ? i.lastPoint : null,
370
+ i.isOnSegment(t.firstPoint) ? t.firstPoint : null,
371
+ i.isOnSegment(t.lastPoint) ? t.lastPoint : null
372
+ ].filter((u) => u !== null)
373
+ ).sort((u, l) => u[0] - l[0]);
374
+ if (h.length === 0)
375
+ return null;
376
+ if (h.length === 1)
377
+ return null;
378
+ if (h.length === 2)
379
+ return new R(h[0], h[1]);
380
+ throw console.error(h), new Error(
381
+ "Unexpected number of points while intersecting parallel lines"
382
+ );
383
+ }
384
+ const { intersectionParam1: r, intersectionParam2: o } = s;
385
+ return !i.isValidParameter(r) || !t.isValidParameter(o) ? null : i.paramPoint(r);
386
+ }
387
+ const Pt = (i, t) => {
388
+ const n = A(i, t);
389
+ return Xe(n);
390
+ };
391
+ class I extends zt {
392
+ constructor(t, n, e, s = !1, { ignoreChecks: r = !1 } = {}) {
393
+ if (super(t, n), this.segmentType = "ARC", this._coefficients = null, this._angularLength = null, this._radius = null, this._firstAngle = null, this._lastAngle = null, this._boundingBox = null, this.center = e, this.clockwise = s, !r) {
394
+ if (E(t, n))
395
+ throw new Error("Invalid arc, cannot be a full circle");
396
+ if (Math.abs(this.radius - q(this.lastPoint, this.center)) > this.precision)
397
+ throw new Error(
398
+ `Invalid arc, radius does not match between ${T(
399
+ t
400
+ )} and ${T(n)}} (center ${T(e)})`
401
+ );
402
+ }
403
+ }
404
+ get info() {
405
+ return `ARC(${T(this.firstPoint)}, ${T(
406
+ this.lastPoint
407
+ )}, ${T(this.center)}, ${this.clockwise ? "CW" : "CCW"})`;
408
+ }
409
+ get coefficients() {
410
+ if (this._coefficients === null) {
411
+ const [t, n] = this.center, e = this.radius * this.radius;
412
+ this._coefficients = {
413
+ x2: 1 / e,
414
+ xy: 0,
415
+ y2: 1 / e,
416
+ x: -(2 * t) / e,
417
+ y: -(2 * n) / e,
418
+ c: (t * t + n * n - e) / e
419
+ };
420
+ }
421
+ return this._coefficients;
422
+ }
423
+ isValidParameter(t) {
424
+ return 1 - t >= -this.precision && t >= -this.precision;
425
+ }
426
+ angleToParam(t) {
427
+ return vt(this.firstAngle, st(t), this.clockwise) / this.angularLength;
428
+ }
429
+ get angularLength() {
430
+ return this._angularLength || (this._angularLength = vt(
431
+ this.firstAngle,
432
+ this.lastAngle,
433
+ this.clockwise
434
+ )), this._angularLength;
435
+ }
436
+ paramPoint(t) {
437
+ return O(
438
+ this.center,
439
+ ft(
440
+ this.radius,
441
+ this.firstAngle + t * this.angularLength * (this.clockwise ? -1 : 1)
442
+ )
443
+ );
444
+ }
445
+ pointToParam(t) {
446
+ const [n, e] = Pt(t, this.center);
447
+ if (Math.abs(n - this.radius) > this.precision)
448
+ throw new Error(
449
+ `Point ${T(t)} is not on segment ${this.repr}`
450
+ );
451
+ const s = this.angleToParam(e);
452
+ if (!this.isValidParameter(s))
453
+ throw new Error(
454
+ `Point ${T(t)} is not on segment ${this.repr}`
455
+ );
456
+ return s;
457
+ }
458
+ get radius() {
459
+ return this._radius === null && (this._radius = q(this.firstPoint, this.center)), this._radius;
460
+ }
461
+ get firstAngle() {
462
+ if (this._firstAngle === null) {
463
+ const [t, n] = A(this.firstPoint, this.center);
464
+ this._firstAngle = st(Math.atan2(n, t));
465
+ }
466
+ return this._firstAngle;
467
+ }
468
+ get lastAngle() {
469
+ if (this._lastAngle === null) {
470
+ const [t, n] = A(this.lastPoint, this.center);
471
+ this._lastAngle = st(Math.atan2(n, t));
472
+ }
473
+ return this._lastAngle;
474
+ }
475
+ get length() {
476
+ return this.radius * this.angularLength;
477
+ }
478
+ get squareLength() {
479
+ return this.length * this.length;
480
+ }
481
+ get midPoint() {
482
+ return this.paramPoint(0.5);
483
+ }
484
+ isSame(t) {
485
+ return !(t instanceof I) || !E(this.center, t.center) ? !1 : E(this.firstPoint, t.firstPoint) && E(this.lastPoint, t.lastPoint) && this.clockwise === t.clockwise || E(this.lastPoint, t.firstPoint) && E(this.firstPoint, t.lastPoint) && this.clockwise === !t.clockwise;
486
+ }
487
+ clone() {
488
+ return new I(
489
+ this.firstPoint,
490
+ this.lastPoint,
491
+ this.center,
492
+ this.clockwise
493
+ );
494
+ }
495
+ reverse() {
496
+ return new I(
497
+ this.lastPoint,
498
+ this.firstPoint,
499
+ this.center,
500
+ !this.clockwise
501
+ );
502
+ }
503
+ get boundingBox() {
504
+ if (this._boundingBox === null) {
505
+ const t = this.radius + this.precision, n = (e) => this.isValidParameter(this.angleToParam(e));
506
+ this._boundingBox = new it(
507
+ n(Math.PI) ? this.center[0] - t : Math.min(this.firstPoint[0], this.lastPoint[0]) - this.precision,
508
+ n(Math.PI * 1.5) ? this.center[1] - t : Math.min(this.firstPoint[1], this.lastPoint[1]) - this.precision,
509
+ n(0) ? this.center[0] + t : Math.max(this.firstPoint[0], this.lastPoint[0]) + this.precision,
510
+ n(Math.PI / 2) ? this.center[1] + t : Math.max(this.firstPoint[1], this.lastPoint[1]) + this.precision
511
+ );
512
+ }
513
+ return this._boundingBox;
514
+ }
515
+ distanceFrom(t) {
516
+ const [n, e] = Pt(t, this.center);
517
+ return this.isValidParameter(this.angleToParam(e)) ? Math.abs(n - this.radius) : Math.sqrt(
518
+ Math.min(
519
+ mt(t, this.firstPoint),
520
+ mt(t, this.lastPoint)
521
+ )
522
+ );
523
+ }
524
+ isOnSegment(t) {
525
+ if (E(t, this.firstPoint) || E(t, this.lastPoint))
526
+ return !0;
527
+ const [n, e] = Pt(t, this.center);
528
+ if (Math.abs(n - this.radius) > this.precision)
529
+ return !1;
530
+ const s = this.angleToParam(e);
531
+ return this.isValidParameter(s);
532
+ }
533
+ gradientAt(t) {
534
+ const n = this.firstAngle + t * this.angularLength * (this.clockwise ? -1 : 1), e = this.radius * this.angularLength, s = -e * Math.sin(n), r = e * Math.cos(n);
535
+ return this.clockwise ? [-s, -r] : [s, r];
536
+ }
537
+ tangentAt(t) {
538
+ const [n, e] = Pt(t, this.center);
539
+ if (Math.abs(n - this.radius) > this.precision)
540
+ throw new Error("Point is not on the arc");
541
+ const s = this.angleToParam(e);
542
+ if (!this.isValidParameter(s))
543
+ throw new Error("Point is not on the arc");
544
+ const r = ft(1, e);
545
+ return (this.clockwise ? bt : J)(W(r));
546
+ }
547
+ get tangentAtFirstPoint() {
548
+ const t = ft(1, this.firstAngle);
549
+ return (this.clockwise ? bt : J)(W(t));
550
+ }
551
+ get tangentAtLastPoint() {
552
+ const t = ft(1, this.lastAngle);
553
+ return (this.clockwise ? bt : J)(W(t));
554
+ }
555
+ splitAt(t) {
556
+ let n;
557
+ if (Array.isArray(t) && t.length === 0)
558
+ return [this];
559
+ Array.isArray(t[0]) ? n = t : n = [t];
560
+ const s = [0, 1, ...n.map((h) => this.pointToParam(h))], r = new Map(
561
+ nt([s, [this.firstPoint, this.lastPoint, ...n]])
562
+ );
563
+ s.sort((h, u) => h - u);
564
+ let o = null;
565
+ return s.flatMap((h, u) => {
566
+ if (u === s.length - 1)
567
+ return [];
568
+ const l = s[u + 1];
569
+ if (l - h < this.precision)
570
+ return o === null && (o = h), [];
571
+ const c = o === null ? h : o, a = new I(
572
+ r.get(c) || this.paramPoint(c),
573
+ r.get(l) || this.paramPoint(l),
574
+ this.center,
575
+ this.clockwise
576
+ );
577
+ return o = null, a;
578
+ });
579
+ }
580
+ transform(t) {
581
+ return new I(
582
+ t.transform(this.firstPoint),
583
+ t.transform(this.lastPoint),
584
+ t.transform(this.center),
585
+ t.keepsOrientation() ? this.clockwise : !this.clockwise
586
+ );
587
+ }
588
+ }
589
+ function as(i, t, n) {
590
+ const e = new R(t, i), s = new R(t, n), r = J(e.tangentAtFirstPoint), o = J(s.tangentAtLastPoint), h = Ft(
591
+ { firstPoint: e.midPoint, V: r, precision: 1e-9 },
592
+ { firstPoint: s.midPoint, V: o, precision: 1e-9 }
593
+ );
594
+ if (h === "parallel")
595
+ throw new Error("Cannot create an arc from three colinear points");
596
+ const u = at(
597
+ A(i, t),
598
+ A(n, t)
599
+ ) > 0;
600
+ return new I(
601
+ i,
602
+ n,
603
+ O(e.midPoint, D(r, h.intersectionParam1)),
604
+ u,
605
+ { ignoreChecks: !0 }
606
+ );
607
+ }
608
+ function cs(i, t, n) {
609
+ const e = new R(t, i), s = J(e.tangentAtFirstPoint), r = Ft(
610
+ { firstPoint: e.midPoint, V: s, precision: 1e-9 },
611
+ {
612
+ firstPoint: i,
613
+ V: J(n),
614
+ precision: 1e-9
615
+ }
616
+ );
617
+ if (r === "parallel")
618
+ throw new Error("Cannot create an arc from three colinear points");
619
+ const o = O(
620
+ e.midPoint,
621
+ D(s, r.intersectionParam1)
622
+ ), h = at(
623
+ A(o, i),
624
+ A(o, O(i, n))
625
+ ) < 0;
626
+ return new I(i, t, o, h, {
627
+ ignoreChecks: !0
628
+ });
629
+ }
630
+ function Qe(i, t) {
631
+ const n = A(t, i.firstPoint), e = $t(n, i.V) / i.squareLength;
632
+ return i.paramPoint(e);
633
+ }
634
+ function kt(i, t, n) {
635
+ const e = n || i.precision, s = Qe(i, t.center), r = q(s, t.center);
636
+ if (r > t.radius + e)
637
+ return [];
638
+ if (Math.abs(r - t.radius) < e) {
639
+ const a = s;
640
+ return i.isOnSegment(a) && t.isOnSegment(a) ? [a] : [];
641
+ }
642
+ const o = [], h = Math.sqrt(
643
+ t.radius * t.radius - r * r
644
+ ), u = i.tangentAtFirstPoint, l = O(s, D(u, h));
645
+ i.isOnSegment(l) && t.isOnSegment(l) && o.push(l);
646
+ const c = O(s, D(u, -h));
647
+ return i.isOnSegment(c) && t.isOnSegment(c) && o.push(c), o;
648
+ }
649
+ const Ze = (i) => {
650
+ const { firstPoint: t, lastPoint: n, center: e, clockwise: s } = i;
651
+ return new I(n, t, e, s, {
652
+ ignoreChecks: !0
653
+ });
654
+ }, He = (i, t) => {
655
+ if (i.isSame(t))
656
+ return [i];
657
+ const n = ct(
658
+ [
659
+ t.isOnSegment(i.firstPoint) ? i.firstPoint : null,
660
+ t.isOnSegment(i.lastPoint) ? i.lastPoint : null,
661
+ i.isOnSegment(t.firstPoint) ? t.firstPoint : null,
662
+ i.isOnSegment(t.lastPoint) ? t.lastPoint : null
663
+ ].filter((e) => e !== null)
664
+ // We sort by the param value of the first arc. This means that the points
665
+ // will be sorted with the same orientation than arc1
666
+ ).sort((e, s) => i.pointToParam(e) - i.pointToParam(s));
667
+ if (n.length === 0)
668
+ return [];
669
+ if (n.length === 1)
670
+ return [];
671
+ if (n.length === 2)
672
+ return i.isSame(Ze(t)) ? [] : [new I(n[0], n[1], i.center, i.clockwise)];
673
+ if (n.length === 3) {
674
+ const e = E(n[0], t.lastPoint) || E(n[0], t.firstPoint) ? 1 : 0;
675
+ return [
676
+ new I(
677
+ n[0 + e],
678
+ n[1 + e],
679
+ i.center,
680
+ i.clockwise
681
+ )
682
+ ];
683
+ } else if (n.length === 4)
684
+ return [
685
+ new I(n[0], n[1], i.center, i.clockwise),
686
+ new I(n[2], n[3], i.center, i.clockwise)
687
+ ];
688
+ throw new Error("Bug in the arc arc overlap algorithm");
689
+ };
690
+ function me(i, t, n = !1, e) {
691
+ const s = e || i.precision, r = q(i.center, t.center), o = i.radius + t.radius;
692
+ if (r > o + s)
693
+ return [];
694
+ const h = Math.abs(i.radius - t.radius);
695
+ if (r < h - s)
696
+ return [];
697
+ if (r < s)
698
+ return h > s ? [] : n ? He(i, t) : [];
699
+ const u = W(A(t.center, i.center)), l = r > o - s;
700
+ if (
701
+ // circles are outside each other
702
+ l || // circles are inside each other
703
+ Math.abs(r - h) < s
704
+ ) {
705
+ const f = l || i.radius > t.radius ? 1 : -1, p = O(
706
+ i.center,
707
+ D(u, f * i.radius)
708
+ );
709
+ return i.isOnSegment(p) && t.isOnSegment(p) ? [p] : [];
710
+ }
711
+ const c = i.radius * i.radius / (2 * r) - t.radius * t.radius / (2 * r) + r / 2, a = O(
712
+ i.center,
713
+ D(u, c)
714
+ ), g = Math.sqrt(
715
+ i.radius * i.radius - c * c
716
+ ), w = J(u), m = O(a, D(w, g)), d = O(a, D(w, -g)), P = [];
717
+ return i.isOnSegment(m) && t.isOnSegment(m) && P.push(m), i.isOnSegment(d) && t.isOnSegment(d) && P.push(d), P;
718
+ }
719
+ class C extends zt {
720
+ constructor(t, n, e, s, r, o, h = !1, {
721
+ ignoreChecks: u = !1,
722
+ angleUnits: l = "deg"
723
+ } = {}) {
724
+ super(t, n), this.segmentType = "ELLIPSE_ARC", this.precision = 1e-6, this._coefficients = null, this.center = e;
725
+ const c = s >= r;
726
+ this.majorRadius = c ? s : r, this.minorRadius = c ? r : s;
727
+ const a = l === "deg" ? o * Lt : o;
728
+ if (this.tiltAngle = st(
729
+ c ? a : a + Math.PI / 2
730
+ ), this.clockwise = h, !u) {
731
+ if (E(t, n))
732
+ throw new Error("Invalid arc, cannot be a full circle");
733
+ if (!this.isPointOnEllipse(t))
734
+ throw new Error(
735
+ `First point ${T(
736
+ t
737
+ )} not on the ellipse defined by ${this.info}`
738
+ );
739
+ if (!this.isPointOnEllipse(n))
740
+ throw new Error(
741
+ `Last point ${T(n)} not on the ellipse defined by ${this.info}`
742
+ );
743
+ if (Math.abs(this.majorRadius - this.minorRadius) < this.precision)
744
+ throw new Error(
745
+ "Both radii should be different, create an arc instead"
746
+ );
747
+ }
748
+ }
749
+ get coefficients() {
750
+ if (this._coefficients === null) {
751
+ const [t, n] = this.center, e = this.majorRadius * this.majorRadius, s = this.minorRadius * this.minorRadius, r = Math.cos(this.tiltAngle), o = Math.sin(this.tiltAngle), h = e * o * o + s * r * r, u = 2 * (s - e) * o * r, l = e * r * r + s * o * o;
752
+ this._coefficients = {
753
+ x2: h,
754
+ xy: u,
755
+ y2: l,
756
+ x: -2 * h * t - u * n,
757
+ y: -2 * l * n - u * t,
758
+ c: h * t * t + u * t * n + l * n * n - e * s
759
+ };
760
+ }
761
+ return this._coefficients;
762
+ }
763
+ get info() {
764
+ return `ELLIPSE_ARC(${T(this.firstPoint)}, ${T(
765
+ this.lastPoint
766
+ )}, ${T(this.center)}, ${this.majorRadius}, ${this.minorRadius}, ${this.tiltAngle * Ue}, ${this.clockwise ? "CW" : "CCW"})`;
767
+ }
768
+ reverse() {
769
+ return new C(
770
+ this.lastPoint,
771
+ this.firstPoint,
772
+ this.center,
773
+ this.majorRadius,
774
+ this.minorRadius,
775
+ this.tiltAngle,
776
+ !this.clockwise,
777
+ { ignoreChecks: !0, angleUnits: "rad" }
778
+ );
779
+ }
780
+ clone() {
781
+ return new C(
782
+ this.firstPoint,
783
+ this.lastPoint,
784
+ this.center,
785
+ this.majorRadius,
786
+ this.minorRadius,
787
+ this.tiltAngle,
788
+ this.clockwise,
789
+ { ignoreChecks: !0, angleUnits: "rad" }
790
+ );
791
+ }
792
+ computeEllipseExtrema() {
793
+ const t = Math.tan(this.tiltAngle), n = this.minorRadius / this.majorRadius, e = -Math.atan(n * t), s = Math.atan(n / t);
794
+ return [e, Math.PI + e, s, Math.PI + s].map((o) => this.thetaToParam(o)).filter((o) => this.isValidParameter(o)).map((o) => this.paramPoint(o));
795
+ }
796
+ get boundingBox() {
797
+ if (this._boundingBox === void 0) {
798
+ const t = this.computeEllipseExtrema(), n = [
799
+ this.firstPoint,
800
+ this.lastPoint,
801
+ ...t
802
+ ];
803
+ this._boundingBox = De(n);
804
+ }
805
+ return this._boundingBox;
806
+ }
807
+ get linearExentricity() {
808
+ return this._linearExentricity === void 0 && (this._linearExentricity = Math.sqrt(
809
+ this.majorRadius * this.majorRadius - this.minorRadius * this.minorRadius
810
+ )), this._linearExentricity;
811
+ }
812
+ get exentricity() {
813
+ return this._exentricity === void 0 && (this._exentricity = this.linearExentricity / this.majorRadius), this._exentricity;
814
+ }
815
+ get focals() {
816
+ if (this._focals === void 0) {
817
+ const t = this.majorAxis;
818
+ this._focals = [
819
+ O(this.center, D(t, this.linearExentricity)),
820
+ O(this.center, D(t, -this.linearExentricity))
821
+ ];
822
+ }
823
+ return this._focals;
824
+ }
825
+ get majorAxis() {
826
+ return ft(1, this.tiltAngle);
827
+ }
828
+ paramPoint(t) {
829
+ const n = this.firstAngle + t * this.deltaAngle * (this.clockwise ? -1 : 1);
830
+ return this.reverseEllipseReferenceFrameTransform.transform([
831
+ this.majorRadius * Math.cos(n),
832
+ this.minorRadius * Math.sin(n)
833
+ ]);
834
+ }
835
+ pointToParam(t) {
836
+ if (!this.isPointOnEllipse(t))
837
+ throw new Error(
838
+ `Point ${T(t)} not on the ellipse defined by ${this.repr}`
839
+ );
840
+ const n = this.thetaToParam(this.pointTheta(t));
841
+ if (!this.isValidParameter(n))
842
+ throw new Error(
843
+ `Point ${T(t)} is not on segment ${this.repr}`
844
+ );
845
+ return n;
846
+ }
847
+ get midPoint() {
848
+ return this.paramPoint(0.5);
849
+ }
850
+ isValidParameter(t) {
851
+ return 1 - t >= -this.precision && t >= -this.precision;
852
+ }
853
+ isSame(t) {
854
+ return E(this.center, t.center) && Math.abs(this.majorRadius - t.majorRadius) < this.precision && Math.abs(this.minorRadius - t.minorRadius) < this.precision && (Math.abs(this.tiltAngle - t.tiltAngle) < this.precision || Math.abs(Math.abs(this.tiltAngle - t.tiltAngle) - Math.PI) < this.precision) && (E(this.firstPoint, t.firstPoint) && this.clockwise === t.clockwise || E(this.firstPoint, t.lastPoint) && this.clockwise !== t.clockwise);
855
+ }
856
+ pointTheta(t) {
857
+ const n = this.ellipseReferenceFrameTransform.transform(t), e = Math.atan2(
858
+ n[1] / this.minorRadius,
859
+ n[0] / this.majorRadius
860
+ );
861
+ return st(e);
862
+ }
863
+ thetaToParam(t) {
864
+ return vt(this.firstAngle, st(t), this.clockwise) / this.deltaAngle;
865
+ }
866
+ isPointOnEllipse(t) {
867
+ const [n, e] = this.focals, s = q(t, n), r = q(t, e);
868
+ return Math.abs(2 * this.majorRadius - s - r) < this.precision;
869
+ }
870
+ isOnSegment(t) {
871
+ return this.isPointOnEllipse(t) ? this.isValidParameter(this.thetaToParam(this.pointTheta(t))) : !1;
872
+ }
873
+ distanceFrom(t) {
874
+ let n;
875
+ if (E(t, this.center) ? n = O(
876
+ this.center,
877
+ D(J(this.majorAxis), this.minorRadius)
878
+ ) : n = this.reverseEllipseReferenceFrameTransform.transform(
879
+ en(
880
+ this.majorRadius,
881
+ this.minorRadius,
882
+ this.ellipseReferenceFrameTransform.transform(t)
883
+ )
884
+ ), this.isValidParameter(this.thetaToParam(this.pointTheta(t))))
885
+ return q(t, n);
886
+ if (Ge(t, this.majorAxis, this.center)) {
887
+ const e = st(
888
+ 2 * Math.PI - this.pointTheta(t)
889
+ ), s = this.thetaToParam(e);
890
+ if (this.isValidParameter(s))
891
+ return q(t, this.paramPoint(s));
892
+ }
893
+ return Math.min(
894
+ q(t, this.firstPoint),
895
+ q(t, this.lastPoint)
896
+ );
897
+ }
898
+ get ellipseReferenceFrameTransform() {
899
+ return this._ellipseReferenceFrameTransform === void 0 && (this._ellipseReferenceFrameTransform = new V().rotate(-this.tiltAngle).translate(-this.center[0], -this.center[1])), this._ellipseReferenceFrameTransform;
900
+ }
901
+ get reverseEllipseReferenceFrameTransform() {
902
+ return this._reverseEllipseReferenceFrameTransform === void 0 && (this._reverseEllipseReferenceFrameTransform = new V().translate(this.center[0], this.center[1]).rotate(this.tiltAngle)), this._reverseEllipseReferenceFrameTransform;
903
+ }
904
+ get rotateFromEllipseReferenceFrame() {
905
+ return this._rotateFromEllipseReferenceFrame === void 0 && (this._rotateFromEllipseReferenceFrame = new V().rotate(
906
+ this.tiltAngle
907
+ )), this._rotateFromEllipseReferenceFrame;
908
+ }
909
+ get firstAngle() {
910
+ return this._firstAngle === void 0 && (this._firstAngle = this.pointTheta(this.firstPoint)), this._firstAngle;
911
+ }
912
+ get lastAngle() {
913
+ return this._lastAngle === void 0 && (this._lastAngle = this.pointTheta(this.lastPoint)), this._lastAngle;
914
+ }
915
+ get deltaAngle() {
916
+ return this._deltaAngle === void 0 && (this._deltaAngle = vt(
917
+ this.firstAngle,
918
+ this.lastAngle,
919
+ this.clockwise
920
+ )), this._deltaAngle;
921
+ }
922
+ normalAt(t) {
923
+ const n = this.tangentAt(t);
924
+ return this.clockwise ? J(n) : bt(n);
925
+ }
926
+ gradientAt(t) {
927
+ const n = this.firstAngle + t * this.deltaAngle * (this.clockwise ? -1 : 1), e = -this.majorRadius * this.deltaAngle * Math.sin(n), s = this.minorRadius * this.deltaAngle * Math.cos(n), r = this.clockwise ? [-e, -s] : [e, s];
928
+ return this.rotateFromEllipseReferenceFrame.transform(r);
929
+ }
930
+ tangentAt(t) {
931
+ const n = this.pointTheta(t), e = -this.majorRadius * Math.sin(n), s = this.minorRadius * Math.cos(n), r = this.clockwise ? [-e, -s] : [e, s];
932
+ return W(this.rotateFromEllipseReferenceFrame.transform(r));
933
+ }
934
+ get tangentAtFirstPoint() {
935
+ const t = -this.majorRadius * Math.sin(this.firstAngle), n = this.minorRadius * Math.cos(this.firstAngle), e = this.clockwise ? [-t, -n] : [t, n];
936
+ return W(this.rotateFromEllipseReferenceFrame.transform(e));
937
+ }
938
+ get tangentAtLastPoint() {
939
+ const t = -this.majorRadius * Math.sin(this.lastAngle), n = this.minorRadius * Math.cos(this.lastAngle), e = this.clockwise ? [-t, -n] : [t, n];
940
+ return W(this.rotateFromEllipseReferenceFrame.transform(e));
941
+ }
942
+ transform(t) {
943
+ const n = t.transformAngle(this.tiltAngle), e = t.scaleFactor();
944
+ return new C(
945
+ t.transform(this.firstPoint),
946
+ t.transform(this.lastPoint),
947
+ t.transform(this.center),
948
+ this.majorRadius * e,
949
+ this.minorRadius * e,
950
+ n,
951
+ t.keepsOrientation() ? this.clockwise : !this.clockwise,
952
+ { angleUnits: "rad" }
953
+ );
954
+ }
955
+ splitAt(t) {
956
+ let n;
957
+ if (Array.isArray(t) && t.length === 0)
958
+ return [this];
959
+ Array.isArray(t[0]) ? n = t : n = [t];
960
+ const s = [0, 1, ...n.map((h) => this.pointToParam(h))], r = new Map(
961
+ nt([s, [this.firstPoint, this.lastPoint, ...n]])
962
+ );
963
+ s.sort((h, u) => h - u);
964
+ let o = null;
965
+ return s.flatMap((h, u) => {
966
+ if (u === s.length - 1)
967
+ return [];
968
+ const l = s[u + 1];
969
+ if (l - h < this.precision)
970
+ return o === null && (o = h), [];
971
+ const c = o === null ? h : o, a = new C(
972
+ r.get(c) || this.paramPoint(c),
973
+ r.get(l) || this.paramPoint(l),
974
+ this.center,
975
+ this.majorRadius,
976
+ this.minorRadius,
977
+ this.tiltAngle,
978
+ this.clockwise,
979
+ { angleUnits: "rad" }
980
+ );
981
+ return o = null, a;
982
+ });
983
+ }
984
+ }
985
+ function fs(i, t, n, e, s, r, o) {
986
+ const { center: h, rx: u, ry: l } = tn(
987
+ i,
988
+ t,
989
+ n,
990
+ e,
991
+ s * Lt,
992
+ !r,
993
+ o
994
+ );
995
+ return Math.abs(u - l) < 1e-9 ? new I(i, t, h, o) : new C(i, t, h, u, l, s, o);
996
+ }
997
+ function tn([i, t], [n, e], s, r, o, h, u) {
998
+ if (s < 0 && (s = -s), r < 0 && (r = -r), s == 0 || r == 0)
999
+ throw Error("rx and ry can not be 0");
1000
+ const l = Math.sin(o), c = Math.cos(o), a = (i - n) / 2, g = (t - e) / 2, w = (i + n) / 2, m = (t + e) / 2, d = c * a + l * g, P = c * g - l * a, f = d * d / (s * s) + P * P / (r * r);
1001
+ f > 1 && (s = s * Math.sqrt(f), r = r * Math.sqrt(f));
1002
+ const p = s * r, y = s * P, M = r * d, b = y * y + M * M;
1003
+ if (!b)
1004
+ throw Error("start point can not be same as end point");
1005
+ let x = Math.sqrt(Math.abs((p * p - b) / b));
1006
+ h == u && (x = -x);
1007
+ const k = x * y / r, S = -x * M / s, _ = c * k - l * S + w, F = l * k + c * S + m;
1008
+ return {
1009
+ center: [_, F],
1010
+ rx: s,
1011
+ ry: r
1012
+ };
1013
+ }
1014
+ function en(i, t, n) {
1015
+ const e = Math.abs(n[0]), s = Math.abs(n[1]);
1016
+ let r = 0.707, o = 0.707;
1017
+ const h = i, u = t;
1018
+ for (let l = 0; l < 3; l++) {
1019
+ const c = h * r, a = u * o, g = (h * h - u * u) * r ** 3 / h, w = (u * u - h * h) * o ** 3 / u, m = c - g, d = a - w, P = e - g, f = s - w, p = Math.hypot(m, d), y = Math.hypot(P, f);
1020
+ r = Math.min(1, Math.max(0, (P * p / y + g) / h)), o = Math.min(1, Math.max(0, (f * p / y + w) / u));
1021
+ const M = Math.hypot(r, o);
1022
+ r /= M, o /= M;
1023
+ }
1024
+ return [h * r * Math.sign(n[0]), u * o * Math.sign(n[1])];
1025
+ }
1026
+ function qt(i, t, n = 1e-9) {
1027
+ const e = i.transform(t.ellipseReferenceFrameTransform), s = e.slope, r = e.yIntercept, o = t.majorRadius * t.majorRadius, h = t.minorRadius * t.minorRadius, u = t.majorRadius * t.minorRadius, l = e.slope * e.slope, c = e.yIntercept * e.yIntercept, a = (f) => f.map(
1028
+ (p) => t.reverseEllipseReferenceFrameTransform.transform(p)
1029
+ ).filter((p) => i.isOnSegment(p) && t.isOnSegment(p));
1030
+ if (!Number.isFinite(s)) {
1031
+ const f = e.firstPoint[0];
1032
+ if (Math.abs(f) - t.majorRadius > n)
1033
+ return [];
1034
+ if (Math.abs(Math.abs(f) - t.majorRadius) < n)
1035
+ return a([[f, 0]]);
1036
+ const p = t.minorRadius * Math.sqrt(1 - f * f / o), y = [f, p], M = [f, -p];
1037
+ return a([y, M]);
1038
+ }
1039
+ const g = o * l + h - c;
1040
+ if (g < -n)
1041
+ return [];
1042
+ const w = o * l + h;
1043
+ if (Math.abs(g) < n) {
1044
+ const f = -(o * s * r) / w, p = h * r / w;
1045
+ return a([[f, p]]);
1046
+ }
1047
+ const m = Math.sqrt(g), d = [
1048
+ -(o * s * r + u * m) / w,
1049
+ (h * r - u * s * m) / w
1050
+ ], P = [
1051
+ -(o * s * r - u * m) / w,
1052
+ (h * r + u * s * m) / w
1053
+ ];
1054
+ return a([d, P]);
1055
+ }
1056
+ const nn = Object.prototype.toString;
1057
+ function z(i) {
1058
+ const t = nn.call(i);
1059
+ return t.endsWith("Array]") && !t.includes("Big");
1060
+ }
1061
+ function sn(i) {
1062
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1063
+ if (!z(i))
1064
+ throw new TypeError("input must be an array");
1065
+ if (i.length === 0)
1066
+ throw new TypeError("input must not be empty");
1067
+ var n = t.fromIndex, e = n === void 0 ? 0 : n, s = t.toIndex, r = s === void 0 ? i.length : s;
1068
+ if (e < 0 || e >= i.length || !Number.isInteger(e))
1069
+ throw new Error("fromIndex must be a positive integer smaller than length");
1070
+ if (r <= e || r > i.length || !Number.isInteger(r))
1071
+ throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");
1072
+ for (var o = i[e], h = e + 1; h < r; h++)
1073
+ i[h] > o && (o = i[h]);
1074
+ return o;
1075
+ }
1076
+ function rn(i) {
1077
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1078
+ if (!z(i))
1079
+ throw new TypeError("input must be an array");
1080
+ if (i.length === 0)
1081
+ throw new TypeError("input must not be empty");
1082
+ var n = t.fromIndex, e = n === void 0 ? 0 : n, s = t.toIndex, r = s === void 0 ? i.length : s;
1083
+ if (e < 0 || e >= i.length || !Number.isInteger(e))
1084
+ throw new Error("fromIndex must be a positive integer smaller than length");
1085
+ if (r <= e || r > i.length || !Number.isInteger(r))
1086
+ throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");
1087
+ for (var o = i[e], h = e + 1; h < r; h++)
1088
+ i[h] < o && (o = i[h]);
1089
+ return o;
1090
+ }
1091
+ function Kt(i) {
1092
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1093
+ if (z(i)) {
1094
+ if (i.length === 0)
1095
+ throw new TypeError("input must not be empty");
1096
+ } else
1097
+ throw new TypeError("input must be an array");
1098
+ var n;
1099
+ if (t.output !== void 0) {
1100
+ if (!z(t.output))
1101
+ throw new TypeError("output option must be an array if specified");
1102
+ n = t.output;
1103
+ } else
1104
+ n = new Array(i.length);
1105
+ var e = rn(i), s = sn(i);
1106
+ if (e === s)
1107
+ throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");
1108
+ var r = t.min, o = r === void 0 ? t.autoMinMax ? e : 0 : r, h = t.max, u = h === void 0 ? t.autoMinMax ? s : 1 : h;
1109
+ if (o >= u)
1110
+ throw new RangeError("min option must be smaller than max option");
1111
+ for (var l = (u - o) / (s - e), c = 0; c < i.length; c++)
1112
+ n[c] = (i[c] - e) * l + o;
1113
+ return n;
1114
+ }
1115
+ const Mt = " ".repeat(2), pe = " ".repeat(4);
1116
+ function on() {
1117
+ return we(this);
1118
+ }
1119
+ function we(i, t = {}) {
1120
+ const {
1121
+ maxRows: n = 15,
1122
+ maxColumns: e = 10,
1123
+ maxNumSize: s = 8,
1124
+ padMinus: r = "auto"
1125
+ } = t;
1126
+ return `${i.constructor.name} {
1127
+ ${Mt}[
1128
+ ${pe}${hn(i, n, e, s, r)}
1129
+ ${Mt}]
1130
+ ${Mt}rows: ${i.rows}
1131
+ ${Mt}columns: ${i.columns}
1132
+ }`;
1133
+ }
1134
+ function hn(i, t, n, e, s) {
1135
+ const { rows: r, columns: o } = i, h = Math.min(r, t), u = Math.min(o, n), l = [];
1136
+ if (s === "auto") {
1137
+ s = !1;
1138
+ t:
1139
+ for (let c = 0; c < h; c++)
1140
+ for (let a = 0; a < u; a++)
1141
+ if (i.get(c, a) < 0) {
1142
+ s = !0;
1143
+ break t;
1144
+ }
1145
+ }
1146
+ for (let c = 0; c < h; c++) {
1147
+ let a = [];
1148
+ for (let g = 0; g < u; g++)
1149
+ a.push(ln(i.get(c, g), e, s));
1150
+ l.push(`${a.join(" ")}`);
1151
+ }
1152
+ return u !== o && (l[l.length - 1] += ` ... ${o - n} more columns`), h !== r && l.push(`... ${r - t} more rows`), l.join(`
1153
+ ${pe}`);
1154
+ }
1155
+ function ln(i, t, n) {
1156
+ return (i >= 0 && n ? ` ${Qt(i, t - 1)}` : Qt(i, t)).padEnd(t);
1157
+ }
1158
+ function Qt(i, t) {
1159
+ let n = i.toString();
1160
+ if (n.length <= t)
1161
+ return n;
1162
+ let e = i.toFixed(t);
1163
+ if (e.length > t && (e = i.toFixed(Math.max(0, t - (e.length - t)))), e.length <= t && !e.startsWith("0.000") && !e.startsWith("-0.000"))
1164
+ return e;
1165
+ let s = i.toExponential(t);
1166
+ return s.length > t && (s = i.toExponential(Math.max(0, t - (s.length - t)))), s.slice(0);
1167
+ }
1168
+ function un(i, t) {
1169
+ i.prototype.add = function(e) {
1170
+ return typeof e == "number" ? this.addS(e) : this.addM(e);
1171
+ }, i.prototype.addS = function(e) {
1172
+ for (let s = 0; s < this.rows; s++)
1173
+ for (let r = 0; r < this.columns; r++)
1174
+ this.set(s, r, this.get(s, r) + e);
1175
+ return this;
1176
+ }, i.prototype.addM = function(e) {
1177
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1178
+ throw new RangeError("Matrices dimensions must be equal");
1179
+ for (let s = 0; s < this.rows; s++)
1180
+ for (let r = 0; r < this.columns; r++)
1181
+ this.set(s, r, this.get(s, r) + e.get(s, r));
1182
+ return this;
1183
+ }, i.add = function(e, s) {
1184
+ return new t(e).add(s);
1185
+ }, i.prototype.sub = function(e) {
1186
+ return typeof e == "number" ? this.subS(e) : this.subM(e);
1187
+ }, i.prototype.subS = function(e) {
1188
+ for (let s = 0; s < this.rows; s++)
1189
+ for (let r = 0; r < this.columns; r++)
1190
+ this.set(s, r, this.get(s, r) - e);
1191
+ return this;
1192
+ }, i.prototype.subM = function(e) {
1193
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1194
+ throw new RangeError("Matrices dimensions must be equal");
1195
+ for (let s = 0; s < this.rows; s++)
1196
+ for (let r = 0; r < this.columns; r++)
1197
+ this.set(s, r, this.get(s, r) - e.get(s, r));
1198
+ return this;
1199
+ }, i.sub = function(e, s) {
1200
+ return new t(e).sub(s);
1201
+ }, i.prototype.subtract = i.prototype.sub, i.prototype.subtractS = i.prototype.subS, i.prototype.subtractM = i.prototype.subM, i.subtract = i.sub, i.prototype.mul = function(e) {
1202
+ return typeof e == "number" ? this.mulS(e) : this.mulM(e);
1203
+ }, i.prototype.mulS = function(e) {
1204
+ for (let s = 0; s < this.rows; s++)
1205
+ for (let r = 0; r < this.columns; r++)
1206
+ this.set(s, r, this.get(s, r) * e);
1207
+ return this;
1208
+ }, i.prototype.mulM = function(e) {
1209
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1210
+ throw new RangeError("Matrices dimensions must be equal");
1211
+ for (let s = 0; s < this.rows; s++)
1212
+ for (let r = 0; r < this.columns; r++)
1213
+ this.set(s, r, this.get(s, r) * e.get(s, r));
1214
+ return this;
1215
+ }, i.mul = function(e, s) {
1216
+ return new t(e).mul(s);
1217
+ }, i.prototype.multiply = i.prototype.mul, i.prototype.multiplyS = i.prototype.mulS, i.prototype.multiplyM = i.prototype.mulM, i.multiply = i.mul, i.prototype.div = function(e) {
1218
+ return typeof e == "number" ? this.divS(e) : this.divM(e);
1219
+ }, i.prototype.divS = function(e) {
1220
+ for (let s = 0; s < this.rows; s++)
1221
+ for (let r = 0; r < this.columns; r++)
1222
+ this.set(s, r, this.get(s, r) / e);
1223
+ return this;
1224
+ }, i.prototype.divM = function(e) {
1225
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1226
+ throw new RangeError("Matrices dimensions must be equal");
1227
+ for (let s = 0; s < this.rows; s++)
1228
+ for (let r = 0; r < this.columns; r++)
1229
+ this.set(s, r, this.get(s, r) / e.get(s, r));
1230
+ return this;
1231
+ }, i.div = function(e, s) {
1232
+ return new t(e).div(s);
1233
+ }, i.prototype.divide = i.prototype.div, i.prototype.divideS = i.prototype.divS, i.prototype.divideM = i.prototype.divM, i.divide = i.div, i.prototype.mod = function(e) {
1234
+ return typeof e == "number" ? this.modS(e) : this.modM(e);
1235
+ }, i.prototype.modS = function(e) {
1236
+ for (let s = 0; s < this.rows; s++)
1237
+ for (let r = 0; r < this.columns; r++)
1238
+ this.set(s, r, this.get(s, r) % e);
1239
+ return this;
1240
+ }, i.prototype.modM = function(e) {
1241
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1242
+ throw new RangeError("Matrices dimensions must be equal");
1243
+ for (let s = 0; s < this.rows; s++)
1244
+ for (let r = 0; r < this.columns; r++)
1245
+ this.set(s, r, this.get(s, r) % e.get(s, r));
1246
+ return this;
1247
+ }, i.mod = function(e, s) {
1248
+ return new t(e).mod(s);
1249
+ }, i.prototype.modulus = i.prototype.mod, i.prototype.modulusS = i.prototype.modS, i.prototype.modulusM = i.prototype.modM, i.modulus = i.mod, i.prototype.and = function(e) {
1250
+ return typeof e == "number" ? this.andS(e) : this.andM(e);
1251
+ }, i.prototype.andS = function(e) {
1252
+ for (let s = 0; s < this.rows; s++)
1253
+ for (let r = 0; r < this.columns; r++)
1254
+ this.set(s, r, this.get(s, r) & e);
1255
+ return this;
1256
+ }, i.prototype.andM = function(e) {
1257
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1258
+ throw new RangeError("Matrices dimensions must be equal");
1259
+ for (let s = 0; s < this.rows; s++)
1260
+ for (let r = 0; r < this.columns; r++)
1261
+ this.set(s, r, this.get(s, r) & e.get(s, r));
1262
+ return this;
1263
+ }, i.and = function(e, s) {
1264
+ return new t(e).and(s);
1265
+ }, i.prototype.or = function(e) {
1266
+ return typeof e == "number" ? this.orS(e) : this.orM(e);
1267
+ }, i.prototype.orS = function(e) {
1268
+ for (let s = 0; s < this.rows; s++)
1269
+ for (let r = 0; r < this.columns; r++)
1270
+ this.set(s, r, this.get(s, r) | e);
1271
+ return this;
1272
+ }, i.prototype.orM = function(e) {
1273
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1274
+ throw new RangeError("Matrices dimensions must be equal");
1275
+ for (let s = 0; s < this.rows; s++)
1276
+ for (let r = 0; r < this.columns; r++)
1277
+ this.set(s, r, this.get(s, r) | e.get(s, r));
1278
+ return this;
1279
+ }, i.or = function(e, s) {
1280
+ return new t(e).or(s);
1281
+ }, i.prototype.xor = function(e) {
1282
+ return typeof e == "number" ? this.xorS(e) : this.xorM(e);
1283
+ }, i.prototype.xorS = function(e) {
1284
+ for (let s = 0; s < this.rows; s++)
1285
+ for (let r = 0; r < this.columns; r++)
1286
+ this.set(s, r, this.get(s, r) ^ e);
1287
+ return this;
1288
+ }, i.prototype.xorM = function(e) {
1289
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1290
+ throw new RangeError("Matrices dimensions must be equal");
1291
+ for (let s = 0; s < this.rows; s++)
1292
+ for (let r = 0; r < this.columns; r++)
1293
+ this.set(s, r, this.get(s, r) ^ e.get(s, r));
1294
+ return this;
1295
+ }, i.xor = function(e, s) {
1296
+ return new t(e).xor(s);
1297
+ }, i.prototype.leftShift = function(e) {
1298
+ return typeof e == "number" ? this.leftShiftS(e) : this.leftShiftM(e);
1299
+ }, i.prototype.leftShiftS = function(e) {
1300
+ for (let s = 0; s < this.rows; s++)
1301
+ for (let r = 0; r < this.columns; r++)
1302
+ this.set(s, r, this.get(s, r) << e);
1303
+ return this;
1304
+ }, i.prototype.leftShiftM = function(e) {
1305
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1306
+ throw new RangeError("Matrices dimensions must be equal");
1307
+ for (let s = 0; s < this.rows; s++)
1308
+ for (let r = 0; r < this.columns; r++)
1309
+ this.set(s, r, this.get(s, r) << e.get(s, r));
1310
+ return this;
1311
+ }, i.leftShift = function(e, s) {
1312
+ return new t(e).leftShift(s);
1313
+ }, i.prototype.signPropagatingRightShift = function(e) {
1314
+ return typeof e == "number" ? this.signPropagatingRightShiftS(e) : this.signPropagatingRightShiftM(e);
1315
+ }, i.prototype.signPropagatingRightShiftS = function(e) {
1316
+ for (let s = 0; s < this.rows; s++)
1317
+ for (let r = 0; r < this.columns; r++)
1318
+ this.set(s, r, this.get(s, r) >> e);
1319
+ return this;
1320
+ }, i.prototype.signPropagatingRightShiftM = function(e) {
1321
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1322
+ throw new RangeError("Matrices dimensions must be equal");
1323
+ for (let s = 0; s < this.rows; s++)
1324
+ for (let r = 0; r < this.columns; r++)
1325
+ this.set(s, r, this.get(s, r) >> e.get(s, r));
1326
+ return this;
1327
+ }, i.signPropagatingRightShift = function(e, s) {
1328
+ return new t(e).signPropagatingRightShift(s);
1329
+ }, i.prototype.rightShift = function(e) {
1330
+ return typeof e == "number" ? this.rightShiftS(e) : this.rightShiftM(e);
1331
+ }, i.prototype.rightShiftS = function(e) {
1332
+ for (let s = 0; s < this.rows; s++)
1333
+ for (let r = 0; r < this.columns; r++)
1334
+ this.set(s, r, this.get(s, r) >>> e);
1335
+ return this;
1336
+ }, i.prototype.rightShiftM = function(e) {
1337
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1338
+ throw new RangeError("Matrices dimensions must be equal");
1339
+ for (let s = 0; s < this.rows; s++)
1340
+ for (let r = 0; r < this.columns; r++)
1341
+ this.set(s, r, this.get(s, r) >>> e.get(s, r));
1342
+ return this;
1343
+ }, i.rightShift = function(e, s) {
1344
+ return new t(e).rightShift(s);
1345
+ }, i.prototype.zeroFillRightShift = i.prototype.rightShift, i.prototype.zeroFillRightShiftS = i.prototype.rightShiftS, i.prototype.zeroFillRightShiftM = i.prototype.rightShiftM, i.zeroFillRightShift = i.rightShift, i.prototype.not = function() {
1346
+ for (let e = 0; e < this.rows; e++)
1347
+ for (let s = 0; s < this.columns; s++)
1348
+ this.set(e, s, ~this.get(e, s));
1349
+ return this;
1350
+ }, i.not = function(e) {
1351
+ return new t(e).not();
1352
+ }, i.prototype.abs = function() {
1353
+ for (let e = 0; e < this.rows; e++)
1354
+ for (let s = 0; s < this.columns; s++)
1355
+ this.set(e, s, Math.abs(this.get(e, s)));
1356
+ return this;
1357
+ }, i.abs = function(e) {
1358
+ return new t(e).abs();
1359
+ }, i.prototype.acos = function() {
1360
+ for (let e = 0; e < this.rows; e++)
1361
+ for (let s = 0; s < this.columns; s++)
1362
+ this.set(e, s, Math.acos(this.get(e, s)));
1363
+ return this;
1364
+ }, i.acos = function(e) {
1365
+ return new t(e).acos();
1366
+ }, i.prototype.acosh = function() {
1367
+ for (let e = 0; e < this.rows; e++)
1368
+ for (let s = 0; s < this.columns; s++)
1369
+ this.set(e, s, Math.acosh(this.get(e, s)));
1370
+ return this;
1371
+ }, i.acosh = function(e) {
1372
+ return new t(e).acosh();
1373
+ }, i.prototype.asin = function() {
1374
+ for (let e = 0; e < this.rows; e++)
1375
+ for (let s = 0; s < this.columns; s++)
1376
+ this.set(e, s, Math.asin(this.get(e, s)));
1377
+ return this;
1378
+ }, i.asin = function(e) {
1379
+ return new t(e).asin();
1380
+ }, i.prototype.asinh = function() {
1381
+ for (let e = 0; e < this.rows; e++)
1382
+ for (let s = 0; s < this.columns; s++)
1383
+ this.set(e, s, Math.asinh(this.get(e, s)));
1384
+ return this;
1385
+ }, i.asinh = function(e) {
1386
+ return new t(e).asinh();
1387
+ }, i.prototype.atan = function() {
1388
+ for (let e = 0; e < this.rows; e++)
1389
+ for (let s = 0; s < this.columns; s++)
1390
+ this.set(e, s, Math.atan(this.get(e, s)));
1391
+ return this;
1392
+ }, i.atan = function(e) {
1393
+ return new t(e).atan();
1394
+ }, i.prototype.atanh = function() {
1395
+ for (let e = 0; e < this.rows; e++)
1396
+ for (let s = 0; s < this.columns; s++)
1397
+ this.set(e, s, Math.atanh(this.get(e, s)));
1398
+ return this;
1399
+ }, i.atanh = function(e) {
1400
+ return new t(e).atanh();
1401
+ }, i.prototype.cbrt = function() {
1402
+ for (let e = 0; e < this.rows; e++)
1403
+ for (let s = 0; s < this.columns; s++)
1404
+ this.set(e, s, Math.cbrt(this.get(e, s)));
1405
+ return this;
1406
+ }, i.cbrt = function(e) {
1407
+ return new t(e).cbrt();
1408
+ }, i.prototype.ceil = function() {
1409
+ for (let e = 0; e < this.rows; e++)
1410
+ for (let s = 0; s < this.columns; s++)
1411
+ this.set(e, s, Math.ceil(this.get(e, s)));
1412
+ return this;
1413
+ }, i.ceil = function(e) {
1414
+ return new t(e).ceil();
1415
+ }, i.prototype.clz32 = function() {
1416
+ for (let e = 0; e < this.rows; e++)
1417
+ for (let s = 0; s < this.columns; s++)
1418
+ this.set(e, s, Math.clz32(this.get(e, s)));
1419
+ return this;
1420
+ }, i.clz32 = function(e) {
1421
+ return new t(e).clz32();
1422
+ }, i.prototype.cos = function() {
1423
+ for (let e = 0; e < this.rows; e++)
1424
+ for (let s = 0; s < this.columns; s++)
1425
+ this.set(e, s, Math.cos(this.get(e, s)));
1426
+ return this;
1427
+ }, i.cos = function(e) {
1428
+ return new t(e).cos();
1429
+ }, i.prototype.cosh = function() {
1430
+ for (let e = 0; e < this.rows; e++)
1431
+ for (let s = 0; s < this.columns; s++)
1432
+ this.set(e, s, Math.cosh(this.get(e, s)));
1433
+ return this;
1434
+ }, i.cosh = function(e) {
1435
+ return new t(e).cosh();
1436
+ }, i.prototype.exp = function() {
1437
+ for (let e = 0; e < this.rows; e++)
1438
+ for (let s = 0; s < this.columns; s++)
1439
+ this.set(e, s, Math.exp(this.get(e, s)));
1440
+ return this;
1441
+ }, i.exp = function(e) {
1442
+ return new t(e).exp();
1443
+ }, i.prototype.expm1 = function() {
1444
+ for (let e = 0; e < this.rows; e++)
1445
+ for (let s = 0; s < this.columns; s++)
1446
+ this.set(e, s, Math.expm1(this.get(e, s)));
1447
+ return this;
1448
+ }, i.expm1 = function(e) {
1449
+ return new t(e).expm1();
1450
+ }, i.prototype.floor = function() {
1451
+ for (let e = 0; e < this.rows; e++)
1452
+ for (let s = 0; s < this.columns; s++)
1453
+ this.set(e, s, Math.floor(this.get(e, s)));
1454
+ return this;
1455
+ }, i.floor = function(e) {
1456
+ return new t(e).floor();
1457
+ }, i.prototype.fround = function() {
1458
+ for (let e = 0; e < this.rows; e++)
1459
+ for (let s = 0; s < this.columns; s++)
1460
+ this.set(e, s, Math.fround(this.get(e, s)));
1461
+ return this;
1462
+ }, i.fround = function(e) {
1463
+ return new t(e).fround();
1464
+ }, i.prototype.log = function() {
1465
+ for (let e = 0; e < this.rows; e++)
1466
+ for (let s = 0; s < this.columns; s++)
1467
+ this.set(e, s, Math.log(this.get(e, s)));
1468
+ return this;
1469
+ }, i.log = function(e) {
1470
+ return new t(e).log();
1471
+ }, i.prototype.log1p = function() {
1472
+ for (let e = 0; e < this.rows; e++)
1473
+ for (let s = 0; s < this.columns; s++)
1474
+ this.set(e, s, Math.log1p(this.get(e, s)));
1475
+ return this;
1476
+ }, i.log1p = function(e) {
1477
+ return new t(e).log1p();
1478
+ }, i.prototype.log10 = function() {
1479
+ for (let e = 0; e < this.rows; e++)
1480
+ for (let s = 0; s < this.columns; s++)
1481
+ this.set(e, s, Math.log10(this.get(e, s)));
1482
+ return this;
1483
+ }, i.log10 = function(e) {
1484
+ return new t(e).log10();
1485
+ }, i.prototype.log2 = function() {
1486
+ for (let e = 0; e < this.rows; e++)
1487
+ for (let s = 0; s < this.columns; s++)
1488
+ this.set(e, s, Math.log2(this.get(e, s)));
1489
+ return this;
1490
+ }, i.log2 = function(e) {
1491
+ return new t(e).log2();
1492
+ }, i.prototype.round = function() {
1493
+ for (let e = 0; e < this.rows; e++)
1494
+ for (let s = 0; s < this.columns; s++)
1495
+ this.set(e, s, Math.round(this.get(e, s)));
1496
+ return this;
1497
+ }, i.round = function(e) {
1498
+ return new t(e).round();
1499
+ }, i.prototype.sign = function() {
1500
+ for (let e = 0; e < this.rows; e++)
1501
+ for (let s = 0; s < this.columns; s++)
1502
+ this.set(e, s, Math.sign(this.get(e, s)));
1503
+ return this;
1504
+ }, i.sign = function(e) {
1505
+ return new t(e).sign();
1506
+ }, i.prototype.sin = function() {
1507
+ for (let e = 0; e < this.rows; e++)
1508
+ for (let s = 0; s < this.columns; s++)
1509
+ this.set(e, s, Math.sin(this.get(e, s)));
1510
+ return this;
1511
+ }, i.sin = function(e) {
1512
+ return new t(e).sin();
1513
+ }, i.prototype.sinh = function() {
1514
+ for (let e = 0; e < this.rows; e++)
1515
+ for (let s = 0; s < this.columns; s++)
1516
+ this.set(e, s, Math.sinh(this.get(e, s)));
1517
+ return this;
1518
+ }, i.sinh = function(e) {
1519
+ return new t(e).sinh();
1520
+ }, i.prototype.sqrt = function() {
1521
+ for (let e = 0; e < this.rows; e++)
1522
+ for (let s = 0; s < this.columns; s++)
1523
+ this.set(e, s, Math.sqrt(this.get(e, s)));
1524
+ return this;
1525
+ }, i.sqrt = function(e) {
1526
+ return new t(e).sqrt();
1527
+ }, i.prototype.tan = function() {
1528
+ for (let e = 0; e < this.rows; e++)
1529
+ for (let s = 0; s < this.columns; s++)
1530
+ this.set(e, s, Math.tan(this.get(e, s)));
1531
+ return this;
1532
+ }, i.tan = function(e) {
1533
+ return new t(e).tan();
1534
+ }, i.prototype.tanh = function() {
1535
+ for (let e = 0; e < this.rows; e++)
1536
+ for (let s = 0; s < this.columns; s++)
1537
+ this.set(e, s, Math.tanh(this.get(e, s)));
1538
+ return this;
1539
+ }, i.tanh = function(e) {
1540
+ return new t(e).tanh();
1541
+ }, i.prototype.trunc = function() {
1542
+ for (let e = 0; e < this.rows; e++)
1543
+ for (let s = 0; s < this.columns; s++)
1544
+ this.set(e, s, Math.trunc(this.get(e, s)));
1545
+ return this;
1546
+ }, i.trunc = function(e) {
1547
+ return new t(e).trunc();
1548
+ }, i.pow = function(e, s) {
1549
+ return new t(e).pow(s);
1550
+ }, i.prototype.pow = function(e) {
1551
+ return typeof e == "number" ? this.powS(e) : this.powM(e);
1552
+ }, i.prototype.powS = function(e) {
1553
+ for (let s = 0; s < this.rows; s++)
1554
+ for (let r = 0; r < this.columns; r++)
1555
+ this.set(s, r, Math.pow(this.get(s, r), e));
1556
+ return this;
1557
+ }, i.prototype.powM = function(e) {
1558
+ if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
1559
+ throw new RangeError("Matrices dimensions must be equal");
1560
+ for (let s = 0; s < this.rows; s++)
1561
+ for (let r = 0; r < this.columns; r++)
1562
+ this.set(s, r, Math.pow(this.get(s, r), e.get(s, r)));
1563
+ return this;
1564
+ };
1565
+ }
1566
+ function Y(i, t, n) {
1567
+ let e = n ? i.rows : i.rows - 1;
1568
+ if (t < 0 || t > e)
1569
+ throw new RangeError("Row index out of range");
1570
+ }
1571
+ function X(i, t, n) {
1572
+ let e = n ? i.columns : i.columns - 1;
1573
+ if (t < 0 || t > e)
1574
+ throw new RangeError("Column index out of range");
1575
+ }
1576
+ function lt(i, t) {
1577
+ if (t.to1DArray && (t = t.to1DArray()), t.length !== i.columns)
1578
+ throw new RangeError(
1579
+ "vector size must be the same as the number of columns"
1580
+ );
1581
+ return t;
1582
+ }
1583
+ function ut(i, t) {
1584
+ if (t.to1DArray && (t = t.to1DArray()), t.length !== i.rows)
1585
+ throw new RangeError("vector size must be the same as the number of rows");
1586
+ return t;
1587
+ }
1588
+ function an(i, t) {
1589
+ if (!z(t))
1590
+ throw new TypeError("row indices must be an array");
1591
+ for (let n = 0; n < t.length; n++)
1592
+ if (t[n] < 0 || t[n] >= i.rows)
1593
+ throw new RangeError("row indices are out of range");
1594
+ }
1595
+ function cn(i, t) {
1596
+ if (!z(t))
1597
+ throw new TypeError("column indices must be an array");
1598
+ for (let n = 0; n < t.length; n++)
1599
+ if (t[n] < 0 || t[n] >= i.columns)
1600
+ throw new RangeError("column indices are out of range");
1601
+ }
1602
+ function Zt(i, t, n, e, s) {
1603
+ if (arguments.length !== 5)
1604
+ throw new RangeError("expected 4 arguments");
1605
+ if (Et("startRow", t), Et("endRow", n), Et("startColumn", e), Et("endColumn", s), t > n || e > s || t < 0 || t >= i.rows || n < 0 || n >= i.rows || e < 0 || e >= i.columns || s < 0 || s >= i.columns)
1606
+ throw new RangeError("Submatrix indices are out of range");
1607
+ }
1608
+ function Tt(i, t = 0) {
1609
+ let n = [];
1610
+ for (let e = 0; e < i; e++)
1611
+ n.push(t);
1612
+ return n;
1613
+ }
1614
+ function Et(i, t) {
1615
+ if (typeof t != "number")
1616
+ throw new TypeError(`${i} must be a number`);
1617
+ }
1618
+ function ht(i) {
1619
+ if (i.isEmpty())
1620
+ throw new Error("Empty matrix has no elements to index");
1621
+ }
1622
+ function fn(i) {
1623
+ let t = Tt(i.rows);
1624
+ for (let n = 0; n < i.rows; ++n)
1625
+ for (let e = 0; e < i.columns; ++e)
1626
+ t[n] += i.get(n, e);
1627
+ return t;
1628
+ }
1629
+ function gn(i) {
1630
+ let t = Tt(i.columns);
1631
+ for (let n = 0; n < i.rows; ++n)
1632
+ for (let e = 0; e < i.columns; ++e)
1633
+ t[e] += i.get(n, e);
1634
+ return t;
1635
+ }
1636
+ function mn(i) {
1637
+ let t = 0;
1638
+ for (let n = 0; n < i.rows; n++)
1639
+ for (let e = 0; e < i.columns; e++)
1640
+ t += i.get(n, e);
1641
+ return t;
1642
+ }
1643
+ function pn(i) {
1644
+ let t = Tt(i.rows, 1);
1645
+ for (let n = 0; n < i.rows; ++n)
1646
+ for (let e = 0; e < i.columns; ++e)
1647
+ t[n] *= i.get(n, e);
1648
+ return t;
1649
+ }
1650
+ function wn(i) {
1651
+ let t = Tt(i.columns, 1);
1652
+ for (let n = 0; n < i.rows; ++n)
1653
+ for (let e = 0; e < i.columns; ++e)
1654
+ t[e] *= i.get(n, e);
1655
+ return t;
1656
+ }
1657
+ function dn(i) {
1658
+ let t = 1;
1659
+ for (let n = 0; n < i.rows; n++)
1660
+ for (let e = 0; e < i.columns; e++)
1661
+ t *= i.get(n, e);
1662
+ return t;
1663
+ }
1664
+ function yn(i, t, n) {
1665
+ const e = i.rows, s = i.columns, r = [];
1666
+ for (let o = 0; o < e; o++) {
1667
+ let h = 0, u = 0, l = 0;
1668
+ for (let c = 0; c < s; c++)
1669
+ l = i.get(o, c) - n[o], h += l, u += l * l;
1670
+ t ? r.push((u - h * h / s) / (s - 1)) : r.push((u - h * h / s) / s);
1671
+ }
1672
+ return r;
1673
+ }
1674
+ function Pn(i, t, n) {
1675
+ const e = i.rows, s = i.columns, r = [];
1676
+ for (let o = 0; o < s; o++) {
1677
+ let h = 0, u = 0, l = 0;
1678
+ for (let c = 0; c < e; c++)
1679
+ l = i.get(c, o) - n[o], h += l, u += l * l;
1680
+ t ? r.push((u - h * h / e) / (e - 1)) : r.push((u - h * h / e) / e);
1681
+ }
1682
+ return r;
1683
+ }
1684
+ function Mn(i, t, n) {
1685
+ const e = i.rows, s = i.columns, r = e * s;
1686
+ let o = 0, h = 0, u = 0;
1687
+ for (let l = 0; l < e; l++)
1688
+ for (let c = 0; c < s; c++)
1689
+ u = i.get(l, c) - n, o += u, h += u * u;
1690
+ return t ? (h - o * o / r) / (r - 1) : (h - o * o / r) / r;
1691
+ }
1692
+ function En(i, t) {
1693
+ for (let n = 0; n < i.rows; n++)
1694
+ for (let e = 0; e < i.columns; e++)
1695
+ i.set(n, e, i.get(n, e) - t[n]);
1696
+ }
1697
+ function Sn(i, t) {
1698
+ for (let n = 0; n < i.rows; n++)
1699
+ for (let e = 0; e < i.columns; e++)
1700
+ i.set(n, e, i.get(n, e) - t[e]);
1701
+ }
1702
+ function bn(i, t) {
1703
+ for (let n = 0; n < i.rows; n++)
1704
+ for (let e = 0; e < i.columns; e++)
1705
+ i.set(n, e, i.get(n, e) - t);
1706
+ }
1707
+ function jn(i) {
1708
+ const t = [];
1709
+ for (let n = 0; n < i.rows; n++) {
1710
+ let e = 0;
1711
+ for (let s = 0; s < i.columns; s++)
1712
+ e += Math.pow(i.get(n, s), 2) / (i.columns - 1);
1713
+ t.push(Math.sqrt(e));
1714
+ }
1715
+ return t;
1716
+ }
1717
+ function vn(i, t) {
1718
+ for (let n = 0; n < i.rows; n++)
1719
+ for (let e = 0; e < i.columns; e++)
1720
+ i.set(n, e, i.get(n, e) / t[n]);
1721
+ }
1722
+ function kn(i) {
1723
+ const t = [];
1724
+ for (let n = 0; n < i.columns; n++) {
1725
+ let e = 0;
1726
+ for (let s = 0; s < i.rows; s++)
1727
+ e += Math.pow(i.get(s, n), 2) / (i.rows - 1);
1728
+ t.push(Math.sqrt(e));
1729
+ }
1730
+ return t;
1731
+ }
1732
+ function In(i, t) {
1733
+ for (let n = 0; n < i.rows; n++)
1734
+ for (let e = 0; e < i.columns; e++)
1735
+ i.set(n, e, i.get(n, e) / t[e]);
1736
+ }
1737
+ function xn(i) {
1738
+ const t = i.size - 1;
1739
+ let n = 0;
1740
+ for (let e = 0; e < i.columns; e++)
1741
+ for (let s = 0; s < i.rows; s++)
1742
+ n += Math.pow(i.get(s, e), 2) / t;
1743
+ return Math.sqrt(n);
1744
+ }
1745
+ function Rn(i, t) {
1746
+ for (let n = 0; n < i.rows; n++)
1747
+ for (let e = 0; e < i.columns; e++)
1748
+ i.set(n, e, i.get(n, e) / t);
1749
+ }
1750
+ class v {
1751
+ static from1DArray(t, n, e) {
1752
+ if (t * n !== e.length)
1753
+ throw new RangeError("data length does not match given dimensions");
1754
+ let r = new j(t, n);
1755
+ for (let o = 0; o < t; o++)
1756
+ for (let h = 0; h < n; h++)
1757
+ r.set(o, h, e[o * n + h]);
1758
+ return r;
1759
+ }
1760
+ static rowVector(t) {
1761
+ let n = new j(1, t.length);
1762
+ for (let e = 0; e < t.length; e++)
1763
+ n.set(0, e, t[e]);
1764
+ return n;
1765
+ }
1766
+ static columnVector(t) {
1767
+ let n = new j(t.length, 1);
1768
+ for (let e = 0; e < t.length; e++)
1769
+ n.set(e, 0, t[e]);
1770
+ return n;
1771
+ }
1772
+ static zeros(t, n) {
1773
+ return new j(t, n);
1774
+ }
1775
+ static ones(t, n) {
1776
+ return new j(t, n).fill(1);
1777
+ }
1778
+ static rand(t, n, e = {}) {
1779
+ if (typeof e != "object")
1780
+ throw new TypeError("options must be an object");
1781
+ const { random: s = Math.random } = e;
1782
+ let r = new j(t, n);
1783
+ for (let o = 0; o < t; o++)
1784
+ for (let h = 0; h < n; h++)
1785
+ r.set(o, h, s());
1786
+ return r;
1787
+ }
1788
+ static randInt(t, n, e = {}) {
1789
+ if (typeof e != "object")
1790
+ throw new TypeError("options must be an object");
1791
+ const { min: s = 0, max: r = 1e3, random: o = Math.random } = e;
1792
+ if (!Number.isInteger(s))
1793
+ throw new TypeError("min must be an integer");
1794
+ if (!Number.isInteger(r))
1795
+ throw new TypeError("max must be an integer");
1796
+ if (s >= r)
1797
+ throw new RangeError("min must be smaller than max");
1798
+ let h = r - s, u = new j(t, n);
1799
+ for (let l = 0; l < t; l++)
1800
+ for (let c = 0; c < n; c++) {
1801
+ let a = s + Math.round(o() * h);
1802
+ u.set(l, c, a);
1803
+ }
1804
+ return u;
1805
+ }
1806
+ static eye(t, n, e) {
1807
+ n === void 0 && (n = t), e === void 0 && (e = 1);
1808
+ let s = Math.min(t, n), r = this.zeros(t, n);
1809
+ for (let o = 0; o < s; o++)
1810
+ r.set(o, o, e);
1811
+ return r;
1812
+ }
1813
+ static diag(t, n, e) {
1814
+ let s = t.length;
1815
+ n === void 0 && (n = s), e === void 0 && (e = n);
1816
+ let r = Math.min(s, n, e), o = this.zeros(n, e);
1817
+ for (let h = 0; h < r; h++)
1818
+ o.set(h, h, t[h]);
1819
+ return o;
1820
+ }
1821
+ static min(t, n) {
1822
+ t = this.checkMatrix(t), n = this.checkMatrix(n);
1823
+ let e = t.rows, s = t.columns, r = new j(e, s);
1824
+ for (let o = 0; o < e; o++)
1825
+ for (let h = 0; h < s; h++)
1826
+ r.set(o, h, Math.min(t.get(o, h), n.get(o, h)));
1827
+ return r;
1828
+ }
1829
+ static max(t, n) {
1830
+ t = this.checkMatrix(t), n = this.checkMatrix(n);
1831
+ let e = t.rows, s = t.columns, r = new this(e, s);
1832
+ for (let o = 0; o < e; o++)
1833
+ for (let h = 0; h < s; h++)
1834
+ r.set(o, h, Math.max(t.get(o, h), n.get(o, h)));
1835
+ return r;
1836
+ }
1837
+ static checkMatrix(t) {
1838
+ return v.isMatrix(t) ? t : new j(t);
1839
+ }
1840
+ static isMatrix(t) {
1841
+ return t != null && t.klass === "Matrix";
1842
+ }
1843
+ get size() {
1844
+ return this.rows * this.columns;
1845
+ }
1846
+ apply(t) {
1847
+ if (typeof t != "function")
1848
+ throw new TypeError("callback must be a function");
1849
+ for (let n = 0; n < this.rows; n++)
1850
+ for (let e = 0; e < this.columns; e++)
1851
+ t.call(this, n, e);
1852
+ return this;
1853
+ }
1854
+ to1DArray() {
1855
+ let t = [];
1856
+ for (let n = 0; n < this.rows; n++)
1857
+ for (let e = 0; e < this.columns; e++)
1858
+ t.push(this.get(n, e));
1859
+ return t;
1860
+ }
1861
+ to2DArray() {
1862
+ let t = [];
1863
+ for (let n = 0; n < this.rows; n++) {
1864
+ t.push([]);
1865
+ for (let e = 0; e < this.columns; e++)
1866
+ t[n].push(this.get(n, e));
1867
+ }
1868
+ return t;
1869
+ }
1870
+ toJSON() {
1871
+ return this.to2DArray();
1872
+ }
1873
+ isRowVector() {
1874
+ return this.rows === 1;
1875
+ }
1876
+ isColumnVector() {
1877
+ return this.columns === 1;
1878
+ }
1879
+ isVector() {
1880
+ return this.rows === 1 || this.columns === 1;
1881
+ }
1882
+ isSquare() {
1883
+ return this.rows === this.columns;
1884
+ }
1885
+ isEmpty() {
1886
+ return this.rows === 0 || this.columns === 0;
1887
+ }
1888
+ isSymmetric() {
1889
+ if (this.isSquare()) {
1890
+ for (let t = 0; t < this.rows; t++)
1891
+ for (let n = 0; n <= t; n++)
1892
+ if (this.get(t, n) !== this.get(n, t))
1893
+ return !1;
1894
+ return !0;
1895
+ }
1896
+ return !1;
1897
+ }
1898
+ isEchelonForm() {
1899
+ let t = 0, n = 0, e = -1, s = !0, r = !1;
1900
+ for (; t < this.rows && s; ) {
1901
+ for (n = 0, r = !1; n < this.columns && r === !1; )
1902
+ this.get(t, n) === 0 ? n++ : this.get(t, n) === 1 && n > e ? (r = !0, e = n) : (s = !1, r = !0);
1903
+ t++;
1904
+ }
1905
+ return s;
1906
+ }
1907
+ isReducedEchelonForm() {
1908
+ let t = 0, n = 0, e = -1, s = !0, r = !1;
1909
+ for (; t < this.rows && s; ) {
1910
+ for (n = 0, r = !1; n < this.columns && r === !1; )
1911
+ this.get(t, n) === 0 ? n++ : this.get(t, n) === 1 && n > e ? (r = !0, e = n) : (s = !1, r = !0);
1912
+ for (let o = n + 1; o < this.rows; o++)
1913
+ this.get(t, o) !== 0 && (s = !1);
1914
+ t++;
1915
+ }
1916
+ return s;
1917
+ }
1918
+ echelonForm() {
1919
+ let t = this.clone(), n = 0, e = 0;
1920
+ for (; n < t.rows && e < t.columns; ) {
1921
+ let s = n;
1922
+ for (let r = n; r < t.rows; r++)
1923
+ t.get(r, e) > t.get(s, e) && (s = r);
1924
+ if (t.get(s, e) === 0)
1925
+ e++;
1926
+ else {
1927
+ t.swapRows(n, s);
1928
+ let r = t.get(n, e);
1929
+ for (let o = e; o < t.columns; o++)
1930
+ t.set(n, o, t.get(n, o) / r);
1931
+ for (let o = n + 1; o < t.rows; o++) {
1932
+ let h = t.get(o, e) / t.get(n, e);
1933
+ t.set(o, e, 0);
1934
+ for (let u = e + 1; u < t.columns; u++)
1935
+ t.set(o, u, t.get(o, u) - t.get(n, u) * h);
1936
+ }
1937
+ n++, e++;
1938
+ }
1939
+ }
1940
+ return t;
1941
+ }
1942
+ reducedEchelonForm() {
1943
+ let t = this.echelonForm(), n = t.columns, e = t.rows, s = e - 1;
1944
+ for (; s >= 0; )
1945
+ if (t.maxRow(s) === 0)
1946
+ s--;
1947
+ else {
1948
+ let r = 0, o = !1;
1949
+ for (; r < e && o === !1; )
1950
+ t.get(s, r) === 1 ? o = !0 : r++;
1951
+ for (let h = 0; h < s; h++) {
1952
+ let u = t.get(h, r);
1953
+ for (let l = r; l < n; l++) {
1954
+ let c = t.get(h, l) - u * t.get(s, l);
1955
+ t.set(h, l, c);
1956
+ }
1957
+ }
1958
+ s--;
1959
+ }
1960
+ return t;
1961
+ }
1962
+ set() {
1963
+ throw new Error("set method is unimplemented");
1964
+ }
1965
+ get() {
1966
+ throw new Error("get method is unimplemented");
1967
+ }
1968
+ repeat(t = {}) {
1969
+ if (typeof t != "object")
1970
+ throw new TypeError("options must be an object");
1971
+ const { rows: n = 1, columns: e = 1 } = t;
1972
+ if (!Number.isInteger(n) || n <= 0)
1973
+ throw new TypeError("rows must be a positive integer");
1974
+ if (!Number.isInteger(e) || e <= 0)
1975
+ throw new TypeError("columns must be a positive integer");
1976
+ let s = new j(this.rows * n, this.columns * e);
1977
+ for (let r = 0; r < n; r++)
1978
+ for (let o = 0; o < e; o++)
1979
+ s.setSubMatrix(this, this.rows * r, this.columns * o);
1980
+ return s;
1981
+ }
1982
+ fill(t) {
1983
+ for (let n = 0; n < this.rows; n++)
1984
+ for (let e = 0; e < this.columns; e++)
1985
+ this.set(n, e, t);
1986
+ return this;
1987
+ }
1988
+ neg() {
1989
+ return this.mulS(-1);
1990
+ }
1991
+ getRow(t) {
1992
+ Y(this, t);
1993
+ let n = [];
1994
+ for (let e = 0; e < this.columns; e++)
1995
+ n.push(this.get(t, e));
1996
+ return n;
1997
+ }
1998
+ getRowVector(t) {
1999
+ return j.rowVector(this.getRow(t));
2000
+ }
2001
+ setRow(t, n) {
2002
+ Y(this, t), n = lt(this, n);
2003
+ for (let e = 0; e < this.columns; e++)
2004
+ this.set(t, e, n[e]);
2005
+ return this;
2006
+ }
2007
+ swapRows(t, n) {
2008
+ Y(this, t), Y(this, n);
2009
+ for (let e = 0; e < this.columns; e++) {
2010
+ let s = this.get(t, e);
2011
+ this.set(t, e, this.get(n, e)), this.set(n, e, s);
2012
+ }
2013
+ return this;
2014
+ }
2015
+ getColumn(t) {
2016
+ X(this, t);
2017
+ let n = [];
2018
+ for (let e = 0; e < this.rows; e++)
2019
+ n.push(this.get(e, t));
2020
+ return n;
2021
+ }
2022
+ getColumnVector(t) {
2023
+ return j.columnVector(this.getColumn(t));
2024
+ }
2025
+ setColumn(t, n) {
2026
+ X(this, t), n = ut(this, n);
2027
+ for (let e = 0; e < this.rows; e++)
2028
+ this.set(e, t, n[e]);
2029
+ return this;
2030
+ }
2031
+ swapColumns(t, n) {
2032
+ X(this, t), X(this, n);
2033
+ for (let e = 0; e < this.rows; e++) {
2034
+ let s = this.get(e, t);
2035
+ this.set(e, t, this.get(e, n)), this.set(e, n, s);
2036
+ }
2037
+ return this;
2038
+ }
2039
+ addRowVector(t) {
2040
+ t = lt(this, t);
2041
+ for (let n = 0; n < this.rows; n++)
2042
+ for (let e = 0; e < this.columns; e++)
2043
+ this.set(n, e, this.get(n, e) + t[e]);
2044
+ return this;
2045
+ }
2046
+ subRowVector(t) {
2047
+ t = lt(this, t);
2048
+ for (let n = 0; n < this.rows; n++)
2049
+ for (let e = 0; e < this.columns; e++)
2050
+ this.set(n, e, this.get(n, e) - t[e]);
2051
+ return this;
2052
+ }
2053
+ mulRowVector(t) {
2054
+ t = lt(this, t);
2055
+ for (let n = 0; n < this.rows; n++)
2056
+ for (let e = 0; e < this.columns; e++)
2057
+ this.set(n, e, this.get(n, e) * t[e]);
2058
+ return this;
2059
+ }
2060
+ divRowVector(t) {
2061
+ t = lt(this, t);
2062
+ for (let n = 0; n < this.rows; n++)
2063
+ for (let e = 0; e < this.columns; e++)
2064
+ this.set(n, e, this.get(n, e) / t[e]);
2065
+ return this;
2066
+ }
2067
+ addColumnVector(t) {
2068
+ t = ut(this, t);
2069
+ for (let n = 0; n < this.rows; n++)
2070
+ for (let e = 0; e < this.columns; e++)
2071
+ this.set(n, e, this.get(n, e) + t[n]);
2072
+ return this;
2073
+ }
2074
+ subColumnVector(t) {
2075
+ t = ut(this, t);
2076
+ for (let n = 0; n < this.rows; n++)
2077
+ for (let e = 0; e < this.columns; e++)
2078
+ this.set(n, e, this.get(n, e) - t[n]);
2079
+ return this;
2080
+ }
2081
+ mulColumnVector(t) {
2082
+ t = ut(this, t);
2083
+ for (let n = 0; n < this.rows; n++)
2084
+ for (let e = 0; e < this.columns; e++)
2085
+ this.set(n, e, this.get(n, e) * t[n]);
2086
+ return this;
2087
+ }
2088
+ divColumnVector(t) {
2089
+ t = ut(this, t);
2090
+ for (let n = 0; n < this.rows; n++)
2091
+ for (let e = 0; e < this.columns; e++)
2092
+ this.set(n, e, this.get(n, e) / t[n]);
2093
+ return this;
2094
+ }
2095
+ mulRow(t, n) {
2096
+ Y(this, t);
2097
+ for (let e = 0; e < this.columns; e++)
2098
+ this.set(t, e, this.get(t, e) * n);
2099
+ return this;
2100
+ }
2101
+ mulColumn(t, n) {
2102
+ X(this, t);
2103
+ for (let e = 0; e < this.rows; e++)
2104
+ this.set(e, t, this.get(e, t) * n);
2105
+ return this;
2106
+ }
2107
+ max(t) {
2108
+ if (this.isEmpty())
2109
+ return NaN;
2110
+ switch (t) {
2111
+ case "row": {
2112
+ const n = new Array(this.rows).fill(Number.NEGATIVE_INFINITY);
2113
+ for (let e = 0; e < this.rows; e++)
2114
+ for (let s = 0; s < this.columns; s++)
2115
+ this.get(e, s) > n[e] && (n[e] = this.get(e, s));
2116
+ return n;
2117
+ }
2118
+ case "column": {
2119
+ const n = new Array(this.columns).fill(Number.NEGATIVE_INFINITY);
2120
+ for (let e = 0; e < this.rows; e++)
2121
+ for (let s = 0; s < this.columns; s++)
2122
+ this.get(e, s) > n[s] && (n[s] = this.get(e, s));
2123
+ return n;
2124
+ }
2125
+ case void 0: {
2126
+ let n = this.get(0, 0);
2127
+ for (let e = 0; e < this.rows; e++)
2128
+ for (let s = 0; s < this.columns; s++)
2129
+ this.get(e, s) > n && (n = this.get(e, s));
2130
+ return n;
2131
+ }
2132
+ default:
2133
+ throw new Error(`invalid option: ${t}`);
2134
+ }
2135
+ }
2136
+ maxIndex() {
2137
+ ht(this);
2138
+ let t = this.get(0, 0), n = [0, 0];
2139
+ for (let e = 0; e < this.rows; e++)
2140
+ for (let s = 0; s < this.columns; s++)
2141
+ this.get(e, s) > t && (t = this.get(e, s), n[0] = e, n[1] = s);
2142
+ return n;
2143
+ }
2144
+ min(t) {
2145
+ if (this.isEmpty())
2146
+ return NaN;
2147
+ switch (t) {
2148
+ case "row": {
2149
+ const n = new Array(this.rows).fill(Number.POSITIVE_INFINITY);
2150
+ for (let e = 0; e < this.rows; e++)
2151
+ for (let s = 0; s < this.columns; s++)
2152
+ this.get(e, s) < n[e] && (n[e] = this.get(e, s));
2153
+ return n;
2154
+ }
2155
+ case "column": {
2156
+ const n = new Array(this.columns).fill(Number.POSITIVE_INFINITY);
2157
+ for (let e = 0; e < this.rows; e++)
2158
+ for (let s = 0; s < this.columns; s++)
2159
+ this.get(e, s) < n[s] && (n[s] = this.get(e, s));
2160
+ return n;
2161
+ }
2162
+ case void 0: {
2163
+ let n = this.get(0, 0);
2164
+ for (let e = 0; e < this.rows; e++)
2165
+ for (let s = 0; s < this.columns; s++)
2166
+ this.get(e, s) < n && (n = this.get(e, s));
2167
+ return n;
2168
+ }
2169
+ default:
2170
+ throw new Error(`invalid option: ${t}`);
2171
+ }
2172
+ }
2173
+ minIndex() {
2174
+ ht(this);
2175
+ let t = this.get(0, 0), n = [0, 0];
2176
+ for (let e = 0; e < this.rows; e++)
2177
+ for (let s = 0; s < this.columns; s++)
2178
+ this.get(e, s) < t && (t = this.get(e, s), n[0] = e, n[1] = s);
2179
+ return n;
2180
+ }
2181
+ maxRow(t) {
2182
+ if (Y(this, t), this.isEmpty())
2183
+ return NaN;
2184
+ let n = this.get(t, 0);
2185
+ for (let e = 1; e < this.columns; e++)
2186
+ this.get(t, e) > n && (n = this.get(t, e));
2187
+ return n;
2188
+ }
2189
+ maxRowIndex(t) {
2190
+ Y(this, t), ht(this);
2191
+ let n = this.get(t, 0), e = [t, 0];
2192
+ for (let s = 1; s < this.columns; s++)
2193
+ this.get(t, s) > n && (n = this.get(t, s), e[1] = s);
2194
+ return e;
2195
+ }
2196
+ minRow(t) {
2197
+ if (Y(this, t), this.isEmpty())
2198
+ return NaN;
2199
+ let n = this.get(t, 0);
2200
+ for (let e = 1; e < this.columns; e++)
2201
+ this.get(t, e) < n && (n = this.get(t, e));
2202
+ return n;
2203
+ }
2204
+ minRowIndex(t) {
2205
+ Y(this, t), ht(this);
2206
+ let n = this.get(t, 0), e = [t, 0];
2207
+ for (let s = 1; s < this.columns; s++)
2208
+ this.get(t, s) < n && (n = this.get(t, s), e[1] = s);
2209
+ return e;
2210
+ }
2211
+ maxColumn(t) {
2212
+ if (X(this, t), this.isEmpty())
2213
+ return NaN;
2214
+ let n = this.get(0, t);
2215
+ for (let e = 1; e < this.rows; e++)
2216
+ this.get(e, t) > n && (n = this.get(e, t));
2217
+ return n;
2218
+ }
2219
+ maxColumnIndex(t) {
2220
+ X(this, t), ht(this);
2221
+ let n = this.get(0, t), e = [0, t];
2222
+ for (let s = 1; s < this.rows; s++)
2223
+ this.get(s, t) > n && (n = this.get(s, t), e[0] = s);
2224
+ return e;
2225
+ }
2226
+ minColumn(t) {
2227
+ if (X(this, t), this.isEmpty())
2228
+ return NaN;
2229
+ let n = this.get(0, t);
2230
+ for (let e = 1; e < this.rows; e++)
2231
+ this.get(e, t) < n && (n = this.get(e, t));
2232
+ return n;
2233
+ }
2234
+ minColumnIndex(t) {
2235
+ X(this, t), ht(this);
2236
+ let n = this.get(0, t), e = [0, t];
2237
+ for (let s = 1; s < this.rows; s++)
2238
+ this.get(s, t) < n && (n = this.get(s, t), e[0] = s);
2239
+ return e;
2240
+ }
2241
+ diag() {
2242
+ let t = Math.min(this.rows, this.columns), n = [];
2243
+ for (let e = 0; e < t; e++)
2244
+ n.push(this.get(e, e));
2245
+ return n;
2246
+ }
2247
+ norm(t = "frobenius") {
2248
+ let n = 0;
2249
+ if (t === "max")
2250
+ return this.max();
2251
+ if (t === "frobenius") {
2252
+ for (let e = 0; e < this.rows; e++)
2253
+ for (let s = 0; s < this.columns; s++)
2254
+ n = n + this.get(e, s) * this.get(e, s);
2255
+ return Math.sqrt(n);
2256
+ } else
2257
+ throw new RangeError(`unknown norm type: ${t}`);
2258
+ }
2259
+ cumulativeSum() {
2260
+ let t = 0;
2261
+ for (let n = 0; n < this.rows; n++)
2262
+ for (let e = 0; e < this.columns; e++)
2263
+ t += this.get(n, e), this.set(n, e, t);
2264
+ return this;
2265
+ }
2266
+ dot(t) {
2267
+ v.isMatrix(t) && (t = t.to1DArray());
2268
+ let n = this.to1DArray();
2269
+ if (n.length !== t.length)
2270
+ throw new RangeError("vectors do not have the same size");
2271
+ let e = 0;
2272
+ for (let s = 0; s < n.length; s++)
2273
+ e += n[s] * t[s];
2274
+ return e;
2275
+ }
2276
+ mmul(t) {
2277
+ t = j.checkMatrix(t);
2278
+ let n = this.rows, e = this.columns, s = t.columns, r = new j(n, s), o = new Float64Array(e);
2279
+ for (let h = 0; h < s; h++) {
2280
+ for (let u = 0; u < e; u++)
2281
+ o[u] = t.get(u, h);
2282
+ for (let u = 0; u < n; u++) {
2283
+ let l = 0;
2284
+ for (let c = 0; c < e; c++)
2285
+ l += this.get(u, c) * o[c];
2286
+ r.set(u, h, l);
2287
+ }
2288
+ }
2289
+ return r;
2290
+ }
2291
+ strassen2x2(t) {
2292
+ t = j.checkMatrix(t);
2293
+ let n = new j(2, 2);
2294
+ const e = this.get(0, 0), s = t.get(0, 0), r = this.get(0, 1), o = t.get(0, 1), h = this.get(1, 0), u = t.get(1, 0), l = this.get(1, 1), c = t.get(1, 1), a = (e + l) * (s + c), g = (h + l) * s, w = e * (o - c), m = l * (u - s), d = (e + r) * c, P = (h - e) * (s + o), f = (r - l) * (u + c), p = a + m - d + f, y = w + d, M = g + m, b = a - g + w + P;
2295
+ return n.set(0, 0, p), n.set(0, 1, y), n.set(1, 0, M), n.set(1, 1, b), n;
2296
+ }
2297
+ strassen3x3(t) {
2298
+ t = j.checkMatrix(t);
2299
+ let n = new j(3, 3);
2300
+ const e = this.get(0, 0), s = this.get(0, 1), r = this.get(0, 2), o = this.get(1, 0), h = this.get(1, 1), u = this.get(1, 2), l = this.get(2, 0), c = this.get(2, 1), a = this.get(2, 2), g = t.get(0, 0), w = t.get(0, 1), m = t.get(0, 2), d = t.get(1, 0), P = t.get(1, 1), f = t.get(1, 2), p = t.get(2, 0), y = t.get(2, 1), M = t.get(2, 2), b = (e + s + r - o - h - c - a) * P, x = (e - o) * (-w + P), k = h * (-g + w + d - P - f - p + M), S = (-e + o + h) * (g - w + P), _ = (o + h) * (-g + w), F = e * g, B = (-e + l + c) * (g - m + f), K = (-e + l) * (m - f), Q = (l + c) * (-g + m), Z = (e + s + r - h - u - l - c) * f, $ = c * (-g + m + d - P - f - p + y), N = (-r + c + a) * (P + p - y), dt = (r - a) * (P - y), H = r * p, rt = (c + a) * (-p + y), L = (-r + h + u) * (f + p - M), Gt = (r - u) * (f - M), Wt = (h + u) * (-p + M), Re = s * d, _e = u * y, Fe = o * m, Te = l * w, Ce = a * M, $e = F + H + Re, qe = b + S + _ + F + N + H + rt, Be = F + B + Q + Z + H + L + Wt, Oe = x + k + S + F + H + L + Gt, Ae = x + S + _ + F + _e, Ne = H + L + Gt + Wt + Fe, Le = F + B + K + $ + N + dt + H, Ve = N + dt + H + rt + Te, ze = F + B + K + Q + Ce;
2301
+ return n.set(0, 0, $e), n.set(0, 1, qe), n.set(0, 2, Be), n.set(1, 0, Oe), n.set(1, 1, Ae), n.set(1, 2, Ne), n.set(2, 0, Le), n.set(2, 1, Ve), n.set(2, 2, ze), n;
2302
+ }
2303
+ mmulStrassen(t) {
2304
+ t = j.checkMatrix(t);
2305
+ let n = this.clone(), e = n.rows, s = n.columns, r = t.rows, o = t.columns;
2306
+ s !== r && console.warn(
2307
+ `Multiplying ${e} x ${s} and ${r} x ${o} matrix: dimensions do not match.`
2308
+ );
2309
+ function h(a, g, w) {
2310
+ let m = a.rows, d = a.columns;
2311
+ if (m === g && d === w)
2312
+ return a;
2313
+ {
2314
+ let P = v.zeros(g, w);
2315
+ return P = P.setSubMatrix(a, 0, 0), P;
2316
+ }
2317
+ }
2318
+ let u = Math.max(e, r), l = Math.max(s, o);
2319
+ n = h(n, u, l), t = h(t, u, l);
2320
+ function c(a, g, w, m) {
2321
+ if (w <= 512 || m <= 512)
2322
+ return a.mmul(g);
2323
+ w % 2 === 1 && m % 2 === 1 ? (a = h(a, w + 1, m + 1), g = h(g, w + 1, m + 1)) : w % 2 === 1 ? (a = h(a, w + 1, m), g = h(g, w + 1, m)) : m % 2 === 1 && (a = h(a, w, m + 1), g = h(g, w, m + 1));
2324
+ let d = parseInt(a.rows / 2, 10), P = parseInt(a.columns / 2, 10), f = a.subMatrix(0, d - 1, 0, P - 1), p = g.subMatrix(0, d - 1, 0, P - 1), y = a.subMatrix(0, d - 1, P, a.columns - 1), M = g.subMatrix(0, d - 1, P, g.columns - 1), b = a.subMatrix(d, a.rows - 1, 0, P - 1), x = g.subMatrix(d, g.rows - 1, 0, P - 1), k = a.subMatrix(d, a.rows - 1, P, a.columns - 1), S = g.subMatrix(d, g.rows - 1, P, g.columns - 1), _ = c(
2325
+ v.add(f, k),
2326
+ v.add(p, S),
2327
+ d,
2328
+ P
2329
+ ), F = c(v.add(b, k), p, d, P), B = c(f, v.sub(M, S), d, P), K = c(k, v.sub(x, p), d, P), Q = c(v.add(f, y), S, d, P), Z = c(
2330
+ v.sub(b, f),
2331
+ v.add(p, M),
2332
+ d,
2333
+ P
2334
+ ), $ = c(
2335
+ v.sub(y, k),
2336
+ v.add(x, S),
2337
+ d,
2338
+ P
2339
+ ), N = v.add(_, K);
2340
+ N.sub(Q), N.add($);
2341
+ let dt = v.add(B, Q), H = v.add(F, K), rt = v.sub(_, F);
2342
+ rt.add(B), rt.add(Z);
2343
+ let L = v.zeros(2 * N.rows, 2 * N.columns);
2344
+ return L = L.setSubMatrix(N, 0, 0), L = L.setSubMatrix(dt, N.rows, 0), L = L.setSubMatrix(H, 0, N.columns), L = L.setSubMatrix(rt, N.rows, N.columns), L.subMatrix(0, w - 1, 0, m - 1);
2345
+ }
2346
+ return c(n, t, u, l);
2347
+ }
2348
+ scaleRows(t = {}) {
2349
+ if (typeof t != "object")
2350
+ throw new TypeError("options must be an object");
2351
+ const { min: n = 0, max: e = 1 } = t;
2352
+ if (!Number.isFinite(n))
2353
+ throw new TypeError("min must be a number");
2354
+ if (!Number.isFinite(e))
2355
+ throw new TypeError("max must be a number");
2356
+ if (n >= e)
2357
+ throw new RangeError("min must be smaller than max");
2358
+ let s = new j(this.rows, this.columns);
2359
+ for (let r = 0; r < this.rows; r++) {
2360
+ const o = this.getRow(r);
2361
+ o.length > 0 && Kt(o, { min: n, max: e, output: o }), s.setRow(r, o);
2362
+ }
2363
+ return s;
2364
+ }
2365
+ scaleColumns(t = {}) {
2366
+ if (typeof t != "object")
2367
+ throw new TypeError("options must be an object");
2368
+ const { min: n = 0, max: e = 1 } = t;
2369
+ if (!Number.isFinite(n))
2370
+ throw new TypeError("min must be a number");
2371
+ if (!Number.isFinite(e))
2372
+ throw new TypeError("max must be a number");
2373
+ if (n >= e)
2374
+ throw new RangeError("min must be smaller than max");
2375
+ let s = new j(this.rows, this.columns);
2376
+ for (let r = 0; r < this.columns; r++) {
2377
+ const o = this.getColumn(r);
2378
+ o.length && Kt(o, {
2379
+ min: n,
2380
+ max: e,
2381
+ output: o
2382
+ }), s.setColumn(r, o);
2383
+ }
2384
+ return s;
2385
+ }
2386
+ flipRows() {
2387
+ const t = Math.ceil(this.columns / 2);
2388
+ for (let n = 0; n < this.rows; n++)
2389
+ for (let e = 0; e < t; e++) {
2390
+ let s = this.get(n, e), r = this.get(n, this.columns - 1 - e);
2391
+ this.set(n, e, r), this.set(n, this.columns - 1 - e, s);
2392
+ }
2393
+ return this;
2394
+ }
2395
+ flipColumns() {
2396
+ const t = Math.ceil(this.rows / 2);
2397
+ for (let n = 0; n < this.columns; n++)
2398
+ for (let e = 0; e < t; e++) {
2399
+ let s = this.get(e, n), r = this.get(this.rows - 1 - e, n);
2400
+ this.set(e, n, r), this.set(this.rows - 1 - e, n, s);
2401
+ }
2402
+ return this;
2403
+ }
2404
+ kroneckerProduct(t) {
2405
+ t = j.checkMatrix(t);
2406
+ let n = this.rows, e = this.columns, s = t.rows, r = t.columns, o = new j(n * s, e * r);
2407
+ for (let h = 0; h < n; h++)
2408
+ for (let u = 0; u < e; u++)
2409
+ for (let l = 0; l < s; l++)
2410
+ for (let c = 0; c < r; c++)
2411
+ o.set(s * h + l, r * u + c, this.get(h, u) * t.get(l, c));
2412
+ return o;
2413
+ }
2414
+ kroneckerSum(t) {
2415
+ if (t = j.checkMatrix(t), !this.isSquare() || !t.isSquare())
2416
+ throw new Error("Kronecker Sum needs two Square Matrices");
2417
+ let n = this.rows, e = t.rows, s = this.kroneckerProduct(j.eye(e, e)), r = j.eye(n, n).kroneckerProduct(t);
2418
+ return s.add(r);
2419
+ }
2420
+ transpose() {
2421
+ let t = new j(this.columns, this.rows);
2422
+ for (let n = 0; n < this.rows; n++)
2423
+ for (let e = 0; e < this.columns; e++)
2424
+ t.set(e, n, this.get(n, e));
2425
+ return t;
2426
+ }
2427
+ sortRows(t = Ht) {
2428
+ for (let n = 0; n < this.rows; n++)
2429
+ this.setRow(n, this.getRow(n).sort(t));
2430
+ return this;
2431
+ }
2432
+ sortColumns(t = Ht) {
2433
+ for (let n = 0; n < this.columns; n++)
2434
+ this.setColumn(n, this.getColumn(n).sort(t));
2435
+ return this;
2436
+ }
2437
+ subMatrix(t, n, e, s) {
2438
+ Zt(this, t, n, e, s);
2439
+ let r = new j(
2440
+ n - t + 1,
2441
+ s - e + 1
2442
+ );
2443
+ for (let o = t; o <= n; o++)
2444
+ for (let h = e; h <= s; h++)
2445
+ r.set(o - t, h - e, this.get(o, h));
2446
+ return r;
2447
+ }
2448
+ subMatrixRow(t, n, e) {
2449
+ if (n === void 0 && (n = 0), e === void 0 && (e = this.columns - 1), n > e || n < 0 || n >= this.columns || e < 0 || e >= this.columns)
2450
+ throw new RangeError("Argument out of range");
2451
+ let s = new j(t.length, e - n + 1);
2452
+ for (let r = 0; r < t.length; r++)
2453
+ for (let o = n; o <= e; o++) {
2454
+ if (t[r] < 0 || t[r] >= this.rows)
2455
+ throw new RangeError(`Row index out of range: ${t[r]}`);
2456
+ s.set(r, o - n, this.get(t[r], o));
2457
+ }
2458
+ return s;
2459
+ }
2460
+ subMatrixColumn(t, n, e) {
2461
+ if (n === void 0 && (n = 0), e === void 0 && (e = this.rows - 1), n > e || n < 0 || n >= this.rows || e < 0 || e >= this.rows)
2462
+ throw new RangeError("Argument out of range");
2463
+ let s = new j(e - n + 1, t.length);
2464
+ for (let r = 0; r < t.length; r++)
2465
+ for (let o = n; o <= e; o++) {
2466
+ if (t[r] < 0 || t[r] >= this.columns)
2467
+ throw new RangeError(`Column index out of range: ${t[r]}`);
2468
+ s.set(o - n, r, this.get(o, t[r]));
2469
+ }
2470
+ return s;
2471
+ }
2472
+ setSubMatrix(t, n, e) {
2473
+ if (t = j.checkMatrix(t), t.isEmpty())
2474
+ return this;
2475
+ let s = n + t.rows - 1, r = e + t.columns - 1;
2476
+ Zt(this, n, s, e, r);
2477
+ for (let o = 0; o < t.rows; o++)
2478
+ for (let h = 0; h < t.columns; h++)
2479
+ this.set(n + o, e + h, t.get(o, h));
2480
+ return this;
2481
+ }
2482
+ selection(t, n) {
2483
+ an(this, t), cn(this, n);
2484
+ let e = new j(t.length, n.length);
2485
+ for (let s = 0; s < t.length; s++) {
2486
+ let r = t[s];
2487
+ for (let o = 0; o < n.length; o++) {
2488
+ let h = n[o];
2489
+ e.set(s, o, this.get(r, h));
2490
+ }
2491
+ }
2492
+ return e;
2493
+ }
2494
+ trace() {
2495
+ let t = Math.min(this.rows, this.columns), n = 0;
2496
+ for (let e = 0; e < t; e++)
2497
+ n += this.get(e, e);
2498
+ return n;
2499
+ }
2500
+ clone() {
2501
+ let t = new j(this.rows, this.columns);
2502
+ for (let n = 0; n < this.rows; n++)
2503
+ for (let e = 0; e < this.columns; e++)
2504
+ t.set(n, e, this.get(n, e));
2505
+ return t;
2506
+ }
2507
+ sum(t) {
2508
+ switch (t) {
2509
+ case "row":
2510
+ return fn(this);
2511
+ case "column":
2512
+ return gn(this);
2513
+ case void 0:
2514
+ return mn(this);
2515
+ default:
2516
+ throw new Error(`invalid option: ${t}`);
2517
+ }
2518
+ }
2519
+ product(t) {
2520
+ switch (t) {
2521
+ case "row":
2522
+ return pn(this);
2523
+ case "column":
2524
+ return wn(this);
2525
+ case void 0:
2526
+ return dn(this);
2527
+ default:
2528
+ throw new Error(`invalid option: ${t}`);
2529
+ }
2530
+ }
2531
+ mean(t) {
2532
+ const n = this.sum(t);
2533
+ switch (t) {
2534
+ case "row": {
2535
+ for (let e = 0; e < this.rows; e++)
2536
+ n[e] /= this.columns;
2537
+ return n;
2538
+ }
2539
+ case "column": {
2540
+ for (let e = 0; e < this.columns; e++)
2541
+ n[e] /= this.rows;
2542
+ return n;
2543
+ }
2544
+ case void 0:
2545
+ return n / this.size;
2546
+ default:
2547
+ throw new Error(`invalid option: ${t}`);
2548
+ }
2549
+ }
2550
+ variance(t, n = {}) {
2551
+ if (typeof t == "object" && (n = t, t = void 0), typeof n != "object")
2552
+ throw new TypeError("options must be an object");
2553
+ const { unbiased: e = !0, mean: s = this.mean(t) } = n;
2554
+ if (typeof e != "boolean")
2555
+ throw new TypeError("unbiased must be a boolean");
2556
+ switch (t) {
2557
+ case "row": {
2558
+ if (!z(s))
2559
+ throw new TypeError("mean must be an array");
2560
+ return yn(this, e, s);
2561
+ }
2562
+ case "column": {
2563
+ if (!z(s))
2564
+ throw new TypeError("mean must be an array");
2565
+ return Pn(this, e, s);
2566
+ }
2567
+ case void 0: {
2568
+ if (typeof s != "number")
2569
+ throw new TypeError("mean must be a number");
2570
+ return Mn(this, e, s);
2571
+ }
2572
+ default:
2573
+ throw new Error(`invalid option: ${t}`);
2574
+ }
2575
+ }
2576
+ standardDeviation(t, n) {
2577
+ typeof t == "object" && (n = t, t = void 0);
2578
+ const e = this.variance(t, n);
2579
+ if (t === void 0)
2580
+ return Math.sqrt(e);
2581
+ for (let s = 0; s < e.length; s++)
2582
+ e[s] = Math.sqrt(e[s]);
2583
+ return e;
2584
+ }
2585
+ center(t, n = {}) {
2586
+ if (typeof t == "object" && (n = t, t = void 0), typeof n != "object")
2587
+ throw new TypeError("options must be an object");
2588
+ const { center: e = this.mean(t) } = n;
2589
+ switch (t) {
2590
+ case "row": {
2591
+ if (!z(e))
2592
+ throw new TypeError("center must be an array");
2593
+ return En(this, e), this;
2594
+ }
2595
+ case "column": {
2596
+ if (!z(e))
2597
+ throw new TypeError("center must be an array");
2598
+ return Sn(this, e), this;
2599
+ }
2600
+ case void 0: {
2601
+ if (typeof e != "number")
2602
+ throw new TypeError("center must be a number");
2603
+ return bn(this, e), this;
2604
+ }
2605
+ default:
2606
+ throw new Error(`invalid option: ${t}`);
2607
+ }
2608
+ }
2609
+ scale(t, n = {}) {
2610
+ if (typeof t == "object" && (n = t, t = void 0), typeof n != "object")
2611
+ throw new TypeError("options must be an object");
2612
+ let e = n.scale;
2613
+ switch (t) {
2614
+ case "row": {
2615
+ if (e === void 0)
2616
+ e = jn(this);
2617
+ else if (!z(e))
2618
+ throw new TypeError("scale must be an array");
2619
+ return vn(this, e), this;
2620
+ }
2621
+ case "column": {
2622
+ if (e === void 0)
2623
+ e = kn(this);
2624
+ else if (!z(e))
2625
+ throw new TypeError("scale must be an array");
2626
+ return In(this, e), this;
2627
+ }
2628
+ case void 0: {
2629
+ if (e === void 0)
2630
+ e = xn(this);
2631
+ else if (typeof e != "number")
2632
+ throw new TypeError("scale must be a number");
2633
+ return Rn(this, e), this;
2634
+ }
2635
+ default:
2636
+ throw new Error(`invalid option: ${t}`);
2637
+ }
2638
+ }
2639
+ toString(t) {
2640
+ return we(this, t);
2641
+ }
2642
+ }
2643
+ v.prototype.klass = "Matrix";
2644
+ typeof Symbol < "u" && (v.prototype[Symbol.for("nodejs.util.inspect.custom")] = on);
2645
+ function Ht(i, t) {
2646
+ return i - t;
2647
+ }
2648
+ function _n(i) {
2649
+ return i.every((t) => typeof t == "number");
2650
+ }
2651
+ v.random = v.rand;
2652
+ v.randomInt = v.randInt;
2653
+ v.diagonal = v.diag;
2654
+ v.prototype.diagonal = v.prototype.diag;
2655
+ v.identity = v.eye;
2656
+ v.prototype.negate = v.prototype.neg;
2657
+ v.prototype.tensorProduct = v.prototype.kroneckerProduct;
2658
+ class j extends v {
2659
+ constructor(t, n) {
2660
+ if (super(), j.isMatrix(t))
2661
+ return t.clone();
2662
+ if (Number.isInteger(t) && t >= 0)
2663
+ if (this.data = [], Number.isInteger(n) && n >= 0)
2664
+ for (let e = 0; e < t; e++)
2665
+ this.data.push(new Float64Array(n));
2666
+ else
2667
+ throw new TypeError("nColumns must be a positive integer");
2668
+ else if (z(t)) {
2669
+ const e = t;
2670
+ if (t = e.length, n = t ? e[0].length : 0, typeof n != "number")
2671
+ throw new TypeError(
2672
+ "Data must be a 2D array with at least one element"
2673
+ );
2674
+ this.data = [];
2675
+ for (let s = 0; s < t; s++) {
2676
+ if (e[s].length !== n)
2677
+ throw new RangeError("Inconsistent array dimensions");
2678
+ if (!_n(e[s]))
2679
+ throw new TypeError("Input data contains non-numeric values");
2680
+ this.data.push(Float64Array.from(e[s]));
2681
+ }
2682
+ } else
2683
+ throw new TypeError(
2684
+ "First argument must be a positive number or an array"
2685
+ );
2686
+ this.rows = t, this.columns = n;
2687
+ }
2688
+ set(t, n, e) {
2689
+ return this.data[t][n] = e, this;
2690
+ }
2691
+ get(t, n) {
2692
+ return this.data[t][n];
2693
+ }
2694
+ removeRow(t) {
2695
+ return Y(this, t), this.data.splice(t, 1), this.rows -= 1, this;
2696
+ }
2697
+ addRow(t, n) {
2698
+ return n === void 0 && (n = t, t = this.rows), Y(this, t, !0), n = Float64Array.from(lt(this, n)), this.data.splice(t, 0, n), this.rows += 1, this;
2699
+ }
2700
+ removeColumn(t) {
2701
+ X(this, t);
2702
+ for (let n = 0; n < this.rows; n++) {
2703
+ const e = new Float64Array(this.columns - 1);
2704
+ for (let s = 0; s < t; s++)
2705
+ e[s] = this.data[n][s];
2706
+ for (let s = t + 1; s < this.columns; s++)
2707
+ e[s - 1] = this.data[n][s];
2708
+ this.data[n] = e;
2709
+ }
2710
+ return this.columns -= 1, this;
2711
+ }
2712
+ addColumn(t, n) {
2713
+ typeof n > "u" && (n = t, t = this.columns), X(this, t, !0), n = ut(this, n);
2714
+ for (let e = 0; e < this.rows; e++) {
2715
+ const s = new Float64Array(this.columns + 1);
2716
+ let r = 0;
2717
+ for (; r < t; r++)
2718
+ s[r] = this.data[e][r];
2719
+ for (s[r++] = n[e]; r < this.columns + 1; r++)
2720
+ s[r] = this.data[e][r - 1];
2721
+ this.data[e] = s;
2722
+ }
2723
+ return this.columns += 1, this;
2724
+ }
2725
+ }
2726
+ un(v, j);
2727
+ class Fn extends v {
2728
+ constructor(t) {
2729
+ super(), this.data = t, this.rows = t.length, this.columns = t[0].length;
2730
+ }
2731
+ set(t, n, e) {
2732
+ return this.data[t][n] = e, this;
2733
+ }
2734
+ get(t, n) {
2735
+ return this.data[t][n];
2736
+ }
2737
+ }
2738
+ function te(i, t) {
2739
+ let n = 0;
2740
+ return Math.abs(i) > Math.abs(t) ? (n = t / i, Math.abs(i) * Math.sqrt(1 + n * n)) : t !== 0 ? (n = i / t, Math.abs(t) * Math.sqrt(1 + n * n)) : 0;
2741
+ }
2742
+ class Tn {
2743
+ constructor(t, n = {}) {
2744
+ const { assumeSymmetric: e = !1 } = n;
2745
+ if (t = Fn.checkMatrix(t), !t.isSquare())
2746
+ throw new Error("Matrix is not a square matrix");
2747
+ if (t.isEmpty())
2748
+ throw new Error("Matrix must be non-empty");
2749
+ let s = t.columns, r = new j(s, s), o = new Float64Array(s), h = new Float64Array(s), u = t, l, c, a = !1;
2750
+ if (e ? a = !0 : a = t.isSymmetric(), a) {
2751
+ for (l = 0; l < s; l++)
2752
+ for (c = 0; c < s; c++)
2753
+ r.set(l, c, u.get(l, c));
2754
+ Cn(s, h, o, r), $n(s, h, o, r);
2755
+ } else {
2756
+ let g = new j(s, s), w = new Float64Array(s);
2757
+ for (c = 0; c < s; c++)
2758
+ for (l = 0; l < s; l++)
2759
+ g.set(l, c, u.get(l, c));
2760
+ qn(s, g, w, r), Bn(s, h, o, r, g);
2761
+ }
2762
+ this.n = s, this.e = h, this.d = o, this.V = r;
2763
+ }
2764
+ get realEigenvalues() {
2765
+ return Array.from(this.d);
2766
+ }
2767
+ get imaginaryEigenvalues() {
2768
+ return Array.from(this.e);
2769
+ }
2770
+ get eigenvectorMatrix() {
2771
+ return this.V;
2772
+ }
2773
+ get diagonalMatrix() {
2774
+ let t = this.n, n = this.e, e = this.d, s = new j(t, t), r, o;
2775
+ for (r = 0; r < t; r++) {
2776
+ for (o = 0; o < t; o++)
2777
+ s.set(r, o, 0);
2778
+ s.set(r, r, e[r]), n[r] > 0 ? s.set(r, r + 1, n[r]) : n[r] < 0 && s.set(r, r - 1, n[r]);
2779
+ }
2780
+ return s;
2781
+ }
2782
+ }
2783
+ function Cn(i, t, n, e) {
2784
+ let s, r, o, h, u, l, c, a;
2785
+ for (u = 0; u < i; u++)
2786
+ n[u] = e.get(i - 1, u);
2787
+ for (h = i - 1; h > 0; h--) {
2788
+ for (a = 0, o = 0, l = 0; l < h; l++)
2789
+ a = a + Math.abs(n[l]);
2790
+ if (a === 0)
2791
+ for (t[h] = n[h - 1], u = 0; u < h; u++)
2792
+ n[u] = e.get(h - 1, u), e.set(h, u, 0), e.set(u, h, 0);
2793
+ else {
2794
+ for (l = 0; l < h; l++)
2795
+ n[l] /= a, o += n[l] * n[l];
2796
+ for (s = n[h - 1], r = Math.sqrt(o), s > 0 && (r = -r), t[h] = a * r, o = o - s * r, n[h - 1] = s - r, u = 0; u < h; u++)
2797
+ t[u] = 0;
2798
+ for (u = 0; u < h; u++) {
2799
+ for (s = n[u], e.set(u, h, s), r = t[u] + e.get(u, u) * s, l = u + 1; l <= h - 1; l++)
2800
+ r += e.get(l, u) * n[l], t[l] += e.get(l, u) * s;
2801
+ t[u] = r;
2802
+ }
2803
+ for (s = 0, u = 0; u < h; u++)
2804
+ t[u] /= o, s += t[u] * n[u];
2805
+ for (c = s / (o + o), u = 0; u < h; u++)
2806
+ t[u] -= c * n[u];
2807
+ for (u = 0; u < h; u++) {
2808
+ for (s = n[u], r = t[u], l = u; l <= h - 1; l++)
2809
+ e.set(l, u, e.get(l, u) - (s * t[l] + r * n[l]));
2810
+ n[u] = e.get(h - 1, u), e.set(h, u, 0);
2811
+ }
2812
+ }
2813
+ n[h] = o;
2814
+ }
2815
+ for (h = 0; h < i - 1; h++) {
2816
+ if (e.set(i - 1, h, e.get(h, h)), e.set(h, h, 1), o = n[h + 1], o !== 0) {
2817
+ for (l = 0; l <= h; l++)
2818
+ n[l] = e.get(l, h + 1) / o;
2819
+ for (u = 0; u <= h; u++) {
2820
+ for (r = 0, l = 0; l <= h; l++)
2821
+ r += e.get(l, h + 1) * e.get(l, u);
2822
+ for (l = 0; l <= h; l++)
2823
+ e.set(l, u, e.get(l, u) - r * n[l]);
2824
+ }
2825
+ }
2826
+ for (l = 0; l <= h; l++)
2827
+ e.set(l, h + 1, 0);
2828
+ }
2829
+ for (u = 0; u < i; u++)
2830
+ n[u] = e.get(i - 1, u), e.set(i - 1, u, 0);
2831
+ e.set(i - 1, i - 1, 1), t[0] = 0;
2832
+ }
2833
+ function $n(i, t, n, e) {
2834
+ let s, r, o, h, u, l, c, a, g, w, m, d, P, f, p, y;
2835
+ for (o = 1; o < i; o++)
2836
+ t[o - 1] = t[o];
2837
+ t[i - 1] = 0;
2838
+ let M = 0, b = 0, x = Number.EPSILON;
2839
+ for (l = 0; l < i; l++) {
2840
+ for (b = Math.max(b, Math.abs(n[l]) + Math.abs(t[l])), c = l; c < i && !(Math.abs(t[c]) <= x * b); )
2841
+ c++;
2842
+ if (c > l)
2843
+ do {
2844
+ for (s = n[l], a = (n[l + 1] - s) / (2 * t[l]), g = te(a, 1), a < 0 && (g = -g), n[l] = t[l] / (a + g), n[l + 1] = t[l] * (a + g), w = n[l + 1], r = s - n[l], o = l + 2; o < i; o++)
2845
+ n[o] -= r;
2846
+ for (M = M + r, a = n[c], m = 1, d = m, P = m, f = t[l + 1], p = 0, y = 0, o = c - 1; o >= l; o--)
2847
+ for (P = d, d = m, y = p, s = m * t[o], r = m * a, g = te(a, t[o]), t[o + 1] = p * g, p = t[o] / g, m = a / g, a = m * n[o] - p * s, n[o + 1] = r + p * (m * s + p * n[o]), u = 0; u < i; u++)
2848
+ r = e.get(u, o + 1), e.set(u, o + 1, p * e.get(u, o) + m * r), e.set(u, o, m * e.get(u, o) - p * r);
2849
+ a = -p * y * P * f * t[l] / w, t[l] = p * a, n[l] = m * a;
2850
+ } while (Math.abs(t[l]) > x * b);
2851
+ n[l] = n[l] + M, t[l] = 0;
2852
+ }
2853
+ for (o = 0; o < i - 1; o++) {
2854
+ for (u = o, a = n[o], h = o + 1; h < i; h++)
2855
+ n[h] < a && (u = h, a = n[h]);
2856
+ if (u !== o)
2857
+ for (n[u] = n[o], n[o] = a, h = 0; h < i; h++)
2858
+ a = e.get(h, o), e.set(h, o, e.get(h, u)), e.set(h, u, a);
2859
+ }
2860
+ }
2861
+ function qn(i, t, n, e) {
2862
+ let s = 0, r = i - 1, o, h, u, l, c, a, g;
2863
+ for (a = s + 1; a <= r - 1; a++) {
2864
+ for (g = 0, l = a; l <= r; l++)
2865
+ g = g + Math.abs(t.get(l, a - 1));
2866
+ if (g !== 0) {
2867
+ for (u = 0, l = r; l >= a; l--)
2868
+ n[l] = t.get(l, a - 1) / g, u += n[l] * n[l];
2869
+ for (h = Math.sqrt(u), n[a] > 0 && (h = -h), u = u - n[a] * h, n[a] = n[a] - h, c = a; c < i; c++) {
2870
+ for (o = 0, l = r; l >= a; l--)
2871
+ o += n[l] * t.get(l, c);
2872
+ for (o = o / u, l = a; l <= r; l++)
2873
+ t.set(l, c, t.get(l, c) - o * n[l]);
2874
+ }
2875
+ for (l = 0; l <= r; l++) {
2876
+ for (o = 0, c = r; c >= a; c--)
2877
+ o += n[c] * t.get(l, c);
2878
+ for (o = o / u, c = a; c <= r; c++)
2879
+ t.set(l, c, t.get(l, c) - o * n[c]);
2880
+ }
2881
+ n[a] = g * n[a], t.set(a, a - 1, g * h);
2882
+ }
2883
+ }
2884
+ for (l = 0; l < i; l++)
2885
+ for (c = 0; c < i; c++)
2886
+ e.set(l, c, l === c ? 1 : 0);
2887
+ for (a = r - 1; a >= s + 1; a--)
2888
+ if (t.get(a, a - 1) !== 0) {
2889
+ for (l = a + 1; l <= r; l++)
2890
+ n[l] = t.get(l, a - 1);
2891
+ for (c = a; c <= r; c++) {
2892
+ for (h = 0, l = a; l <= r; l++)
2893
+ h += n[l] * e.get(l, c);
2894
+ for (h = h / n[a] / t.get(a, a - 1), l = a; l <= r; l++)
2895
+ e.set(l, c, e.get(l, c) + h * n[l]);
2896
+ }
2897
+ }
2898
+ }
2899
+ function Bn(i, t, n, e, s) {
2900
+ let r = i - 1, o = 0, h = i - 1, u = Number.EPSILON, l = 0, c = 0, a = 0, g = 0, w = 0, m = 0, d = 0, P = 0, f, p, y, M, b, x, k, S, _, F, B, K, Q, Z, $;
2901
+ for (f = 0; f < i; f++)
2902
+ for ((f < o || f > h) && (n[f] = s.get(f, f), t[f] = 0), p = Math.max(f - 1, 0); p < i; p++)
2903
+ c = c + Math.abs(s.get(f, p));
2904
+ for (; r >= o; ) {
2905
+ for (M = r; M > o && (m = Math.abs(s.get(M - 1, M - 1)) + Math.abs(s.get(M, M)), m === 0 && (m = c), !(Math.abs(s.get(M, M - 1)) < u * m)); )
2906
+ M--;
2907
+ if (M === r)
2908
+ s.set(r, r, s.get(r, r) + l), n[r] = s.get(r, r), t[r] = 0, r--, P = 0;
2909
+ else if (M === r - 1) {
2910
+ if (k = s.get(r, r - 1) * s.get(r - 1, r), a = (s.get(r - 1, r - 1) - s.get(r, r)) / 2, g = a * a + k, d = Math.sqrt(Math.abs(g)), s.set(r, r, s.get(r, r) + l), s.set(r - 1, r - 1, s.get(r - 1, r - 1) + l), S = s.get(r, r), g >= 0) {
2911
+ for (d = a >= 0 ? a + d : a - d, n[r - 1] = S + d, n[r] = n[r - 1], d !== 0 && (n[r] = S - k / d), t[r - 1] = 0, t[r] = 0, S = s.get(r, r - 1), m = Math.abs(S) + Math.abs(d), a = S / m, g = d / m, w = Math.sqrt(a * a + g * g), a = a / w, g = g / w, p = r - 1; p < i; p++)
2912
+ d = s.get(r - 1, p), s.set(r - 1, p, g * d + a * s.get(r, p)), s.set(r, p, g * s.get(r, p) - a * d);
2913
+ for (f = 0; f <= r; f++)
2914
+ d = s.get(f, r - 1), s.set(f, r - 1, g * d + a * s.get(f, r)), s.set(f, r, g * s.get(f, r) - a * d);
2915
+ for (f = o; f <= h; f++)
2916
+ d = e.get(f, r - 1), e.set(f, r - 1, g * d + a * e.get(f, r)), e.set(f, r, g * e.get(f, r) - a * d);
2917
+ } else
2918
+ n[r - 1] = S + a, n[r] = S + a, t[r - 1] = d, t[r] = -d;
2919
+ r = r - 2, P = 0;
2920
+ } else {
2921
+ if (S = s.get(r, r), _ = 0, k = 0, M < r && (_ = s.get(r - 1, r - 1), k = s.get(r, r - 1) * s.get(r - 1, r)), P === 10) {
2922
+ for (l += S, f = o; f <= r; f++)
2923
+ s.set(f, f, s.get(f, f) - S);
2924
+ m = Math.abs(s.get(r, r - 1)) + Math.abs(s.get(r - 1, r - 2)), S = _ = 0.75 * m, k = -0.4375 * m * m;
2925
+ }
2926
+ if (P === 30 && (m = (_ - S) / 2, m = m * m + k, m > 0)) {
2927
+ for (m = Math.sqrt(m), _ < S && (m = -m), m = S - k / ((_ - S) / 2 + m), f = o; f <= r; f++)
2928
+ s.set(f, f, s.get(f, f) - m);
2929
+ l += m, S = _ = k = 0.964;
2930
+ }
2931
+ for (P = P + 1, b = r - 2; b >= M && (d = s.get(b, b), w = S - d, m = _ - d, a = (w * m - k) / s.get(b + 1, b) + s.get(b, b + 1), g = s.get(b + 1, b + 1) - d - w - m, w = s.get(b + 2, b + 1), m = Math.abs(a) + Math.abs(g) + Math.abs(w), a = a / m, g = g / m, w = w / m, !(b === M || Math.abs(s.get(b, b - 1)) * (Math.abs(g) + Math.abs(w)) < u * (Math.abs(a) * (Math.abs(s.get(b - 1, b - 1)) + Math.abs(d) + Math.abs(s.get(b + 1, b + 1)))))); )
2932
+ b--;
2933
+ for (f = b + 2; f <= r; f++)
2934
+ s.set(f, f - 2, 0), f > b + 2 && s.set(f, f - 3, 0);
2935
+ for (y = b; y <= r - 1 && (Z = y !== r - 1, y !== b && (a = s.get(y, y - 1), g = s.get(y + 1, y - 1), w = Z ? s.get(y + 2, y - 1) : 0, S = Math.abs(a) + Math.abs(g) + Math.abs(w), S !== 0 && (a = a / S, g = g / S, w = w / S)), S !== 0); y++)
2936
+ if (m = Math.sqrt(a * a + g * g + w * w), a < 0 && (m = -m), m !== 0) {
2937
+ for (y !== b ? s.set(y, y - 1, -m * S) : M !== b && s.set(y, y - 1, -s.get(y, y - 1)), a = a + m, S = a / m, _ = g / m, d = w / m, g = g / a, w = w / a, p = y; p < i; p++)
2938
+ a = s.get(y, p) + g * s.get(y + 1, p), Z && (a = a + w * s.get(y + 2, p), s.set(y + 2, p, s.get(y + 2, p) - a * d)), s.set(y, p, s.get(y, p) - a * S), s.set(y + 1, p, s.get(y + 1, p) - a * _);
2939
+ for (f = 0; f <= Math.min(r, y + 3); f++)
2940
+ a = S * s.get(f, y) + _ * s.get(f, y + 1), Z && (a = a + d * s.get(f, y + 2), s.set(f, y + 2, s.get(f, y + 2) - a * w)), s.set(f, y, s.get(f, y) - a), s.set(f, y + 1, s.get(f, y + 1) - a * g);
2941
+ for (f = o; f <= h; f++)
2942
+ a = S * e.get(f, y) + _ * e.get(f, y + 1), Z && (a = a + d * e.get(f, y + 2), e.set(f, y + 2, e.get(f, y + 2) - a * w)), e.set(f, y, e.get(f, y) - a), e.set(f, y + 1, e.get(f, y + 1) - a * g);
2943
+ }
2944
+ }
2945
+ }
2946
+ if (c !== 0) {
2947
+ for (r = i - 1; r >= 0; r--)
2948
+ if (a = n[r], g = t[r], g === 0)
2949
+ for (M = r, s.set(r, r, 1), f = r - 1; f >= 0; f--) {
2950
+ for (k = s.get(f, f) - a, w = 0, p = M; p <= r; p++)
2951
+ w = w + s.get(f, p) * s.get(p, r);
2952
+ if (t[f] < 0)
2953
+ d = k, m = w;
2954
+ else if (M = f, t[f] === 0 ? s.set(f, r, k !== 0 ? -w / k : -w / (u * c)) : (S = s.get(f, f + 1), _ = s.get(f + 1, f), g = (n[f] - a) * (n[f] - a) + t[f] * t[f], x = (S * m - d * w) / g, s.set(f, r, x), s.set(
2955
+ f + 1,
2956
+ r,
2957
+ Math.abs(S) > Math.abs(d) ? (-w - k * x) / S : (-m - _ * x) / d
2958
+ )), x = Math.abs(s.get(f, r)), u * x * x > 1)
2959
+ for (p = f; p <= r; p++)
2960
+ s.set(p, r, s.get(p, r) / x);
2961
+ }
2962
+ else if (g < 0)
2963
+ for (M = r - 1, Math.abs(s.get(r, r - 1)) > Math.abs(s.get(r - 1, r)) ? (s.set(r - 1, r - 1, g / s.get(r, r - 1)), s.set(r - 1, r, -(s.get(r, r) - a) / s.get(r, r - 1))) : ($ = St(0, -s.get(r - 1, r), s.get(r - 1, r - 1) - a, g), s.set(r - 1, r - 1, $[0]), s.set(r - 1, r, $[1])), s.set(r, r - 1, 0), s.set(r, r, 1), f = r - 2; f >= 0; f--) {
2964
+ for (F = 0, B = 0, p = M; p <= r; p++)
2965
+ F = F + s.get(f, p) * s.get(p, r - 1), B = B + s.get(f, p) * s.get(p, r);
2966
+ if (k = s.get(f, f) - a, t[f] < 0)
2967
+ d = k, w = F, m = B;
2968
+ else if (M = f, t[f] === 0 ? ($ = St(-F, -B, k, g), s.set(f, r - 1, $[0]), s.set(f, r, $[1])) : (S = s.get(f, f + 1), _ = s.get(f + 1, f), K = (n[f] - a) * (n[f] - a) + t[f] * t[f] - g * g, Q = (n[f] - a) * 2 * g, K === 0 && Q === 0 && (K = u * c * (Math.abs(k) + Math.abs(g) + Math.abs(S) + Math.abs(_) + Math.abs(d))), $ = St(
2969
+ S * w - d * F + g * B,
2970
+ S * m - d * B - g * F,
2971
+ K,
2972
+ Q
2973
+ ), s.set(f, r - 1, $[0]), s.set(f, r, $[1]), Math.abs(S) > Math.abs(d) + Math.abs(g) ? (s.set(
2974
+ f + 1,
2975
+ r - 1,
2976
+ (-F - k * s.get(f, r - 1) + g * s.get(f, r)) / S
2977
+ ), s.set(
2978
+ f + 1,
2979
+ r,
2980
+ (-B - k * s.get(f, r) - g * s.get(f, r - 1)) / S
2981
+ )) : ($ = St(
2982
+ -w - _ * s.get(f, r - 1),
2983
+ -m - _ * s.get(f, r),
2984
+ d,
2985
+ g
2986
+ ), s.set(f + 1, r - 1, $[0]), s.set(f + 1, r, $[1]))), x = Math.max(Math.abs(s.get(f, r - 1)), Math.abs(s.get(f, r))), u * x * x > 1)
2987
+ for (p = f; p <= r; p++)
2988
+ s.set(p, r - 1, s.get(p, r - 1) / x), s.set(p, r, s.get(p, r) / x);
2989
+ }
2990
+ for (f = 0; f < i; f++)
2991
+ if (f < o || f > h)
2992
+ for (p = f; p < i; p++)
2993
+ e.set(f, p, s.get(f, p));
2994
+ for (p = i - 1; p >= o; p--)
2995
+ for (f = o; f <= h; f++) {
2996
+ for (d = 0, y = o; y <= Math.min(p, h); y++)
2997
+ d = d + e.get(f, y) * s.get(y, p);
2998
+ e.set(f, p, d);
2999
+ }
3000
+ }
3001
+ }
3002
+ function St(i, t, n, e) {
3003
+ let s, r;
3004
+ return Math.abs(n) > Math.abs(e) ? (s = e / n, r = n + s * e, [(i + s * t) / r, (t - s * i) / r]) : (s = n / e, r = e + s * n, [(s * i + t) / r, (s * t - i) / r]);
3005
+ }
3006
+ function de(i, t = 1e-9) {
3007
+ if (i[i.length - 1] == 0)
3008
+ return de(i.slice(0, -1), t);
3009
+ const n = new j([
3010
+ i.slice(0, -1).reverse().map((s) => -s / i[i.length - 1]),
3011
+ ...Array.from({ length: i.length - 2 }, (s, r) => {
3012
+ const o = new Array(i.length - 1).fill(0);
3013
+ return o[r] = 1, o;
3014
+ })
3015
+ ]), e = new Tn(n);
3016
+ return e.realEigenvalues.filter(
3017
+ (s, r) => Math.abs(e.imaginaryEigenvalues[r]) < t
3018
+ );
3019
+ }
3020
+ function ye(i, t) {
3021
+ const n = Math.max(i.precision, t.precision), e = i.coefficients, s = e.x2, r = e.xy, o = e.y2, h = e.x, u = e.y, l = e.c, c = t.coefficients, a = c.x2, g = c.xy, w = c.y2, m = c.x, d = c.y, P = c.c, f = {
3022
+ z0: l * s * m * m + s * s * P * P - h * s * m * P + a * a * l * l - 2 * s * P * a * l - h * m * a * l + a * h * h * P,
3023
+ z1: d * h * h * a - P * m * s * r - 2 * s * P * a * u - l * a * g * h + 2 * m * g * s * l + 2 * d * P * s * s + m * m * s * u - d * m * s * h - 2 * s * d * a * l - l * a * m * r + 2 * l * u * a * a - P * g * s * h - u * a * m * h + 2 * P * r * a * h,
3024
+ z2: d * d * s * s + 2 * w * P * s * s - u * a * m * r + P * a * r * r - u * a * g * h - P * g * s * r - 2 * s * d * a * u + 2 * m * g * s * u - w * m * s * h - 2 * s * w * a * l + g * g * s * l + 2 * d * r * a * h + u * u * a * a - o * a * m * h - d * g * s * h + 2 * l * o * a * a - l * a * g * r + w * h * h * a + m * m * s * o - d * m * s * r - 2 * s * P * a * o,
3025
+ z3: -2 * s * a * o * d + d * a * r * r + 2 * w * r * a * h - o * a * g * h + g * g * s * u - d * g * s * r - 2 * s * w * a * u - u * a * g * r - w * g * s * h + 2 * d * w * s * s + 2 * u * o * a * a - o * a * m * r + 2 * m * g * s * o - w * m * s * r,
3026
+ z4: s * s * w * w - 2 * s * w * a * o + a * a * o * o - r * s * g * w - r * g * a * o + r * r * a * w + o * s * g * g
3027
+ }, y = de(
3028
+ [f.z0, f.z1, f.z2, f.z3, f.z4],
3029
+ n
3030
+ ).flatMap((M) => {
3031
+ const b = s * g * M + s * m - a * r * M - a * h;
3032
+ if (b)
3033
+ return [[-(s * P + s * w * M * M - a * o * M * M + s * d * M - a * u * M - a * l) / b, M]];
3034
+ const x = r * M + h, k = -x / (2 * s), S = o * M * M + u * M + l, _ = x * x / (4 * s * s) - S / s;
3035
+ if (Math.abs(_) < n)
3036
+ return [[k, M]];
3037
+ if (_ > 0) {
3038
+ const F = Math.sqrt(_);
3039
+ return [[k + F, M], [k - F, M]];
3040
+ }
3041
+ return [];
3042
+ });
3043
+ return ct(y, n);
3044
+ }
3045
+ function ee(i, t) {
3046
+ return ye(i, t).filter((e) => i.isOnSegment(e) && t.isOnSegment(e));
3047
+ }
3048
+ const On = (i) => {
3049
+ const {
3050
+ firstPoint: t,
3051
+ lastPoint: n,
3052
+ center: e,
3053
+ majorRadius: s,
3054
+ minorRadius: r,
3055
+ tiltAngle: o,
3056
+ clockwise: h
3057
+ } = i;
3058
+ return new C(
3059
+ n,
3060
+ t,
3061
+ e,
3062
+ s,
3063
+ r,
3064
+ o,
3065
+ h,
3066
+ {
3067
+ ignoreChecks: !0,
3068
+ angleUnits: "rad"
3069
+ }
3070
+ );
3071
+ }, An = (i, t) => {
3072
+ if (i.isSame(t))
3073
+ return [i];
3074
+ const n = (s, r) => new C(
3075
+ s,
3076
+ r,
3077
+ i.center,
3078
+ i.majorRadius,
3079
+ i.minorRadius,
3080
+ i.tiltAngle,
3081
+ i.clockwise,
3082
+ { ignoreChecks: !0, angleUnits: "rad" }
3083
+ ), e = ct(
3084
+ [
3085
+ t.isOnSegment(i.firstPoint) ? i.firstPoint : null,
3086
+ t.isOnSegment(i.lastPoint) ? i.lastPoint : null,
3087
+ i.isOnSegment(t.firstPoint) ? t.firstPoint : null,
3088
+ i.isOnSegment(t.lastPoint) ? t.lastPoint : null
3089
+ ].filter((s) => s !== null)
3090
+ // We sort by the param value of the first arc. This means that the points
3091
+ // will be sorted with the same orientation than arc1
3092
+ ).sort((s, r) => i.pointToParam(s) - i.pointToParam(r));
3093
+ if (e.length === 0)
3094
+ return [];
3095
+ if (e.length === 1)
3096
+ return [];
3097
+ if (e.length === 2)
3098
+ return i.isSame(On(t)) ? [] : [n(e[0], e[1])];
3099
+ if (e.length === 3) {
3100
+ const s = E(e[0], t.lastPoint) || E(e[0], t.firstPoint) ? 1 : 0;
3101
+ return [n(e[0 + s], e[1 + s])];
3102
+ } else if (e.length === 4)
3103
+ return [n(e[0], e[1]), n(e[2], e[3])];
3104
+ throw new Error("Bug in the ellipse arc ellipse arc overlap algorithm");
3105
+ };
3106
+ function Nn(i, t, n = !1) {
3107
+ const e = Math.max(i.precision, t.precision);
3108
+ return E(i.center, t.center) && Math.abs(i.majorRadius - t.majorRadius) < e && Math.abs(i.minorRadius - t.minorRadius) < e && (Math.abs(i.tiltAngle - t.tiltAngle) < e || Math.abs(Math.abs(i.tiltAngle - t.tiltAngle) - Math.PI) < e) ? n ? An(i, t) : [] : ye(i, t).filter((o) => i.isOnSegment(o) && t.isOnSegment(o));
3109
+ }
3110
+ function gs(i, t, n) {
3111
+ if (i instanceof R && t instanceof R) {
3112
+ const e = ge(
3113
+ i,
3114
+ t,
3115
+ !1,
3116
+ n
3117
+ );
3118
+ return e === null ? [] : [e];
3119
+ }
3120
+ if (i instanceof R && t instanceof I)
3121
+ return kt(i, t, n);
3122
+ if (i instanceof I && t instanceof R)
3123
+ return kt(t, i, n);
3124
+ if (i instanceof I && t instanceof I)
3125
+ return me(i, t, !1, n);
3126
+ throw new Error("Not implemented");
3127
+ }
3128
+ function It(i, t, n) {
3129
+ if (i instanceof R && t instanceof R) {
3130
+ const e = ge(
3131
+ i,
3132
+ t,
3133
+ !0,
3134
+ n
3135
+ );
3136
+ return e === null ? { intersections: [], overlaps: [], count: 0 } : e instanceof R ? { intersections: [], overlaps: [e], count: 1 } : { intersections: [e], overlaps: [], count: 1 };
3137
+ }
3138
+ if (!i.boundingBox.overlaps(t.boundingBox))
3139
+ return { intersections: [], overlaps: [], count: 0 };
3140
+ if (i instanceof R && t instanceof I) {
3141
+ const e = kt(i, t, n);
3142
+ return { intersections: e, overlaps: [], count: e.length };
3143
+ }
3144
+ if (i instanceof I && t instanceof R) {
3145
+ const e = kt(t, i, n);
3146
+ return { intersections: e, overlaps: [], count: e.length };
3147
+ }
3148
+ if (i instanceof I && t instanceof I) {
3149
+ const e = me(
3150
+ i,
3151
+ t,
3152
+ !0,
3153
+ n
3154
+ );
3155
+ return e.length ? e[0] instanceof I ? {
3156
+ intersections: [],
3157
+ overlaps: e,
3158
+ count: e.length
3159
+ } : {
3160
+ intersections: e,
3161
+ overlaps: [],
3162
+ count: e.length
3163
+ } : { intersections: [], overlaps: [], count: 0 };
3164
+ }
3165
+ if (i instanceof R && t instanceof C) {
3166
+ const e = qt(
3167
+ i,
3168
+ t,
3169
+ n
3170
+ );
3171
+ return { intersections: e, overlaps: [], count: e.length };
3172
+ }
3173
+ if (t instanceof R && i instanceof C) {
3174
+ const e = qt(
3175
+ t,
3176
+ i,
3177
+ n
3178
+ );
3179
+ return { intersections: e, overlaps: [], count: e.length };
3180
+ }
3181
+ if (i instanceof I && t instanceof C) {
3182
+ const e = ee(i, t);
3183
+ return { intersections: e, overlaps: [], count: e.length };
3184
+ }
3185
+ if (t instanceof I && i instanceof C) {
3186
+ const e = ee(t, i);
3187
+ return { intersections: e, overlaps: [], count: e.length };
3188
+ }
3189
+ if (i instanceof C && t instanceof C) {
3190
+ const e = Nn(
3191
+ i,
3192
+ t,
3193
+ !0
3194
+ );
3195
+ return e.length ? e[0] instanceof C ? {
3196
+ intersections: [],
3197
+ overlaps: e,
3198
+ count: e.length
3199
+ } : {
3200
+ intersections: e,
3201
+ overlaps: [],
3202
+ count: e.length
3203
+ } : { intersections: [], overlaps: [], count: 0 };
3204
+ }
3205
+ throw new Error("Not implemented");
3206
+ }
3207
+ function Pe(i) {
3208
+ const t = [];
3209
+ for (let n = 0; n < i; n++)
3210
+ for (let e = 0; e <= n; e++)
3211
+ t.push([n, e]);
3212
+ return t;
3213
+ }
3214
+ function* Bt(i) {
3215
+ for (const [t, n] of Pe(i.length))
3216
+ t !== n && (yield [i[t], i[n]]);
3217
+ }
3218
+ class Me extends _t {
3219
+ constructor(t, { ignoreChecks: n = !1 } = {}) {
3220
+ super(), this._boundingBox = null, n || Ee(t), this.segments = t;
3221
+ }
3222
+ get repr() {
3223
+ return this.segments.map((t) => t.repr).join(`
3224
+ `) + `
3225
+ `;
3226
+ }
3227
+ get info() {
3228
+ return this.repr;
3229
+ }
3230
+ get firstPoint() {
3231
+ return this.segments[0].firstPoint;
3232
+ }
3233
+ get lastPoint() {
3234
+ return this.segments[this.segments.length - 1].lastPoint;
3235
+ }
3236
+ get segmentsCount() {
3237
+ return this.segments.length;
3238
+ }
3239
+ onStroke(t) {
3240
+ return this.segments.some((n) => n.isOnSegment(t));
3241
+ }
3242
+ intersects(t) {
3243
+ return this.boundingBox.overlaps(t.boundingBox) ? this.segments.some(
3244
+ (n) => t.segments.some(
3245
+ (e) => It(n, e).count > 0
3246
+ )
3247
+ ) : !1;
3248
+ }
3249
+ overlappingSegments(t) {
3250
+ return this.segments.flatMap((n) => t.segments.flatMap((e) => n.boundingBox.overlaps(e.boundingBox) ? It(n, e).overlaps : []));
3251
+ }
3252
+ get boundingBox() {
3253
+ if (this._boundingBox === null) {
3254
+ let t = this.segments[0].boundingBox;
3255
+ this.segments.slice(1).forEach((n) => {
3256
+ t = t.merge(n.boundingBox);
3257
+ }), this._boundingBox = t;
3258
+ }
3259
+ return this._boundingBox;
3260
+ }
3261
+ [Symbol.for("nodejs.util.inspect.custom")]() {
3262
+ return this.repr;
3263
+ }
3264
+ }
3265
+ function Ln(i, t = "Stroke") {
3266
+ Pe(i.length).forEach(
3267
+ ([n, e]) => {
3268
+ if (n === e)
3269
+ return;
3270
+ const s = i[n], r = i[e], o = It(s, r), h = Math.max(s.precision, r.precision);
3271
+ if (o.count !== 0) {
3272
+ if (o.count === 1 && !o.overlaps.length) {
3273
+ const u = n - e, l = o.intersections[0];
3274
+ if (u === 1 && E(s.firstPoint, l, h) || u === -1 && E(s.lastPoint, l, h) || u === i.length - 1 && E(s.lastPoint, l, h) && E(r.firstPoint, l, h) || -u === i.length - 1 && E(s.firstPoint, l, h) && E(r.lastPoint, l, h))
3275
+ return;
3276
+ }
3277
+ if (!(o.count === 2 && i.length === 2 && (E(
3278
+ s.firstPoint,
3279
+ o.intersections[0],
3280
+ h
3281
+ ) && E(
3282
+ s.lastPoint,
3283
+ o.intersections[1],
3284
+ h
3285
+ ) || E(
3286
+ s.firstPoint,
3287
+ o.intersections[1],
3288
+ h
3289
+ ) && E(
3290
+ s.lastPoint,
3291
+ o.intersections[0],
3292
+ h
3293
+ ))))
3294
+ throw new Error(
3295
+ `${t} segments must not intersect, but segments ${s.info} and ${r.info} do at ${JSON.stringify(
3296
+ o.intersections
3297
+ )}`
3298
+ );
3299
+ }
3300
+ }
3301
+ );
3302
+ }
3303
+ function Ee(i, t = "Stroke") {
3304
+ if (i.length === 0)
3305
+ throw new Error(`${t} must have at least one segment`);
3306
+ nt([i.slice(0, -1), i.slice(1)]).forEach(
3307
+ ([n, e]) => {
3308
+ if (!E(n.lastPoint, e.firstPoint))
3309
+ throw new Error(
3310
+ `${t} segments must be connected, but ${n.info} and ${e.info} are not`
3311
+ );
3312
+ }
3313
+ ), Ln(i, t);
3314
+ }
3315
+ function ne(i, t) {
3316
+ return !!(i instanceof R && t instanceof R && Vt(i.V, t.V) || i instanceof I && t instanceof I && E(i.center, t.center) && i.radius - t.radius < i.precision);
3317
+ }
3318
+ function se(i, t) {
3319
+ if (i instanceof R && t instanceof R)
3320
+ return new R(i.firstPoint, t.lastPoint);
3321
+ if (i instanceof I && t instanceof I)
3322
+ return new I(
3323
+ i.firstPoint,
3324
+ t.lastPoint,
3325
+ i.center,
3326
+ i.clockwise
3327
+ );
3328
+ throw new Error("Not implemented");
3329
+ }
3330
+ function Se(i) {
3331
+ let t = !1;
3332
+ const n = [];
3333
+ for (const e of i.segments) {
3334
+ if (n.length === 0) {
3335
+ n.push(e);
3336
+ continue;
3337
+ }
3338
+ const s = n[n.length - 1];
3339
+ ne(s, e) ? (t = !0, n.pop(), n.push(se(s, e))) : n.push(e);
3340
+ }
3341
+ if (E(i.firstPoint, i.lastPoint) && ne(
3342
+ n[0],
3343
+ n[n.length - 1]
3344
+ )) {
3345
+ t = !0;
3346
+ const e = n.pop();
3347
+ n[0] = se(e, n[0]);
3348
+ }
3349
+ return t ? n : null;
3350
+ }
3351
+ class G extends Me {
3352
+ constructor() {
3353
+ super(...arguments), this.strokeType = "STRAND";
3354
+ }
3355
+ reverse() {
3356
+ const t = this.segments.map((n) => n.reverse());
3357
+ return t.reverse(), new G(t, { ignoreChecks: !0 });
3358
+ }
3359
+ clone() {
3360
+ return new G(
3361
+ this.segments.map((t) => t.clone()),
3362
+ { ignoreChecks: !0 }
3363
+ );
3364
+ }
3365
+ extend(t) {
3366
+ if (!E(this.lastPoint, t.firstPoint))
3367
+ throw console.error(this.repr, t.repr), new Error("Cannot extend strand: connection point is not the same");
3368
+ return new G([...this.segments, ...t.segments]);
3369
+ }
3370
+ simplify() {
3371
+ const t = Se(this);
3372
+ return t ? new G(t, { ignoreChecks: !0 }) : this;
3373
+ }
3374
+ transform(t) {
3375
+ return new G(
3376
+ this.segments.map((n) => n.transform(t)),
3377
+ { ignoreChecks: !0 }
3378
+ );
3379
+ }
3380
+ }
3381
+ const Vn = (i, t) => {
3382
+ const n = Ft(t, {
3383
+ V: [1, 0],
3384
+ firstPoint: i,
3385
+ precision: t.precision
3386
+ });
3387
+ if (n === "parallel")
3388
+ return 0;
3389
+ const { intersectionParam1: e, intersectionParam2: s } = n;
3390
+ if (!t.isValidParameter(e) || s <= -t.precision)
3391
+ return 0;
3392
+ if (Math.abs(e) < t.precision || Math.abs(e - 1) < t.precision) {
3393
+ const [, r] = t.midPoint;
3394
+ return i[1] - r < 0 ? 1 : 0;
3395
+ }
3396
+ return 1;
3397
+ };
3398
+ class be {
3399
+ constructor(t) {
3400
+ this._count = 0, this.segment = t;
3401
+ }
3402
+ update(t, n = !1) {
3403
+ !n && !this.segment.isOnSegment(t) || (E(t, this.segment.firstPoint) ? this._count += this.segment.tangentAtFirstPoint[1] > 0 ? 1 : 0 : E(t, this.segment.lastPoint) ? this._count += this.segment.tangentAtLastPoint[1] > 0 ? 0 : 1 : this._count += 1);
3404
+ }
3405
+ get count() {
3406
+ return this._count;
3407
+ }
3408
+ }
3409
+ const zn = (i, t) => {
3410
+ const n = t.precision, e = Math.abs(i[1] - t.center[1]);
3411
+ if (e > t.radius + n)
3412
+ return 0;
3413
+ const s = mt(i, t.center), r = t.radius * t.radius, o = n * n;
3414
+ if (Math.abs(s - r) < o && t.isOnSegment(i))
3415
+ return 0;
3416
+ const h = s - r > o;
3417
+ if (h && t.center[0] < i[0])
3418
+ return 0;
3419
+ const u = Math.sqrt(
3420
+ t.radius * t.radius - e * e
3421
+ ), l = new be(t);
3422
+ return l.update([t.center[0] + u, i[1]]), h && l.update([t.center[0] - u, i[1]]), l.count;
3423
+ }, Dn = (i, t) => {
3424
+ const n = t.boundingBox.xMax + t.boundingBox.width / 2, e = new R(i, [n, i[1]]), s = new be(t);
3425
+ return qt(e, t).forEach((r) => {
3426
+ s.update(r, !0);
3427
+ }), s.count;
3428
+ };
3429
+ function Un(i, t) {
3430
+ if (t instanceof R)
3431
+ return Vn(i, t);
3432
+ if (t instanceof I)
3433
+ return zn(i, t);
3434
+ if (t instanceof C)
3435
+ return Dn(i, t);
3436
+ throw new Error("Not implemented");
3437
+ }
3438
+ class et extends Me {
3439
+ constructor(t, { ignoreChecks: n = !1 } = {}) {
3440
+ super(t, { ignoreChecks: !0 }), this.strokeType = "LOOP", this._clockwise = null, n || Yn(t);
3441
+ }
3442
+ get clockwise() {
3443
+ if (this._clockwise === null) {
3444
+ const t = this.segments.flatMap((e) => e instanceof R ? [e.firstPoint] : [e.firstPoint, e.paramPoint(0.5)]), n = t.map((e, s) => {
3445
+ const r = t[(s + 1) % t.length];
3446
+ return (r[0] - e[0]) * (r[1] + e[1]);
3447
+ }).reduce((e, s) => e + s, 0);
3448
+ this._clockwise = n > 0;
3449
+ }
3450
+ return this._clockwise;
3451
+ }
3452
+ clone() {
3453
+ return new et(
3454
+ this.segments.map((t) => t.clone()),
3455
+ { ignoreChecks: !0 }
3456
+ );
3457
+ }
3458
+ reverse() {
3459
+ const t = this.segments.map((n) => n.reverse());
3460
+ return t.reverse(), new et(t, { ignoreChecks: !0 });
3461
+ }
3462
+ transform(t) {
3463
+ return new et(
3464
+ this.segments.map((n) => n.transform(t)),
3465
+ { ignoreChecks: !0 }
3466
+ );
3467
+ }
3468
+ contains(t) {
3469
+ return this.onStroke(t) || !this.boundingBox.contains(t) ? !1 : this.segments.reduce((e, s) => e + Un(t, s), 0) % 2 === 1;
3470
+ }
3471
+ simplify() {
3472
+ const t = Se(this);
3473
+ return t ? new et(t, { ignoreChecks: !0 }) : this;
3474
+ }
3475
+ }
3476
+ function Yn(i) {
3477
+ if (Ee(i, "Loop"), !E(i[0].firstPoint, i[i.length - 1].lastPoint))
3478
+ throw new Error("Loop segment must be closed");
3479
+ }
3480
+ function je(i) {
3481
+ if (i instanceof R)
3482
+ return {
3483
+ type: i.segmentType,
3484
+ firstPoint: i.firstPoint,
3485
+ lastPoint: i.lastPoint
3486
+ };
3487
+ if (i instanceof I)
3488
+ return {
3489
+ type: i.segmentType,
3490
+ firstPoint: i.firstPoint,
3491
+ lastPoint: i.lastPoint,
3492
+ center: i.center,
3493
+ clockwise: i.clockwise
3494
+ };
3495
+ if (i instanceof C)
3496
+ return {
3497
+ type: i.segmentType,
3498
+ firstPoint: i.firstPoint,
3499
+ lastPoint: i.lastPoint,
3500
+ center: i.center,
3501
+ clockwise: i.clockwise,
3502
+ majorRadius: i.majorRadius,
3503
+ minorRadius: i.minorRadius,
3504
+ tiltAngle: i.tiltAngle
3505
+ };
3506
+ throw new Error("Unknown segment type");
3507
+ }
3508
+ function Ot(i) {
3509
+ return {
3510
+ type: "LOOP",
3511
+ segments: i.segments.map(je)
3512
+ };
3513
+ }
3514
+ function ve(i) {
3515
+ return {
3516
+ type: "FIGURE",
3517
+ contour: Ot(i.contour),
3518
+ holes: i.holes.map(Ot)
3519
+ };
3520
+ }
3521
+ function Xn(i) {
3522
+ return {
3523
+ type: "DIAGRAM",
3524
+ figures: i.figures.map(ve)
3525
+ };
3526
+ }
3527
+ function ie(i) {
3528
+ if (i instanceof tt)
3529
+ return Xn(i);
3530
+ if (i instanceof U)
3531
+ return ve(i);
3532
+ if (i instanceof et)
3533
+ return Ot(i);
3534
+ if (i instanceof I || i instanceof R)
3535
+ return je(i);
3536
+ throw new Error("Unknown shape type");
3537
+ }
3538
+ class Gn {
3539
+ constructor() {
3540
+ this.ids = [], this.values = [], this.length = 0;
3541
+ }
3542
+ clear() {
3543
+ this.length = 0;
3544
+ }
3545
+ push(t, n) {
3546
+ let e = this.length++;
3547
+ for (; e > 0; ) {
3548
+ const s = e - 1 >> 1, r = this.values[s];
3549
+ if (n >= r)
3550
+ break;
3551
+ this.ids[e] = this.ids[s], this.values[e] = r, e = s;
3552
+ }
3553
+ this.ids[e] = t, this.values[e] = n;
3554
+ }
3555
+ pop() {
3556
+ if (this.length === 0)
3557
+ return;
3558
+ const t = this.ids[0];
3559
+ if (this.length--, this.length > 0) {
3560
+ const n = this.ids[0] = this.ids[this.length], e = this.values[0] = this.values[this.length], s = this.length >> 1;
3561
+ let r = 0;
3562
+ for (; r < s; ) {
3563
+ let o = (r << 1) + 1;
3564
+ const h = o + 1;
3565
+ let u = this.ids[o], l = this.values[o];
3566
+ const c = this.values[h];
3567
+ if (h < this.length && c < l && (o = h, u = this.ids[h], l = c), l >= e)
3568
+ break;
3569
+ this.ids[r] = u, this.values[r] = l, r = o;
3570
+ }
3571
+ this.ids[r] = n, this.values[r] = e;
3572
+ }
3573
+ return t;
3574
+ }
3575
+ peek() {
3576
+ if (this.length !== 0)
3577
+ return this.ids[0];
3578
+ }
3579
+ peekValue() {
3580
+ if (this.length !== 0)
3581
+ return this.values[0];
3582
+ }
3583
+ shrink() {
3584
+ this.ids.length = this.values.length = this.length;
3585
+ }
3586
+ }
3587
+ const re = [
3588
+ Int8Array,
3589
+ Uint8Array,
3590
+ Uint8ClampedArray,
3591
+ Int16Array,
3592
+ Uint16Array,
3593
+ Int32Array,
3594
+ Uint32Array,
3595
+ Float32Array,
3596
+ Float64Array
3597
+ ], Ct = 3;
3598
+ class Dt {
3599
+ static from(t) {
3600
+ if (!t || t.byteLength === void 0 || t.buffer)
3601
+ throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");
3602
+ const [n, e] = new Uint8Array(t, 0, 2);
3603
+ if (n !== 251)
3604
+ throw new Error("Data does not appear to be in a Flatbush format.");
3605
+ if (e >> 4 !== Ct)
3606
+ throw new Error(`Got v${e >> 4} data when expected v${Ct}.`);
3607
+ const [s] = new Uint16Array(t, 2, 1), [r] = new Uint32Array(t, 4, 1);
3608
+ return new Dt(r, s, re[e & 15], void 0, t);
3609
+ }
3610
+ constructor(t, n = 16, e = Float64Array, s = ArrayBuffer, r) {
3611
+ if (t === void 0)
3612
+ throw new Error("Missing required argument: numItems.");
3613
+ if (isNaN(t) || t <= 0)
3614
+ throw new Error(`Unexpected numItems value: ${t}.`);
3615
+ this.numItems = +t, this.nodeSize = Math.min(Math.max(+n, 2), 65535);
3616
+ let o = t, h = o;
3617
+ this._levelBounds = [o * 4];
3618
+ do
3619
+ o = Math.ceil(o / this.nodeSize), h += o, this._levelBounds.push(h * 4);
3620
+ while (o !== 1);
3621
+ this.ArrayType = e || Float64Array, this.IndexArrayType = h < 16384 ? Uint16Array : Uint32Array;
3622
+ const u = re.indexOf(this.ArrayType), l = h * 4 * this.ArrayType.BYTES_PER_ELEMENT;
3623
+ if (u < 0)
3624
+ throw new Error(`Unexpected typed array class: ${e}.`);
3625
+ r && r.byteLength !== void 0 && !r.buffer ? (this.data = r, this._boxes = new this.ArrayType(this.data, 8, h * 4), this._indices = new this.IndexArrayType(this.data, 8 + l, h), this._pos = h * 4, this.minX = this._boxes[this._pos - 4], this.minY = this._boxes[this._pos - 3], this.maxX = this._boxes[this._pos - 2], this.maxY = this._boxes[this._pos - 1]) : (this.data = new s(8 + l + h * this.IndexArrayType.BYTES_PER_ELEMENT), this._boxes = new this.ArrayType(this.data, 8, h * 4), this._indices = new this.IndexArrayType(this.data, 8 + l, h), this._pos = 0, this.minX = 1 / 0, this.minY = 1 / 0, this.maxX = -1 / 0, this.maxY = -1 / 0, new Uint8Array(this.data, 0, 2).set([251, (Ct << 4) + u]), new Uint16Array(this.data, 2, 1)[0] = n, new Uint32Array(this.data, 4, 1)[0] = t), this._queue = new Gn();
3626
+ }
3627
+ add(t, n, e, s) {
3628
+ const r = this._pos >> 2, o = this._boxes;
3629
+ return this._indices[r] = r, o[this._pos++] = t, o[this._pos++] = n, o[this._pos++] = e, o[this._pos++] = s, t < this.minX && (this.minX = t), n < this.minY && (this.minY = n), e > this.maxX && (this.maxX = e), s > this.maxY && (this.maxY = s), r;
3630
+ }
3631
+ finish() {
3632
+ if (this._pos >> 2 !== this.numItems)
3633
+ throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
3634
+ const t = this._boxes;
3635
+ if (this.numItems <= this.nodeSize) {
3636
+ t[this._pos++] = this.minX, t[this._pos++] = this.minY, t[this._pos++] = this.maxX, t[this._pos++] = this.maxY;
3637
+ return;
3638
+ }
3639
+ const n = this.maxX - this.minX || 1, e = this.maxY - this.minY || 1, s = new Uint32Array(this.numItems), r = (1 << 16) - 1;
3640
+ for (let o = 0, h = 0; o < this.numItems; o++) {
3641
+ const u = t[h++], l = t[h++], c = t[h++], a = t[h++], g = Math.floor(r * ((u + c) / 2 - this.minX) / n), w = Math.floor(r * ((l + a) / 2 - this.minY) / e);
3642
+ s[o] = Jn(g, w);
3643
+ }
3644
+ At(s, t, this._indices, 0, this.numItems - 1, this.nodeSize);
3645
+ for (let o = 0, h = 0; o < this._levelBounds.length - 1; o++) {
3646
+ const u = this._levelBounds[o];
3647
+ for (; h < u; ) {
3648
+ const l = h;
3649
+ let c = t[h++], a = t[h++], g = t[h++], w = t[h++];
3650
+ for (let m = 1; m < this.nodeSize && h < u; m++)
3651
+ c = Math.min(c, t[h++]), a = Math.min(a, t[h++]), g = Math.max(g, t[h++]), w = Math.max(w, t[h++]);
3652
+ this._indices[this._pos >> 2] = l, t[this._pos++] = c, t[this._pos++] = a, t[this._pos++] = g, t[this._pos++] = w;
3653
+ }
3654
+ }
3655
+ }
3656
+ search(t, n, e, s, r) {
3657
+ if (this._pos !== this._boxes.length)
3658
+ throw new Error("Data not yet indexed - call index.finish().");
3659
+ let o = this._boxes.length - 4;
3660
+ const h = [], u = [];
3661
+ for (; o !== void 0; ) {
3662
+ const l = Math.min(o + this.nodeSize * 4, he(o, this._levelBounds));
3663
+ for (let c = o; c < l; c += 4) {
3664
+ if (e < this._boxes[c] || s < this._boxes[c + 1] || t > this._boxes[c + 2] || n > this._boxes[c + 3])
3665
+ continue;
3666
+ const a = this._indices[c >> 2] | 0;
3667
+ o >= this.numItems * 4 ? h.push(a) : (r === void 0 || r(a)) && u.push(a);
3668
+ }
3669
+ o = h.pop();
3670
+ }
3671
+ return u;
3672
+ }
3673
+ neighbors(t, n, e = 1 / 0, s = 1 / 0, r) {
3674
+ if (this._pos !== this._boxes.length)
3675
+ throw new Error("Data not yet indexed - call index.finish().");
3676
+ let o = this._boxes.length - 4;
3677
+ const h = this._queue, u = [], l = s * s;
3678
+ for (; o !== void 0; ) {
3679
+ const c = Math.min(o + this.nodeSize * 4, he(o, this._levelBounds));
3680
+ for (let a = o; a < c; a += 4) {
3681
+ const g = this._indices[a >> 2] | 0, w = oe(t, this._boxes[a], this._boxes[a + 2]), m = oe(n, this._boxes[a + 1], this._boxes[a + 3]), d = w * w + m * m;
3682
+ o >= this.numItems * 4 ? h.push(g << 1, d) : (r === void 0 || r(g)) && h.push((g << 1) + 1, d);
3683
+ }
3684
+ for (; h.length && h.peek() & 1; )
3685
+ if (h.peekValue() > l || (u.push(h.pop() >> 1), u.length === e))
3686
+ return h.clear(), u;
3687
+ o = h.pop() >> 1;
3688
+ }
3689
+ return h.clear(), u;
3690
+ }
3691
+ }
3692
+ function oe(i, t, n) {
3693
+ return i < t ? t - i : i <= n ? 0 : i - n;
3694
+ }
3695
+ function he(i, t) {
3696
+ let n = 0, e = t.length - 1;
3697
+ for (; n < e; ) {
3698
+ const s = n + e >> 1;
3699
+ t[s] > i ? e = s : n = s + 1;
3700
+ }
3701
+ return t[n];
3702
+ }
3703
+ function At(i, t, n, e, s, r) {
3704
+ if (Math.floor(e / r) >= Math.floor(s / r))
3705
+ return;
3706
+ const o = i[e + s >> 1];
3707
+ let h = e - 1, u = s + 1;
3708
+ for (; ; ) {
3709
+ do
3710
+ h++;
3711
+ while (i[h] < o);
3712
+ do
3713
+ u--;
3714
+ while (i[u] > o);
3715
+ if (h >= u)
3716
+ break;
3717
+ Wn(i, t, n, h, u);
3718
+ }
3719
+ At(i, t, n, e, u, r), At(i, t, n, u + 1, s, r);
3720
+ }
3721
+ function Wn(i, t, n, e, s) {
3722
+ const r = i[e];
3723
+ i[e] = i[s], i[s] = r;
3724
+ const o = 4 * e, h = 4 * s, u = t[o], l = t[o + 1], c = t[o + 2], a = t[o + 3];
3725
+ t[o] = t[h], t[o + 1] = t[h + 1], t[o + 2] = t[h + 2], t[o + 3] = t[h + 3], t[h] = u, t[h + 1] = l, t[h + 2] = c, t[h + 3] = a;
3726
+ const g = n[e];
3727
+ n[e] = n[s], n[s] = g;
3728
+ }
3729
+ function Jn(i, t) {
3730
+ let n = i ^ t, e = 65535 ^ n, s = 65535 ^ (i | t), r = i & (t ^ 65535), o = n | e >> 1, h = n >> 1 ^ n, u = s >> 1 ^ e & r >> 1 ^ s, l = n & s >> 1 ^ r >> 1 ^ r;
3731
+ n = o, e = h, s = u, r = l, o = n & n >> 2 ^ e & e >> 2, h = n & e >> 2 ^ e & (n ^ e) >> 2, u ^= n & s >> 2 ^ e & r >> 2, l ^= e & s >> 2 ^ (n ^ e) & r >> 2, n = o, e = h, s = u, r = l, o = n & n >> 4 ^ e & e >> 4, h = n & e >> 4 ^ e & (n ^ e) >> 4, u ^= n & s >> 4 ^ e & r >> 4, l ^= e & s >> 4 ^ (n ^ e) & r >> 4, n = o, e = h, s = u, r = l, u ^= n & s >> 8 ^ e & r >> 8, l ^= e & s >> 8 ^ (n ^ e) & r >> 8, n = u ^ u >> 1, e = l ^ l >> 1;
3732
+ let c = i ^ t, a = e | 65535 ^ (c | n);
3733
+ return c = (c | c << 8) & 16711935, c = (c | c << 4) & 252645135, c = (c | c << 2) & 858993459, c = (c | c << 1) & 1431655765, a = (a | a << 8) & 16711935, a = (a | a << 4) & 252645135, a = (a | a << 2) & 858993459, a = (a | a << 1) & 1431655765, (a << 1 | c) >>> 0;
3734
+ }
3735
+ function ke(i, t = 1e-7) {
3736
+ if (i.length === 0)
3737
+ return [];
3738
+ if (i.length === 1)
3739
+ return [i];
3740
+ const n = new Dt(i.length);
3741
+ i.forEach((r) => {
3742
+ const [o, h] = r.firstPoint;
3743
+ n.add(o - t, h - t, o + t, h + t);
3744
+ }), n.finish();
3745
+ const e = [], s = /* @__PURE__ */ new Set();
3746
+ return i.forEach((r, o) => {
3747
+ if (s.has(o))
3748
+ return;
3749
+ const h = [r];
3750
+ let u = o;
3751
+ s.add(o);
3752
+ let l = i.length;
3753
+ for (; ; ) {
3754
+ if (l-- < 0)
3755
+ throw new Error("Infinite loop detected");
3756
+ const c = h[h.length - 1].lastPoint, [a, g] = c, w = n.search(
3757
+ a - t,
3758
+ g - t,
3759
+ a + t,
3760
+ g + t
3761
+ ), m = (p) => Math.abs((u - p) % i.length), d = w.filter((p) => !s.has(p)).map((p) => [
3762
+ i[p],
3763
+ p,
3764
+ m(p)
3765
+ ]).sort(([, , p], [, , y]) => m(p) - m(y));
3766
+ if (d.length === 0) {
3767
+ e.push(h);
3768
+ break;
3769
+ }
3770
+ const [P, f] = d[0];
3771
+ h.push(P), s.add(f), u = f;
3772
+ }
3773
+ }), e;
3774
+ }
3775
+ class U extends _t {
3776
+ constructor(t, n = [], { ignoreChecks: e = !1 } = {}) {
3777
+ super(), e || Kn(t, n), this.contour = t, this.holes = n;
3778
+ }
3779
+ get boundingBox() {
3780
+ return this.contour.boundingBox;
3781
+ }
3782
+ get isFull() {
3783
+ return this.holes.length === 0;
3784
+ }
3785
+ get allLoops() {
3786
+ return [this.contour, ...this.holes];
3787
+ }
3788
+ clone() {
3789
+ return new U(
3790
+ this.contour.clone(),
3791
+ this.holes.map((t) => t.clone())
3792
+ );
3793
+ }
3794
+ transform(t) {
3795
+ return new U(
3796
+ this.contour.transform(t),
3797
+ this.holes.map((n) => n.transform(t))
3798
+ );
3799
+ }
3800
+ contains(t) {
3801
+ return this.contour.contains(t) && !this.holes.some((n) => n.contains(t));
3802
+ }
3803
+ intersects(t) {
3804
+ return this.allLoops.some(
3805
+ (n) => t.allLoops.some((e) => n.intersects(e))
3806
+ );
3807
+ }
3808
+ overlappingStrands(t) {
3809
+ const n = t instanceof U ? t.allLoops : [t], e = this.allLoops.flatMap((s) => n.flatMap((r) => s.overlappingSegments(r)));
3810
+ return ke(e).map((s) => new G(s));
3811
+ }
3812
+ }
3813
+ function Kn(i, t = []) {
3814
+ if (!i)
3815
+ throw new Error("Figure must have a contour");
3816
+ for (const [n, e] of Bt([i, ...t]))
3817
+ if (n.intersects(e))
3818
+ throw new Error("Loops in a figure must not intersect");
3819
+ if (t.some(
3820
+ (n) => !i.contains(n.firstPoint) && !i.onStroke(n.firstPoint)
3821
+ ))
3822
+ throw new Error("Holes must be inside the contour");
3823
+ for (const [n, e] of Bt(t))
3824
+ if (n.contains(e.firstPoint))
3825
+ throw console.error(ie(n), ie(e)), new Error("Holes must not be inside other holes");
3826
+ }
3827
+ const Qn = (i) => {
3828
+ const t = i.map((s, r) => i.slice(r + 1).map((o, h) => [h + r + 1, o]).filter(([, o]) => s.boundingBox.overlaps(o.boundingBox)).map(([o]) => o)), n = [], e = Array(t.length);
3829
+ return t.forEach((s, r) => {
3830
+ let o = e[r];
3831
+ o || (o = [], n.push(o)), o.push(i[r]), s.length && s.forEach((h) => {
3832
+ e[h] = o;
3833
+ });
3834
+ }), n;
3835
+ }, Ie = (i) => i.map((t, n) => {
3836
+ const s = t.segments[0].midPoint, r = i.filter((o, h) => n === h ? !1 : o.contains(s));
3837
+ return {
3838
+ loop: t,
3839
+ isIn: r
3840
+ };
3841
+ }), Zn = (i, t) => i.flatMap(({ loop: n }) => Ut(
3842
+ t.filter(
3843
+ ({ loop: e, isIn: s }) => e === n || s.indexOf(n) !== -1
3844
+ )
3845
+ )), Hn = (i, t) => {
3846
+ const n = t.filter(({ isIn: s }) => s.length <= 1), e = Ut(
3847
+ Ie(i.map(({ loop: s }) => s))
3848
+ );
3849
+ return [n, ...e];
3850
+ }, Ut = (i) => {
3851
+ if (!i.length)
3852
+ return [];
3853
+ const t = i.filter(({ isIn: e }) => !e.length), n = i.filter(({ isIn: e }) => e.length > 1);
3854
+ return t.length === 1 && n.length === 0 ? [i] : t.length > 1 ? Zn(t, i) : Hn(n, i);
3855
+ };
3856
+ function gt(i) {
3857
+ return Qn(i).map(Ie).flatMap(Ut).map((n) => {
3858
+ if (n.length === 1)
3859
+ return new U(n[0].loop);
3860
+ n.sort((r, o) => r.isIn.length - o.isIn.length);
3861
+ const [e, ...s] = n.map(({ loop: r }) => r);
3862
+ return new U(e, s);
3863
+ });
3864
+ }
3865
+ function ts(i, t) {
3866
+ const n = [];
3867
+ for (const e of i)
3868
+ for (const s of t)
3869
+ n.push([e, s]);
3870
+ return n;
3871
+ }
3872
+ function* le(i, t, n) {
3873
+ const e = (o) => t.some((h) => E(h, o.lastPoint)), s = (o) => n.some((h) => o.isSame(h));
3874
+ let r = [];
3875
+ for (const o of i)
3876
+ e(o) ? (r.push(o), yield new G(r, { ignoreChecks: !0 }), r = []) : s(o) ? (r.length && (yield new G(r, { ignoreChecks: !0 }), r = []), yield new G([o], { ignoreChecks: !0 })) : r.push(o);
3877
+ r.length && (yield new G(r, { ignoreChecks: !0 }));
3878
+ }
3879
+ const ue = (i, t) => {
3880
+ const n = i.findIndex((r) => E(t, r.firstPoint)), e = i.slice(0, n);
3881
+ return i.slice(n).concat(e);
3882
+ }, ae = (i, t) => {
3883
+ let n = i;
3884
+ const e = (h) => E(h.firstPoint, t.firstPoint) && E(h.lastPoint, t.lastPoint);
3885
+ let s = i.findIndex(e);
3886
+ if (s === -1) {
3887
+ const h = i.map((u) => u.reverse());
3888
+ if (h.reverse(), s = h.findIndex(e), s === -1)
3889
+ throw console.error(
3890
+ h.map((u) => u.repr),
3891
+ t.repr
3892
+ ), new Error("Failed to rotate to segment start");
3893
+ n = h;
3894
+ }
3895
+ const r = n.slice(0, s);
3896
+ return n.slice(s).concat(r);
3897
+ };
3898
+ function es(i, t, n) {
3899
+ return i.filter((e) => {
3900
+ const s = t.filter((h) => E(h.firstPoint, e) || E(h.lastPoint, e));
3901
+ if (s.length % 2)
3902
+ throw new Error("Bug in the intersection algo on non crossing point");
3903
+ const r = s.map((h) => n.contains(h.midPoint));
3904
+ return !(r.every((h) => h) || !r.some((h) => h));
3905
+ });
3906
+ }
3907
+ function ns(i, t, n) {
3908
+ let e = [];
3909
+ const s = [], r = new Array(i.segments.length).fill(0).map(() => []), o = new Array(t.segments.length).fill(0).map(() => []);
3910
+ if (i.segments.forEach((g, w) => {
3911
+ t.segments.forEach((m, d) => {
3912
+ const { intersections: P, overlaps: f } = It(
3913
+ g,
3914
+ m,
3915
+ n
3916
+ );
3917
+ e.push(...P), r[w].push(...P), o[d].push(...P), s.push(...f);
3918
+ const p = f.flatMap((y) => [
3919
+ y.firstPoint,
3920
+ y.lastPoint
3921
+ ]);
3922
+ e.push(...p), r[w].push(...p), o[d].push(...p);
3923
+ });
3924
+ }), e = ct(e, n), !e.length || e.length === 1)
3925
+ return null;
3926
+ const h = ([g, w]) => w.length ? g.splitAt(w) : [g];
3927
+ let u = nt([i.segments, r]).flatMap(h), l = nt([t.segments, o]).flatMap(h);
3928
+ if (e = es(
3929
+ e,
3930
+ u,
3931
+ t
3932
+ ), !e.length && !s.length)
3933
+ return null;
3934
+ if (s.length) {
3935
+ const g = s[0];
3936
+ u = ae(
3937
+ u,
3938
+ g
3939
+ ), l = ae(
3940
+ l,
3941
+ g
3942
+ );
3943
+ } else {
3944
+ const g = e[0];
3945
+ u = ue(u, g), l = ue(l, g);
3946
+ }
3947
+ let c = Array.from(
3948
+ le(
3949
+ u,
3950
+ e,
3951
+ s
3952
+ )
3953
+ ), a = Array.from(
3954
+ le(
3955
+ l,
3956
+ e,
3957
+ s
3958
+ )
3959
+ );
3960
+ return (!E(
3961
+ a[0].lastPoint,
3962
+ c[0].lastPoint
3963
+ ) || s.length > 0 && a[0].segmentsCount !== 1) && (a = a.map((g) => g.reverse()).reverse(), E(a[0].lastPoint, c[0].lastPoint) || (c = c.map((g) => g.reverse()).reverse())), nt([c, a]).map(([g, w]) => g.segmentsCount === 1 && s.some((m) => g.segments[0].isSame(m)) ? [g, "same"] : [g, w]);
3964
+ }
3965
+ function ce(i) {
3966
+ let t = i[0];
3967
+ for (const n of i.slice(1))
3968
+ t = t.extend(n);
3969
+ if (!E(t.firstPoint, t.lastPoint))
3970
+ throw console.error(
3971
+ T(t.firstPoint),
3972
+ T(t.lastPoint)
3973
+ ), new Error("Bug in the intersection algo on non closing strand");
3974
+ return new et(t.segments);
3975
+ }
3976
+ function ss(i, t) {
3977
+ const n = nt([
3978
+ t.slice(0, -1),
3979
+ t.slice(1)
3980
+ ]).map(([s, r]) => ce(i.slice(s, r)));
3981
+ let e = i.slice(
3982
+ t[t.length - 1]
3983
+ );
3984
+ return t[0] !== 0 && (e = e.concat(i.slice(0, t[0]))), n.push(ce(e)), n;
3985
+ }
3986
+ function is(i) {
3987
+ if (!i.length)
3988
+ return [];
3989
+ const t = i.map((s) => s.firstPoint);
3990
+ let n = i.map((s) => s.lastPoint);
3991
+ n = n.slice(-1).concat(n.slice(0, -1));
3992
+ const e = nt([t, n]).flatMap(
3993
+ ([s, r], o) => E(s, r) ? [] : o
3994
+ );
3995
+ try {
3996
+ return ss(i, e);
3997
+ } catch {
3998
+ return ke(i.flatMap((r) => r.segments)).filter((r) => r.length > 1).filter((r) => E(r[0].firstPoint, r.at(-1).lastPoint)).map((r) => new et(r));
3999
+ }
4000
+ }
4001
+ const fe = (i, t) => {
4002
+ if (i.length === 0)
4003
+ return [t];
4004
+ const n = i.at(-1);
4005
+ return E(n.lastPoint, t.firstPoint) ? i.slice(0, -1).concat([n.extend(t)]) : E(n.lastPoint, t.lastPoint) ? i.slice(0, -1).concat([n.extend(t.reverse())]) : i.concat([t]);
4006
+ }, rs = (i, t) => i.length === 0 ? [t] : E(i[0].firstPoint, t.lastPoint) ? [t.extend(i[0])].concat(i.slice(1)) : [t].concat(i);
4007
+ function Yt(i, t, {
4008
+ firstInside: n,
4009
+ secondInside: e
4010
+ }) {
4011
+ const s = ns(i, t);
4012
+ if (!s) {
4013
+ const u = i.segments[0].midPoint, l = t.contains(u), c = t.segments[0].midPoint, a = i.contains(c);
4014
+ return {
4015
+ identical: !1,
4016
+ firstCurveInSecond: l,
4017
+ secondCurveInFirst: a
4018
+ };
4019
+ }
4020
+ if (s.every(([, u]) => u === "same"))
4021
+ return { identical: !0 };
4022
+ let r = null, o = null;
4023
+ const h = s.flatMap(([u, l]) => {
4024
+ let c = [], a = 0;
4025
+ if (l === "same")
4026
+ return o === 1 ? (o = 1, u) : o === 2 || o === 0 ? (o = null, []) : o === null ? (r ? r = r.extend(u) : r = u, []) : (console.error("weird situation"), []);
4027
+ const g = u.segments[0].midPoint, w = t.contains(g);
4028
+ (n === "keep" && w || n === "remove" && !w) && (a += 1, c = fe(c, u));
4029
+ const m = l.segments[0].midPoint, d = i.contains(m);
4030
+ if (e === "keep" && d || e === "remove" && !d) {
4031
+ const P = l;
4032
+ a += 1, a === 2 && c.length ? (c = fe(c, P), r = null) : c = [P];
4033
+ }
4034
+ return o === null && a === 1 && r && (c = rs(c, r)), a === 1 && (o = a, r = null), c.length ? c : (r = null, []);
4035
+ });
4036
+ return is(h);
4037
+ }
4038
+ const os = (i, t) => {
4039
+ const n = Yt(i, t, {
4040
+ firstInside: "remove",
4041
+ secondInside: "remove"
4042
+ });
4043
+ return Array.isArray(n) ? n : n.identical ? [i] : n.firstCurveInSecond ? [t] : n.secondCurveInFirst ? [i] : [i, t];
4044
+ }, xt = (i, t) => {
4045
+ const n = Yt(i, t, {
4046
+ firstInside: "remove",
4047
+ secondInside: "keep"
4048
+ });
4049
+ return Array.isArray(n) ? n : n.identical ? [] : n.firstCurveInSecond ? [] : n.secondCurveInFirst ? [i, t] : [i];
4050
+ }, Xt = (i, t) => {
4051
+ const n = Yt(i, t, {
4052
+ firstInside: "keep",
4053
+ secondInside: "keep"
4054
+ });
4055
+ return Array.isArray(n) ? n : n.identical ? [i] : n.firstCurveInSecond ? [i] : n.secondCurveInFirst ? [t] : [];
4056
+ };
4057
+ function hs(i) {
4058
+ const t = /* @__PURE__ */ new Map(), n = [];
4059
+ return i.forEach((e, s) => {
4060
+ let r;
4061
+ t.has(s) ? r = t.get(s) : (r = { current: [e], fusedWith: /* @__PURE__ */ new Set([s]) }, n.push(r)), i.slice(s + 1).forEach((o, h) => {
4062
+ const u = r.current, l = s + h + 1;
4063
+ if (r.fusedWith.has(l))
4064
+ return;
4065
+ let c = [o], a = !1;
4066
+ if (t.has(l) && (c = t.get(l).current, a = !0), !u.some(
4067
+ (m) => c.some((d) => m.intersects(d))
4068
+ ))
4069
+ return;
4070
+ let w;
4071
+ u.length > 1 || c.length > 1 ? w = pt(u, c) : w = xe(u[0], c[0]), r.fusedWith.add(l), r.current = w, a || t.set(l, r);
4072
+ });
4073
+ }), n.flatMap(({ current: e }) => e);
4074
+ }
4075
+ function xe(i, t) {
4076
+ const n = os(i.contour, t.contour), e = t.holes.flatMap((o) => xt(o, i.contour)), s = i.holes.flatMap((o) => xt(o, t.contour)), r = ts(i.holes, t.holes).flatMap(
4077
+ ([o, h]) => Xt(o, h)
4078
+ );
4079
+ return gt([
4080
+ ...n,
4081
+ ...e,
4082
+ ...s,
4083
+ ...r
4084
+ ]);
4085
+ }
4086
+ function Rt(i, t) {
4087
+ if (i.isFull && t.isFull)
4088
+ return gt(xt(i.contour, t.contour));
4089
+ if (i.isFull) {
4090
+ const e = xt(i.contour, t.contour), s = t.holes.flatMap(
4091
+ (r) => Xt(r, i.contour)
4092
+ );
4093
+ return gt([...e, ...s]);
4094
+ } else if (t.isFull && !i.contour.intersects(t.contour))
4095
+ if (i.contour.contains(t.contour.firstPoint)) {
4096
+ const e = pt(
4097
+ i.holes.map((s) => new U(s)),
4098
+ [t]
4099
+ );
4100
+ return gt([
4101
+ i.contour,
4102
+ ...e.flatMap((s) => s.allLoops)
4103
+ ]);
4104
+ } else
4105
+ return [i];
4106
+ let n = Rt(new U(i.contour), t);
4107
+ return i.holes.forEach((e) => {
4108
+ n = n.flatMap((s) => Rt(s, new U(e)));
4109
+ }), n;
4110
+ }
4111
+ function ls(i, t) {
4112
+ const n = Xt(i.contour, t.contour);
4113
+ if (!n.length)
4114
+ return [];
4115
+ let e = gt(n);
4116
+ return e = wt(
4117
+ e,
4118
+ i.holes.map((s) => new U(s))
4119
+ ), wt(
4120
+ e,
4121
+ t.holes.map((s) => new U(s))
4122
+ );
4123
+ }
4124
+ function pt(i, t) {
4125
+ if (!i.length)
4126
+ return t;
4127
+ if (!t.length)
4128
+ return i;
4129
+ if (i.length === 1 && t.length > 1 || t.length === 1 && i.length > 1)
4130
+ return hs([...i, ...t]);
4131
+ if (i.length > 1 && t.length > 1) {
4132
+ let n = pt([i[0]], t);
4133
+ return i.slice(1).forEach((e) => {
4134
+ n = pt([e], n);
4135
+ }), n;
4136
+ }
4137
+ return i.length === 1 && t.length === 1 ? xe(i[0], t[0]) : [];
4138
+ }
4139
+ function wt(i, t) {
4140
+ if (!i.length)
4141
+ return [];
4142
+ if (!t.length)
4143
+ return i;
4144
+ if (i.length === 1 && t.length === 1)
4145
+ return Rt(i[0], t[0]);
4146
+ if (i.length > 1)
4147
+ return i.flatMap((e) => wt([e], t));
4148
+ let n = Rt(i[0], t[0]);
4149
+ return t.slice(1).forEach((e) => {
4150
+ n = wt(n, [e]);
4151
+ }), n;
4152
+ }
4153
+ function Nt(i, t) {
4154
+ return !i.length || !t.length ? [] : i.length === 1 && t.length === 1 ? ls(i[0], t[0]) : i.length > 1 ? i.flatMap((n) => Nt([n], t)) : t.flatMap((n) => Nt(i, [n]));
4155
+ }
4156
+ class tt extends _t {
4157
+ constructor(t = [], { ignoreChecks: n = !1 } = {}) {
4158
+ super(), this._boundingBox = null, n || us(t), this.figures = t;
4159
+ }
4160
+ get isEmpty() {
4161
+ return this.figures.length === 0;
4162
+ }
4163
+ get boundingBox() {
4164
+ if (this.isEmpty)
4165
+ return new it();
4166
+ if (this._boundingBox === null) {
4167
+ let t = this.figures[0].boundingBox;
4168
+ for (const n of this.figures.slice(1))
4169
+ t = t.merge(n.boundingBox);
4170
+ this._boundingBox = t;
4171
+ }
4172
+ return this._boundingBox;
4173
+ }
4174
+ clone() {
4175
+ return new tt(this.figures.map((t) => t.clone()));
4176
+ }
4177
+ transform(t) {
4178
+ return new tt(this.figures.map((n) => n.transform(t)));
4179
+ }
4180
+ contains(t) {
4181
+ return this.figures.some((n) => n.contains(t));
4182
+ }
4183
+ intersects(t) {
4184
+ return this.figures.some(
4185
+ (n) => t.figures.some((e) => n.intersects(e))
4186
+ );
4187
+ }
4188
+ overlappingStrands(t) {
4189
+ return this.figures.flatMap((n) => t instanceof tt ? t.figures.flatMap(
4190
+ (e) => n.overlappingStrands(e)
4191
+ ) : n.overlappingStrands(t));
4192
+ }
4193
+ fuse(t) {
4194
+ return new tt(pt(this.figures, t.figures));
4195
+ }
4196
+ cut(t) {
4197
+ return new tt(wt(this.figures, t.figures));
4198
+ }
4199
+ intersect(t) {
4200
+ return new tt(Nt(this.figures, t.figures));
4201
+ }
4202
+ }
4203
+ function us(i) {
4204
+ for (const [t, n] of Bt(i))
4205
+ if (t.intersects(n))
4206
+ throw new Error("Diagram figures must not intersect");
4207
+ }
4208
+ export {
4209
+ I as A,
4210
+ it as B,
4211
+ gs as C,
4212
+ tt as D,
4213
+ C as E,
4214
+ U as F,
4215
+ bt as G,
4216
+ as as H,
4217
+ fs as I,
4218
+ Xe as J,
4219
+ ft as K,
4220
+ et as L,
4221
+ Lt as M,
4222
+ Ue as R,
4223
+ G as S,
4224
+ V as T,
4225
+ pt as a,
4226
+ kt as b,
4227
+ wt as c,
4228
+ q as d,
4229
+ A as e,
4230
+ It as f,
4231
+ O as g,
4232
+ D as h,
4233
+ Nt as i,
4234
+ me as j,
4235
+ Ye as k,
4236
+ Ft as l,
4237
+ mt as m,
4238
+ W as n,
4239
+ R as o,
4240
+ Qe as p,
4241
+ ke as q,
4242
+ ct as r,
4243
+ le as s,
4244
+ E as t,
4245
+ cs as u,
4246
+ at as v,
4247
+ ie as w,
4248
+ _t as x,
4249
+ J as y,
4250
+ nt as z
4251
+ };
4252
+ //# sourceMappingURL=Diagram-d848c815.js.map