UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) • 22.7 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{g as t,t as s,a as o}from"./Geometry.js";import{m as i,P as e,s as h,M as r,a,b as l}from"./Point2D.js";class y{constructor(t,s,o){if(t instanceof y)return this.data=t.data,this.N=t.N,this.M=t.M,t.data=null,t.N=0,void(t.M=0);this.data=t,this.N=s,this.M=o}assignCopy(s){return this===s||(t(this.N*this.M==s.N*s.M),this.data.set(s.data),this.N=s.N,this.M=s.M),this}setZero(){return this.data?.fill(0),this}setIdentity(){const t=0,s=1;for(let o=0;o<this.N;o++)for(let i=0;i<this.M;i++)this.setRowCol(o,i,o===i?s:t);return this}rows(){return this.N}cols(){return this.M}row(s){return t(0),{}}set(t,s){return this.data[t]=s,this}setRowCol(t,s,o){return this.data[t*this.M+s]=o,this}at(t){return this.data[t]}atRowCol(t,s){return this.data[t*this.M+s]}mulScalar(s,o){t(0)}mul(s,o){if(t(this.M===s.rows()),t(this.N===o.rows()),t(s.cols()===o.cols()),o===this){const t=new Float64Array(this.N*this.M),i=new y(t,this.N,this.M);return this.mul(s,i),void o.assignCopy(i)}if(o===s){const t=new Float64Array(s.N*s.M),i=new y(t,s.N,s.M);return this.mul(s,i),void o.assignCopy(i)}const i=s.cols();for(let t=0;t<this.N;t++)for(let e=0;e<i;e++){let i=0;for(let o=0;o<this.M;o++)i+=this.atRowCol(t,o)*s.atRowCol(o,e);o.setRowCol(t,e,i)}}mulTranspose(s,o){if(t(this.M===s.cols()),t(this.N===o.rows()),t(s.rows()===o.cols()),o===this){const t=new Float64Array(this.N*this.M),i=new y(t,this.N,this.M);return this.mulTranspose(s,i),void o.assignCopy(i)}if(o===s){const t=new Float64Array(s.N*s.M),i=new y(t,s.N,s.M);return this.mulTranspose(s,i),void o.assignCopy(i)}const i=s.rows();for(let t=0;t<this.N;t++)for(let e=0;e<i;e++){let i=0;for(let o=0;o<this.M;o++)i+=this.atRowCol(t,o)*s.atRowCol(e,o);o.setRowCol(t,e,i)}}mulLeft(s,o){t(0)}mulLeftTranspose(s,o){t(0)}mulDiag(s,o){if(t(this.M===s.N*s.M),t(this.N===o.rows()),t(this.M===o.cols()),o===this){const t=new Float64Array(this.N*this.M),i=new y(t,this.N,this.M);return this.mulDiag(s,i),void o.assignCopy(i)}const i=this.M;for(let t=0;t<this.N;t++)for(let e=0;e<i;e++)o.setRowCol(t,e,this.atRowCol(t,e)*s.at(e))}transposeInPlace(){if(this.N===this.M){for(let t=0;t<this.N;t++)for(let s=t+1;s<this.M;s++){const o=this.atRowCol(t,s);this.setRowCol(t,s,this.atRowCol(s,t)),this.setRowCol(s,t,o)}return this}const t=new Float64Array(this.N*this.M),s=new y(t,this.N,this.M);return s.assignCopy(this),this.M=l(this.N,this.N=this.M),s.transpose(this),this}transpose(t){if(this!==t){y.checkDims(t,this.M,this.N);for(let s=0;s<this.N;s++)for(let o=0;o<this.M;o++)t.setRowCol(o,s,this.atRowCol(s,o))}else t.transposeInPlace()}add(t,s){}svd(s,o,i,e=!1){if(y.checkDims(s,this.N,this.M),y.checkDims(o,this.M,1),y.checkDims(i,this.M,this.M),e){if(t(this.N===this.M),!this.symmetricEigen(o,i))return!1;for(let t=0;t<this.M;++t)o.at(t)<0&&o.set(t,0);return s.assignCopy(i),!0}let h,r,a,l,n,x,w,u=0,C=0,f=0,R=0,d=0;const c=this.M,M=this.N;s.assignCopy(this);const m=new Float64Array(c),N=new y(m,c,1),b=(t,s)=>s>=0?Math.abs(t):-Math.abs(t),p=(t,s)=>{if((t=Math.abs(t))>(s=Math.abs(s))){const o=s/t;return t*Math.sqrt(o*o+1)}if(s>0){const o=t/s;return s*Math.sqrt(o*o+1)}return 0};for(let t=0;t<c;t++){if(u=t+1,N.set(t,R*f),f=l=R=0,t<M){for(let o=t;o<M;o++)R+=Math.abs(s.atRowCol(o,t));if(R){for(let o=t;o<M;o++)s.setRowCol(o,t,s.atRowCol(o,t)/R),l+=s.atRowCol(o,t)*s.atRowCol(o,t);r=s.atRowCol(t,t),f=-b(Math.sqrt(l),r),a=r*f-l,s.setRowCol(t,t,r-f);for(let o=u;o<c;o++){l=0;for(let i=t;i<M;i++)l+=s.atRowCol(i,t)*s.atRowCol(i,o);r=l/a;for(let i=t;i<M;i++)s.setRowCol(i,o,s.atRowCol(i,o)+r*s.atRowCol(i,t))}for(let o=t;o<M;o++)s.setRowCol(o,t,s.atRowCol(o,t)*R)}}if(o.set(t,R*f),f=l=R=0,t<M&&t!==c-1){for(let o=u;o<c;o++)R+=Math.abs(s.atRowCol(t,o));if(R){for(let o=u;o<c;o++)s.setRowCol(t,o,s.atRowCol(t,o)/R),l+=s.atRowCol(t,o)*s.atRowCol(t,o);r=s.atRowCol(t,u),f=-b(Math.sqrt(l),r),a=r*f-l,s.setRowCol(t,u,r-f);for(let o=u;o<c;o++)N.set(o,s.atRowCol(t,o)/a);for(let o=u;o<M;o++){l=0;for(let i=u;i<c;i++)l+=s.atRowCol(o,i)*s.atRowCol(t,i);for(let t=u;t<c;t++)s.setRowCol(o,t,s.atRowCol(o,t)+l*N.at(t))}for(let o=u;o<c;o++)s.setRowCol(t,o,s.atRowCol(t,o)*R)}}const i=Math.abs(o.at(t))+Math.abs(N.at(t));d=i>d?i:d}for(let t=c-1;t>=0;t--){if(t<c-1){if(f){for(let o=u;o<c;o++)i.setRowCol(o,t,s.atRowCol(t,o)/s.atRowCol(t,u)/f);for(let o=u;o<c;o++){l=0;for(let e=u;e<c;e++)l+=s.atRowCol(t,e)*i.atRowCol(e,o);for(let s=u;s<c;s++)i.setRowCol(s,o,i.atRowCol(s,o)+l*i.atRowCol(s,t))}}for(let s=u;s<c;s++)i.setRowCol(t,s,0),i.setRowCol(s,t,0)}i.setRowCol(t,t,1),f=N.at(t),u=t}for(let t=(M<c?M:c)-1;t>=0;t--){u=t+1,f=o.at(t);for(let o=u;o<c;o++)s.setRowCol(t,o,0);if(f){f=1/f;for(let o=u;o<c;o++){l=0;for(let i=u;i<M;i++)l+=s.atRowCol(i,t)*s.atRowCol(i,o);r=l/s.atRowCol(t,t)*f;for(let i=t;i<M;i++)s.setRowCol(i,o,s.atRowCol(i,o)+r*s.atRowCol(i,t))}for(let o=t;o<M;o++)s.setRowCol(o,t,s.atRowCol(o,t)*f)}else for(let o=t;o<M;o++)s.setRowCol(o,t,0);s.setRowCol(t,t,s.atRowCol(t,t)+1)}for(let t=c-1;t>=0;t--)for(let e=1;;e++){let y=1;for(u=t;u>=0;u--){if(C=u-1,Math.abs(N.at(u))+d===d){y=0;break}if(Math.abs(o.at(C))+d===d)break}if(y){h=0,l=1;for(let i=u;i<=t&&(r=l*N.at(i),N.set(i,N.at(i)*h),Math.abs(r)+d!==d);i++){f=o.at(i),a=p(r,f),o.set(i,a),a=1/a,h=f*a,l=-r*a;for(let t=0;t<M;t++)x=s.atRowCol(t,C),w=s.atRowCol(t,i),s.setRowCol(t,C,x*h+w*l),s.setRowCol(t,i,w*h-x*l)}}if(w=o.at(t),u===t){if(w<0){o.set(t,-w);for(let s=0;s<c;s++)i.setRowCol(s,t,-i.atRowCol(s,t))}break}if(100===e)return!1;n=o.at(u),C=t-1,x=o.at(C),f=N.at(C),a=N.at(t),r=((x-w)*(x+w)+(f-a)*(f+a))/(2*a*x),f=p(r,1),r=((n-w)*(n+w)+a*(x/(r+b(f,r))-a))/n,h=l=1;for(let t=u;t<=C;t++){const e=t+1;f=N.at(e),x=o.at(e),a=l*f,f*=h,w=p(r,a),N.set(t,w),h=r/w,l=a/w,r=n*h+f*l,f=f*h-n*l,a=x*l,x*=h;for(let s=0;s<c;s++)n=i.atRowCol(s,t),w=i.atRowCol(s,e),i.setRowCol(s,t,n*h+w*l),i.setRowCol(s,e,w*h-n*l);w=p(r,a),o.set(t,w),w&&(w=1/w,h=r*w,l=a*w),r=h*f+l*x,n=h*x-l*f;for(let o=0;o<M;o++)x=s.atRowCol(o,t),w=s.atRowCol(o,e),s.setRowCol(o,t,x*h+w*l),s.setRowCol(o,e,w*h-x*l)}N.set(u,0),N.set(t,r),o.set(t,n)}const g=new Float64Array(this.N),v=new Float64Array(this.M),T=new y(g,this.N,1),I=new y(v,this.M,1);let A=1;do{A*=3,A++}while(A<=this.M);do{A/=3,A=Math.trunc(A);for(let t=A;t<this.M;t++){const e=o.at(t);for(let o=0;o<this.N;o++)T.set(o,s.atRowCol(o,t));for(let s=0;s<this.M;s++)I.set(s,i.atRowCol(s,t));let h=t;for(;o.at(h-A)<e;){o.set(h,o.at(h-A));for(let t=0;t<this.N;t++)s.setRowCol(t,h,s.atRowCol(t,h-A));for(let t=0;t<this.M;t++)i.setRowCol(t,h,i.atRowCol(t,h-A));if(h-=A,h<A)break}o.set(h,e);for(let t=0;t<this.N;t++)s.setRowCol(t,h,T.at(t));for(let t=0;t<this.M;t++)i.setRowCol(t,h,I.at(t))}}while(A>1);for(let t=0;t<this.M;t++){let o=0;for(let i=0;i<this.N;i++)s.atRowCol(i,t)<0&&o++;for(let s=0;s<this.M;s++)i.atRowCol(s,t)<0&&o++;if(o>Math.trunc((this.N+this.M)/2)){for(let o=0;o<this.N;o++)s.setRowCol(o,t,-s.atRowCol(o,t));for(let s=0;s<this.M;s++)i.setRowCol(s,t,-i.atRowCol(s,t))}}return!0}isSymmetric(){if(this.N!==this.M)return!1;for(let t=0;t<this.N;t++)for(let s=t+1;s<this.M;s++)if(this.atRowCol(t,s)!==this.atRowCol(s,t))return!1;return!0}isZero(){return t(0),!1}isIdentity(){return t(0),!1}equals(s,o){if(void 0!==o&&t(0),this.N!==s.N||this.M!==s.M)return!1;for(let t=0;t<this.N*this.M;t++)if(this.data[t]!==s.data[t])return!1;return!0}maxElement(){return t(0),0}minElement(){return t(0),0}determinant(){if(t(this.N===this.M),1===this.N)return this.data[0];if(2===this.N)return this.data[0]*this.data[3]-this.data[1]*this.data[2];if(3===this.N){const t=this;return t.atRowCol(0,0)*(t.atRowCol(1,1)*t.atRowCol(2,2)-t.atRowCol(1,2)*t.atRowCol(2,1))-t.atRowCol(0,1)*(t.atRowCol(1,0)*t.atRowCol(2,2)-t.atRowCol(2,0)*t.atRowCol(1,2))+t.atRowCol(0,2)*(t.atRowCol(1,0)*t.atRowCol(2,1)-t.atRowCol(1,1)*t.atRowCol(2,0))}const s=new Float64Array(this.N*this.N),o=new y(s,this.N,this.N),i=new Float64Array(this.N);if(!this.luDecomposition(o,i))return 0;let e=1;for(let t=0;t<this.N;t++)e*=o.atRowCol(t,t),i[t]!==t&&(e=-e);return e}submatrix(s,o,i){t(0)}inverse(s){t(0)}pseudoInverse(t,s=!1,o=2220446049250313e-31){if(t.setZero(),1===this.N&&1===this.M)return 0!==this.atRowCol(0,0)?t.setRowCol(0,0,1/this.atRowCol(0,0)):t.setRowCol(0,0,0),!0;if(2===this.N&&2===this.M){const s=this.atRowCol(0,0)*this.atRowCol(1,1)-this.atRowCol(0,1)*this.atRowCol(1,0),o=1e-5*(Math.abs(this.atRowCol(0,0)*this.atRowCol(1,1))+Math.abs(this.atRowCol(0,1)*this.atRowCol(1,0)));if(Math.abs(s)>o)return t.setRowCol(0,0,this.atRowCol(1,1)/s),t.setRowCol(0,1,-this.atRowCol(0,1)/s),t.setRowCol(1,0,-this.atRowCol(1,0)/s),t.setRowCol(1,1,this.atRowCol(0,0)/s),!0}const i=new Float64Array(this.N*this.M),e=new y(i,this.N,this.M),h=new Float64Array(this.M),r=new y(h,this.M,1),a=new Float64Array(this.M*this.M),l=new y(a,this.M,this.M);if(!this.svd(e,r,l,s))return!1;const n=Math.max(this.N,this.M),x=o*Math.abs(r.at(0))*n;for(let y=0;y<this.M;y++)r.at(y)>x?r.set(y,1/r.at(y)):r.set(y,0);return l.mulDiag(r,t),t.mulTranspose(e,t),!0}luDecomposition(s,o){return t(0),!1}symmetricEigen(s,o){t(this.rows()===this.cols()),t(this.rows()===s.rows()),t(o.rows()===o.cols()&&o.rows()===this.rows()),t(this.isSymmetric());const i=new Float64Array(this.N*this.M),e=new y(i,this.N,this.M);e.assignCopy(this);const h=100/Number.EPSILON,r=this.rows(),a=new Float64Array(r),l=new Float64Array(r),n=new y(a,r,1),x=new y(l,r,1);for(let t=0;t<r;t++)n.set(t,e.atRowCol(t,t)),s.set(t,e.atRowCol(t,t)),x.set(t,0);o.setIdentity();const w=()=>{const t=n;o.transposeInPlace();let i=1;do{i*=3,i++}while(i<=r);do{i/=3,i=Math.trunc(i);for(let e=i;e<r;e++){const h=s.at(e),r=Math.abs(h);for(let s=0;s<this.M;s++)t.set(s,o.atRowCol(s,e));let a=e;for(;Math.abs(s.at(a-i))<r;){s.set(a,s.at(a-i));for(let t=0;t<this.M;t++)o.setRowCol(t,a,o.atRowCol(t,a-i));if(a-=i,a<i)break}if(a!==e){s.set(a,h);for(let s=0;s<this.M;s++)o.setRowCol(s,a,t.at(s))}}}while(i>1)};for(let t=1;;t++){let i=0;for(let t=1;t<r;t++)for(let s=0;s<t;s++)i+=Math.abs(e.atRowCol(t,s));if(0===i)return w(),!0;const a=t<4?.2*i/(r*r):0;for(let l=0;l<r;l++)for(let i=l+1;i<r;i++){let y=h*Math.abs(e.atRowCol(i,l));if(t>4&&y<=Math.abs(s.at(l))&&y<=Math.abs(s.at(i)))e.setRowCol(i,l,0);else if(Math.abs(e.atRowCol(i,l))>a){let t,h=s.at(i)-s.at(l);if(y<Math.abs(h))t=e.atRowCol(i,l)/h;else{const s=.5*h/e.atRowCol(i,l);t=1/(Math.abs(s)+Math.sqrt(1+s*s)),s<0&&(t=-t)}const a=1/Math.sqrt(1+t*t),n=t*a,w=n/(1+a);h=t*e.atRowCol(i,l),x.set(l,x.at(l)-h),x.set(i,x.at(i)+h),s.set(l,s.at(l)-h),s.set(i,s.at(i)+h),e.setRowCol(i,l,0);let u=0;for(;u<l;u++)y=e.atRowCol(l,u),h=e.atRowCol(i,u),e.setRowCol(l,u,y-n*(h+y*w)),e.setRowCol(i,u,h+n*(y-h*w));for(u++;u<i;u++)y=e.atRowCol(u,l),h=e.atRowCol(i,u),e.setRowCol(u,l,y-n*(h+y*w)),e.setRowCol(i,u,h+n*(y-h*w));for(u++;u<r;u++)y=e.atRowCol(u,l),h=e.atRowCol(u,i),e.setRowCol(u,l,y-n*(h+y*w)),e.setRowCol(u,i,h+n*(y-h*w));for(u=0;u<r;u++)y=o.atRowCol(l,u),h=o.atRowCol(i,u),o.setRowCol(l,u,y-n*(h+y*w)),o.setRowCol(i,u,h+n*(y-h*w))}}for(let t=0;t<r;t++)n.set(t,n.at(t)+x.at(t)),s.set(t,n.at(t)),x.set(t,0)}}static checkDims(s,o,i){t(s.rows()===o&&s.cols()===i)}}class n extends y{constructor(t){if(t.copy){const s=new Float64Array(t.copy.N*t.copy.M);return super(s,t.copy.N,t.copy.M),this.buffer=s,void this.assignCopy(t.copy)}const s=new Float64Array(t.NN*t.MM);super(s,t.NN,t.MM),this.buffer=s,t.initializerList&&a(this.buffer,t.initializerList,0,0,t.initializerList.length)}assignCopy(t){return this===t||super.assignCopy(t),this}}class x{constructor(t){this.m_TransformationType=1,void 0===t?this.setIdentity():t instanceof x?this.set(t):this.setScale(t)}set(t){return this.xx=t.xx,this.xy=t.xy,this.xd=t.xd,this.yx=t.yx,this.yy=t.yy,this.yd=t.yd,this}clone(){return(new x).set(this)}setZero(){this.xx=0,this.yy=0,this.xy=0,this.yx=0,this.xd=0,this.yd=0}isEqual(t){return this===t||this.xx===t.xx&&this.xy===t.xy&&this.xd===t.xd&&this.yx===t.yx&&this.yy===t.yy&&this.yd===t.yd}transformInPlace(t){const s=this.xx*t.x+this.xy*t.y+this.xd,o=this.yx*t.x+this.yy*t.y+this.yd;t.x=s,t.y=o}transform(t){const s=t.clone();return this.transformInPlace(s),s}queryTransform(t,s){const o=this.xx*t.x+this.xy*t.y+this.xd,i=this.yx*t.x+this.yy*t.y+this.yd;s.setCoords(o,i)}transformEnvInPlace(t){if(t.isEmpty())return;const s=i(e,4);t.queryCorners(s),this.transformPoints2D(s,4,s),t.setFromPoints(s,4)}queryTransformEnv(s,o){t(0)}transformPoints2D(t,s,o){for(let i=0;i<s;++i)this.queryTransform(t[i],o[i])}transformInterleavedPoints(t,s,o){s*=2;const i=e.getNAN();for(let e=0;e<s;e+=2)i.x=t[e],i.y=t[e+1],this.transformInPlace(i),o[e]=i.x,o[e+1]=i.y}multiply(t){return x.st_multiply(this,t,this),this}mulLeft(s){return t(0),this}static st_multiply(t,s,o){const i=t.xx*s.xx+t.yx*s.xy,e=t.xy*s.xx+t.yy*s.xy,h=t.xd*s.xx+t.yd*s.xy+s.xd,r=t.xx*s.yx+t.yx*s.yy,a=t.xy*s.yx+t.yy*s.yy,l=t.xd*s.yx+t.yd*s.yy+s.yd;o.xx=i,o.xy=e,o.xd=h,o.yx=r,o.yy=a,o.yd=l}getCoefficients(s){t(s.length>=6),s[0]=this.xx,s[1]=this.xy,s[2]=this.xd,s[3]=this.yx,s[4]=this.yy,s[5]=this.yd}setCoefficients(s){t(s.length>=6),this.xx=s[0],this.xy=s[1],this.xd=s[2],this.yx=s[3],this.yy=s[4],this.yd=s[5]}copyTo(s){t(0)}initializeFromRect(t,s){t.isEmpty()||s.isEmpty()||!t.width()||!t.height()?this.setZero():(this.xy=this.yx=0,this.xx=s.width()/t.width(),this.yy=s.height()/t.height(),this.xd=s.xmin-t.xmin*this.xx,this.yd=s.ymin-t.ymin*this.yy)}initializeFromRectIsotropic(t,s){if(t.isEmpty()||!t.width()||!t.height()||s.isEmpty())this.setZero();else{this.yx=0,this.xy=0,this.xx=s.width()/t.width(),this.yy=s.height()/t.height(),this.xx>this.yy?this.xx=this.yy:this.yy=this.xx;const o=s.getCenter(),i=t.getCenter();this.xd=o.x-i.x*this.xx,this.yd=o.y-i.y*this.yy}}initializeFromTwoPointsArray(t,o){if(t[0].equals(o[0])&&t[1].equals(o[1]))return void this.setIdentity();if(t[0].equals(t[1])){if(o[0].equals(o[1]))return void this.setShift(o[0].sub(t[0]));s("")}if(!t[0].equals(t[1])&&o[0].equals(o[1]))return this.setZero(),void this.shift(o[0]);this.setShiftCoords(-t[0].x,-t[0].y);const i=e.distance(t[0],t[1]),h=e.distance(o[0],o[1]),r=h/i;this.scale(r,r);const a=t[1].sub(t[0]);a.divThis(i);const l=o[1].sub(o[0]);l.divThis(h);const y=a.crossProduct(l),n=a.dotProduct(l);this.rotate(n,y),this.shiftCoords(o[0].x,o[0].y)}initializeFromTwoPoints(t,s,o,i){const e=[t,s],h=[o,i];this.initializeFromTwoPointsArray(e,h)}transformSizeInPlace(s){t(0)}transformSize(s,o){t(0)}transformTol(s){return t(0),0}transformWithoutTranslateArray(t,s,o){for(let i=0;i<s;++i)this.transformWithoutTranslate(t[i],o[i])}transformWithoutTranslateInPlace(t){const s=this.xx*t.x+this.xy*t.y,o=this.yx*t.x+this.yy*t.y;t.setCoords(s,o)}transformWithoutTranslate(t,s){const o=this.xx*t.x+this.xy*t.y,i=this.yx*t.x+this.yy*t.y;s.setCoords(o,i)}setIdentity(){this.xx=1,this.xy=0,this.xd=0,this.yx=0,this.yy=1,this.yd=0}isIdentity(){return!(1!==this.xx||1!==this.yy||this.xy||this.xd||this.yx||this.yd)}isIdentityTol(t){const s=t*t;return!(h(this.xd)+h(this.yd)>s)&&(!(h(this.xy+this.xd)+h(this.yy+this.yd-1)>s)&&!(h(this.xx+this.xd-1)+h(this.yx+this.yd)>s))}isReflective(){return this.xx*this.yy-this.yx*this.xy<0}isUniform(t){const s=this.xx*this.xx+this.yx*this.yx,o=this.xy*this.xy+this.yy*this.yy,i=(s+o)*t;return Math.abs(s-o)<=i&&Math.abs(this.xx*this.xy+this.yx*this.yy)<=i}isUniformNoRotation(){return 0!==this.xx&&Math.abs(this.xx)===Math.abs(this.yy)&&0===this.xy&&0===this.yx}isTranslate(){return 1===this.xx&&1===this.yy&&!this.xy&&!this.yx}isTranslateTol(t){const s=new e;return s.setCoords(0,1),this.transformWithoutTranslateInPlace(s),s.y-=1,!(s.sqrLength()>t*t)&&(s.setCoords(1,0),this.transformWithoutTranslateInPlace(s),s.x-=1,s.sqrLength()<=t*t)}isOrthonormal(t){const s=new x;return s.xx=this.xx*this.xx+this.xy*this.xy,s.xy=this.xx*this.yx+this.xy*this.yy,s.yx=this.yx*this.xx+this.yy*this.xy,s.yy=this.yx*this.yx+this.yy*this.yy,s.xd=0,s.yd=0,s.isIdentityTol(t)}isDegenerate(t){return Math.abs(this.xx*this.yy-this.yx*this.xy)<=2*t*(Math.abs(this.xx*this.yy)+Math.abs(this.yx*this.xy))}isZero(){return 0===this.xx&&0===this.yy&&0===this.xy&&0===this.yx&&0===this.xd&&0===this.yd}isScaleAndTranslateTol(t){return this.xy*this.xy+this.yx*this.yx<=(this.xx*this.xx+this.yy*this.yy)*t}setTranslate(t,s){return this.xx=1,this.xy=0,this.xd=t,this.yx=0,this.yy=1,this.yd=s,this}setShiftCoords(t,s){return this.xx=1,this.xy=0,this.xd=t,this.yx=0,this.yy=1,this.yd=s,this}setShift(t){return this.xx=1,this.xy=0,this.xd=t.x,this.yx=0,this.yy=1,this.yd=t.y,this}setScaleCoords(t,s){return this.xx=t,this.xy=0,this.xd=0,this.yx=0,this.yy=s,this.yd=0,this}setScale(t){return this.setScaleCoords(t,t),this}setFlipX(t,s){return this.xx=-1,this.xy=0,this.xd=t+s,this.yx=0,this.yy=1,this.yd=0,this}setFlipY(t,s){return this.xx=1,this.xy=0,this.xd=0,this.yx=0,this.yy=-1,this.yd=t+s,this}setShear(t,s){return this.xx=1,this.xy=t,this.xd=0,this.yx=s,this.yy=1,this.yd=0,this}scale(t,s){return this.xx*=t,this.xy*=t,this.xd*=t,this.yx*=s,this.yy*=s,this.yd*=s,this}setRotateAngle(t){return this.setRotate(Math.cos(t),Math.sin(t))}setRotate(t,s){return this.xx=t,this.xy=-s,this.xd=0,this.yx=s,this.yy=t,this.yd=0,this}setRotateAngleAbout(t,s){return this.setRotateAbout(Math.cos(t),Math.sin(t),s)}setRotateAbout(t,s,o){return this.setTranslate(-o.x,-o.y),this.rotate(t,s),this.translate(o.x,o.y)}setSwapCoordinates(){return this.xx=0,this.xy=1,this.xd=0,this.yx=1,this.yy=0,this.yd=0,this}setRotateCw90(){return this.xx=0,this.xy=1,this.xd=0,this.yx=-1,this.yy=0,this.yd=0,this}setRotateCcw90(){return this.xx=0,this.xy=-1,this.xd=0,this.yx=1,this.yy=0,this.yd=0,this}shiftCoords(t,s){return this.xd+=t,this.yd+=s,this}shift(t){return this.xd+=t.x,this.yd+=t.y,this}translate(t,s){return this.xd+=t,this.yd+=s,this}flipX(t,s){return this.xx=-this.xx,this.xy=-this.xy,this.xd=t+s-this.xd,this}flipY(t,s){return this.yx=-this.yx,this.yy=-this.yy,this.yd=t+s-this.yd,this}shear(t,s){const o=new x;return o.setShear(t,s),this.multiply(o)}rotateAngle(t){const s=new x;return s.setRotateAngle(t),this.multiply(s)}rotate(t,s){const o=new x;return o.setRotate(t,s),this.multiply(o)}rotateAbout(t,s,o){return this.translate(-o.x,-o.y),this.rotate(t,s),this.translate(o.x,o.y)}rotateAngleAbout(t,s){return this.rotateAbout(Math.cos(t),Math.sin(t),s)}setInvert(t){return this.set(t),this.invertThis()}invertThis(){let t=this.xx*this.yy-this.xy*this.yx;if(0===t)return this.setZero(),this;t=1/t;const s=(this.xy*this.yd-this.xd*this.yy)*t,o=(this.xd*this.yx-this.xx*this.yd)*t,i=this.yy*t,e=-this.xy*t,h=-this.yx*t,r=this.xx*t;return this.xd=s,this.yd=o,this.xx=i,this.yy=r,this.xy=e,this.yx=h,this}invertPrecise(t){return this.set(t),this.invertPreciseThis()}invertPreciseThis(){const t=r.constructDouble(this.xy),s=r.constructDouble(this.xx),o=s.mulDouble(this.yy).sub(t.mulDouble(this.yx));if(o.isZero())return this.setZero(),this;const i=o.clone();i.invertThis();const e=r.constructDouble(this.xd),h=t.mulDouble(this.yd).sub(e.mulDouble(this.yy)).mul(i).toDouble(),a=e.mulDouble(this.yx).sub(s.mulDouble(this.yd)).mul(i).toDouble(),l=i.mulDouble(this.yy).toDouble(),y=i.mulDouble(-this.xy).toDouble(),n=i.mulDouble(-this.yx).toDouble(),x=i.mulDouble(this.xx).toDouble();return this.xd=h,this.yd=a,this.xx=l,this.yy=x,this.xy=y,this.yx=n,this}extractScaleTransform(t,s){const o=Math.sqrt(this.xx*this.xx+this.xy*this.xy),i=Math.sqrt(this.yx*this.yx+this.yy*this.yy);s.setScaleCoords(1/o,1/i),s.multiply(this),t.setScaleCoords(o,i)}setFromTwoTriangles(t,s){let o=!0;for(let e=0;e<3;++e)o=o&&t[e].equals(s[e]);if(o)return this.setIdentity(),!0;const i=new e;i.setSub(t[0],t[1]);const h=new e;h.setSub(t[0],t[2]);const r=new e;r.setSub(s[0],s[1]);const a=new e;a.setSub(s[0],s[2]);const l=4*Number.EPSILON*(Math.abs(i.x*h.y)+Math.abs(h.x*i.y));let y=i.x*h.y-i.y*h.x;return Math.abs(y)>l?(y=1/y,this.xx=(r.x*h.y-i.y*a.x)*y,this.xy=(i.x*a.x-r.x*h.x)*y,this.yx=(r.y*h.y-i.y*a.y)*y,this.yy=(i.x*a.y-r.y*h.x)*y,this.xd=s[0].x-(this.xx*t[0].x+this.xy*t[0].y),this.yd=s[0].y-(this.yx*t[0].x+this.yy*t[0].y),!0):(this.setZero(),!1)}initializeFromControlPoints(t,s,o,i,e=null){return 0===s?(this.setIdentity(),void(e&&e.setIdentity())):1===s?(this.setShift(i[0].sub(o[0])),void(e&&e.setShift(o[0].sub(i[0])))):(s<3&&(t=1),void(4===t&&s>2?C(this,s,o,i,e):f(t,this,s,o,i,e)))}calculateErrors(s,o,i,h){t(s>0&&null!==o&&null!==i);let r=0;for(let t=0;t<s;++t){const s=this.transform(o[t]),a=e.sqrDistance(i[t],s);r+=a,h&&(h[t]=Math.sqrt(a))}return Math.sqrt(r/s)}}const w=[43,11,41,9,61];function u(s,o){t(!(2!==o.rows()&&3!==o.rows()||2!==o.cols()&&3!==o.rows())),s.xx=o.atRowCol(0,0),s.xy=o.atRowCol(0,1),s.yx=o.atRowCol(1,0),s.yy=o.atRowCol(1,1),3===o.cols()?(s.xd=o.atRowCol(0,2),s.yd=o.atRowCol(1,2)):(s.xd=0,s.yd=0)}function C(t,s,i,h,r){const a=e.average(i,s),l=e.average(h,s),y=new n({NN:2,MM:2});y.setZero();const x=new n({NN:2,MM:2});x.setZero();for(let o=0;o<s;++o)y.setRowCol(0,0,y.atRowCol(0,0)+(i[o].x-a.x)*(i[o].x-a.x)),y.setRowCol(0,1,y.atRowCol(0,1)+(i[o].x-a.x)*(i[o].y-a.y)),y.setRowCol(1,1,y.atRowCol(1,1)+(i[o].y-a.y)*(i[o].y-a.y)),x.setRowCol(0,0,x.atRowCol(0,0)+(h[o].x-l.x)*(i[o].x-a.x)),x.setRowCol(0,1,x.atRowCol(0,1)+(h[o].x-l.x)*(i[o].y-a.y)),x.setRowCol(1,0,x.atRowCol(1,0)+(h[o].y-l.y)*(i[o].x-a.x)),x.setRowCol(1,1,x.atRowCol(1,1)+(h[o].y-l.y)*(i[o].y-a.y));y.setRowCol(1,0,y.atRowCol(0,1));const w=new n({NN:2,MM:2});y.pseudoInverse(w,!0)||o("Failed to compute pseudo inverse"),x.mul(w,x),u(t,x);const C=a.clone();t.transformInPlace(C),t.xd=l.x-C.x,t.yd=l.y-C.y,r&&(x.pseudoInverse(w,!1)||o("Failed to compute pseudo inverse"),u(r,w),r.transformInPlace(l),r.xd=a.x-l.x,r.yd=a.y-l.y)}function f(s,i,h,r,a,l){t(1===s||0===s||2===s||3===s),i.setIdentity();const y=e.average(r,h),C=e.average(a,h);if(t(s<w.length&&s>0),8&w[s]){const t=new n({NN:2,MM:2});t.setZero();for(let s=0;s<h;++s)t.setRowCol(0,0,t.atRowCol(0,0)+(a[s].x-C.x)*(r[s].x-y.x)),t.setRowCol(1,0,t.atRowCol(1,0)+(a[s].x-C.x)*(r[s].y-y.y)),t.setRowCol(0,1,t.atRowCol(0,1)+(a[s].y-C.y)*(r[s].x-y.x)),t.setRowCol(1,1,t.atRowCol(1,1)+(a[s].y-C.y)*(r[s].y-y.y));const e=new n({NN:2,MM:2}),l=new n({NN:2,MM:1}),f=new n({NN:2,MM:2});t.svd(e,l,f)||o("Failed to compute svd");const R=new n({NN:2,MM:2});e.transpose(R);const d=new n({NN:2,MM:2});if(f.mul(R,d),!(32&w[s])){d.determinant()<0&&(R.setRowCol(1,0,-R.atRowCol(1,0)),R.setRowCol(1,1,-R.atRowCol(1,1)),f.mul(R,d))}const c=new x;u(c,d),i.set(c)}if(2&w[s]){let t=0,s=0;for(let o=0;o<h;++o){const e=r[o].sub(y);t+=e.sqrLength(),i.transformInPlace(e),s+=e.dotProduct(a[o].sub(C))}if(0===t)0===s?i.setIdentity():i.setZero();else{const o=s/t;i.scale(o,o)}}else t(!(4&w[s]));const f=y.clone();i.transformInPlace(f),i.xd=C.x-f.x,i.yd=C.y-f.y,l&&(l.set(i),l.invertThis(),l.isZero()&&(l.xd=y.x,l.yd=y.y))}export{x as T};