UNPKG

voluptasquisquam

Version:

Image processing and manipulation in JavaScript

90 lines 283 kB
(function(e,t){'object'==typeof exports&&'undefined'!=typeof module?module.exports=t():'function'==typeof define&&define.amd?define(t):e.IJS=t()})(this,function(){'use strict';function e(e){return To[e]}function t(e){var t=e.channels*e.size;return 1===e.bitDepth&&(t=Io(t/8)),t}function a(e){var t=e.channels*e.size,a;switch(e.bitDepth){case 1:a=new Uint8Array(Io(t/8));break;case 8:a=new Uint8ClampedArray(t);break;case 16:a=new Uint16Array(t);break;case 32:a=new Float32Array(t);break;default:throw new Error('Cannot create pixel array for bit depth '+e.bitDepth);}if(e.alpha)for(var n=e.components;n<a.length;n+=e.channels)a[n]=e.maxValue;return a}function n(e){try{var t=new URL(e);return t.origin!==Uo}catch(t){return!1}}function o(e,t){var i=self.document.createElement('canvas');return i.width=e,i.height=t,i}function s(e,{withCredentials:t=!1}={}){return new Promise(function(i,a){var n=new self.XMLHttpRequest;n.open('GET',e,!0),n.responseType='arraybuffer',n.withCredentials=t,n.onload=function(t){200===this.status?i(this.response):a(t)},n.onerror=a,n.send()})}function r(){throw new Error('createWriteStream does not exist in the browser')}function l(){throw new Error('writeFile does not exist in the browser')}function d(){if(this.checkProcessable('invert',{bitDepth:[1,8,16]}),1===this.bitDepth)for(var e=this.data,t=0;t<e.length;t++)e[t]=~e[t];else for(var i=0;i<this.width;i++)for(var a=0;a<this.height;a++)for(var n=0,o;n<this.components;n++)o=this.getValueXY(i,a,n),this.setValueXY(i,a,n,this.maxValue-o)}function h(){if(this.checkProcessable('invert',{bitDepth:[1,8,16]}),1===this.bitDepth)for(var e=this.data,t=0;t<e.length;t++)e[t]=~e[t];else for(var i of this.pixels())for(var a=i.index,n=i.pixel,o=0;o<this.components;o++)this.setValue(a,o,this.maxValue-n[o])}function g(){this.checkProcessable('invertOneLoop',{bitDepth:[8,16]});for(var e=this.data,t=0;t<e.length;t+=this.channels)for(var i=0;i<this.components;i++)e[t+i]=this.maxValue-e[t+i]}function c(){this.checkProcessable('invertPixel',{bitDepth:[8,16]});for(var e=0;e<this.width;e++)for(var t=0,i;t<this.height;t++){i=this.getPixelXY(e,t);for(var a=0;a<this.components;a++)i[a]=this.maxValue-i[a];this.setPixelXY(e,t,i)}}function m(){if(1===this.bitDepth)for(var e=this.data,t=0;t<e.length;t++)e[t]=~e[t];else this.checkProcessable('invertApply',{bitDepth:[8,16]}),this.apply(function(e){for(var t=0;t<this.components;t++)this.data[e+t]=this.maxValue-this.data[e+t]})}function p(){this.checkProcessable('invertBinaryLoop',{bitDepth:[1]});for(var e=0;e<this.size;e++)this.toggleBit(e)}function u(e,t={}){var i=t.channels,a=t.allowAlpha,n=t.defaultAlpha;return'boolean'!=typeof a&&(a=!0),'undefined'==typeof i?f(e,n):_(e,i,a)}function f(e,t){for(var a=t?e.channels:e.components,n=Array(a),o=0;o<a;o++)n[o]=o;return n}function _(e,t,i){Array.isArray(t)||(t=[t]);for(var a=0;a<t.length;a++)t[a]=b(e,t[a],i);return t}function b(e,t,i=!0){if(void 0===t)throw new RangeError('validateChannel : the channel has to be >=0 and <'+e.channels);if('string'==typeof t){switch(e.colorModel){case Eo:break;case Ro:'rgb'.includes(t)&&('r'===t?t=0:'g'===t?t=1:'b'===t?t=2:void 0);break;case Co:'hsl'.includes(t)&&('h'===t?t=0:'s'===t?t=1:'l'===t?t=2:void 0);break;case zo:'hsv'.includes(t)&&('h'===t?t=0:'s'===t?t=1:'v'===t?t=2:void 0);break;case Lo:'cmyk'.includes(t)&&('c'===t?t=0:'m'===t?t=1:'y'===t?t=2:'k'===t?t=3:void 0);break;default:throw new Error(`Unexpected color model: ${e.colorModel}`);}if('a'===t){if(!e.alpha)throw new Error('validateChannel : the image does not contain alpha channel');t=e.components}if('string'==typeof t)throw new Error('validateChannel : undefined channel: '+t)}if(t>=e.channels)throw new RangeError('validateChannel : the channel has to be >=0 and <'+e.channels);if(!i&&t>=e.components)throw new RangeError('validateChannel : alpha channel may not be selected');return t}function w(e={}){var t=e.channels;if(this.checkProcessable('invertOneLoop',{bitDepth:[1,8,16]}),1===this.bitDepth)for(var a=this.data,n=0;n<a.length;n++)a[n]=~a[n];else{t=u(this,{channels:t});for(var i=0,o;i<t.length;i++){o=t[i];for(var s=o;s<this.data.length;s+=this.channels)this.data[s]=this.maxValue-this.data[s]}}return this}function x(){this.checkProcessable('flipX',{bitDepth:[8,16]});for(var e=0,t;e<this.height;e++){t=e*this.width*this.channels;for(var i=0;i<Po(this.width/2);i++)for(var a=i*this.channels+t,n=(this.width-i-1)*this.channels+t,o=0,s;o<this.channels;o++)s=this.data[a+o],this.data[a+o]=this.data[n+o],this.data[n+o]=s}return this}function k(){this.checkProcessable('flipY',{bitDepth:[8,16]});for(var e=0;e<Po(this.height/2);e++)for(var t=0;t<this.width;t++)for(var i=t*this.channels+e*this.width*this.channels,a=t*this.channels+(this.height-1-e)*this.channels*this.width,n=0,o;n<this.channels;n++)o=this.data[i+n],this.data[i+n]=this.data[a+n],this.data[a+n]=o;return this}function y(e,t={}){return t=Object.assign({},t),t.algorithm='fft',this.convolution(e,t)}function v(e={}){var t=e.radius,a=void 0===t?1:t;if(this.checkProcessable('meanFilter',{components:[1],bitDepth:[8,16]}),1>a)throw new Error('Number of neighbors should be grater than 0');for(var o=2*a+1,n=Array(o*o),s=0;s<n.length;s++)n[s]=1;return y.call(this,n)}function j(e){if('number'!=typeof e||Yo(e))throw new TypeError('Expected a number')}function D(e={}){var t=e.radius,a=void 0===t?1:t,o=e.channels,s=e.border,r=void 0===s?'copy':s;if(this.checkProcessable('median',{bitDepth:[8,16]}),1>a)throw new Error('Kernel radius should be greater than 0');o=u(this,o,!0);for(var l=a,d=a,h=Dc.createFrom(this),g=(2*l+1)*(2*d+1),m=Po(g/2),p=Array(g),f=0,_;f<o.length;f++){_=o[f];for(var c=d;c<this.height-d;c++)for(var b=l,w;b<this.width-l;b++){w=0;for(var n=-d;n<=d;n++)for(var x=-l,i;x<=l;x++)i=((c+n)*this.width+b+x)*this.channels+_,p[w++]=this.data[i];var k=(c*this.width+b)*this.channels+_,y=p.sort(Xo)[m];h.data[k]=y}}if(this.alpha&&!o.includes(this.channels))for(var v=this.components;v<this.data.length;v+=this.channels)h.data[v]=this.data[v];return h.setBorder({size:[l,d],algorithm:r}),h}function M(){throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs')}function S(e,t){return t={exports:{}},e(t,t.exports),t.exports}function P(e){var t=e,a,n;if('number'!=typeof e[0]){a=e.length,n=e[0].length,t=Array(a*n);for(var o=0;o<a;o++)for(var i=0;i<n;i++)t[o*n+i]=e[o][i]}else{var s=Do(e.length);yo(s)&&(a=s,n=s)}return{data:t,rows:a,cols:n}}function I(e){var t,a;if(!Array.isArray(e))throw new Error('validateKernel: Invalid Kernel: '+e);else if(!Array.isArray(e[0])){var n=Do(e.length);if(Ko(n))a=t=Po(Do(e.length)/2);else throw new RangeError('validateKernel: Kernel array should be a square');for(var o=Array(n),s=0;s<n;s++){o[s]=Array(n);for(var i=0;i<n;i++)o[s][i]=e[s*n+i]}e=o}else if(0==(1&e.length)||0==(1&e[0].length))throw new RangeError('validateKernel: Kernel rows and columns should be odd numbers');else t=Po(e.length/2),a=Po(e[0].length/2);return{kernel:e,kWidth:a,kHeight:t}}function B(e,t,a){if(void 0===a){const i=e.length+t.length-1;a=Array(i)}A(a);for(var n=0;n<e.length;n++)for(var i=0;i<t.length;i++)a[n+i]+=e[n]*t[i];return a}function A(e){for(var t=0;t<e.length;t++)e[t]=0}function R(e,t,i,a){var n=Array(e.length),o,s,r,l;l=t[1],r=(l.length-1)/2,s=Array(i+l.length-1),o=Array(i);for(var d=0;d<a;d++){for(var h=0;h<i;h++)o[h]=e[d*i+h];B(o,l,s);for(var g=0;g<i;g++)n[d*i+g]=s[r+g]}l=t[0],r=(l.length-1)/2,s=Array(a+l.length-1),o=Array(a);for(var c=0;c<i;c++){for(var m=0;m<a;m++)o[m]=n[m*i+c];B(o,l,s);for(var p=0;p<a;p++)n[p*i+c]=s[r+p]}return n}function C(e){if(!(this instanceof C))return new C(e);e=fs.checkMatrix(e);var a=e.clone(),n=a.rows,o=a.columns,r=Array(n),l=1,d,i,h,g,c,s,t,m,p,u;for(d=0;d<n;d++)r[d]=d;for(p=Array(n),i=0;i<o;i++){for(d=0;d<n;d++)p[d]=a[d][i];for(d=0;d<n;d++){for(m=a[d],u=xo(d,i),c=0,h=0;h<u;h++)c+=m[h]*p[h];m[i]=p[d]-=c}for(g=i,d=i+1;d<n;d++)wo(p[d])>wo(p[g])&&(g=d);if(g!==i){for(h=0;h<o;h++)s=a[g][h],a[g][h]=a[i][h],a[i][h]=s;t=r[g],r[g]=r[i],r[i]=t,l=-l}if(i<n&&0!==a[i][i])for(d=i+1;d<n;d++)a[d][i]/=a[i][i]}this.LU=a,this.pivotVector=r,this.pivotSign=l}function z(e,t){var i;return wo(e)>wo(t)?(i=t/e,wo(e)*Do(1+i*i)):0===t?0:(i=e/t,wo(t)*Do(1+i*i))}function L(e,t,a){for(var n=Array(e),o=0;o<e;o++){n[o]=Array(t);for(var i=0;i<t;i++)n[o][i]=a}return n}function E(o,r){if(!(this instanceof E))return new E(o,r);o=fs.checkMatrix(o),r=r||{};var l=o.rows,d=o.columns,n=xo(l,d),h=!0,m=!0;!1===r.computeLeftSingularVectors&&(h=!1),!1===r.computeRightSingularVectors&&(m=!1);var u=!0===r.autoTranspose,_=!1,w;if(!(l<d))w=o.clone();else if(!u)w=o.clone(),console.warn('Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose');else{w=o.transpose(),l=w.rows,d=w.columns,_=!0;var a=h;h=m,m=a}var x=Array(xo(l+1,d)),s=L(l,n,0),y=L(d,d,0),v=Array(d),e=Array(l),D=xo(l-1,d),M=bo(0,xo(d-2,l)),S,i,j,k,p,P,I,f,B,A,R,C,T,V,F,U,Y,X,b,c,O;for(j=0,A=bo(D,M);j<A;j++){if(j<D){for(x[j]=0,S=j;S<l;S++)x[j]=z(x[j],w[S][j]);if(0!==x[j]){for(0>w[j][j]&&(x[j]=-x[j]),S=j;S<l;S++)w[S][j]/=x[j];w[j][j]+=1}x[j]=-x[j]}for(i=j+1;i<d;i++){if(j<D&&0!==x[j]){for(p=0,S=j;S<l;S++)p+=w[S][j]*w[S][i];for(p=-p/w[j][j],S=j;S<l;S++)w[S][i]+=p*w[S][j]}v[i]=w[j][i]}if(h&&j<D)for(S=j;S<l;S++)s[S][j]=w[S][j];if(j<M){for(v[j]=0,S=j+1;S<d;S++)v[j]=z(v[j],v[S]);if(0!==v[j]){for(0>v[j+1]&&(v[j]=0-v[j]),S=j+1;S<d;S++)v[S]/=v[j];v[j+1]+=1}if(v[j]=-v[j],j+1<l&&0!==v[j]){for(S=j+1;S<l;S++)e[S]=0;for(i=j+1;i<d;i++)for(S=j+1;S<l;S++)e[S]+=v[i]*w[S][i];for(i=j+1;i<d;i++)for(p=-v[i]/v[j+1],S=j+1;S<l;S++)w[S][i]+=p*e[S]}if(m)for(S=j+1;S<d;S++)y[S][j]=v[S]}}if(k=xo(d,l+1),D<d&&(x[D]=w[D][D]),l<k&&(x[k-1]=0),M+1<k&&(v[M]=w[M][k-1]),v[k-1]=0,h){for(i=D;i<n;i++){for(S=0;S<l;S++)s[S][i]=0;s[i][i]=1}for(j=D-1;0<=j;j--)if(0!==x[j]){for(i=j+1;i<n;i++){for(p=0,S=j;S<l;S++)p+=s[S][j]*s[S][i];for(p=-p/s[j][j],S=j;S<l;S++)s[S][i]+=p*s[S][j]}for(S=j;S<l;S++)s[S][j]=-s[S][j];for(s[j][j]=1+s[j][j],S=0;S<j-1;S++)s[S][j]=0}else{for(S=0;S<l;S++)s[S][j]=0;s[j][j]=1}}if(m)for(j=d-1;0<=j;j--){if(j<M&&0!==v[j])for(i=j+1;i<d;i++){for(p=0,S=j+1;S<d;S++)p+=y[S][j]*y[S][i];for(p=-p/y[j+1][j],S=j+1;S<d;S++)y[S][i]+=p*y[S][j]}for(S=0;S<d;S++)y[S][j]=0;y[j][j]=1}for(var g=k-1,N=0,G=2.220446049250313e-16;0<k;){for(j=k-2;-1<=j&&-1!==j;j--)if(wo(v[j])<=G*(wo(x[j])+wo(x[j+1]))){v[j]=0;break}if(j===k-2)R=4;else{for(P=k-1;P>=j&&P!==j;P--)if(p=(P===k?0:wo(v[P]))+(P===j+1?0:wo(v[P-1])),wo(x[P])<=G*p){x[P]=0;break}P===j?R=3:P===k-1?R=1:(R=2,j=P)}switch(j++,R){case 1:{for(I=v[k-2],v[k-2]=0,i=k-2;i>=j;i--)if(p=z(x[i],I),f=x[i]/p,B=I/p,x[i]=p,i!==j&&(I=-B*v[i-1],v[i-1]=f*v[i-1]),m)for(S=0;S<d;S++)p=f*y[S][i]+B*y[S][k-1],y[S][k-1]=-B*y[S][i]+f*y[S][k-1],y[S][i]=p;break}case 2:{for(I=v[j-1],v[j-1]=0,i=j;i<k;i++)if(p=z(x[i],I),f=x[i]/p,B=I/p,x[i]=p,I=-B*v[i],v[i]=f*v[i],h)for(S=0;S<l;S++)p=f*s[S][i]+B*s[S][j-1],s[S][j-1]=-B*s[S][i]+f*s[S][j-1],s[S][i]=p;break}case 3:{for(C=bo(bo(bo(bo(wo(x[k-1]),wo(x[k-2])),wo(v[k-2])),wo(x[j])),wo(v[j])),T=x[k-1]/C,V=x[k-2]/C,F=v[k-2]/C,U=x[j]/C,Y=v[j]/C,X=((V+T)*(V-T)+F*F)/2,b=T*F*(T*F),c=0,(0!==X||0!==b)&&(c=Do(X*X+b),0>X&&(c=-c),c=b/(X+c)),I=(U+T)*(U-T)+c,O=U*Y,i=j;i<k-1;i++){if(p=z(I,O),f=I/p,B=O/p,i!==j&&(v[i-1]=p),I=f*x[i]+B*v[i],v[i]=f*v[i]-B*x[i],O=B*x[i+1],x[i+1]=f*x[i+1],m)for(S=0;S<d;S++)p=f*y[S][i]+B*y[S][i+1],y[S][i+1]=-B*y[S][i]+f*y[S][i+1],y[S][i]=p;if(p=z(I,O),f=I/p,B=O/p,x[i]=p,I=f*v[i]+B*x[i+1],x[i+1]=-B*v[i]+f*x[i+1],O=B*v[i+1],v[i+1]=f*v[i+1],h&&i<l-1)for(S=0;S<l;S++)p=f*s[S][i]+B*s[S][i+1],s[S][i+1]=-B*s[S][i]+f*s[S][i+1],s[S][i]=p}v[k-2]=I,++N;break}case 4:{if(0>=x[j]&&(x[j]=0>x[j]?-x[j]:0,m))for(S=0;S<=g;S++)y[S][j]=-y[S][j];for(;j<g&&!(x[j]>=x[j+1]);){if(p=x[j],x[j]=x[j+1],x[j+1]=p,m&&j<d-1)for(S=0;S<d;S++)p=y[S][j+1],y[S][j+1]=y[S][j],y[S][j]=p;if(h&&j<l-1)for(S=0;S<l;S++)p=s[S][j+1],s[S][j+1]=s[S][j],s[S][j]=p;j++}N=0,k--;break}}}if(_){var q=y;y=s,s=q}this.m=l,this.n=d,this.s=x,this.U=s,this.V=y}function T(e){for(var t=Array(e[0].length),a=0;a<t.length;++a)t[a]=Array(e.length);for(a=0;a<e.length;++a)for(var i=0;i<e[0].length;++i)t[i][a]=e[a][i];return t}function V(e,t,a,n,o){function s(e,t,i,a){return(a-t)/(i-e)}var r=e.length,l=(n-a)/(o-1),d=a-l/2,h=Array(o),g=e[1]-e[0],c=e[e.length-1]-e[e.length-2],m=d,p=d+l,u=uo,f=0,_=e[0]-g,b=0,w=0,x=0,k=0,y=0,v=0,D=0,i=0;main:for(;;){for(;0<=_-p;){var j=U(0,p-u,x,f);if(v=w+j,h[i]=(v-y)/l,i++,i===o)break main;m=p,p+=l,y=v}u<=m&&m<=_&&(j=U(0,m-u,x,f),y=w+j),w+=U(u,_,x,k),u=_,f=b,D<r?(_=e[D],b=t[D],D++):D===r&&(_+=c,b=0),x=s(u,f,_,b),k=-x*u+f}return h}function F(e,t,a,n,o){var s=e.length,r=(n-a)/(o-1),l=e[e.length-1]-e[e.length-2],d=a-r/2,h=Array(o),g=d,c=d+r,m=-po,p=0,u=e[0],f=t[0],_=0,b=!0,w=0,x=0,k=1,i=0;main:for(;;){if(m>=u)throw new Error('x must be an increasing serie');for(;0<m-c;){if(b&&(x++,b=!1),h[i]=0>=x?0:w/x,i++,i===o)break main;g=c,c+=r,w=0,x=0}m>g&&(w+=p,x++),(m==-po||1<_)&&x--,m=u,p=f,k<s?(u=e[k],f=t[k],k++):(u+=l,f=0,_++)}return h}function U(e,t,i,a){return 0.5*i*t*t+a*t-(0.5*i*e*e+a*e)}function Y(e,t,i){var a=i?e.rows:e.rows-1;if(0>t||t>a)throw new RangeError('Row index out of range')}function X(e,t,i){var a=i?e.columns:e.columns-1;if(0>t||t>a)throw new RangeError('Column index out of range')}function O(e,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==e.columns)throw new RangeError('vector size must be the same as the number of columns');return t}function N(e,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==e.rows)throw new RangeError('vector size must be the same as the number of rows');return t}function G(e,t,i){var a=t.some((t)=>{return 0>t||t>=e.rows}),n=i.some((t)=>{return 0>t||t>=e.columns});if(a||n)throw new RangeError('Indices are out of range');if('object'!=typeof t||'object'!=typeof i)throw new TypeError('Unexpected type for row/column indices');return Array.isArray(t)||(t=Array.from(t)),Array.isArray(i)||(t=Array.from(i)),{row:t,column:i}}function H(e,t,i,a,n){if(5!==arguments.length)throw new TypeError('Invalid argument type');var o=Array.from(arguments).slice(1).some(function(e){return'number'!=typeof e});if(o)throw new TypeError('Invalid argument type');if(t>i||a>n||0>t||t>=e.rows||0>i||i>=e.rows||0>a||a>=e.columns||0>n||n>=e.columns)throw new RangeError('Submatrix indices are out of range')}function W(e){for(var t=fs.zeros(e.rows,1),a=0;a<e.rows;++a)for(var i=0;i<e.columns;++i)t.set(a,0,t.get(a,0)+e.get(a,i));return t}function Z(e){for(var t=fs.zeros(1,e.columns),a=0;a<e.rows;++a)for(var i=0;i<e.columns;++i)t.set(0,i,t.get(0,i)+e.get(a,i));return t}function K(e){for(var t=0,a=0;a<e.rows;a++)for(var i=0;i<e.columns;i++)t+=e.get(a,i);return t}function Q(e){function t(e,t){return e-t}function a(e,t){for(var i in t)e=e.replace(new RegExp('%'+i+'%','g'),t[i]);return e}void 0===e&&(e=Object);class n extends e{static get[Symbol.species](){return this}static from1DArray(e,t,i){if(e*t!==i.length)throw new RangeError('Data length does not match given dimensions');for(var a=new this(e,t),n=0;n<e;n++)for(var o=0;o<t;o++)a.set(n,o,i[n*t+o]);return a}static rowVector(e){for(var t=new this(1,e.length),a=0;a<e.length;a++)t.set(0,a,e[a]);return t}static columnVector(e){for(var t=new this(e.length,1),a=0;a<e.length;a++)t.set(a,0,e[a]);return t}static empty(e,t){return new this(e,t)}static zeros(e,t){return this.empty(e,t).fill(0)}static ones(e,t){return this.empty(e,t).fill(1)}static rand(e,t,a){void 0===a&&(a=Math.random);for(var n=this.empty(e,t),o=0;o<e;o++)for(var i=0;i<t;i++)n.set(o,i,a());return n}static randInt(e,t,a,n){void 0===a&&(a=1e3),void 0===n&&(n=Math.random);for(var o=this.empty(e,t),s=0;s<e;s++)for(var i=0,r;i<t;i++)r=Po(n()*a),o.set(s,i,r);return o}static eye(e,t,a){void 0===t&&(t=e),void 0===a&&(a=1);for(var n=xo(e,t),o=this.zeros(e,t),s=0;s<n;s++)o.set(s,s,a);return o}static diag(e,t,a){var n=e.length;void 0===t&&(t=n),void 0===a&&(a=t);for(var o=xo(n,t,a),s=this.zeros(t,a),r=0;r<o;r++)s.set(r,r,e[r]);return s}static min(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);for(var a=e.rows,n=e.columns,o=new this(a,n),s=0;s<a;s++)for(var i=0;i<n;i++)o.set(s,i,xo(e.get(s,i),t.get(s,i)));return o}static max(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);for(var a=e.rows,n=e.columns,o=new this(a,n),s=0;s<a;s++)for(var i=0;i<n;i++)o.set(s,i,bo(e.get(s,i),t.get(s,i)));return o}static checkMatrix(e){return n.isMatrix(e)?e:new this(e)}static isMatrix(e){return null!=e&&'Matrix'===e.klass}get size(){return this.rows*this.columns}apply(e){if('function'!=typeof e)throw new TypeError('callback must be a function');for(var t=this.rows,a=this.columns,n=0;n<t;n++)for(var i=0;i<a;i++)e.call(this,n,i);return this}to1DArray(){for(var e=Array(this.size),t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)e[t*this.columns+i]=this.get(t,i);return e}to2DArray(){for(var e=Array(this.rows),t=0;t<this.rows;t++){e[t]=Array(this.columns);for(var i=0;i<this.columns;i++)e[t][i]=this.get(t,i)}return e}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isSymmetric(){if(this.isSquare()){for(var e=0;e<this.rows;e++)for(var t=0;t<=e;t++)if(this.get(e,t)!==this.get(t,e))return!1;return!0}return!1}set(){throw new Error('set method is unimplemented')}get(){throw new Error('get method is unimplemented')}repeat(e,t){e=e||1,t=t||1;for(var a=new this.constructor[Symbol.species](this.rows*e,this.columns*t),n=0;n<e;n++)for(var i=0;i<t;i++)a.setSubMatrix(this,this.rows*n,this.columns*i);return a}fill(e){for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,e);return this}neg(){return this.mulS(-1)}getRow(e){Y(this,e);for(var t=Array(this.columns),a=0;a<this.columns;a++)t[a]=this.get(e,a);return t}getRowVector(e){return this.constructor.rowVector(this.getRow(e))}setRow(e,t){Y(this,e),t=O(this,t);for(var a=0;a<this.columns;a++)this.set(e,a,t[a]);return this}swapRows(e,t){Y(this,e),Y(this,t);for(var a=0,i;a<this.columns;a++)i=this.get(e,a),this.set(e,a,this.get(t,a)),this.set(t,a,i);return this}getColumn(e){X(this,e);for(var t=Array(this.rows),a=0;a<this.rows;a++)t[a]=this.get(a,e);return t}getColumnVector(e){return this.constructor.columnVector(this.getColumn(e))}setColumn(e,t){X(this,e),t=N(this,t);for(var a=0;a<this.rows;a++)this.set(a,e,t[a]);return this}swapColumns(e,t){X(this,e),X(this,t);for(var a=0,i;a<this.rows;a++)i=this.get(a,e),this.set(a,e,this.get(a,t)),this.set(a,t,i);return this}addRowVector(e){e=O(this,e);for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,this.get(t,i)+e[i]);return this}subRowVector(e){e=O(this,e);for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,this.get(t,i)-e[i]);return this}mulRowVector(e){e=O(this,e);for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,this.get(t,i)*e[i]);return this}divRowVector(e){e=O(this,e);for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,this.get(t,i)/e[i]);return this}addColumnVector(e){e=N(this,e);for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,this.get(t,i)+e[t]);return this}subColumnVector(e){e=N(this,e);for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,this.get(t,i)-e[t]);return this}mulColumnVector(e){e=N(this,e);for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,this.get(t,i)*e[t]);return this}divColumnVector(e){e=N(this,e);for(var t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.set(t,i,this.get(t,i)/e[t]);return this}mulRow(e,t){Y(this,e);for(var a=0;a<this.columns;a++)this.set(e,a,this.get(e,a)*t);return this}mulColumn(e,t){X(this,e);for(var a=0;a<this.rows;a++)this.set(a,e,this.get(a,e)*t);return this}max(){for(var e=this.get(0,0),t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.get(t,i)>e&&(e=this.get(t,i));return e}maxIndex(){for(var e=this.get(0,0),t=[0,0],a=0;a<this.rows;a++)for(var i=0;i<this.columns;i++)this.get(a,i)>e&&(e=this.get(a,i),t[0]=a,t[1]=i);return t}min(){for(var e=this.get(0,0),t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)this.get(t,i)<e&&(e=this.get(t,i));return e}minIndex(){for(var e=this.get(0,0),t=[0,0],a=0;a<this.rows;a++)for(var i=0;i<this.columns;i++)this.get(a,i)<e&&(e=this.get(a,i),t[0]=a,t[1]=i);return t}maxRow(e){Y(this,e);for(var t=this.get(e,0),a=1;a<this.columns;a++)this.get(e,a)>t&&(t=this.get(e,a));return t}maxRowIndex(e){Y(this,e);for(var t=this.get(e,0),a=[e,0],n=1;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),a[1]=n);return a}minRow(e){Y(this,e);for(var t=this.get(e,0),a=1;a<this.columns;a++)this.get(e,a)<t&&(t=this.get(e,a));return t}minRowIndex(e){Y(this,e);for(var t=this.get(e,0),a=[e,0],n=1;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),a[1]=n);return a}maxColumn(e){X(this,e);for(var t=this.get(0,e),a=1;a<this.rows;a++)this.get(a,e)>t&&(t=this.get(a,e));return t}maxColumnIndex(e){X(this,e);for(var t=this.get(0,e),a=[0,e],n=1;n<this.rows;n++)this.get(n,e)>t&&(t=this.get(n,e),a[0]=n);return a}minColumn(e){X(this,e);for(var t=this.get(0,e),a=1;a<this.rows;a++)this.get(a,e)<t&&(t=this.get(a,e));return t}minColumnIndex(e){X(this,e);for(var t=this.get(0,e),a=[0,e],n=1;n<this.rows;n++)this.get(n,e)<t&&(t=this.get(n,e),a[0]=n);return a}diag(){for(var e=xo(this.rows,this.columns),t=Array(e),a=0;a<e;a++)t[a]=this.get(a,a);return t}sum(e){return'row'===e?W(this):'column'===e?Z(this):K(this)}mean(){return this.sum()/this.size}prod(){for(var e=1,t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)e*=this.get(t,i);return e}cumulativeSum(){for(var e=0,t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)e+=this.get(t,i),this.set(t,i,e);return this}dot(e){n.isMatrix(e)&&(e=e.to1DArray());var t=this.to1DArray();if(t.length!==e.length)throw new RangeError('vectors do not have the same size');for(var a=0,o=0;o<t.length;o++)a+=t[o]*e[o];return a}mmul(e){e=this.constructor.checkMatrix(e),this.columns!==e.rows&&console.warn('Number of columns of left matrix are not equal to number of rows of right matrix.');for(var t=this.rows,a=this.columns,n=e.columns,o=new this.constructor[Symbol.species](t,n),r=Array(a),l=0;l<n;l++){for(var d=0;d<a;d++)r[d]=e.get(d,l);for(var h=0,i;h<t;h++){for(i=0,d=0;d<a;d++)i+=this.get(h,d)*r[d];o.set(h,l,i)}}return o}strassen2x2(e){var t=new this.constructor[Symbol.species](2,2);const i=this.get(0,0),a=e.get(0,0),n=this.get(0,1),o=e.get(0,1),s=this.get(1,0),r=e.get(1,0),l=this.get(1,1),d=e.get(1,1),h=(i+l)*(a+d),g=(s+l)*a,c=i*(o-d),m=l*(r-a),p=(i+n)*d;return t.set(0,0,h+m-p+(n-l)*(r+d)),t.set(0,1,c+p),t.set(1,0,g+m),t.set(1,1,h-g+c+(s-i)*(a+o)),t}strassen3x3(e){var t=new this.constructor[Symbol.species](3,3);const i=this.get(0,0),a=this.get(0,1),n=this.get(0,2),o=this.get(1,0),s=this.get(1,1),r=this.get(1,2),l=this.get(2,0),d=this.get(2,1),h=this.get(2,2),g=e.get(0,0),c=e.get(0,1),m=e.get(0,2),p=e.get(1,0),u=e.get(1,1),f=e.get(1,2),_=e.get(2,0),b=e.get(2,1),w=e.get(2,2),x=(i-o)*(-c+u),k=(-i+o+s)*(g-c+u),y=(o+s)*(-g+c),v=i*g,j=(-i+l+d)*(g-m+f),D=(-i+l)*(m-f),M=(l+d)*(-g+m),S=(-n+d+h)*(u+_-b),P=(n-h)*(u-b),I=n*_,B=(d+h)*(-_+b),A=(-n+s+r)*(f+_-w),R=(n-r)*(f-w),C=(s+r)*(-_+w);return t.set(0,0,v+I+a*p),t.set(0,1,(i+a+n-o-s-d-h)*u+k+y+v+S+I+B),t.set(0,2,v+j+M+(i+a+n-s-r-l-d)*f+I+A+C),t.set(1,0,x+s*(-g+c+p-u-f-_+w)+k+v+I+A+R),t.set(1,1,x+k+y+v+r*b),t.set(1,2,I+A+R+C+o*m),t.set(2,0,v+j+D+d*(-g+m+p-u-f-_+b)+S+P+I),t.set(2,1,S+P+I+B+l*c),t.set(2,2,v+j+D+M+h*w),t}mmulStrassen(e){function t(e,t,i){var a=e.rows,o=e.columns;if(a===t&&o===i)return e;var s=n.zeros(t,i);return s=s.setSubMatrix(e,0,0),s}function i(e,a,o,s){if(512>=o||512>=s)return e.mmul(a);1==o%2&&1==s%2?(e=t(e,o+1,s+1),a=t(a,o+1,s+1)):1==o%2?(e=t(e,o+1,s),a=t(a,o+1,s)):1==s%2&&(e=t(e,o,s+1),a=t(a,o,s+1));var r=parseInt(e.rows/2),l=parseInt(e.columns/2),d=e.subMatrix(0,r-1,0,l-1),h=a.subMatrix(0,r-1,0,l-1),g=e.subMatrix(0,r-1,l,e.columns-1),c=a.subMatrix(0,r-1,l,a.columns-1),m=e.subMatrix(r,e.rows-1,0,l-1),p=a.subMatrix(r,a.rows-1,0,l-1),u=e.subMatrix(r,e.rows-1,l,e.columns-1),f=a.subMatrix(r,a.rows-1,l,a.columns-1),_=i(n.add(d,u),n.add(h,f),r,l),b=i(n.add(m,u),h,r,l),w=i(d,n.sub(c,f),r,l),x=i(u,n.sub(p,h),r,l),k=i(n.add(d,g),f,r,l),y=i(n.sub(m,d),n.add(h,c),r,l),v=i(n.sub(g,u),n.add(p,f),r,l),j=n.add(_,x);j.sub(k),j.add(v);var D=n.add(w,k),M=n.add(b,x),S=n.sub(_,b);S.add(w),S.add(y);var P=n.zeros(2*j.rows,2*j.columns);return P=P.setSubMatrix(j,0,0),P=P.setSubMatrix(D,j.rows,0),P=P.setSubMatrix(M,0,j.columns),P=P.setSubMatrix(S,j.rows,j.columns),P.subMatrix(0,o-1,0,s-1)}var a=this.clone(),o=a.rows,s=a.columns,l=e.rows,d=e.columns;s!==l&&console.warn(`Multiplying ${o} x ${s} and ${l} x ${d} matrix: dimensions do not match.`);var h=bo(o,l),r=bo(s,d);return a=t(a,h,r),e=t(e,h,r),i(a,e,h,r)}scaleRows(e,t){if(e=void 0===e?0:e,t=void 0===t?1:t,e>=t)throw new RangeError('min should be strictly smaller than max');for(var a=this.constructor.empty(this.rows,this.columns),n=0,i;n<this.rows;n++)i=rs(this.getRow(n),{min:e,max:t}),a.setRow(n,i);return a}scaleColumns(e,t){if(e=void 0===e?0:e,t=void 0===t?1:t,e>=t)throw new RangeError('min should be strictly smaller than max');for(var a=this.constructor.empty(this.rows,this.columns),n=0,i;n<this.columns;n++)i=rs(this.getColumn(n),{min:e,max:t}),a.setColumn(n,i);return a}kroneckerProduct(e){e=this.constructor.checkMatrix(e);for(var t=this.rows,a=this.columns,n=e.rows,o=e.columns,s=new this.constructor[Symbol.species](t*n,a*o),r=0;r<t;r++)for(var i=0;i<a;i++)for(var d=0;d<n;d++)for(var h=0;h<o;h++)s[n*r+d][o*i+h]=this.get(r,i)*e.get(d,h);return s}transpose(){for(var e=new this.constructor[Symbol.species](this.columns,this.rows),t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)e.set(i,t,this.get(t,i));return e}sortRows(e){void 0===e&&(e=t);for(var a=0;a<this.rows;a++)this.setRow(a,this.getRow(a).sort(e));return this}sortColumns(e){void 0===e&&(e=t);for(var a=0;a<this.columns;a++)this.setColumn(a,this.getColumn(a).sort(e));return this}subMatrix(e,t,a,n){H(this,e,t,a,n);for(var o=new this.constructor[Symbol.species](t-e+1,n-a+1),s=e;s<=t;s++)for(var i=a;i<=n;i++)o[s-e][i-a]=this.get(s,i);return o}subMatrixRow(e,t,a){if(void 0===t&&(t=0),void 0===a&&(a=this.columns-1),t>a||0>t||t>=this.columns||0>a||a>=this.columns)throw new RangeError('Argument out of range');for(var n=new this.constructor[Symbol.species](e.length,a-t+1),o=0;o<e.length;o++)for(var i=t;i<=a;i++){if(0>e[o]||e[o]>=this.rows)throw new RangeError('Row index out of range: '+e[o]);n.set(o,i-t,this.get(e[o],i))}return n}subMatrixColumn(e,t,a){if(void 0===t&&(t=0),void 0===a&&(a=this.rows-1),t>a||0>t||t>=this.rows||0>a||a>=this.rows)throw new RangeError('Argument out of range');for(var n=new this.constructor[Symbol.species](a-t+1,e.length),o=0;o<e.length;o++)for(var i=t;i<=a;i++){if(0>e[o]||e[o]>=this.columns)throw new RangeError('Column index out of range: '+e[o]);n.set(i-t,o,this.get(i,e[o]))}return n}setSubMatrix(e,t,a){e=this.constructor.checkMatrix(e);var n=t+e.rows-1,o=a+e.columns-1;H(this,t,n,a,o);for(var s=0;s<e.rows;s++)for(var i=0;i<e.columns;i++)this[t+s][a+i]=e.get(s,i);return this}selection(e,t){for(var a=G(this,e,t),n=new this.constructor[Symbol.species](e.length,t.length),o=0,i;o<a.row.length;o++){i=a.row[o];for(var s=0,r;s<a.column.length;s++)r=a.column[s],n[o][s]=this.get(i,r)}return n}trace(){for(var e=xo(this.rows,this.columns),t=0,a=0;a<e;a++)t+=this.get(a,a);return t}transposeView(){return new ds(this)}rowView(e){return Y(this,e),new hs(this,e)}columnView(e){return X(this,e),new ms(this,e)}flipRowView(){return new ps(this)}flipColumnView(){return new us(this)}subMatrixView(e,t,i,a){return new gs(this,e,t,i,a)}selectionView(e,t){return new cs(this,e,t)}det(){if(this.isSquare()){var e,t,i,a;if(2===this.columns)return e=this.get(0,0),t=this.get(0,1),i=this.get(1,0),a=this.get(1,1),e*a-t*i;if(3===this.columns){var n,o,s;return n=this.selectionView([1,2],[1,2]),o=this.selectionView([1,2],[0,2]),s=this.selectionView([1,2],[0,1]),e=this.get(0,0),t=this.get(0,1),i=this.get(0,2),e*n.det()-t*o.det()+i*s.det()}return new C(this).determinant}throw Error('Determinant can only be calculated for a square matrix.')}pseudoInverse(e){void 0===e&&(e=mo);for(var t=new E(this,{autoTranspose:!0}),a=t.leftSingularVectors,n=t.rightSingularVectors,o=t.diagonal,s=0;s<o.length;s++)o[s]=wo(o[s])>e?1/o[s]:0;return o=this.constructor[Symbol.species].diag(o),n.mmul(o.mmul(a.transposeView()))}}n.prototype.klass='Matrix',n.random=n.rand,n.diagonal=n.diag,n.prototype.diagonal=n.prototype.diag,n.identity=n.eye,n.prototype.negate=n.prototype.neg,n.prototype.tensorProduct=n.prototype.kroneckerProduct,n.prototype.determinant=n.prototype.det;var o=` (function %name%(value) { if (typeof value === 'number') return this.%name%S(value); return this.%name%M(value); }) `,s=` (function %name%S(value) { for (var i = 0; i < this.rows; i++) { for (var j = 0; j < this.columns; j++) { this.set(i, j, this.get(i, j) %op% value); } } return this; }) `,r=` (function %name%M(matrix) { matrix = this.constructor.checkMatrix(matrix); if (this.rows !== matrix.rows || this.columns !== matrix.columns) { throw new RangeError('Matrices dimensions must be equal'); } for (var i = 0; i < this.rows; i++) { for (var j = 0; j < this.columns; j++) { this.set(i, j, this.get(i, j) %op% matrix.get(i, j)); } } return this; }) `,l=` (function %name%(matrix, value) { var newMatrix = new this[Symbol.species](matrix); return newMatrix.%name%(value); }) `,d=` (function %name%() { for (var i = 0; i < this.rows; i++) { for (var j = 0; j < this.columns; j++) { this.set(i, j, %method%(this.get(i, j))); } } return this; }) `,h=` (function %name%(matrix) { var newMatrix = new this[Symbol.species](matrix); return newMatrix.%name%(); }) `,g=` (function %name%(%args%) { for (var i = 0; i < this.rows; i++) { for (var j = 0; j < this.columns; j++) { this.set(i, j, %method%(this.get(i, j), %args%)); } } return this; }) `,c=` (function %name%(matrix, %args%) { var newMatrix = new this[Symbol.species](matrix); return newMatrix.%name%(%args%); }) `,m=` (function %name%S(value) { for (var i = 0; i < this.rows; i++) { for (var j = 0; j < this.columns; j++) { this.set(i, j, %method%(this.get(i, j), value)); } } return this; }) `,p=` (function %name%M(matrix) { matrix = this.constructor.checkMatrix(matrix); if (this.rows !== matrix.rows || this.columns !== matrix.columns) { throw new RangeError('Matrices dimensions must be equal'); } for (var i = 0; i < this.rows; i++) { for (var j = 0; j < this.columns; j++) { this.set(i, j, %method%(this.get(i, j), matrix.get(i, j))); } } return this; }) `,u=` (function %name%(value) { if (typeof value === 'number') return this.%name%S(value); return this.%name%M(value); }) `,f=[['+','add'],['-','sub','subtract'],['*','mul','multiply'],['/','div','divide'],['%','mod','modulus'],['&','and'],['|','or'],['^','xor'],['<<','leftShift'],['>>','signPropagatingRightShift'],['>>>','rightShift','zeroFillRightShift']],_=eval,b;for(var i of f){var w=_(a(o,{name:i[1],op:i[0]})),x=_(a(s,{name:i[1]+'S',op:i[0]})),k=_(a(r,{name:i[1]+'M',op:i[0]})),y=_(a(l,{name:i[1]}));for(b=1;b<i.length;b++)n.prototype[i[b]]=w,n.prototype[i[b]+'S']=x,n.prototype[i[b]+'M']=k,n[i[b]]=y}var v=[['~','not']];['abs','acos','acosh','asin','asinh','atan','atanh','cbrt','ceil','clz32','cos','cosh','exp','expm1','floor','fround','log','log1p','log10','log2','round','sign','sin','sinh','sqrt','tan','tanh','trunc'].forEach(function(e){v.push(['Math.'+e,e])});for(var j of v){var D=_(a(d,{name:j[1],method:j[0]})),M=_(a(h,{name:j[1]}));for(b=1;b<j.length;b++)n.prototype[j[b]]=D,n[j[b]]=M}var S=[['Math.pow',1,'pow']];for(var P of S){var I='arg0';for(b=1;b<P[1];b++)I+=`, arg${b}`;if(1!==P[1]){var B=_(a(g,{name:P[2],method:P[0],args:I})),A=_(a(c,{name:P[2],args:I}));for(b=2;b<P.length;b++)n.prototype[P[b]]=B,n[P[b]]=A}else{var R={name:P[2],args:I,method:P[0]},z=_(a(u,R)),L=_(a(m,R)),T=_(a(p,R)),V=_(a(c,R));for(b=2;b<P.length;b++)n.prototype[P[b]]=z,n.prototype[P[b]+'M']=T,n.prototype[P[b]+'S']=L,n[P[b]]=V}}return n}function J(e){if(!(this instanceof J))return new J(e);e=fs.checkMatrix(e);var t=e.clone(),a=e.rows,o=e.columns,n=Array(o),r,i,l,d;for(l=0;l<o;l++){var h=0;for(r=l;r<a;r++)h=z(h,t[r][l]);if(0!==h){for(0>t[l][l]&&(h=-h),r=l;r<a;r++)t[r][l]/=h;for(t[l][l]+=1,i=l+1;i<o;i++){for(d=0,r=l;r<a;r++)d+=t[r][l]*t[r][i];for(d=-d/t[l][l],r=l;r<a;r++)t[r][i]+=d*t[r][l]}}n[l]=-h}this.QR=t,this.Rdiag=n}function $(e,t){return e=fs.checkMatrix(e),t=fs.checkMatrix(t),e.isSquare()?new C(e).solve(t):new J(e).solve(t)}function ee(t,a){if(a=Object.assign({},_s,a),!(this instanceof ee))return new ee(t,a);if(t=fs.checkMatrix(t),!t.isSquare())throw new Error('Matrix is not a square matrix');var o=t.columns,n=L(o,o,0),s=Array(o),r=Array(o),e=t,l=!1,d,i;if(l=!!a.assumeSymmetric||t.isSymmetric(),l){for(d=0;d<o;d++)for(i=0;i<o;i++)n[d][i]=e.get(d,i);te(o,r,s,n),ie(o,r,s,n)}else{var h=L(o,o,0),g=Array(o);for(i=0;i<o;i++)for(d=0;d<o;d++)h[d][i]=e.get(d,i);ae(o,h,g,n),ne(o,r,s,n,h)}this.n=o,this.e=r,this.d=s,this.V=n}function te(t,a,e,n){var o,s,r,l,i,d,h,c;for(i=0;i<t;i++)e[i]=n[t-1][i];for(l=t-1;0<l;l--){for(c=0,r=0,d=0;d<l;d++)c+=wo(e[d]);if(0===c)for(a[l]=e[l-1],i=0;i<l;i++)e[i]=n[l-1][i],n[l][i]=0,n[i][l]=0;else{for(d=0;d<l;d++)e[d]/=c,r+=e[d]*e[d];for(o=e[l-1],s=Do(r),0<o&&(s=-s),a[l]=c*s,r-=o*s,e[l-1]=o-s,i=0;i<l;i++)a[i]=0;for(i=0;i<l;i++){for(o=e[i],n[i][l]=o,s=a[i]+n[i][i]*o,d=i+1;d<=l-1;d++)s+=n[d][i]*e[d],a[d]+=n[d][i]*o;a[i]=s}for(o=0,i=0;i<l;i++)a[i]/=r,o+=a[i]*e[i];for(h=o/(r+r),i=0;i<l;i++)a[i]-=h*e[i];for(i=0;i<l;i++){for(o=e[i],s=a[i],d=i;d<=l-1;d++)n[d][i]-=o*a[d]+s*e[d];e[i]=n[l-1][i],n[l][i]=0}}e[l]=r}for(l=0;l<t-1;l++){if(n[t-1][l]=n[l][l],n[l][l]=1,r=e[l+1],0!==r){for(d=0;d<=l;d++)e[d]=n[d][l+1]/r;for(i=0;i<=l;i++){for(s=0,d=0;d<=l;d++)s+=n[d][l+1]*n[d][i];for(d=0;d<=l;d++)n[d][i]-=s*e[d]}}for(d=0;d<=l;d++)n[d][l+1]=0}for(i=0;i<t;i++)e[i]=n[t-1][i],n[t-1][i]=0;n[t-1][t-1]=1,a[0]=0}function ie(t,a,e,n){var o,d,h,i,g,u,l,m,p,_,b,c,w,x,k,y,v;for(h=1;h<t;h++)a[h-1]=a[h];a[t-1]=0;var j=0,f=0,D=2.220446049250313e-16;for(u=0;u<t;u++){for(f=bo(f,wo(e[u])+wo(a[u])),l=u;l<t&&!(wo(a[l])<=D*f);)l++;if(l>u){v=0;do{for(++v,o=e[u],m=(e[u+1]-o)/(2*a[u]),p=z(m,1),0>m&&(p=-p),e[u]=a[u]/(m+p),e[u+1]=a[u]*(m+p),_=e[u+1],d=o-e[u],h=u+2;h<t;h++)e[h]-=d;for(j+=d,m=e[l],b=1,c=b,w=b,x=a[u+1],k=0,y=0,h=l-1;h>=u;h--)for(w=c,c=b,y=k,o=b*a[h],d=b*m,p=z(m,a[h]),a[h+1]=k*p,k=a[h]/p,b=m/p,m=b*e[h]-k*o,e[h+1]=d+k*(b*o+k*e[h]),g=0;g<t;g++)d=n[g][h+1],n[g][h+1]=k*n[g][h]+b*d,n[g][h]=b*n[g][h]-k*d;m=-k*y*w*x*a[u]/_,a[u]=k*m,e[u]=b*m}while(wo(a[u])>D*f)}e[u]+=j,a[u]=0}for(h=0;h<t-1;h++){for(g=h,m=e[h],i=h+1;i<t;i++)e[i]<m&&(g=i,m=e[i]);if(g!==h)for(e[g]=e[h],e[h]=m,i=0;i<t;i++)m=n[i][h],n[i][h]=n[i][g],n[i][g]=m}}function ae(e,t,a,n){var o=0,s=e-1,r,l,d,h,i,c,m;for(c=o+1;c<=s-1;c++){for(m=0,h=c;h<=s;h++)m+=wo(t[h][c-1]);if(0!==m){for(d=0,h=s;h>=c;h--)a[h]=t[h][c-1]/m,d+=a[h]*a[h];for(l=Do(d),0<a[c]&&(l=-l),d-=a[c]*l,a[c]-=l,i=c;i<e;i++){for(r=0,h=s;h>=c;h--)r+=a[h]*t[h][i];for(r/=d,h=c;h<=s;h++)t[h][i]-=r*a[h]}for(h=0;h<=s;h++){for(r=0,i=s;i>=c;i--)r+=a[i]*t[h][i];for(r/=d,i=c;i<=s;i++)t[h][i]-=r*a[i]}a[c]=m*a[c],t[c][c-1]=m*l}}for(h=0;h<e;h++)for(i=0;i<e;i++)n[h][i]=h===i?1:0;for(c=s-1;c>=o+1;c--)if(0!==t[c][c-1]){for(h=c+1;h<=s;h++)a[h]=t[h][c-1];for(i=c;i<=s;i++){for(l=0,h=c;h<=s;h++)l+=a[h]*n[h][i];for(l=l/a[c]/t[c][c-1],h=c;h<=s;h++)n[h][i]+=l*a[h]}}}function ne(a,o,e,d,h){var g=a-1,n=0,c=a-1,u=2.220446049250313e-16,f=0,_=0,b=0,p=0,v=0,D=0,M=0,S=0,P,i,j,k,l,m,t,w,x,y,I,B,A,R,C;for(P=0;P<a;P++)for((P<n||P>c)&&(e[P]=h[P][P],o[P]=0),i=bo(P-1,0);i<a;i++)_+=wo(h[P][i]);for(;g>=n;){for(k=g;k>n&&(D=wo(h[k-1][k-1])+wo(h[k][k]),0===D&&(D=_),!(wo(h[k][k-1])<u*D));)k--;if(k===g)h[g][g]+=f,e[g]=h[g][g],o[g]=0,g--,S=0;else if(k===g-1){if(t=h[g][g-1]*h[g-1][g],b=(h[g-1][g-1]-h[g][g])/2,p=b*b+t,M=Do(wo(p)),h[g][g]+=f,h[g-1][g-1]=h[g-1][g-1]+f,w=h[g][g],0<=p){for(M=0<=b?b+M:b-M,e[g-1]=w+M,e[g]=e[g-1],0!==M&&(e[g]=w-t/M),o[g-1]=0,o[g]=0,w=h[g][g-1],D=wo(w)+wo(M),b=w/D,p=M/D,v=Do(b*b+p*p),b/=v,p/=v,i=g-1;i<a;i++)M=h[g-1][i],h[g-1][i]=p*M+b*h[g][i],h[g][i]=p*h[g][i]-b*M;for(P=0;P<=g;P++)M=h[P][g-1],h[P][g-1]=p*M+b*h[P][g],h[P][g]=p*h[P][g]-b*M;for(P=n;P<=c;P++)M=d[P][g-1],d[P][g-1]=p*M+b*d[P][g],d[P][g]=p*d[P][g]-b*M}else e[g-1]=w+b,e[g]=w+b,o[g-1]=M,o[g]=-M;g-=2,S=0}else{if(w=h[g][g],x=0,t=0,k<g&&(x=h[g-1][g-1],t=h[g][g-1]*h[g-1][g]),10==S){for(f+=w,P=n;P<=g;P++)h[P][P]-=w;D=wo(h[g][g-1])+wo(h[g-1][g-2]),w=x=0.75*D,t=-0.4375*D*D}if(30==S&&(D=(x-w)/2,D=D*D+t,0<D)){for(D=Do(D),x<w&&(D=-D),D=w-t/((x-w)/2+D),P=n;P<=g;P++)h[P][P]-=D;f+=D,w=x=t=0.964}for(++S,l=g-2;l>=k&&(M=h[l][l],v=w-M,D=x-M,b=(v*D-t)/h[l+1][l]+h[l][l+1],p=h[l+1][l+1]-M-v-D,v=h[l+2][l+1],D=wo(b)+wo(p)+wo(v),b/=D,p/=D,v/=D,l!==k)&&!(wo(h[l][l-1])*(wo(p)+wo(v))<u*(wo(b)*(wo(h[l-1][l-1])+wo(M)+wo(h[l+1][l+1]))));)l--;for(P=l+2;P<=g;P++)h[P][P-2]=0,P>l+2&&(h[P][P-3]=0);for(j=l;j<=g-1&&(R=j!==g-1,j!==l&&(b=h[j][j-1],p=h[j+1][j-1],v=R?h[j+2][j-1]:0,w=wo(b)+wo(p)+wo(v),0!==w&&(b/=w,p/=w,v/=w)),0!==w);j++)if(D=Do(b*b+p*p+v*v),0>b&&(D=-D),0!==D){for(j===l?k!==l&&(h[j][j-1]=-h[j][j-1]):h[j][j-1]=-D*w,b+=D,w=b/D,x=p/D,M=v/D,p/=b,v/=b,i=j;i<a;i++)b=h[j][i]+p*h[j+1][i],R&&(b+=v*h[j+2][i],h[j+2][i]=h[j+2][i]-b*M),h[j][i]-=b*w,h[j+1][i]=h[j+1][i]-b*x;for(P=0;P<=xo(g,j+3);P++)b=w*h[P][j]+x*h[P][j+1],R&&(b+=M*h[P][j+2],h[P][j+2]=h[P][j+2]-b*v),h[P][j]-=b,h[P][j+1]=h[P][j+1]-b*p;for(P=n;P<=c;P++)b=w*d[P][j]+x*d[P][j+1],R&&(b+=M*d[P][j+2],d[P][j+2]=d[P][j+2]-b*v),d[P][j]-=b,d[P][j+1]=d[P][j+1]-b*p}}}if(0!==_){for(g=a-1;0<=g;g--)if(b=e[g],p=o[g],0===p)for(k=g,h[g][g]=1,P=g-1;0<=P;P--){for(t=h[P][P]-b,v=0,i=k;i<=g;i++)v+=h[P][i]*h[i][g];if(0>o[P])M=t,D=v;else if(k=P,0===o[P]?h[P][g]=0===t?-v/(u*_):-v/t:(w=h[P][P+1],x=h[P+1][P],p=(e[P]-b)*(e[P]-b)+o[P]*o[P],m=(w*D-M*v)/p,h[P][g]=m,h[P+1][g]=wo(w)>wo(M)?(-v-t*m)/w:(-D-x*m)/M),m=wo(h[P][g]),1<u*m*m)for(i=P;i<=g;i++)h[i][g]/=m}else if(0>p)for(k=g-1,wo(h[g][g-1])>wo(h[g-1][g])?(h[g-1][g-1]=p/h[g][g-1],h[g-1][g]=-(h[g][g]-b)/h[g][g-1]):(C=oe(0,-h[g-1][g],h[g-1][g-1]-b,p),h[g-1][g-1]=C[0],h[g-1][g]=C[1]),h[g][g-1]=0,h[g][g]=1,P=g-2;0<=P;P--){for(y=0,I=0,i=k;i<=g;i++)y+=h[P][i]*h[i][g-1],I+=h[P][i]*h[i][g];if(t=h[P][P]-b,0>o[P])M=t,v=y,D=I;else if(k=P,0===o[P]?(C=oe(-y,-I,t,p),h[P][g-1]=C[0],h[P][g]=C[1]):(w=h[P][P+1],x=h[P+1][P],B=(e[P]-b)*(e[P]-b)+o[P]*o[P]-p*p,A=2*(e[P]-b)*p,0===B&&0===A&&(B=u*_*(wo(t)+wo(p)+wo(w)+wo(x)+wo(M))),C=oe(w*v-M*y+p*I,w*D-M*I-p*y,B,A),h[P][g-1]=C[0],h[P][g]=C[1],wo(w)>wo(M)+wo(p)?(h[P+1][g-1]=(-y-t*h[P][g-1]+p*h[P][g])/w,h[P+1][g]=(-I-t*h[P][g]-p*h[P][g-1])/w):(C=oe(-v-x*h[P][g-1],-D-x*h[P][g],M,p),h[P+1][g-1]=C[0],h[P+1][g]=C[1])),m=bo(wo(h[P][g-1]),wo(h[P][g])),1<u*m*m)for(i=P;i<=g;i++)h[i][g-1]=h[i][g-1]/m,h[i][g]/=m}for(P=0;P<a;P++)if(P<n||P>c)for(i=P;i<a;i++)d[P][i]=h[P][i];for(i=a-1;i>=n;i--)for(P=n;P<=c;P++){for(M=0,j=n;j<=xo(i,c);j++)M+=d[P][j]*h[j][i];d[P][i]=M}}}function oe(e,t,i,a){var n,o;return wo(i)>wo(a)?(n=a/i,o=i+n*a,[(e+n*t)/o,(t-n*e)/o]):(n=i/a,o=a+n*i,[(n*e+t)/o,(n*t-e)/o])}function se(e){if(!(this instanceof se))return new se(e);if(e=fs.checkMatrix(e),!e.isSymmetric())throw new Error('Matrix is not symmetric');var t=e,a=t.rows,n=new fs(a,a),o=!0,r,i,l;for(i=0;i<a;i++){var h=n[i],g=0;for(l=0;l<i;l++){var d=n[l],c=0;for(r=0;r<l;r++)c+=d[r]*h[r];h[l]=c=(t[i][l]-c)/n[l][l],g+=c*c}for(g=t[i][i]-g,o&=0<g,n[i][i]=Do(bo(g,0)),l=i+1;l<a;l++)n[i][l]=0}if(!o)throw new Error('Matrix is not positive definite');this.L=n}function re(e){var t=new E(e,{autoTranspose:!0});if(1!==t.rank)return null;var i=Do(t.s[0]),a=t.U.map((e)=>e[0]*i),n=t.V.map((e)=>e[0]*i);return[a,n]}function le(e,t={}){var a=t.channels,n=t.bitDepth,o=t.normalize,s=void 0!==o&&o,r=t.divisor,l=void 0===r?1:r,d=t.border,h=void 0===d?'copy':d,g=t.algorithm,m=void 0===g?'auto':g,p=Dc.createFrom(this,{bitDepth:n});if(a=u(this,a,!0),'separable'!==m){var f=I(e);e=f.kernel}else if(!Array.isArray(e)||2!==e.length)throw new RangeError('separable convolution requires two arrays of numbers to represent the kernel');if('auto'===m){var _=re(e);null===_?(9<e.length||9<e[0].length)&&4096>=this.width&&4096>=this.height?m='fft':m='direct':(m='separable',e=_)}var b,w;'separable'===m?(b=Po(e[0].length/2),w=Po(e[1].length/2)):(b=Po(e.length/2),w=Po(e[0].length/2));var k=p.isClamped,v=Array(this.height*this.width),D,M,x,y,S,c;for(y=0;y<a.length;y++){for(S=a[y],x=0;x<this.height;x++)for(M=0;M<this.width;M++)D=x*this.width+M,v[D]=this.data[D*this.channels+S];if('direct'===m)c=Ho(v,e,{rows:this.height,cols:this.width,normalize:s,divisor:l});else if('separable'===m){if(c=R(v,e,this.width,this.height),s){l=0;for(var P=0;P<e[0].length;P++)for(var i=0;i<e[1].length;i++)l+=e[0][P]*e[1][i]}if(1!==l)for(var j=0;j<c.length;j++)c[j]/=l}else c=Wo(v,e,{rows:this.height,cols:this.width,normalize:s,divisor:l});for(x=0;x<this.height;x++)for(M=0;M<this.width;M++)D=x*this.width+M,p.data[D*this.channels+S]=k?xo(bo(c[D],0),p.maxValue):c[D]}if(this.alpha&&!a.includes(this.channels))for(M=this.components;M<this.data.length;M+=this.channels)p.data[M]=this.data[M];return'periodic'!==h&&p.setBorder({size:[w,b],algorithm:h}),p}function de(e={}){var t=e.radius,i=void 0===t?1:t,a=e.sigma,n=e.channels,o=e.border,s=void 0===o?'copy':o;this.checkProcessable('gaussian',{bitDepth:[8,16]});var r;return a?r=ge(a):(a=0.3*(i-1)+0.8,r=he(i,a)),le.call(this,[r,r],{border:s,channels:n,algorithm:'separable'})}function he(e,t){if(1>e)throw new RangeError('Radius should be grater than 0');for(var a=Array(2*e+1),n=0,i;n<=e;n++)i=jo(n*n*(0-1/(2*t*t)))*(1/(t*ws)),a[e+n]=i,a[e-n]=i;return a}function ge(e){if(0>=e)throw new RangeError('Sigma should be grater than 0');for(var t=2*(e*e),a=So*t,n=1/a,o=n,s=0;0.99>o;){s++,n=jo(-(s*s)/t)/a,o+=4*n;for(var r=1;r<s;r++)n=jo(-(r*r+s*s)/t)/a,o+=8*n;n=4*jo(-(2*s*s)/t)/a,o+=n}if(1<o)throw new Error('unexpected sum over 1');return he(s,e)}function ce(e={}){var t=e.kernelX,i=void 0===t?xs:t,a=e.kernelY,n=void 0===a?ks:a,o=e.border,s=void 0===o?'copy':o,r=e.channels,l=e.bitDepth,d=void 0===l?this.bitDepth:l;this.checkProcessable('sobel',{bitDepth:[8,16]});var h=le.call(this,i,{channels:r,border:s,bitDepth:32}),g=le.call(this,n,{channels:r,border:s,bitDepth:32});return h.hypotenuse(g,{bitDepth:d,channels:r})}function me(e={}){var t=e.algorithm,i=void 0===t?'range':t,a=e.channels,n=e.min,o=void 0===n?this.min:n,s=e.max,r=void 0===s?this.max:s;switch(this.checkProcessable('level',{bitDepth:[8,16]}),a=u(this,{channels:a}),i){case'range':0>o&&(o=0),r>this.maxValue&&(r=this.maxValue),Array.isArray(o)||(o=ys(a.length,o)),Array.isArray(r)||(r=ys(a.length,r)),pe(this,o,r,a);break;default:throw new Error('level: algorithm not implement: '+i);}return this}function pe(e,t,a,n){var o=1e-5,s=Array(e.channels);for(var r of n)s[r]=0===t[r]&&a[r]===e.maxValue?0:a[r]===t[r]?0:(e.maxValue+1-o)/(a[r]-t[r]),t[r]+=(0.5-o/2)/s[r];for(var l=0,d;l<n.length;l++)if(d=n[l],0!==s[d])for(var h=0;h<e.data.length;h+=e.channels)e.data[h+d]=xo(bo(0,0|(e.data[h+d]-t[d])*s[d]+0.5),e.maxValue)}function ue(e){if(!isNaN(e)){if(0>=e)throw new Error('checkNumberArray: the value must be greater than 0');return e}if(e instanceof Dc)return e.data;if(!js(e))throw new Error('checkNumberArray: the value should be either a number, array or Image');return e}function fe(e,t={}){var a=t.channels;if(this.checkProcessable('add',{bitDepth:[8,16]}),a=u(this,{channels:a}),e=ue(e),!isNaN(e))for(var n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<this.data.length;s+=this.channels)this.data[s+o]=xo(this.maxValue,this.data[s+o]+e>>0)}else{if(this.data.length!==e.length)throw new Error('add: the data size is different');for(var i=0,r;i<a.length;i++){r=a[i];for(var l=0;l<this.data.length;l+=this.channels)this.data[l+r]=bo(0,xo(this.maxValue,this.data[l+r]+e[l+r]>>0))}}return this}function _e(e,t={}){var a=t.channels;if(this.checkProcessable('subtract',{bitDepth:[8,16]}),a=u(this,{channels:a}),e=ue(e),!isNaN(e))for(var n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<this.data.length;s+=this.channels)this.data[s+o]=bo(0,this.data[s+o]-e>>0)}else{if(this.data.length!==e.length)throw new Error('substract: the data size is different');for(var i=0,r;i<a.length;i++){r=a[i];for(var l=0;l<this.data.length;l+=this.channels)this.data[l+r]=bo(0,xo(this.maxValue,this.data[l+r]-e[l+r]>>0))}}return this}function be(e,t={}){var a=t.bitDepth,n=void 0===a?this.bitDepth:a,o=t.channels;if(this.checkProcessable('hypotenuse',{bitDepth:[8,16,32]}),this.width!==e.width||this.height!==e.height)throw new Error('hypotenuse: both images must have the same size');if(this.alpha!==e.alpha||this.bitDepth!==e.bitDepth)throw new Error('hypotenuse: both images must have the same alpha and bitDepth');if(this.channels!==e.channels)throw new Error('hypotenuse: both images must have the same number of channels');var s=Dc.createFrom(this,{bitDepth:n});o=u(this,{channels:o});for(var r=s.isClamped,l=0,d;l<o.length;l++){d=o[l];for(var h=d,i;h<this.data.length;h+=this.channels)i=Math.hypot(this.data[h],e.data[h]),s.data[h]=r?xo(bo(vo(i),0),s.maxValue):i}return s}function we(e,t={}){var a=t.channels;if(this.checkProcessable('multiply',{bitDepth:[8,16]}),0>=e)throw new Error('multiply: the value must be greater than 0');if(a=u(this,{channels:a}),e=ue(e),!isNaN(e))for(var n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<this.data.length;s+=this.channels)this.data[s+o]=xo(this.maxValue,this.data[s+o]*e>>0)}else{if(this.data.length!==e.length)throw new Error('multiply: the data size is different');for(var i=0,r;i<a.length;i++){r=a[i];for(var l=0;l<this.data.length;l+=this.channels)this.data[l+r]=bo(0,xo(this.maxValue,this.data[l+r]*e[l+r]>>0))}}return this}function xe(e,t={}){var a=t.channels;if(this.checkProcessable('divide',{bitDepth:[8,16]}),a=u(this,{channels:a}),e=ue(e),!isNaN(e))for(var n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<this.data.length;s+=this.channels)this.data[s+o]=xo(this.maxValue,this.data[s+o]/e>>0)}else{if(this.data.length!==e.length)throw new Error('divide: the: the data size is different');for(var i=0,r;i<a.length;i++){r=a[i];for(var l=0;l<this.data.length;l+=this.channels)this.data[l+r]=bo(0,xo(this.maxValue,this.data[l+r]/e[l+r]>>0))}}return this}function ke(e,t){return 0>e?(e=0-e,'number'==typeof t?'- '+e.toPrecision(t):'- '+e.toString()):'number'==typeof t?e.toPrecision(t):e.toString()}function ye(e,t){if(!Array.isArray(e)||!Array.isArray(t))throw new TypeError('x and y must be arrays');if(e.length!==t.length)throw new RangeError('x and y arrays must have the same length')}function ve(e,t,a){const o=t.length;let n=0,s=0,r=0,l=0;for(let d=0;d<o;d++)n+=t[d],s+=a[d],r+=t[d]*t[d],l+=t[d]*a[d];const i=o*l-n*s;e.slope=i/(o*r-n*n),e.intercept=1/o*s-e.slope*(1/o)*n,e.coefficients=[e.intercept,e.slope]}function je(e,t,i,a){const o=t.length;let n;if(Array.isArray(a))n=a,a=n.length;else{a++,n=Array(a);for(let e=0;e<a;e++)n[e]=e}const s=new fs(o,a),r=new fs([i]);for(let r=0;r<a;r++)for(let e=0;e<o;e++)s[e][r]=0===n[r]?1:_o(t[e],n[r]);const l=s.transposeView(),d=l.mmul(s),h=l.mmul(r.transposeView());e.degree=a-1,e.powers=n,e.coefficients=$(d,h).to1DArray()}function De(e,t,a){const o=t.length,n=Array(o);for(let s=0;s<o;s++)n[s]=fo(a[s]);const i=new Ms(t,n);e.A=i.slope,e.B=jo(i.intercept)}function Me(e,t,a){const o=t.length,n=Array(o),s=Array(o);for(let r=0;r<o;r++)n[r]=fo(t[r]),s[r]=fo(a[r]);const i=new Ms(n,s);e.A=jo(i.intercept),e.B=i.slope}function Se(e,t){for(var a=0,n=0;n<e.length;n++)a+=(e[n]-t[n])*(e[n]-t[n]);return a}function Pe(e,t){return Do(Se(e,t))}function Ie(e,t){for(var a=e.clone(),n=0;n<e.rows;++n)a[n][0]=_o(a[n][0],t);return a}function Be(e,t){this[e][t]=wo(this[e][t])}function Ae(e,t,a){let n=t.length,o=Array(n*n),s=0;for(let r=0;r<n;++r)for(let e=r+1;e<n;++e)t[r]!==t[e]&&(o[s++]=(a[e]-a[r])/(t[e]-t[r]));o.length=s;let r=pr(o),l=Array(n);for(let o=0;o<n;++o)l[o]=a[o]-r*t[o];e.slope=r,e.intercept=pr(l),e.coefficients=[e.intercept,e.slope]}function Re(e,t,a,n){let o=Array(n);for(let i=0;i<n;i++)o[i]=i;const s=Ce(t,a,n);for(var r=0,i;r<s.length;r++){for(var l=s[r],d=ze(l,o),h=t.slice(),g=0;g<t.length;g++)h[g]=a[g]-Le(t[g],o,d),h[g]={residual:h[g]*h[g],coefficients:d};var c=Ee(h);(!i||c.residual<i.residual)&&(i=c)}e.degree=n,e.powers=o,e.coefficients=i.coefficients}function Ce(e,t,a){for(var n=Po(e.length/a),o=Array(n),s=0;s<e.length;s++){for(var i=Po(Math.random()*n),r=0;r<e.length;)if(!o[i]){o[i]=[{x:e[s],y:t[s]}];break}else if(o[i].length<a){o[i].push({x:e[s],y:t[s]});break}else r++,i=(i+1)%n;if(r===e.length)return o}return o}function ze(e,t){for(var a=e.slice(),n=e.slice(),o=0;o<a.length;o++){n[o]=[e[o].y],a[o]=Array(t.length);for(var i=0;i<t.length;i++)a[o][i]=_o(e[o].x,t[i])}return $(a,n).to1DArray()}function Le(e,t,i){let a=0;for(let n=0;n<t.length;n++)a+=i[n]*_o(e,t[n]);return a}function Ee(e){e.sort((e,t)=>e.residual-t.residual);var t=e.length,i=Po(t/2);return 0==t%2?e[i-1]:e[i]}function Te(e,t,a){for(var n=new xr(e,t,a),o=Array(this.size),s=0;s<this.width;s++)for(var i=0;i<this.height;i++)o[i*this.width+s]=[s,i];for(var r=n.predict(o),l=Dc.createFrom(this),d=0;d<this.size;d++)l.data[d]=xo(this.maxValue,bo(0,r[d][0]));return l}function Ve(e={}){var t=e.x,a=void 0===t?0:t,n=e.y,o=void 0===n?0:n,s=e.width,r=void 0===s?this.width-a:s,l=e.height,d=void 0===l?this.height-o:l;if(this.checkProcessable('max',{bitDepth:[8,16]}),a=vo(a),o=vo(o),r=vo(r),d=vo(d),a>this.width-1||o>this.height-1)throw new RangeError(`crop: origin (x:${a}, y:${o}) out of range (${this.width-1}; ${this.height-1})`);if(0>=r||0>=d)throw new RangeError(`crop: width and height (width:${r}; height:${d}) must be positive numbers`);if(0>a||0>o)throw new RangeError(`crop: x and y (x:${a}, y:${o}) must be positive numbers`);if(r>this.width-a||d>this.height-o)throw new RangeError(`crop: (x: ${a}, y:${o}, width:${r}, height:${d}) size is out of ran