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