pantograph2d 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -658
- package/dist/QuadraticBezier-BKElJOgn.cjs +9 -0
- package/dist/QuadraticBezier-BKElJOgn.cjs.map +1 -0
- package/dist/QuadraticBezier-PcRS9HZK.js +4773 -0
- package/dist/QuadraticBezier-PcRS9HZK.js.map +1 -0
- package/dist/draw-L71G180-.cjs +2 -0
- package/dist/draw-L71G180-.cjs.map +1 -0
- package/dist/draw-N2ntigsw.js +417 -0
- package/dist/draw-N2ntigsw.js.map +1 -0
- package/dist/models-BXU-Gx3U.cjs +4 -0
- package/dist/models-BXU-Gx3U.cjs.map +1 -0
- package/dist/{Diagram-2450b2e6.js → models-BjaFYsN2.js} +278 -279
- package/dist/models-BjaFYsN2.js.map +1 -0
- package/dist/pantograph/drawShape.cjs +1 -1
- package/dist/pantograph/drawShape.cjs.map +1 -1
- package/dist/pantograph/drawShape.js +12 -14
- package/dist/pantograph/drawShape.js.map +1 -1
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +2 -2
- package/dist/pantograph/svg.cjs +1 -1
- package/dist/pantograph/svg.js +5 -6
- package/dist/pantograph/svg.js.map +1 -1
- package/dist/pantograph.cjs +2 -2
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.js +432 -400
- package/dist/pantograph.js.map +1 -1
- package/dist/{wrapSVG-02b823ac.cjs → svg-ZTvNxsWu.cjs} +2 -2
- package/dist/svg-ZTvNxsWu.cjs.map +1 -0
- package/dist/{wrapSVG-0ec8a111.js → svg-hNHYuj_r.js} +2 -2
- package/dist/svg-hNHYuj_r.js.map +1 -0
- package/dist/types/examples/importSVG.d.ts +4 -0
- package/dist/{algorithms → types/src/algorithms}/boolean/figureBooleans.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/boolean/loopBooleans.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/boolean/strandBoolean.d.ts +4 -4
- package/dist/{algorithms → types/src/algorithms}/boolean/strandsBetweenIntersections.d.ts +3 -3
- package/dist/types/src/algorithms/conversions/bezierToArcs.d.ts +7 -0
- package/dist/types/src/algorithms/conversions/bezierToSafeBezier.d.ts +12 -0
- package/dist/types/src/algorithms/conversions/ellipseToArcs.d.ts +0 -0
- package/dist/types/src/algorithms/conversions/ellipseToBezier.d.ts +3 -0
- package/dist/types/src/algorithms/conversions/helpers.d.ts +13 -0
- package/dist/{algorithms → types/src/algorithms}/distances/arcArcDistance.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/distances/genericDistance.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/distances/index.d.ts +1 -1
- package/dist/types/src/algorithms/distances/lineArcDistance.d.ts +3 -0
- package/dist/{algorithms → types/src/algorithms}/distances/lineLineDistance.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/filletSegments.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/intersections/arcArcIntersection.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/arcEllipseArcIntersection.d.ts +3 -0
- package/dist/types/src/algorithms/intersections/arcsCubicBezierIntersection.d.ts +5 -0
- package/dist/types/src/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +5 -0
- package/dist/{algorithms → types/src/algorithms}/intersections/bezierClip.d.ts +3 -3
- package/dist/{algorithms → types/src/algorithms}/intersections/cubicBezierCubicBezierIntersection.d.ts +2 -2
- package/dist/{algorithms → types/src/algorithms}/intersections/ellipseArcEllipseArcIntersection.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/ellipseEllipseIntersection.d.ts +4 -0
- package/dist/types/src/algorithms/intersections/fullLinesIntersection.d.ts +18 -0
- package/dist/{algorithms → types/src/algorithms}/intersections/index.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/lineArcIntersection.d.ts +4 -0
- package/dist/types/src/algorithms/intersections/lineBezierIntersection.d.ts +5 -0
- package/dist/types/src/algorithms/intersections/lineEllipseArcIntersection.d.ts +4 -0
- package/dist/{algorithms → types/src/algorithms}/intersections/lineLineIntersection.d.ts +4 -4
- package/dist/{algorithms → types/src/algorithms}/intersections/quadraticBezierQuadraticBezierIntersection.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/rayIntersections.d.ts +3 -0
- package/dist/{algorithms → types/src/algorithms}/offsets/offsetFigure.d.ts +2 -2
- package/dist/types/src/algorithms/offsets/offsetSegment.d.ts +15 -0
- package/dist/types/src/algorithms/offsets/offsetStroke.d.ts +11 -0
- package/dist/{algorithms → types/src/algorithms}/organiseLoops.d.ts +2 -2
- package/dist/types/src/algorithms/simplify.d.ts +3 -0
- package/dist/types/src/algorithms/solvers/findZeroViaNewton.d.ts +1 -0
- package/dist/{algorithms → types/src/algorithms}/stitchSegments.d.ts +1 -1
- package/dist/types/src/api/drawShape.d.ts +2 -0
- package/dist/types/src/api/models.d.ts +1 -0
- package/dist/types/src/api/svg.d.ts +1 -0
- package/dist/{booleanOperations.d.ts → types/src/booleanOperations.d.ts} +5 -5
- package/dist/types/src/conversionOperations.d.ts +8 -0
- package/dist/{draw.d.ts → types/src/draw.d.ts} +4 -4
- package/dist/{drawShape → types/src/drawShape}/drawCircle.d.ts +1 -1
- package/dist/types/src/drawShape/drawEllipse.d.ts +2 -0
- package/dist/{drawShape → types/src/drawShape}/drawRect.d.ts +1 -1
- package/dist/types/src/drawShape/drawSVGPath.d.ts +2 -0
- package/dist/types/src/drawShape/index.d.ts +4 -0
- package/dist/{export → types/src/export}/json/exportJSON.d.ts +94 -94
- package/dist/{export → types/src/export}/json/jsonDiagram.d.ts +31 -31
- package/dist/{export → types/src/export}/json/jsonFigure.d.ts +31 -31
- package/dist/{export → types/src/export}/json/jsonLoop.d.ts +16 -16
- package/dist/{export → types/src/export}/json/jsonSegment.d.ts +16 -16
- package/dist/types/src/export/svg/api.d.ts +6 -0
- package/dist/{export → types/src/export}/svg/exportSVG.d.ts +6 -6
- package/dist/{export → types/src/export}/svg/svgDiagram.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/svgFigure.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/svgLoop.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/svgSegment.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/svgStrand.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/wrapSVG.d.ts +1 -1
- package/dist/types/src/import/json/importJSON.d.ts +9 -0
- package/dist/{main.d.ts → types/src/main.d.ts} +7 -7
- package/dist/{models → types/src/models}/BoundingBox.d.ts +1 -1
- package/dist/{models → types/src/models}/Diagram.d.ts +7 -7
- package/dist/{models → types/src/models}/Figure.d.ts +7 -7
- package/dist/{models → types/src/models}/Loop.d.ts +4 -4
- package/dist/{models → types/src/models}/Strand.d.ts +2 -2
- package/dist/{models → types/src/models}/Stroke.d.ts +5 -5
- package/dist/{models → types/src/models}/TransformationMatrix.d.ts +1 -1
- package/dist/types/src/models/exports.d.ts +15 -0
- package/dist/types/src/models/segments/AbstractSegment.d.ts +25 -0
- package/dist/{models → types/src/models}/segments/Arc.d.ts +5 -4
- package/dist/{models → types/src/models}/segments/CubicBezier.d.ts +11 -4
- package/dist/{models → types/src/models}/segments/EllipseArc.d.ts +5 -5
- package/dist/{models → types/src/models}/segments/Line.d.ts +4 -4
- package/dist/{models → types/src/models}/segments/QuadraticBezier.d.ts +9 -4
- package/dist/{models → types/src/models}/segments/Segment.d.ts +4 -4
- package/dist/{models → types/src/models}/segments/utils/deCasteljau.d.ts +1 -1
- package/dist/types/src/models/segments/utils/isSegment.d.ts +8 -0
- package/dist/{models → types/src/models}/utils/Transformable.d.ts +2 -2
- package/dist/{offsetOperations.d.ts → types/src/offsetOperations.d.ts} +4 -4
- package/dist/types/src/operations.d.ts +2 -0
- package/dist/types/src/utils/applyMixins.d.ts +1 -0
- package/dist/types/src/utils/listOfFigures.d.ts +4 -0
- package/dist/types/src/utils/projectPointOnLine.d.ts +3 -0
- package/dist/{utils → types/src/utils}/removeDuplicatePoints.d.ts +1 -1
- package/dist/{vectorOperations.d.ts → types/src/vectorOperations.d.ts} +1 -1
- package/package.json +4 -4
- package/dist/Diagram-2450b2e6.js.map +0 -1
- package/dist/Diagram-57e17509.cjs +0 -4
- package/dist/Diagram-57e17509.cjs.map +0 -1
- package/dist/QuadraticBezier-e116a2d6.js +0 -3647
- package/dist/QuadraticBezier-e116a2d6.js.map +0 -1
- package/dist/QuadraticBezier-e3d7218b.cjs +0 -9
- package/dist/QuadraticBezier-e3d7218b.cjs.map +0 -1
- package/dist/algorithms/distances/lineArcDistance.d.ts +0 -3
- package/dist/algorithms/intersections/arcEllipseArcIntersection.d.ts +0 -3
- package/dist/algorithms/intersections/arcsCubicBezierIntersection.d.ts +0 -5
- package/dist/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +0 -5
- package/dist/algorithms/intersections/ellipseEllipseIntersection.d.ts +0 -4
- package/dist/algorithms/intersections/lineArcIntersection.d.ts +0 -4
- package/dist/algorithms/intersections/lineBezierIntersection.d.ts +0 -5
- package/dist/algorithms/intersections/lineEllipseArcIntersection.d.ts +0 -4
- package/dist/algorithms/intersections/rayIntersections.d.ts +0 -3
- package/dist/algorithms/offsets/offsetSegment.d.ts +0 -12
- package/dist/algorithms/offsets/offsetStroke.d.ts +0 -9
- package/dist/algorithms/simplify.d.ts +0 -3
- package/dist/api/drawShape.d.ts +0 -2
- package/dist/api/models.d.ts +0 -1
- package/dist/api/svg.d.ts +0 -1
- package/dist/draw-27ac6dae.cjs +0 -2
- package/dist/draw-27ac6dae.cjs.map +0 -1
- package/dist/draw-c7b2705c.js +0 -344
- package/dist/draw-c7b2705c.js.map +0 -1
- package/dist/export/svg/api.d.ts +0 -6
- package/dist/import/json/importJSON.d.ts +0 -9
- package/dist/models/exports.d.ts +0 -15
- package/dist/models/segments/utils/isSegment.d.ts +0 -8
- package/dist/operations.d.ts +0 -2
- package/dist/utils/listOfFigures.d.ts +0 -4
- package/dist/utils/projectPointOnLine.d.ts +0 -3
- package/dist/wrapSVG-02b823ac.cjs.map +0 -1
- package/dist/wrapSVG-0ec8a111.js.map +0 -1
- /package/dist/{algorithms → types/src/algorithms}/optimisation/Brent.d.ts +0 -0
- /package/dist/{algorithms → types/src/algorithms}/optimisation/DiRect.d.ts +0 -0
- /package/dist/{algorithms → types/src/algorithms}/solvers/solvePolynomials.d.ts +0 -0
- /package/dist/{definitions.d.ts → types/src/definitions.d.ts} +0 -0
- /package/dist/{utils → types/src/utils}/allCombinations.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/allPairs.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/angularDistance.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/range.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/removeDuplicateValues.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/unitAngle.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/zip.d.ts +0 -0
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";var pe=Object.defineProperty;var we=(r,n,e)=>n in r?pe(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var E=(r,n,e)=>(we(r,typeof n!="symbol"?n+"":n,e),e);function It(r,n,e,t){return r<=t&&n>=e}class it{constructor(n=1/0,e=1/0,t=-1/0,s=-1/0){E(this,"xMin");E(this,"yMin");E(this,"xMax");E(this,"yMax");this.xMin=n,this.yMin=e,this.xMax=t,this.yMax=s}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(n){return new it(this.xMin-n,this.yMin-n,this.xMax+n,this.yMax+n)}contains(n){const[e,t]=n;return It(this.xMin,this.xMax,e,e)&&It(this.yMin,this.yMax,t,t)}overlaps(n){return It(this.xMin,this.xMax,n.xMin,n.xMax)&&It(this.yMin,this.yMax,n.yMin,n.yMax)}addPoint(n){const[e,t]=n;return new it(Math.min(this.xMin,e),Math.min(this.yMin,t),Math.max(this.xMax,e),Math.max(this.yMax,t))}merge(n){return new it(Math.min(this.xMin,n.xMin),Math.min(this.yMin,n.yMin),Math.max(this.xMax,n.xMax),Math.max(this.yMax,n.yMax))}intersection(n){return new it(Math.max(this.xMin,n.xMin),Math.max(this.yMin,n.yMin),Math.min(this.xMax,n.xMax),Math.min(this.yMax,n.yMax))}}function Ut(r){return r.reduce((n,e)=>n.addPoint(e),new it)}const Kt=(r,n=1e-9)=>{let e=r;return Math.abs(r)<n&&(e=0),e.toFixed(-Math.log10(n))};function Wt(r,n=1e-9){return Array.from(new Map(r.map(([e,t])=>[`[${Kt(e,n)},${Kt(t,n)}]`,[e,t]])).values())}const Bt=Math.PI/180,oe=180/Math.PI,O=r=>`[${r[0]}, ${r[1]}]`,N=([r,n],[e,t],s=1e-9)=>Math.abs(r-e)<=s&&Math.abs(n-t)<=s,st=([r,n],[e,t])=>[r+e,n+t],V=([r,n],[e,t])=>[r-e,n-t],Et=([r,n])=>r*r+n*n,de=([r,n])=>Math.sqrt(Et([r,n])),ht=([r,n],e)=>[r*e,n*e],gt=([r,n],[e,t]=[0,0])=>(r-e)**2+(n-t)**2,Y=(r,n=[0,0])=>Math.sqrt(gt(r,n));function mt([r,n],[e,t]){return r*t-n*e}function Gt([r,n],[e,t]){return r*e+n*t}function G([r,n]){const e=Y([r,n]);return[r/e,n/e]}function Mt(r,n){const e=Math.cos(n)*r,t=Math.sin(n)*r;return[e,t]}function he([r,n]){return Math.atan2(n,r)}function le(r){const n=Y(r),e=he(r);return[n,e]}function Xt(r,n,e=1e-9){const t=mt(r,n),s=Et(r),i=Et(n);return t*t<s*i*e*e}function K(r){return[-r[1],r[0]]}function _t(r){return[r[1],-r[0]]}function Pe(r,n,e){return N(e,r)||Xt(V(e,r),n)}const pt=(r,n)=>{const[e,t,s,i,o,h,a,l,c]=r,[u,m,d,w,g,M,f,p,P]=n;return[e*u+t*w+s*f,e*m+t*g+s*p,e*d+t*M+s*P,i*u+o*w+h*f,i*m+o*g+h*p,i*d+o*M+h*P,a*u+l*w+c*f,a*m+l*g+c*p,a*d+l*M+c*P]},Me=r=>{const[n,e,t,s,i,o,h,a,l]=r,c=n*(i*l-o*a)-e*(s*l-o*h)+t*(s*a-i*h);return[(i*l-o*a)/c,(t*a-e*l)/c,(e*o-t*i)/c,(o*h-s*l)/c,(n*l-t*h)/c,(t*s-n*o)/c,(s*a-i*h)/c,(e*h-n*a)/c,(n*i-e*s)/c]},ye=r=>{const[n,e,t,s,i,o,h,a,l]=r;return[n,s,h,e,i,a,t,o,l]};class W{constructor(n){E(this,"_matrix",[1,0,0,0,1,0,0,0,1]);n&&(this._matrix=[...n])}clone(){return new W(this._matrix)}transpose(){return this._matrix=ye(this._matrix),this}inverse(){return this._matrix=Me(this._matrix),this}translate(n,e){return this._matrix=pt(this._matrix,[1,0,n,0,1,e,0,0,1]),this}rotate(n,e){const t=Math.cos(n),s=Math.sin(n),i=[t,-s,0,s,t,0,0,0,1];return e&&this.translate(e[0],e[1]),this._matrix=pt(this._matrix,i),e&&this.translate(-e[0],-e[1]),this}mirrorX(){return this._matrix=pt(this._matrix,[1,0,0,0,-1,0,0,0,1]),this}mirrorY(){return this._matrix=pt(this._matrix,[-1,0,0,0,1,0,0,0,1]),this}mirrorLine(n,e){const[t,s]=n,i=Math.atan2(s,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(n){return n&&this.translate(n[0],n[1]),this._matrix=pt(this._matrix,[-1,0,0,0,-1,0,0,0,1]),n&&this.translate(-n[0],-n[1]),this}scale(n,e){return e&&this.translate(e[0],e[1]),this._matrix=pt(this._matrix,[n,0,0,0,n,0,0,0,1]),e&&this.translate(-e[0],-e[1]),this}transform(n){const[e,t]=n,[s,i,o,h,a,l]=this._matrix;return[s*e+i*t+o,h*e+a*t+l]}transformAngle(n){const[e,t]=this.transform([Math.cos(n),Math.sin(n)]),[s,i]=this.transform([0,0]);return Math.atan2(t-i,e-s)}keepsOrientation(){const[n,,,,e]=this._matrix;return n*e>0}scaleFactor(){const[n,,,e]=this._matrix;return Math.sqrt(n*n+e*e)}}class ae{translateX(n){const e=new W().translate(n,0);return this.transform(e)}translateY(n){const e=new W().translate(0,n);return this.transform(e)}translate(n,e){const t=new W().translate(n,e);return this.transform(t)}translateTo([n,e]){const t=new W().translate(n,e);return this.transform(t)}rotate(n,e){const t=new W().rotate(n*Bt,e);return this.transform(t)}scale(n,e){const t=new W().scale(n,e);return this.transform(t)}mirrorCenter(n){const e=new W().mirrorCenter(n);return this.transform(e)}mirror(n="x",e){const t=new W;return n==="x"?t.mirrorX():n==="y"?t.mirrorY():t.mirrorLine(n,e),this.transform(t)}}class bt extends ae{constructor(e,t){super();E(this,"precision",1e-9);this.firstPoint=e,this.lastPoint=t,this.firstPoint=e,this.lastPoint=t}get repr(){return`${this.segmentType} ${O(this.firstPoint)} - ${O(this.lastPoint)}`}get info(){return this.repr}[Symbol.for("nodejs.util.inspect.custom")](){return this.repr}}class H extends bt{constructor(){super(...arguments);E(this,"segmentType","LINE");E(this,"_V",null);E(this,"_slope",null);E(this,"_yIntercept",null);E(this,"_boundingBox",null)}isValidParameter(e){const t=this.length*this.precision;return e>=-t&&1-e>=-t}paramPoint(e){return st(this.firstPoint,ht(this.V,e))}get length(){return Y(this.firstPoint,this.lastPoint)}get squareLength(){return gt(this.firstPoint,this.lastPoint)}get V(){return this._V===null&&(this._V=V(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 st(this.firstPoint,ht(this.V,.5))}isSame(e){return e instanceof H?N(this.firstPoint,e.firstPoint)&&N(this.lastPoint,e.lastPoint)||N(this.lastPoint,e.firstPoint)&&N(this.firstPoint,e.lastPoint):!1}clone(){return new H(this.firstPoint,this.lastPoint)}reverse(){return new H(this.lastPoint,this.firstPoint)}get boundingBox(){return this._boundingBox===null&&(this._boundingBox=new it(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=V(e,this.firstPoint),s=Gt(t,this.V)/this.squareLength;if(s<0)return Y(e,this.firstPoint);if(s>1)return Y(e,this.lastPoint);const i=this.paramPoint(s);return Y(e,i)}isOnSegment(e){if(N(e,this.firstPoint,this.precision))return!0;const t=V(e,this.firstPoint);if(!Xt(this.V,t))return!1;const s=Gt(t,this.V)/this.squareLength;return this.isValidParameter(s)}gradientAt(e){return this.V}tangentAt(e){if(!this.isOnSegment(e))throw new Error("Point is not on segment");return G(this.V)}get normalVector(){return K(G(this.V))}get tangentAtFirstPoint(){return G(this.V)}get tangentAtLastPoint(){return G(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(l=>{if(!this.isOnSegment(l))throw new Error(`Point ${O(l)} is not on segment ${this.repr}`)});const s=[this.firstPoint,...t,this.lastPoint],i=Wt(s),o=this.lastPoint[0]-this.firstPoint[0];let h=Math.sign(o),a=0;return Math.abs(o)<this.precision&&(h=Math.sign(this.lastPoint[1]-this.firstPoint[1]),a=1),i.sort((l,c)=>h*(l[a]-c[a])),i.flatMap((l,c)=>c===i.length-1?[]:new H(l,i[c+1]))}transform(e){return new H(e.transform(this.firstPoint),e.transform(this.lastPoint))}}function Ee(r){return Array.from(Array(r).keys())}function jt(r){const n=Math.min(...r.map(e=>e.length));return Ee(n).map(e=>r.map(t=>t[e]))}function ct(r,n=1e-9){return r<0?r+2*Math.PI:r>=2*Math.PI?r%(2*Math.PI):r>2*Math.PI-n?0:r}function Nt(r,n,e,t=1e-9){let s=n-r;return e&&(s=-s),s<0&&(s+=2*Math.PI),s>2*Math.PI-t?0:s}const Lt=(r,n,e)=>{const t=mt(r.V,n.V),s=Et(r.V),i=Et(n.V),o=e?e*e:r.precision*n.precision;if(t*t<s*i*o)return"parallel";const h=V(n.firstPoint,r.firstPoint),a=mt(h,n.V)/t,l=mt(h,r.V)/t;return{intersectionParam1:a,intersectionParam2:l}};function _e(r,n,e=!1,t){const s=Lt(r,n,t);if(s==="parallel"){if(!e)return null;if(r.isSame(n))return r;const h=Wt([n.isOnSegment(r.firstPoint)?r.firstPoint:null,n.isOnSegment(r.lastPoint)?r.lastPoint:null,r.isOnSegment(n.firstPoint)?n.firstPoint:null,r.isOnSegment(n.lastPoint)?n.lastPoint:null].filter(a=>a!==null)).sort((a,l)=>a[0]-l[0]);if(h.length===0)return null;if(h.length===1)return null;if(h.length===2)return new H(h[0],h[1]);throw console.error(h),new Error("Unexpected number of points while intersecting parallel lines")}const{intersectionParam1:i,intersectionParam2:o}=s;return!r.isValidParameter(i)||!n.isValidParameter(o)?null:r.paramPoint(i)}const qt=(r,n)=>{const e=V(r,n);return le(e)};class et extends bt{constructor(e,t,s,i=!1,{ignoreChecks:o=!1}={}){super(e,t);E(this,"segmentType","ARC");E(this,"center");E(this,"clockwise");E(this,"_coefficients",null);E(this,"_angularLength",null);E(this,"_radius",null);E(this,"_firstAngle",null);E(this,"_lastAngle",null);E(this,"_boundingBox",null);if(this.center=s,this.clockwise=i,!o){if(N(e,t))throw new Error("Invalid arc, cannot be a full circle");if(Math.abs(this.radius-Y(this.lastPoint,this.center))>this.precision)throw new Error(`Invalid arc, radius does not match between ${O(e)} and ${O(t)}} (center ${O(s)})`)}}get info(){return`ARC(${O(this.firstPoint)}, ${O(this.lastPoint)}, ${O(this.center)}, ${this.clockwise?"CW":"CCW"})`}get coefficients(){if(this._coefficients===null){const[e,t]=this.center,s=this.radius*this.radius;this._coefficients={x2:1/s,xy:0,y2:1/s,x:-(2*e)/s,y:-(2*t)/s,c:(e*e+t*t-s)/s}}return this._coefficients}isValidParameter(e){return 1-e>=-this.precision&&e>=-this.precision}angleToParam(e){return Nt(this.firstAngle,ct(e),this.clockwise)/this.angularLength}get angularLength(){return this._angularLength||(this._angularLength=Nt(this.firstAngle,this.lastAngle,this.clockwise)),this._angularLength}paramPoint(e){return st(this.center,Mt(this.radius,this.firstAngle+e*this.angularLength*(this.clockwise?-1:1)))}pointToParam(e){const[t,s]=qt(e,this.center);if(Math.abs(t-this.radius)>this.precision)throw new Error(`Point ${O(e)} is not on segment ${this.repr}`);const i=this.angleToParam(s);if(!this.isValidParameter(i))throw new Error(`Point ${O(e)} is not on segment ${this.repr}`);return i}get radius(){return this._radius===null&&(this._radius=Y(this.firstPoint,this.center)),this._radius}get firstAngle(){if(this._firstAngle===null){const[e,t]=V(this.firstPoint,this.center);this._firstAngle=ct(Math.atan2(t,e))}return this._firstAngle}get lastAngle(){if(this._lastAngle===null){const[e,t]=V(this.lastPoint,this.center);this._lastAngle=ct(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 et)||!N(this.center,e.center)?!1:N(this.firstPoint,e.firstPoint)&&N(this.lastPoint,e.lastPoint)&&this.clockwise===e.clockwise||N(this.lastPoint,e.firstPoint)&&N(this.firstPoint,e.lastPoint)&&this.clockwise===!e.clockwise}clone(){return new et(this.firstPoint,this.lastPoint,this.center,this.clockwise)}reverse(){return new et(this.lastPoint,this.firstPoint,this.center,!this.clockwise)}get boundingBox(){if(this._boundingBox===null){const e=this.radius+this.precision,t=s=>this.isValidParameter(this.angleToParam(s));this._boundingBox=new it(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,s]=qt(e,this.center);return this.isValidParameter(this.angleToParam(s))?Math.abs(t-this.radius):Math.sqrt(Math.min(gt(e,this.firstPoint),gt(e,this.lastPoint)))}isOnSegment(e){if(N(e,this.firstPoint)||N(e,this.lastPoint))return!0;const[t,s]=qt(e,this.center);if(Math.abs(t-this.radius)>this.precision)return!1;const i=this.angleToParam(s);return this.isValidParameter(i)}gradientAt(e){const t=this.firstAngle+e*this.angularLength*(this.clockwise?-1:1),s=this.radius*this.angularLength,i=-s*Math.sin(t),o=s*Math.cos(t);return this.clockwise?[-i,-o]:[i,o]}tangentAt(e){const[t,s]=qt(e,this.center);if(Math.abs(t-this.radius)>this.precision)throw new Error("Point is not on the arc");const i=this.angleToParam(s);if(!this.isValidParameter(i))throw new Error("Point is not on the arc");const o=Mt(1,s);return(this.clockwise?_t:K)(G(o))}get tangentAtFirstPoint(){const e=Mt(1,this.firstAngle);return(this.clockwise?_t:K)(G(e))}get tangentAtLastPoint(){const e=Mt(1,this.lastAngle);return(this.clockwise?_t:K)(G(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(a=>this.pointToParam(a))],o=new Map(jt([i,[this.firstPoint,this.lastPoint,...t]]));i.sort((a,l)=>a-l);let h=null;return i.flatMap((a,l)=>{if(l===i.length-1)return[];const c=i[l+1];if(c-a<this.precision)return h===null&&(h=a),[];const u=h===null?a:h,m=new et(o.get(u)||this.paramPoint(u),o.get(c)||this.paramPoint(c),this.center,this.clockwise);return h=null,m})}transform(e){return new et(e.transform(this.firstPoint),e.transform(this.lastPoint),e.transform(this.center),e.keepsOrientation()?this.clockwise:!this.clockwise)}}function be(r,n,e){const t=new H(n,r),s=new H(n,e),i=K(t.tangentAtFirstPoint),o=K(s.tangentAtLastPoint),h=Lt({firstPoint:t.midPoint,V:i,precision:1e-9},{firstPoint:s.midPoint,V:o,precision:1e-9});if(h==="parallel")throw new Error("Cannot create an arc from three colinear points");const a=mt(V(r,n),V(e,n))>0;return new et(r,e,st(t.midPoint,ht(i,h.intersectionParam1)),a,{ignoreChecks:!0})}function je(r,n,e){const t=new H(n,r),s=K(t.tangentAtFirstPoint),i=Lt({firstPoint:t.midPoint,V:s,precision:1e-9},{firstPoint:r,V:K(e),precision:1e-9});if(i==="parallel")throw new Error("Cannot create an arc from three colinear points");const o=st(t.midPoint,ht(s,i.intersectionParam1)),h=mt(V(o,r),V(o,st(r,e)))<0;return new et(r,n,o,h,{ignoreChecks:!0})}const Qt=1e-21,Ct=1.618034;function Jt(r,n=0,e=1,t=110,s=1e3){let i,o,h,a,l,c,u,m,d,w,g,M,f;for(o=r(n),h=r(e),o<h&&([n,e]=[e,n],[o,h]=[h,o]),f=e+Ct*(e-n),a=r(f),l=3,u=0;a<h;){if(m=(e-n)*(h-a),d=(e-f)*(h-o),w=d-m,Math.abs(w)<Qt?i=2*Qt:i=2*w,g=e-((e-f)*d-(e-n)*m)/i,M=e+t*(f-e),u>s)throw new Error("Too many iterations.");if(u+=1,(g-f)*(e-g)>0){if(c=r(g),l+=1,c<a)return n=e,e=g,o=h,h=c,[n,e,f,o,h,a,l];if(c>h)return f=g,a=c,[n,e,f,o,h,a,l];g=f+Ct*(f-e),c=r(g),l+=1}else(g-M)*(M-f)>=0?(g=M,c=r(g),l+=1):(g-M)*(f-g)>0?(c=r(g),l+=1,c<a&&(e=f,f=g,g=f+Ct*(f-e),h=a,a=c,c=r(g),l+=1)):(g=f+Ct*(f-e),c=r(g),l+=1);n=e,e=f,f=g,o=h,h=a,a=c}return[n,e,f,o,h,a,l]}const Ht=.381966,Se=1e-11;class Re{constructor(n,e=148e-10,t=500){E(this,"xmin");E(this,"fval");E(this,"iter");E(this,"funcalls");E(this,"brack");this.func=n,this.tol=e,this.maxiter=t,this.func=n,this.tol=e,this.maxiter=t,this.xmin=1/0,this.fval=1/0,this.iter=0,this.funcalls=0,this.brack=null}setBracket(n=null){this.brack=n}getBracketInfo(){let n,e,t,s,i,o,h;const a=this.func,l=this.brack;if(l===null)[i,o,h,n,e,t,s]=Jt(a);else if(l.length===2)[i,o,h,n,e,t,s]=Jt(a,l[0],l[1]);else if(l.length===3){if([i,o,h]=l,i>h&&([h,i]=[i,h]),!(i<o&&o<h))throw new Error("Not a bracketing interval.");if(n=a(i),e=a(o),t=a(h),!(e<n&&e<t))throw new Error("Not a bracketing interval.");s=3}else throw new Error("Bracketing interval must be length 2 or 3 sequence.");return[i,o,h,n,e,t,s]}optimize(){const n=this.func;let[e,t,s,,,,i]=this.getBracketInfo(),o=t,h=t,a=t,l=n(o),c=l,u=l,m,d;e<s?(m=e,d=s):(m=s,d=e);let w=0;i=1;let g=0,M=0,f;for(;g<this.maxiter;){const p=this.tol*Math.abs(o)+Se,P=2*p,_=.5*(m+d);if(Math.abs(o-_)<P-.5*(d-m))break;if(Math.abs(w)<=p)o>=_?w=m-o:w=d-o,M=Ht*w;else{const C=(o-h)*(u-c);let j=(o-a)*(u-l),y=(o-a)*j-(o-h)*C;j=2*(j-C),j>0&&(y=-y),j=Math.abs(j);const x=w;w=M,y>j*(m-o)&&y<j*(d-o)&&Math.abs(y)<Math.abs(.5*j*x)?(M=y*1/j,f=o+M,(f-m<P||d-f<P)&&(_-o>=0?M=p:M=-p)):(o>=_?w=m-o:w=d-o,M=Ht*w)}Math.abs(M)<p?M>=0?f=o+p:f=o-p:f=o+M;const b=n(f);i+=1,b>u?(f<o?m=f:d=f,b<=l||h===o?(a=h,h=f,c=l,l=b):(b<=c||a===o||a===h)&&(a=f,c=b)):(f>=o?m=o:d=o,a=h,h=o,o=f,c=l,l=u,u=b),g+=1}this.xmin=o,this.fval=u,this.iter=g,this.funcalls=i}results(){return{argMin:this.xmin,fMin:this.fval,iterations:this.iter,funcCalls:this.funcalls}}run(){return this.optimize(),this.results()}}function ue(r,n=1e-8,e=1e3){const t=new Re(r,n,e);return t.setBracket([0,1]),t.run()}const ke=Object.prototype.toString;function Z(r){const n=ke.call(r);return n.endsWith("Array]")&&!n.includes("Big")}function Te(r){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Z(r))throw new TypeError("input must be an array");if(r.length===0)throw new TypeError("input must not be empty");var e=n.fromIndex,t=e===void 0?0:e,s=n.toIndex,i=s===void 0?r.length:s;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],h=t+1;h<i;h++)r[h]>o&&(o=r[h]);return o}function ve(r){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Z(r))throw new TypeError("input must be an array");if(r.length===0)throw new TypeError("input must not be empty");var e=n.fromIndex,t=e===void 0?0:e,s=n.toIndex,i=s===void 0?r.length:s;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],h=t+1;h<i;h++)r[h]<o&&(o=r[h]);return o}function te(r){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(Z(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(n.output!==void 0){if(!Z(n.output))throw new TypeError("output option must be an array if specified");e=n.output}else e=new Array(r.length);var t=ve(r),s=Te(r);if(t===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=n.min,o=i===void 0?n.autoMinMax?t:0:i,h=n.max,a=h===void 0?n.autoMinMax?s:1:h;if(o>=a)throw new RangeError("min option must be smaller than max option");for(var l=(a-o)/(s-t),c=0;c<r.length;c++)e[c]=(r[c]-t)*l+o;return e}const Ft=" ".repeat(2),ce=" ".repeat(4);function Ie(){return fe(this)}function fe(r,n={}){const{maxRows:e=15,maxColumns:t=10,maxNumSize:s=8,padMinus:i="auto"}=n;return`${r.constructor.name} {
|
|
2
|
-
${Ft}[
|
|
3
|
-
${ce}${qe(r,e,t,s,i)}
|
|
4
|
-
${Ft}]
|
|
5
|
-
${Ft}rows: ${r.rows}
|
|
6
|
-
${Ft}columns: ${r.columns}
|
|
7
|
-
}`}function qe(r,n,e,t,s){const{rows:i,columns:o}=r,h=Math.min(i,n),a=Math.min(o,e),l=[];if(s==="auto"){s=!1;t:for(let c=0;c<h;c++)for(let u=0;u<a;u++)if(r.get(c,u)<0){s=!0;break t}}for(let c=0;c<h;c++){let u=[];for(let m=0;m<a;m++)u.push(Ce(r.get(c,m),t,s));l.push(`${u.join(" ")}`)}return a!==o&&(l[l.length-1]+=` ... ${o-e} more columns`),h!==i&&l.push(`... ${i-n} more rows`),l.join(`
|
|
8
|
-
${ce}`)}function Ce(r,n,e){return(r>=0&&e?` ${ee(r,n-1)}`:ee(r,n)).padEnd(n)}function ee(r,n){let e=r.toString();if(e.length<=n)return e;let t=r.toFixed(n);if(t.length>n&&(t=r.toFixed(Math.max(0,n-(t.length-n)))),t.length<=n&&!t.startsWith("0.000")&&!t.startsWith("-0.000"))return t;let s=r.toExponential(n);return s.length>n&&(s=r.toExponential(Math.max(0,n-(s.length-n)))),s.slice(0)}function Fe(r,n){r.prototype.add=function(t){return typeof t=="number"?this.addS(t):this.addM(t)},r.prototype.addS=function(t){for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)+t);return this},r.prototype.addM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)+t.get(s,i));return this},r.add=function(t,s){return new n(t).add(s)},r.prototype.sub=function(t){return typeof t=="number"?this.subS(t):this.subM(t)},r.prototype.subS=function(t){for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)-t);return this},r.prototype.subM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)-t.get(s,i));return this},r.sub=function(t,s){return new n(t).sub(s)},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 s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)*t);return this},r.prototype.mulM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)*t.get(s,i));return this},r.mul=function(t,s){return new n(t).mul(s)},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 s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)/t);return this},r.prototype.divM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)/t.get(s,i));return this},r.div=function(t,s){return new n(t).div(s)},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 s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)%t);return this},r.prototype.modM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)%t.get(s,i));return this},r.mod=function(t,s){return new n(t).mod(s)},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 s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)&t);return this},r.prototype.andM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)&t.get(s,i));return this},r.and=function(t,s){return new n(t).and(s)},r.prototype.or=function(t){return typeof t=="number"?this.orS(t):this.orM(t)},r.prototype.orS=function(t){for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)|t);return this},r.prototype.orM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)|t.get(s,i));return this},r.or=function(t,s){return new n(t).or(s)},r.prototype.xor=function(t){return typeof t=="number"?this.xorS(t):this.xorM(t)},r.prototype.xorS=function(t){for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)^t);return this},r.prototype.xorM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)^t.get(s,i));return this},r.xor=function(t,s){return new n(t).xor(s)},r.prototype.leftShift=function(t){return typeof t=="number"?this.leftShiftS(t):this.leftShiftM(t)},r.prototype.leftShiftS=function(t){for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)<<t);return this},r.prototype.leftShiftM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)<<t.get(s,i));return this},r.leftShift=function(t,s){return new n(t).leftShift(s)},r.prototype.signPropagatingRightShift=function(t){return typeof t=="number"?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},r.prototype.signPropagatingRightShiftS=function(t){for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)>>t);return this},r.prototype.signPropagatingRightShiftM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)>>t.get(s,i));return this},r.signPropagatingRightShift=function(t,s){return new n(t).signPropagatingRightShift(s)},r.prototype.rightShift=function(t){return typeof t=="number"?this.rightShiftS(t):this.rightShiftM(t)},r.prototype.rightShiftS=function(t){for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)>>>t);return this},r.prototype.rightShiftM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,this.get(s,i)>>>t.get(s,i));return this},r.rightShift=function(t,s){return new n(t).rightShift(s)},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 s=0;s<this.columns;s++)this.set(t,s,~this.get(t,s));return this},r.not=function(t){return new n(t).not()},r.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.abs(this.get(t,s)));return this},r.abs=function(t){return new n(t).abs()},r.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.acos(this.get(t,s)));return this},r.acos=function(t){return new n(t).acos()},r.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.acosh(this.get(t,s)));return this},r.acosh=function(t){return new n(t).acosh()},r.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.asin(this.get(t,s)));return this},r.asin=function(t){return new n(t).asin()},r.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.asinh(this.get(t,s)));return this},r.asinh=function(t){return new n(t).asinh()},r.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.atan(this.get(t,s)));return this},r.atan=function(t){return new n(t).atan()},r.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.atanh(this.get(t,s)));return this},r.atanh=function(t){return new n(t).atanh()},r.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.cbrt(this.get(t,s)));return this},r.cbrt=function(t){return new n(t).cbrt()},r.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.ceil(this.get(t,s)));return this},r.ceil=function(t){return new n(t).ceil()},r.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.clz32(this.get(t,s)));return this},r.clz32=function(t){return new n(t).clz32()},r.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.cos(this.get(t,s)));return this},r.cos=function(t){return new n(t).cos()},r.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.cosh(this.get(t,s)));return this},r.cosh=function(t){return new n(t).cosh()},r.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.exp(this.get(t,s)));return this},r.exp=function(t){return new n(t).exp()},r.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.expm1(this.get(t,s)));return this},r.expm1=function(t){return new n(t).expm1()},r.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.floor(this.get(t,s)));return this},r.floor=function(t){return new n(t).floor()},r.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.fround(this.get(t,s)));return this},r.fround=function(t){return new n(t).fround()},r.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.log(this.get(t,s)));return this},r.log=function(t){return new n(t).log()},r.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.log1p(this.get(t,s)));return this},r.log1p=function(t){return new n(t).log1p()},r.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.log10(this.get(t,s)));return this},r.log10=function(t){return new n(t).log10()},r.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.log2(this.get(t,s)));return this},r.log2=function(t){return new n(t).log2()},r.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.round(this.get(t,s)));return this},r.round=function(t){return new n(t).round()},r.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.sign(this.get(t,s)));return this},r.sign=function(t){return new n(t).sign()},r.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.sin(this.get(t,s)));return this},r.sin=function(t){return new n(t).sin()},r.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.sinh(this.get(t,s)));return this},r.sinh=function(t){return new n(t).sinh()},r.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.sqrt(this.get(t,s)));return this},r.sqrt=function(t){return new n(t).sqrt()},r.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.tan(this.get(t,s)));return this},r.tan=function(t){return new n(t).tan()},r.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.tanh(this.get(t,s)));return this},r.tanh=function(t){return new n(t).tanh()},r.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.set(t,s,Math.trunc(this.get(t,s)));return this},r.trunc=function(t){return new n(t).trunc()},r.pow=function(t,s){return new n(t).pow(s)},r.prototype.pow=function(t){return typeof t=="number"?this.powS(t):this.powM(t)},r.prototype.powS=function(t){for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,Math.pow(this.get(s,i),t));return this},r.prototype.powM=function(t){if(t=n.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let s=0;s<this.rows;s++)for(let i=0;i<this.columns;i++)this.set(s,i,Math.pow(this.get(s,i),t.get(s,i)));return this}}function Q(r,n,e){let t=e?r.rows:r.rows-1;if(n<0||n>t)throw new RangeError("Row index out of range")}function J(r,n,e){let t=e?r.columns:r.columns-1;if(n<0||n>t)throw new RangeError("Column index out of range")}function dt(r,n){if(n.to1DArray&&(n=n.to1DArray()),n.length!==r.columns)throw new RangeError("vector size must be the same as the number of columns");return n}function Pt(r,n){if(n.to1DArray&&(n=n.to1DArray()),n.length!==r.rows)throw new RangeError("vector size must be the same as the number of rows");return n}function $e(r,n){if(!Z(n))throw new TypeError("row indices must be an array");for(let e=0;e<n.length;e++)if(n[e]<0||n[e]>=r.rows)throw new RangeError("row indices are out of range")}function xe(r,n){if(!Z(n))throw new TypeError("column indices must be an array");for(let e=0;e<n.length;e++)if(n[e]<0||n[e]>=r.columns)throw new RangeError("column indices are out of range")}function se(r,n,e,t,s){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if($t("startRow",n),$t("endRow",e),$t("startColumn",t),$t("endColumn",s),n>e||t>s||n<0||n>=r.rows||e<0||e>=r.rows||t<0||t>=r.columns||s<0||s>=r.columns)throw new RangeError("Submatrix indices are out of range")}function At(r,n=0){let e=[];for(let t=0;t<r;t++)e.push(n);return e}function $t(r,n){if(typeof n!="number")throw new TypeError(`${r} must be a number`)}function wt(r){if(r.isEmpty())throw new Error("Empty matrix has no elements to index")}function Ne(r){let n=At(r.rows);for(let e=0;e<r.rows;++e)for(let t=0;t<r.columns;++t)n[e]+=r.get(e,t);return n}function Be(r){let n=At(r.columns);for(let e=0;e<r.rows;++e)for(let t=0;t<r.columns;++t)n[t]+=r.get(e,t);return n}function Le(r){let n=0;for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)n+=r.get(e,t);return n}function Ae(r){let n=At(r.rows,1);for(let e=0;e<r.rows;++e)for(let t=0;t<r.columns;++t)n[e]*=r.get(e,t);return n}function ze(r){let n=At(r.columns,1);for(let e=0;e<r.rows;++e)for(let t=0;t<r.columns;++t)n[t]*=r.get(e,t);return n}function Ve(r){let n=1;for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)n*=r.get(e,t);return n}function De(r,n,e){const t=r.rows,s=r.columns,i=[];for(let o=0;o<t;o++){let h=0,a=0,l=0;for(let c=0;c<s;c++)l=r.get(o,c)-e[o],h+=l,a+=l*l;n?i.push((a-h*h/s)/(s-1)):i.push((a-h*h/s)/s)}return i}function Oe(r,n,e){const t=r.rows,s=r.columns,i=[];for(let o=0;o<s;o++){let h=0,a=0,l=0;for(let c=0;c<t;c++)l=r.get(c,o)-e[o],h+=l,a+=l*l;n?i.push((a-h*h/t)/(t-1)):i.push((a-h*h/t)/t)}return i}function Ye(r,n,e){const t=r.rows,s=r.columns,i=t*s;let o=0,h=0,a=0;for(let l=0;l<t;l++)for(let c=0;c<s;c++)a=r.get(l,c)-e,o+=a,h+=a*a;return n?(h-o*o/i)/(i-1):(h-o*o/i)/i}function Ge(r,n){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)-n[e])}function Ue(r,n){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)-n[t])}function We(r,n){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)-n)}function Xe(r){const n=[];for(let e=0;e<r.rows;e++){let t=0;for(let s=0;s<r.columns;s++)t+=Math.pow(r.get(e,s),2)/(r.columns-1);n.push(Math.sqrt(t))}return n}function Ze(r,n){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)/n[e])}function Ke(r){const n=[];for(let e=0;e<r.columns;e++){let t=0;for(let s=0;s<r.rows;s++)t+=Math.pow(r.get(s,e),2)/(r.rows-1);n.push(Math.sqrt(t))}return n}function Qe(r,n){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)/n[t])}function Je(r){const n=r.size-1;let e=0;for(let t=0;t<r.columns;t++)for(let s=0;s<r.rows;s++)e+=Math.pow(r.get(s,t),2)/n;return Math.sqrt(e)}function He(r,n){for(let e=0;e<r.rows;e++)for(let t=0;t<r.columns;t++)r.set(e,t,r.get(e,t)/n)}class I{static from1DArray(n,e,t){if(n*e!==t.length)throw new RangeError("data length does not match given dimensions");let i=new k(n,e);for(let o=0;o<n;o++)for(let h=0;h<e;h++)i.set(o,h,t[o*e+h]);return i}static rowVector(n){let e=new k(1,n.length);for(let t=0;t<n.length;t++)e.set(0,t,n[t]);return e}static columnVector(n){let e=new k(n.length,1);for(let t=0;t<n.length;t++)e.set(t,0,n[t]);return e}static zeros(n,e){return new k(n,e)}static ones(n,e){return new k(n,e).fill(1)}static rand(n,e,t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{random:s=Math.random}=t;let i=new k(n,e);for(let o=0;o<n;o++)for(let h=0;h<e;h++)i.set(o,h,s());return i}static randInt(n,e,t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:s=0,max:i=1e3,random:o=Math.random}=t;if(!Number.isInteger(s))throw new TypeError("min must be an integer");if(!Number.isInteger(i))throw new TypeError("max must be an integer");if(s>=i)throw new RangeError("min must be smaller than max");let h=i-s,a=new k(n,e);for(let l=0;l<n;l++)for(let c=0;c<e;c++){let u=s+Math.round(o()*h);a.set(l,c,u)}return a}static eye(n,e,t){e===void 0&&(e=n),t===void 0&&(t=1);let s=Math.min(n,e),i=this.zeros(n,e);for(let o=0;o<s;o++)i.set(o,o,t);return i}static diag(n,e,t){let s=n.length;e===void 0&&(e=s),t===void 0&&(t=e);let i=Math.min(s,e,t),o=this.zeros(e,t);for(let h=0;h<i;h++)o.set(h,h,n[h]);return o}static min(n,e){n=this.checkMatrix(n),e=this.checkMatrix(e);let t=n.rows,s=n.columns,i=new k(t,s);for(let o=0;o<t;o++)for(let h=0;h<s;h++)i.set(o,h,Math.min(n.get(o,h),e.get(o,h)));return i}static max(n,e){n=this.checkMatrix(n),e=this.checkMatrix(e);let t=n.rows,s=n.columns,i=new this(t,s);for(let o=0;o<t;o++)for(let h=0;h<s;h++)i.set(o,h,Math.max(n.get(o,h),e.get(o,h)));return i}static checkMatrix(n){return I.isMatrix(n)?n:new k(n)}static isMatrix(n){return n!=null&&n.klass==="Matrix"}get size(){return this.rows*this.columns}apply(n){if(typeof n!="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++)n.call(this,e,t);return this}to1DArray(){let n=[];for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)n.push(this.get(e,t));return n}to2DArray(){let n=[];for(let e=0;e<this.rows;e++){n.push([]);for(let t=0;t<this.columns;t++)n[e].push(this.get(e,t))}return n}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 n=0;n<this.rows;n++)for(let e=0;e<=n;e++)if(this.get(n,e)!==this.get(e,n))return!1;return!0}return!1}isEchelonForm(){let n=0,e=0,t=-1,s=!0,i=!1;for(;n<this.rows&&s;){for(e=0,i=!1;e<this.columns&&i===!1;)this.get(n,e)===0?e++:this.get(n,e)===1&&e>t?(i=!0,t=e):(s=!1,i=!0);n++}return s}isReducedEchelonForm(){let n=0,e=0,t=-1,s=!0,i=!1;for(;n<this.rows&&s;){for(e=0,i=!1;e<this.columns&&i===!1;)this.get(n,e)===0?e++:this.get(n,e)===1&&e>t?(i=!0,t=e):(s=!1,i=!0);for(let o=e+1;o<this.rows;o++)this.get(n,o)!==0&&(s=!1);n++}return s}echelonForm(){let n=this.clone(),e=0,t=0;for(;e<n.rows&&t<n.columns;){let s=e;for(let i=e;i<n.rows;i++)n.get(i,t)>n.get(s,t)&&(s=i);if(n.get(s,t)===0)t++;else{n.swapRows(e,s);let i=n.get(e,t);for(let o=t;o<n.columns;o++)n.set(e,o,n.get(e,o)/i);for(let o=e+1;o<n.rows;o++){let h=n.get(o,t)/n.get(e,t);n.set(o,t,0);for(let a=t+1;a<n.columns;a++)n.set(o,a,n.get(o,a)-n.get(e,a)*h)}e++,t++}}return n}reducedEchelonForm(){let n=this.echelonForm(),e=n.columns,t=n.rows,s=t-1;for(;s>=0;)if(n.maxRow(s)===0)s--;else{let i=0,o=!1;for(;i<t&&o===!1;)n.get(s,i)===1?o=!0:i++;for(let h=0;h<s;h++){let a=n.get(h,i);for(let l=i;l<e;l++){let c=n.get(h,l)-a*n.get(s,l);n.set(h,l,c)}}s--}return n}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(n={}){if(typeof n!="object")throw new TypeError("options must be an object");const{rows:e=1,columns:t=1}=n;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 s=new k(this.rows*e,this.columns*t);for(let i=0;i<e;i++)for(let o=0;o<t;o++)s.setSubMatrix(this,this.rows*i,this.columns*o);return s}fill(n){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,n);return this}neg(){return this.mulS(-1)}getRow(n){Q(this,n);let e=[];for(let t=0;t<this.columns;t++)e.push(this.get(n,t));return e}getRowVector(n){return k.rowVector(this.getRow(n))}setRow(n,e){Q(this,n),e=dt(this,e);for(let t=0;t<this.columns;t++)this.set(n,t,e[t]);return this}swapRows(n,e){Q(this,n),Q(this,e);for(let t=0;t<this.columns;t++){let s=this.get(n,t);this.set(n,t,this.get(e,t)),this.set(e,t,s)}return this}getColumn(n){J(this,n);let e=[];for(let t=0;t<this.rows;t++)e.push(this.get(t,n));return e}getColumnVector(n){return k.columnVector(this.getColumn(n))}setColumn(n,e){J(this,n),e=Pt(this,e);for(let t=0;t<this.rows;t++)this.set(t,n,e[t]);return this}swapColumns(n,e){J(this,n),J(this,e);for(let t=0;t<this.rows;t++){let s=this.get(t,n);this.set(t,n,this.get(t,e)),this.set(t,e,s)}return this}addRowVector(n){n=dt(this,n);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)+n[t]);return this}subRowVector(n){n=dt(this,n);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)-n[t]);return this}mulRowVector(n){n=dt(this,n);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)*n[t]);return this}divRowVector(n){n=dt(this,n);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)/n[t]);return this}addColumnVector(n){n=Pt(this,n);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)+n[e]);return this}subColumnVector(n){n=Pt(this,n);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)-n[e]);return this}mulColumnVector(n){n=Pt(this,n);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)*n[e]);return this}divColumnVector(n){n=Pt(this,n);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)this.set(e,t,this.get(e,t)/n[e]);return this}mulRow(n,e){Q(this,n);for(let t=0;t<this.columns;t++)this.set(n,t,this.get(n,t)*e);return this}mulColumn(n,e){J(this,n);for(let t=0;t<this.rows;t++)this.set(t,n,this.get(t,n)*e);return this}max(n){if(this.isEmpty())return NaN;switch(n){case"row":{const e=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.get(t,s)>e[t]&&(e[t]=this.get(t,s));return e}case"column":{const e=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.get(t,s)>e[s]&&(e[s]=this.get(t,s));return e}case void 0:{let e=this.get(0,0);for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.get(t,s)>e&&(e=this.get(t,s));return e}default:throw new Error(`invalid option: ${n}`)}}maxIndex(){wt(this);let n=this.get(0,0),e=[0,0];for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.get(t,s)>n&&(n=this.get(t,s),e[0]=t,e[1]=s);return e}min(n){if(this.isEmpty())return NaN;switch(n){case"row":{const e=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.get(t,s)<e[t]&&(e[t]=this.get(t,s));return e}case"column":{const e=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.get(t,s)<e[s]&&(e[s]=this.get(t,s));return e}case void 0:{let e=this.get(0,0);for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.get(t,s)<e&&(e=this.get(t,s));return e}default:throw new Error(`invalid option: ${n}`)}}minIndex(){wt(this);let n=this.get(0,0),e=[0,0];for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)this.get(t,s)<n&&(n=this.get(t,s),e[0]=t,e[1]=s);return e}maxRow(n){if(Q(this,n),this.isEmpty())return NaN;let e=this.get(n,0);for(let t=1;t<this.columns;t++)this.get(n,t)>e&&(e=this.get(n,t));return e}maxRowIndex(n){Q(this,n),wt(this);let e=this.get(n,0),t=[n,0];for(let s=1;s<this.columns;s++)this.get(n,s)>e&&(e=this.get(n,s),t[1]=s);return t}minRow(n){if(Q(this,n),this.isEmpty())return NaN;let e=this.get(n,0);for(let t=1;t<this.columns;t++)this.get(n,t)<e&&(e=this.get(n,t));return e}minRowIndex(n){Q(this,n),wt(this);let e=this.get(n,0),t=[n,0];for(let s=1;s<this.columns;s++)this.get(n,s)<e&&(e=this.get(n,s),t[1]=s);return t}maxColumn(n){if(J(this,n),this.isEmpty())return NaN;let e=this.get(0,n);for(let t=1;t<this.rows;t++)this.get(t,n)>e&&(e=this.get(t,n));return e}maxColumnIndex(n){J(this,n),wt(this);let e=this.get(0,n),t=[0,n];for(let s=1;s<this.rows;s++)this.get(s,n)>e&&(e=this.get(s,n),t[0]=s);return t}minColumn(n){if(J(this,n),this.isEmpty())return NaN;let e=this.get(0,n);for(let t=1;t<this.rows;t++)this.get(t,n)<e&&(e=this.get(t,n));return e}minColumnIndex(n){J(this,n),wt(this);let e=this.get(0,n),t=[0,n];for(let s=1;s<this.rows;s++)this.get(s,n)<e&&(e=this.get(s,n),t[0]=s);return t}diag(){let n=Math.min(this.rows,this.columns),e=[];for(let t=0;t<n;t++)e.push(this.get(t,t));return e}norm(n="frobenius"){let e=0;if(n==="max")return this.max();if(n==="frobenius"){for(let t=0;t<this.rows;t++)for(let s=0;s<this.columns;s++)e=e+this.get(t,s)*this.get(t,s);return Math.sqrt(e)}else throw new RangeError(`unknown norm type: ${n}`)}cumulativeSum(){let n=0;for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)n+=this.get(e,t),this.set(e,t,n);return this}dot(n){I.isMatrix(n)&&(n=n.to1DArray());let e=this.to1DArray();if(e.length!==n.length)throw new RangeError("vectors do not have the same size");let t=0;for(let s=0;s<e.length;s++)t+=e[s]*n[s];return t}mmul(n){n=k.checkMatrix(n);let e=this.rows,t=this.columns,s=n.columns,i=new k(e,s),o=new Float64Array(t);for(let h=0;h<s;h++){for(let a=0;a<t;a++)o[a]=n.get(a,h);for(let a=0;a<e;a++){let l=0;for(let c=0;c<t;c++)l+=this.get(a,c)*o[c];i.set(a,h,l)}}return i}strassen2x2(n){n=k.checkMatrix(n);let e=new k(2,2);const t=this.get(0,0),s=n.get(0,0),i=this.get(0,1),o=n.get(0,1),h=this.get(1,0),a=n.get(1,0),l=this.get(1,1),c=n.get(1,1),u=(t+l)*(s+c),m=(h+l)*s,d=t*(o-c),w=l*(a-s),g=(t+i)*c,M=(h-t)*(s+o),f=(i-l)*(a+c),p=u+w-g+f,P=d+g,_=m+w,b=u-m+d+M;return e.set(0,0,p),e.set(0,1,P),e.set(1,0,_),e.set(1,1,b),e}strassen3x3(n){n=k.checkMatrix(n);let e=new k(3,3);const t=this.get(0,0),s=this.get(0,1),i=this.get(0,2),o=this.get(1,0),h=this.get(1,1),a=this.get(1,2),l=this.get(2,0),c=this.get(2,1),u=this.get(2,2),m=n.get(0,0),d=n.get(0,1),w=n.get(0,2),g=n.get(1,0),M=n.get(1,1),f=n.get(1,2),p=n.get(2,0),P=n.get(2,1),_=n.get(2,2),b=(t+s+i-o-h-c-u)*M,C=(t-o)*(-d+M),j=h*(-m+d+g-M-f-p+_),y=(-t+o+h)*(m-d+M),x=(o+h)*(-m+d),B=t*m,D=(-t+l+c)*(m-w+f),X=(-t+l)*(w-f),F=(l+c)*(-m+w),T=(t+s+i-h-a-l-c)*f,R=c*(-m+w+g-M-f-p+P),S=(-i+c+u)*(M+p-P),rt=(i-u)*(M-P),q=i*p,$=(c+u)*(-p+P),v=(-i+h+a)*(f+p-_),L=(i-a)*(f-_),z=(h+a)*(-p+_),A=s*g,U=a*P,nt=o*w,tt=l*d,ot=u*_,Vt=B+q+A,Dt=b+y+x+B+S+q+$,Ot=B+D+F+T+q+v+z,Yt=C+j+y+B+q+v+L,St=C+y+x+B+U,Rt=q+v+L+z+nt,kt=B+D+X+R+S+rt+q,Tt=S+rt+q+$+tt,vt=B+D+X+F+ot;return e.set(0,0,Vt),e.set(0,1,Dt),e.set(0,2,Ot),e.set(1,0,Yt),e.set(1,1,St),e.set(1,2,Rt),e.set(2,0,kt),e.set(2,1,Tt),e.set(2,2,vt),e}mmulStrassen(n){n=k.checkMatrix(n);let e=this.clone(),t=e.rows,s=e.columns,i=n.rows,o=n.columns;s!==i&&console.warn(`Multiplying ${t} x ${s} and ${i} x ${o} matrix: dimensions do not match.`);function h(u,m,d){let w=u.rows,g=u.columns;if(w===m&&g===d)return u;{let M=I.zeros(m,d);return M=M.setSubMatrix(u,0,0),M}}let a=Math.max(t,i),l=Math.max(s,o);e=h(e,a,l),n=h(n,a,l);function c(u,m,d,w){if(d<=512||w<=512)return u.mmul(m);d%2===1&&w%2===1?(u=h(u,d+1,w+1),m=h(m,d+1,w+1)):d%2===1?(u=h(u,d+1,w),m=h(m,d+1,w)):w%2===1&&(u=h(u,d,w+1),m=h(m,d,w+1));let g=parseInt(u.rows/2,10),M=parseInt(u.columns/2,10),f=u.subMatrix(0,g-1,0,M-1),p=m.subMatrix(0,g-1,0,M-1),P=u.subMatrix(0,g-1,M,u.columns-1),_=m.subMatrix(0,g-1,M,m.columns-1),b=u.subMatrix(g,u.rows-1,0,M-1),C=m.subMatrix(g,m.rows-1,0,M-1),j=u.subMatrix(g,u.rows-1,M,u.columns-1),y=m.subMatrix(g,m.rows-1,M,m.columns-1),x=c(I.add(f,j),I.add(p,y),g,M),B=c(I.add(b,j),p,g,M),D=c(f,I.sub(_,y),g,M),X=c(j,I.sub(C,p),g,M),F=c(I.add(f,P),y,g,M),T=c(I.sub(b,f),I.add(p,_),g,M),R=c(I.sub(P,j),I.add(C,y),g,M),S=I.add(x,X);S.sub(F),S.add(R);let rt=I.add(D,F),q=I.add(B,X),$=I.sub(x,B);$.add(D),$.add(T);let v=I.zeros(2*S.rows,2*S.columns);return v=v.setSubMatrix(S,0,0),v=v.setSubMatrix(rt,S.rows,0),v=v.setSubMatrix(q,0,S.columns),v=v.setSubMatrix($,S.rows,S.columns),v.subMatrix(0,d-1,0,w-1)}return c(e,n,a,l)}scaleRows(n={}){if(typeof n!="object")throw new TypeError("options must be an object");const{min:e=0,max:t=1}=n;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 s=new k(this.rows,this.columns);for(let i=0;i<this.rows;i++){const o=this.getRow(i);o.length>0&&te(o,{min:e,max:t,output:o}),s.setRow(i,o)}return s}scaleColumns(n={}){if(typeof n!="object")throw new TypeError("options must be an object");const{min:e=0,max:t=1}=n;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 s=new k(this.rows,this.columns);for(let i=0;i<this.columns;i++){const o=this.getColumn(i);o.length&&te(o,{min:e,max:t,output:o}),s.setColumn(i,o)}return s}flipRows(){const n=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let t=0;t<n;t++){let s=this.get(e,t),i=this.get(e,this.columns-1-t);this.set(e,t,i),this.set(e,this.columns-1-t,s)}return this}flipColumns(){const n=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let t=0;t<n;t++){let s=this.get(t,e),i=this.get(this.rows-1-t,e);this.set(t,e,i),this.set(this.rows-1-t,e,s)}return this}kroneckerProduct(n){n=k.checkMatrix(n);let e=this.rows,t=this.columns,s=n.rows,i=n.columns,o=new k(e*s,t*i);for(let h=0;h<e;h++)for(let a=0;a<t;a++)for(let l=0;l<s;l++)for(let c=0;c<i;c++)o.set(s*h+l,i*a+c,this.get(h,a)*n.get(l,c));return o}kroneckerSum(n){if(n=k.checkMatrix(n),!this.isSquare()||!n.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,t=n.rows,s=this.kroneckerProduct(k.eye(t,t)),i=k.eye(e,e).kroneckerProduct(n);return s.add(i)}transpose(){let n=new k(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)n.set(t,e,this.get(e,t));return n}sortRows(n=ne){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(n));return this}sortColumns(n=ne){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(n));return this}subMatrix(n,e,t,s){se(this,n,e,t,s);let i=new k(e-n+1,s-t+1);for(let o=n;o<=e;o++)for(let h=t;h<=s;h++)i.set(o-n,h-t,this.get(o,h));return i}subMatrixRow(n,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 s=new k(n.length,t-e+1);for(let i=0;i<n.length;i++)for(let o=e;o<=t;o++){if(n[i]<0||n[i]>=this.rows)throw new RangeError(`Row index out of range: ${n[i]}`);s.set(i,o-e,this.get(n[i],o))}return s}subMatrixColumn(n,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 s=new k(t-e+1,n.length);for(let i=0;i<n.length;i++)for(let o=e;o<=t;o++){if(n[i]<0||n[i]>=this.columns)throw new RangeError(`Column index out of range: ${n[i]}`);s.set(o-e,i,this.get(o,n[i]))}return s}setSubMatrix(n,e,t){if(n=k.checkMatrix(n),n.isEmpty())return this;let s=e+n.rows-1,i=t+n.columns-1;se(this,e,s,t,i);for(let o=0;o<n.rows;o++)for(let h=0;h<n.columns;h++)this.set(e+o,t+h,n.get(o,h));return this}selection(n,e){$e(this,n),xe(this,e);let t=new k(n.length,e.length);for(let s=0;s<n.length;s++){let i=n[s];for(let o=0;o<e.length;o++){let h=e[o];t.set(s,o,this.get(i,h))}}return t}trace(){let n=Math.min(this.rows,this.columns),e=0;for(let t=0;t<n;t++)e+=this.get(t,t);return e}clone(){let n=new k(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)n.set(e,t,this.get(e,t));return n}sum(n){switch(n){case"row":return Ne(this);case"column":return Be(this);case void 0:return Le(this);default:throw new Error(`invalid option: ${n}`)}}product(n){switch(n){case"row":return Ae(this);case"column":return ze(this);case void 0:return Ve(this);default:throw new Error(`invalid option: ${n}`)}}mean(n){const e=this.sum(n);switch(n){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: ${n}`)}}variance(n,e={}){if(typeof n=="object"&&(e=n,n=void 0),typeof e!="object")throw new TypeError("options must be an object");const{unbiased:t=!0,mean:s=this.mean(n)}=e;if(typeof t!="boolean")throw new TypeError("unbiased must be a boolean");switch(n){case"row":{if(!Z(s))throw new TypeError("mean must be an array");return De(this,t,s)}case"column":{if(!Z(s))throw new TypeError("mean must be an array");return Oe(this,t,s)}case void 0:{if(typeof s!="number")throw new TypeError("mean must be a number");return Ye(this,t,s)}default:throw new Error(`invalid option: ${n}`)}}standardDeviation(n,e){typeof n=="object"&&(e=n,n=void 0);const t=this.variance(n,e);if(n===void 0)return Math.sqrt(t);for(let s=0;s<t.length;s++)t[s]=Math.sqrt(t[s]);return t}center(n,e={}){if(typeof n=="object"&&(e=n,n=void 0),typeof e!="object")throw new TypeError("options must be an object");const{center:t=this.mean(n)}=e;switch(n){case"row":{if(!Z(t))throw new TypeError("center must be an array");return Ge(this,t),this}case"column":{if(!Z(t))throw new TypeError("center must be an array");return Ue(this,t),this}case void 0:{if(typeof t!="number")throw new TypeError("center must be a number");return We(this,t),this}default:throw new Error(`invalid option: ${n}`)}}scale(n,e={}){if(typeof n=="object"&&(e=n,n=void 0),typeof e!="object")throw new TypeError("options must be an object");let t=e.scale;switch(n){case"row":{if(t===void 0)t=Xe(this);else if(!Z(t))throw new TypeError("scale must be an array");return Ze(this,t),this}case"column":{if(t===void 0)t=Ke(this);else if(!Z(t))throw new TypeError("scale must be an array");return Qe(this,t),this}case void 0:{if(t===void 0)t=Je(this);else if(typeof t!="number")throw new TypeError("scale must be a number");return He(this,t),this}default:throw new Error(`invalid option: ${n}`)}}toString(n){return fe(this,n)}}I.prototype.klass="Matrix";typeof Symbol<"u"&&(I.prototype[Symbol.for("nodejs.util.inspect.custom")]=Ie);function ne(r,n){return r-n}function ts(r){return r.every(n=>typeof n=="number")}I.random=I.rand;I.randomInt=I.randInt;I.diagonal=I.diag;I.prototype.diagonal=I.prototype.diag;I.identity=I.eye;I.prototype.negate=I.prototype.neg;I.prototype.tensorProduct=I.prototype.kroneckerProduct;class k extends I{constructor(n,e){if(super(),k.isMatrix(n))return n.clone();if(Number.isInteger(n)&&n>=0)if(this.data=[],Number.isInteger(e)&&e>=0)for(let t=0;t<n;t++)this.data.push(new Float64Array(e));else throw new TypeError("nColumns must be a positive integer");else if(Z(n)){const t=n;if(n=t.length,e=n?t[0].length:0,typeof e!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let s=0;s<n;s++){if(t[s].length!==e)throw new RangeError("Inconsistent array dimensions");if(!ts(t[s]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(t[s]))}}else throw new TypeError("First argument must be a positive number or an array");this.rows=n,this.columns=e}set(n,e,t){return this.data[n][e]=t,this}get(n,e){return this.data[n][e]}removeRow(n){return Q(this,n),this.data.splice(n,1),this.rows-=1,this}addRow(n,e){return e===void 0&&(e=n,n=this.rows),Q(this,n,!0),e=Float64Array.from(dt(this,e)),this.data.splice(n,0,e),this.rows+=1,this}removeColumn(n){J(this,n);for(let e=0;e<this.rows;e++){const t=new Float64Array(this.columns-1);for(let s=0;s<n;s++)t[s]=this.data[e][s];for(let s=n+1;s<this.columns;s++)t[s-1]=this.data[e][s];this.data[e]=t}return this.columns-=1,this}addColumn(n,e){typeof e>"u"&&(e=n,n=this.columns),J(this,n,!0),e=Pt(this,e);for(let t=0;t<this.rows;t++){const s=new Float64Array(this.columns+1);let i=0;for(;i<n;i++)s[i]=this.data[t][i];for(s[i++]=e[t];i<this.columns+1;i++)s[i]=this.data[t][i-1];this.data[t]=s}return this.columns+=1,this}}Fe(I,k);class es extends I{constructor(n){super(),this.data=n,this.rows=n.length,this.columns=n[0].length}set(n,e,t){return this.data[n][e]=t,this}get(n,e){return this.data[n][e]}}function ie(r,n){let e=0;return Math.abs(r)>Math.abs(n)?(e=n/r,Math.abs(r)*Math.sqrt(1+e*e)):n!==0?(e=r/n,Math.abs(n)*Math.sqrt(1+e*e)):0}class ss{constructor(n,e={}){const{assumeSymmetric:t=!1}=e;if(n=es.checkMatrix(n),!n.isSquare())throw new Error("Matrix is not a square matrix");if(n.isEmpty())throw new Error("Matrix must be non-empty");let s=n.columns,i=new k(s,s),o=new Float64Array(s),h=new Float64Array(s),a=n,l,c,u=!1;if(t?u=!0:u=n.isSymmetric(),u){for(l=0;l<s;l++)for(c=0;c<s;c++)i.set(l,c,a.get(l,c));ns(s,h,o,i),is(s,h,o,i)}else{let m=new k(s,s),d=new Float64Array(s);for(c=0;c<s;c++)for(l=0;l<s;l++)m.set(l,c,a.get(l,c));rs(s,m,d,i),os(s,h,o,i,m)}this.n=s,this.e=h,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 n=this.n,e=this.e,t=this.d,s=new k(n,n),i,o;for(i=0;i<n;i++){for(o=0;o<n;o++)s.set(i,o,0);s.set(i,i,t[i]),e[i]>0?s.set(i,i+1,e[i]):e[i]<0&&s.set(i,i-1,e[i])}return s}}function ns(r,n,e,t){let s,i,o,h,a,l,c,u;for(a=0;a<r;a++)e[a]=t.get(r-1,a);for(h=r-1;h>0;h--){for(u=0,o=0,l=0;l<h;l++)u=u+Math.abs(e[l]);if(u===0)for(n[h]=e[h-1],a=0;a<h;a++)e[a]=t.get(h-1,a),t.set(h,a,0),t.set(a,h,0);else{for(l=0;l<h;l++)e[l]/=u,o+=e[l]*e[l];for(s=e[h-1],i=Math.sqrt(o),s>0&&(i=-i),n[h]=u*i,o=o-s*i,e[h-1]=s-i,a=0;a<h;a++)n[a]=0;for(a=0;a<h;a++){for(s=e[a],t.set(a,h,s),i=n[a]+t.get(a,a)*s,l=a+1;l<=h-1;l++)i+=t.get(l,a)*e[l],n[l]+=t.get(l,a)*s;n[a]=i}for(s=0,a=0;a<h;a++)n[a]/=o,s+=n[a]*e[a];for(c=s/(o+o),a=0;a<h;a++)n[a]-=c*e[a];for(a=0;a<h;a++){for(s=e[a],i=n[a],l=a;l<=h-1;l++)t.set(l,a,t.get(l,a)-(s*n[l]+i*e[l]));e[a]=t.get(h-1,a),t.set(h,a,0)}}e[h]=o}for(h=0;h<r-1;h++){if(t.set(r-1,h,t.get(h,h)),t.set(h,h,1),o=e[h+1],o!==0){for(l=0;l<=h;l++)e[l]=t.get(l,h+1)/o;for(a=0;a<=h;a++){for(i=0,l=0;l<=h;l++)i+=t.get(l,h+1)*t.get(l,a);for(l=0;l<=h;l++)t.set(l,a,t.get(l,a)-i*e[l])}}for(l=0;l<=h;l++)t.set(l,h+1,0)}for(a=0;a<r;a++)e[a]=t.get(r-1,a),t.set(r-1,a,0);t.set(r-1,r-1,1),n[0]=0}function is(r,n,e,t){let s,i,o,h,a,l,c,u,m,d,w,g,M,f,p,P;for(o=1;o<r;o++)n[o-1]=n[o];n[r-1]=0;let _=0,b=0,C=Number.EPSILON;for(l=0;l<r;l++){for(b=Math.max(b,Math.abs(e[l])+Math.abs(n[l])),c=l;c<r&&!(Math.abs(n[c])<=C*b);)c++;if(c>l)do{for(s=e[l],u=(e[l+1]-s)/(2*n[l]),m=ie(u,1),u<0&&(m=-m),e[l]=n[l]/(u+m),e[l+1]=n[l]*(u+m),d=e[l+1],i=s-e[l],o=l+2;o<r;o++)e[o]-=i;for(_=_+i,u=e[c],w=1,g=w,M=w,f=n[l+1],p=0,P=0,o=c-1;o>=l;o--)for(M=g,g=w,P=p,s=w*n[o],i=w*u,m=ie(u,n[o]),n[o+1]=p*m,p=n[o]/m,w=u/m,u=w*e[o]-p*s,e[o+1]=i+p*(w*s+p*e[o]),a=0;a<r;a++)i=t.get(a,o+1),t.set(a,o+1,p*t.get(a,o)+w*i),t.set(a,o,w*t.get(a,o)-p*i);u=-p*P*M*f*n[l]/d,n[l]=p*u,e[l]=w*u}while(Math.abs(n[l])>C*b);e[l]=e[l]+_,n[l]=0}for(o=0;o<r-1;o++){for(a=o,u=e[o],h=o+1;h<r;h++)e[h]<u&&(a=h,u=e[h]);if(a!==o)for(e[a]=e[o],e[o]=u,h=0;h<r;h++)u=t.get(h,o),t.set(h,o,t.get(h,a)),t.set(h,a,u)}}function rs(r,n,e,t){let s=0,i=r-1,o,h,a,l,c,u,m;for(u=s+1;u<=i-1;u++){for(m=0,l=u;l<=i;l++)m=m+Math.abs(n.get(l,u-1));if(m!==0){for(a=0,l=i;l>=u;l--)e[l]=n.get(l,u-1)/m,a+=e[l]*e[l];for(h=Math.sqrt(a),e[u]>0&&(h=-h),a=a-e[u]*h,e[u]=e[u]-h,c=u;c<r;c++){for(o=0,l=i;l>=u;l--)o+=e[l]*n.get(l,c);for(o=o/a,l=u;l<=i;l++)n.set(l,c,n.get(l,c)-o*e[l])}for(l=0;l<=i;l++){for(o=0,c=i;c>=u;c--)o+=e[c]*n.get(l,c);for(o=o/a,c=u;c<=i;c++)n.set(l,c,n.get(l,c)-o*e[c])}e[u]=m*e[u],n.set(u,u-1,m*h)}}for(l=0;l<r;l++)for(c=0;c<r;c++)t.set(l,c,l===c?1:0);for(u=i-1;u>=s+1;u--)if(n.get(u,u-1)!==0){for(l=u+1;l<=i;l++)e[l]=n.get(l,u-1);for(c=u;c<=i;c++){for(h=0,l=u;l<=i;l++)h+=e[l]*t.get(l,c);for(h=h/e[u]/n.get(u,u-1),l=u;l<=i;l++)t.set(l,c,t.get(l,c)+h*e[l])}}}function os(r,n,e,t,s){let i=r-1,o=0,h=r-1,a=Number.EPSILON,l=0,c=0,u=0,m=0,d=0,w=0,g=0,M=0,f,p,P,_,b,C,j,y,x,B,D,X,F,T,R;for(f=0;f<r;f++)for((f<o||f>h)&&(e[f]=s.get(f,f),n[f]=0),p=Math.max(f-1,0);p<r;p++)c=c+Math.abs(s.get(f,p));for(;i>=o;){for(_=i;_>o&&(w=Math.abs(s.get(_-1,_-1))+Math.abs(s.get(_,_)),w===0&&(w=c),!(Math.abs(s.get(_,_-1))<a*w));)_--;if(_===i)s.set(i,i,s.get(i,i)+l),e[i]=s.get(i,i),n[i]=0,i--,M=0;else if(_===i-1){if(j=s.get(i,i-1)*s.get(i-1,i),u=(s.get(i-1,i-1)-s.get(i,i))/2,m=u*u+j,g=Math.sqrt(Math.abs(m)),s.set(i,i,s.get(i,i)+l),s.set(i-1,i-1,s.get(i-1,i-1)+l),y=s.get(i,i),m>=0){for(g=u>=0?u+g:u-g,e[i-1]=y+g,e[i]=e[i-1],g!==0&&(e[i]=y-j/g),n[i-1]=0,n[i]=0,y=s.get(i,i-1),w=Math.abs(y)+Math.abs(g),u=y/w,m=g/w,d=Math.sqrt(u*u+m*m),u=u/d,m=m/d,p=i-1;p<r;p++)g=s.get(i-1,p),s.set(i-1,p,m*g+u*s.get(i,p)),s.set(i,p,m*s.get(i,p)-u*g);for(f=0;f<=i;f++)g=s.get(f,i-1),s.set(f,i-1,m*g+u*s.get(f,i)),s.set(f,i,m*s.get(f,i)-u*g);for(f=o;f<=h;f++)g=t.get(f,i-1),t.set(f,i-1,m*g+u*t.get(f,i)),t.set(f,i,m*t.get(f,i)-u*g)}else e[i-1]=y+u,e[i]=y+u,n[i-1]=g,n[i]=-g;i=i-2,M=0}else{if(y=s.get(i,i),x=0,j=0,_<i&&(x=s.get(i-1,i-1),j=s.get(i,i-1)*s.get(i-1,i)),M===10){for(l+=y,f=o;f<=i;f++)s.set(f,f,s.get(f,f)-y);w=Math.abs(s.get(i,i-1))+Math.abs(s.get(i-1,i-2)),y=x=.75*w,j=-.4375*w*w}if(M===30&&(w=(x-y)/2,w=w*w+j,w>0)){for(w=Math.sqrt(w),x<y&&(w=-w),w=y-j/((x-y)/2+w),f=o;f<=i;f++)s.set(f,f,s.get(f,f)-w);l+=w,y=x=j=.964}for(M=M+1,b=i-2;b>=_&&(g=s.get(b,b),d=y-g,w=x-g,u=(d*w-j)/s.get(b+1,b)+s.get(b,b+1),m=s.get(b+1,b+1)-g-d-w,d=s.get(b+2,b+1),w=Math.abs(u)+Math.abs(m)+Math.abs(d),u=u/w,m=m/w,d=d/w,!(b===_||Math.abs(s.get(b,b-1))*(Math.abs(m)+Math.abs(d))<a*(Math.abs(u)*(Math.abs(s.get(b-1,b-1))+Math.abs(g)+Math.abs(s.get(b+1,b+1))))));)b--;for(f=b+2;f<=i;f++)s.set(f,f-2,0),f>b+2&&s.set(f,f-3,0);for(P=b;P<=i-1&&(T=P!==i-1,P!==b&&(u=s.get(P,P-1),m=s.get(P+1,P-1),d=T?s.get(P+2,P-1):0,y=Math.abs(u)+Math.abs(m)+Math.abs(d),y!==0&&(u=u/y,m=m/y,d=d/y)),y!==0);P++)if(w=Math.sqrt(u*u+m*m+d*d),u<0&&(w=-w),w!==0){for(P!==b?s.set(P,P-1,-w*y):_!==b&&s.set(P,P-1,-s.get(P,P-1)),u=u+w,y=u/w,x=m/w,g=d/w,m=m/u,d=d/u,p=P;p<r;p++)u=s.get(P,p)+m*s.get(P+1,p),T&&(u=u+d*s.get(P+2,p),s.set(P+2,p,s.get(P+2,p)-u*g)),s.set(P,p,s.get(P,p)-u*y),s.set(P+1,p,s.get(P+1,p)-u*x);for(f=0;f<=Math.min(i,P+3);f++)u=y*s.get(f,P)+x*s.get(f,P+1),T&&(u=u+g*s.get(f,P+2),s.set(f,P+2,s.get(f,P+2)-u*d)),s.set(f,P,s.get(f,P)-u),s.set(f,P+1,s.get(f,P+1)-u*m);for(f=o;f<=h;f++)u=y*t.get(f,P)+x*t.get(f,P+1),T&&(u=u+g*t.get(f,P+2),t.set(f,P+2,t.get(f,P+2)-u*d)),t.set(f,P,t.get(f,P)-u),t.set(f,P+1,t.get(f,P+1)-u*m)}}}if(c!==0){for(i=r-1;i>=0;i--)if(u=e[i],m=n[i],m===0)for(_=i,s.set(i,i,1),f=i-1;f>=0;f--){for(j=s.get(f,f)-u,d=0,p=_;p<=i;p++)d=d+s.get(f,p)*s.get(p,i);if(n[f]<0)g=j,w=d;else if(_=f,n[f]===0?s.set(f,i,j!==0?-d/j:-d/(a*c)):(y=s.get(f,f+1),x=s.get(f+1,f),m=(e[f]-u)*(e[f]-u)+n[f]*n[f],C=(y*w-g*d)/m,s.set(f,i,C),s.set(f+1,i,Math.abs(y)>Math.abs(g)?(-d-j*C)/y:(-w-x*C)/g)),C=Math.abs(s.get(f,i)),a*C*C>1)for(p=f;p<=i;p++)s.set(p,i,s.get(p,i)/C)}else if(m<0)for(_=i-1,Math.abs(s.get(i,i-1))>Math.abs(s.get(i-1,i))?(s.set(i-1,i-1,m/s.get(i,i-1)),s.set(i-1,i,-(s.get(i,i)-u)/s.get(i,i-1))):(R=xt(0,-s.get(i-1,i),s.get(i-1,i-1)-u,m),s.set(i-1,i-1,R[0]),s.set(i-1,i,R[1])),s.set(i,i-1,0),s.set(i,i,1),f=i-2;f>=0;f--){for(B=0,D=0,p=_;p<=i;p++)B=B+s.get(f,p)*s.get(p,i-1),D=D+s.get(f,p)*s.get(p,i);if(j=s.get(f,f)-u,n[f]<0)g=j,d=B,w=D;else if(_=f,n[f]===0?(R=xt(-B,-D,j,m),s.set(f,i-1,R[0]),s.set(f,i,R[1])):(y=s.get(f,f+1),x=s.get(f+1,f),X=(e[f]-u)*(e[f]-u)+n[f]*n[f]-m*m,F=(e[f]-u)*2*m,X===0&&F===0&&(X=a*c*(Math.abs(j)+Math.abs(m)+Math.abs(y)+Math.abs(x)+Math.abs(g))),R=xt(y*d-g*B+m*D,y*w-g*D-m*B,X,F),s.set(f,i-1,R[0]),s.set(f,i,R[1]),Math.abs(y)>Math.abs(g)+Math.abs(m)?(s.set(f+1,i-1,(-B-j*s.get(f,i-1)+m*s.get(f,i))/y),s.set(f+1,i,(-D-j*s.get(f,i)-m*s.get(f,i-1))/y)):(R=xt(-d-x*s.get(f,i-1),-w-x*s.get(f,i),g,m),s.set(f+1,i-1,R[0]),s.set(f+1,i,R[1]))),C=Math.max(Math.abs(s.get(f,i-1)),Math.abs(s.get(f,i))),a*C*C>1)for(p=f;p<=i;p++)s.set(p,i-1,s.get(p,i-1)/C),s.set(p,i,s.get(p,i)/C)}for(f=0;f<r;f++)if(f<o||f>h)for(p=f;p<r;p++)t.set(f,p,s.get(f,p));for(p=r-1;p>=o;p--)for(f=o;f<=h;f++){for(g=0,P=o;P<=Math.min(p,h);P++)g=g+t.get(f,P)*s.get(P,p);t.set(f,p,g)}}}function xt(r,n,e,t){let s,i;return Math.abs(e)>Math.abs(t)?(s=t/e,i=e+s*t,[(r+s*n)/i,(n-s*r)/i]):(s=e/t,i=t+s*e,[(s*r+n)/i,(s*n-r)/i])}function zt(r,n,e){const t=r/e,s=n/e;if(!(isFinite(t)&&isFinite(s))){const a=-r/n;return isFinite(a)?[a]:r==0&&n==0?[0]:[]}const i=s*s-4*t;let o=0;if(isFinite(i)){if(i<0)return[];if(i==0)return[-.5*s];o=-.5*(s+yt(Math.sqrt(i),s))}else o=-s;const h=t/o;return isFinite(h)?h>o?[o,h]:[h,o]:[o]}function me(r,n,e,t){const s=e/(3*t),i=n/(3*t),o=r/t;if(!(isFinite(o)&&isFinite(i)&&isFinite(s)))return zt(r,n,e);const h=-s*s+i,a=-i*s+o,l=s*o-i*i,c=4*h*l-a*a,u=-2*s*h+a;if(c<0){const m=Math.sqrt(-.25*c),d=-.5*u;return[Math.cbrt(d+m)+Math.cbrt(d-m)-s]}else if(c==0){const m=yt(Math.sqrt(-h),u);return[m-s,-2*m-s]}else{const m=Math.atan2(Math.sqrt(c),-u)/3,d=Math.cos(m),w=Math.sin(m)*Math.sqrt(3),g=.5*(-d+w),M=.5*(-d-w),f=2*Math.sqrt(-h);return[f*d-s,f*g-s,f*M-s]}}function hs(r,n,e,t,s){if(s==0)return me(r,n,e,t);const i=t/s,o=e/s,h=n/s,a=r/s;let l=re(i,o,h,a,!1);if(l!==null)return l;const c=716e74;for(let u=0;u<2;u++)if(l=re(i/c,o/(c*c),h/(c*c*c),a/(c*c*c*c),u!=0),l!==null){for(let m=0;m<l.length;m++)l[m]*=c;return l}return[]}function lt(r,n){return n==0?Math.abs(r):Math.abs((r-n)/n)}function re(r,n,e,t,s){const i=ls(r,n,e,t,s);if(i!==null&&i.length==4){let o=[];for(let h=0;h<2;h++){const a=i[h*2],l=i[h*2+1];o=o.concat(zt(l,a,1))}return o}return null}function ls(r,n,e,t,s){function i(q,$,v,L){const z=lt(q+v,r),A=lt($+q*v+L,n),U=lt($*v+q*L,e);return z+A+U}function o(q,$,v,L){return i(q,$,v,L)+lt($*L,t)}const h=9*r*r-24*n,a=h>=0?-2*n/(3*r+yt(Math.sqrt(h),r)):-.25*r,l=r+4*a,c=n+3*a*(r+2*a),u=e+a*(2*n+a*(3*r+4*a)),m=t+a*(e+a*(n+a*(r+a)));let d=0,w=0;const g=349e100;if(s){const q=l/g,$=c/g,v=u/g,L=m/g;d=q*v-4/g*L-1/3*$*$,w=(q*v-8/g*L-2/9*$*$)*(1/3)*$-v*(v/g)-q*q*L}else d=l*u-4*m-1/3*c*c,w=(l*u+8*m-2/9*c*c)*(1/3)*c-u*u-l*l*m;if(!isFinite(d)&&isFinite(w))return null;let M=as(d,w);s&&(M*=g);const f=r*.5,p=1/6*n+.5*M,P=e-r*p,_=2/3*n-M-f*f,b=.5*P/_,C=2*(t-p*p)/P,j=.5*P/C;let y=0,x=0,B=0;for(let q=0;q<3;q++){const $=q==1?j:_,v=q==0?b:C,L=lt($+f*f+2*p,n),z=lt(2*($*v+f*p),e),A=lt($*v*v+p*p,t),U=L+z+A;(q==0||U<B)&&(y=$,x=v,B=U)}const D=y,X=x;let F=0,T=0,R=0,S=0;if(D<0){const q=Math.sqrt(-D);if(F=f+q,T=p+q*X,R=f-q,S=p-q*X,Math.abs(S)<Math.abs(T)?S=t/T:Math.abs(S)>Math.abs(T)&&(T=t/S),Math.abs(F)!=Math.abs(R)){let $=null,v=null;if(Math.abs(F)<Math.abs(R)){const z=(e-T*R)/S,A=(n-S-T)/R;$=[r-R,z,A],v=[R,R,R]}else{const z=(e-F*S)/T,A=(n-S-T)/F,U=r-F;$=[F,F,F],v=[U,z,A]}let L=0;for(let z=0;z<3;z++){const A=$[z],U=v[z];if(isFinite(A)&&isFinite(U)){const nt=i(A,T,U,S);(z==0||nt<L)&&(F=A,R=U,L=nt)}}}}else if(D==0){const q=t-p*p;F=f,T=p+Math.sqrt(-q),R=f,S=p-Math.sqrt(-q),Math.abs(T)>Math.abs(S)?S=t/T:Math.abs(S)>Math.abs(T)&&(T=t/S)}else return[];let rt=o(F,T,R,S);for(let q=0;q<8&&rt!=0;q++){const $=T*S-t,v=T*R+F*S-e,L=T+F*R+S-n,z=F+R-r,A=F-R,U=T*T-T*(R*A+2*S)+S*(F*A+S);if(U==0)break;const nt=1/U,tt=S-T,ot=T*R-F*S,Vt=A*$+tt*v+ot*L-(T*tt+F*ot)*z,Dt=(F*A+tt)*$-T*(A*v+tt*L+ot*z),Ot=-A*$-tt*v-ot*L+(R*ot+S*tt)*z,Yt=-(R*A+tt)*$+S*(A*v+tt*L+ot*z),St=F-nt*Vt,Rt=T-nt*Dt,kt=R-nt*Ot,Tt=S-nt*Yt,vt=o(St,Rt,kt,Tt);if(vt<rt)F=St,T=Rt,R=kt,S=Tt,rt=vt;else break}return[F,T,R,S]}function as(r,n){const e=-.3333333333333333*r,t=.5*n;let s,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?s=0:s=Math.sqrt(-r);else if(i!==null?i<0:t*t<e*e*e){const l=i!==null?t/e/Math.sqrt(e):t/Math.sqrt(e*e*e);s=-2*Math.sqrt(e)*yt(Math.cos(Math.acos(Math.abs(l))*(1/3)),l)}else{let l;i!==null?Math.abs(e)<Math.abs(t)?l=-t*(1+Math.sqrt(i)):l=-t-yt(Math.sqrt(Math.abs(e))*e*Math.sqrt(i),t):l=Math.cbrt(-t-yt(Math.sqrt(t*t-e*e*e),t));const c=l==0?0:e/l;s=l+c}let o=s,h=(o*o+r)*o+n;const a=222045e-21;if(Math.abs(h)<a*Math.max(o*o*o,r*o,n))return o;for(let l=0;l<8;l++){const c=3*o*o+r;if(c==0)break;const u=o-h/c,m=(u*u+r)*u+n;if(m==0)return u;if(Math.abs(m)>=Math.abs(h))break;o=u,h=m}return o}function yt(r,n){const e=Math.abs(r);return n<0?-e:e}function ge(r,n=1e-9){if(r[r.length-1]==0)return ge(r.slice(0,-1),n);const e=new k([r.slice(0,-1).reverse().map(s=>-s/r[r.length-1]),...Array.from({length:r.length-2},(s,i)=>{const o=new Array(r.length-1).fill(0);return o[i]=1,o})]),t=new ss(e);return t.realEigenvalues.filter((s,i)=>Math.abs(t.imaginaryEigenvalues[i])<n)}const us=(r,n,e)=>[r[0]*(1-e)+n[0]*e,r[1]*(1-e)+n[1]*e];function cs(r){const n=[];for(let e=0;e<r.length-1;e++)n.push([r[e],r[e+1]]);return n}function Zt(r,n){const e=cs(r).map(([t,s])=>us(t,s,n));return r.length===2?[e]:[...Zt(e,n),e]}class at extends bt{constructor(e,t,s,i){super(e,t);E(this,"segmentType","CUBIC_BEZIER");E(this,"firstControlPoint");E(this,"lastControlPoint");E(this,"_boundingBox",null);E(this,"_polynomialCoefficients",null);this.firstControlPoint=s,this.lastControlPoint=i}get midPoint(){return this.paramPoint(.5)}get boundingBox(){if(this._boundingBox===null){const e=t=>{const[s,i,o,h]=[this.firstPoint[t],this.firstControlPoint[t],this.lastControlPoint[t],this.lastPoint[t]],a=-s+3*i-3*o+h,l=2*s-4*i+2*o,c=-s+i;return zt(c,l,a).filter(u=>u>=-this.precision&&u<=1+this.precision)};this._boundingBox=Ut([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 at(this.firstPoint,this.lastPoint,this.firstControlPoint,this.lastControlPoint)}reverse(){return new at(this.lastPoint,this.firstPoint,this.lastControlPoint,this.firstControlPoint)}isSame(e){return e.segmentType!=="CUBIC_BEZIER"?!1:N(this.firstPoint,e.firstPoint)&&N(this.lastPoint,e.lastPoint)&&N(this.firstControlPoint,e.firstControlPoint)&&N(this.lastControlPoint,e.lastControlPoint)}distanceFrom(e){const s=ue(i=>gt(this.paramPoint(i),e),this.precision);return s.argMin<-this.precision||s.argMin>1+this.precision?Math.min(Y(this.firstPoint,e),Y(this.lastPoint,e)):Math.sqrt(s.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,s=t*t,i=e*e,o=3*s,h=6*t*e,a=3*i,l=V(this.firstControlPoint,this.firstPoint),c=V(this.lastControlPoint,this.firstControlPoint),u=V(this.lastPoint,this.lastControlPoint);return[o*l[0]+h*c[0]+a*u[0],o*l[1]+h*c[1]+a*u[1]]}tangentAt(e){const t=this.pointToParam(e);return G(this.gradientAt(t))}get tangentAtFirstPoint(){return G(V(this.firstControlPoint,this.firstPoint))}get tangentAtLastPoint(){return G(V(this.lastControlPoint,this.lastPoint))}normalAt(e){const t=this.tangentAt(e);return K(t)}splitAtParameters(e,t=null){const s=[...e];s.sort((o,h)=>o-h);let i={originalParam:0,param:0,p0:this.firstPoint,p1:this.firstControlPoint,p2:this.lastControlPoint};return s.flatMap((o,h)=>{if(o-i.originalParam<this.precision)return[];let a=!1;o>1-this.precision&&(a=!0);const l=(o-i.originalParam)/(1-i.originalParam),c=Zt([i.p0,i.p1,i.p2,this.lastPoint],a?1:l),u=a?this.lastPoint:(t==null?void 0:t.get(o))??c[0][0],m=c[1][0],d=c[2][0],w=c[1][1],g=c[2][2],M=new at(i.p0,u,d,m);return i={param:l,originalParam:o,p0:u,p1:w,p2:g},h===s.length-1&&!a?[M,new at(i.p0,this.lastPoint,i.p1,i.p2)]:M})}splitAt(e){let t;if(Array.isArray(e)&&e.length===0)return[this];Array.isArray(e[0])?t=e:t=[e];const s=t.map(o=>this.pointToParam(o)),i=new Map(jt([s,t]));return this.splitAtParameters(s,i)}transform(e){return new at(e.transform(this.firstPoint),e.transform(this.lastPoint),e.transform(this.firstControlPoint),e.transform(this.lastControlPoint))}paramPoint(e){const t=1-e,s=t*t,i=e*e,o=s*t,h=3*s*e,a=3*t*i,l=i*e;return[o*this.firstPoint[0]+h*this.firstControlPoint[0]+a*this.lastControlPoint[0]+l*this.lastPoint[0],o*this.firstPoint[1]+h*this.firstControlPoint[1]+a*this.lastControlPoint[1]+l*this.lastPoint[1]]}get polynomialCoefficients(){if(this._polynomialCoefficients===null){const e=t=>{const s=this.firstPoint[t],i=this.firstControlPoint[t],o=this.lastControlPoint[t],h=this.lastPoint[t],a=-s+3*i-3*o+h,l=3*s-6*i+3*o,c=-3*s+3*i;return[s,c,l,a]};this._polynomialCoefficients=[e(0),e(1)]}return this._polynomialCoefficients}paramsAtY(e){const[t,s,i,o]=this.polynomialCoefficients[1];return me(t-e,s,i,o).filter(h=>h>=-this.precision&&h<=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 s=o=>Math.abs(this.paramPoint(o)[0]-e[0])<=this.precision,i=t.find(s);if(i===void 0)throw new Error("Point is not on the curve");return i}}class ft extends bt{constructor(e,t,s,i,o,h,a=!1,{ignoreChecks:l=!1,angleUnits:c="deg"}={}){super(e,t);E(this,"segmentType","ELLIPSE_ARC");E(this,"precision",1e-6);E(this,"majorRadius");E(this,"minorRadius");E(this,"center");E(this,"tiltAngle");E(this,"clockwise");E(this,"_coefficients",null);E(this,"_boundingBox");E(this,"_linearExentricity");E(this,"_exentricity");E(this,"_focals");E(this,"_ellipseReferenceFrameTransform");E(this,"_reverseEllipseReferenceFrameTransform");E(this,"_rotateFromEllipseReferenceFrame");E(this,"_firstAngle");E(this,"_lastAngle");E(this,"_deltaAngle");this.center=s;const u=i>=o;this.majorRadius=u?i:o,this.minorRadius=u?o:i;const m=c==="deg"?h*Bt:h;if(this.tiltAngle=ct(u?m:m+Math.PI/2),this.clockwise=a,!l){if(N(e,t))throw new Error("Invalid arc, cannot be a full circle");if(!this.isPointOnEllipse(e))throw new Error(`First point ${O(e)} not on the ellipse defined by ${this.info}`);if(!this.isPointOnEllipse(t))throw new Error(`Last point ${O(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,s=this.majorRadius*this.majorRadius,i=this.minorRadius*this.minorRadius,o=Math.cos(this.tiltAngle),h=Math.sin(this.tiltAngle),a=s*h*h+i*o*o,l=2*(i-s)*h*o,c=s*o*o+i*h*h;this._coefficients={x2:a,xy:l,y2:c,x:-2*a*e-l*t,y:-2*c*t-l*e,c:a*e*e+l*e*t+c*t*t-s*i}}return this._coefficients}get info(){return`ELLIPSE_ARC(${O(this.firstPoint)}, ${O(this.lastPoint)}, ${O(this.center)}, ${this.majorRadius}, ${this.minorRadius}, ${this.tiltAngle*oe}, ${this.clockwise?"CW":"CCW"})`}reverse(){return new ft(this.lastPoint,this.firstPoint,this.center,this.majorRadius,this.minorRadius,this.tiltAngle,!this.clockwise,{ignoreChecks:!0,angleUnits:"rad"})}clone(){return new ft(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,s=-Math.atan(t*e),i=Math.atan(t/e);return[s,Math.PI+s,i,Math.PI+i].map(h=>this.thetaToParam(h)).filter(h=>this.isValidParameter(h)).map(h=>this.paramPoint(h))}get boundingBox(){if(this._boundingBox===void 0){const e=this.computeEllipseExtrema(),t=[this.firstPoint,this.lastPoint,...e];this._boundingBox=Ut(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=[st(this.center,ht(e,this.linearExentricity)),st(this.center,ht(e,-this.linearExentricity))]}return this._focals}get majorAxis(){return Mt(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 ${O(e)} not on the ellipse defined by ${this.repr}`);const t=this.thetaToParam(this.pointTheta(e));if(!this.isValidParameter(t))throw new Error(`Point ${O(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 N(this.center,e.center)&&Math.abs(this.majorRadius-e.majorRadius)<this.precision&&Math.abs(this.minorRadius-e.minorRadius)<this.precision&&(Math.abs(this.tiltAngle-e.tiltAngle)<this.precision||Math.abs(Math.abs(this.tiltAngle-e.tiltAngle)-Math.PI)<this.precision)&&(N(this.firstPoint,e.firstPoint)&&this.clockwise===e.clockwise||N(this.firstPoint,e.lastPoint)&&this.clockwise!==e.clockwise)}pointTheta(e){const t=this.ellipseReferenceFrameTransform.transform(e),s=Math.atan2(t[1]/this.minorRadius,t[0]/this.majorRadius);return ct(s)}thetaToParam(e){return Nt(this.firstAngle,ct(e),this.clockwise)/this.deltaAngle}isPointOnEllipse(e){const[t,s]=this.focals,i=Y(e,t),o=Y(e,s);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(N(e,this.center)?t=st(this.center,ht(K(this.majorAxis),this.minorRadius)):t=this.reverseEllipseReferenceFrameTransform.transform(gs(this.majorRadius,this.minorRadius,this.ellipseReferenceFrameTransform.transform(e))),this.isValidParameter(this.thetaToParam(this.pointTheta(e))))return Y(e,t);if(Pe(e,this.majorAxis,this.center)){const s=ct(2*Math.PI-this.pointTheta(e)),i=this.thetaToParam(s);if(this.isValidParameter(i))return Y(e,this.paramPoint(i))}return Math.min(Y(e,this.firstPoint),Y(e,this.lastPoint))}get ellipseReferenceFrameTransform(){return this._ellipseReferenceFrameTransform===void 0&&(this._ellipseReferenceFrameTransform=new W().rotate(-this.tiltAngle).translate(-this.center[0],-this.center[1])),this._ellipseReferenceFrameTransform}get reverseEllipseReferenceFrameTransform(){return this._reverseEllipseReferenceFrameTransform===void 0&&(this._reverseEllipseReferenceFrameTransform=new W().translate(this.center[0],this.center[1]).rotate(this.tiltAngle)),this._reverseEllipseReferenceFrameTransform}get rotateFromEllipseReferenceFrame(){return this._rotateFromEllipseReferenceFrame===void 0&&(this._rotateFromEllipseReferenceFrame=new W().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=Nt(this.firstAngle,this.lastAngle,this.clockwise)),this._deltaAngle}normalAt(e){const t=this.tangentAt(e);return this.clockwise?K(t):_t(t)}gradientAt(e){const t=this.firstAngle+e*this.deltaAngle*(this.clockwise?-1:1),s=-this.majorRadius*this.deltaAngle*Math.sin(t),i=this.minorRadius*this.deltaAngle*Math.cos(t),o=this.clockwise?[-s,-i]:[s,i];return this.rotateFromEllipseReferenceFrame.transform(o)}tangentAt(e){const t=this.pointTheta(e),s=-this.majorRadius*Math.sin(t),i=this.minorRadius*Math.cos(t),o=this.clockwise?[-s,-i]:[s,i];return G(this.rotateFromEllipseReferenceFrame.transform(o))}get tangentAtFirstPoint(){const e=-this.majorRadius*Math.sin(this.firstAngle),t=this.minorRadius*Math.cos(this.firstAngle),s=this.clockwise?[-e,-t]:[e,t];return G(this.rotateFromEllipseReferenceFrame.transform(s))}get tangentAtLastPoint(){const e=-this.majorRadius*Math.sin(this.lastAngle),t=this.minorRadius*Math.cos(this.lastAngle),s=this.clockwise?[-e,-t]:[e,t];return G(this.rotateFromEllipseReferenceFrame.transform(s))}transform(e){const t=e.transformAngle(this.tiltAngle),s=e.scaleFactor();return new ft(e.transform(this.firstPoint),e.transform(this.lastPoint),e.transform(this.center),this.majorRadius*s,this.minorRadius*s,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(a=>this.pointToParam(a))],o=new Map(jt([i,[this.firstPoint,this.lastPoint,...t]]));i.sort((a,l)=>a-l);let h=null;return i.flatMap((a,l)=>{if(l===i.length-1)return[];const c=i[l+1];if(c-a<this.precision)return h===null&&(h=a),[];const u=h===null?a:h,m=new ft(o.get(u)||this.paramPoint(u),o.get(c)||this.paramPoint(c),this.center,this.majorRadius,this.minorRadius,this.tiltAngle,this.clockwise,{angleUnits:"rad"});return h=null,m})}}function fs(r,n,e,t,s,i,o){const{center:h,rx:a,ry:l}=ms(r,n,e,t,s*Bt,!i,o);return Math.abs(a-l)<1e-9?new et(r,n,h,o):new ft(r,n,h,a,l,s,o)}function ms([r,n],[e,t],s,i,o,h,a){if(s<0&&(s=-s),i<0&&(i=-i),s==0||i==0)throw Error("rx and ry can not be 0");const l=Math.sin(o),c=Math.cos(o),u=(r-e)/2,m=(n-t)/2,d=(r+e)/2,w=(n+t)/2,g=c*u+l*m,M=c*m-l*u,f=g*g/(s*s)+M*M/(i*i);f>1&&(s=s*Math.sqrt(f),i=i*Math.sqrt(f));const p=s*i,P=s*M,_=i*g,b=P*P+_*_;if(!b)throw Error("start point can not be same as end point");let C=Math.sqrt(Math.abs((p*p-b)/b));h==a&&(C=-C);const j=C*P/i,y=-C*_/s,x=c*j-l*y+d,B=l*j+c*y+w;return{center:[x,B],rx:s,ry:i}}function gs(r,n,e){const t=Math.abs(e[0]),s=Math.abs(e[1]);let i=.707,o=.707;const h=r,a=n;for(let l=0;l<3;l++){const c=h*i,u=a*o,m=(h*h-a*a)*i**3/h,d=(a*a-h*h)*o**3/a,w=c-m,g=u-d,M=t-m,f=s-d,p=Math.hypot(w,g),P=Math.hypot(M,f);i=Math.min(1,Math.max(0,(M*p/P+m)/h)),o=Math.min(1,Math.max(0,(f*p/P+d)/a));const _=Math.hypot(i,o);i/=_,o/=_}return[h*i*Math.sign(e[0]),a*o*Math.sign(e[1])]}class ut extends bt{constructor(e,t,s){super(e,t);E(this,"segmentType","QUADRATIC_BEZIER");E(this,"controlPoint");E(this,"_boundingBox",null);E(this,"_polynomialCoefficients",null);this.controlPoint=s}get midPoint(){return this.paramPoint(.5)}get boundingBox(){if(this._boundingBox===null){const e=t=>{const[s,i,o]=[this.firstPoint[t],this.controlPoint[t],this.lastPoint[t]],h=s-2*i+o;if(!h)return[];const a=(s-i)/h;return a>=-this.precision&&a<=1+this.precision?[a]:[]};this._boundingBox=Ut([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 ut(this.firstPoint,this.lastPoint,this.controlPoint)}reverse(){return new ut(this.lastPoint,this.firstPoint,this.controlPoint)}isSame(e){return e.segmentType!=="QUADRATIC_BEZIER"?!1:N(this.firstPoint,e.firstPoint)&&N(this.lastPoint,e.lastPoint)&&N(this.controlPoint,e.controlPoint)}distanceFrom(e){const s=ue(i=>gt(this.paramPoint(i),e),this.precision);return s.argMin<-this.precision||s.argMin>1+this.precision?Math.min(Y(this.firstPoint,e),Y(this.lastPoint,e)):Math.sqrt(s.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=s=>{const i=this.firstPoint[s],o=this.controlPoint[s],h=this.lastPoint[s];return 2*(e*(i-2*o+h)-i+o)};return[t(0),t(1)]}tangentAt(e){const t=this.pointToParam(e);return G(this.gradientAt(t))}get tangentAtFirstPoint(){return G(V(this.controlPoint,this.firstPoint))}get tangentAtLastPoint(){return G(V(this.controlPoint,this.lastPoint))}normalAt(e){const t=this.tangentAt(e);return K(t)}splitAtParameters(e,t=null){const s=[...e];s.sort((o,h)=>o-h);let i={originalParam:0,param:0,p0:this.firstPoint,p1:this.controlPoint};return s.flatMap((o,h)=>{if(o-i.originalParam<this.precision)return[];let a=!1;o>1-this.precision&&(a=!0);const l=(o-i.originalParam)/(1-i.originalParam),c=Zt([i.p0,i.p1,this.lastPoint],a?1:l),u=a?this.lastPoint:(t==null?void 0:t.get(o))??c[0][0],m=c[1][0],d=c[1][1],w=new ut(i.p0,u,m);return i={param:l,originalParam:o,p0:u,p1:d},h===s.length-1&&!a?[w,new ut(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 s=t.map(o=>this.pointToParam(o)),i=new Map(jt([s,t]));return this.splitAtParameters(s,i)}transform(e){return new ut(e.transform(this.firstPoint),e.transform(this.lastPoint),e.transform(this.controlPoint))}paramPoint(e){const t=1-e,s=t*t,i=2*t*e,o=e*e;return[s*this.firstPoint[0]+i*this.controlPoint[0]+o*this.lastPoint[0],s*this.firstPoint[1]+i*this.controlPoint[1]+o*this.lastPoint[1]]}get polynomialCoefficients(){if(this._polynomialCoefficients===null){const e=t=>{const s=this.firstPoint[t],i=this.controlPoint[t],o=this.lastPoint[t],h=s-2*i+o,a=2*(i-s);return[s,a,h]};this._polynomialCoefficients=[e(0),e(1)]}return this._polynomialCoefficients}paramsAtY(e){const[t,s,i]=this.polynomialCoefficients[1];return zt(t-e,s,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 s=o=>Math.abs(this.paramPoint(o)[0]-e[0])<=this.precision,i=t.find(s);if(i===void 0)throw new Error("Point is not on the curve");return i}}exports.Arc=et;exports.BoundingBox=it;exports.CubicBezier=at;exports.DEG2RAD=Bt;exports.EllipseArc=ft;exports.Line=H;exports.QuadraticBezier=ut;exports.RAD2DEG=oe;exports.Transformable=ae;exports.TransformationMatrix=W;exports.add=st;exports.cartesianToPolar=le;exports.crossProduct=mt;exports.distance=Y;exports.dotProduct=Gt;exports.length=de;exports.lineLineIntersection=_e;exports.lineLineParams=Lt;exports.normalize=G;exports.parallel=Xt;exports.perpendicular=K;exports.perpendicularClockwise=_t;exports.polarAngle=he;exports.polarToCartesian=Mt;exports.removeDuplicatePoints=Wt;exports.reprVector=O;exports.sameVector=N;exports.scalarMultiply=ht;exports.solveGenericPolynomial=ge;exports.solveQuartic=hs;exports.squareDistance=gt;exports.squareLength=Et;exports.subtract=V;exports.svgEllipse=fs;exports.tangentArc=je;exports.threePointsArc=be;exports.zip=jt;
|
|
9
|
-
//# sourceMappingURL=QuadraticBezier-e3d7218b.cjs.map
|