pantograph2d 0.8.0 → 0.8.1

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