pantograph2d 0.7.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 (154) 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-DqsKIWJD.js +337 -0
  7. package/dist/draw-DqsKIWJD.js.map +1 -0
  8. package/dist/draw-NcYfDZjT.cjs +2 -0
  9. package/dist/draw-NcYfDZjT.cjs.map +1 -0
  10. package/dist/models-Dxwusy3i.cjs +4 -0
  11. package/dist/models-Dxwusy3i.cjs.map +1 -0
  12. package/dist/models-WQ-B7GSL.js +1749 -0
  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 -13
  17. package/dist/pantograph/drawShape.js.map +1 -1
  18. package/dist/pantograph/models.cjs +1 -1
  19. package/dist/pantograph/models.js +15 -12
  20. package/dist/pantograph/models.js.map +1 -1
  21. package/dist/pantograph/svg.cjs +2 -0
  22. package/dist/pantograph/svg.cjs.map +1 -0
  23. package/dist/pantograph/svg.js +10 -0
  24. package/dist/pantograph/svg.js.map +1 -0
  25. package/dist/pantograph.cjs +2 -8
  26. package/dist/pantograph.cjs.map +1 -1
  27. package/dist/pantograph.js +406 -452
  28. package/dist/pantograph.js.map +1 -1
  29. package/dist/svg-BylQQgsL.js +62 -0
  30. package/dist/svg-BylQQgsL.js.map +1 -0
  31. package/dist/svg-D0nYyMk7.cjs +8 -0
  32. package/dist/svg-D0nYyMk7.cjs.map +1 -0
  33. package/dist/types/examples/importSVG.d.ts +4 -0
  34. package/dist/types/{algorithms → src/algorithms}/boolean/figureBooleans.d.ts +1 -1
  35. package/dist/types/{algorithms → src/algorithms}/boolean/loopBooleans.d.ts +1 -1
  36. package/dist/types/{algorithms → src/algorithms}/boolean/strandBoolean.d.ts +4 -4
  37. package/dist/types/{algorithms → src/algorithms}/boolean/strandsBetweenIntersections.d.ts +3 -3
  38. package/dist/types/{algorithms → src/algorithms}/distances/arcArcDistance.d.ts +1 -1
  39. package/dist/types/{algorithms → src/algorithms}/distances/genericDistance.d.ts +1 -1
  40. package/dist/types/{algorithms → src/algorithms}/distances/index.d.ts +1 -1
  41. package/dist/types/src/algorithms/distances/lineArcDistance.d.ts +3 -0
  42. package/dist/types/{algorithms → src/algorithms}/distances/lineLineDistance.d.ts +1 -1
  43. package/dist/types/{algorithms → src/algorithms}/filletSegments.d.ts +1 -1
  44. package/dist/types/{algorithms → src/algorithms}/intersections/arcArcIntersection.d.ts +2 -2
  45. package/dist/types/src/algorithms/intersections/arcEllipseArcIntersection.d.ts +3 -0
  46. package/dist/types/src/algorithms/intersections/arcsCubicBezierIntersection.d.ts +5 -0
  47. package/dist/types/src/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +5 -0
  48. package/dist/types/{algorithms → src/algorithms}/intersections/bezierClip.d.ts +3 -3
  49. package/dist/types/{algorithms → src/algorithms}/intersections/cubicBezierCubicBezierIntersection.d.ts +2 -2
  50. package/dist/types/{algorithms → src/algorithms}/intersections/ellipseArcEllipseArcIntersection.d.ts +2 -2
  51. package/dist/types/src/algorithms/intersections/ellipseEllipseIntersection.d.ts +4 -0
  52. package/dist/types/{algorithms → src/algorithms}/intersections/index.d.ts +2 -2
  53. package/dist/types/src/algorithms/intersections/lineArcIntersection.d.ts +4 -0
  54. package/dist/types/src/algorithms/intersections/lineBezierIntersection.d.ts +5 -0
  55. package/dist/types/src/algorithms/intersections/lineEllipseArcIntersection.d.ts +4 -0
  56. package/dist/types/{algorithms → src/algorithms}/intersections/lineLineIntersection.d.ts +4 -4
  57. package/dist/types/{algorithms → src/algorithms}/intersections/quadraticBezierQuadraticBezierIntersection.d.ts +2 -2
  58. package/dist/types/src/algorithms/intersections/rayIntersections.d.ts +3 -0
  59. package/dist/types/{algorithms → src/algorithms}/offsets/offsetFigure.d.ts +2 -2
  60. package/dist/types/{algorithms → src/algorithms}/offsets/offsetSegment.d.ts +4 -4
  61. package/dist/types/{algorithms → src/algorithms}/offsets/offsetStroke.d.ts +5 -5
  62. package/dist/types/{algorithms → src/algorithms}/organiseLoops.d.ts +2 -2
  63. package/dist/types/src/algorithms/simplify.d.ts +3 -0
  64. package/dist/types/src/algorithms/solvers/findZeroViaNewton.d.ts +1 -0
  65. package/dist/types/src/algorithms/solvers/zeroViaNewton.d.ts +1 -0
  66. package/dist/types/{algorithms → src/algorithms}/stitchSegments.d.ts +1 -1
  67. package/dist/types/src/api/drawShape.d.ts +2 -0
  68. package/dist/types/src/api/models.d.ts +1 -0
  69. package/dist/types/src/api/svg.d.ts +1 -0
  70. package/dist/types/{booleanOperations.d.ts → src/booleanOperations.d.ts} +5 -5
  71. package/dist/types/{draw.d.ts → src/draw.d.ts} +4 -4
  72. package/dist/types/{drawShape → src/drawShape}/drawCircle.d.ts +1 -1
  73. package/dist/types/src/drawShape/drawEllipse.d.ts +2 -0
  74. package/dist/types/{drawShape → src/drawShape}/drawRect.d.ts +1 -1
  75. package/dist/types/src/drawShape/drawSVGPath.d.ts +2 -0
  76. package/dist/types/src/drawShape/index.d.ts +4 -0
  77. package/dist/types/{export → src/export}/json/exportJSON.d.ts +94 -94
  78. package/dist/types/{export → src/export}/json/jsonDiagram.d.ts +31 -31
  79. package/dist/types/{export → src/export}/json/jsonFigure.d.ts +31 -31
  80. package/dist/types/{export → src/export}/json/jsonLoop.d.ts +16 -16
  81. package/dist/types/{export → src/export}/json/jsonSegment.d.ts +16 -16
  82. package/dist/types/src/export/svg/api.d.ts +6 -0
  83. package/dist/types/{export → src/export}/svg/exportSVG.d.ts +6 -6
  84. package/dist/types/{export → src/export}/svg/svgDiagram.d.ts +1 -1
  85. package/dist/types/{export → src/export}/svg/svgFigure.d.ts +1 -1
  86. package/dist/types/{export → src/export}/svg/svgLoop.d.ts +1 -1
  87. package/dist/types/{export → src/export}/svg/svgSegment.d.ts +1 -1
  88. package/dist/types/{export → src/export}/svg/svgStrand.d.ts +1 -1
  89. package/dist/types/{export → src/export}/svg/wrapSVG.d.ts +2 -2
  90. package/dist/types/src/import/json/importJSON.d.ts +9 -0
  91. package/dist/types/{main.d.ts → src/main.d.ts} +7 -7
  92. package/dist/types/{models → src/models}/BoundingBox.d.ts +1 -1
  93. package/dist/types/{models → src/models}/Diagram.d.ts +7 -7
  94. package/dist/types/{models → src/models}/Figure.d.ts +7 -7
  95. package/dist/types/{models → src/models}/Loop.d.ts +4 -4
  96. package/dist/types/{models → src/models}/Strand.d.ts +2 -2
  97. package/dist/types/{models → src/models}/Stroke.d.ts +5 -5
  98. package/dist/types/{models → src/models}/TransformationMatrix.d.ts +1 -1
  99. package/dist/types/src/models/exports.d.ts +15 -0
  100. package/dist/types/src/models/segments/AbstractSegment.d.ts +25 -0
  101. package/dist/types/{models → src/models}/segments/Arc.d.ts +4 -4
  102. package/dist/types/{models → src/models}/segments/CubicBezier.d.ts +4 -4
  103. package/dist/types/{models → src/models}/segments/EllipseArc.d.ts +5 -5
  104. package/dist/types/{models → src/models}/segments/Line.d.ts +4 -4
  105. package/dist/types/{models → src/models}/segments/QuadraticBezier.d.ts +4 -4
  106. package/dist/types/{models → src/models}/segments/Segment.d.ts +4 -4
  107. package/dist/types/{models → src/models}/segments/utils/deCasteljau.d.ts +1 -1
  108. package/dist/types/src/models/segments/utils/isSegment.d.ts +8 -0
  109. package/dist/types/{models → src/models}/utils/Transformable.d.ts +2 -2
  110. package/dist/types/{offsetOperations.d.ts → src/offsetOperations.d.ts} +4 -4
  111. package/dist/types/src/operations.d.ts +2 -0
  112. package/dist/types/src/utils/applyMixins.d.ts +1 -0
  113. package/dist/types/src/utils/listOfFigures.d.ts +4 -0
  114. package/dist/types/src/utils/projectPointOnLine.d.ts +3 -0
  115. package/dist/types/{utils → src/utils}/removeDuplicatePoints.d.ts +1 -1
  116. package/dist/types/{vectorOperations.d.ts → src/vectorOperations.d.ts} +1 -1
  117. package/package.json +33 -25
  118. package/dist/Diagram-8c3c5e1b.js +0 -5301
  119. package/dist/Diagram-8c3c5e1b.js.map +0 -1
  120. package/dist/Diagram-d8288579.cjs +0 -11
  121. package/dist/Diagram-d8288579.cjs.map +0 -1
  122. package/dist/draw-3ee546c3.cjs +0 -2
  123. package/dist/draw-3ee546c3.cjs.map +0 -1
  124. package/dist/draw-825692f1.js +0 -336
  125. package/dist/draw-825692f1.js.map +0 -1
  126. package/dist/types/algorithms/distances/lineArcDistance.d.ts +0 -3
  127. package/dist/types/algorithms/intersections/arcEllipseArcIntersection.d.ts +0 -3
  128. package/dist/types/algorithms/intersections/arcsCubicBezierIntersection.d.ts +0 -5
  129. package/dist/types/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +0 -5
  130. package/dist/types/algorithms/intersections/ellipseEllipseIntersection.d.ts +0 -4
  131. package/dist/types/algorithms/intersections/lineArcIntersection.d.ts +0 -4
  132. package/dist/types/algorithms/intersections/lineBezierIntersection.d.ts +0 -5
  133. package/dist/types/algorithms/intersections/lineEllipseArcIntersection.d.ts +0 -4
  134. package/dist/types/algorithms/intersections/rayIntersections.d.ts +0 -3
  135. package/dist/types/algorithms/simplify.d.ts +0 -3
  136. package/dist/types/api/drawShape.d.ts +0 -2
  137. package/dist/types/api/models.d.ts +0 -1
  138. package/dist/types/import/json/importJSON.d.ts +0 -9
  139. package/dist/types/models/exports.d.ts +0 -13
  140. package/dist/types/models/segments/utils/isSegment.d.ts +0 -8
  141. package/dist/types/operations.d.ts +0 -2
  142. package/dist/types/utils/listOfFigures.d.ts +0 -4
  143. package/dist/types/utils/projectPointOnLine.d.ts +0 -3
  144. /package/dist/types/{algorithms → src/algorithms}/optimisation/Brent.d.ts +0 -0
  145. /package/dist/types/{algorithms → src/algorithms}/optimisation/DiRect.d.ts +0 -0
  146. /package/dist/types/{algorithms → src/algorithms}/solvers/solvePolynomials.d.ts +0 -0
  147. /package/dist/types/{definitions.d.ts → src/definitions.d.ts} +0 -0
  148. /package/dist/types/{utils → src/utils}/allCombinations.d.ts +0 -0
  149. /package/dist/types/{utils → src/utils}/allPairs.d.ts +0 -0
  150. /package/dist/types/{utils → src/utils}/angularDistance.d.ts +0 -0
  151. /package/dist/types/{utils → src/utils}/range.d.ts +0 -0
  152. /package/dist/types/{utils → src/utils}/removeDuplicateValues.d.ts +0 -0
  153. /package/dist/types/{utils → src/utils}/unitAngle.d.ts +0 -0
  154. /package/dist/types/{utils → src/utils}/zip.d.ts +0 -0
@@ -0,0 +1,9 @@
1
+ "use strict";var Ge=Object.defineProperty;var be=r=>{throw TypeError(r)};var Qe=(r,s,e)=>s in r?Ge(r,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[s]=e;var q=(r,s,e)=>Qe(r,typeof s!="symbol"?s+"":s,e),he=(r,s,e)=>s.has(r)||be("Cannot "+e);var ot=(r,s,e)=>(he(r,s,"read from private field"),e?e.call(r):s.get(r)),ae=(r,s,e)=>s.has(r)?be("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(r):s.set(r,e),zt=(r,s,e,t)=>(he(r,s,"write to private field"),t?t.call(r,e):s.set(r,e),e),ue=(r,s,e)=>(he(r,s,"access private method"),e);function Bt(r,s,e,t){return r<=t&&s>=e}class ct{constructor(s=1/0,e=1/0,t=-1/0,n=-1/0){q(this,"xMin");q(this,"yMin");q(this,"xMax");q(this,"yMax");this.xMin=s,this.yMin=e,this.xMax=t,this.yMax=n}get width(){return this.xMax-this.xMin}get height(){return this.yMax-this.yMin}get center(){return[(this.xMin+this.xMax)/2,(this.yMin+this.yMax)/2]}grow(s){return new ct(this.xMin-s,this.yMin-s,this.xMax+s,this.yMax+s)}contains(s){const[e,t]=s;return Bt(this.xMin,this.xMax,e,e)&&Bt(this.yMin,this.yMax,t,t)}overlaps(s){return Bt(this.xMin,this.xMax,s.xMin,s.xMax)&&Bt(this.yMin,this.yMax,s.yMin,s.yMax)}addPoint(s){const[e,t]=s;return new ct(Math.min(this.xMin,e),Math.min(this.yMin,t),Math.max(this.xMax,e),Math.max(this.yMax,t))}merge(s){return new ct(Math.min(this.xMin,s.xMin),Math.min(this.yMin,s.yMin),Math.max(this.xMax,s.xMax),Math.max(this.yMax,s.yMax))}intersection(s){return new ct(Math.max(this.xMin,s.xMin),Math.max(this.yMin,s.yMin),Math.min(this.xMax,s.xMax),Math.min(this.yMax,s.yMax))}}function ge(r){return r.reduce((s,e)=>s.addPoint(e),new ct)}const Ee=(r,s=1e-9)=>{let e=r;return Math.abs(r)<s&&(e=0),e.toFixed(-Math.log10(s))};function we(r,s=1e-9){return Array.from(new Map(r.map(([e,t])=>[`[${Ee(e,s)},${Ee(t,s)}]`,[e,t]])).values())}const Kt=Math.PI/180,Ce=180/Math.PI,Z=r=>`[${r[0]}, ${r[1]}]`,Y=([r,s],[e,t],n=1e-9)=>Math.abs(r-e)<=n&&Math.abs(s-t)<=n,at=([r,s],[e,t])=>[r+e,s+t],X=([r,s],[e,t])=>[r-e,s-t],Tt=([r,s])=>r*r+s*s,Xe=([r,s])=>Math.sqrt(Tt([r,s])),mt=([r,s],e)=>[r*e,s*e],Et=([r,s],[e,t]=[0,0])=>(r-e)**2+(s-t)**2,J=(r,s=[0,0])=>Math.sqrt(Et(r,s));function yt([r,s],[e,t]){return r*t-s*e}function ce([r,s],[e,t]){return r*e+s*t}function K([r,s]){const e=J([r,s]);return[r/e,s/e]}function Rt(r,s){const e=Math.cos(s)*r,t=Math.sin(s)*r;return[e,t]}function qe([r,s]){return Math.atan2(s,r)}function Fe(r){const s=J(r),e=qe(r);return[s,e]}function pe(r,s,e=1e-9){const t=yt(r,s),n=Tt(r),i=Tt(s);return t*t<n*i*e*e}function st(r){return[-r[1],r[0]]}function Ct(r){return[r[1],-r[0]]}function Ze(r,s,e){return Y(e,r)||pe(X(e,r),s)}const _t=(r,s)=>{const[e,t,n,i,o,l,h,a,u]=r,[c,g,d,w,p,P,f,M,E]=s;return[e*c+t*w+n*f,e*g+t*p+n*M,e*d+t*P+n*E,i*c+o*w+l*f,i*g+o*p+l*M,i*d+o*P+l*E,h*c+a*w+u*f,h*g+a*p+u*M,h*d+a*P+u*E]},Je=r=>{const[s,e,t,n,i,o,l,h,a]=r,u=s*(i*a-o*h)-e*(n*a-o*l)+t*(n*h-i*l);return[(i*a-o*h)/u,(t*h-e*a)/u,(e*o-t*i)/u,(o*l-n*a)/u,(s*a-t*l)/u,(t*n-s*o)/u,(n*h-i*l)/u,(e*l-s*h)/u,(s*i-e*n)/u]},Ke=r=>{const[s,e,t,n,i,o,l,h,a]=r;return[s,n,l,e,i,h,t,o,a]};class tt{constructor(s){q(this,"_matrix",[1,0,0,0,1,0,0,0,1]);s&&(this._matrix=[...s])}clone(){return new tt(this._matrix)}transpose(){return this._matrix=Ke(this._matrix),this}inverse(){return this._matrix=Je(this._matrix),this}translate(s,e){return this._matrix=_t(this._matrix,[1,0,s,0,1,e,0,0,1]),this}rotate(s,e){const t=Math.cos(s),n=Math.sin(s),i=[t,-n,0,n,t,0,0,0,1];return e&&this.translate(e[0],e[1]),this._matrix=_t(this._matrix,i),e&&this.translate(-e[0],-e[1]),this}mirrorX(){return this._matrix=_t(this._matrix,[1,0,0,0,-1,0,0,0,1]),this}mirrorY(){return this._matrix=_t(this._matrix,[-1,0,0,0,1,0,0,0,1]),this}mirrorLine(s,e){const[t,n]=s,i=Math.atan2(n,t);return e&&this.translate(e[0],e[1]),this.rotate(i),this.mirrorX(),this.rotate(-i),e&&this.translate(-e[0],-e[1]),this}mirrorCenter(s){return s&&this.translate(s[0],s[1]),this._matrix=_t(this._matrix,[-1,0,0,0,-1,0,0,0,1]),s&&this.translate(-s[0],-s[1]),this}scale(s,e){return e&&this.translate(e[0],e[1]),this._matrix=_t(this._matrix,[s,0,0,0,s,0,0,0,1]),e&&this.translate(-e[0],-e[1]),this}transform(s){const[e,t]=s,[n,i,o,l,h,a]=this._matrix;return[n*e+i*t+o,l*e+h*t+a]}transformAngle(s){const[e,t]=this.transform([Math.cos(s),Math.sin(s)]),[n,i]=this.transform([0,0]);return Math.atan2(t-i,e-n)}keepsOrientation(){const[s,,,,e]=this._matrix;return s*e>0}scaleFactor(){const[s,,,e]=this._matrix;return Math.sqrt(s*s+e*e)}}class Ae{translateX(s){const e=new tt().translate(s,0);return this.transform(e)}translateY(s){const e=new tt().translate(0,s);return this.transform(e)}translate(s,e){const t=new tt().translate(s,e);return this.transform(t)}translateTo([s,e]){const t=new tt().translate(s,e);return this.transform(t)}rotate(s,e){const t=new tt().rotate(s*Kt,e);return this.transform(t)}scale(s,e){const t=new tt().scale(s,e);return this.transform(t)}mirrorCenter(s){const e=new tt().mirrorCenter(s);return this.transform(e)}mirror(s="x",e){const t=new tt;return s==="x"?t.mirrorX():s==="y"?t.mirrorY():t.mirrorLine(s,e),this.transform(t)}}class At extends Ae{constructor(e,t){super();q(this,"precision",1e-9);this.firstPoint=e,this.lastPoint=t,this.firstPoint=e,this.lastPoint=t}get repr(){return`${this.segmentType} ${Z(this.firstPoint)} - ${Z(this.lastPoint)}`}get info(){return this.repr}[Symbol.for("nodejs.util.inspect.custom")](){return this.repr}}class lt extends At{constructor(){super(...arguments);q(this,"segmentType","LINE");q(this,"_V",null);q(this,"_slope",null);q(this,"_yIntercept",null);q(this,"_boundingBox",null)}isValidParameter(e){const t=this.length*this.precision;return e>=-t&&1-e>=-t}paramPoint(e){return at(this.firstPoint,mt(this.V,e))}get length(){return J(this.firstPoint,this.lastPoint)}get squareLength(){return Et(this.firstPoint,this.lastPoint)}get V(){return this._V===null&&(this._V=X(this.lastPoint,this.firstPoint)),this._V}get slope(){if(this._slope===null){const[e,t]=this.V;this._slope=t/e}return this._slope}get yIntercept(){return this._yIntercept===null&&(this._yIntercept=this.firstPoint[1]-this.slope*this.firstPoint[0]),this._yIntercept}get midPoint(){return at(this.firstPoint,mt(this.V,.5))}isSame(e){return e instanceof lt?Y(this.firstPoint,e.firstPoint)&&Y(this.lastPoint,e.lastPoint)||Y(this.lastPoint,e.firstPoint)&&Y(this.firstPoint,e.lastPoint):!1}clone(){return new lt(this.firstPoint,this.lastPoint)}reverse(){return new lt(this.lastPoint,this.firstPoint)}get boundingBox(){return this._boundingBox===null&&(this._boundingBox=new ct(Math.min(this.firstPoint[0],this.lastPoint[0])-this.precision,Math.min(this.firstPoint[1],this.lastPoint[1])-this.precision,Math.max(this.firstPoint[0],this.lastPoint[0])+this.precision,Math.max(this.firstPoint[1],this.lastPoint[1])+this.precision)),this._boundingBox}distanceFrom(e){const t=X(e,this.firstPoint),n=ce(t,this.V)/this.squareLength;if(n<0)return J(e,this.firstPoint);if(n>1)return J(e,this.lastPoint);const i=this.paramPoint(n);return J(e,i)}isOnSegment(e){if(Y(e,this.firstPoint,this.precision))return!0;const t=X(e,this.firstPoint);if(!pe(this.V,t))return!1;const n=ce(t,this.V)/this.squareLength;return this.isValidParameter(n)}gradientAt(e){return this.V}tangentAt(e){if(!this.isOnSegment(e))throw new Error("Point is not on segment");return K(this.V)}get normalVector(){return st(K(this.V))}get tangentAtFirstPoint(){return K(this.V)}get tangentAtLastPoint(){return K(this.V)}splitAt(e){let t;if(Array.isArray(e)&&e.length===0)return[this];Array.isArray(e[0])?t=e:t=[e],t.forEach(a=>{if(!this.isOnSegment(a))throw new Error(`Point ${Z(a)} is not on segment ${this.repr}`)});const n=[this.firstPoint,...t,this.lastPoint],i=we(n),o=this.lastPoint[0]-this.firstPoint[0];let l=Math.sign(o),h=0;return Math.abs(o)<this.precision&&(l=Math.sign(this.lastPoint[1]-this.firstPoint[1]),h=1),i.sort((a,u)=>l*(a[h]-u[h])),i.flatMap((a,u)=>u===i.length-1?[]:new lt(a,i[u+1]))}transform(e){return new lt(e.transform(this.firstPoint),e.transform(this.lastPoint))}}function He(r){return Array.from(Array(r).keys())}function xt(r){const s=Math.min(...r.map(e=>e.length));return He(s).map(e=>r.map(t=>t[e]))}function dt(r,s=1e-9){return r<0?r+2*Math.PI:r>=2*Math.PI?r%(2*Math.PI):r>2*Math.PI-s?0:r}function Zt(r,s,e,t=1e-9){let n=s-r;return e&&(n=-n),n<0&&(n+=2*Math.PI),n>2*Math.PI-t?0:n}const Ht=(r,s,e)=>{const t=yt(r.V,s.V),n=Tt(r.V),i=Tt(s.V),o=e?e*e:r.precision*s.precision;if(t*t<n*i*o)return"parallel";const l=X(s.firstPoint,r.firstPoint),h=yt(l,s.V)/t,a=yt(l,r.V)/t;return{intersectionParam1:h,intersectionParam2:a}};function ts(r,s,e=!1,t){const n=Ht(r,s,t);if(n==="parallel"){if(!e)return null;if(r.isSame(s))return r;const l=we([s.isOnSegment(r.firstPoint)?r.firstPoint:null,s.isOnSegment(r.lastPoint)?r.lastPoint:null,r.isOnSegment(s.firstPoint)?s.firstPoint:null,r.isOnSegment(s.lastPoint)?s.lastPoint:null].filter(h=>h!==null)).sort((h,a)=>h[0]-a[0]);if(l.length===0)return null;if(l.length===1)return null;if(l.length===2)return new lt(l[0],l[1]);throw console.error(l),new Error("Unexpected number of points while intersecting parallel lines")}const{intersectionParam1:i,intersectionParam2:o}=n;return!r.isValidParameter(i)||!s.isValidParameter(o)?null:r.paramPoint(i)}const Ot=(r,s)=>{const e=X(r,s);return Fe(e)};class ht extends At{constructor(e,t,n,i=!1,{ignoreChecks:o=!1}={}){super(e,t);q(this,"segmentType","ARC");q(this,"center");q(this,"clockwise");q(this,"_coefficients",null);q(this,"_angularLength",null);q(this,"_radius",null);q(this,"_firstAngle",null);q(this,"_lastAngle",null);q(this,"_boundingBox",null);if(this.center=n,this.clockwise=i,!o){if(Y(e,t))throw new Error("Invalid arc, cannot be a full circle");if(Math.abs(this.radius-J(this.lastPoint,this.center))>this.precision)throw new Error(`Invalid arc, radius does not match between ${Z(e)} and ${Z(t)}} (center ${Z(n)})`)}}get info(){return`ARC(${Z(this.firstPoint)}, ${Z(this.lastPoint)}, ${Z(this.center)}, ${this.clockwise?"CW":"CCW"})`}get coefficients(){if(this._coefficients===null){const[e,t]=this.center,n=this.radius*this.radius;this._coefficients={x2:1/n,xy:0,y2:1/n,x:-(2*e)/n,y:-(2*t)/n,c:(e*e+t*t-n)/n}}return this._coefficients}isValidParameter(e){return 1-e>=-this.precision&&e>=-this.precision}angleToParam(e){return Zt(this.firstAngle,dt(e),this.clockwise)/this.angularLength}get angularLength(){return this._angularLength||(this._angularLength=Zt(this.firstAngle,this.lastAngle,this.clockwise)),this._angularLength}paramPoint(e){return at(this.center,Rt(this.radius,this.firstAngle+e*this.angularLength*(this.clockwise?-1:1)))}pointToParam(e){const[t,n]=Ot(e,this.center);if(Math.abs(t-this.radius)>this.precision)throw new Error(`Point ${Z(e)} is not on segment ${this.repr}`);const i=this.angleToParam(n);if(!this.isValidParameter(i))throw new Error(`Point ${Z(e)} is not on segment ${this.repr}`);return i}get radius(){return this._radius===null&&(this._radius=J(this.firstPoint,this.center)),this._radius}get firstAngle(){if(this._firstAngle===null){const[e,t]=X(this.firstPoint,this.center);this._firstAngle=dt(Math.atan2(t,e))}return this._firstAngle}get lastAngle(){if(this._lastAngle===null){const[e,t]=X(this.lastPoint,this.center);this._lastAngle=dt(Math.atan2(t,e))}return this._lastAngle}get length(){return this.radius*this.angularLength}get squareLength(){return this.length*this.length}get midPoint(){return this.paramPoint(.5)}isSame(e){return!(e instanceof ht)||!Y(this.center,e.center)?!1:Y(this.firstPoint,e.firstPoint)&&Y(this.lastPoint,e.lastPoint)&&this.clockwise===e.clockwise||Y(this.lastPoint,e.firstPoint)&&Y(this.firstPoint,e.lastPoint)&&this.clockwise===!e.clockwise}clone(){return new ht(this.firstPoint,this.lastPoint,this.center,this.clockwise)}reverse(){return new ht(this.lastPoint,this.firstPoint,this.center,!this.clockwise)}get boundingBox(){if(this._boundingBox===null){const e=this.radius+this.precision,t=n=>this.isValidParameter(this.angleToParam(n));this._boundingBox=new ct(t(Math.PI)?this.center[0]-e:Math.min(this.firstPoint[0],this.lastPoint[0])-this.precision,t(Math.PI*1.5)?this.center[1]-e:Math.min(this.firstPoint[1],this.lastPoint[1])-this.precision,t(0)?this.center[0]+e:Math.max(this.firstPoint[0],this.lastPoint[0])+this.precision,t(Math.PI/2)?this.center[1]+e:Math.max(this.firstPoint[1],this.lastPoint[1])+this.precision)}return this._boundingBox}distanceFrom(e){const[t,n]=Ot(e,this.center);return this.isValidParameter(this.angleToParam(n))?Math.abs(t-this.radius):Math.sqrt(Math.min(Et(e,this.firstPoint),Et(e,this.lastPoint)))}isOnSegment(e){if(Y(e,this.firstPoint)||Y(e,this.lastPoint))return!0;const[t,n]=Ot(e,this.center);if(Math.abs(t-this.radius)>this.precision)return!1;const i=this.angleToParam(n);return this.isValidParameter(i)}gradientAt(e){const t=this.firstAngle+e*this.angularLength*(this.clockwise?-1:1),n=this.radius*this.angularLength,i=-n*Math.sin(t),o=n*Math.cos(t);return this.clockwise?[-i,-o]:[i,o]}tangentAt(e){const[t,n]=Ot(e,this.center);if(Math.abs(t-this.radius)>this.precision)throw new Error("Point is not on the arc");const i=this.angleToParam(n);if(!this.isValidParameter(i))throw new Error("Point is not on the arc");const o=Rt(1,n);return(this.clockwise?Ct:st)(K(o))}get tangentAtFirstPoint(){const e=Rt(1,this.firstAngle);return(this.clockwise?Ct:st)(K(e))}get tangentAtLastPoint(){const e=Rt(1,this.lastAngle);return(this.clockwise?Ct:st)(K(e))}splitAt(e){let t;if(Array.isArray(e)&&e.length===0)return[this];Array.isArray(e[0])?t=e:t=[e];const i=[0,1,...t.map(h=>this.pointToParam(h))],o=new Map(xt([i,[this.firstPoint,this.lastPoint,...t]]));i.sort((h,a)=>h-a);let l=null;return i.flatMap((h,a)=>{if(a===i.length-1)return[];const u=i[a+1];if(u-h<this.precision)return l===null&&(l=h),[];const c=l===null?h:l,g=new ht(o.get(c)||this.paramPoint(c),o.get(u)||this.paramPoint(u),this.center,this.clockwise);return l=null,g})}transform(e){return new ht(e.transform(this.firstPoint),e.transform(this.lastPoint),e.transform(this.center),e.keepsOrientation()?this.clockwise:!this.clockwise)}}function es(r,s,e){const t=new lt(s,r),n=new lt(s,e),i=st(t.tangentAtFirstPoint),o=st(n.tangentAtLastPoint),l=Ht({firstPoint:t.midPoint,V:i,precision:1e-9},{firstPoint:n.midPoint,V:o,precision:1e-9});if(l==="parallel")throw new Error("Cannot create an arc from three colinear points");const h=yt(X(r,s),X(e,s))>0;return new ht(r,e,at(t.midPoint,mt(i,l.intersectionParam1)),h,{ignoreChecks:!0})}function ss(r,s,e){const t=new lt(s,r),n=st(t.tangentAtFirstPoint),i=Ht({firstPoint:t.midPoint,V:n,precision:1e-9},{firstPoint:r,V:st(e),precision:1e-9});if(i==="parallel")throw new Error("Cannot create an arc from three colinear points");const o=at(t.midPoint,mt(n,i.intersectionParam1)),l=yt(X(o,r),X(o,at(r,e)))<0;return new ht(r,s,o,l,{ignoreChecks:!0})}const _e=1e-21,Ut=1.618034;function je(r,s=0,e=1,t=110,n=1e3){let i,o,l,h,a,u,c,g,d,w,p,P,f;for(o=r(s),l=r(e),o<l&&([s,e]=[e,s],[o,l]=[l,o]),f=e+Ut*(e-s),h=r(f),a=3,c=0;h<l;){if(g=(e-s)*(l-h),d=(e-f)*(l-o),w=d-g,Math.abs(w)<_e?i=2*_e:i=2*w,p=e-((e-f)*d-(e-s)*g)/i,P=e+t*(f-e),c>n)throw new Error("Too many iterations.");if(c+=1,(p-f)*(e-p)>0){if(u=r(p),a+=1,u<h)return s=e,e=p,o=l,l=u,[s,e,f,o,l,h,a];if(u>l)return f=p,h=u,[s,e,f,o,l,h,a];p=f+Ut*(f-e),u=r(p),a+=1}else(p-P)*(P-f)>=0?(p=P,u=r(p),a+=1):(p-P)*(f-p)>0?(u=r(p),a+=1,u<h&&(e=f,f=p,p=f+Ut*(f-e),l=h,h=u,u=r(p),a+=1)):(p=f+Ut*(f-e),u=r(p),a+=1);s=e,e=f,f=p,o=l,l=h,h=u}return[s,e,f,o,l,h,a]}const Se=.381966,ns=1e-11;class is{constructor(s,e=148e-10,t=500){q(this,"xmin");q(this,"fval");q(this,"iter");q(this,"funcalls");q(this,"brack");this.func=s,this.tol=e,this.maxiter=t,this.func=s,this.tol=e,this.maxiter=t,this.xmin=1/0,this.fval=1/0,this.iter=0,this.funcalls=0,this.brack=null}setBracket(s=null){this.brack=s}getBracketInfo(){let s,e,t,n,i,o,l;const h=this.func,a=this.brack;if(a===null)[i,o,l,s,e,t,n]=je(h);else if(a.length===2)[i,o,l,s,e,t,n]=je(h,a[0],a[1]);else if(a.length===3){if([i,o,l]=a,i>l&&([l,i]=[i,l]),!(i<o&&o<l))throw new Error("Not a bracketing interval.");if(s=h(i),e=h(o),t=h(l),!(e<s&&e<t))throw new Error("Not a bracketing interval.");n=3}else throw new Error("Bracketing interval must be length 2 or 3 sequence.");return[i,o,l,s,e,t,n]}optimize(){const s=this.func;let[e,t,n,,,,i]=this.getBracketInfo(),o=t,l=t,h=t,a=s(o),u=a,c=a,g,d;e<n?(g=e,d=n):(g=n,d=e);let w=0;i=1;let p=0,P=0,f;for(;p<this.maxiter;){const M=this.tol*Math.abs(o)+ns,E=2*M,R=.5*(g+d);if(Math.abs(o-R)<E-.5*(d-g))break;if(Math.abs(w)<=M)o>=R?w=g-o:w=d-o,P=Se*w;else{const L=(o-l)*(c-u);let S=(o-h)*(c-a),k=(o-h)*S-(o-l)*L;S=2*(S-L),S>0&&(k=-k),S=Math.abs(S);const D=w;w=P,k>S*(g-o)&&k<S*(d-o)&&Math.abs(k)<Math.abs(.5*S*D)?(P=k*1/S,f=o+P,(f-g<E||d-f<E)&&(R-o>=0?P=M:P=-M)):(o>=R?w=g-o:w=d-o,P=Se*w)}Math.abs(P)<M?P>=0?f=o+M:f=o-M:f=o+P;const v=s(f);i+=1,v>c?(f<o?g=f:d=f,v<=a||l===o?(h=l,l=f,u=a,a=v):(v<=u||h===o||h===l)&&(h=f,u=v)):(f>=o?g=o:d=o,h=l,l=o,o=f,u=a,a=c,c=v),p+=1}this.xmin=o,this.fval=c,this.iter=p,this.funcalls=i}results(){return{argMin:this.xmin,fMin:this.fval,iterations:this.iter,funcCalls:this.funcalls}}run(){return this.optimize(),this.results()}}function xe(r,s=1e-8,e=1e3){const t=new is(r,s,e);return t.setBracket([0,1]),t.run()}function Ve(r){if(r.__esModule)return r;var s=r.default;if(typeof s=="function"){var e=function t(){return this instanceof t?Reflect.construct(s,arguments,this.constructor):s.apply(this,arguments)};e.prototype=s.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(r).forEach(function(t){var n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return r[t]}})}),e}var $={};const rs=Object.prototype.toString;function qt(r){const s=rs.call(r);return s.endsWith("Array]")&&!s.includes("Big")}const os=Object.freeze(Object.defineProperty({__proto__:null,isAnyArray:qt},Symbol.toStringTag,{value:"Module"})),ls=Ve(os);function hs(r){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!qt(r))throw new TypeError("input must be an array");if(r.length===0)throw new TypeError("input must not be empty");var e=s.fromIndex,t=e===void 0?0:e,n=s.toIndex,i=n===void 0?r.length:n;if(t<0||t>=r.length||!Number.isInteger(t))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=t||i>r.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var o=r[t],l=t+1;l<i;l++)r[l]>o&&(o=r[l]);return o}function as(r){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!qt(r))throw new TypeError("input must be an array");if(r.length===0)throw new TypeError("input must not be empty");var e=s.fromIndex,t=e===void 0?0:e,n=s.toIndex,i=n===void 0?r.length:n;if(t<0||t>=r.length||!Number.isInteger(t))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=t||i>r.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var o=r[t],l=t+1;l<i;l++)r[l]<o&&(o=r[l]);return o}function us(r){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(qt(r)){if(r.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var e;if(s.output!==void 0){if(!qt(s.output))throw new TypeError("output option must be an array if specified");e=s.output}else e=new Array(r.length);var t=as(r),n=hs(r);if(t===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=s.min,o=i===void 0?s.autoMinMax?t:0:i,l=s.max,h=l===void 0?s.autoMinMax?n:1:l;if(o>=h)throw new RangeError("min option must be smaller than max option");for(var a=(h-o)/(n-t),u=0;u<r.length;u++)e[u]=(r[u]-t)*a+o;return e}const cs=Object.freeze(Object.defineProperty({__proto__:null,default:us},Symbol.toStringTag,{value:"Module"})),fs=Ve(cs);Object.defineProperty($,"__esModule",{value:!0});var et=ls,ke=fs;const Yt=" ".repeat(2),Ne=" ".repeat(4);function ms(){return $e(this)}function $e(r,s={}){const{maxRows:e=15,maxColumns:t=10,maxNumSize:n=8,padMinus:i="auto"}=s;return`${r.constructor.name} {
2
+ ${Yt}[
3
+ ${Ne}${gs(r,e,t,n,i)}
4
+ ${Yt}]
5
+ ${Yt}rows: ${r.rows}
6
+ ${Yt}columns: ${r.columns}
7
+ }`}function gs(r,s,e,t,n){const{rows:i,columns:o}=r,l=Math.min(i,s),h=Math.min(o,e),a=[];if(n==="auto"){n=!1;t:for(let u=0;u<l;u++)for(let c=0;c<h;c++)if(r.get(u,c)<0){n=!0;break t}}for(let u=0;u<l;u++){let c=[];for(let g=0;g<h;g++)c.push(ws(r.get(u,g),t,n));a.push(`${c.join(" ")}`)}return h!==o&&(a[a.length-1]+=` ... ${o-e} more columns`),l!==i&&a.push(`... ${i-s} more rows`),a.join(`
8
+ ${Ne}`)}function ws(r,s,e){return(r>=0&&e?` ${Re(r,s-1)}`:Re(r,s)).padEnd(s)}function Re(r,s){let e=r.toString();if(e.length<=s)return e;let t=r.toFixed(s);if(t.length>s&&(t=r.toFixed(Math.max(0,s-(t.length-s)))),t.length<=s&&!t.startsWith("0.000")&&!t.startsWith("-0.000"))return t;let n=r.toExponential(s);return n.length>s&&(n=r.toExponential(Math.max(0,s-(n.length-s)))),n.slice(0)}function ps(r,s){r.prototype.add=function(t){return typeof t=="number"?this.addS(t):this.addM(t)},r.prototype.addS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)+t);return this},r.prototype.addM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)+t.get(n,i));return this},r.add=function(t,n){return new s(t).add(n)},r.prototype.sub=function(t){return typeof t=="number"?this.subS(t):this.subM(t)},r.prototype.subS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)-t);return this},r.prototype.subM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)-t.get(n,i));return this},r.sub=function(t,n){return new s(t).sub(n)},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){return typeof t=="number"?this.mulS(t):this.mulM(t)},r.prototype.mulS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)*t);return this},r.prototype.mulM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)*t.get(n,i));return this},r.mul=function(t,n){return new s(t).mul(n)},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){return typeof t=="number"?this.divS(t):this.divM(t)},r.prototype.divS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)/t);return this},r.prototype.divM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)/t.get(n,i));return this},r.div=function(t,n){return new s(t).div(n)},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){return typeof t=="number"?this.modS(t):this.modM(t)},r.prototype.modS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)%t);return this},r.prototype.modM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)%t.get(n,i));return this},r.mod=function(t,n){return new s(t).mod(n)},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){return typeof t=="number"?this.andS(t):this.andM(t)},r.prototype.andS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)&t);return this},r.prototype.andM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)&t.get(n,i));return this},r.and=function(t,n){return new s(t).and(n)},r.prototype.or=function(t){return typeof t=="number"?this.orS(t):this.orM(t)},r.prototype.orS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)|t);return this},r.prototype.orM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)|t.get(n,i));return this},r.or=function(t,n){return new s(t).or(n)},r.prototype.xor=function(t){return typeof t=="number"?this.xorS(t):this.xorM(t)},r.prototype.xorS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)^t);return this},r.prototype.xorM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)^t.get(n,i));return this},r.xor=function(t,n){return new s(t).xor(n)},r.prototype.leftShift=function(t){return typeof t=="number"?this.leftShiftS(t):this.leftShiftM(t)},r.prototype.leftShiftS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)<<t);return this},r.prototype.leftShiftM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)<<t.get(n,i));return this},r.leftShift=function(t,n){return new s(t).leftShift(n)},r.prototype.signPropagatingRightShift=function(t){return typeof t=="number"?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},r.prototype.signPropagatingRightShiftS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>t);return this},r.prototype.signPropagatingRightShiftM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>t.get(n,i));return this},r.signPropagatingRightShift=function(t,n){return new s(t).signPropagatingRightShift(n)},r.prototype.rightShift=function(t){return typeof t=="number"?this.rightShiftS(t):this.rightShiftM(t)},r.prototype.rightShiftS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>>t);return this},r.prototype.rightShiftM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>>t.get(n,i));return this},r.rightShift=function(t,n){return new s(t).rightShift(n)},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(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,~this.get(t,n));return this},r.not=function(t){return new s(t).not()},r.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.abs(this.get(t,n)));return this},r.abs=function(t){return new s(t).abs()},r.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.acos(this.get(t,n)));return this},r.acos=function(t){return new s(t).acos()},r.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.acosh(this.get(t,n)));return this},r.acosh=function(t){return new s(t).acosh()},r.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.asin(this.get(t,n)));return this},r.asin=function(t){return new s(t).asin()},r.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.asinh(this.get(t,n)));return this},r.asinh=function(t){return new s(t).asinh()},r.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.atan(this.get(t,n)));return this},r.atan=function(t){return new s(t).atan()},r.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.atanh(this.get(t,n)));return this},r.atanh=function(t){return new s(t).atanh()},r.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.cbrt(this.get(t,n)));return this},r.cbrt=function(t){return new s(t).cbrt()},r.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.ceil(this.get(t,n)));return this},r.ceil=function(t){return new s(t).ceil()},r.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.clz32(this.get(t,n)));return this},r.clz32=function(t){return new s(t).clz32()},r.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.cos(this.get(t,n)));return this},r.cos=function(t){return new s(t).cos()},r.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.cosh(this.get(t,n)));return this},r.cosh=function(t){return new s(t).cosh()},r.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.exp(this.get(t,n)));return this},r.exp=function(t){return new s(t).exp()},r.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.expm1(this.get(t,n)));return this},r.expm1=function(t){return new s(t).expm1()},r.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.floor(this.get(t,n)));return this},r.floor=function(t){return new s(t).floor()},r.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.fround(this.get(t,n)));return this},r.fround=function(t){return new s(t).fround()},r.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.log(this.get(t,n)));return this},r.log=function(t){return new s(t).log()},r.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.log1p(this.get(t,n)));return this},r.log1p=function(t){return new s(t).log1p()},r.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.log10(this.get(t,n)));return this},r.log10=function(t){return new s(t).log10()},r.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.log2(this.get(t,n)));return this},r.log2=function(t){return new s(t).log2()},r.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.round(this.get(t,n)));return this},r.round=function(t){return new s(t).round()},r.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.sign(this.get(t,n)));return this},r.sign=function(t){return new s(t).sign()},r.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.sin(this.get(t,n)));return this},r.sin=function(t){return new s(t).sin()},r.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.sinh(this.get(t,n)));return this},r.sinh=function(t){return new s(t).sinh()},r.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.sqrt(this.get(t,n)));return this},r.sqrt=function(t){return new s(t).sqrt()},r.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.tan(this.get(t,n)));return this},r.tan=function(t){return new s(t).tan()},r.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.tanh(this.get(t,n)));return this},r.tanh=function(t){return new s(t).tanh()},r.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.set(t,n,Math.trunc(this.get(t,n)));return this},r.trunc=function(t){return new s(t).trunc()},r.pow=function(t,n){return new s(t).pow(n)},r.prototype.pow=function(t){return typeof t=="number"?this.powS(t):this.powM(t)},r.prototype.powS=function(t){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)**t);return this},r.prototype.powM=function(t){if(t=s.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)**t.get(n,i));return this}}function it(r,s,e){let t=e?r.rows:r.rows-1;if(s<0||s>t)throw new RangeError("Row index out of range")}function rt(r,s,e){let t=e?r.columns:r.columns-1;if(s<0||s>t)throw new RangeError("Column index out of range")}function St(r,s){if(s.to1DArray&&(s=s.to1DArray()),s.length!==r.columns)throw new RangeError("vector size must be the same as the number of columns");return s}function kt(r,s){if(s.to1DArray&&(s=s.to1DArray()),s.length!==r.rows)throw new RangeError("vector size must be the same as the number of rows");return s}function de(r,s){if(!et.isAnyArray(s))throw new TypeError("row indices must be an array");for(let e=0;e<s.length;e++)if(s[e]<0||s[e]>=r.rows)throw new RangeError("row indices are out of range")}function Me(r,s){if(!et.isAnyArray(s))throw new TypeError("column indices must be an array");for(let e=0;e<s.length;e++)if(s[e]<0||s[e]>=r.columns)throw new RangeError("column indices are out of range")}function fe(r,s,e,t,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(Wt("startRow",s),Wt("endRow",e),Wt("startColumn",t),Wt("endColumn",n),s>e||t>n||s<0||s>=r.rows||e<0||e>=r.rows||t<0||t>=r.columns||n<0||n>=r.columns)throw new RangeError("Submatrix indices are out of range")}function te(r,s=0){let e=[];for(let t=0;t<r;t++)e.push(s);return e}function Wt(r,s){if(typeof s!="number")throw new TypeError(`${r} must be a number`)}function jt(r){if(r.isEmpty())throw new Error("Empty matrix has no elements to index")}function ds(r){let s=te(r.rows);for(let e=0;e<r.rows;++e)for(let t=0;t<r.columns;++t)s[e]+=r.get(e,t);return s}function Ms(r){let s=te(r.columns);for(let e=0;e<r.rows;++e)for(let t=0;t<r.columns;++t)s[t]+=r.get(e,t);return s}function ys(r){let s=0;for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)s+=r.get(e,t);return s}function Ps(r){let s=te(r.rows,1);for(let e=0;e<r.rows;++e)for(let t=0;t<r.columns;++t)s[e]*=r.get(e,t);return s}function bs(r){let s=te(r.columns,1);for(let e=0;e<r.rows;++e)for(let t=0;t<r.columns;++t)s[t]*=r.get(e,t);return s}function Es(r){let s=1;for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)s*=r.get(e,t);return s}function _s(r,s,e){const t=r.rows,n=r.columns,i=[];for(let o=0;o<t;o++){let l=0,h=0,a=0;for(let u=0;u<n;u++)a=r.get(o,u)-e[o],l+=a,h+=a*a;s?i.push((h-l*l/n)/(n-1)):i.push((h-l*l/n)/n)}return i}function js(r,s,e){const t=r.rows,n=r.columns,i=[];for(let o=0;o<n;o++){let l=0,h=0,a=0;for(let u=0;u<t;u++)a=r.get(u,o)-e[o],l+=a,h+=a*a;s?i.push((h-l*l/t)/(t-1)):i.push((h-l*l/t)/t)}return i}function Ss(r,s,e){const t=r.rows,n=r.columns,i=t*n;let o=0,l=0,h=0;for(let a=0;a<t;a++)for(let u=0;u<n;u++)h=r.get(a,u)-e,o+=h,l+=h*h;return s?(l-o*o/i)/(i-1):(l-o*o/i)/i}function ks(r,s){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)-s[e])}function Rs(r,s){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)-s[t])}function vs(r,s){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)-s)}function Ts(r){const s=[];for(let e=0;e<r.rows;e++){let t=0;for(let n=0;n<r.columns;n++)t+=r.get(e,n)**2/(r.columns-1);s.push(Math.sqrt(t))}return s}function Is(r,s){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)/s[e])}function Cs(r){const s=[];for(let e=0;e<r.columns;e++){let t=0;for(let n=0;n<r.rows;n++)t+=r.get(n,e)**2/(r.rows-1);s.push(Math.sqrt(t))}return s}function qs(r,s){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)/s[t])}function Fs(r){const s=r.size-1;let e=0;for(let t=0;t<r.columns;t++)for(let n=0;n<r.rows;n++)e+=r.get(n,t)**2/s;return Math.sqrt(e)}function As(r,s){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)/s)}class V{static from1DArray(s,e,t){if(s*e!==t.length)throw new RangeError("data length does not match given dimensions");let i=new _(s,e);for(let o=0;o<s;o++)for(let l=0;l<e;l++)i.set(o,l,t[o*e+l]);return i}static rowVector(s){let e=new _(1,s.length);for(let t=0;t<s.length;t++)e.set(0,t,s[t]);return e}static columnVector(s){let e=new _(s.length,1);for(let t=0;t<s.length;t++)e.set(t,0,s[t]);return e}static zeros(s,e){return new _(s,e)}static ones(s,e){return new _(s,e).fill(1)}static rand(s,e,t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{random:n=Math.random}=t;let i=new _(s,e);for(let o=0;o<s;o++)for(let l=0;l<e;l++)i.set(o,l,n());return i}static randInt(s,e,t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:n=0,max:i=1e3,random:o=Math.random}=t;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(i))throw new TypeError("max must be an integer");if(n>=i)throw new RangeError("min must be smaller than max");let l=i-n,h=new _(s,e);for(let a=0;a<s;a++)for(let u=0;u<e;u++){let c=n+Math.round(o()*l);h.set(a,u,c)}return h}static eye(s,e,t){e===void 0&&(e=s),t===void 0&&(t=1);let n=Math.min(s,e),i=this.zeros(s,e);for(let o=0;o<n;o++)i.set(o,o,t);return i}static diag(s,e,t){let n=s.length;e===void 0&&(e=n),t===void 0&&(t=e);let i=Math.min(n,e,t),o=this.zeros(e,t);for(let l=0;l<i;l++)o.set(l,l,s[l]);return o}static min(s,e){s=this.checkMatrix(s),e=this.checkMatrix(e);let t=s.rows,n=s.columns,i=new _(t,n);for(let o=0;o<t;o++)for(let l=0;l<n;l++)i.set(o,l,Math.min(s.get(o,l),e.get(o,l)));return i}static max(s,e){s=this.checkMatrix(s),e=this.checkMatrix(e);let t=s.rows,n=s.columns,i=new this(t,n);for(let o=0;o<t;o++)for(let l=0;l<n;l++)i.set(o,l,Math.max(s.get(o,l),e.get(o,l)));return i}static checkMatrix(s){return V.isMatrix(s)?s:new _(s)}static isMatrix(s){return s!=null&&s.klass==="Matrix"}get size(){return this.rows*this.columns}apply(s){if(typeof s!="function")throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)s.call(this,e,t);return this}to1DArray(){let s=[];for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)s.push(this.get(e,t));return s}to2DArray(){let s=[];for(let e=0;e<this.rows;e++){s.push([]);for(let t=0;t<this.columns;t++)s[e].push(this.get(e,t))}return s}toJSON(){return this.to2DArray()}isRowVector(){return this.rows===1}isColumnVector(){return this.columns===1}isVector(){return this.rows===1||this.columns===1}isSquare(){return this.rows===this.columns}isEmpty(){return this.rows===0||this.columns===0}isSymmetric(){if(this.isSquare()){for(let s=0;s<this.rows;s++)for(let e=0;e<=s;e++)if(this.get(s,e)!==this.get(e,s))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let s=0;s<this.rows;s++)if(this.get(s,s)!==0)return!1;return!0}isEchelonForm(){let s=0,e=0,t=-1,n=!0,i=!1;for(;s<this.rows&&n;){for(e=0,i=!1;e<this.columns&&i===!1;)this.get(s,e)===0?e++:this.get(s,e)===1&&e>t?(i=!0,t=e):(n=!1,i=!0);s++}return n}isReducedEchelonForm(){let s=0,e=0,t=-1,n=!0,i=!1;for(;s<this.rows&&n;){for(e=0,i=!1;e<this.columns&&i===!1;)this.get(s,e)===0?e++:this.get(s,e)===1&&e>t?(i=!0,t=e):(n=!1,i=!0);for(let o=e+1;o<this.rows;o++)this.get(s,o)!==0&&(n=!1);s++}return n}echelonForm(){let s=this.clone(),e=0,t=0;for(;e<s.rows&&t<s.columns;){let n=e;for(let i=e;i<s.rows;i++)s.get(i,t)>s.get(n,t)&&(n=i);if(s.get(n,t)===0)t++;else{s.swapRows(e,n);let i=s.get(e,t);for(let o=t;o<s.columns;o++)s.set(e,o,s.get(e,o)/i);for(let o=e+1;o<s.rows;o++){let l=s.get(o,t)/s.get(e,t);s.set(o,t,0);for(let h=t+1;h<s.columns;h++)s.set(o,h,s.get(o,h)-s.get(e,h)*l)}e++,t++}}return s}reducedEchelonForm(){let s=this.echelonForm(),e=s.columns,t=s.rows,n=t-1;for(;n>=0;)if(s.maxRow(n)===0)n--;else{let i=0,o=!1;for(;i<t&&o===!1;)s.get(n,i)===1?o=!0:i++;for(let l=0;l<n;l++){let h=s.get(l,i);for(let a=i;a<e;a++){let u=s.get(l,a)-h*s.get(n,a);s.set(l,a,u)}}n--}return s}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(s={}){if(typeof s!="object")throw new TypeError("options must be an object");const{rows:e=1,columns:t=1}=s;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(t)||t<=0)throw new TypeError("columns must be a positive integer");let n=new _(this.rows*e,this.columns*t);for(let i=0;i<e;i++)for(let o=0;o<t;o++)n.setSubMatrix(this,this.rows*i,this.columns*o);return n}fill(s){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,s);return this}neg(){return this.mulS(-1)}getRow(s){it(this,s);let e=[];for(let t=0;t<this.columns;t++)e.push(this.get(s,t));return e}getRowVector(s){return _.rowVector(this.getRow(s))}setRow(s,e){it(this,s),e=St(this,e);for(let t=0;t<this.columns;t++)this.set(s,t,e[t]);return this}swapRows(s,e){it(this,s),it(this,e);for(let t=0;t<this.columns;t++){let n=this.get(s,t);this.set(s,t,this.get(e,t)),this.set(e,t,n)}return this}getColumn(s){rt(this,s);let e=[];for(let t=0;t<this.rows;t++)e.push(this.get(t,s));return e}getColumnVector(s){return _.columnVector(this.getColumn(s))}setColumn(s,e){rt(this,s),e=kt(this,e);for(let t=0;t<this.rows;t++)this.set(t,s,e[t]);return this}swapColumns(s,e){rt(this,s),rt(this,e);for(let t=0;t<this.rows;t++){let n=this.get(t,s);this.set(t,s,this.get(t,e)),this.set(t,e,n)}return this}addRowVector(s){s=St(this,s);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)+s[t]);return this}subRowVector(s){s=St(this,s);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)-s[t]);return this}mulRowVector(s){s=St(this,s);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)*s[t]);return this}divRowVector(s){s=St(this,s);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)/s[t]);return this}addColumnVector(s){s=kt(this,s);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)+s[e]);return this}subColumnVector(s){s=kt(this,s);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)-s[e]);return this}mulColumnVector(s){s=kt(this,s);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)*s[e]);return this}divColumnVector(s){s=kt(this,s);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)/s[e]);return this}mulRow(s,e){it(this,s);for(let t=0;t<this.columns;t++)this.set(s,t,this.get(s,t)*e);return this}mulColumn(s,e){rt(this,s);for(let t=0;t<this.rows;t++)this.set(t,s,this.get(t,s)*e);return this}max(s){if(this.isEmpty())return NaN;switch(s){case"row":{const e=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.get(t,n)>e[t]&&(e[t]=this.get(t,n));return e}case"column":{const e=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.get(t,n)>e[n]&&(e[n]=this.get(t,n));return e}case void 0:{let e=this.get(0,0);for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n));return e}default:throw new Error(`invalid option: ${s}`)}}maxIndex(){jt(this);let s=this.get(0,0),e=[0,0];for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.get(t,n)>s&&(s=this.get(t,n),e[0]=t,e[1]=n);return e}min(s){if(this.isEmpty())return NaN;switch(s){case"row":{const e=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.get(t,n)<e[t]&&(e[t]=this.get(t,n));return e}case"column":{const e=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.get(t,n)<e[n]&&(e[n]=this.get(t,n));return e}case void 0:{let e=this.get(0,0);for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n));return e}default:throw new Error(`invalid option: ${s}`)}}minIndex(){jt(this);let s=this.get(0,0),e=[0,0];for(let t=0;t<this.rows;t++)for(let n=0;n<this.columns;n++)this.get(t,n)<s&&(s=this.get(t,n),e[0]=t,e[1]=n);return e}maxRow(s){if(it(this,s),this.isEmpty())return NaN;let e=this.get(s,0);for(let t=1;t<this.columns;t++)this.get(s,t)>e&&(e=this.get(s,t));return e}maxRowIndex(s){it(this,s),jt(this);let e=this.get(s,0),t=[s,0];for(let n=1;n<this.columns;n++)this.get(s,n)>e&&(e=this.get(s,n),t[1]=n);return t}minRow(s){if(it(this,s),this.isEmpty())return NaN;let e=this.get(s,0);for(let t=1;t<this.columns;t++)this.get(s,t)<e&&(e=this.get(s,t));return e}minRowIndex(s){it(this,s),jt(this);let e=this.get(s,0),t=[s,0];for(let n=1;n<this.columns;n++)this.get(s,n)<e&&(e=this.get(s,n),t[1]=n);return t}maxColumn(s){if(rt(this,s),this.isEmpty())return NaN;let e=this.get(0,s);for(let t=1;t<this.rows;t++)this.get(t,s)>e&&(e=this.get(t,s));return e}maxColumnIndex(s){rt(this,s),jt(this);let e=this.get(0,s),t=[0,s];for(let n=1;n<this.rows;n++)this.get(n,s)>e&&(e=this.get(n,s),t[0]=n);return t}minColumn(s){if(rt(this,s),this.isEmpty())return NaN;let e=this.get(0,s);for(let t=1;t<this.rows;t++)this.get(t,s)<e&&(e=this.get(t,s));return e}minColumnIndex(s){rt(this,s),jt(this);let e=this.get(0,s),t=[0,s];for(let n=1;n<this.rows;n++)this.get(n,s)<e&&(e=this.get(n,s),t[0]=n);return t}diag(){let s=Math.min(this.rows,this.columns),e=[];for(let t=0;t<s;t++)e.push(this.get(t,t));return e}norm(s="frobenius"){switch(s){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${s}`)}}cumulativeSum(){let s=0;for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)s+=this.get(e,t),this.set(e,t,s);return this}dot(s){V.isMatrix(s)&&(s=s.to1DArray());let e=this.to1DArray();if(e.length!==s.length)throw new RangeError("vectors do not have the same size");let t=0;for(let n=0;n<e.length;n++)t+=e[n]*s[n];return t}mmul(s){s=_.checkMatrix(s);let e=this.rows,t=this.columns,n=s.columns,i=new _(e,n),o=new Float64Array(t);for(let l=0;l<n;l++){for(let h=0;h<t;h++)o[h]=s.get(h,l);for(let h=0;h<e;h++){let a=0;for(let u=0;u<t;u++)a+=this.get(h,u)*o[u];i.set(h,l,a)}}return i}mpow(s){if(!this.isSquare())throw new RangeError("Matrix must be square");if(!Number.isInteger(s)||s<0)throw new RangeError("Exponent must be a non-negative integer");let e=_.eye(this.rows),t=this;for(let n=s;n>1;n/=2)n&1&&(e=e.mmul(t)),t=t.mmul(t);return e}strassen2x2(s){s=_.checkMatrix(s);let e=new _(2,2);const t=this.get(0,0),n=s.get(0,0),i=this.get(0,1),o=s.get(0,1),l=this.get(1,0),h=s.get(1,0),a=this.get(1,1),u=s.get(1,1),c=(t+a)*(n+u),g=(l+a)*n,d=t*(o-u),w=a*(h-n),p=(t+i)*u,P=(l-t)*(n+o),f=(i-a)*(h+u),M=c+w-p+f,E=d+p,R=g+w,v=c-g+d+P;return e.set(0,0,M),e.set(0,1,E),e.set(1,0,R),e.set(1,1,v),e}strassen3x3(s){s=_.checkMatrix(s);let e=new _(3,3);const t=this.get(0,0),n=this.get(0,1),i=this.get(0,2),o=this.get(1,0),l=this.get(1,1),h=this.get(1,2),a=this.get(2,0),u=this.get(2,1),c=this.get(2,2),g=s.get(0,0),d=s.get(0,1),w=s.get(0,2),p=s.get(1,0),P=s.get(1,1),f=s.get(1,2),M=s.get(2,0),E=s.get(2,1),R=s.get(2,2),v=(t+n+i-o-l-u-c)*P,L=(t-o)*(-d+P),S=l*(-g+d+p-P-f-M+R),k=(-t+o+l)*(g-d+P),D=(o+l)*(-g+d),m=t*g,b=(-t+a+u)*(g-w+f),j=(-t+a)*(w-f),y=(a+u)*(-g+w),C=(t+n+i-l-h-a-u)*f,F=u*(-g+w+p-P-f-M+E),I=(-i+u+c)*(P+M-E),O=(i-c)*(P-E),A=i*M,N=(u+c)*(-M+E),x=(-i+l+h)*(f+M-R),B=(i-h)*(f-R),U=(l+h)*(-M+R),T=n*p,z=h*E,Q=o*w,G=a*d,W=c*R,ie=m+A+T,re=v+k+D+m+I+A+N,oe=m+b+y+C+A+x+U,le=L+S+k+m+A+x+B,Vt=L+k+D+m+z,Nt=A+x+B+U+Q,$t=m+b+j+F+I+O+A,Lt=I+O+A+N+G,Dt=m+b+j+y+W;return e.set(0,0,ie),e.set(0,1,re),e.set(0,2,oe),e.set(1,0,le),e.set(1,1,Vt),e.set(1,2,Nt),e.set(2,0,$t),e.set(2,1,Lt),e.set(2,2,Dt),e}mmulStrassen(s){s=_.checkMatrix(s);let e=this.clone(),t=e.rows,n=e.columns,i=s.rows,o=s.columns;n!==i&&console.warn(`Multiplying ${t} x ${n} and ${i} x ${o} matrix: dimensions do not match.`);function l(c,g,d){let w=c.rows,p=c.columns;if(w===g&&p===d)return c;{let P=V.zeros(g,d);return P=P.setSubMatrix(c,0,0),P}}let h=Math.max(t,i),a=Math.max(n,o);e=l(e,h,a),s=l(s,h,a);function u(c,g,d,w){if(d<=512||w<=512)return c.mmul(g);d%2===1&&w%2===1?(c=l(c,d+1,w+1),g=l(g,d+1,w+1)):d%2===1?(c=l(c,d+1,w),g=l(g,d+1,w)):w%2===1&&(c=l(c,d,w+1),g=l(g,d,w+1));let p=parseInt(c.rows/2,10),P=parseInt(c.columns/2,10),f=c.subMatrix(0,p-1,0,P-1),M=g.subMatrix(0,p-1,0,P-1),E=c.subMatrix(0,p-1,P,c.columns-1),R=g.subMatrix(0,p-1,P,g.columns-1),v=c.subMatrix(p,c.rows-1,0,P-1),L=g.subMatrix(p,g.rows-1,0,P-1),S=c.subMatrix(p,c.rows-1,P,c.columns-1),k=g.subMatrix(p,g.rows-1,P,g.columns-1),D=u(V.add(f,S),V.add(M,k),p,P),m=u(V.add(v,S),M,p,P),b=u(f,V.sub(R,k),p,P),j=u(S,V.sub(L,M),p,P),y=u(V.add(f,E),k,p,P),C=u(V.sub(v,f),V.add(M,R),p,P),F=u(V.sub(E,S),V.add(L,k),p,P),I=V.add(D,j);I.sub(y),I.add(F);let O=V.add(b,y),A=V.add(m,j),N=V.sub(D,m);N.add(b),N.add(C);let x=V.zeros(2*I.rows,2*I.columns);return x=x.setSubMatrix(I,0,0),x=x.setSubMatrix(O,I.rows,0),x=x.setSubMatrix(A,0,I.columns),x=x.setSubMatrix(N,I.rows,I.columns),x.subMatrix(0,d-1,0,w-1)}return u(e,s,h,a)}scaleRows(s={}){if(typeof s!="object")throw new TypeError("options must be an object");const{min:e=0,max:t=1}=s;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(t))throw new TypeError("max must be a number");if(e>=t)throw new RangeError("min must be smaller than max");let n=new _(this.rows,this.columns);for(let i=0;i<this.rows;i++){const o=this.getRow(i);o.length>0&&ke(o,{min:e,max:t,output:o}),n.setRow(i,o)}return n}scaleColumns(s={}){if(typeof s!="object")throw new TypeError("options must be an object");const{min:e=0,max:t=1}=s;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(t))throw new TypeError("max must be a number");if(e>=t)throw new RangeError("min must be smaller than max");let n=new _(this.rows,this.columns);for(let i=0;i<this.columns;i++){const o=this.getColumn(i);o.length&&ke(o,{min:e,max:t,output:o}),n.setColumn(i,o)}return n}flipRows(){const s=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let t=0;t<s;t++){let n=this.get(e,t),i=this.get(e,this.columns-1-t);this.set(e,t,i),this.set(e,this.columns-1-t,n)}return this}flipColumns(){const s=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let t=0;t<s;t++){let n=this.get(t,e),i=this.get(this.rows-1-t,e);this.set(t,e,i),this.set(this.rows-1-t,e,n)}return this}kroneckerProduct(s){s=_.checkMatrix(s);let e=this.rows,t=this.columns,n=s.rows,i=s.columns,o=new _(e*n,t*i);for(let l=0;l<e;l++)for(let h=0;h<t;h++)for(let a=0;a<n;a++)for(let u=0;u<i;u++)o.set(n*l+a,i*h+u,this.get(l,h)*s.get(a,u));return o}kroneckerSum(s){if(s=_.checkMatrix(s),!this.isSquare()||!s.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,t=s.rows,n=this.kroneckerProduct(_.eye(t,t)),i=_.eye(e,e).kroneckerProduct(s);return n.add(i)}transpose(){let s=new _(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)s.set(t,e,this.get(e,t));return s}sortRows(s=ve){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(s));return this}sortColumns(s=ve){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(s));return this}subMatrix(s,e,t,n){fe(this,s,e,t,n);let i=new _(e-s+1,n-t+1);for(let o=s;o<=e;o++)for(let l=t;l<=n;l++)i.set(o-s,l-t,this.get(o,l));return i}subMatrixRow(s,e,t){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)throw new RangeError("Argument out of range");let n=new _(s.length,t-e+1);for(let i=0;i<s.length;i++)for(let o=e;o<=t;o++){if(s[i]<0||s[i]>=this.rows)throw new RangeError(`Row index out of range: ${s[i]}`);n.set(i,o-e,this.get(s[i],o))}return n}subMatrixColumn(s,e,t){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)throw new RangeError("Argument out of range");let n=new _(t-e+1,s.length);for(let i=0;i<s.length;i++)for(let o=e;o<=t;o++){if(s[i]<0||s[i]>=this.columns)throw new RangeError(`Column index out of range: ${s[i]}`);n.set(o-e,i,this.get(o,s[i]))}return n}setSubMatrix(s,e,t){if(s=_.checkMatrix(s),s.isEmpty())return this;let n=e+s.rows-1,i=t+s.columns-1;fe(this,e,n,t,i);for(let o=0;o<s.rows;o++)for(let l=0;l<s.columns;l++)this.set(e+o,t+l,s.get(o,l));return this}selection(s,e){de(this,s),Me(this,e);let t=new _(s.length,e.length);for(let n=0;n<s.length;n++){let i=s[n];for(let o=0;o<e.length;o++){let l=e[o];t.set(n,o,this.get(i,l))}}return t}trace(){let s=Math.min(this.rows,this.columns),e=0;for(let t=0;t<s;t++)e+=this.get(t,t);return e}clone(){return this.constructor.copy(this,new _(this.rows,this.columns))}static copy(s,e){for(const[t,n,i]of s.entries())e.set(t,n,i);return e}sum(s){switch(s){case"row":return ds(this);case"column":return Ms(this);case void 0:return ys(this);default:throw new Error(`invalid option: ${s}`)}}product(s){switch(s){case"row":return Ps(this);case"column":return bs(this);case void 0:return Es(this);default:throw new Error(`invalid option: ${s}`)}}mean(s){const e=this.sum(s);switch(s){case"row":{for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e}case"column":{for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e}case void 0:return e/this.size;default:throw new Error(`invalid option: ${s}`)}}variance(s,e={}){if(typeof s=="object"&&(e=s,s=void 0),typeof e!="object")throw new TypeError("options must be an object");const{unbiased:t=!0,mean:n=this.mean(s)}=e;if(typeof t!="boolean")throw new TypeError("unbiased must be a boolean");switch(s){case"row":{if(!et.isAnyArray(n))throw new TypeError("mean must be an array");return _s(this,t,n)}case"column":{if(!et.isAnyArray(n))throw new TypeError("mean must be an array");return js(this,t,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return Ss(this,t,n)}default:throw new Error(`invalid option: ${s}`)}}standardDeviation(s,e){typeof s=="object"&&(e=s,s=void 0);const t=this.variance(s,e);if(s===void 0)return Math.sqrt(t);for(let n=0;n<t.length;n++)t[n]=Math.sqrt(t[n]);return t}center(s,e={}){if(typeof s=="object"&&(e=s,s=void 0),typeof e!="object")throw new TypeError("options must be an object");const{center:t=this.mean(s)}=e;switch(s){case"row":{if(!et.isAnyArray(t))throw new TypeError("center must be an array");return ks(this,t),this}case"column":{if(!et.isAnyArray(t))throw new TypeError("center must be an array");return Rs(this,t),this}case void 0:{if(typeof t!="number")throw new TypeError("center must be a number");return vs(this,t),this}default:throw new Error(`invalid option: ${s}`)}}scale(s,e={}){if(typeof s=="object"&&(e=s,s=void 0),typeof e!="object")throw new TypeError("options must be an object");let t=e.scale;switch(s){case"row":{if(t===void 0)t=Ts(this);else if(!et.isAnyArray(t))throw new TypeError("scale must be an array");return Is(this,t),this}case"column":{if(t===void 0)t=Cs(this);else if(!et.isAnyArray(t))throw new TypeError("scale must be an array");return qs(this,t),this}case void 0:{if(t===void 0)t=Fs(this);else if(typeof t!="number")throw new TypeError("scale must be a number");return As(this,t),this}default:throw new Error(`invalid option: ${s}`)}}toString(s){return $e(this,s)}[Symbol.iterator](){return this.entries()}*entries(){for(let s=0;s<this.rows;s++)for(let e=0;e<this.columns;e++)yield[s,e,this.get(s,e)]}*values(){for(let s=0;s<this.rows;s++)for(let e=0;e<this.columns;e++)yield this.get(s,e)}}V.prototype.klass="Matrix";typeof Symbol<"u"&&(V.prototype[Symbol.for("nodejs.util.inspect.custom")]=ms);function ve(r,s){return r-s}function xs(r){return r.every(s=>typeof s=="number")}V.random=V.rand;V.randomInt=V.randInt;V.diagonal=V.diag;V.prototype.diagonal=V.prototype.diag;V.identity=V.eye;V.prototype.negate=V.prototype.neg;V.prototype.tensorProduct=V.prototype.kroneckerProduct;var Ft,me,bt;let _=(bt=class extends V{constructor(e,t){super();ae(this,Ft);q(this,"data");if(bt.isMatrix(e))ue(this,Ft,me).call(this,e.rows,e.columns),bt.copy(e,this);else if(Number.isInteger(e)&&e>=0)ue(this,Ft,me).call(this,e,t);else if(et.isAnyArray(e)){const n=e;if(e=n.length,t=e?n[0].length:0,typeof t!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let i=0;i<e;i++){if(n[i].length!==t)throw new RangeError("Inconsistent array dimensions");if(!xs(n[i]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[i]))}this.rows=e,this.columns=t}else throw new TypeError("First argument must be a positive number or an array")}set(e,t,n){return this.data[e][t]=n,this}get(e,t){return this.data[e][t]}removeRow(e){return it(this,e),this.data.splice(e,1),this.rows-=1,this}addRow(e,t){return t===void 0&&(t=e,e=this.rows),it(this,e,!0),t=Float64Array.from(St(this,t)),this.data.splice(e,0,t),this.rows+=1,this}removeColumn(e){rt(this,e);for(let t=0;t<this.rows;t++){const n=new Float64Array(this.columns-1);for(let i=0;i<e;i++)n[i]=this.data[t][i];for(let i=e+1;i<this.columns;i++)n[i-1]=this.data[t][i];this.data[t]=n}return this.columns-=1,this}addColumn(e,t){typeof t>"u"&&(t=e,e=this.columns),rt(this,e,!0),t=kt(this,t);for(let n=0;n<this.rows;n++){const i=new Float64Array(this.columns+1);let o=0;for(;o<e;o++)i[o]=this.data[n][o];for(i[o++]=t[n];o<this.columns+1;o++)i[o]=this.data[n][o-1];this.data[n]=i}return this.columns+=1,this}},Ft=new WeakSet,me=function(e,t){if(this.data=[],Number.isInteger(t)&&t>=0)for(let n=0;n<e;n++)this.data.push(new Float64Array(t));else throw new TypeError("nColumns must be a positive integer");this.rows=e,this.columns=t},bt);ps(V,_);var H;const Jt=class Jt extends V{constructor(e){super();ae(this,H);if(_.isMatrix(e)){if(!e.isSymmetric())throw new TypeError("not symmetric data");zt(this,H,_.copy(e,new _(e.rows,e.rows)))}else if(Number.isInteger(e)&&e>=0)zt(this,H,new _(e,e));else if(zt(this,H,new _(e)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return ot(this,H).size}get rows(){return ot(this,H).rows}get columns(){return ot(this,H).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(e){return _.isMatrix(e)&&e.klassType==="SymmetricMatrix"}static zeros(e){return new this(e)}static ones(e){return new this(e).fill(1)}clone(){const e=new Jt(this.diagonalSize);for(const[t,n,i]of this.upperRightEntries())e.set(t,n,i);return e}toMatrix(){return new _(this)}get(e,t){return ot(this,H).get(e,t)}set(e,t,n){return ot(this,H).set(e,t,n),ot(this,H).set(t,e,n),this}removeCross(e){return ot(this,H).removeRow(e),ot(this,H).removeColumn(e),this}addCross(e,t){t===void 0&&(t=e,e=this.diagonalSize);const n=t.slice();return n.splice(e,1),ot(this,H).addRow(e,n),ot(this,H).addColumn(e,t),this}applyMask(e){if(e.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const t=[];for(const[n,i]of e.entries())i||t.push(n);t.reverse();for(const n of t)this.removeCross(n);return this}toCompact(){const{diagonalSize:e}=this,t=new Array(e*(e+1)/2);for(let n=0,i=0,o=0;o<t.length;o++)t[o]=this.get(i,n),++n>=e&&(n=++i);return t}static fromCompact(e){const t=e.length,n=(Math.sqrt(8*t+1)-1)/2;if(!Number.isInteger(n))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(e)}`);const i=new Jt(n);for(let o=0,l=0,h=0;h<t;h++)i.set(o,l,e[h]),++o>=n&&(o=++l);return i}*upperRightEntries(){for(let e=0,t=0;e<this.diagonalSize;void 0){const n=this.get(e,t);yield[e,t,n],++t>=this.diagonalSize&&(t=++e)}}*upperRightValues(){for(let e=0,t=0;e<this.diagonalSize;void 0)yield this.get(e,t),++t>=this.diagonalSize&&(t=++e)}};H=new WeakMap;let Pt=Jt;Pt.prototype.klassType="SymmetricMatrix";class ee extends Pt{static isDistanceMatrix(s){return Pt.isSymmetricMatrix(s)&&s.klassSubType==="DistanceMatrix"}constructor(s){if(super(s),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(s,e,t){return s===e&&(t=0),super.set(s,e,t)}addCross(s,e){return e===void 0&&(e=s,s=this.diagonalSize),e=e.slice(),e[s]=0,super.addCross(s,e)}toSymmetricMatrix(){return new Pt(this)}clone(){const s=new ee(this.diagonalSize);for(const[e,t,n]of this.upperRightEntries())e!==t&&s.set(e,t,n);return s}toCompact(){const{diagonalSize:s}=this,e=(s-1)*s/2,t=new Array(e);for(let n=1,i=0,o=0;o<t.length;o++)t[o]=this.get(i,n),++n>=s&&(n=++i+1);return t}static fromCompact(s){const e=s.length;if(e===0)return new this(0);const t=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(t))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(s)}`);const n=new this(t);for(let i=1,o=0,l=0;l<e;l++)n.set(i,o,s[l]),++i>=t&&(i=++o+1);return n}}ee.prototype.klassSubType="DistanceMatrix";class ft extends V{constructor(s,e,t){super(),this.matrix=s,this.rows=e,this.columns=t}}class Vs extends ft{constructor(s,e){rt(s,e),super(s,s.rows,1),this.column=e}set(s,e,t){return this.matrix.set(s,this.column,t),this}get(s){return this.matrix.get(s,this.column)}}class Ns extends ft{constructor(s,e){Me(s,e),super(s,s.rows,e.length),this.columnIndices=e}set(s,e,t){return this.matrix.set(s,this.columnIndices[e],t),this}get(s,e){return this.matrix.get(s,this.columnIndices[e])}}class $s extends ft{constructor(s){super(s,s.rows,s.columns)}set(s,e,t){return this.matrix.set(s,this.columns-e-1,t),this}get(s,e){return this.matrix.get(s,this.columns-e-1)}}class Ls extends ft{constructor(s){super(s,s.rows,s.columns)}set(s,e,t){return this.matrix.set(this.rows-s-1,e,t),this}get(s,e){return this.matrix.get(this.rows-s-1,e)}}class Ds extends ft{constructor(s,e){it(s,e),super(s,1,s.columns),this.row=e}set(s,e,t){return this.matrix.set(this.row,e,t),this}get(s,e){return this.matrix.get(this.row,e)}}class zs extends ft{constructor(s,e){de(s,e),super(s,e.length,s.columns),this.rowIndices=e}set(s,e,t){return this.matrix.set(this.rowIndices[s],e,t),this}get(s,e){return this.matrix.get(this.rowIndices[s],e)}}class Qt extends ft{constructor(s,e,t){de(s,e),Me(s,t),super(s,e.length,t.length),this.rowIndices=e,this.columnIndices=t}set(s,e,t){return this.matrix.set(this.rowIndices[s],this.columnIndices[e],t),this}get(s,e){return this.matrix.get(this.rowIndices[s],this.columnIndices[e])}}class Bs extends ft{constructor(s,e,t,n,i){fe(s,e,t,n,i),super(s,t-e+1,i-n+1),this.startRow=e,this.startColumn=n}set(s,e,t){return this.matrix.set(this.startRow+s,this.startColumn+e,t),this}get(s,e){return this.matrix.get(this.startRow+s,this.startColumn+e)}}class Os extends ft{constructor(s){super(s,s.columns,s.rows)}set(s,e,t){return this.matrix.set(e,s,t),this}get(s,e){return this.matrix.get(e,s)}}class Le extends V{constructor(s,e={}){const{rows:t=1}=e;if(s.length%t!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=t,this.columns=s.length/t,this.data=s}set(s,e,t){let n=this._calculateIndex(s,e);return this.data[n]=t,this}get(s,e){let t=this._calculateIndex(s,e);return this.data[t]}_calculateIndex(s,e){return s*this.columns+e}}class nt extends V{constructor(s){super(),this.data=s,this.rows=s.length,this.columns=s[0].length}set(s,e,t){return this.data[s][e]=t,this}get(s,e){return this.data[s][e]}}function Us(r,s){if(et.isAnyArray(r))return r[0]&&et.isAnyArray(r[0])?new nt(r):new Le(r,s);throw new Error("the argument is not an array")}class se{constructor(s){s=nt.checkMatrix(s);let e=s.clone(),t=e.rows,n=e.columns,i=new Float64Array(t),o=1,l,h,a,u,c,g,d,w,p;for(l=0;l<t;l++)i[l]=l;for(w=new Float64Array(t),h=0;h<n;h++){for(l=0;l<t;l++)w[l]=e.get(l,h);for(l=0;l<t;l++){for(p=Math.min(l,h),c=0,a=0;a<p;a++)c+=e.get(l,a)*w[a];w[l]-=c,e.set(l,h,w[l])}for(u=h,l=h+1;l<t;l++)Math.abs(w[l])>Math.abs(w[u])&&(u=l);if(u!==h){for(a=0;a<n;a++)g=e.get(u,a),e.set(u,a,e.get(h,a)),e.set(h,a,g);d=i[u],i[u]=i[h],i[h]=d,o=-o}if(h<t&&e.get(h,h)!==0)for(l=h+1;l<t;l++)e.set(l,h,e.get(l,h)/e.get(h,h))}this.LU=e,this.pivotVector=i,this.pivotSign=o}isSingular(){let s=this.LU,e=s.columns;for(let t=0;t<e;t++)if(s.get(t,t)===0)return!0;return!1}solve(s){s=_.checkMatrix(s);let e=this.LU;if(e.rows!==s.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let n=s.columns,i=s.subMatrixRow(this.pivotVector,0,n-1),o=e.columns,l,h,a;for(a=0;a<o;a++)for(l=a+1;l<o;l++)for(h=0;h<n;h++)i.set(l,h,i.get(l,h)-i.get(a,h)*e.get(l,a));for(a=o-1;a>=0;a--){for(h=0;h<n;h++)i.set(a,h,i.get(a,h)/e.get(a,a));for(l=0;l<a;l++)for(h=0;h<n;h++)i.set(l,h,i.get(l,h)-i.get(a,h)*e.get(l,a))}return i}get determinant(){let s=this.LU;if(!s.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,t=s.columns;for(let n=0;n<t;n++)e*=s.get(n,n);return e}get lowerTriangularMatrix(){let s=this.LU,e=s.rows,t=s.columns,n=new _(e,t);for(let i=0;i<e;i++)for(let o=0;o<t;o++)i>o?n.set(i,o,s.get(i,o)):i===o?n.set(i,o,1):n.set(i,o,0);return n}get upperTriangularMatrix(){let s=this.LU,e=s.rows,t=s.columns,n=new _(e,t);for(let i=0;i<e;i++)for(let o=0;o<t;o++)i<=o?n.set(i,o,s.get(i,o)):n.set(i,o,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function ut(r,s){let e=0;return Math.abs(r)>Math.abs(s)?(e=s/r,Math.abs(r)*Math.sqrt(1+e*e)):s!==0?(e=r/s,Math.abs(s)*Math.sqrt(1+e*e)):0}class ye{constructor(s){s=nt.checkMatrix(s);let e=s.clone(),t=s.rows,n=s.columns,i=new Float64Array(n),o,l,h,a;for(h=0;h<n;h++){let u=0;for(o=h;o<t;o++)u=ut(u,e.get(o,h));if(u!==0){for(e.get(h,h)<0&&(u=-u),o=h;o<t;o++)e.set(o,h,e.get(o,h)/u);for(e.set(h,h,e.get(h,h)+1),l=h+1;l<n;l++){for(a=0,o=h;o<t;o++)a+=e.get(o,h)*e.get(o,l);for(a=-a/e.get(h,h),o=h;o<t;o++)e.set(o,l,e.get(o,l)+a*e.get(o,h))}}i[h]=-u}this.QR=e,this.Rdiag=i}solve(s){s=_.checkMatrix(s);let e=this.QR,t=e.rows;if(s.rows!==t)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n=s.columns,i=s.clone(),o=e.columns,l,h,a,u;for(a=0;a<o;a++)for(h=0;h<n;h++){for(u=0,l=a;l<t;l++)u+=e.get(l,a)*i.get(l,h);for(u=-u/e.get(a,a),l=a;l<t;l++)i.set(l,h,i.get(l,h)+u*e.get(l,a))}for(a=o-1;a>=0;a--){for(h=0;h<n;h++)i.set(a,h,i.get(a,h)/this.Rdiag[a]);for(l=0;l<a;l++)for(h=0;h<n;h++)i.set(l,h,i.get(l,h)-i.get(a,h)*e.get(l,a))}return i.subMatrix(0,o-1,0,n-1)}isFullRank(){let s=this.QR.columns;for(let e=0;e<s;e++)if(this.Rdiag[e]===0)return!1;return!0}get upperTriangularMatrix(){let s=this.QR,e=s.columns,t=new _(e,e),n,i;for(n=0;n<e;n++)for(i=0;i<e;i++)n<i?t.set(n,i,s.get(n,i)):n===i?t.set(n,i,this.Rdiag[n]):t.set(n,i,0);return t}get orthogonalMatrix(){let s=this.QR,e=s.rows,t=s.columns,n=new _(e,t),i,o,l,h;for(l=t-1;l>=0;l--){for(i=0;i<e;i++)n.set(i,l,0);for(n.set(l,l,1),o=l;o<t;o++)if(s.get(l,l)!==0){for(h=0,i=l;i<e;i++)h+=s.get(i,l)*n.get(i,o);for(h=-h/s.get(l,l),i=l;i<e;i++)n.set(i,o,n.get(i,o)+h*s.get(i,l))}}return n}}class It{constructor(s,e={}){if(s=nt.checkMatrix(s),s.isEmpty())throw new Error("Matrix must be non-empty");let t=s.rows,n=s.columns;const{computeLeftSingularVectors:i=!0,computeRightSingularVectors:o=!0,autoTranspose:l=!1}=e;let h=!!i,a=!!o,u=!1,c;if(t<n)if(!l)c=s.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{c=s.transpose(),t=c.rows,n=c.columns,u=!0;let m=h;h=a,a=m}else c=s.clone();let g=Math.min(t,n),d=Math.min(t+1,n),w=new Float64Array(d),p=new _(t,g),P=new _(n,n),f=new Float64Array(n),M=new Float64Array(t),E=new Float64Array(d);for(let m=0;m<d;m++)E[m]=m;let R=Math.min(t-1,n),v=Math.max(0,Math.min(n-2,t)),L=Math.max(R,v);for(let m=0;m<L;m++){if(m<R){w[m]=0;for(let b=m;b<t;b++)w[m]=ut(w[m],c.get(b,m));if(w[m]!==0){c.get(m,m)<0&&(w[m]=-w[m]);for(let b=m;b<t;b++)c.set(b,m,c.get(b,m)/w[m]);c.set(m,m,c.get(m,m)+1)}w[m]=-w[m]}for(let b=m+1;b<n;b++){if(m<R&&w[m]!==0){let j=0;for(let y=m;y<t;y++)j+=c.get(y,m)*c.get(y,b);j=-j/c.get(m,m);for(let y=m;y<t;y++)c.set(y,b,c.get(y,b)+j*c.get(y,m))}f[b]=c.get(m,b)}if(h&&m<R)for(let b=m;b<t;b++)p.set(b,m,c.get(b,m));if(m<v){f[m]=0;for(let b=m+1;b<n;b++)f[m]=ut(f[m],f[b]);if(f[m]!==0){f[m+1]<0&&(f[m]=0-f[m]);for(let b=m+1;b<n;b++)f[b]/=f[m];f[m+1]+=1}if(f[m]=-f[m],m+1<t&&f[m]!==0){for(let b=m+1;b<t;b++)M[b]=0;for(let b=m+1;b<t;b++)for(let j=m+1;j<n;j++)M[b]+=f[j]*c.get(b,j);for(let b=m+1;b<n;b++){let j=-f[b]/f[m+1];for(let y=m+1;y<t;y++)c.set(y,b,c.get(y,b)+j*M[y])}}if(a)for(let b=m+1;b<n;b++)P.set(b,m,f[b])}}let S=Math.min(n,t+1);if(R<n&&(w[R]=c.get(R,R)),t<S&&(w[S-1]=0),v+1<S&&(f[v]=c.get(v,S-1)),f[S-1]=0,h){for(let m=R;m<g;m++){for(let b=0;b<t;b++)p.set(b,m,0);p.set(m,m,1)}for(let m=R-1;m>=0;m--)if(w[m]!==0){for(let b=m+1;b<g;b++){let j=0;for(let y=m;y<t;y++)j+=p.get(y,m)*p.get(y,b);j=-j/p.get(m,m);for(let y=m;y<t;y++)p.set(y,b,p.get(y,b)+j*p.get(y,m))}for(let b=m;b<t;b++)p.set(b,m,-p.get(b,m));p.set(m,m,1+p.get(m,m));for(let b=0;b<m-1;b++)p.set(b,m,0)}else{for(let b=0;b<t;b++)p.set(b,m,0);p.set(m,m,1)}}if(a)for(let m=n-1;m>=0;m--){if(m<v&&f[m]!==0)for(let b=m+1;b<n;b++){let j=0;for(let y=m+1;y<n;y++)j+=P.get(y,m)*P.get(y,b);j=-j/P.get(m+1,m);for(let y=m+1;y<n;y++)P.set(y,b,P.get(y,b)+j*P.get(y,m))}for(let b=0;b<n;b++)P.set(b,m,0);P.set(m,m,1)}let k=S-1,D=Number.EPSILON;for(;S>0;){let m,b;for(m=S-2;m>=-1&&m!==-1;m--){const j=Number.MIN_VALUE+D*Math.abs(w[m]+Math.abs(w[m+1]));if(Math.abs(f[m])<=j||Number.isNaN(f[m])){f[m]=0;break}}if(m===S-2)b=4;else{let j;for(j=S-1;j>=m&&j!==m;j--){let y=(j!==S?Math.abs(f[j]):0)+(j!==m+1?Math.abs(f[j-1]):0);if(Math.abs(w[j])<=D*y){w[j]=0;break}}j===m?b=3:j===S-1?b=1:(b=2,m=j)}switch(m++,b){case 1:{let j=f[S-2];f[S-2]=0;for(let y=S-2;y>=m;y--){let C=ut(w[y],j),F=w[y]/C,I=j/C;if(w[y]=C,y!==m&&(j=-I*f[y-1],f[y-1]=F*f[y-1]),a)for(let O=0;O<n;O++)C=F*P.get(O,y)+I*P.get(O,S-1),P.set(O,S-1,-I*P.get(O,y)+F*P.get(O,S-1)),P.set(O,y,C)}break}case 2:{let j=f[m-1];f[m-1]=0;for(let y=m;y<S;y++){let C=ut(w[y],j),F=w[y]/C,I=j/C;if(w[y]=C,j=-I*f[y],f[y]=F*f[y],h)for(let O=0;O<t;O++)C=F*p.get(O,y)+I*p.get(O,m-1),p.set(O,m-1,-I*p.get(O,y)+F*p.get(O,m-1)),p.set(O,y,C)}break}case 3:{const j=Math.max(Math.abs(w[S-1]),Math.abs(w[S-2]),Math.abs(f[S-2]),Math.abs(w[m]),Math.abs(f[m])),y=w[S-1]/j,C=w[S-2]/j,F=f[S-2]/j,I=w[m]/j,O=f[m]/j,A=((C+y)*(C-y)+F*F)/2,N=y*F*(y*F);let x=0;(A!==0||N!==0)&&(A<0?x=0-Math.sqrt(A*A+N):x=Math.sqrt(A*A+N),x=N/(A+x));let B=(I+y)*(I-y)+x,U=I*O;for(let T=m;T<S-1;T++){let z=ut(B,U);z===0&&(z=Number.MIN_VALUE);let Q=B/z,G=U/z;if(T!==m&&(f[T-1]=z),B=Q*w[T]+G*f[T],f[T]=Q*f[T]-G*w[T],U=G*w[T+1],w[T+1]=Q*w[T+1],a)for(let W=0;W<n;W++)z=Q*P.get(W,T)+G*P.get(W,T+1),P.set(W,T+1,-G*P.get(W,T)+Q*P.get(W,T+1)),P.set(W,T,z);if(z=ut(B,U),z===0&&(z=Number.MIN_VALUE),Q=B/z,G=U/z,w[T]=z,B=Q*f[T]+G*w[T+1],w[T+1]=-G*f[T]+Q*w[T+1],U=G*f[T+1],f[T+1]=Q*f[T+1],h&&T<t-1)for(let W=0;W<t;W++)z=Q*p.get(W,T)+G*p.get(W,T+1),p.set(W,T+1,-G*p.get(W,T)+Q*p.get(W,T+1)),p.set(W,T,z)}f[S-2]=B;break}case 4:{if(w[m]<=0&&(w[m]=w[m]<0?-w[m]:0,a))for(let j=0;j<=k;j++)P.set(j,m,-P.get(j,m));for(;m<k&&!(w[m]>=w[m+1]);){let j=w[m];if(w[m]=w[m+1],w[m+1]=j,a&&m<n-1)for(let y=0;y<n;y++)j=P.get(y,m+1),P.set(y,m+1,P.get(y,m)),P.set(y,m,j);if(h&&m<t-1)for(let y=0;y<t;y++)j=p.get(y,m+1),p.set(y,m+1,p.get(y,m)),p.set(y,m,j);m++}S--;break}}}if(u){let m=P;P=p,p=m}this.m=t,this.n=n,this.s=w,this.U=p,this.V=P}solve(s){let e=s,t=this.threshold,n=this.s.length,i=_.zeros(n,n);for(let g=0;g<n;g++)Math.abs(this.s[g])<=t?i.set(g,g,0):i.set(g,g,1/this.s[g]);let o=this.U,l=this.rightSingularVectors,h=l.mmul(i),a=l.rows,u=o.rows,c=_.zeros(a,u);for(let g=0;g<a;g++)for(let d=0;d<u;d++){let w=0;for(let p=0;p<n;p++)w+=h.get(g,p)*o.get(d,p);c.set(g,d,w)}return c.mmul(e)}solveForDiagonal(s){return this.solve(_.diag(s))}inverse(){let s=this.V,e=this.threshold,t=s.rows,n=s.columns,i=new _(t,this.s.length);for(let u=0;u<t;u++)for(let c=0;c<n;c++)Math.abs(this.s[c])>e&&i.set(u,c,s.get(u,c)/this.s[c]);let o=this.U,l=o.rows,h=o.columns,a=new _(t,l);for(let u=0;u<t;u++)for(let c=0;c<l;c++){let g=0;for(let d=0;d<h;d++)g+=i.get(u,d)*o.get(c,d);a.set(u,c,g)}return a}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let s=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,t=this.s;for(let n=0,i=t.length;n<i;n++)t[n]>s&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return _.diag(this.s)}}function Ys(r,s=!1){return r=nt.checkMatrix(r),s?new It(r).inverse():De(r,_.eye(r.rows))}function De(r,s,e=!1){return r=nt.checkMatrix(r),s=nt.checkMatrix(s),e?new It(r).solve(s):r.isSquare()?new se(r).solve(s):new ye(r).solve(s)}function Xt(r){if(r=_.checkMatrix(r),r.isSquare()){if(r.columns===0)return 1;let s,e,t,n;if(r.columns===2)return s=r.get(0,0),e=r.get(0,1),t=r.get(1,0),n=r.get(1,1),s*n-e*t;if(r.columns===3){let i,o,l;return i=new Qt(r,[1,2],[1,2]),o=new Qt(r,[1,2],[0,2]),l=new Qt(r,[1,2],[0,1]),s=r.get(0,0),e=r.get(0,1),t=r.get(0,2),s*Xt(i)-e*Xt(o)+t*Xt(l)}else return new se(r).determinant}else throw Error("determinant can only be calculated for a square matrix")}function Ws(r,s){let e=[];for(let t=0;t<r;t++)t!==s&&e.push(t);return e}function Gs(r,s,e,t=1e-9,n=1e-9){if(r>n)return new Array(s.rows+1).fill(0);{let i=s.addRow(e,[0]);for(let o=0;o<i.rows;o++)Math.abs(i.get(o,0))<t&&i.set(o,0,0);return i.to1DArray()}}function Qs(r,s={}){const{thresholdValue:e=1e-9,thresholdError:t=1e-9}=s;r=_.checkMatrix(r);let n=r.rows,i=new _(n,n);for(let o=0;o<n;o++){let l=_.columnVector(r.getRow(o)),h=r.subMatrixRow(Ws(n,o)).transpose(),u=new It(h).solve(l),c=_.sub(l,h.mmul(u)).abs().max();i.setRow(o,Gs(c,u,o,e,t))}return i}function Xs(r,s=Number.EPSILON){if(r=_.checkMatrix(r),r.isEmpty())return r.transpose();let e=new It(r,{autoTranspose:!0}),t=e.leftSingularVectors,n=e.rightSingularVectors,i=e.diagonal;for(let o=0;o<i.length;o++)Math.abs(i[o])>s?i[o]=1/i[o]:i[o]=0;return n.mmul(_.diag(i).mmul(t.transpose()))}function Zs(r,s=r,e={}){r=new _(r);let t=!1;if(typeof s=="object"&&!_.isMatrix(s)&&!et.isAnyArray(s)?(e=s,s=r,t=!0):s=new _(s),r.rows!==s.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=e;n&&(r=r.center("column"),t||(s=s.center("column")));const i=r.transpose().mmul(s);for(let o=0;o<i.rows;o++)for(let l=0;l<i.columns;l++)i.set(o,l,i.get(o,l)*(1/(r.rows-1)));return i}function Js(r,s=r,e={}){r=new _(r);let t=!1;if(typeof s=="object"&&!_.isMatrix(s)&&!et.isAnyArray(s)?(e=s,s=r,t=!0):s=new _(s),r.rows!==s.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:i=!0}=e;n&&(r.center("column"),t||s.center("column")),i&&(r.scale("column"),t||s.scale("column"));const o=r.standardDeviation("column",{unbiased:!0}),l=t?o:s.standardDeviation("column",{unbiased:!0}),h=r.transpose().mmul(s);for(let a=0;a<h.rows;a++)for(let u=0;u<h.columns;u++)h.set(a,u,h.get(a,u)*(1/(o[a]*l[u]))*(1/(r.rows-1)));return h}let ze=class{constructor(s,e={}){const{assumeSymmetric:t=!1}=e;if(s=nt.checkMatrix(s),!s.isSquare())throw new Error("Matrix is not a square matrix");if(s.isEmpty())throw new Error("Matrix must be non-empty");let n=s.columns,i=new _(n,n),o=new Float64Array(n),l=new Float64Array(n),h=s,a,u,c=!1;if(t?c=!0:c=s.isSymmetric(),c){for(a=0;a<n;a++)for(u=0;u<n;u++)i.set(a,u,h.get(a,u));Ks(n,l,o,i),Hs(n,l,o,i)}else{let g=new _(n,n),d=new Float64Array(n);for(u=0;u<n;u++)for(a=0;a<n;a++)g.set(a,u,h.get(a,u));tn(n,g,d,i),en(n,l,o,i,g)}this.n=n,this.e=l,this.d=o,this.V=i}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let s=this.n,e=this.e,t=this.d,n=new _(s,s),i,o;for(i=0;i<s;i++){for(o=0;o<s;o++)n.set(i,o,0);n.set(i,i,t[i]),e[i]>0?n.set(i,i+1,e[i]):e[i]<0&&n.set(i,i-1,e[i])}return n}};function Ks(r,s,e,t){let n,i,o,l,h,a,u,c;for(h=0;h<r;h++)e[h]=t.get(r-1,h);for(l=r-1;l>0;l--){for(c=0,o=0,a=0;a<l;a++)c=c+Math.abs(e[a]);if(c===0)for(s[l]=e[l-1],h=0;h<l;h++)e[h]=t.get(l-1,h),t.set(l,h,0),t.set(h,l,0);else{for(a=0;a<l;a++)e[a]/=c,o+=e[a]*e[a];for(n=e[l-1],i=Math.sqrt(o),n>0&&(i=-i),s[l]=c*i,o=o-n*i,e[l-1]=n-i,h=0;h<l;h++)s[h]=0;for(h=0;h<l;h++){for(n=e[h],t.set(h,l,n),i=s[h]+t.get(h,h)*n,a=h+1;a<=l-1;a++)i+=t.get(a,h)*e[a],s[a]+=t.get(a,h)*n;s[h]=i}for(n=0,h=0;h<l;h++)s[h]/=o,n+=s[h]*e[h];for(u=n/(o+o),h=0;h<l;h++)s[h]-=u*e[h];for(h=0;h<l;h++){for(n=e[h],i=s[h],a=h;a<=l-1;a++)t.set(a,h,t.get(a,h)-(n*s[a]+i*e[a]));e[h]=t.get(l-1,h),t.set(l,h,0)}}e[l]=o}for(l=0;l<r-1;l++){if(t.set(r-1,l,t.get(l,l)),t.set(l,l,1),o=e[l+1],o!==0){for(a=0;a<=l;a++)e[a]=t.get(a,l+1)/o;for(h=0;h<=l;h++){for(i=0,a=0;a<=l;a++)i+=t.get(a,l+1)*t.get(a,h);for(a=0;a<=l;a++)t.set(a,h,t.get(a,h)-i*e[a])}}for(a=0;a<=l;a++)t.set(a,l+1,0)}for(h=0;h<r;h++)e[h]=t.get(r-1,h),t.set(r-1,h,0);t.set(r-1,r-1,1),s[0]=0}function Hs(r,s,e,t){let n,i,o,l,h,a,u,c,g,d,w,p,P,f,M,E;for(o=1;o<r;o++)s[o-1]=s[o];s[r-1]=0;let R=0,v=0,L=Number.EPSILON;for(a=0;a<r;a++){for(v=Math.max(v,Math.abs(e[a])+Math.abs(s[a])),u=a;u<r&&!(Math.abs(s[u])<=L*v);)u++;if(u>a)do{for(n=e[a],c=(e[a+1]-n)/(2*s[a]),g=ut(c,1),c<0&&(g=-g),e[a]=s[a]/(c+g),e[a+1]=s[a]*(c+g),d=e[a+1],i=n-e[a],o=a+2;o<r;o++)e[o]-=i;for(R=R+i,c=e[u],w=1,p=w,P=w,f=s[a+1],M=0,E=0,o=u-1;o>=a;o--)for(P=p,p=w,E=M,n=w*s[o],i=w*c,g=ut(c,s[o]),s[o+1]=M*g,M=s[o]/g,w=c/g,c=w*e[o]-M*n,e[o+1]=i+M*(w*n+M*e[o]),h=0;h<r;h++)i=t.get(h,o+1),t.set(h,o+1,M*t.get(h,o)+w*i),t.set(h,o,w*t.get(h,o)-M*i);c=-M*E*P*f*s[a]/d,s[a]=M*c,e[a]=w*c}while(Math.abs(s[a])>L*v);e[a]=e[a]+R,s[a]=0}for(o=0;o<r-1;o++){for(h=o,c=e[o],l=o+1;l<r;l++)e[l]<c&&(h=l,c=e[l]);if(h!==o)for(e[h]=e[o],e[o]=c,l=0;l<r;l++)c=t.get(l,o),t.set(l,o,t.get(l,h)),t.set(l,h,c)}}function tn(r,s,e,t){let n=0,i=r-1,o,l,h,a,u,c,g;for(c=n+1;c<=i-1;c++){for(g=0,a=c;a<=i;a++)g=g+Math.abs(s.get(a,c-1));if(g!==0){for(h=0,a=i;a>=c;a--)e[a]=s.get(a,c-1)/g,h+=e[a]*e[a];for(l=Math.sqrt(h),e[c]>0&&(l=-l),h=h-e[c]*l,e[c]=e[c]-l,u=c;u<r;u++){for(o=0,a=i;a>=c;a--)o+=e[a]*s.get(a,u);for(o=o/h,a=c;a<=i;a++)s.set(a,u,s.get(a,u)-o*e[a])}for(a=0;a<=i;a++){for(o=0,u=i;u>=c;u--)o+=e[u]*s.get(a,u);for(o=o/h,u=c;u<=i;u++)s.set(a,u,s.get(a,u)-o*e[u])}e[c]=g*e[c],s.set(c,c-1,g*l)}}for(a=0;a<r;a++)for(u=0;u<r;u++)t.set(a,u,a===u?1:0);for(c=i-1;c>=n+1;c--)if(s.get(c,c-1)!==0){for(a=c+1;a<=i;a++)e[a]=s.get(a,c-1);for(u=c;u<=i;u++){for(l=0,a=c;a<=i;a++)l+=e[a]*t.get(a,u);for(l=l/e[c]/s.get(c,c-1),a=c;a<=i;a++)t.set(a,u,t.get(a,u)+l*e[a])}}}function en(r,s,e,t,n){let i=r-1,o=0,l=r-1,h=Number.EPSILON,a=0,u=0,c=0,g=0,d=0,w=0,p=0,P=0,f,M,E,R,v,L,S,k,D,m,b,j,y,C,F;for(f=0;f<r;f++)for((f<o||f>l)&&(e[f]=n.get(f,f),s[f]=0),M=Math.max(f-1,0);M<r;M++)u=u+Math.abs(n.get(f,M));for(;i>=o;){for(R=i;R>o&&(w=Math.abs(n.get(R-1,R-1))+Math.abs(n.get(R,R)),w===0&&(w=u),!(Math.abs(n.get(R,R-1))<h*w));)R--;if(R===i)n.set(i,i,n.get(i,i)+a),e[i]=n.get(i,i),s[i]=0,i--,P=0;else if(R===i-1){if(S=n.get(i,i-1)*n.get(i-1,i),c=(n.get(i-1,i-1)-n.get(i,i))/2,g=c*c+S,p=Math.sqrt(Math.abs(g)),n.set(i,i,n.get(i,i)+a),n.set(i-1,i-1,n.get(i-1,i-1)+a),k=n.get(i,i),g>=0){for(p=c>=0?c+p:c-p,e[i-1]=k+p,e[i]=e[i-1],p!==0&&(e[i]=k-S/p),s[i-1]=0,s[i]=0,k=n.get(i,i-1),w=Math.abs(k)+Math.abs(p),c=k/w,g=p/w,d=Math.sqrt(c*c+g*g),c=c/d,g=g/d,M=i-1;M<r;M++)p=n.get(i-1,M),n.set(i-1,M,g*p+c*n.get(i,M)),n.set(i,M,g*n.get(i,M)-c*p);for(f=0;f<=i;f++)p=n.get(f,i-1),n.set(f,i-1,g*p+c*n.get(f,i)),n.set(f,i,g*n.get(f,i)-c*p);for(f=o;f<=l;f++)p=t.get(f,i-1),t.set(f,i-1,g*p+c*t.get(f,i)),t.set(f,i,g*t.get(f,i)-c*p)}else e[i-1]=k+c,e[i]=k+c,s[i-1]=p,s[i]=-p;i=i-2,P=0}else{if(k=n.get(i,i),D=0,S=0,R<i&&(D=n.get(i-1,i-1),S=n.get(i,i-1)*n.get(i-1,i)),P===10){for(a+=k,f=o;f<=i;f++)n.set(f,f,n.get(f,f)-k);w=Math.abs(n.get(i,i-1))+Math.abs(n.get(i-1,i-2)),k=D=.75*w,S=-.4375*w*w}if(P===30&&(w=(D-k)/2,w=w*w+S,w>0)){for(w=Math.sqrt(w),D<k&&(w=-w),w=k-S/((D-k)/2+w),f=o;f<=i;f++)n.set(f,f,n.get(f,f)-w);a+=w,k=D=S=.964}for(P=P+1,v=i-2;v>=R&&(p=n.get(v,v),d=k-p,w=D-p,c=(d*w-S)/n.get(v+1,v)+n.get(v,v+1),g=n.get(v+1,v+1)-p-d-w,d=n.get(v+2,v+1),w=Math.abs(c)+Math.abs(g)+Math.abs(d),c=c/w,g=g/w,d=d/w,!(v===R||Math.abs(n.get(v,v-1))*(Math.abs(g)+Math.abs(d))<h*(Math.abs(c)*(Math.abs(n.get(v-1,v-1))+Math.abs(p)+Math.abs(n.get(v+1,v+1))))));)v--;for(f=v+2;f<=i;f++)n.set(f,f-2,0),f>v+2&&n.set(f,f-3,0);for(E=v;E<=i-1&&(C=E!==i-1,E!==v&&(c=n.get(E,E-1),g=n.get(E+1,E-1),d=C?n.get(E+2,E-1):0,k=Math.abs(c)+Math.abs(g)+Math.abs(d),k!==0&&(c=c/k,g=g/k,d=d/k)),k!==0);E++)if(w=Math.sqrt(c*c+g*g+d*d),c<0&&(w=-w),w!==0){for(E!==v?n.set(E,E-1,-w*k):R!==v&&n.set(E,E-1,-n.get(E,E-1)),c=c+w,k=c/w,D=g/w,p=d/w,g=g/c,d=d/c,M=E;M<r;M++)c=n.get(E,M)+g*n.get(E+1,M),C&&(c=c+d*n.get(E+2,M),n.set(E+2,M,n.get(E+2,M)-c*p)),n.set(E,M,n.get(E,M)-c*k),n.set(E+1,M,n.get(E+1,M)-c*D);for(f=0;f<=Math.min(i,E+3);f++)c=k*n.get(f,E)+D*n.get(f,E+1),C&&(c=c+p*n.get(f,E+2),n.set(f,E+2,n.get(f,E+2)-c*d)),n.set(f,E,n.get(f,E)-c),n.set(f,E+1,n.get(f,E+1)-c*g);for(f=o;f<=l;f++)c=k*t.get(f,E)+D*t.get(f,E+1),C&&(c=c+p*t.get(f,E+2),t.set(f,E+2,t.get(f,E+2)-c*d)),t.set(f,E,t.get(f,E)-c),t.set(f,E+1,t.get(f,E+1)-c*g)}}}if(u!==0){for(i=r-1;i>=0;i--)if(c=e[i],g=s[i],g===0)for(R=i,n.set(i,i,1),f=i-1;f>=0;f--){for(S=n.get(f,f)-c,d=0,M=R;M<=i;M++)d=d+n.get(f,M)*n.get(M,i);if(s[f]<0)p=S,w=d;else if(R=f,s[f]===0?n.set(f,i,S!==0?-d/S:-d/(h*u)):(k=n.get(f,f+1),D=n.get(f+1,f),g=(e[f]-c)*(e[f]-c)+s[f]*s[f],L=(k*w-p*d)/g,n.set(f,i,L),n.set(f+1,i,Math.abs(k)>Math.abs(p)?(-d-S*L)/k:(-w-D*L)/p)),L=Math.abs(n.get(f,i)),h*L*L>1)for(M=f;M<=i;M++)n.set(M,i,n.get(M,i)/L)}else if(g<0)for(R=i-1,Math.abs(n.get(i,i-1))>Math.abs(n.get(i-1,i))?(n.set(i-1,i-1,g/n.get(i,i-1)),n.set(i-1,i,-(n.get(i,i)-c)/n.get(i,i-1))):(F=Gt(0,-n.get(i-1,i),n.get(i-1,i-1)-c,g),n.set(i-1,i-1,F[0]),n.set(i-1,i,F[1])),n.set(i,i-1,0),n.set(i,i,1),f=i-2;f>=0;f--){for(m=0,b=0,M=R;M<=i;M++)m=m+n.get(f,M)*n.get(M,i-1),b=b+n.get(f,M)*n.get(M,i);if(S=n.get(f,f)-c,s[f]<0)p=S,d=m,w=b;else if(R=f,s[f]===0?(F=Gt(-m,-b,S,g),n.set(f,i-1,F[0]),n.set(f,i,F[1])):(k=n.get(f,f+1),D=n.get(f+1,f),j=(e[f]-c)*(e[f]-c)+s[f]*s[f]-g*g,y=(e[f]-c)*2*g,j===0&&y===0&&(j=h*u*(Math.abs(S)+Math.abs(g)+Math.abs(k)+Math.abs(D)+Math.abs(p))),F=Gt(k*d-p*m+g*b,k*w-p*b-g*m,j,y),n.set(f,i-1,F[0]),n.set(f,i,F[1]),Math.abs(k)>Math.abs(p)+Math.abs(g)?(n.set(f+1,i-1,(-m-S*n.get(f,i-1)+g*n.get(f,i))/k),n.set(f+1,i,(-b-S*n.get(f,i)-g*n.get(f,i-1))/k)):(F=Gt(-d-D*n.get(f,i-1),-w-D*n.get(f,i),p,g),n.set(f+1,i-1,F[0]),n.set(f+1,i,F[1]))),L=Math.max(Math.abs(n.get(f,i-1)),Math.abs(n.get(f,i))),h*L*L>1)for(M=f;M<=i;M++)n.set(M,i-1,n.get(M,i-1)/L),n.set(M,i,n.get(M,i)/L)}for(f=0;f<r;f++)if(f<o||f>l)for(M=f;M<r;M++)t.set(f,M,n.get(f,M));for(M=r-1;M>=o;M--)for(f=o;f<=l;f++){for(p=0,E=o;E<=Math.min(M,l);E++)p=p+t.get(f,E)*n.get(E,M);t.set(f,M,p)}}}function Gt(r,s,e,t){let n,i;return Math.abs(e)>Math.abs(t)?(n=t/e,i=e+n*t,[(r+n*s)/i,(s-n*r)/i]):(n=e/t,i=t+n*e,[(n*r+s)/i,(n*s-r)/i])}class Be{constructor(s){if(s=nt.checkMatrix(s),!s.isSymmetric())throw new Error("Matrix is not symmetric");let e=s,t=e.rows,n=new _(t,t),i=!0,o,l,h;for(l=0;l<t;l++){let a=0;for(h=0;h<l;h++){let u=0;for(o=0;o<h;o++)u+=n.get(h,o)*n.get(l,o);u=(e.get(l,h)-u)/n.get(h,h),n.set(l,h,u),a=a+u*u}for(a=e.get(l,l)-a,i&&(i=a>0),n.set(l,l,Math.sqrt(Math.max(a,0))),h=l+1;h<t;h++)n.set(l,h,0)}this.L=n,this.positiveDefinite=i}isPositiveDefinite(){return this.positiveDefinite}solve(s){s=nt.checkMatrix(s);let e=this.L,t=e.rows;if(s.rows!==t)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let n=s.columns,i=s.clone(),o,l,h;for(h=0;h<t;h++)for(l=0;l<n;l++){for(o=0;o<h;o++)i.set(h,l,i.get(h,l)-i.get(o,l)*e.get(h,o));i.set(h,l,i.get(h,l)/e.get(h,h))}for(h=t-1;h>=0;h--)for(l=0;l<n;l++){for(o=h+1;o<t;o++)i.set(h,l,i.get(h,l)-i.get(o,l)*e.get(o,h));i.set(h,l,i.get(h,l)/e.get(h,h))}return i}get lowerTriangularMatrix(){return this.L}}class Oe{constructor(s,e={}){s=nt.checkMatrix(s);let{Y:t}=e;const{scaleScores:n=!1,maxIterations:i=1e3,terminationCriteria:o=1e-10}=e;let l;if(t){if(et.isAnyArray(t)&&typeof t[0]=="number"?t=_.columnVector(t):t=nt.checkMatrix(t),t.rows!==s.rows)throw new Error("Y should have the same number of rows as X");l=t.getColumnVector(0)}else l=s.getColumnVector(0);let h=1,a,u,c,g;for(let d=0;d<i&&h>o;d++)c=s.transpose().mmul(l).div(l.transpose().mmul(l).get(0,0)),c=c.div(c.norm()),a=s.mmul(c).div(c.transpose().mmul(c).get(0,0)),d>0&&(h=a.clone().sub(g).pow(2).sum()),g=a.clone(),t?(u=t.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0)),u=u.div(u.norm()),l=t.mmul(u).div(u.transpose().mmul(u).get(0,0))):l=a;if(t){let d=s.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0));d=d.div(d.norm());let w=s.clone().sub(a.clone().mmul(d.transpose())),p=l.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0)),P=t.clone().sub(a.clone().mulS(p.get(0,0)).mmul(u.transpose()));this.t=a,this.p=d.transpose(),this.w=c.transpose(),this.q=u,this.u=l,this.s=a.transpose().mmul(a),this.xResidual=w,this.yResidual=P,this.betas=p}else this.w=c.transpose(),this.s=a.transpose().mmul(a).sqrt(),n?this.t=a.clone().div(this.s.get(0,0)):this.t=a,this.xResidual=s.sub(a.mmul(c.transpose()))}}$.AbstractMatrix=V;$.CHO=Be;$.CholeskyDecomposition=Be;$.DistanceMatrix=ee;$.EVD=ze;var sn=$.EigenvalueDecomposition=ze;$.LU=se;$.LuDecomposition=se;var Ue=$.Matrix=_;$.MatrixColumnSelectionView=Ns;$.MatrixColumnView=Vs;$.MatrixFlipColumnView=$s;$.MatrixFlipRowView=Ls;$.MatrixRowSelectionView=zs;$.MatrixRowView=Ds;$.MatrixSelectionView=Qt;$.MatrixSubView=Bs;$.MatrixTransposeView=Os;$.NIPALS=Oe;$.Nipals=Oe;$.QR=ye;$.QrDecomposition=ye;$.SVD=It;$.SingularValueDecomposition=It;$.SymmetricMatrix=Pt;$.WrapperMatrix1D=Le;$.WrapperMatrix2D=nt;$.correlation=Js;$.covariance=Zs;var Te=$.default=_;$.determinant=Xt;$.inverse=Ys;$.linearDependencies=Qs;$.pseudoInverse=Xs;$.solve=De;$.wrap=Us;const nn=sn,rn=Ue;Te.Matrix&&Te.Matrix;function ne(r,s,e){const t=r/e,n=s/e;if(!(isFinite(t)&&isFinite(n))){const h=-r/s;return isFinite(h)?[h]:r==0&&s==0?[0]:[]}const i=n*n-4*t;let o=0;if(isFinite(i)){if(i<0)return[];if(i==0)return[-.5*n];o=-.5*(n+vt(Math.sqrt(i),n))}else o=-n;const l=t/o;return isFinite(l)?l>o?[o,l]:[l,o]:[o]}function Ye(r,s,e,t){const n=e/(3*t),i=s/(3*t),o=r/t;if(!(isFinite(o)&&isFinite(i)&&isFinite(n)))return ne(r,s,e);const l=-n*n+i,h=-i*n+o,a=n*o-i*i,u=4*l*a-h*h,c=-2*n*l+h;if(u<0){const g=Math.sqrt(-.25*u),d=-.5*c;return[Math.cbrt(d+g)+Math.cbrt(d-g)-n]}else if(u==0){const g=vt(Math.sqrt(-l),c);return[g-n,-2*g-n]}else{const g=Math.atan2(Math.sqrt(u),-c)/3,d=Math.cos(g),w=Math.sin(g)*Math.sqrt(3),p=.5*(-d+w),P=.5*(-d-w),f=2*Math.sqrt(-l);return[f*d-n,f*p-n,f*P-n]}}function on(r,s,e,t,n){if(n==0)return Ye(r,s,e,t);const i=t/n,o=e/n,l=s/n,h=r/n;let a=Ie(i,o,l,h,!1);if(a!==null)return a;const u=716e74;for(let c=0;c<2;c++)if(a=Ie(i/u,o/(u*u),l/(u*u*u),h/(u*u*u*u),c!=0),a!==null){for(let g=0;g<a.length;g++)a[g]*=u;return a}return[]}function gt(r,s){return s==0?Math.abs(r):Math.abs((r-s)/s)}function Ie(r,s,e,t,n){const i=ln(r,s,e,t,n);if(i!==null&&i.length==4){let o=[];for(let l=0;l<2;l++){const h=i[l*2],a=i[l*2+1];o=o.concat(ne(a,h,1))}return o}return null}function ln(r,s,e,t,n){function i(A,N,x,B){const U=gt(A+x,r),T=gt(N+A*x+B,s),z=gt(N*x+A*B,e);return U+T+z}function o(A,N,x,B){return i(A,N,x,B)+gt(N*B,t)}const l=9*r*r-24*s,h=l>=0?-2*s/(3*r+vt(Math.sqrt(l),r)):-.25*r,a=r+4*h,u=s+3*h*(r+2*h),c=e+h*(2*s+h*(3*r+4*h)),g=t+h*(e+h*(s+h*(r+h)));let d=0,w=0;const p=349e100;if(n){const A=a/p,N=u/p,x=c/p,B=g/p;d=A*x-4/p*B-1/3*N*N,w=(A*x-8/p*B-2/9*N*N)*(1/3)*N-x*(x/p)-A*A*B}else d=a*c-4*g-1/3*u*u,w=(a*c+8*g-2/9*u*u)*(1/3)*u-c*c-a*a*g;if(!isFinite(d)&&isFinite(w))return null;let P=hn(d,w);n&&(P*=p);const f=r*.5,M=1/6*s+.5*P,E=e-r*M,R=2/3*s-P-f*f,v=.5*E/R,L=2*(t-M*M)/E,S=.5*E/L;let k=0,D=0,m=0;for(let A=0;A<3;A++){const N=A==1?S:R,x=A==0?v:L,B=gt(N+f*f+2*M,s),U=gt(2*(N*x+f*M),e),T=gt(N*x*x+M*M,t),z=B+U+T;(A==0||z<m)&&(k=N,D=x,m=z)}const b=k,j=D;let y=0,C=0,F=0,I=0;if(b<0){const A=Math.sqrt(-b);if(y=f+A,C=M+A*j,F=f-A,I=M-A*j,Math.abs(I)<Math.abs(C)?I=t/C:Math.abs(I)>Math.abs(C)&&(C=t/I),Math.abs(y)!=Math.abs(F)){let N=null,x=null;if(Math.abs(y)<Math.abs(F)){const U=(e-C*F)/I,T=(s-I-C)/F;N=[r-F,U,T],x=[F,F,F]}else{const U=(e-y*I)/C,T=(s-I-C)/y,z=r-y;N=[y,y,y],x=[z,U,T]}let B=0;for(let U=0;U<3;U++){const T=N[U],z=x[U];if(isFinite(T)&&isFinite(z)){const Q=i(T,C,z,I);(U==0||Q<B)&&(y=T,F=z,B=Q)}}}}else if(b==0){const A=t-M*M;y=f,C=M+Math.sqrt(-A),F=f,I=M-Math.sqrt(-A),Math.abs(C)>Math.abs(I)?I=t/C:Math.abs(I)>Math.abs(C)&&(C=t/I)}else return[];let O=o(y,C,F,I);for(let A=0;A<8&&O!=0;A++){const N=C*I-t,x=C*F+y*I-e,B=C+y*F+I-s,U=y+F-r,T=y-F,z=C*C-C*(F*T+2*I)+I*(y*T+I);if(z==0)break;const Q=1/z,G=I-C,W=C*F-y*I,ie=T*N+G*x+W*B-(C*G+y*W)*U,re=(y*T+G)*N-C*(T*x+G*B+W*U),oe=-T*N-G*x-W*B+(F*W+I*G)*U,le=-(F*T+G)*N+I*(T*x+G*B+W*U),Vt=y-Q*ie,Nt=C-Q*re,$t=F-Q*oe,Lt=I-Q*le,Dt=o(Vt,Nt,$t,Lt);if(Dt<O)y=Vt,C=Nt,F=$t,I=Lt,O=Dt;else break}return[y,C,F,I]}function hn(r,s){const e=-.3333333333333333*r,t=.5*s;let n,i=null;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)r>0?n=0:n=Math.sqrt(-r);else if(i!==null?i<0:t*t<e*e*e){const a=i!==null?t/e/Math.sqrt(e):t/Math.sqrt(e*e*e);n=-2*Math.sqrt(e)*vt(Math.cos(Math.acos(Math.abs(a))*(1/3)),a)}else{let a;i!==null?Math.abs(e)<Math.abs(t)?a=-t*(1+Math.sqrt(i)):a=-t-vt(Math.sqrt(Math.abs(e))*e*Math.sqrt(i),t):a=Math.cbrt(-t-vt(Math.sqrt(t*t-e*e*e),t));const u=a==0?0:e/a;n=a+u}let o=n,l=(o*o+r)*o+s;if(Math.abs(l)<222045e-21*Math.max(o*o*o,r*o,s))return o;for(let a=0;a<8;a++){const u=3*o*o+r;if(u==0)break;const c=o-l/u,g=(c*c+r)*c+s;if(g==0)return c;if(Math.abs(g)>=Math.abs(l))break;o=c,l=g}return o}function vt(r,s){const e=Math.abs(r);return s<0?-e:e}function We(r,s=1e-9){if(r[r.length-1]==0)return We(r.slice(0,-1),s);const e=new rn([r.slice(0,-1).reverse().map(n=>-n/r[r.length-1]),...Array.from({length:r.length-2},(n,i)=>{const o=new Array(r.length-1).fill(0);return o[i]=1,o})]),t=new nn(e);return t.realEigenvalues.filter((n,i)=>Math.abs(t.imaginaryEigenvalues[i])<s)}const an=(r,s,e)=>[r[0]*(1-e)+s[0]*e,r[1]*(1-e)+s[1]*e];function un(r){const s=[];for(let e=0;e<r.length-1;e++)s.push([r[e],r[e+1]]);return s}function Pe(r,s){const e=un(r).map(([t,n])=>an(t,n,s));return r.length===2?[e]:[...Pe(e,s),e]}class wt extends At{constructor(e,t,n,i){super(e,t);q(this,"segmentType","CUBIC_BEZIER");q(this,"firstControlPoint");q(this,"lastControlPoint");q(this,"_boundingBox",null);q(this,"_polynomialCoefficients",null);this.firstControlPoint=n,this.lastControlPoint=i}get midPoint(){return this.paramPoint(.5)}get boundingBox(){if(this._boundingBox===null){const e=t=>{const[n,i,o,l]=[this.firstPoint[t],this.firstControlPoint[t],this.lastControlPoint[t],this.lastPoint[t]],h=-n+3*i-3*o+l,a=2*n-4*i+2*o,u=-n+i;return ne(u,a,h).filter(c=>c>=-this.precision&&c<=1+this.precision)};this._boundingBox=ge([this.firstPoint,...e(0).map(t=>this.paramPoint(t)),...e(1).map(t=>this.paramPoint(t)),this.lastPoint]).grow(this.precision)}return this._boundingBox}clone(){return new wt(this.firstPoint,this.lastPoint,this.firstControlPoint,this.lastControlPoint)}reverse(){return new wt(this.lastPoint,this.firstPoint,this.lastControlPoint,this.firstControlPoint)}isSame(e){return e.segmentType!=="CUBIC_BEZIER"?!1:Y(this.firstPoint,e.firstPoint)&&Y(this.lastPoint,e.lastPoint)&&Y(this.firstControlPoint,e.firstControlPoint)&&Y(this.lastControlPoint,e.lastControlPoint)}distanceFrom(e){const n=xe(i=>Et(this.paramPoint(i),e),this.precision);return n.argMin<-this.precision||n.argMin>1+this.precision?Math.min(J(this.firstPoint,e),J(this.lastPoint,e)):Math.sqrt(n.fMin)}isOnSegment(e){if(!this.boundingBox.contains(e))return!1;try{const t=this.pointToParam(e);return t>=-this.precision&&t<=1+this.precision}catch{return!1}}gradientAt(e){const t=1-e,n=t*t,i=e*e,o=3*n,l=6*t*e,h=3*i,a=X(this.firstControlPoint,this.firstPoint),u=X(this.lastControlPoint,this.firstControlPoint),c=X(this.lastPoint,this.lastControlPoint);return[o*a[0]+l*u[0]+h*c[0],o*a[1]+l*u[1]+h*c[1]]}tangentAt(e){const t=this.pointToParam(e);return K(this.gradientAt(t))}get tangentAtFirstPoint(){return K(X(this.firstControlPoint,this.firstPoint))}get tangentAtLastPoint(){return K(X(this.lastControlPoint,this.lastPoint))}normalAt(e){const t=this.tangentAt(e);return st(t)}splitAtParameters(e,t=null){const n=[...e];n.sort((o,l)=>o-l);let i={originalParam:0,param:0,p0:this.firstPoint,p1:this.firstControlPoint,p2:this.lastControlPoint};return n.flatMap((o,l)=>{if(o-i.originalParam<this.precision)return[];let h=!1;o>1-this.precision&&(h=!0);const a=(o-i.originalParam)/(1-i.originalParam),u=Pe([i.p0,i.p1,i.p2,this.lastPoint],h?1:a),c=h?this.lastPoint:(t==null?void 0:t.get(o))??u[0][0],g=u[1][0],d=u[2][0],w=u[1][1],p=u[2][2],P=new wt(i.p0,c,d,g);return i={param:a,originalParam:o,p0:c,p1:w,p2:p},l===n.length-1&&!h?[P,new wt(i.p0,this.lastPoint,i.p1,i.p2)]:P})}splitAt(e){let t;if(Array.isArray(e)&&e.length===0)return[this];Array.isArray(e[0])?t=e:t=[e];const n=t.map(o=>this.pointToParam(o)),i=new Map(xt([n,t]));return this.splitAtParameters(n,i)}transform(e){return new wt(e.transform(this.firstPoint),e.transform(this.lastPoint),e.transform(this.firstControlPoint),e.transform(this.lastControlPoint))}paramPoint(e){const t=1-e,n=t*t,i=e*e,o=n*t,l=3*n*e,h=3*t*i,a=i*e;return[o*this.firstPoint[0]+l*this.firstControlPoint[0]+h*this.lastControlPoint[0]+a*this.lastPoint[0],o*this.firstPoint[1]+l*this.firstControlPoint[1]+h*this.lastControlPoint[1]+a*this.lastPoint[1]]}get polynomialCoefficients(){if(this._polynomialCoefficients===null){const e=t=>{const n=this.firstPoint[t],i=this.firstControlPoint[t],o=this.lastControlPoint[t],l=this.lastPoint[t],h=-n+3*i-3*o+l,a=3*n-6*i+3*o,u=-3*n+3*i;return[n,u,a,h]};this._polynomialCoefficients=[e(0),e(1)]}return this._polynomialCoefficients}paramsAtY(e){const[t,n,i,o]=this.polynomialCoefficients[1];return Ye(t-e,n,i,o).filter(l=>l>=-this.precision&&l<=1+this.precision)}pointToParam(e){const t=this.paramsAtY(e[1]);if(t.length===0)throw new Error("Point is not on the curve");const n=o=>Math.abs(this.paramPoint(o)[0]-e[0])<=this.precision,i=t.find(n);if(i===void 0)throw new Error("Point is not on the curve");return i}}class Mt extends At{constructor(e,t,n,i,o,l,h=!1,{ignoreChecks:a=!1,angleUnits:u="deg"}={}){super(e,t);q(this,"segmentType","ELLIPSE_ARC");q(this,"precision",1e-6);q(this,"majorRadius");q(this,"minorRadius");q(this,"center");q(this,"tiltAngle");q(this,"clockwise");q(this,"_coefficients",null);q(this,"_boundingBox");q(this,"_linearExentricity");q(this,"_exentricity");q(this,"_focals");q(this,"_ellipseReferenceFrameTransform");q(this,"_reverseEllipseReferenceFrameTransform");q(this,"_rotateFromEllipseReferenceFrame");q(this,"_firstAngle");q(this,"_lastAngle");q(this,"_deltaAngle");this.center=n;const c=i>=o;this.majorRadius=c?i:o,this.minorRadius=c?o:i;const g=u==="deg"?l*Kt:l;if(this.tiltAngle=dt(c?g:g+Math.PI/2),this.clockwise=h,!a){if(Y(e,t))throw new Error("Invalid arc, cannot be a full circle");if(!this.isPointOnEllipse(e))throw new Error(`First point ${Z(e)} not on the ellipse defined by ${this.info}`);if(!this.isPointOnEllipse(t))throw new Error(`Last point ${Z(t)} not on the ellipse defined by ${this.info}`);if(Math.abs(this.majorRadius-this.minorRadius)<this.precision)throw new Error("Both radii should be different, create an arc instead")}}get coefficients(){if(this._coefficients===null){const[e,t]=this.center,n=this.majorRadius*this.majorRadius,i=this.minorRadius*this.minorRadius,o=Math.cos(this.tiltAngle),l=Math.sin(this.tiltAngle),h=n*l*l+i*o*o,a=2*(i-n)*l*o,u=n*o*o+i*l*l;this._coefficients={x2:h,xy:a,y2:u,x:-2*h*e-a*t,y:-2*u*t-a*e,c:h*e*e+a*e*t+u*t*t-n*i}}return this._coefficients}get info(){return`ELLIPSE_ARC(${Z(this.firstPoint)}, ${Z(this.lastPoint)}, ${Z(this.center)}, ${this.majorRadius}, ${this.minorRadius}, ${this.tiltAngle*Ce}, ${this.clockwise?"CW":"CCW"})`}reverse(){return new Mt(this.lastPoint,this.firstPoint,this.center,this.majorRadius,this.minorRadius,this.tiltAngle,!this.clockwise,{ignoreChecks:!0,angleUnits:"rad"})}clone(){return new Mt(this.firstPoint,this.lastPoint,this.center,this.majorRadius,this.minorRadius,this.tiltAngle,this.clockwise,{ignoreChecks:!0,angleUnits:"rad"})}computeEllipseExtrema(){const e=Math.tan(this.tiltAngle),t=this.minorRadius/this.majorRadius,n=-Math.atan(t*e),i=Math.atan(t/e);return[n,Math.PI+n,i,Math.PI+i].map(l=>this.thetaToParam(l)).filter(l=>this.isValidParameter(l)).map(l=>this.paramPoint(l))}get boundingBox(){if(this._boundingBox===void 0){const e=this.computeEllipseExtrema(),t=[this.firstPoint,this.lastPoint,...e];this._boundingBox=ge(t).grow(this.precision)}return this._boundingBox}get linearExentricity(){return this._linearExentricity===void 0&&(this._linearExentricity=Math.sqrt(this.majorRadius*this.majorRadius-this.minorRadius*this.minorRadius)),this._linearExentricity}get exentricity(){return this._exentricity===void 0&&(this._exentricity=this.linearExentricity/this.majorRadius),this._exentricity}get focals(){if(this._focals===void 0){const e=this.majorAxis;this._focals=[at(this.center,mt(e,this.linearExentricity)),at(this.center,mt(e,-this.linearExentricity))]}return this._focals}get majorAxis(){return Rt(1,this.tiltAngle)}paramPoint(e){const t=this.firstAngle+e*this.deltaAngle*(this.clockwise?-1:1);return this.reverseEllipseReferenceFrameTransform.transform([this.majorRadius*Math.cos(t),this.minorRadius*Math.sin(t)])}pointToParam(e){if(!this.isPointOnEllipse(e))throw new Error(`Point ${Z(e)} not on the ellipse defined by ${this.repr}`);const t=this.thetaToParam(this.pointTheta(e));if(!this.isValidParameter(t))throw new Error(`Point ${Z(e)} is not on segment ${this.repr}`);return t}get midPoint(){return this.paramPoint(.5)}isValidParameter(e){return 1-e>=-this.precision&&e>=-this.precision}isSame(e){return Y(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)&&(Y(this.firstPoint,e.firstPoint)&&this.clockwise===e.clockwise||Y(this.firstPoint,e.lastPoint)&&this.clockwise!==e.clockwise)}pointTheta(e){const t=this.ellipseReferenceFrameTransform.transform(e),n=Math.atan2(t[1]/this.minorRadius,t[0]/this.majorRadius);return dt(n)}thetaToParam(e){return Zt(this.firstAngle,dt(e),this.clockwise)/this.deltaAngle}isPointOnEllipse(e){const[t,n]=this.focals,i=J(e,t),o=J(e,n);return Math.abs(2*this.majorRadius-i-o)<this.precision}isOnSegment(e){return this.isPointOnEllipse(e)?this.isValidParameter(this.thetaToParam(this.pointTheta(e))):!1}distanceFrom(e){let t;if(Y(e,this.center)?t=at(this.center,mt(st(this.majorAxis),this.minorRadius)):t=this.reverseEllipseReferenceFrameTransform.transform(mn(this.majorRadius,this.minorRadius,this.ellipseReferenceFrameTransform.transform(e))),this.isValidParameter(this.thetaToParam(this.pointTheta(e))))return J(e,t);if(Ze(e,this.majorAxis,this.center)){const n=dt(2*Math.PI-this.pointTheta(e)),i=this.thetaToParam(n);if(this.isValidParameter(i))return J(e,this.paramPoint(i))}return Math.min(J(e,this.firstPoint),J(e,this.lastPoint))}get ellipseReferenceFrameTransform(){return this._ellipseReferenceFrameTransform===void 0&&(this._ellipseReferenceFrameTransform=new tt().rotate(-this.tiltAngle).translate(-this.center[0],-this.center[1])),this._ellipseReferenceFrameTransform}get reverseEllipseReferenceFrameTransform(){return this._reverseEllipseReferenceFrameTransform===void 0&&(this._reverseEllipseReferenceFrameTransform=new tt().translate(this.center[0],this.center[1]).rotate(this.tiltAngle)),this._reverseEllipseReferenceFrameTransform}get rotateFromEllipseReferenceFrame(){return this._rotateFromEllipseReferenceFrame===void 0&&(this._rotateFromEllipseReferenceFrame=new tt().rotate(this.tiltAngle)),this._rotateFromEllipseReferenceFrame}get firstAngle(){return this._firstAngle===void 0&&(this._firstAngle=this.pointTheta(this.firstPoint)),this._firstAngle}get lastAngle(){return this._lastAngle===void 0&&(this._lastAngle=this.pointTheta(this.lastPoint)),this._lastAngle}get deltaAngle(){return this._deltaAngle===void 0&&(this._deltaAngle=Zt(this.firstAngle,this.lastAngle,this.clockwise)),this._deltaAngle}normalAt(e){const t=this.tangentAt(e);return this.clockwise?st(t):Ct(t)}gradientAt(e){const t=this.firstAngle+e*this.deltaAngle*(this.clockwise?-1:1),n=-this.majorRadius*this.deltaAngle*Math.sin(t),i=this.minorRadius*this.deltaAngle*Math.cos(t),o=this.clockwise?[-n,-i]:[n,i];return this.rotateFromEllipseReferenceFrame.transform(o)}tangentAt(e){const t=this.pointTheta(e),n=-this.majorRadius*Math.sin(t),i=this.minorRadius*Math.cos(t),o=this.clockwise?[-n,-i]:[n,i];return K(this.rotateFromEllipseReferenceFrame.transform(o))}get tangentAtFirstPoint(){const e=-this.majorRadius*Math.sin(this.firstAngle),t=this.minorRadius*Math.cos(this.firstAngle),n=this.clockwise?[-e,-t]:[e,t];return K(this.rotateFromEllipseReferenceFrame.transform(n))}get tangentAtLastPoint(){const e=-this.majorRadius*Math.sin(this.lastAngle),t=this.minorRadius*Math.cos(this.lastAngle),n=this.clockwise?[-e,-t]:[e,t];return K(this.rotateFromEllipseReferenceFrame.transform(n))}transform(e){const t=e.transformAngle(this.tiltAngle),n=e.scaleFactor();return new Mt(e.transform(this.firstPoint),e.transform(this.lastPoint),e.transform(this.center),this.majorRadius*n,this.minorRadius*n,t,e.keepsOrientation()?this.clockwise:!this.clockwise,{angleUnits:"rad"})}splitAt(e){let t;if(Array.isArray(e)&&e.length===0)return[this];Array.isArray(e[0])?t=e:t=[e];const i=[0,1,...t.map(h=>this.pointToParam(h))],o=new Map(xt([i,[this.firstPoint,this.lastPoint,...t]]));i.sort((h,a)=>h-a);let l=null;return i.flatMap((h,a)=>{if(a===i.length-1)return[];const u=i[a+1];if(u-h<this.precision)return l===null&&(l=h),[];const c=l===null?h:l,g=new Mt(o.get(c)||this.paramPoint(c),o.get(u)||this.paramPoint(u),this.center,this.majorRadius,this.minorRadius,this.tiltAngle,this.clockwise,{angleUnits:"rad"});return l=null,g})}}function cn(r,s,e,t,n,i,o){const{center:l,rx:h,ry:a}=fn(r,s,e,t,n*Kt,!i,o);return Math.abs(h-a)<1e-9?new ht(r,s,l,o):new Mt(r,s,l,h,a,n,o)}function fn([r,s],[e,t],n,i,o,l,h){if(n<0&&(n=-n),i<0&&(i=-i),n==0||i==0)throw Error("rx and ry can not be 0");const a=Math.sin(o),u=Math.cos(o),c=(r-e)/2,g=(s-t)/2,d=(r+e)/2,w=(s+t)/2,p=u*c+a*g,P=u*g-a*c,f=p*p/(n*n)+P*P/(i*i);f>1&&(n=n*Math.sqrt(f),i=i*Math.sqrt(f));const M=n*i,E=n*P,R=i*p,v=E*E+R*R;if(!v)throw Error("start point can not be same as end point");let L=Math.sqrt(Math.abs((M*M-v)/v));l==h&&(L=-L);const S=L*E/i,k=-L*R/n,D=u*S-a*k+d,m=a*S+u*k+w;return{center:[D,m],rx:n,ry:i}}function mn(r,s,e){const t=Math.abs(e[0]),n=Math.abs(e[1]);let i=.707,o=.707;const l=r,h=s;for(let a=0;a<3;a++){const u=l*i,c=h*o,g=(l*l-h*h)*i**3/l,d=(h*h-l*l)*o**3/h,w=u-g,p=c-d,P=t-g,f=n-d,M=Math.hypot(w,p),E=Math.hypot(P,f);i=Math.min(1,Math.max(0,(P*M/E+g)/l)),o=Math.min(1,Math.max(0,(f*M/E+d)/h));const R=Math.hypot(i,o);i/=R,o/=R}return[l*i*Math.sign(e[0]),h*o*Math.sign(e[1])]}class pt extends At{constructor(e,t,n){super(e,t);q(this,"segmentType","QUADRATIC_BEZIER");q(this,"controlPoint");q(this,"_boundingBox",null);q(this,"_polynomialCoefficients",null);this.controlPoint=n}get midPoint(){return this.paramPoint(.5)}get boundingBox(){if(this._boundingBox===null){const e=t=>{const[n,i,o]=[this.firstPoint[t],this.controlPoint[t],this.lastPoint[t]],l=n-2*i+o;if(!l)return[];const h=(n-i)/l;return h>=-this.precision&&h<=1+this.precision?[h]:[]};this._boundingBox=ge([this.firstPoint,...e(0).map(t=>this.paramPoint(t)),...e(1).map(t=>this.paramPoint(t)),this.lastPoint]).grow(this.precision)}return this._boundingBox}clone(){return new pt(this.firstPoint,this.lastPoint,this.controlPoint)}reverse(){return new pt(this.lastPoint,this.firstPoint,this.controlPoint)}isSame(e){return e.segmentType!=="QUADRATIC_BEZIER"?!1:Y(this.firstPoint,e.firstPoint)&&Y(this.lastPoint,e.lastPoint)&&Y(this.controlPoint,e.controlPoint)}distanceFrom(e){const n=xe(i=>Et(this.paramPoint(i),e),this.precision);return n.argMin<-this.precision||n.argMin>1+this.precision?Math.min(J(this.firstPoint,e),J(this.lastPoint,e)):Math.sqrt(n.fMin)}isOnSegment(e){if(!this.boundingBox.contains(e))return!1;try{const t=this.pointToParam(e);return t>=-this.precision&&t<=1+this.precision}catch{return!1}}gradientAt(e){const t=n=>{const i=this.firstPoint[n],o=this.controlPoint[n],l=this.lastPoint[n];return 2*(e*(i-2*o+l)-i+o)};return[t(0),t(1)]}tangentAt(e){const t=this.pointToParam(e);return K(this.gradientAt(t))}get tangentAtFirstPoint(){return K(X(this.controlPoint,this.firstPoint))}get tangentAtLastPoint(){return K(X(this.controlPoint,this.lastPoint))}normalAt(e){const t=this.tangentAt(e);return st(t)}splitAtParameters(e,t=null){const n=[...e];n.sort((o,l)=>o-l);let i={originalParam:0,param:0,p0:this.firstPoint,p1:this.controlPoint};return n.flatMap((o,l)=>{if(o-i.originalParam<this.precision)return[];let h=!1;o>1-this.precision&&(h=!0);const a=(o-i.originalParam)/(1-i.originalParam),u=Pe([i.p0,i.p1,this.lastPoint],h?1:a),c=h?this.lastPoint:(t==null?void 0:t.get(o))??u[0][0],g=u[1][0],d=u[1][1],w=new pt(i.p0,c,g);return i={param:a,originalParam:o,p0:c,p1:d},l===n.length-1&&!h?[w,new pt(i.p0,this.lastPoint,i.p1)]:w})}splitAt(e){let t;if(Array.isArray(e)&&e.length===0)return[this];Array.isArray(e[0])?t=e:t=[e];const n=t.map(o=>this.pointToParam(o)),i=new Map(xt([n,t]));return this.splitAtParameters(n,i)}transform(e){return new pt(e.transform(this.firstPoint),e.transform(this.lastPoint),e.transform(this.controlPoint))}paramPoint(e){const t=1-e,n=t*t,i=2*t*e,o=e*e;return[n*this.firstPoint[0]+i*this.controlPoint[0]+o*this.lastPoint[0],n*this.firstPoint[1]+i*this.controlPoint[1]+o*this.lastPoint[1]]}get polynomialCoefficients(){if(this._polynomialCoefficients===null){const e=t=>{const n=this.firstPoint[t],i=this.controlPoint[t],o=this.lastPoint[t],l=n-2*i+o,h=2*(i-n);return[n,h,l]};this._polynomialCoefficients=[e(0),e(1)]}return this._polynomialCoefficients}paramsAtY(e){const[t,n,i]=this.polynomialCoefficients[1];return ne(t-e,n,i).filter(o=>o>=-this.precision&&o<=1+this.precision)}pointToParam(e){const t=this.paramsAtY(e[1]);if(t.length===0)throw new Error("Point is not on the curve!");const n=o=>Math.abs(this.paramPoint(o)[0]-e[0])<=this.precision,i=t.find(n);if(i===void 0)throw new Error("Point is not on the curve");return i}}exports.Arc=ht;exports.BoundingBox=ct;exports.CubicBezier=wt;exports.DEG2RAD=Kt;exports.EllipseArc=Mt;exports.Line=lt;exports.QuadraticBezier=pt;exports.RAD2DEG=Ce;exports.Transformable=Ae;exports.TransformationMatrix=tt;exports.add=at;exports.cartesianToPolar=Fe;exports.crossProduct=yt;exports.distance=J;exports.dotProduct=ce;exports.length=Xe;exports.lineLineIntersection=ts;exports.lineLineParams=Ht;exports.normalize=K;exports.parallel=pe;exports.perpendicular=st;exports.perpendicularClockwise=Ct;exports.polarAngle=qe;exports.polarToCartesian=Rt;exports.removeDuplicatePoints=we;exports.reprVector=Z;exports.sameVector=Y;exports.scalarMultiply=mt;exports.solveGenericPolynomial=We;exports.solveQuartic=on;exports.squareDistance=Et;exports.squareLength=Tt;exports.subtract=X;exports.svgEllipse=cn;exports.tangentArc=ss;exports.threePointsArc=es;exports.zip=xt;
9
+ //# sourceMappingURL=QuadraticBezier-BAVasVfu.cjs.map