@inovitas/infra3dapi 0.2.8 → 1.0.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.
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("infra3dapi",[],e):"object"==typeof exports?exports.infra3dapi=e():t.infra3dapi=e()}(self,(()=>(()=>{"use strict";var t,e,r={7012:(t,e,r)=>{var a=r(17505),o=r.n(a);const h=self;class s{constructor(){this.offsetConstant=6,this.minimumPixelDistance=5,this.NCCCutoff=.75,this.alphaCutoff=1e-6,this.minAffParsNorm=.15,this.minRadParsNorm=1.5,this.omegaIterationStop=1.01,this.mue=.1,this.alphaMin=1e-9,this.autoradio=1,this.searchWindowPosQuality=0,this.onprogress=null,this._createFilterMatrix=function(){let t=[],e=[];t.push([-3,0,3],[-10,0,10],[-3,0,3]),e.push([-3,-10,-3],[0,0,0],[3,10,3]);let r={};return r.filterX=t,r.filterY=e,r},this._obtainGradient=function(t,e){let r=[],a=[];for(let o=0;o<t.length;++o){let h=Math.floor(o/e),s=Math.floor(o%e);if(0!=s&&s!=e-1&&0!=h&&h!=e-1){let h=(t[o+1]-t[o-1])/2;r.push(h);let s=(t[o+e]-t[o-e])/2;a.push(s)}}let o={};return o.gradientX=r,o.gradientY=a,o},this._interpolate2D=function(t,e,r,a){if("bilinear"==a){let a=t[Math.floor(e[1])][Math.floor(e[0])],o=t[Math.floor(e[1])][Math.floor(e[0])+1],h=t[Math.floor(e[1])+1][Math.floor(e[0])],s=t[Math.floor(e[1])+1][Math.floor(e[0])+1];return a=r[0]*a+r[1],o=r[0]*o+r[1],h=r[0]*h+r[1],s=r[0]*s+r[1],(e[0]-Math.floor(e[0]))*(e[1]-Math.floor(e[1]))*s+(1-e[0]+Math.floor(e[0]))*(e[1]-Math.floor(e[1]))*h+(e[0]-Math.floor(e[0]))*(1-e[1]+Math.floor(e[1]))*o+(1-e[0]+Math.floor(e[0]))*(1-e[1]+Math.floor(e[1]))*a}if("lanczos2"==a){(p=[]).push(Math.floor(e[0])-1),p.push(p[0]+1),p.push(p[0]+2),p.push(p[0]+3),(d=[]).push(Math.floor(e[1])-1),d.push(d[0]+1),d.push(d[0]+2),d.push(d[0]+3);for(var o=[],h=0;h<4;++h)if((M=Math.abs(e[0]-p[h]))>=2)o.push(0);else if(0==M)o.push(1);else{if(!(M<2&&M>=0))return 0;var s=Math.sin(Math.PI*M)/(Math.PI*M)*Math.sin(Math.PI*M/2)/(Math.PI*M/2);o.push(s)}for(var i=[],n=0;n<4;++n){var l=0;for(h=0;h<4;++h)l+=o[h]*(r[0]*t[d[n]][p[h]]+r[1]);i.push(l)}var f=[];for(h=0;h<4;++h)if((M=Math.abs(e[1]-d[h]))>=2)f.push(0);else if(0==M)f.push(1);else{if(!(M<2&&M>=0))return 0;s=Math.sin(Math.PI*M)/(Math.PI*M)*Math.sin(Math.PI*M/2)/(Math.PI*M/2),f.push(s)}var u=0;for(n=0;n<4;++n)u+=f[n]*i[n];return u}if("lanczos3"==a){var p,d;for((p=[]).push(Math.floor(e[0])-2),p.push(p[0]+1),p.push(p[0]+2),p.push(p[0]+3),p.push(p[0]+4),p.push(p[0]+5),(d=[]).push(Math.floor(e[1])-2),d.push(d[0]+1),d.push(d[0]+2),d.push(d[0]+3),d.push(d[0]+4),d.push(d[0]+5),o=[],h=0;h<6;++h)if((M=Math.abs(e[0]-p[h]))>=2)o.push(0);else if(0==M)o.push(1);else{if(!(M<2&&M>=0))return 0;s=Math.sin(Math.PI*M)/(Math.PI*M)*Math.sin(Math.PI*M/3)/(Math.PI*M/3),o.push(s)}for(i=[],n=0;n<6;++n){for(l=0,h=0;h<6;++h)l+=o[h]*(r[0]*t[d[n]][p[h]]+r[1]);i.push(l)}for(f=[],h=0;h<6;++h){var M;if((M=Math.abs(e[1]-d[h]))>=2)f.push(0);else if(0==M)f.push(1);else{if(!(M<2&&M>=0))return 0;s=Math.sin(Math.PI*M)/(Math.PI*M)*Math.sin(Math.PI*M/3)/(Math.PI*M/3),f.push(s)}}for(u=0,n=0;n<6;++n)u+=f[n]*i[n];return u}},this._fillAMatrix=function(t,e,r,a,o){let h=[],s=0;for(let o=-Math.floor(a/2);o<=Math.floor(a/2);++o)for(let i=-Math.floor(a/2);i<=Math.floor(a/2);++i){let a=[i,0],n=[o,0],l=[0,i],f=[0,o],u=[1,0],p=[0,1],d=e[s]*a[0]+r[s]*a[1],M=e[s]*n[0]+r[s]*n[1],c=e[s]*l[0]+r[s]*l[1],g=e[s]*f[0]+r[s]*f[1],m=e[s]*u[0]+r[s]*u[1],v=e[s]*p[0]+r[s]*p[1];h.push([]);let C=t[s],N=1;h[s].push(d,M,c,g,m,v,C,N),s++}return h},this._Adjustment=function(t,e,r,a){let h=0,s=0,i=0,n=0,l=[Math.floor(t.length/2),Math.floor(t[0].length/2)],f=[a[0],a[1]],u=[1,0,0,1,l[1],l[0],1,0],p=[1,0,0,1,f[1],f[0],1,0],d=this._generatePatch(t,u,r),M=this._Wallisfilter(d);if(0==M)return 0;let c=p,g=c,m=1e10,v=0,C=0,N=0,P=[],_=[],b=[],w=o().diag([1,1,1,1,1,1,1,1]);for(;0==h;){this.onprogress&&this.onprogress();let t=this._generatePatch(e,c,r+2);if(0==t)return 0;let a=this._obtainGradient(t,r+2),l=a.gradientX,f=a.gradientY,u=this._generatePatch(e,c,r),d=this._Wallisfilter(u);if(0==d)return 0;0==s&&0==s&&(m=o().sub(M,d),N=this._NormCrossCor(M,d)),P=this._fillAMatrix(d,l,f,r,i),_=o().dot(o().transpose(P),P),0==i?(w[6][6]=1e32,w[7][7]=1e32):(w[6][6]=1,w[7][7]=1),_=o().add(_,w),b=o().dot(o().transpose(P),m);let O=o().solve(_,b),R=o().dot(P,O),k=o().dot(R,m),W=o().sub(R,m);v=C,C=.5*o().dot(W,W);let U=this._Linesearch(c,O,m,k,this.alphaMin,this.mue,M,d,e,r);if(0==U)return 0;var I=U.alphaLength;let T=U.xNew,z=U.rNew;N=U.NCC;var S=U.searchUpdate;g=c,c=T,m=z,o().norm2(R),o().norm2(m);let B=Math.sqrt(C/(Math.pow(r,2)-8)),Q=o().inv(_);for(var x=[],y=0;y<8;++y)x.push(Math.sqrt(B*Q[y][y]));let X=[],Y=[];for(y=0;y<8;++y){X.push([]);let t=Q[y][y];for(var D=0;D<8;++D){let e=Q[D][D];X[y].push(Q[y][D]/Math.sqrt(t*e))}}let $=7;for(y=0;y<7;++y){for(D=1;D<$;++D)X[y][D]>.99&&y!=D?X[y][D]>X[D][y]?Y.push(y,D,1e20,X[y][D]):Y.push(D,y,1e20,X[D][y]):X[y][D]>.9&&y!=D?X[y][D]>X[D][y]?Y.push(y,D,10/X[y][D],X[y][D]):Y.push(D,y,10/X[D][y],X[D][y]):X[y][D]>.7&&y!=D?X[y][D]>X[D][y]?Y.push(y,D,5/X[y][D],X[y][D]):Y.push(D,y,5/X[D][y],X[D][y]):X[y][D]>.5&&y!=D?X[y][D]>X[D][y]?Y.push(y,D,2/X[y][D],X[y][D]):Y.push(D,y,2/X[D][y],X[D][y]):X[y][D]>.3&&y!=D&&(X[y][D]>X[D][y]?Y.push(y,D,1/X[y][D],X[y][D]):Y.push(D,y,1/X[D][y],X[D][y]));--$}if(s++,(s>=50||I<this.alphaMin)&&(h=2),s>0&&v/C<this.omegaIterationStop&&v/C>1/this.omegaIterationStop)if(1==this.autoradio){if(0==i&&(n=s),i=1,v/C<this.omegaIterationStop&&v/C>1/this.omegaIterationStop&&s>n){let t=[];for(y=0;y<8;++y){let e=o().sub(c,p);t.push(Math.abs(e[y]/x[y]))}var A=o().getBlock(x,[0,0],[5,0]),j=o().getBlock(x,[6,0],[7,0]),L=o().norm2(A),q=o().norm2(j);h=L>this.minAffParsNorm||q>this.minRadParsNorm?2:1}}else v/C<this.omegaIterationStop&&v/C>1/this.omegaIterationStop&&(h=1)}if(0==h||2==h)return 0;if(1==h){let t={};return t.alphaLength=I,t.x=c,t.r=m,t.NCC=N,t.searchUpdate=S,t.ParsStdDev=x,t.AffStdDev=A,t.RadStdDev=j,t.NormAffStdDev=L,t.NormRadStdDev=q,t}},this._Linesearch=function(t,e,r,a,h,s,i,n,l,f){let u=.5*o().dot(r,r),p=1;for(;Math.abs(p)>=this.alphaMin;){let r=o().add(t,o().dot(p,e)),h=this._generatePatch(l,r,f);var d=this._Wallisfilter(h);if(0==d)return 0;let s=o().sub(i,d);var M=this._NormCrossCor(i,d);if(.5*o().dot(s,s)<.1+u+this.mue*p*a)return(c={}).alphaLength=p,c.Change=o().dot(p,e),c.xNew=r,c.rNew=s,c.NCC=M,c.searchUpdate=d,c;p/=2}var c;return(c={alphaLength:0}).xNew=o().add(t,e),c.rNew=r,c.NCC=M,c.searchUpdate=d,c},this._NormCrossCor=function(t,e){let r=t.length,a=(Math.sqrt(r),0),o=0,h=0,s=0;for(var i=0;i<r;++i)a+=t[i],o+=e[i];for(a/=r,o/=r,i=0;i<r;++i)h+=Math.pow(t[i]-a,2),s+=Math.pow(e[i]-o,2);h=Math.sqrt(h/r),s=Math.sqrt(s/r);let n=0;for(i=0;i<r;++i)n+=(t[i]-a)*(e[i]-o)/(h*s);return n*=1/r,n}}runLsm(t,e){let r=(this._IntegralImage(t),this._IntegralImage(e),[Math.floor(t.length/2),Math.floor(t[0].length/2)]),a=[1,0,0,1,r[1],r[0],1,0],o=this._generatePatch(t,a,15),h=this._Wallisfilter(o),s=[],i=[];for(var n=this.offsetConstant;n<e[0].length-(15+this.offsetConstant);++n){i=[Math.floor(e.length/2),n+Math.floor(7.5)],a=[1,0,0,1,i[1],i[0],1,0];let t=this._generatePatch(e,a,15),r=this._Wallisfilter(t);s.push(this._NormCrossCor(h,r))}let l=[],f=0,u=0,p=-1,d=this.offsetConstant+Math.floor(7.5);for(n=0;n<s.length;++n)s[n]>this.NCCCutoff&&s[n]>f?(f=s[n],p=n+d,u=this.minimumPixelDistance):u>0&&(--u,0==u&&(l.push(i[0],p),p=-1,f=0));let M=[];for(n=0;n<l.length;n+=2){a=[l[n],l[n+1]];let r=this._Adjustment(t,e,15,a);if(0!=r){var c={};c.alphaLength=r.alphaLength,c.x=r.x,c.r=r.r,c.NCC=r.NCC,c.searchUpdate=r.searchUpdate,c.ParsStdDev=r.ParsStdDev,c.NormAffStdDev=r.NormAffStdDev,c.NormRadStdDev=r.NormRadStdDev,M.push(c)}}let g=this.NCCCutoff,m=-1,v=this.minAffParsNorm,C=this.minRadParsNorm,N=e[0].length/2,P=1/0;for(n=0;n<M.length;++n)if(this.searchWindowPosQuality>.7){var _=Math.abs(N-M[n].x[4]);_<P&&(m=n,P=_)}else M[n].NCC>g&&M[n].alphaLength>this.alphaCutoff&&M[n].NormAffStdDev<v&&M[n].NormRadStdDev<C&&(m=n,g=M[n].NCC,v=M[n].NormAffStdDev,C=M[n].NormRadStdDev,P=_);return m>-1?[M[m].x[4],M[m].x[5]]:(M.push(c),null)}_Wallisfilter(t){let e=[],r=0,a=0;for(var o=0;o<t.length;++o)r+=t[o];for(r/=t.length,o=0;o<t.length;++o)a+=Math.pow(t[o]-r,2);a=Math.sqrt(a/t.length);let h=81/(.9*a+90*(1-.9)),s=127.5+(0-h)*r;for(let r=0;r<t.length;++r){let a=t[r]*h+s;e[r]=a>255?255:a<0?0:a}return e}_IntegralImage(t){let e=[],r=[];for(let a=0;a<t.length;++a){e.push([]),r.push([]);for(let o=0;o<t[0].length;++o){let h=0,s=0,i=0;o>0&&(h=e[a][o-1]),a>0&&(s=e[a-1][o]),o>0&&a>0&&(i=e[a-1][o-1]);let n=t[a][o]+h+s-i;e[a].push(n),r[a].push(Math.pow(n,2))}}let a={};return a.Integral=e,a.IntegralSq=r,a}_generatePatch(t,e,r){let a=[],h=[[e[0],e[1]],[e[2],e[3]]],s=[[e[4]],[e[5]]],i=[e[6],e[7]],n=0;for(let e=-Math.floor(r/2);e<=Math.floor(r/2)&&1!=n;++e)for(let l=-Math.floor(r/2);l<=Math.floor(r/2);++l){let r=[[l],[e]],f=o().add(o().dot(h,r),s);if(f[1]<this.offsetConstant||f[1]>t.length-this.offsetConstant||f[0]<this.offsetConstant||f[0]>t[0].length-this.offsetConstant){n=1;break}let u=this._interpolate2D(t,f,i,"lanczos2");a.push(u)}return 0==n?a:0}}h.onmessage=t=>{if(t.data.topic&&"run"===t.data.topic){var e=new s;t.data.searchwindowposquality&&(e.searchWindowPosQuality=t.data.searchwindowposquality),t.data.NCC_Threshold&&(e.NCCCutoff=t.data.NCC_Threshold),t.data.adjustRadiometry&&(e.autoradio=1);var r=e.runLsm(t.data.template,t.data.searchwindow);h.postMessage(r)}}}},a={};function o(t){var e=a[t];if(void 0!==e)return e.exports;var h=a[t]={exports:{}};return r[t](h,h.exports,o),h.exports}return o.m=r,o.x=()=>{var t=o.O(void 0,[505],(()=>o(7012)));return o.O(t)},t=[],o.O=(e,r,a,h)=>{if(!r){var s=1/0;for(f=0;f<t.length;f++){r=t[f][0],a=t[f][1],h=t[f][2];for(var i=!0,n=0;n<r.length;n++)(!1&h||s>=h)&&Object.keys(o.O).every((t=>o.O[t](r[n])))?r.splice(n--,1):(i=!1,h<s&&(s=h));if(i){t.splice(f--,1);var l=a();void 0!==l&&(e=l)}}return e}h=h||0;for(var f=t.length;f>0&&t[f-1][2]>h;f--)t[f]=t[f-1];t[f]=[r,a,h]},o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},o.d=(t,e)=>{for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.f={},o.e=t=>Promise.all(Object.keys(o.f).reduce(((e,r)=>(o.f[r](t,e),e)),[])),o.u=t=>t+".infra3dapi.js",o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{var t;o.g.importScripts&&(t=o.g.location+"");var e=o.g.document;if(!t&&e&&(e.currentScript&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var a=r.length-1;a>-1&&(!t||!/^http(s?):/.test(t));)t=r[a--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=t})(),(()=>{var t={12:1};o.f.i=(e,r)=>{t[e]||importScripts(o.p+o.u(e))};var e=self.webpackChunkinfra3dapi=self.webpackChunkinfra3dapi||[],r=e.push.bind(e);e.push=e=>{var a=e[0],h=e[1],s=e[2];for(var i in h)o.o(h,i)&&(o.m[i]=h[i]);for(s&&s(o);a.length;)t[a.pop()]=1;r(e)}})(),e=o.x,o.x=()=>o.e(505).then(e),o.x()})()));
@@ -0,0 +1 @@
1
+ !function(t,a){"object"==typeof exports&&"object"==typeof module?module.exports=a():"function"==typeof define&&define.amd?define("infra3dapi",[],a):"object"==typeof exports?exports.infra3dapi=a():t.infra3dapi=a()}(self,(()=>(()=>{const t=self;function a(t,a,e,d,i,h){const n=Math.round(Math.sqrt(i.length)),r=Math.floor(n/2),f=t,o=e,g=d,m=o,s=g,l=a,w=l;let p=0,u=0,c=0;for(let t=1;t<s-1;+t++)for(let a=1;a<m-1;+a++){const e=t,d=a,h=4*(t*m+a);let s=0,l=0,b=0,y=0;for(let t=0;t<n;t++)for(let a=0;a<n;a++){const h=e+t-r,m=d+a-r;if(h>=0&&h<g&&m>=0&&m<o){const e=4*(h*o+m),d=i[t*n+a];s+=f[e]*d,l+=f[e+1]*d,b+=f[e+2]*d,y+=f[e+3]}}s>p&&(p=s,u=a,c=t),w[h]=s,w[h+1]=l,w[h+2]=b,w[h+3]=y}return l}function e(t,a){const e=t.length;if(e!=a.length)throw"mmImageUtils Add: ImageData1 and ImageData2 must be same sized.";for(let d=0;d<e;d++)t[d]=t[d]+a[d]}return t.onmessage=function(d){const i=new Uint8ClampedArray(d.data.width*d.data.height*4),h=new Uint8ClampedArray(d.data.width*d.data.height*4),n=new Uint8ClampedArray(d.data.width*d.data.height*4),r=new Uint8ClampedArray(d.data.width*d.data.height*4),f=new Uint8ClampedArray(d.data.width*d.data.height*4),o=new Uint8ClampedArray(d.data.width*d.data.height*4);a(d.data.imgbuffer,i,d.data.width,d.data.height,[-1,0,1,-1,0,1,-1,0,1]),a(d.data.imgbuffer,h,d.data.width,d.data.height,[-1,-1,-1,0,0,0,1,1,1]),a(d.data.imgbuffer,n,d.data.width,d.data.height,[1,0,-1,1,0,-1,1,0,-1]),a(d.data.imgbuffer,r,d.data.width,d.data.height,[1,1,1,0,0,0,-1,-1,-1]),a(d.data.imgbuffer,f,d.data.width,d.data.height,[-1,-1,0,-1,0,1,0,1,1]),a(d.data.imgbuffer,o,d.data.width,d.data.height,[1,1,0,1,0,-1,0,-1,-1]),e(i,h),e(i,n),e(i,r),e(i,f),e(i,o),t.postMessage(i)},{}})()));
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunkinfra3dapi=self.webpackChunkinfra3dapi||[]).push([[505],{17505:(__unused_webpack_module,exports,__webpack_require__)=>{var numeric=exports;void 0!==__webpack_require__.g&&(__webpack_require__.g.numeric=numeric),numeric.version="1.2.6",numeric.bench=function(r,n){var e,i,t;for(void 0===n&&(n=15),i=.5,e=new Date;;){for(t=i*=2;t>3;t-=4)r(),r(),r(),r();for(;t>0;)r(),t--;if(new Date-e>n)break}for(t=i;t>3;t-=4)r(),r(),r(),r();for(;t>0;)r(),t--;return 1e3*(3*i-1)/(new Date-e)},numeric._myIndexOf=function(r){var n,e=this.length;for(n=0;n<e;++n)if(this[n]===r)return n;return-1},numeric.myIndexOf=Array.prototype.indexOf?Array.prototype.indexOf:numeric._myIndexOf,numeric.Function=Function,numeric.precision=4,numeric.largeArray=50,numeric.prettyPrint=function(r){function n(r){if(0===r)return"0";if(isNaN(r))return"NaN";if(r<0)return"-"+n(-r);if(isFinite(r)){var e=Math.floor(Math.log(r)/Math.log(10)),i=r/Math.pow(10,e),t=i.toPrecision(numeric.precision);return 10===parseFloat(t)&&(e++,t=(i=1).toPrecision(numeric.precision)),parseFloat(t).toString()+"e"+e.toString()}return"Infinity"}var e=[];return function r(i){var t;if(void 0===i)return e.push(Array(numeric.precision+8).join(" ")),!1;if("string"==typeof i)return e.push('"'+i+'"'),!1;if("boolean"==typeof i)return e.push(i.toString()),!1;if("number"==typeof i){var u=n(i),o=i.toPrecision(numeric.precision),c=parseFloat(i.toString()).toString(),a=[u,o,c,parseFloat(o).toString(),parseFloat(c).toString()];for(t=1;t<a.length;t++)a[t].length<u.length&&(u=a[t]);return e.push(Array(numeric.precision+8-u.length).join(" ")+u),!1}if(null===i)return e.push("null"),!1;if("function"==typeof i){e.push(i.toString());var f=!1;for(t in i)i.hasOwnProperty(t)&&(f?e.push(",\n"):e.push("\n{"),f=!0,e.push(t),e.push(": \n"),r(i[t]));return f&&e.push("}\n"),!0}if(i instanceof Array){if(i.length>numeric.largeArray)return e.push("...Large Array..."),!0;for(f=!1,e.push("["),t=0;t<i.length;t++)t>0&&(e.push(","),f&&e.push("\n ")),f=r(i[t]);return e.push("]"),!0}for(t in e.push("{"),f=!1,i)i.hasOwnProperty(t)&&(f&&e.push(",\n"),f=!0,e.push(t),e.push(": \n"),r(i[t]));return e.push("}"),!0}(r),e.join("")},numeric.parseDate=function(r){return function r(n){if("string"==typeof n)return Date.parse(n.replace(/-/g,"/"));if(!(n instanceof Array))throw new Error("parseDate: parameter must be arrays of strings");var e,i=[];for(e=0;e<n.length;e++)i[e]=r(n[e]);return i}(r)},numeric.parseFloat=function(r){return function r(n){if("string"==typeof n)return parseFloat(n);if(!(n instanceof Array))throw new Error("parseFloat: parameter must be arrays of strings");var e,i=[];for(e=0;e<n.length;e++)i[e]=r(n[e]);return i}(r)},numeric.parseCSV=function(r){var n,e,i,t=r.split("\n"),u=[],o=/(([^'",]*)|('[^']*')|("[^"]*")),/g,c=/^\s*(([+-]?[0-9]+(\.[0-9]*)?(e[+-]?[0-9]+)?)|([+-]?[0-9]*(\.[0-9]+)?(e[+-]?[0-9]+)?))\s*$/,a=0;for(e=0;e<t.length;e++){var f,m=(t[e]+",").match(o);if(m.length>0){for(u[a]=[],n=0;n<m.length;n++)f=(i=m[n]).substr(0,i.length-1),c.test(f)?u[a][n]=parseFloat(f):u[a][n]=f;a++}}return u},numeric.toCSV=function(r){var n,e,i,t,u,o=numeric.dim(r);for(i=o[0],o[1],u=[],n=0;n<i;n++){for(t=[],e=0;e<i;e++)t[e]=r[n][e].toString();u[n]=t.join(", ")}return u.join("\n")+"\n"},numeric.getURL=function(r){var n=new XMLHttpRequest;return n.open("GET",r,!1),n.send(),n},numeric.imageURL=function(r){function n(r,n,e){void 0===n&&(n=0),void 0===e&&(e=r.length);var i,t=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],u=-1;for(r.length,i=n;i<e;i++)u=u>>>8^t[255&(u^r[i])];return~u}var e,i,t,u,o,c,a,f,m,s,h=r[0].length,l=r[0][0].length,p=[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,l>>24&255,l>>16&255,l>>8&255,255&l,h>>24&255,h>>16&255,h>>8&255,255&h,8,2,0,0,0,-1,-2,-3,-4,-5,-6,-7,-8,73,68,65,84,8,29];for(s=n(p,12,29),p[29]=s>>24&255,p[30]=s>>16&255,p[31]=s>>8&255,p[32]=255&s,e=1,i=0,a=0;a<h;a++){for(a<h-1?p.push(0):p.push(1),o=3*l+1+(0===a)&255,c=3*l+1+(0===a)>>8&255,p.push(o),p.push(c),p.push(255&~o),p.push(255&~c),0===a&&p.push(0),f=0;f<l;f++)for(t=0;t<3;t++)i=(i+(e=(e+(o=(o=r[t][a][f])>255?255:o<0?0:Math.round(o)))%65521))%65521,p.push(o);p.push(0)}return m=(i<<16)+e,p.push(m>>24&255),p.push(m>>16&255),p.push(m>>8&255),p.push(255&m),u=p.length-41,p[33]=u>>24&255,p[34]=u>>16&255,p[35]=u>>8&255,p[36]=255&u,s=n(p,37),p.push(s>>24&255),p.push(s>>16&255),p.push(s>>8&255),p.push(255&s),p.push(0),p.push(0),p.push(0),p.push(0),p.push(73),p.push(69),p.push(78),p.push(68),p.push(174),p.push(66),p.push(96),p.push(130),"data:image/png;base64,"+function(r){var n,e,i,t,u,o,c,a=r.length,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",m="";for(n=0;n<a;n+=3)u=((3&(e=r[n]))<<4)+((i=r[n+1])>>4),o=((15&i)<<2)+((t=r[n+2])>>6),c=63&t,n+1>=a?o=c=64:n+2>=a&&(c=64),m+=f.charAt(e>>2)+f.charAt(u)+f.charAt(o)+f.charAt(c);return m}(p)},numeric._dim=function(r){for(var n=[];"object"==typeof r;)n.push(r.length),r=r[0];return n},numeric.dim=function(r){var n;return"object"==typeof r?"object"==typeof(n=r[0])?"object"==typeof n[0]?numeric._dim(r):[r.length,n.length]:[r.length]:[]},numeric.mapreduce=function(r,n){return Function("x","accum","_s","_k",'if(typeof accum === "undefined") accum = '+n+';\nif(typeof x === "number") { var xi = x; '+r+'; return accum; }\nif(typeof _s === "undefined") _s = numeric.dim(x);\nif(typeof _k === "undefined") _k = 0;\nvar _n = _s[_k];\nvar i,xi;\nif(_k < _s.length-1) {\n for(i=_n-1;i>=0;i--) {\n accum = arguments.callee(x[i],accum,_s,_k+1);\n } return accum;\n}\nfor(i=_n-1;i>=1;i-=2) { \n xi = x[i];\n '+r+";\n xi = x[i-1];\n "+r+";\n}\nif(i === 0) {\n xi = x[i];\n "+r+"\n}\nreturn accum;")},numeric.mapreduce2=function(r,n){return Function("x","var n = x.length;\nvar i,xi;\n"+n+";\nfor(i=n-1;i!==-1;--i) { \n xi = x[i];\n "+r+";\n}\nreturn accum;")},numeric.same=function r(n,e){var i,t;if(!(n instanceof Array&&e instanceof Array))return!1;if((t=n.length)!==e.length)return!1;for(i=0;i<t;i++)if(n[i]!==e[i]){if("object"!=typeof n[i])return!1;if(!r(n[i],e[i]))return!1}return!0},numeric.rep=function(r,n,e){void 0===e&&(e=0);var i,t=r[e],u=Array(t);if(e===r.length-1){for(i=t-2;i>=0;i-=2)u[i+1]=n,u[i]=n;return-1===i&&(u[0]=n),u}for(i=t-1;i>=0;i--)u[i]=numeric.rep(r,n,e+1);return u},numeric.dotMMsmall=function(r,n){var e,i,t,u,o,c,a,f,m,s,h;for(u=r.length,o=n.length,c=n[0].length,a=Array(u),e=u-1;e>=0;e--){for(f=Array(c),m=r[e],t=c-1;t>=0;t--){for(s=m[o-1]*n[o-1][t],i=o-2;i>=1;i-=2)h=i-1,s+=m[i]*n[i][t]+m[h]*n[h][t];0===i&&(s+=m[0]*n[0][t]),f[t]=s}a[e]=f}return a},numeric._getCol=function(r,n,e){var i;for(i=r.length-1;i>0;--i)e[i]=r[i][n],e[--i]=r[i][n];0===i&&(e[0]=r[0][n])},numeric.dotMMbig=function(r,n){var e,i,t,u=numeric._getCol,o=n.length,c=Array(o),a=r.length,f=n[0].length,m=new Array(a),s=numeric.dotVV;for(--o,i=--a;-1!==i;--i)m[i]=Array(f);for(i=--f;-1!==i;--i)for(u(n,i,c),t=a;-1!==t;--t)e=r[t],m[t][i]=s(e,c);return m},numeric.dotMV=function(r,n){var e,i=r.length,t=(n.length,Array(i)),u=numeric.dotVV;for(e=i-1;e>=0;e--)t[e]=u(r[e],n);return t},numeric.dotVM=function(r,n){var e,i,t,u,o,c,a;for(t=r.length,u=n[0].length,o=Array(u),i=u-1;i>=0;i--){for(c=r[t-1]*n[t-1][i],e=t-2;e>=1;e-=2)a=e-1,c+=r[e]*n[e][i]+r[a]*n[a][i];0===e&&(c+=r[0]*n[0][i]),o[i]=c}return o},numeric.dotVV=function(r,n){var e,i,t=r.length,u=r[t-1]*n[t-1];for(e=t-2;e>=1;e-=2)i=e-1,u+=r[e]*n[e]+r[i]*n[i];return 0===e&&(u+=r[0]*n[0]),u},numeric.dot=function(r,n){var e=numeric.dim;switch(1e3*e(r).length+e(n).length){case 2002:return n.length<10?numeric.dotMMsmall(r,n):numeric.dotMMbig(r,n);case 2001:return numeric.dotMV(r,n);case 1002:return numeric.dotVM(r,n);case 1001:return numeric.dotVV(r,n);case 1e3:return numeric.mulVS(r,n);case 1:return numeric.mulSV(r,n);case 0:return r*n;default:throw new Error("numeric.dot only works on vectors and matrices")}},numeric.diag=function(r){var n,e,i,t,u=r.length,o=Array(u);for(n=u-1;n>=0;n--){for(t=Array(u),e=n+2,i=u-1;i>=e;i-=2)t[i]=0,t[i-1]=0;for(i>n&&(t[i]=0),t[n]=r[n],i=n-1;i>=1;i-=2)t[i]=0,t[i-1]=0;0===i&&(t[0]=0),o[n]=t}return o},numeric.getDiag=function(r){var n,e=Math.min(r.length,r[0].length),i=Array(e);for(n=e-1;n>=1;--n)i[n]=r[n][n],i[--n]=r[n][n];return 0===n&&(i[0]=r[0][0]),i},numeric.identity=function(r){return numeric.diag(numeric.rep([r],1))},numeric.pointwise=function(r,n,e){void 0===e&&(e="");var i,t,u=[],o=/\[i\]$/,c="",a=!1;for(i=0;i<r.length;i++)o.test(r[i])?c=t=r[i].substring(0,r[i].length-3):t=r[i],"ret"===t&&(a=!0),u.push(t);return u[r.length]="_s",u[r.length+1]="_k",u[r.length+2]='if(typeof _s === "undefined") _s = numeric.dim('+c+');\nif(typeof _k === "undefined") _k = 0;\nvar _n = _s[_k];\nvar i'+(a?"":", ret = Array(_n)")+";\nif(_k < _s.length-1) {\n for(i=_n-1;i>=0;i--) ret[i] = arguments.callee("+r.join(",")+",_s,_k+1);\n return ret;\n}\n"+e+"\nfor(i=_n-1;i!==-1;--i) {\n "+n+"\n}\nreturn ret;",Function.apply(null,u)},numeric.pointwise2=function(r,n,e){void 0===e&&(e="");var i,t,u=[],o=/\[i\]$/,c="",a=!1;for(i=0;i<r.length;i++)o.test(r[i])?c=t=r[i].substring(0,r[i].length-3):t=r[i],"ret"===t&&(a=!0),u.push(t);return u[r.length]="var _n = "+c+".length;\nvar i"+(a?"":", ret = Array(_n)")+";\n"+e+"\nfor(i=_n-1;i!==-1;--i) {\n"+n+"\n}\nreturn ret;",Function.apply(null,u)},numeric._biforeach=function r(n,e,i,t,u){var o;if(t!==i.length-1)for(o=i[t]-1;o>=0;o--)r("object"==typeof n?n[o]:n,"object"==typeof e?e[o]:e,i,t+1,u);else u(n,e)},numeric._biforeach2=function r(n,e,i,t,u){if(t===i.length-1)return u(n,e);var o,c=i[t],a=Array(c);for(o=c-1;o>=0;--o)a[o]=r("object"==typeof n?n[o]:n,"object"==typeof e?e[o]:e,i,t+1,u);return a},numeric._foreach=function r(n,e,i,t){var u;if(i!==e.length-1)for(u=e[i]-1;u>=0;u--)r(n[u],e,i+1,t);else t(n)},numeric._foreach2=function r(n,e,i,t){if(i===e.length-1)return t(n);var u,o=e[i],c=Array(o);for(u=o-1;u>=0;u--)c[u]=r(n[u],e,i+1,t);return c},numeric.ops2={add:"+",sub:"-",mul:"*",div:"/",mod:"%",and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">=",band:"&",bor:"|",bxor:"^",lshift:"<<",rshift:">>",rrshift:">>>"},numeric.opseq={addeq:"+=",subeq:"-=",muleq:"*=",diveq:"/=",modeq:"%=",lshifteq:"<<=",rshifteq:">>=",rrshifteq:">>>=",bandeq:"&=",boreq:"|=",bxoreq:"^="},numeric.mathfuns=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan","isNaN","isFinite"],numeric.mathfuns2=["atan2","pow","max","min"],numeric.ops1={neg:"-",not:"!",bnot:"~",clone:""},numeric.mapreducers={any:["if(xi) return true;","var accum = false;"],all:["if(!xi) return false;","var accum = true;"],sum:["accum += xi;","var accum = 0;"],prod:["accum *= xi;","var accum = 1;"],norm2Squared:["accum += xi*xi;","var accum = 0;"],norminf:["accum = max(accum,abs(xi));","var accum = 0, max = Math.max, abs = Math.abs;"],norm1:["accum += abs(xi)","var accum = 0, abs = Math.abs;"],sup:["accum = max(accum,xi);","var accum = -Infinity, max = Math.max;"],inf:["accum = min(accum,xi);","var accum = Infinity, min = Math.min;"]},function(){var r,n;for(r=0;r<numeric.mathfuns2.length;++r)n=numeric.mathfuns2[r],numeric.ops2[n]=n;for(r in numeric.ops2)if(numeric.ops2.hasOwnProperty(r)){n=numeric.ops2[r];var e,i,t="";-1!==numeric.myIndexOf.call(numeric.mathfuns2,r)?(t="var "+n+" = Math."+n+";\n",e=function(r,e,i){return r+" = "+n+"("+e+","+i+")"},i=function(r,e){return r+" = "+n+"("+r+","+e+")"}):(e=function(r,e,i){return r+" = "+e+" "+n+" "+i},i=numeric.opseq.hasOwnProperty(r+"eq")?function(r,e){return r+" "+n+"= "+e}:function(r,e){return r+" = "+r+" "+n+" "+e}),numeric[r+"VV"]=numeric.pointwise2(["x[i]","y[i]"],e("ret[i]","x[i]","y[i]"),t),numeric[r+"SV"]=numeric.pointwise2(["x","y[i]"],e("ret[i]","x","y[i]"),t),numeric[r+"VS"]=numeric.pointwise2(["x[i]","y"],e("ret[i]","x[i]","y"),t),numeric[r]=Function("var n = arguments.length, i, x = arguments[0], y;\nvar VV = numeric."+r+"VV, VS = numeric."+r+"VS, SV = numeric."+r+'SV;\nvar dim = numeric.dim;\nfor(i=1;i!==n;++i) { \n y = arguments[i];\n if(typeof x === "object") {\n if(typeof y === "object") x = numeric._biforeach2(x,y,dim(x),0,VV);\n else x = numeric._biforeach2(x,y,dim(x),0,VS);\n } else if(typeof y === "object") x = numeric._biforeach2(x,y,dim(y),0,SV);\n else '+i("x","y")+"\n}\nreturn x;\n"),numeric[n]=numeric[r],numeric[r+"eqV"]=numeric.pointwise2(["ret[i]","x[i]"],i("ret[i]","x[i]"),t),numeric[r+"eqS"]=numeric.pointwise2(["ret[i]","x"],i("ret[i]","x"),t),numeric[r+"eq"]=Function("var n = arguments.length, i, x = arguments[0], y;\nvar V = numeric."+r+"eqV, S = numeric."+r+'eqS\nvar s = numeric.dim(x);\nfor(i=1;i!==n;++i) { \n y = arguments[i];\n if(typeof y === "object") numeric._biforeach(x,y,s,0,V);\n else numeric._biforeach(x,y,s,0,S);\n}\nreturn x;\n')}for(r=0;r<numeric.mathfuns2.length;++r)n=numeric.mathfuns2[r],delete numeric.ops2[n];for(r=0;r<numeric.mathfuns.length;++r)n=numeric.mathfuns[r],numeric.ops1[n]=n;for(r in numeric.ops1)numeric.ops1.hasOwnProperty(r)&&(t="",n=numeric.ops1[r],-1!==numeric.myIndexOf.call(numeric.mathfuns,r)&&Math.hasOwnProperty(n)&&(t="var "+n+" = Math."+n+";\n"),numeric[r+"eqV"]=numeric.pointwise2(["ret[i]"],"ret[i] = "+n+"(ret[i]);",t),numeric[r+"eq"]=Function("x",'if(typeof x !== "object") return '+n+"x\nvar i;\nvar V = numeric."+r+"eqV;\nvar s = numeric.dim(x);\nnumeric._foreach(x,s,0,V);\nreturn x;\n"),numeric[r+"V"]=numeric.pointwise2(["x[i]"],"ret[i] = "+n+"(x[i]);",t),numeric[r]=Function("x",'if(typeof x !== "object") return '+n+"(x)\nvar i;\nvar V = numeric."+r+"V;\nvar s = numeric.dim(x);\nreturn numeric._foreach2(x,s,0,V);\n"));for(r=0;r<numeric.mathfuns.length;++r)n=numeric.mathfuns[r],delete numeric.ops1[n];for(r in numeric.mapreducers)numeric.mapreducers.hasOwnProperty(r)&&(n=numeric.mapreducers[r],numeric[r+"V"]=numeric.mapreduce2(n[0],n[1]),numeric[r]=Function("x","s","k",n[1]+'if(typeof x !== "object") { xi = x;\n'+n[0]+';\n return accum;\n}if(typeof s === "undefined") s = numeric.dim(x);\nif(typeof k === "undefined") k = 0;\nif(k === s.length-1) return numeric.'+r+"V(x);\nvar xi;\nvar n = x.length, i;\nfor(i=n-1;i!==-1;--i) {\n xi = arguments.callee(x[i]);\n"+n[0]+";\n}\nreturn accum;\n"))}(),numeric.truncVV=numeric.pointwise(["x[i]","y[i]"],"ret[i] = round(x[i]/y[i])*y[i];","var round = Math.round;"),numeric.truncVS=numeric.pointwise(["x[i]","y"],"ret[i] = round(x[i]/y)*y;","var round = Math.round;"),numeric.truncSV=numeric.pointwise(["x","y[i]"],"ret[i] = round(x/y[i])*y[i];","var round = Math.round;"),numeric.trunc=function(r,n){return"object"==typeof r?"object"==typeof n?numeric.truncVV(r,n):numeric.truncVS(r,n):"object"==typeof n?numeric.truncSV(r,n):Math.round(r/n)*n},numeric.inv=function(r){var n,e,i,t,u,o,c,a=numeric.dim(r),f=Math.abs,m=a[0],s=a[1],h=numeric.clone(r),l=numeric.identity(m);for(o=0;o<s;++o){var p=-1,y=-1;for(u=o;u!==m;++u)(c=f(h[u][o]))>y&&(p=u,y=c);for(e=h[p],h[p]=h[o],h[o]=e,t=l[p],l[p]=l[o],l[o]=t,r=e[o],c=o;c!==s;++c)e[c]/=r;for(c=s-1;-1!==c;--c)t[c]/=r;for(u=m-1;-1!==u;--u)if(u!==o){for(n=h[u],i=l[u],r=n[o],c=o+1;c!==s;++c)n[c]-=e[c]*r;for(c=s-1;c>0;--c)i[c]-=t[c]*r,i[--c]-=t[c]*r;0===c&&(i[0]-=t[0]*r)}}return l},numeric.det=function(r){var n=numeric.dim(r);if(2!==n.length||n[0]!==n[1])throw new Error("numeric: det() only works on square matrices");var e,i,t,u,o,c,a,f,m=n[0],s=1,h=numeric.clone(r);for(i=0;i<m-1;i++){for(t=i,e=i+1;e<m;e++)Math.abs(h[e][i])>Math.abs(h[t][i])&&(t=e);for(t!==i&&(a=h[t],h[t]=h[i],h[i]=a,s*=-1),u=h[i],e=i+1;e<m;e++){for(c=(o=h[e])[i]/u[i],t=i+1;t<m-1;t+=2)f=t+1,o[t]-=u[t]*c,o[f]-=u[f]*c;t!==m&&(o[t]-=u[t]*c)}if(0===u[i])return 0;s*=u[i]}return s*h[i][i]},numeric.transpose=function(r){var n,e,i,t,u,o=r.length,c=r[0].length,a=Array(c);for(e=0;e<c;e++)a[e]=Array(o);for(n=o-1;n>=1;n-=2){for(t=r[n],i=r[n-1],e=c-1;e>=1;--e)(u=a[e])[n]=t[e],u[n-1]=i[e],(u=a[--e])[n]=t[e],u[n-1]=i[e];0===e&&((u=a[0])[n]=t[0],u[n-1]=i[0])}if(0===n){for(i=r[0],e=c-1;e>=1;--e)a[e][0]=i[e],a[--e][0]=i[e];0===e&&(a[0][0]=i[0])}return a},numeric.negtranspose=function(r){var n,e,i,t,u,o=r.length,c=r[0].length,a=Array(c);for(e=0;e<c;e++)a[e]=Array(o);for(n=o-1;n>=1;n-=2){for(t=r[n],i=r[n-1],e=c-1;e>=1;--e)(u=a[e])[n]=-t[e],u[n-1]=-i[e],(u=a[--e])[n]=-t[e],u[n-1]=-i[e];0===e&&((u=a[0])[n]=-t[0],u[n-1]=-i[0])}if(0===n){for(i=r[0],e=c-1;e>=1;--e)a[e][0]=-i[e],a[--e][0]=-i[e];0===e&&(a[0][0]=-i[0])}return a},numeric._random=function r(n,e){var i,t,u=n[e],o=Array(u);if(e===n.length-1){for(t=Math.random,i=u-1;i>=1;i-=2)o[i]=t(),o[i-1]=t();return 0===i&&(o[0]=t()),o}for(i=u-1;i>=0;i--)o[i]=r(n,e+1);return o},numeric.random=function(r){return numeric._random(r,0)},numeric.norm2=function(r){return Math.sqrt(numeric.norm2Squared(r))},numeric.linspace=function(r,n,e){if(void 0===e&&(e=Math.max(Math.round(n-r)+1,1)),e<2)return 1===e?[r]:[];var i,t=Array(e);for(i=--e;i>=0;i--)t[i]=(i*n+(e-i)*r)/e;return t},numeric.getBlock=function(r,n,e){var i=numeric.dim(r);return function r(t,u){var o,c=n[u],a=e[u]-c,f=Array(a);if(u===i.length-1){for(o=a;o>=0;o--)f[o]=t[o+c];return f}for(o=a;o>=0;o--)f[o]=r(t[o+c],u+1);return f}(r,0)},numeric.setBlock=function(r,n,e,i){var t=numeric.dim(r);return function r(i,u,o){var c,a=n[o],f=e[o]-a;if(o===t.length-1)for(c=f;c>=0;c--)i[c+a]=u[c];for(c=f;c>=0;c--)r(i[c+a],u[c],o+1)}(r,i,0),r},numeric.getRange=function(r,n,e){var i,t,u,o,c=n.length,a=e.length,f=Array(c);for(i=c-1;-1!==i;--i)for(f[i]=Array(a),u=f[i],o=r[n[i]],t=a-1;-1!==t;--t)u[t]=o[e[t]];return f},numeric.blockMatrix=function(r){var n=numeric.dim(r);if(n.length<4)return numeric.blockMatrix([r]);var e,i,t,u,o,c=n[0],a=n[1];for(e=0,i=0,t=0;t<c;++t)e+=r[t][0].length;for(u=0;u<a;++u)i+=r[0][u][0].length;var f=Array(e);for(t=0;t<e;++t)f[t]=Array(i);var m,s,h,l,p,y=0;for(t=0;t<c;++t){for(m=i,u=a-1;-1!==u;--u)for(m-=(o=r[t][u])[0].length,h=o.length-1;-1!==h;--h)for(p=o[h],s=f[y+h],l=p.length-1;-1!==l;--l)s[m+l]=p[l];y+=r[t][0].length}return f},numeric.tensor=function(r,n){if("number"==typeof r||"number"==typeof n)return numeric.mul(r,n);var e=numeric.dim(r),i=numeric.dim(n);if(1!==e.length||1!==i.length)throw new Error("numeric: tensor product is only defined for vectors");var t,u,o,c,a=e[0],f=i[0],m=Array(a);for(u=a-1;u>=0;u--){for(t=Array(f),c=r[u],o=f-1;o>=3;--o)t[o]=c*n[o],t[--o]=c*n[o],t[--o]=c*n[o],t[--o]=c*n[o];for(;o>=0;)t[o]=c*n[o],--o;m[u]=t}return m},numeric.T=function(r,n){this.x=r,this.y=n},numeric.t=function(r,n){return new numeric.T(r,n)},numeric.Tbinop=function(r,n,e,i,t){var u;if(numeric.indexOf,"string"!=typeof t)for(u in t="",numeric)numeric.hasOwnProperty(u)&&(r.indexOf(u)>=0||n.indexOf(u)>=0||e.indexOf(u)>=0||i.indexOf(u)>=0)&&u.length>1&&(t+="var "+u+" = numeric."+u+";\n");return Function(["y"],"var x = this;\nif(!(y instanceof numeric.T)) { y = new numeric.T(y); }\n"+t+"\nif(x.y) { if(y.y) { return new numeric.T("+i+");\n }\n return new numeric.T("+e+");\n}\nif(y.y) {\n return new numeric.T("+n+");\n}\nreturn new numeric.T("+r+");\n")},numeric.T.prototype.add=numeric.Tbinop("add(x.x,y.x)","add(x.x,y.x),y.y","add(x.x,y.x),x.y","add(x.x,y.x),add(x.y,y.y)"),numeric.T.prototype.sub=numeric.Tbinop("sub(x.x,y.x)","sub(x.x,y.x),neg(y.y)","sub(x.x,y.x),x.y","sub(x.x,y.x),sub(x.y,y.y)"),numeric.T.prototype.mul=numeric.Tbinop("mul(x.x,y.x)","mul(x.x,y.x),mul(x.x,y.y)","mul(x.x,y.x),mul(x.y,y.x)","sub(mul(x.x,y.x),mul(x.y,y.y)),add(mul(x.x,y.y),mul(x.y,y.x))"),numeric.T.prototype.reciprocal=function(){var r=numeric.mul,n=numeric.div;if(this.y){var e=numeric.add(r(this.x,this.x),r(this.y,this.y));return new numeric.T(n(this.x,e),n(numeric.neg(this.y),e))}return new T(n(1,this.x))},numeric.T.prototype.div=function(r){if(r instanceof numeric.T||(r=new numeric.T(r)),r.y)return this.mul(r.reciprocal());var n=numeric.div;return this.y?new numeric.T(n(this.x,r.x),n(this.y,r.x)):new numeric.T(n(this.x,r.x))},numeric.T.prototype.dot=numeric.Tbinop("dot(x.x,y.x)","dot(x.x,y.x),dot(x.x,y.y)","dot(x.x,y.x),dot(x.y,y.x)","sub(dot(x.x,y.x),dot(x.y,y.y)),add(dot(x.x,y.y),dot(x.y,y.x))"),numeric.T.prototype.transpose=function(){var r=numeric.transpose,n=this.x,e=this.y;return e?new numeric.T(r(n),r(e)):new numeric.T(r(n))},numeric.T.prototype.transjugate=function(){var r=numeric.transpose,n=this.x,e=this.y;return e?new numeric.T(r(n),numeric.negtranspose(e)):new numeric.T(r(n))},numeric.Tunop=function(r,n,e){return"string"!=typeof e&&(e=""),Function("var x = this;\n"+e+"\nif(x.y) { "+n+";\n}\n"+r+";\n")},numeric.T.prototype.exp=numeric.Tunop("return new numeric.T(ex)","return new numeric.T(mul(cos(x.y),ex),mul(sin(x.y),ex))","var ex = numeric.exp(x.x), cos = numeric.cos, sin = numeric.sin, mul = numeric.mul;"),numeric.T.prototype.conj=numeric.Tunop("return new numeric.T(x.x);","return new numeric.T(x.x,numeric.neg(x.y));"),numeric.T.prototype.neg=numeric.Tunop("return new numeric.T(neg(x.x));","return new numeric.T(neg(x.x),neg(x.y));","var neg = numeric.neg;"),numeric.T.prototype.sin=numeric.Tunop("return new numeric.T(numeric.sin(x.x))","return x.exp().sub(x.neg().exp()).div(new numeric.T(0,2));"),numeric.T.prototype.cos=numeric.Tunop("return new numeric.T(numeric.cos(x.x))","return x.exp().add(x.neg().exp()).div(2);"),numeric.T.prototype.abs=numeric.Tunop("return new numeric.T(numeric.abs(x.x));","return new numeric.T(numeric.sqrt(numeric.add(mul(x.x,x.x),mul(x.y,x.y))));","var mul = numeric.mul;"),numeric.T.prototype.log=numeric.Tunop("return new numeric.T(numeric.log(x.x));","var theta = new numeric.T(numeric.atan2(x.y,x.x)), r = x.abs();\nreturn new numeric.T(numeric.log(r.x),theta.x);"),numeric.T.prototype.norm2=numeric.Tunop("return numeric.norm2(x.x);","var f = numeric.norm2Squared;\nreturn Math.sqrt(f(x.x)+f(x.y));"),numeric.T.prototype.inv=function(){var r=this;if(void 0===r.y)return new numeric.T(numeric.inv(r.x));var n,e,i,t,u,o,c,a,f,m,s,h,l,p,y,g,v,d,x=r.x.length,b=numeric.identity(x),w=numeric.rep([x,x],0),M=numeric.clone(r.x),k=numeric.clone(r.y);for(f=0;f<x;f++){for(h=(p=M[f][f])*p+(y=k[f][f])*y,s=f,m=f+1;m<x;m++)(l=(p=M[m][f])*p+(y=k[m][f])*y)>h&&(s=m,h=l);for(s!==f&&(d=M[f],M[f]=M[s],M[s]=d,d=k[f],k[f]=k[s],k[s]=d,d=b[f],b[f]=b[s],b[s]=d,d=w[f],w[f]=w[s],w[s]=d),n=M[f],e=k[f],u=b[f],o=w[f],p=n[f],y=e[f],m=f+1;m<x;m++)g=n[m],v=e[m],n[m]=(g*p+v*y)/h,e[m]=(v*p-g*y)/h;for(m=0;m<x;m++)g=u[m],v=o[m],u[m]=(g*p+v*y)/h,o[m]=(v*p-g*y)/h;for(m=f+1;m<x;m++){for(i=M[m],t=k[m],c=b[m],a=w[m],p=i[f],y=t[f],s=f+1;s<x;s++)g=n[s],v=e[s],i[s]-=g*p-v*y,t[s]-=v*p+g*y;for(s=0;s<x;s++)g=u[s],v=o[s],c[s]-=g*p-v*y,a[s]-=v*p+g*y}}for(f=x-1;f>0;f--)for(u=b[f],o=w[f],m=f-1;m>=0;m--)for(c=b[m],a=w[m],p=M[m][f],y=k[m][f],s=x-1;s>=0;s--)g=u[s],v=o[s],c[s]-=p*g-y*v,a[s]-=p*v+y*g;return new numeric.T(b,w)},numeric.T.prototype.get=function(r){var n,e=this.x,i=this.y,t=0,u=r.length;if(i){for(;t<u;)e=e[n=r[t]],i=i[n],t++;return new numeric.T(e,i)}for(;t<u;)e=e[n=r[t]],t++;return new numeric.T(e)},numeric.T.prototype.set=function(r,n){var e,i=this.x,t=this.y,u=0,o=r.length,c=n.x,a=n.y;if(0===o)return a?this.y=a:t&&(this.y=void 0),this.x=i,this;if(a){for(t||(t=numeric.rep(numeric.dim(i),0),this.y=t);u<o-1;)i=i[e=r[u]],t=t[e],u++;return i[e=r[u]]=c,t[e]=a,this}if(t){for(;u<o-1;)i=i[e=r[u]],t=t[e],u++;return i[e=r[u]]=c,t[e]=c instanceof Array?numeric.rep(numeric.dim(c),0):0,this}for(;u<o-1;)i=i[e=r[u]],u++;return i[e=r[u]]=c,this},numeric.T.prototype.getRows=function(r,n){var e,i,t=n-r+1,u=Array(t),o=this.x,c=this.y;for(e=r;e<=n;e++)u[e-r]=o[e];if(c){for(i=Array(t),e=r;e<=n;e++)i[e-r]=c[e];return new numeric.T(u,i)}return new numeric.T(u)},numeric.T.prototype.setRows=function(r,n,e){var i,t=this.x,u=this.y,o=e.x,c=e.y;for(i=r;i<=n;i++)t[i]=o[i-r];if(c)for(u||(u=numeric.rep(numeric.dim(t),0),this.y=u),i=r;i<=n;i++)u[i]=c[i-r];else if(u)for(i=r;i<=n;i++)u[i]=numeric.rep([o[i-r].length],0);return this},numeric.T.prototype.getRow=function(r){var n=this.x,e=this.y;return e?new numeric.T(n[r],e[r]):new numeric.T(n[r])},numeric.T.prototype.setRow=function(r,n){var e=this.x,i=this.y,t=n.x,u=n.y;return e[r]=t,u?(i||(i=numeric.rep(numeric.dim(e),0),this.y=i),i[r]=u):i&&(i=numeric.rep([t.length],0)),this},numeric.T.prototype.getBlock=function(r,n){var e=this.x,i=this.y,t=numeric.getBlock;return i?new numeric.T(t(e,r,n),t(i,r,n)):new numeric.T(t(e,r,n))},numeric.T.prototype.setBlock=function(r,n,e){e instanceof numeric.T||(e=new numeric.T(e));var i=this.x,t=this.y,u=numeric.setBlock,o=e.x,c=e.y;if(c)return t||(this.y=numeric.rep(numeric.dim(this),0),t=this.y),u(i,r,n,o),u(t,r,n,c),this;u(i,r,n,o),t&&u(t,r,n,numeric.rep(numeric.dim(o),0))},numeric.T.rep=function(r,n){var e=numeric.T;n instanceof e||(n=new e(n));var i=n.x,t=n.y,u=numeric.rep;return t?new e(u(r,i),u(r,t)):new e(u(r,i))},numeric.T.diag=function(r){r instanceof numeric.T||(r=new numeric.T(r));var n=r.x,e=r.y,i=numeric.diag;return e?new numeric.T(i(n),i(e)):new numeric.T(i(n))},numeric.T.eig=function(){if(this.y)throw new Error("eig: not implemented for complex matrices.");return numeric.eig(this.x)},numeric.T.identity=function(r){return new numeric.T(numeric.identity(r))},numeric.T.prototype.getDiag=function(){var r=numeric,n=this.x,e=this.y;return e?new r.T(r.getDiag(n),r.getDiag(e)):new r.T(r.getDiag(n))},numeric.house=function(r){var n=numeric.clone(r),e=(r[0]>=0?1:-1)*numeric.norm2(r);n[0]+=e;var i=numeric.norm2(n);if(0===i)throw new Error("eig: internal error");return numeric.div(n,i)},numeric.toUpperHessenberg=function(r){var n=numeric.dim(r);if(2!==n.length||n[0]!==n[1])throw new Error("numeric: toUpperHessenberg() only works on square matrices");var e,i,t,u,o,c,a,f,m,s,h=n[0],l=numeric.clone(r),p=numeric.identity(h);for(i=0;i<h-2;i++){for(u=Array(h-i-1),e=i+1;e<h;e++)u[e-i-1]=l[e][i];if(numeric.norm2(u)>0){for(o=numeric.house(u),c=numeric.getBlock(l,[i+1,i],[h-1,h-1]),a=numeric.tensor(o,numeric.dot(o,c)),e=i+1;e<h;e++)for(f=l[e],m=a[e-i-1],t=i;t<h;t++)f[t]-=2*m[t-i];for(c=numeric.getBlock(l,[0,i+1],[h-1,h-1]),a=numeric.tensor(numeric.dot(c,o),o),e=0;e<h;e++)for(f=l[e],m=a[e],t=i+1;t<h;t++)f[t]-=2*m[t-i-1];for(c=Array(h-i-1),e=i+1;e<h;e++)c[e-i-1]=p[e];for(a=numeric.tensor(o,numeric.dot(o,c)),e=i+1;e<h;e++)for(s=p[e],m=a[e-i-1],t=0;t<h;t++)s[t]-=2*m[t]}}return{H:l,Q:p}},numeric.epsilon=2220446049250313e-31,numeric.QRFrancis=function(r,n){void 0===n&&(n=1e4),r=numeric.clone(r),numeric.clone(r);var e,i,t,u,o,c,a,f,m,s,h,l,p,y,g,v,d,x,b=numeric.dim(r)[0],w=numeric.identity(b);if(b<3)return{Q:w,B:[[0,b-1]]};var M=numeric.epsilon;for(x=0;x<n;x++){for(v=0;v<b-1;v++)if(Math.abs(r[v+1][v])<M*(Math.abs(r[v][v])+Math.abs(r[v+1][v+1]))){var k=numeric.QRFrancis(numeric.getBlock(r,[0,0],[v,v]),n),A=numeric.QRFrancis(numeric.getBlock(r,[v+1,v+1],[b-1,b-1]),n);for(l=Array(v+1),g=0;g<=v;g++)l[g]=w[g];for(p=numeric.dot(k.Q,l),g=0;g<=v;g++)w[g]=p[g];for(l=Array(b-v-1),g=v+1;g<b;g++)l[g-v-1]=w[g];for(p=numeric.dot(A.Q,l),g=v+1;g<b;g++)w[g]=p[g-v-1];return{Q:w,B:k.B.concat(numeric.add(A.B,v+1))}}var T,j,_;for(t=r[b-2][b-2],u=r[b-2][b-1],o=r[b-1][b-2],f=t+(c=r[b-1][b-1]),a=t*c-u*o,m=numeric.getBlock(r,[0,0],[2,2]),f*f>=4*a?(T=.5*(f+Math.sqrt(f*f-4*a)),j=.5*(f-Math.sqrt(f*f-4*a)),m=numeric.add(numeric.sub(numeric.dot(m,m),numeric.mul(m,T+j)),numeric.diag(numeric.rep([3],T*j)))):m=numeric.add(numeric.sub(numeric.dot(m,m),numeric.mul(m,f)),numeric.diag(numeric.rep([3],a))),e=[m[0][0],m[1][0],m[2][0]],i=numeric.house(e),l=[r[0],r[1],r[2]],p=numeric.tensor(i,numeric.dot(i,l)),g=0;g<3;g++)for(h=r[g],y=p[g],d=0;d<b;d++)h[d]-=2*y[d];for(l=numeric.getBlock(r,[0,0],[b-1,2]),p=numeric.tensor(numeric.dot(l,i),i),g=0;g<b;g++)for(h=r[g],y=p[g],d=0;d<3;d++)h[d]-=2*y[d];for(l=[w[0],w[1],w[2]],p=numeric.tensor(i,numeric.dot(i,l)),g=0;g<3;g++)for(s=w[g],y=p[g],d=0;d<b;d++)s[d]-=2*y[d];for(v=0;v<b-2;v++){for(d=v;d<=v+1;d++)if(Math.abs(r[d+1][d])<M*(Math.abs(r[d][d])+Math.abs(r[d+1][d+1]))){for(k=numeric.QRFrancis(numeric.getBlock(r,[0,0],[d,d]),n),A=numeric.QRFrancis(numeric.getBlock(r,[d+1,d+1],[b-1,b-1]),n),l=Array(d+1),g=0;g<=d;g++)l[g]=w[g];for(p=numeric.dot(k.Q,l),g=0;g<=d;g++)w[g]=p[g];for(l=Array(b-d-1),g=d+1;g<b;g++)l[g-d-1]=w[g];for(p=numeric.dot(A.Q,l),g=d+1;g<b;g++)w[g]=p[g-d-1];return{Q:w,B:k.B.concat(numeric.add(A.B,d+1))}}for(_=Math.min(b-1,v+3),e=Array(_-v),g=v+1;g<=_;g++)e[g-v-1]=r[g][v];for(i=numeric.house(e),l=numeric.getBlock(r,[v+1,v],[_,b-1]),p=numeric.tensor(i,numeric.dot(i,l)),g=v+1;g<=_;g++)for(h=r[g],y=p[g-v-1],d=v;d<b;d++)h[d]-=2*y[d-v];for(l=numeric.getBlock(r,[0,v+1],[b-1,_]),p=numeric.tensor(numeric.dot(l,i),i),g=0;g<b;g++)for(h=r[g],y=p[g],d=v+1;d<=_;d++)h[d]-=2*y[d-v-1];for(l=Array(_-v),g=v+1;g<=_;g++)l[g-v-1]=w[g];for(p=numeric.tensor(i,numeric.dot(i,l)),g=v+1;g<=_;g++)for(s=w[g],y=p[g-v-1],d=0;d<b;d++)s[d]-=2*y[d]}}throw new Error("numeric: eigenvalue iteration does not converge -- increase maxiter?")},numeric.eig=function(r,n){var e,i,t,u,o,c,a,f,m,s,h,l,p,y,g,v,d=numeric.toUpperHessenberg(r),x=numeric.QRFrancis(d.H,n),b=numeric.T,w=r.length,M=x.B,k=numeric.dot(x.Q,numeric.dot(d.H,numeric.transpose(x.Q))),A=new b(numeric.dot(x.Q,d.Q)),T=M.length,j=Math.sqrt;for(i=0;i<T;i++)if((e=M[i][0])===M[i][1]);else{if(u=e+1,o=k[e][e],c=k[e][u],a=k[u][e],f=k[u][u],0===c&&0===a)continue;(s=(m=-o-f)*m-4*(o*f-c*a))>=0?((g=(o-(h=m<0?-.5*(m-j(s)):-.5*(m+j(s))))*(o-h)+c*c)>(v=a*a+(f-h)*(f-h))?(p=(o-h)/(g=j(g)),y=c/g):(p=a/(v=j(v)),y=(f-h)/v),t=new b([[y,-p],[p,y]]),A.setRows(e,u,t.dot(A.getRows(e,u)))):(h=-.5*m,l=.5*j(-s),(g=(o-h)*(o-h)+c*c)>(v=a*a+(f-h)*(f-h))?(p=(o-h)/(g=j(g+l*l)),y=c/g,h=0,l/=g):(p=a/(v=j(v+l*l)),y=(f-h)/v,h=l/v,l=0),t=new b([[y,-p],[p,y]],[[h,l],[l,-h]]),A.setRows(e,u,t.dot(A.getRows(e,u))))}var _=A.dot(r).dot(A.transjugate()),S=(w=r.length,numeric.T.identity(w));for(u=0;u<w;u++)if(u>0)for(i=u-1;i>=0;i--){var q=_.get([i,i]),V=_.get([u,u]);numeric.neq(q.x,V.x)||numeric.neq(q.y,V.y)?(h=_.getRow(i).getBlock([i],[u-1]),l=S.getRow(u).getBlock([i],[u-1]),S.set([u,i],_.get([i,u]).neg().sub(h.dot(l)).div(q.sub(V)))):S.setRow(u,S.getRow(i))}for(u=0;u<w;u++)h=S.getRow(u),S.setRow(u,h.div(h.norm2()));return S=S.transpose(),S=A.transjugate().dot(S),{lambda:_.getDiag(),E:S}},numeric.ccsSparse=function(r){var n,e,i,t=r.length,u=[];for(e=t-1;-1!==e;--e)for(i in n=r[e]){for(i=parseInt(i);i>=u.length;)u[u.length]=0;0!==n[i]&&u[i]++}var o=u.length,c=Array(o+1);for(c[0]=0,e=0;e<o;++e)c[e+1]=c[e]+u[e];var a=Array(c[o]),f=Array(c[o]);for(e=t-1;-1!==e;--e)for(i in n=r[e])0!==n[i]&&(u[i]--,a[c[i]+u[i]]=e,f[c[i]+u[i]]=n[i]);return[c,a,f]},numeric.ccsFull=function(r){var n,e,i,t,u=r[0],o=r[1],c=r[2],a=numeric.ccsDim(r),f=a[0],m=a[1],s=numeric.rep([f,m],0);for(n=0;n<m;n++)for(i=u[n],t=u[n+1],e=i;e<t;++e)s[o[e]][n]=c[e];return s},numeric.ccsTSolve=function(r,n,e,i,t){var u,o,c,a,f,m,s,h=r[0],l=r[1],p=r[2],y=h.length-1,g=Math.max,v=0;function d(r){var n;if(0===e[r]){for(e[r]=1,n=h[r];n<h[r+1];++n)d(l[n]);t[v]=r,++v}}for(void 0===i&&(e=numeric.rep([y],0)),void 0===i&&(i=numeric.linspace(0,e.length-1)),void 0===t&&(t=[]),u=i.length-1;-1!==u;--u)d(i[u]);for(t.length=v,u=t.length-1;-1!==u;--u)e[t[u]]=0;for(u=i.length-1;-1!==u;--u)o=i[u],e[o]=n[o];for(u=t.length-1;-1!==u;--u){for(o=t[u],c=h[o],a=g(h[o+1],c),f=c;f!==a;++f)if(l[f]===o){e[o]/=p[f];break}for(s=e[o],f=c;f!==a;++f)(m=l[f])!==o&&(e[m]-=s*p[f])}return e},numeric.ccsDFS=function(r){this.k=Array(r),this.k1=Array(r),this.j=Array(r)},numeric.ccsDFS.prototype.dfs=function(r,n,e,i,t,u){var o,c,a,f=0,m=t.length,s=this.k,h=this.k1,l=this.j;if(0===i[r])for(i[r]=1,l[0]=r,s[0]=c=n[r],h[0]=a=n[r+1];;)if(c>=a){if(t[m]=l[f],0===f)return;++m,c=s[--f],a=h[f]}else 0===i[o=u[e[c]]]?(i[o]=1,s[f]=c,l[++f]=o,c=n[o],h[f]=a=n[o+1]):++c},numeric.ccsLPSolve=function(r,n,e,i,t,u,o){var c,a,f,m,s,h,l,p,y,g=r[0],v=r[1],d=r[2],x=(g.length,n[0]),b=n[1],w=n[2];for(a=x[t],f=x[t+1],i.length=0,c=a;c<f;++c)o.dfs(u[b[c]],g,v,e,i,u);for(c=i.length-1;-1!==c;--c)e[i[c]]=0;for(c=a;c!==f;++c)e[m=u[b[c]]]=w[c];for(c=i.length-1;-1!==c;--c){for(s=g[m=i[c]],h=g[m+1],l=s;l<h;++l)if(u[v[l]]===m){e[m]/=d[l];break}for(y=e[m],l=s;l<h;++l)(p=u[v[l]])!==m&&(e[p]-=y*d[l])}return e},numeric.ccsLUP1=function(r,n){var e,i,t,u,o,c,a,f=r[0].length-1,m=[numeric.rep([f+1],0),[],[]],s=[numeric.rep([f+1],0),[],[]],h=m[0],l=m[1],p=m[2],y=s[0],g=s[1],v=s[2],d=numeric.rep([f],0),x=numeric.rep([f],0),b=numeric.ccsLPSolve,w=(Math.max,Math.abs),M=numeric.linspace(0,f-1),k=numeric.linspace(0,f-1),A=new numeric.ccsDFS(f);for(void 0===n&&(n=1),e=0;e<f;++e){for(b(m,r,d,x,e,k,A),u=-1,o=-1,i=x.length-1;-1!==i;--i)(t=x[i])<=e||(c=w(d[t]))>u&&(o=t,u=c);for(w(d[e])<n*u&&(i=M[e],u=M[o],M[e]=u,k[u]=e,M[o]=i,k[i]=o,u=d[e],d[e]=d[o],d[o]=u),u=h[e],o=y[e],a=d[e],l[u]=M[e],p[u]=1,++u,i=x.length-1;-1!==i;--i)c=d[t=x[i]],x[i]=0,d[t]=0,t<=e?(g[o]=t,v[o]=c,++o):(l[u]=M[t],p[u]=c/a,++u);h[e+1]=u,y[e+1]=o}for(i=l.length-1;-1!==i;--i)l[i]=k[l[i]];return{L:m,U:s,P:M,Pinv:k}},numeric.ccsDFS0=function(r){this.k=Array(r),this.k1=Array(r),this.j=Array(r)},numeric.ccsDFS0.prototype.dfs=function(r,n,e,i,t,u,o){var c,a,f,m=0,s=t.length,h=this.k,l=this.k1,p=this.j;if(0===i[r])for(i[r]=1,p[0]=r,h[0]=a=n[u[r]],l[0]=f=n[u[r]+1];;){if(isNaN(a))throw new Error("Ow!");if(a>=f){if(t[s]=u[p[m]],0===m)return;++s,a=h[--m],f=l[m]}else 0===i[c=e[a]]?(i[c]=1,h[m]=a,p[++m]=c,a=n[c=u[c]],l[m]=f=n[c+1]):++a}},numeric.ccsLPSolve0=function(r,n,e,i,t,u,o,c){var a,f,m,s,h,l,p,y,g,v=r[0],d=r[1],x=r[2],b=(v.length,n[0]),w=n[1],M=n[2];for(f=b[t],m=b[t+1],i.length=0,a=f;a<m;++a)c.dfs(w[a],v,d,e,i,u,o);for(a=i.length-1;-1!==a;--a)e[o[s=i[a]]]=0;for(a=f;a!==m;++a)e[s=w[a]]=M[a];for(a=i.length-1;-1!==a;--a){for(y=o[s=i[a]],h=v[s],l=v[s+1],p=h;p<l;++p)if(d[p]===y){e[y]/=x[p];break}for(g=e[y],p=h;p<l;++p)e[d[p]]-=g*x[p];e[y]=g}},numeric.ccsLUP0=function(r,n){var e,i,t,u,o,c,a,f=r[0].length-1,m=[numeric.rep([f+1],0),[],[]],s=[numeric.rep([f+1],0),[],[]],h=m[0],l=m[1],p=m[2],y=s[0],g=s[1],v=s[2],d=numeric.rep([f],0),x=numeric.rep([f],0),b=numeric.ccsLPSolve0,w=(Math.max,Math.abs),M=numeric.linspace(0,f-1),k=numeric.linspace(0,f-1),A=new numeric.ccsDFS0(f);for(void 0===n&&(n=1),e=0;e<f;++e){for(b(m,r,d,x,e,k,M,A),u=-1,o=-1,i=x.length-1;-1!==i;--i)(t=x[i])<=e||(c=w(d[M[t]]))>u&&(o=t,u=c);for(w(d[M[e]])<n*u&&(i=M[e],u=M[o],M[e]=u,k[u]=e,M[o]=i,k[i]=o),u=h[e],o=y[e],a=d[M[e]],l[u]=M[e],p[u]=1,++u,i=x.length-1;-1!==i;--i)c=d[M[t=x[i]]],x[i]=0,d[M[t]]=0,t<=e?(g[o]=t,v[o]=c,++o):(l[u]=M[t],p[u]=c/a,++u);h[e+1]=u,y[e+1]=o}for(i=l.length-1;-1!==i;--i)l[i]=k[l[i]];return{L:m,U:s,P:M,Pinv:k}},numeric.ccsLUP=numeric.ccsLUP0,numeric.ccsDim=function(r){return[numeric.sup(r[1])+1,r[0].length-1]},numeric.ccsGetBlock=function(r,n,e){var i=numeric.ccsDim(r),t=i[0],u=i[1];void 0===n?n=numeric.linspace(0,t-1):"number"==typeof n&&(n=[n]),void 0===e?e=numeric.linspace(0,u-1):"number"==typeof e&&(e=[e]);var o,c,a,f,m=n.length,s=e.length,h=numeric.rep([u],0),l=[],p=[],y=[h,l,p],g=r[0],v=r[1],d=r[2],x=numeric.rep([t],0),b=0,w=numeric.rep([t],0);for(c=0;c<s;++c){var M=g[f=e[c]],k=g[f+1];for(o=M;o<k;++o)w[a=v[o]]=1,x[a]=d[o];for(o=0;o<m;++o)w[n[o]]&&(l[b]=o,p[b]=x[n[o]],++b);for(o=M;o<k;++o)w[a=v[o]]=0;h[c+1]=b}return y},numeric.ccsDot=function(r,n){var e,i,t,u,o,c,a,f,m,s,h,l=r[0],p=r[1],y=r[2],g=n[0],v=n[1],d=n[2],x=numeric.ccsDim(r),b=numeric.ccsDim(n),w=x[0],M=(x[1],b[1]),k=numeric.rep([w],0),A=numeric.rep([w],0),T=Array(w),j=numeric.rep([M],0),_=[],S=[],q=[j,_,S];for(t=0;t!==M;++t){for(u=g[t],o=g[t+1],m=0,i=u;i<o;++i)for(s=v[i],h=d[i],c=l[s],a=l[s+1],e=c;e<a;++e)0===A[f=p[e]]&&(T[m]=f,A[f]=1,m+=1),k[f]=k[f]+y[e]*h;for(o=(u=j[t])+m,j[t+1]=o,i=m-1;-1!==i;--i)h=u+i,e=T[i],_[h]=e,S[h]=k[e],A[e]=0,k[e]=0;j[t+1]=j[t]+m}return q},numeric.ccsLUPSolve=function(r,n){var e=r.L,i=r.U,t=(r.P,n[0]),u=!1;"object"!=typeof t&&(t=(n=[[0,n.length],numeric.linspace(0,n.length-1),n])[0],u=!0);var o,c,a,f,m,s,h=n[1],l=n[2],p=e[0].length-1,y=t.length-1,g=numeric.rep([p],0),v=Array(p),d=numeric.rep([p],0),x=Array(p),b=numeric.rep([y+1],0),w=[],M=[],k=numeric.ccsTSolve,A=0;for(o=0;o<y;++o){for(m=0,a=t[o],f=t[o+1],c=a;c<f;++c)s=r.Pinv[h[c]],x[m]=s,d[s]=l[c],++m;for(x.length=m,k(e,d,g,x,v),c=x.length-1;-1!==c;--c)d[x[c]]=0;if(k(i,g,d,v,x),u)return d;for(c=v.length-1;-1!==c;--c)g[v[c]]=0;for(c=x.length-1;-1!==c;--c)s=x[c],w[A]=s,M[A]=d[s],d[s]=0,++A;b[o+1]=A}return[b,w,M]},numeric.ccsbinop=function(r,n){return void 0===n&&(n=""),Function("X","Y","var Xi = X[0], Xj = X[1], Xv = X[2];\nvar Yi = Y[0], Yj = Y[1], Yv = Y[2];\nvar n = Xi.length-1,m = Math.max(numeric.sup(Xj),numeric.sup(Yj))+1;\nvar Zi = numeric.rep([n+1],0), Zj = [], Zv = [];\nvar x = numeric.rep([m],0),y = numeric.rep([m],0);\nvar xk,yk,zk;\nvar i,j,j0,j1,k,p=0;\n"+n+"for(i=0;i<n;++i) {\n j0 = Xi[i]; j1 = Xi[i+1];\n for(j=j0;j!==j1;++j) {\n k = Xj[j];\n x[k] = 1;\n Zj[p] = k;\n ++p;\n }\n j0 = Yi[i]; j1 = Yi[i+1];\n for(j=j0;j!==j1;++j) {\n k = Yj[j];\n y[k] = Yv[j];\n if(x[k] === 0) {\n Zj[p] = k;\n ++p;\n }\n }\n Zi[i+1] = p;\n j0 = Xi[i]; j1 = Xi[i+1];\n for(j=j0;j!==j1;++j) x[Xj[j]] = Xv[j];\n j0 = Zi[i]; j1 = Zi[i+1];\n for(j=j0;j!==j1;++j) {\n k = Zj[j];\n xk = x[k];\n yk = y[k];\n"+r+"\n Zv[j] = zk;\n }\n j0 = Xi[i]; j1 = Xi[i+1];\n for(j=j0;j!==j1;++j) x[Xj[j]] = 0;\n j0 = Yi[i]; j1 = Yi[i+1];\n for(j=j0;j!==j1;++j) y[Yj[j]] = 0;\n}\nreturn [Zi,Zj,Zv];")},function(){var k,A,B,C;for(k in numeric.ops2)A=isFinite(eval("1"+numeric.ops2[k]+"0"))?"[Y[0],Y[1],numeric."+k+"(X,Y[2])]":"NaN",B=isFinite(eval("0"+numeric.ops2[k]+"1"))?"[X[0],X[1],numeric."+k+"(X[2],Y)]":"NaN",C=isFinite(eval("1"+numeric.ops2[k]+"0"))&&isFinite(eval("0"+numeric.ops2[k]+"1"))?"numeric.ccs"+k+"MM(X,Y)":"NaN",numeric["ccs"+k+"MM"]=numeric.ccsbinop("zk = xk "+numeric.ops2[k]+"yk;"),numeric["ccs"+k]=Function("X","Y",'if(typeof X === "number") return '+A+';\nif(typeof Y === "number") return '+B+";\nreturn "+C+";\n")}(),numeric.ccsScatter=function(r){var n,e=r[0],i=r[1],t=r[2],u=numeric.sup(i)+1,o=e.length,c=numeric.rep([u],0),a=Array(o),f=Array(o),m=numeric.rep([u],0);for(n=0;n<o;++n)m[i[n]]++;for(n=0;n<u;++n)c[n+1]=c[n]+m[n];var s,h,l=c.slice(0);for(n=0;n<o;++n)a[s=l[h=i[n]]]=e[n],f[s]=t[n],l[h]=l[h]+1;return[c,a,f]},numeric.ccsGather=function(r){var n,e,i,t,u,o=r[0],c=r[1],a=r[2],f=o.length-1,m=c.length,s=Array(m),h=Array(m),l=Array(m);for(u=0,n=0;n<f;++n)for(i=o[n],t=o[n+1],e=i;e!==t;++e)h[u]=n,s[u]=c[e],l[u]=a[e],++u;return[s,h,l]},numeric.sdim=function r(n,e,i){if(void 0===e&&(e=[]),"object"!=typeof n)return e;var t;for(t in void 0===i&&(i=0),i in e||(e[i]=0),n.length>e[i]&&(e[i]=n.length),n)n.hasOwnProperty(t)&&r(n[t],e,i+1);return e},numeric.sclone=function r(n,e,i){void 0===e&&(e=0),void 0===i&&(i=numeric.sdim(n).length);var t,u=Array(n.length);if(e===i-1){for(t in n)n.hasOwnProperty(t)&&(u[t]=n[t]);return u}for(t in n)n.hasOwnProperty(t)&&(u[t]=r(n[t],e+1,i));return u},numeric.sdiag=function(r){var n,e,i=r.length,t=Array(i);for(n=i-1;n>=1;n-=2)e=n-1,t[n]=[],t[n][n]=r[n],t[e]=[],t[e][e]=r[e];return 0===n&&(t[0]=[],t[0][0]=r[n]),t},numeric.sidentity=function(r){return numeric.sdiag(numeric.rep([r],1))},numeric.stranspose=function(r){var n,e,i,t=[];for(n in r.length,r)if(r.hasOwnProperty(n))for(e in i=r[n])i.hasOwnProperty(e)&&("object"!=typeof t[e]&&(t[e]=[]),t[e][n]=i[e]);return t},numeric.sLUP=function(r,n){throw new Error("The function numeric.sLUP had a bug in it and has been removed. Please use the new numeric.ccsLUP function instead.")},numeric.sdotMM=function(r,n){var e,i,t,u,o,c,a,f=r.length,m=(n.length,numeric.stranspose(n)),s=m.length,h=Array(f);for(t=f-1;t>=0;t--){for(a=[],e=r[t],o=s-1;o>=0;o--){for(u in c=0,i=m[o],e)e.hasOwnProperty(u)&&u in i&&(c+=e[u]*i[u]);c&&(a[o]=c)}h[t]=a}return h},numeric.sdotMV=function(r,n){var e,i,t,u,o=r.length,c=Array(o);for(i=o-1;i>=0;i--){for(t in u=0,e=r[i])e.hasOwnProperty(t)&&n[t]&&(u+=e[t]*n[t]);u&&(c[i]=u)}return c},numeric.sdotVM=function(r,n){var e,i,t,u,o=[];for(e in r)if(r.hasOwnProperty(e))for(i in t=n[e],u=r[e],t)t.hasOwnProperty(i)&&(o[i]||(o[i]=0),o[i]+=u*t[i]);return o},numeric.sdotVV=function(r,n){var e,i=0;for(e in r)r[e]&&n[e]&&(i+=r[e]*n[e]);return i},numeric.sdot=function(r,n){var e=numeric.sdim(r).length,i=numeric.sdim(n).length;switch(1e3*e+i){case 0:return r*n;case 1001:return numeric.sdotVV(r,n);case 2001:return numeric.sdotMV(r,n);case 1002:return numeric.sdotVM(r,n);case 2002:return numeric.sdotMM(r,n);default:throw new Error("numeric.sdot not implemented for tensors of order "+e+" and "+i)}},numeric.sscatter=function(r){var n,e,i,t,u=r[0].length,o=r.length,c=[];for(e=u-1;e>=0;--e)if(r[o-1][e]){for(t=c,i=0;i<o-2;i++)t[n=r[i][e]]||(t[n]=[]),t=t[n];t[r[i][e]]=r[i+1][e]}return c},numeric.sgather=function r(n,e,i){var t,u,o;for(u in void 0===e&&(e=[]),void 0===i&&(i=[]),t=i.length,n)if(n.hasOwnProperty(u))if(i[t]=parseInt(u),"number"==typeof(o=n[u])){if(o){if(0===e.length)for(u=t+1;u>=0;--u)e[u]=[];for(u=t;u>=0;--u)e[u].push(i[u]);e[t+1].push(o)}}else r(o,e,i);return i.length>t&&i.pop(),e},numeric.cLU=function(r){var n,e,i,t,u,o,c=r[0],a=r[1],f=r[2],m=c.length,s=0;for(n=0;n<m;n++)c[n]>s&&(s=c[n]);s++;var h,l=Array(s),p=Array(s),y=numeric.rep([s],1/0),g=numeric.rep([s],-1/0);for(i=0;i<m;i++)n=c[i],(e=a[i])<y[n]&&(y[n]=e),e>g[n]&&(g[n]=e);for(n=0;n<s-1;n++)g[n]>g[n+1]&&(g[n+1]=g[n]);for(n=s-1;n>=1;n--)y[n]<y[n-1]&&(y[n-1]=y[n]);for(n=0;n<s;n++)p[n]=numeric.rep([g[n]-y[n]+1],0),l[n]=numeric.rep([n-y[n]],0),y[n],g[n];for(i=0;i<m;i++)p[n=c[i]][a[i]-y[n]]=f[i];for(n=0;n<s-1;n++)for(t=n-y[n],x=p[n],e=n+1;y[e]<=n&&e<s;e++)if(u=n-y[e],o=g[n]-n,h=(b=p[e])[u]/x[t]){for(i=1;i<=o;i++)b[i+u]-=h*x[i+t];l[e][n-y[e]]=h}var v,d,x=[],b=[],w=[],M=[],k=[],A=[];for(m=0,v=0,n=0;n<s;n++){for(t=y[n],u=g[n],d=p[n],e=n;e<=u;e++)d[e-t]&&(x[m]=n,b[m]=e,w[m]=d[e-t],m++);for(d=l[n],e=t;e<n;e++)d[e-t]&&(M[v]=n,k[v]=e,A[v]=d[e-t],v++);M[v]=n,k[v]=n,A[v]=1,v++}return{U:[x,b,w],L:[M,k,A]}},numeric.cLUsolve=function(r,n){var e,i,t=r.L,u=r.U,o=numeric.clone(n),c=t[0],a=t[1],f=t[2],m=u[0],s=u[1],h=u[2],l=m.length,p=(c.length,o.length);for(i=0,e=0;e<p;e++){for(;a[i]<e;)o[e]-=f[i]*o[a[i]],i++;i++}for(i=l-1,e=p-1;e>=0;e--){for(;s[i]>e;)o[e]-=h[i]*o[s[i]],i--;o[e]/=h[i],i--}return o},numeric.cgrid=function(r,n){"number"==typeof r&&(r=[r,r]);var e,i,t,u=numeric.rep(r,-1);for("function"!=typeof n&&(n="L"===n?function(n,e){return n>=r[0]/2||e<r[1]/2}:function(r,n){return!0}),t=0,e=1;e<r[0]-1;e++)for(i=1;i<r[1]-1;i++)n(e,i)&&(u[e][i]=t,t++);return u},numeric.cdelsq=function(r){var n,e,i,t,u,o=[[-1,0],[0,-1],[0,1],[1,0]],c=numeric.dim(r),a=c[0],f=c[1],m=[],s=[],h=[];for(n=1;n<a-1;n++)for(e=1;e<f-1;e++)if(!(r[n][e]<0)){for(i=0;i<4;i++)t=n+o[i][0],u=e+o[i][1],r[t][u]<0||(m.push(r[n][e]),s.push(r[t][u]),h.push(-1));m.push(r[n][e]),s.push(r[n][e]),h.push(4)}return[m,s,h]},numeric.cdotMV=function(r,n){var e,i,t,u=r[0],o=r[1],c=r[2],a=u.length;for(t=0,i=0;i<a;i++)u[i]>t&&(t=u[i]);for(t++,e=numeric.rep([t],0),i=0;i<a;i++)e[u[i]]+=c[i]*n[o[i]];return e},numeric.Spline=function(r,n,e,i,t){this.x=r,this.yl=n,this.yr=e,this.kl=i,this.kr=t},numeric.Spline.prototype._at=function(r,n){var e,i,t,u=this.x,o=this.yl,c=this.yr,a=this.kl,f=this.kr,m=numeric.add,s=numeric.sub,h=numeric.mul;e=s(h(a[n],u[n+1]-u[n]),s(c[n+1],o[n])),i=m(h(f[n+1],u[n]-u[n+1]),s(c[n+1],o[n]));var l=(t=(r-u[n])/(u[n+1]-u[n]))*(1-t);return m(m(m(h(1-t,o[n]),h(t,c[n+1])),h(e,l*(1-t))),h(i,l*t))},numeric.Spline.prototype.at=function(r){if("number"==typeof r){var n,e,i,t=this.x,u=t.length,o=Math.floor;for(n=0,e=u-1;e-n>1;)t[i=o((n+e)/2)]<=r?n=i:e=i;return this._at(r,n)}u=r.length;var c,a=Array(u);for(c=u-1;-1!==c;--c)a[c]=this.at(r[c]);return a},numeric.Spline.prototype.diff=function(){var r,n,e,i=this.x,t=this.yl,u=this.yr,o=this.kl,c=this.kr,a=t.length,f=o,m=c,s=Array(a),h=Array(a),l=numeric.add,p=numeric.mul,y=numeric.div,g=numeric.sub;for(r=a-1;-1!==r;--r)n=i[r+1]-i[r],e=g(u[r+1],t[r]),s[r]=y(l(p(e,6),p(o[r],-4*n),p(c[r+1],-2*n)),n*n),h[r+1]=y(l(p(e,-6),p(o[r],2*n),p(c[r+1],4*n)),n*n);return new numeric.Spline(i,f,m,s,h)},numeric.Spline.prototype.roots=function(){function r(r){return r*r}var n=[],e=this.x,i=this.yl,t=this.yr,u=this.kl,o=this.kr;"number"==typeof i[0]&&(i=[i],t=[t],u=[u],o=[o]);var c,a,f,m,s,h,l,p,y,g,v,d,x,b,w,M,k,A,T,j,_,S,q,V=i.length,P=e.length-1,F=(n=Array(V),Math.sqrt);for(c=0;c!==V;++c){for(m=i[c],s=t[c],h=u[c],l=o[c],p=[],a=0;a!==P;a++){for(a>0&&s[a]*m[a]<0&&p.push(e[a]),M=e[a+1]-e[a],e[a],v=m[a],d=s[a+1],y=h[a]/M,x=(g=l[a+1]/M)+3*v+2*y-3*d,b=3*(g+y+2*(v-d)),(w=r(y-g+3*(v-d))+12*g*v)<=0?k=(A=x/b)>e[a]&&A<e[a+1]?[e[a],A,e[a+1]]:[e[a],e[a+1]]:(A=(x-F(w))/b,T=(x+F(w))/b,k=[e[a]],A>e[a]&&A<e[a+1]&&k.push(A),T>e[a]&&T<e[a+1]&&k.push(T),k.push(e[a+1])),_=k[0],A=this._at(_,a),f=0;f<k.length-1;f++)if(S=k[f+1],T=this._at(S,a),0!==A)if(0===T||A*T>0)_=S,A=T;else{for(var L=0;!((q=(A*S-T*_)/(A-T))<=_||q>=S);)if((j=this._at(q,a))*T>0)S=q,T=j,-1===L&&(A*=.5),L=-1;else{if(!(j*A>0))break;_=q,A=j,1===L&&(T*=.5),L=1}p.push(q),_=k[f+1],A=this._at(_,a)}else p.push(_),_=S,A=T;0===T&&p.push(S)}n[c]=p}return"number"==typeof this.yl[0]?n[0]:n},numeric.spline=function(r,n,e,i){var t,u=r.length,o=[],c=[],a=[],f=numeric.sub,m=numeric.mul,s=numeric.add;for(t=u-2;t>=0;t--)c[t]=r[t+1]-r[t],a[t]=f(n[t+1],n[t]);"string"!=typeof e&&"string"!=typeof i||(e=i="periodic");var h=[[],[],[]];switch(typeof e){case"undefined":o[0]=m(3/(c[0]*c[0]),a[0]),h[0].push(0,0),h[1].push(0,1),h[2].push(2/c[0],1/c[0]);break;case"string":o[0]=s(m(3/(c[u-2]*c[u-2]),a[u-2]),m(3/(c[0]*c[0]),a[0])),h[0].push(0,0,0),h[1].push(u-2,0,1),h[2].push(1/c[u-2],2/c[u-2]+2/c[0],1/c[0]);break;default:o[0]=e,h[0].push(0),h[1].push(0),h[2].push(1)}for(t=1;t<u-1;t++)o[t]=s(m(3/(c[t-1]*c[t-1]),a[t-1]),m(3/(c[t]*c[t]),a[t])),h[0].push(t,t,t),h[1].push(t-1,t,t+1),h[2].push(1/c[t-1],2/c[t-1]+2/c[t],1/c[t]);switch(typeof i){case"undefined":o[u-1]=m(3/(c[u-2]*c[u-2]),a[u-2]),h[0].push(u-1,u-1),h[1].push(u-2,u-1),h[2].push(1/c[u-2],2/c[u-2]);break;case"string":h[1][h[1].length-1]=0;break;default:o[u-1]=i,h[0].push(u-1),h[1].push(u-1),h[2].push(1)}o="number"!=typeof o[0]?numeric.transpose(o):[o];var l=Array(o.length);if("string"==typeof e)for(t=l.length-1;-1!==t;--t)l[t]=numeric.ccsLUPSolve(numeric.ccsLUP(numeric.ccsScatter(h)),o[t]),l[t][u-1]=l[t][0];else for(t=l.length-1;-1!==t;--t)l[t]=numeric.cLUsolve(numeric.cLU(h),o[t]);return l="number"==typeof n[0]?l[0]:numeric.transpose(l),new numeric.Spline(r,n,n,l,l)},numeric.fftpow2=function r(n,e){var i=n.length;if(1!==i){var t,u,o=Math.cos,c=Math.sin,a=Array(i/2),f=Array(i/2),m=Array(i/2),s=Array(i/2);for(u=i/2,t=i-1;-1!==t;--t)m[--u]=n[t],s[u]=e[t],--t,a[u]=n[t],f[u]=e[t];r(a,f),r(m,s),u=i/2;var h,l,p,y=-6.283185307179586/i;for(t=i-1;-1!==t;--t)-1==--u&&(u=i/2-1),l=o(h=y*t),p=c(h),n[t]=a[u]+l*m[u]-p*s[u],e[t]=f[u]+l*s[u]+p*m[u]}},numeric._ifftpow2=function r(n,e){var i=n.length;if(1!==i){var t,u,o=Math.cos,c=Math.sin,a=Array(i/2),f=Array(i/2),m=Array(i/2),s=Array(i/2);for(u=i/2,t=i-1;-1!==t;--t)m[--u]=n[t],s[u]=e[t],--t,a[u]=n[t],f[u]=e[t];r(a,f),r(m,s),u=i/2;var h,l,p,y=6.283185307179586/i;for(t=i-1;-1!==t;--t)-1==--u&&(u=i/2-1),l=o(h=y*t),p=c(h),n[t]=a[u]+l*m[u]-p*s[u],e[t]=f[u]+l*s[u]+p*m[u]}},numeric.ifftpow2=function(r,n){numeric._ifftpow2(r,n),numeric.diveq(r,r.length),numeric.diveq(n,n.length)},numeric.convpow2=function(r,n,e,i){var t,u,o,c,a;for(numeric.fftpow2(r,n),numeric.fftpow2(e,i),t=r.length-1;-1!==t;--t)u=r[t],c=n[t],o=e[t],a=i[t],r[t]=u*o-c*a,n[t]=u*a+c*o;numeric.ifftpow2(r,n)},numeric.T.prototype.fft=function(){var r,n,e=this.x,i=this.y,t=e.length,u=Math.log,o=u(2),c=Math.ceil(u(2*t-1)/o),a=Math.pow(2,c),f=numeric.rep([a],0),m=numeric.rep([a],0),s=Math.cos,h=Math.sin,l=-3.141592653589793/t,p=numeric.rep([a],0),y=numeric.rep([a],0);for(Math.floor(t/2),r=0;r<t;r++)p[r]=e[r];if(void 0!==i)for(r=0;r<t;r++)y[r]=i[r];for(f[0]=1,r=1;r<=a/2;r++)n=l*r*r,f[r]=s(n),m[r]=h(n),f[a-r]=s(n),m[a-r]=h(n);var g=new numeric.T(p,y),v=new numeric.T(f,m);return g=g.mul(v),numeric.convpow2(g.x,g.y,numeric.clone(v.x),numeric.neg(v.y)),(g=g.mul(v)).x.length=t,g.y.length=t,g},numeric.T.prototype.ifft=function(){var r,n,e=this.x,i=this.y,t=e.length,u=Math.log,o=u(2),c=Math.ceil(u(2*t-1)/o),a=Math.pow(2,c),f=numeric.rep([a],0),m=numeric.rep([a],0),s=Math.cos,h=Math.sin,l=3.141592653589793/t,p=numeric.rep([a],0),y=numeric.rep([a],0);for(Math.floor(t/2),r=0;r<t;r++)p[r]=e[r];if(void 0!==i)for(r=0;r<t;r++)y[r]=i[r];for(f[0]=1,r=1;r<=a/2;r++)n=l*r*r,f[r]=s(n),m[r]=h(n),f[a-r]=s(n),m[a-r]=h(n);var g=new numeric.T(p,y),v=new numeric.T(f,m);return g=g.mul(v),numeric.convpow2(g.x,g.y,numeric.clone(v.x),numeric.neg(v.y)),(g=g.mul(v)).x.length=t,g.y.length=t,g.div(t)},numeric.gradient=function(r,n){var e=n.length,i=r(n);if(isNaN(i))throw new Error("gradient: f(x) is a NaN!");var t,u,o,c,a,f,m,s,h,l=Math.max,p=numeric.clone(n),y=Array(e),g=(numeric.div,numeric.sub,l=Math.max,Math.abs),v=Math.min,d=0;for(t=0;t<e;t++)for(var x=l(1e-6*i,1e-8);;){if(++d>20)throw new Error("Numerical gradient fails");if(p[t]=n[t]+x,u=r(p),p[t]=n[t]-x,o=r(p),p[t]=n[t],isNaN(u)||isNaN(o))x/=16;else{if(y[t]=(u-o)/(2*x),c=n[t]-x,a=n[t],f=n[t]+x,m=(u-i)/x,s=(i-o)/x,h=l(g(y[t]),g(i),g(u),g(o),g(c),g(a),g(f),1e-8),!(v(l(g(m-y[t]),g(s-y[t]),g(m-s))/h,x/h)>.001))break;x/=16}}return y},numeric.uncmin=function(r,n,e,i,t,u,o){var c=numeric.gradient;void 0===o&&(o={}),void 0===e&&(e=1e-8),void 0===i&&(i=function(n){return c(r,n)}),void 0===t&&(t=1e3);var a,f,m=(n=numeric.clone(n)).length,s=r(n);if(isNaN(s))throw new Error("uncmin: f(x0) is a NaN!");var h=Math.max,l=numeric.norm2;e=h(e,numeric.epsilon);var p,y,g,v,d,x,b,w,M,k,A=o.Hinv||numeric.identity(m),T=numeric.dot,j=(numeric.inv,numeric.sub),_=numeric.add,S=numeric.tensor,q=numeric.div,V=numeric.mul,P=numeric.all,F=numeric.isFinite,L=numeric.neg,N=0,O="";for(y=i(n);N<t;){if("function"==typeof u&&u(N,n,s,y,A)){O="Callback returned true";break}if(!P(F(y))){O="Gradient has Infinity or NaN";break}if(!P(F(p=L(T(A,y))))){O="Search direction has Infinity or NaN";break}if((k=l(p))<e){O="Newton step smaller than tol";break}for(M=1,f=T(y,p),d=n;N<t&&!(M*k<e)&&(d=_(n,v=V(p,M)),(a=r(d))-s>=.1*M*f||isNaN(a));)M*=.5,++N;if(M*k<e){O="Line search step size smaller than tol";break}if(N===t){O="maxit reached during line search";break}w=T(x=j(g=i(d),y),v),b=T(A,x),A=j(_(A,V((w+T(x,b))/(w*w),S(v,v))),q(_(S(b,v),S(v,b)),w)),n=d,s=a,y=g,++N}return{solution:n,f:s,gradient:y,invHessian:A,iterations:N,message:O}},numeric.Dopri=function(r,n,e,i,t,u,o){this.x=r,this.y=n,this.f=e,this.ymid=i,this.iterations=t,this.events=o,this.message=u},numeric.Dopri.prototype._at=function(r,n){function e(r){return r*r}var i,t,u,o,c,a,f,m,s,h=this,l=h.x,p=h.y,y=h.f,g=h.ymid,v=(l.length,Math.floor,numeric.add),d=numeric.mul,x=numeric.sub;return i=l[n],t=l[n+1],o=p[n],c=p[n+1],u=i+.5*(t-i),a=g[n],f=x(y[n],d(o,1/(i-u)+2/(i-t))),m=x(y[n+1],d(c,1/(t-u)+2/(t-i))),v(v(v(v(d(o,(s=[e(r-t)*(r-u)/e(i-t)/(i-u),e(r-i)*e(r-t)/e(i-u)/e(t-u),e(r-i)*(r-u)/e(t-i)/(t-u),(r-i)*e(r-t)*(r-u)/e(i-t)/(i-u),(r-t)*e(r-i)*(r-u)/e(i-t)/(t-u)])[0]),d(a,s[1])),d(c,s[2])),d(f,s[3])),d(m,s[4]))},numeric.Dopri.prototype.at=function(r){var n,e,i,t=Math.floor;if("number"!=typeof r){var u=r.length,o=Array(u);for(n=u-1;-1!==n;--n)o[n]=this.at(r[n]);return o}var c=this.x;for(n=0,e=c.length-1;e-n>1;)c[i=t(.5*(n+e))]<=r?n=i:e=i;return this._at(r,n)},numeric.dopri=function(r,n,e,i,t,u,o){void 0===t&&(t=1e-6),void 0===u&&(u=1e3);var c,a,f,m,s,h,l,p,y,g,v,d,x,b=[r],w=[e],M=[i(r,e)],k=[],A=[3/40,9/40],T=[44/45,-56/15,32/9],j=[19372/6561,-25360/2187,64448/6561,-212/729],_=[9017/3168,-355/33,46732/5247,49/176,-5103/18656],S=[35/384,0,500/1113,125/192,-2187/6784,11/84],q=[.10013431883002395,0,.3918321794184259,-.02982460176594817,.05893268337240795,-.04497888809104361,5618549.5/235043384],V=[.2,.3,.8,8/9,1,1],P=[-71/57600,0,71/16695,-71/1920,17253/339200,-22/525,1/40],F=0,L=(n-r)/10,N=0,O=numeric.add,U=numeric.mul,D=(Math.max,Math.min),B=Math.abs,R=numeric.norminf,X=Math.pow,E=numeric.any,Y=numeric.lt,I=numeric.and,Q=(numeric.sub,new numeric.Dopri(b,w,M,k,-1,""));for("function"==typeof o&&(v=o(r,e));r<n&&N<u;)if(++N,r+L>n&&(L=n-r),c=i(r+V[0]*L,O(e,U(.2*L,M[F]))),a=i(r+V[1]*L,O(O(e,U(A[0]*L,M[F])),U(A[1]*L,c))),f=i(r+V[2]*L,O(O(O(e,U(T[0]*L,M[F])),U(T[1]*L,c)),U(T[2]*L,a))),m=i(r+V[3]*L,O(O(O(O(e,U(j[0]*L,M[F])),U(j[1]*L,c)),U(j[2]*L,a)),U(j[3]*L,f))),s=i(r+V[4]*L,O(O(O(O(O(e,U(_[0]*L,M[F])),U(_[1]*L,c)),U(_[2]*L,a)),U(_[3]*L,f)),U(_[4]*L,m))),h=i(r+L,y=O(O(O(O(O(e,U(M[F],L*S[0])),U(a,L*S[2])),U(f,L*S[3])),U(m,L*S[4])),U(s,L*S[5]))),(g="number"==typeof(l=O(O(O(O(O(U(M[F],L*P[0]),U(a,L*P[2])),U(f,L*P[3])),U(m,L*P[4])),U(s,L*P[5])),U(h,L*P[6])))?B(l):R(l))>t){if(r+(L=.2*L*X(t/g,.25))===r){Q.msg="Step size became too small";break}}else{if(k[F]=O(O(O(O(O(O(e,U(M[F],L*q[0])),U(a,L*q[2])),U(f,L*q[3])),U(m,L*q[4])),U(s,L*q[5])),U(h,L*q[6])),b[++F]=r+L,w[F]=y,M[F]=h,"function"==typeof o){var C,Z,H=r,z=r+.5*L;if(d=o(z,k[F-1]),E(x=I(Y(v,0),Y(0,d)))||(H=z,v=d,d=o(z=r+L,y),x=I(Y(v,0),Y(0,d))),E(x)){for(var G,$,W=0,J=1,K=1;;){if("number"==typeof v)Z=(K*d*H-J*v*z)/(K*d-J*v);else for(Z=z,p=v.length-1;-1!==p;--p)v[p]<0&&d[p]>0&&(Z=D(Z,(K*d[p]*H-J*v[p]*z)/(K*d[p]-J*v[p])));if(Z<=H||Z>=z)break;$=o(Z,C=Q._at(Z,F-1)),E(G=I(Y(v,0),Y(0,$)))?(z=Z,d=$,x=G,K=1,-1===W?J*=.5:J=1,W=-1):(H=Z,v=$,J=1,1===W?K*=.5:K=1,W=1)}return y=Q._at(.5*(r+Z),F-1),Q.f[F]=i(Z,C),Q.x[F]=Z,Q.y[F]=C,Q.ymid[F-1]=y,Q.events=x,Q.iterations=N,Q}}r+=L,e=y,v=d,L=D(.8*L*X(t/g,.25),4*L)}return Q.iterations=N,Q},numeric.LU=function(r,n){n=n||!1;var e,i,t,u,o,c,a,f,m,s=Math.abs,h=r.length,l=h-1,p=new Array(h);for(n||(r=numeric.clone(r)),t=0;t<h;++t){for(a=t,m=s((c=r[t])[t]),i=t+1;i<h;++i)m<(u=s(r[i][t]))&&(m=u,a=i);for(p[t]=a,a!=t&&(r[t]=r[a],r[a]=c,c=r[t]),o=c[t],e=t+1;e<h;++e)r[e][t]/=o;for(e=t+1;e<h;++e){for(f=r[e],i=t+1;i<l;++i)f[i]-=f[t]*c[i],f[++i]-=f[t]*c[i];i===l&&(f[i]-=f[t]*c[i])}}return{LU:r,P:p}},numeric.LUsolve=function(r,n){var e,i,t,u,o,c=r.LU,a=c.length,f=numeric.clone(n),m=r.P;for(e=a-1;-1!==e;--e)f[e]=n[e];for(e=0;e<a;++e)for(t=m[e],m[e]!==e&&(o=f[e],f[e]=f[t],f[t]=o),u=c[e],i=0;i<e;++i)f[e]-=f[i]*u[i];for(e=a-1;e>=0;--e){for(u=c[e],i=e+1;i<a;++i)f[e]-=f[i]*u[i];f[e]/=u[e]}return f},numeric.solve=function(r,n,e){return numeric.LUsolve(numeric.LU(r,e),n)},numeric.echelonize=function(r){var n,e,i,t,u,o,c,a,f=numeric.dim(r),m=f[0],s=f[1],h=numeric.identity(m),l=Array(m),p=Math.abs,y=numeric.diveq;for(r=numeric.clone(r),n=0;n<m;++n){for(i=0,u=r[n],o=h[n],e=1;e<s;++e)p(u[i])<p(u[e])&&(i=e);for(l[n]=i,y(o,u[i]),y(u,u[i]),e=0;e<m;++e)if(e!==n){for(a=(c=r[e])[i],t=s-1;-1!==t;--t)c[t]-=u[t]*a;for(c=h[e],t=m-1;-1!==t;--t)c[t]-=o[t]*a}}return{I:h,A:r,P:l}},numeric.__solveLP=function(r,n,e,i,t,u,o){var c,a,f,m,s=numeric.sum,h=(numeric.log,numeric.mul),l=numeric.sub,p=numeric.dot,y=numeric.div,g=numeric.add,v=r.length,d=e.length,x=!1,b=1,w=(numeric.transpose(n),numeric.svd,numeric.transpose),M=(numeric.leq,Math.sqrt),k=Math.abs,A=(numeric.muleq,numeric.norminf,numeric.any,Math.min),T=numeric.all,j=numeric.gt,_=Array(v),S=Array(d),q=(numeric.rep([d],1),numeric.solve),V=l(e,p(n,u)),P=p(r,r);for(f=0;f<t;++f){var F,L;for(F=d-1;-1!==F;--F)S[F]=y(n[F],V[F]);var N=w(S);for(F=v-1;-1!==F;--F)_[F]=s(N[F]);b=.25*k(P/p(r,_));var O=100*M(P/p(_,_));for((!isFinite(b)||b>O)&&(b=O),m=g(r,h(b,_)),a=p(N,S),F=v-1;-1!==F;--F)a[F][F]+=1;L=q(a,y(m,b),!0);var U=y(V,p(n,L)),D=1;for(F=d-1;-1!==F;--F)U[F]<0&&(D=A(D,-.999*U[F]));if(c=l(u,h(L,D)),!T(j(V=l(e,p(n,c)),0)))return{solution:u,message:"",iterations:f};if(u=c,b<i)return{solution:c,message:"",iterations:f};if(o){var B=p(r,m),R=p(n,m);for(x=!0,F=d-1;-1!==F;--F)if(B*R[F]<0){x=!1;break}}else x=!(u[v-1]>=0);if(x)return{solution:c,message:"Unbounded",iterations:f}}return{solution:u,message:"maximum iteration count exceeded",iterations:f}},numeric._solveLP=function(r,n,e,i,t){var u=r.length,o=e.length,c=(numeric.sum,numeric.log,numeric.mul,numeric.sub),a=numeric.dot,f=(numeric.div,numeric.add,numeric.rep([u],0).concat([1])),m=numeric.rep([o,1],-1),s=numeric.blockMatrix([[n,m]]),h=e,l=numeric.rep([u],0).concat(Math.max(0,numeric.sup(numeric.neg(e)))+1),p=numeric.__solveLP(f,s,h,i,t,l,!1),y=numeric.clone(p.solution);if(y.length=u,numeric.inf(c(e,a(n,y)))<0)return{solution:NaN,message:"Infeasible",iterations:p.iterations};var g=numeric.__solveLP(r,n,e,i,t-p.iterations,y,!0);return g.iterations+=p.iterations,g},numeric.solveLP=function(r,n,e,i,t,u,o){if(void 0===o&&(o=1e3),void 0===u&&(u=numeric.epsilon),void 0===i)return numeric._solveLP(r,n,e,u,o);var c,a=i.length,f=i[0].length,m=n.length,s=numeric.echelonize(i),h=numeric.rep([f],0),l=s.P,p=[];for(c=l.length-1;-1!==c;--c)h[l[c]]=1;for(c=f-1;-1!==c;--c)0===h[c]&&p.push(c);var y=numeric.getRange,g=numeric.linspace(0,a-1),v=numeric.linspace(0,m-1),d=y(i,g,p),x=y(n,v,l),b=y(n,v,p),w=numeric.dot,M=numeric.sub,k=w(x,s.I),A=M(b,w(k,d)),T=M(e,w(k,t)),j=Array(l.length),_=Array(p.length);for(c=l.length-1;-1!==c;--c)j[c]=r[l[c]];for(c=p.length-1;-1!==c;--c)_[c]=r[p[c]];var S=M(_,w(j,w(s.I,d))),q=numeric._solveLP(S,A,T,u,o),V=q.solution;if(V!=V)return q;var P=w(s.I,M(t,w(d,V))),F=Array(r.length);for(c=l.length-1;-1!==c;--c)F[l[c]]=P[c];for(c=p.length-1;-1!==c;--c)F[p[c]]=V[c];return{solution:F,message:q.message,iterations:q.iterations}},numeric.MPStoLP=function(r){r instanceof String&&r.split("\n");var n,e,i,t,u=0,o=["Initial state","NAME","ROWS","COLUMNS","RHS","BOUNDS","ENDATA"],c=r.length,a=0,f={},m=[],s=0,h={},l=0,p=[],y=[],g=[];function v(e){throw new Error("MPStoLP: "+e+"\nLine "+n+": "+r[n]+"\nCurrent state: "+o[u]+"\n")}for(n=0;n<c;++n){var d=(i=r[n]).match(/\S*/g),x=[];for(e=0;e<d.length;++e)""!==d[e]&&x.push(d[e]);if(0!==x.length){for(e=0;e<o.length&&i.substr(0,o[e].length)!==o[e];++e);if(e<o.length){if(u=e,1===e&&(t=x[1]),6===e)return{name:t,c:p,A:numeric.transpose(y),b:g,rows:f,vars:h}}else switch(u){case 0:case 1:v("Unexpected line");case 2:switch(x[0]){case"N":0===a?a=x[1]:v("Two or more N rows");break;case"L":f[x[1]]=s,m[s]=1,g[s]=0,++s;break;case"G":f[x[1]]=s,m[s]=-1,g[s]=0,++s;break;case"E":f[x[1]]=s,m[s]=0,g[s]=0,++s;break;default:v("Parse error "+numeric.prettyPrint(x))}break;case 3:h.hasOwnProperty(x[0])||(h[x[0]]=l,p[l]=0,y[l]=numeric.rep([s],0),++l);var b=h[x[0]];for(e=1;e<x.length;e+=2)if(x[e]!==a){var w=f[x[e]];y[b][w]=(m[w]<0?-1:1)*parseFloat(x[e+1])}else p[b]=parseFloat(x[e+1]);break;case 4:for(e=1;e<x.length;e+=2)g[f[x[e]]]=(m[f[x[e]]]<0?-1:1)*parseFloat(x[e+1]);break;case 5:break;case 6:v("Internal error")}}}v("Reached end of file without ENDATA")},numeric.seedrandom={pow:Math.pow,random:Math.random},function(r,n,e,i,t,u,o){function c(r){var n,i,t=this,u=r.length,o=0,c=t.i=t.j=t.m=0;for(t.S=[],t.c=[],u||(r=[u++]);o<e;)t.S[o]=o++;for(o=0;o<e;o++)c=m(c+(n=t.S[o])+r[o%u]),i=t.S[c],t.S[o]=i,t.S[c]=n;t.g=function(r){var n=t.S,i=m(t.i+1),u=n[i],o=m(t.j+u),c=n[o];n[i]=c,n[o]=u;for(var a=n[m(u+c)];--r;)i=m(i+1),c=n[o=m(o+(u=n[i]))],n[i]=c,n[o]=u,a=a*e+n[m(u+c)];return t.i=i,t.j=o,a},t.g(e)}function a(r,n,e,i,t){if(e=[],t=typeof r,n&&"object"==t)for(i in r)if(i.indexOf("S")<5)try{e.push(a(r[i],n-1))}catch(r){}return e.length?e:r+("string"!=t?"\0":"")}function f(r,n,e,i){for(r+="",e=0,i=0;i<r.length;i++)n[m(i)]=m((e^=19*n[m(i)])+r.charCodeAt(i));for(i in r="",n)r+=String.fromCharCode(n[i]);return r}function m(r){return r&e-1}n.seedrandom=function(i,m){var s,h=[];return i=f(a(m?[i,r]:arguments.length?i:[(new Date).getTime(),r,window],3),h),f((s=new c(h)).S,r),n.random=function(){for(var r=s.g(6),n=o,i=0;r<t;)r=(r+i)*e,n*=e,i=s.g(1);for(;r>=u;)r/=2,n/=2,i>>>=1;return(r+i)/n},i},o=n.pow(e,6),t=n.pow(2,t),u=2*t,f(n.random(),r)}([],numeric.seedrandom,256,0,52),function(r){function n(r){if("object"!=typeof r)return r;var e,i=[],t=r.length;for(e=0;e<t;e++)i[e+1]=n(r[e]);return i}function e(r){if("object"!=typeof r)return r;var n,i=[],t=r.length;for(n=1;n<t;n++)i[n-1]=e(r[n]);return i}r.solveQP=function(r,i,t,u,o,c){r=n(r),i=n(i),t=n(t);var a,f,m,s,h,l=[],p=[],y=[],g=[],v=[];if(o=o||0,c=c?n(c):[void 0,0],u=u?n(u):[],f=r.length-1,m=t[1].length-1,!u)for(a=1;a<=m;a+=1)u[a]=0;for(a=1;a<=m;a+=1)p[a]=0;for(s=Math.min(f,m),a=1;a<=f;a+=1)y[a]=0;for(l[1]=0,a=1;a<=2*f+s*(s+5)/2+2*m+1;a+=1)g[a]=0;for(a=1;a<=2;a+=1)v[a]=0;return function(r,n,e,i,t,u,o,c,a,f,m,s,h,l,p,y){var g,v,d,x,b,w,M,k,A,T,j,_,S,q,V,P,F,L,N,O,U,D,B,R,X,E,Y;S=Math.min(i,f),d=2*i+S*(S+5)/2+2*f+1,R=1e-60;do{X=1+.1*(R+=R),E=1+.2*R}while(X<=1||E<=1);for(g=1;g<=i;g+=1)p[g]=n[g];for(g=i+1;g<=d;g+=1)p[g]=0;for(g=1;g<=f;g+=1)s[g]=0;if(b=[],0===y[1]){if(function(r,n,e,i){var t,u,o,c,a,f;for(u=1;u<=e;u+=1){if(i[1]=u,f=0,(o=u-1)<1){if((f=r[u][u]-f)<=0)break;r[u][u]=Math.sqrt(f)}else{for(c=1;c<=o;c+=1){for(a=r[c][u],t=1;t<c;t+=1)a-=r[t][u]*r[t][c];a/=r[c][c],r[c][u]=a,f+=a*a}if((f=r[u][u]-f)<=0)break;r[u][u]=Math.sqrt(f)}i[1]=0}}(r,0,i,b),0!==b[1])return void(y[1]=2);!function(r,n,e,i){var t,u,o,c;for(u=1;u<=e;u+=1){for(c=0,t=1;t<u;t+=1)c+=r[t][u]*i[t];i[u]=(i[u]-c)/r[u][u]}for(o=1;o<=e;o+=1)for(i[u=e+1-o]=i[u]/r[u][u],c=-i[u],t=1;t<u;t+=1)i[t]=i[t]+c*r[t][u]}(r,0,i,n),function(r,n,e){var i,t,u,o,c;for(u=1;u<=e;u+=1){for(r[u][u]=1/r[u][u],c=-r[u][u],i=1;i<u;i+=1)r[i][u]=c*r[i][u];if(e<(o=u+1))break;for(t=o;t<=e;t+=1)for(c=r[u][t],r[u][t]=0,i=1;i<=u;i+=1)r[i][t]=r[i][t]+c*r[i][u]}}(r,0,i)}else{for(v=1;v<=i;v+=1)for(t[v]=0,g=1;g<=v;g+=1)t[v]=t[v]+r[g][v]*n[g];for(v=1;v<=i;v+=1)for(n[v]=0,g=v;g<=i;g+=1)n[v]=n[v]+r[v][g]*t[g]}for(u[1]=0,v=1;v<=i;v+=1)for(t[v]=n[v],u[1]=u[1]+p[v]*t[v],p[v]=0,g=v+1;g<=i;g+=1)r[g][v]=0;for(u[1]=-u[1]/2,y[1]=0,q=(T=(A=(j=(k=(M=i)+i)+S)+S+1)+S*(S+1)/2)+f,g=1;g<=f;g+=1){for(P=0,v=1;v<=i;v+=1)P+=o[v][g]*o[v][g];p[q+g]=Math.sqrt(P)}function I(){for(l[1]=l[1]+1,d=T,g=1;g<=f;g+=1){for(d+=1,P=-c[g],v=1;v<=i;v+=1)P+=o[v][g]*t[v];if(Math.abs(P)<R&&(P=0),g>m)p[d]=P;else if(p[d]=-Math.abs(P),P>0){for(v=1;v<=i;v+=1)o[v][g]=-o[v][g];c[g]=-c[g]}}for(g=1;g<=h;g+=1)p[T+s[g]]=0;for(_=0,V=0,g=1;g<=f;g+=1)p[T+g]<V*p[q+g]&&(_=g,V=p[T+g]/p[q+g]);return 0===_?999:0}function Q(){for(g=1;g<=i;g+=1){for(P=0,v=1;v<=i;v+=1)P+=r[v][g]*o[v][_];p[g]=P}for(x=M,g=1;g<=i;g+=1)p[x+g]=0;for(v=h+1;v<=i;v+=1)for(g=1;g<=i;g+=1)p[x+g]=p[x+g]+r[g][v]*p[v];for(D=!0,g=h;g>=1;g-=1){for(P=p[g],x=(d=A+g*(g+3)/2)-g,v=g+1;v<=h;v+=1)P-=p[d]*p[k+v],d+=v;if(P/=p[x],p[k+g]=P,s[g]<m)break;if(P<0)break;D=!1,w=g}if(!D)for(F=p[j+w]/p[k+w],g=1;g<=h&&!(s[g]<m)&&!(p[k+g]<0);g+=1)(V=p[j+g]/p[k+g])<F&&(F=V,w=g);for(P=0,g=M+1;g<=M+i;g+=1)P+=p[g]*p[g];if(Math.abs(P)<=R){if(D)return y[1]=1,999;for(g=1;g<=h;g+=1)p[j+g]=p[j+g]-F*p[k+g];return p[j+h+1]=p[j+h+1]+F,700}for(P=0,g=1;g<=i;g+=1)P+=p[M+g]*o[g][_];for(L=-p[T+_]/P,B=!0,D||F<L&&(L=F,B=!1),g=1;g<=i;g+=1)t[g]=t[g]+L*p[M+g],Math.abs(t[g])<R&&(t[g]=0);for(u[1]=u[1]+L*P*(L/2+p[j+h+1]),g=1;g<=h;g+=1)p[j+g]=p[j+g]-L*p[k+g];if(p[j+h+1]=p[j+h+1]+L,!B){for(P=-c[_],v=1;v<=i;v+=1)P+=t[v]*o[v][_];if(_>m)p[T+_]=P;else if(p[T+_]=-Math.abs(P),P>0){for(v=1;v<=i;v+=1)o[v][_]=-o[v][_];c[_]=-c[_]}return 700}for(s[h+=1]=_,d=A+(h-1)*h/2+1,g=1;g<=h-1;g+=1)p[d]=p[g],d+=1;if(h===i)p[d]=p[i];else{for(g=i;g>=h+1&&0!==p[g]&&(N=Math.max(Math.abs(p[g-1]),Math.abs(p[g])),O=Math.min(Math.abs(p[g-1]),Math.abs(p[g])),V=p[g-1]>=0?Math.abs(N*Math.sqrt(1+O*O/(N*N))):-Math.abs(N*Math.sqrt(1+O*O/(N*N))),N=p[g-1]/V,O=p[g]/V,1!==N);g-=1)if(0===N)for(p[g-1]=O*V,v=1;v<=i;v+=1)V=r[v][g-1],r[v][g-1]=r[v][g],r[v][g]=V;else for(p[g-1]=V,U=O/(1+N),v=1;v<=i;v+=1)V=N*r[v][g-1]+O*r[v][g],r[v][g]=U*(r[v][g-1]+V)-r[v][g],r[v][g-1]=V;p[d]=p[h]}return 0}function C(){if(0===p[x=(d=A+w*(w+1)/2+1)+w])return 798;if(N=Math.max(Math.abs(p[x-1]),Math.abs(p[x])),O=Math.min(Math.abs(p[x-1]),Math.abs(p[x])),V=p[x-1]>=0?Math.abs(N*Math.sqrt(1+O*O/(N*N))):-Math.abs(N*Math.sqrt(1+O*O/(N*N))),N=p[x-1]/V,O=p[x]/V,1===N)return 798;if(0===N){for(g=w+1;g<=h;g+=1)V=p[x-1],p[x-1]=p[x],p[x]=V,x+=g;for(g=1;g<=i;g+=1)V=r[g][w],r[g][w]=r[g][w+1],r[g][w+1]=V}else{for(U=O/(1+N),g=w+1;g<=h;g+=1)V=N*p[x-1]+O*p[x],p[x]=U*(p[x-1]+V)-p[x],p[x-1]=V,x+=g;for(g=1;g<=i;g+=1)V=N*r[g][w]+O*r[g][w+1],r[g][w+1]=U*(r[g][w]+V)-r[g][w+1],r[g][w]=V}return 0}function Z(){for(x=d-w,g=1;g<=w;g+=1)p[x]=p[d],d+=1,x+=1;return p[j+w]=p[j+w+1],s[w]=s[w+1],(w+=1)<h?797:0}function H(){return p[j+h]=p[j+h+1],p[j+h+1]=0,s[h]=0,h-=1,l[2]=l[2]+1,0}for(h=0,l[1]=0,l[2]=0,Y=0;;){if(999===(Y=I()))return;for(;0!==(Y=Q());){if(999===Y)return;if(700===Y)if(w===h)H();else{for(;C(),797===(Y=Z()););H()}}}}(r,i,0,f,y,l,t,u,0,m,o,p,0,v,g,c),h="",1===c[1]&&(h="constraints are inconsistent, no solution!"),2===c[1]&&(h="matrix D in quadratic function is not positive definite!"),{solution:e(y),value:e(l),unconstrained_solution:e(i),iterations:e(v),iact:e(p),message:h}}}(numeric),numeric.svd=function(r){var n,e=numeric.epsilon,i=1e-64/e,t=0,u=0,o=0,c=0,a=0,f=numeric.clone(r),m=f.length,s=f[0].length;if(m<s)throw"Need more rows than columns";var h=new Array(s),l=new Array(s);for(u=0;u<s;u++)h[u]=l[u]=0;var p=numeric.rep([s,s],0);function y(r,n){return(r=Math.abs(r))>(n=Math.abs(n))?r*Math.sqrt(1+n*n/r/r):0==n?r:n*Math.sqrt(1+r*r/n/n)}var g=0,v=0,d=0,x=0,b=0,w=0,M=0;for(u=0;u<s;u++){for(h[u]=v,M=0,a=u+1,o=u;o<m;o++)M+=f[o][u]*f[o][u];if(M<=i)v=0;else for(g=f[u][u],v=Math.sqrt(M),g>=0&&(v=-v),d=g*v-M,f[u][u]=g-v,o=a;o<s;o++){for(M=0,c=u;c<m;c++)M+=f[c][u]*f[c][o];for(g=M/d,c=u;c<m;c++)f[c][o]+=g*f[c][u]}for(l[u]=v,M=0,o=a;o<s;o++)M+=f[u][o]*f[u][o];if(M<=i)v=0;else{for(g=f[u][u+1],v=Math.sqrt(M),g>=0&&(v=-v),d=g*v-M,f[u][u+1]=g-v,o=a;o<s;o++)h[o]=f[u][o]/d;for(o=a;o<m;o++){for(M=0,c=a;c<s;c++)M+=f[o][c]*f[u][c];for(c=a;c<s;c++)f[o][c]+=M*h[c]}}(b=Math.abs(l[u])+Math.abs(h[u]))>x&&(x=b)}for(u=s-1;-1!=u;u+=-1){if(0!=v){for(d=v*f[u][u+1],o=a;o<s;o++)p[o][u]=f[u][o]/d;for(o=a;o<s;o++){for(M=0,c=a;c<s;c++)M+=f[u][c]*p[c][o];for(c=a;c<s;c++)p[c][o]+=M*p[c][u]}}for(o=a;o<s;o++)p[u][o]=0,p[o][u]=0;p[u][u]=1,v=h[u],a=u}for(u=s-1;-1!=u;u+=-1){for(a=u+1,v=l[u],o=a;o<s;o++)f[u][o]=0;if(0!=v){for(d=f[u][u]*v,o=a;o<s;o++){for(M=0,c=a;c<m;c++)M+=f[c][u]*f[c][o];for(g=M/d,c=u;c<m;c++)f[c][o]+=g*f[c][u]}for(o=u;o<m;o++)f[o][u]=f[o][u]/v}else for(o=u;o<m;o++)f[o][u]=0;f[u][u]+=1}for(e*=x,c=s-1;-1!=c;c+=-1)for(var k=0;k<50;k++){var A=!1;for(a=c;-1!=a;a+=-1){if(Math.abs(h[a])<=e){A=!0;break}if(Math.abs(l[a-1])<=e)break}if(!A){t=0,M=1;var T=a-1;for(u=a;u<c+1&&(g=M*h[u],h[u]=t*h[u],!(Math.abs(g)<=e));u++)for(d=y(g,v=l[u]),l[u]=d,t=v/d,M=-g/d,o=0;o<m;o++)b=f[o][T],w=f[o][u],f[o][T]=b*t+w*M,f[o][u]=-b*M+w*t}if(w=l[c],a==c){if(w<0)for(l[c]=-w,o=0;o<s;o++)p[o][c]=-p[o][c];break}if(k>=49)throw"Error: no convergence.";for(x=l[a],v=y(g=(((b=l[c-1])-w)*(b+w)+((v=h[c-1])-(d=h[c]))*(v+d))/(2*d*b),1),g=g<0?((x-w)*(x+w)+d*(b/(g-v)-d))/x:((x-w)*(x+w)+d*(b/(g+v)-d))/x,t=1,M=1,u=a+1;u<c+1;u++){for(v=h[u],b=l[u],d=M*v,v*=t,w=y(g,d),h[u-1]=w,g=x*(t=g/w)+v*(M=d/w),v=-x*M+v*t,d=b*M,b*=t,o=0;o<s;o++)x=p[o][u-1],w=p[o][u],p[o][u-1]=x*t+w*M,p[o][u]=-x*M+w*t;for(w=y(g,d),l[u-1]=w,g=(t=g/w)*v+(M=d/w)*b,x=-M*v+t*b,o=0;o<m;o++)b=f[o][u-1],w=f[o][u],f[o][u-1]=b*t+w*M,f[o][u]=-b*M+w*t}h[a]=0,h[c]=g,l[c]=x}for(u=0;u<l.length;u++)l[u]<e&&(l[u]=0);for(u=0;u<s;u++)for(o=u-1;o>=0;o--)if(l[o]<l[u]){for(t=l[o],l[o]=l[u],l[u]=t,c=0;c<f.length;c++)n=f[c][u],f[c][u]=f[c][o],f[c][o]=n;for(c=0;c<p.length;c++)n=p[c][u],p[c][u]=p[c][o],p[c][o]=n;u=o}return{U:f,S:l,V:p}}}}]);
@@ -0,0 +1 @@
1
+ !function(t,a){"object"==typeof exports&&"object"==typeof module?module.exports=a():"function"==typeof define&&define.amd?define("infra3dapi",[],a):"object"==typeof exports?exports.infra3dapi=a():t.infra3dapi=a()}(self,(()=>(()=>{"use strict";var t,a,s={35080:(t,a,s)=>{var o=s(17505),e=s.n(o);const i=self;class r{constructor(){this.data=[],this.approxval=null,this.thresh=1e-9,this.iterLimit=100,this.finalIterations=-1,this.convergence=!1,this.correction=[0,0,0],this.onprogress=null}calcApproxValue(){let t,a,s,o,i,r;const h=[],n=[];for(let p=0;p<this.data.length;p++){if(a=this.data[p],t=[a[0],a[1],a[2]],s=this.getRotMat(a[3]*Math.PI/180,a[4]*Math.PI/180,a[5]*Math.PI/180),o=[.001*a[6],.001*a[7],.001*-a[8]],i=e().add(t,e().dot(s,o)),1==a[10]){const o=.001*a[6]/(.001*-a[8]),r=.001*a[7]/(.001*-a[8]),h=Math.sqrt(o*o+r*r),n=o/h*Math.sin(h),p=r/h*Math.sin(h),c=Math.cos(h),d=e().mul(.001*-a[8],[n,p,c]);i=e().add(t,e().dot(s,d))}h.push(i),r=e().sub(i,t),n.push(r)}let p=0,c=[-1,-1];for(let t=0;t<n.length;t++)for(let a=0;a<n.length;a++){if(t==a)continue;const s=Math.acos(e().dot(n[t],n[a])/(e().norm2(n[t])*e().norm2(n[a])));s>p&&(c=[t,a],p=s)}const d=[this.data[c[0]][0],this.data[c[0]][1],this.data[c[0]][2]],l=[this.data[c[1]][0],this.data[c[1]][1],this.data[c[1]][2]],M=h[c[0]],u=h[c[1]],f=d[0],v=d[1],g=d[2],w=l[0],x=l[1],m=l[2];let b=e().norm2(e().sub(M,d));const y=(M[0]-d[0])/b,q=(M[1]-d[1])/b,P=(M[2]-d[2])/b;b=e().norm2(e().sub(u,l));const I=(u[0]-l[0])/b,O=(u[1]-l[1])/b,j=(u[2]-l[2])/b,k=e().det([[y,q],[I,O]]),L=e().det([[q,P],[O,j]]),_=e().det([[P,y],[j,I]]),E=e().det([[y,q,P],[I,O,j],[k,L,_]]),S=e().det([[f-w,v-x,g-m],[k,L,_],[I,O,j]])/E,z=e().det([[f-w,v-x,g-m],[k,L,_],[y,q,P]])/E,D=(f+S*y+(w+z*I))/2,A=(v+S*q+(x+z*O))/2,B=(g+S*P+(m+z*j))/2;return Math.acos(y*I+q*O+P*j),[D,A,B]}runBuendel(t){this.data=JSON.parse(t),null==this.approxval&&(this.approxval=this.calcApproxValue()),this.approxval=[this.approxval[0]-this.data[0][0],this.approxval[1]-this.data[0][1],this.approxval[2]-this.data[0][2]];let a=[0,0,0],s=[],o=[],i=[],r=this.approxval;for(var h=0;h<this.iterLimit;h++){s=[],o=[],i=[],r=e().add(r,[a[0],a[1],a[2]]);for(let t=0;t<this.data.length;t++){const a=[this.data[t][0]-this.data[0][0],this.data[t][1]-this.data[0][1],this.data[t][2]-this.data[0][2]],e=this.getRotMat(this.data[t][3]*Math.PI/180,this.data[t][4]*Math.PI/180,this.data[t][5]*Math.PI/180);let h,n;h=0==this.data[t][10]||2==this.data[t][10]||3==this.data[t][10]?this.coLinEquation(e,a,r,this.data[t][8]):this.coLinEquationPano(e,a,r,this.data[t][8]),i.push(this.data[t][6]-h[0]),i.push(this.data[t][7]-h[1]),n=0==this.data[t][10]||2==this.data[t][10]||3==this.data[t][10]?this.getDeriatives(e,a,r,this.data[t][8]):this.getDeriativesPano(e,a,r,this.data[t][8]),s.push([n[0],n[1],n[2]]),s.push([n[3],n[4],n[5]]),o.push(this.data[t][9]),o.push(this.data[t][9])}const t=e().diag(o),h=e().dot(e().transpose(s),t),p=e().dot(h,s);var n=e().inv(p);a=e().dot(e().dot(n,h),i);const c=e().norm2(a),d={topic:"correction_update",value:c};if(null!==this.onprogress&&this.onprogress(d),c<this.thresh)break}if(h>=this.iterLimit)return this.convergence=!1,null;const p=e().sub(e().dot(s,a),i),c=Math.sqrt(e().dot(p,p)/(2*this.data.length-a.length)),d=[c*Math.sqrt(n[0][0]),c*Math.sqrt(n[1][1]),c*Math.sqrt(n[2][2])];return this.convergence=!0,this.finalIterations=h,this.correction=r,this.m0=c,this.s_xyz=d,this.residuals=p,[r[0]+this.data[0][0],r[1]+this.data[0][1],r[2]+this.data[0][2]]}getRotMat(t,a,s){return[[Math.cos(a)*Math.cos(s),-Math.cos(a)*Math.sin(s),Math.sin(a)],[Math.cos(t)*Math.sin(s)+Math.sin(t)*Math.sin(a)*Math.cos(s),Math.cos(t)*Math.cos(s)-Math.sin(t)*Math.sin(a)*Math.sin(s),-Math.sin(t)*Math.cos(a)],[Math.sin(t)*Math.sin(s)-Math.cos(t)*Math.sin(a)*Math.cos(s),Math.sin(t)*Math.cos(s)+Math.cos(t)*Math.sin(a)*Math.sin(s),Math.cos(t)*Math.cos(a)]]}getDeriatives(t,a,s,o){const e=-o,i=t[0][0]*(s[0]-a[0])+t[1][0]*(s[1]-a[1])+t[2][0]*(s[2]-a[2]),r=t[0][1]*(s[0]-a[0])+t[1][1]*(s[1]-a[1])+t[2][1]*(s[2]-a[2]),h=t[0][2]*(s[0]-a[0])+t[1][2]*(s[1]-a[1])+t[2][2]*(s[2]-a[2]);return[-e/Math.pow(h,2)*(t[0][2]*i-t[0][0]*h),-e/Math.pow(h,2)*(t[1][2]*i-t[1][0]*h),-e/Math.pow(h,2)*(t[2][2]*i-t[2][0]*h),-e/Math.pow(h,2)*(t[0][2]*r-t[0][1]*h),-e/Math.pow(h,2)*(t[1][2]*r-t[1][1]*h),-e/Math.pow(h,2)*(t[2][2]*r-t[2][1]*h)]}getDeriativesPano(t,a,s,o){const e=t[0][0]*(s[0]-a[0])+t[1][0]*(s[1]-a[1])+t[2][0]*(s[2]-a[2]),i=t[0][1]*(s[0]-a[0])+t[1][1]*(s[1]-a[1])+t[2][1]*(s[2]-a[2]),r=t[0][2]*(s[0]-a[0])+t[1][2]*(s[1]-a[1])+t[2][2]*(s[2]-a[2]);Math.pow(r,2),t[0][2],t[0][0],Math.pow(r,2),t[1][2],t[1][0],Math.pow(r,2),t[2][2],t[2][0],Math.pow(r,2),t[0][2],t[0][1],Math.pow(r,2),t[1][2],t[1][1],Math.pow(r,2),t[2][2],t[2][1];let h=t[0][0],n=t[0][1],p=t[0][2],c=e,d=i,l=r,M=r*r,u=o,f=Math.pow(c,2)+Math.pow(d,2),v=Math.sqrt(f),g=Math.atan(Math.sqrt(f)/l),w=c*h+d*n;const x=-u*g*h/v-u*(-v*p/M+w/(v*l))*c/(v*(f/M+1))+u*g*w*c/Math.pow(f,1.5),m=-u*g*n/v-u*(-v*p/M+w/(v*l))*d/(v*(f/M+1))+u*g*w*d/Math.pow(f,1.5);h=t[1][0],n=t[1][1],p=t[1][2],c=e,d=i,l=r,M=r*r,u=o,f=Math.pow(c,2)+Math.pow(d,2),v=Math.sqrt(f),g=Math.atan(Math.sqrt(f)/l),w=c*h+d*n;const b=-u*g*h/v-u*(-v*p/M+w/(v*l))*c/(v*(f/M+1))+u*g*w*c/Math.pow(f,1.5),y=-u*g*n/v-u*(-v*p/M+w/(v*l))*d/(v*(f/M+1))+u*g*w*d/Math.pow(f,1.5);return h=t[2][0],n=t[2][1],p=t[2][2],c=e,d=i,l=r,M=r*r,u=o,f=Math.pow(c,2)+Math.pow(d,2),v=Math.sqrt(f),g=Math.atan(Math.sqrt(f)/l),w=c*h+d*n,[x,b,-u*g*h/v-u*(-v*p/M+w/(v*l))*c/(v*(f/M+1))+u*g*w*c/Math.pow(f,1.5),m,y,-u*g*n/v-u*(-v*p/M+w/(v*l))*d/(v*(f/M+1))+u*g*w*d/Math.pow(f,1.5)]}coLinEquation(t,a,s,o){const e=t[0][0]*(s[0]-a[0])+t[1][0]*(s[1]-a[1])+t[2][0]*(s[2]-a[2]),i=t[0][1]*(s[0]-a[0])+t[1][1]*(s[1]-a[1])+t[2][1]*(s[2]-a[2]),r=t[0][2]*(s[0]-a[0])+t[1][2]*(s[1]-a[1])+t[2][2]*(s[2]-a[2]);return[-o*e/r,-o*i/r]}coLinEquationPano(t,a,s,o){const e=t[0][0]*(s[0]-a[0])+t[1][0]*(s[1]-a[1])+t[2][0]*(s[2]-a[2]),i=t[0][1]*(s[0]-a[0])+t[1][1]*(s[1]-a[1])+t[2][1]*(s[2]-a[2]),r=t[0][2]*(s[0]-a[0])+t[1][2]*(s[1]-a[1])+t[2][2]*(s[2]-a[2]),h=Math.sqrt(e*e+i*i);return[-o*e/h*Math.atan(h/r),-o*i/h*Math.atan(h/r)]}}i.onmessage=t=>{if(t.data.topic&&"run"===t.data.topic){const a=new r;if(a.onprogress=t=>{i.postMessage(t)},t.data.approxval?a.approxval=t.data.approxval:a.approxval=null,t.data.observations){let s={};try{s={topic:"result",result:a.runBuendel(t.data.observations),convergence:a.convergence,finalIterations:a.finalIterations,correction:a.correction,m0:a.m0,s_xyz:a.s_xyz,residuals:a.residuals}}catch(t){console.log(t),s={topic:"result",result:[0,0,0],convergence:!1,finalIterations:-1,correction:[0,0,0],m0:1/0,s_xyz:[1/0,1/0,1/0],residuals:[]}}i.postMessage(s)}}}}},o={};function e(t){var a=o[t];if(void 0!==a)return a.exports;var i=o[t]={exports:{}};return s[t](i,i.exports,e),i.exports}return e.m=s,e.x=()=>{var t=e.O(void 0,[505],(()=>e(35080)));return e.O(t)},t=[],e.O=(a,s,o,i)=>{if(!s){var r=1/0;for(c=0;c<t.length;c++){s=t[c][0],o=t[c][1],i=t[c][2];for(var h=!0,n=0;n<s.length;n++)(!1&i||r>=i)&&Object.keys(e.O).every((t=>e.O[t](s[n])))?s.splice(n--,1):(h=!1,i<r&&(r=i));if(h){t.splice(c--,1);var p=o();void 0!==p&&(a=p)}}return a}i=i||0;for(var c=t.length;c>0&&t[c-1][2]>i;c--)t[c]=t[c-1];t[c]=[s,o,i]},e.n=t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},e.d=(t,a)=>{for(var s in a)e.o(a,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:a[s]})},e.f={},e.e=t=>Promise.all(Object.keys(e.f).reduce(((a,s)=>(e.f[s](t,a),a)),[])),e.u=t=>t+".infra3dapi.js",e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),e.o=(t,a)=>Object.prototype.hasOwnProperty.call(t,a),(()=>{var t;e.g.importScripts&&(t=e.g.location+"");var a=e.g.document;if(!t&&a&&(a.currentScript&&(t=a.currentScript.src),!t)){var s=a.getElementsByTagName("script");if(s.length)for(var o=s.length-1;o>-1&&(!t||!/^http(s?):/.test(t));)t=s[o--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=t})(),(()=>{var t={80:1};e.f.i=(a,s)=>{t[a]||importScripts(e.p+e.u(a))};var a=self.webpackChunkinfra3dapi=self.webpackChunkinfra3dapi||[],s=a.push.bind(a);a.push=a=>{var o=a[0],i=a[1],r=a[2];for(var h in i)e.o(i,h)&&(e.m[h]=i[h]);for(r&&r(e);o.length;)t[o.pop()]=1;s(a)}})(),a=e.x,e.x=()=>e.e(505).then(a),e.x()})()));
package/README.md CHANGED
@@ -1,28 +1,66 @@
1
1
  # Installation
2
+
2
3
  ### NPM Package
4
+
3
5
  The API can be installed as a package using npm. To install it from the npm package repository, simply type:
6
+
4
7
  ```bash
5
8
  npm install @inovitas/infra3dapi
6
9
  ```
7
10
 
8
11
  ### CDN Download
12
+
9
13
  Alternatively, you can obtain the API from a CDN. To get the latest version, add the following script to your HTML file:
14
+
10
15
  ```html
11
16
  <script src="https://cdn.jsdelivr.net/npm/@inovitas/infra3dapi@latest/infra3dapi.js"></script>
12
17
  ```
18
+
13
19
  We recommend using a specific version in your project. To get a specific version, use the following script and adjust the version accordingly:
20
+
14
21
  ```html
15
- <script src="https://cdn.jsdelivr.net/npm/@inovitas/infra3dapi@0.1.0/infra3dapi.js"></script>
22
+ <script src="https://cdn.jsdelivr.net/npm/@inovitas/infra3dapi@1.0.0/infra3dapi.js"></script>
16
23
  ```
17
- **Note**: Please do not name the `<div>` in which the viewer is initialized as "infra3d" as this may cause internal conflicts.
18
24
 
25
+ **Note**: Please do not name the `<div>` in which the viewer is initialized as "infra3d" as this may cause internal conflicts.
19
26
 
20
27
  # Core Concept
28
+
21
29
  To use the API, you can call the init functions in infra3dapi. After loggin in and initializing the view (with [`manager.initView()`](classes/_inovitas_infra3dapi.manager.Manager.html#initView)), you will get a viewer object. This viewer object can then be used to add event-listeners to different events emitted by the viewer (like [`viewer.geoframechanged`](classes/_inovitas_infra3dsdk.Viewer.html#geoframechanged)) or to call some functions (like [`viewer.getRoutes()`](classes/_inovitas_infra3dsdk.Viewer.html#getRoutes) or [`viewer.movePosition()`](classes/_inovitas_infra3dsdk.Viewer.html#movePosition)).
22
30
 
31
+ # Authentication
32
+
33
+ 1. Register your OAuth 2.0 application with our sales team to obtain credentials (client_id and client_secret).
34
+ 2. Develop a server-side component to securely use these credentials, obtaining an access token from infra3D.
35
+ 3. Your server-side component fetches the access token using client credentials, which can then be shared with your client app.
36
+ 4. Your client app uses this token to authenticate with infra3D for requested services, refreshing it via the server component when expired. Remember to treat the client_secret like a password, avoiding exposure in client-side environments for enhanced security.
23
37
 
24
38
  # Changelog
25
39
 
40
+ ## 1.0.0 - 17.05.2024
41
+
42
+ ### Bugfixes
43
+
44
+ - Restoration of toolbar and top bar functionality: They can now be shown and hidden smoothly.
45
+
46
+ ### Added
47
+
48
+ - Introduction of machine authentication and a new corresponding example.
49
+ - Added: Option for access token in the init function.
50
+ - Added: Refresh token for the init function.
51
+ - Typings
52
+
53
+ ### Changed
54
+
55
+ - Examples have been updated to accommodate the new authentication process.
56
+
57
+ ### Deleted
58
+
59
+ - Interactive login functions.
60
+ - Removed: Two options from the init function:
61
+ - demoAccess
62
+ - redirectPath
63
+
26
64
  ## 0.2.8 - 08.04.2024
27
65
 
28
66
  ### Added
@@ -0,0 +1,153 @@
1
+ declare module "@inovitas/infra3dapi";
2
+
3
+ declare type Fn = (arg: any) => void;
4
+ declare class EventEmitter {
5
+ protected _events: {
6
+ [eventType: string]: Fn[];
7
+ };
8
+ constructor();
9
+ on(eventType: string, fn: Fn): void;
10
+ off(eventType: string, fn: Fn): void;
11
+ fire(eventType: string, data: unknown): void;
12
+ private _listens;
13
+ }
14
+
15
+ declare type ViewerEventType = "nodechanged" | "panorotationchanged" | "campaignschanged" | "lookazimuthchanged";
16
+
17
+ interface IViewer {
18
+ fire<T>(type: ViewerEventType, event: T): void;
19
+ off<T>(type: ViewerEventType, handler: (event: T) => void): void;
20
+ on<T>(type: ViewerEventType, handler: (event: T) => void): void;
21
+ }
22
+
23
+ interface ViewerEvent {
24
+ target: IViewer;
25
+ type: ViewerEventType;
26
+ }
27
+
28
+ interface NodechangedEvent extends ViewerEvent {
29
+ lat: number;
30
+ lon: number;
31
+ height: number;
32
+ campaign_id: string;
33
+ date: string;
34
+ type: "nodechanged";
35
+ }
36
+
37
+ interface CampaignschangedEvent extends ViewerEvent {
38
+ id: number;
39
+
40
+ project: number;
41
+
42
+ description: string;
43
+
44
+ type: "campaignschanged";
45
+ }
46
+
47
+ interface PanorotationchangedEvent extends ViewerEvent {
48
+ fov: number;
49
+
50
+ lat: number;
51
+
52
+ lon: number;
53
+
54
+ type: "panorotationchanged";
55
+ }
56
+
57
+ interface LookazimuthchangedEvent extends ViewerEvent {
58
+ value: number;
59
+
60
+ type: "lookazimuthchanged";
61
+ }
62
+
63
+ declare class InternalViewer {}
64
+ declare class GeoJSON {}
65
+ declare class ApmBase {}
66
+
67
+ declare class Viewer extends EventEmitter implements IViewer {
68
+ private _sdk_viewer;
69
+ constructor(sdk_viewer: InternalViewer);
70
+ moveToCampaign(campaignID: string): Promise<void>;
71
+ moveToPosition(easting: number, northing: number, height?: number, maxdist?: number, epsg?: number): Promise<void>;
72
+ lookAtPosition(easting: number, northing: number, height?: number, maxdist?: number, epsg?: number): Promise<void>;
73
+ getRoutes(simplify?: number): Promise<GeoJSON>;
74
+ attachToMeasurementTool(toolname: "lengthMeasure" | "areaMeasure", onmeasured: (value: number, geometry: number[][]) => void): void;
75
+ attachToMeasurementTool(toolname: "pointMeasure", onmeasured: (value: undefined, geometry: number[]) => void): void;
76
+ private _processMeasurementResult;
77
+ off(type: "nodechanged", handler: (event: NodechangedEvent) => void): void;
78
+ off(type: "campaignschanged", handler: (event: CampaignschangedEvent) => void): void;
79
+ off(type: "panorotationchanged", handler: (event: PanorotationchangedEvent) => void): void;
80
+ off(type: "lookazimuthchanged", handler: (event: LookazimuthchangedEvent) => void): void;
81
+ on(type: "nodechanged", handler: (event: NodechangedEvent) => void): void;
82
+ on(type: "campaignschanged", handler: (event: CampaignschangedEvent) => void): void;
83
+ on(type: "panorotationchanged", handler: (event: PanorotationchangedEvent) => void): void;
84
+ on(type: "lookazimuthchanged", handler: (event: LookazimuthchangedEvent) => void): void;
85
+ }
86
+
87
+ declare type applicationProps = {
88
+ name: string;
89
+ url: string;
90
+ };
91
+ declare type cardProps = {
92
+ uid: string;
93
+ name: string;
94
+ description: string;
95
+ applications: applicationProps[];
96
+ created_by: string;
97
+ creation_date: string | Date;
98
+ tags: Array<{
99
+ name: string;
100
+ font_color: string;
101
+ background_color: string;
102
+ }>;
103
+ };
104
+
105
+ declare class Manager extends EventEmitter {
106
+ static viewinitialized: string;
107
+ static viewerset: string;
108
+ static tokenset: string;
109
+ private _apm;
110
+ private _tokens;
111
+ constructor(apm: ApmBase);
112
+ initViewer(options: {
113
+ project_uid: string;
114
+ start_position?: {
115
+ easting: number;
116
+ northing: number;
117
+ };
118
+ start_campaign?: {
119
+ id: string;
120
+ };
121
+ map_expand?: boolean;
122
+ show_cockpit?: boolean;
123
+ show_mapWindow?: boolean;
124
+ show_toolbar?: boolean;
125
+ toolbar?: string;
126
+ show_topbar?: boolean;
127
+ }): Promise<Viewer>;
128
+ getProjects(): Promise<cardProps[]>;
129
+ setViewer(viewer: InternalViewer): void;
130
+ setTokens(tokens: any): void;
131
+ setApmUserContext(userContext?: {
132
+ id?: string;
133
+ username?: string;
134
+ email?: string;
135
+ }): void;
136
+ }
137
+
138
+ declare type accessTokenResponseType = {
139
+ access_token: string;
140
+ expires_in: number;
141
+ token_type: "Bearer";
142
+ };
143
+
144
+ export declare function getAccessToken(url: string, client_id: string, client_secret: string): Promise<accessTokenResponseType>;
145
+
146
+ export declare function init(rootId: string, token: string, userContext?: {
147
+ id?: string;
148
+ username?: string;
149
+ email?: string;
150
+ }): Promise<Manager>;
151
+ export declare function getManager(): Manager;
152
+ export declare function getGuestAccessToken(): Promise<accessTokenResponseType>;
153
+ export declare function refreshToken(token: string): void;