-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmarchingsquares.min.js
9 lines (9 loc) · 32.7 KB
/
marchingsquares.min.js
1
2
3
4
5
6
7
8
9
/*!
* MarchingSquaresJS
* version 1.3.1
* https://github.com/RaumZeit/MarchingSquares.js
*
* @license GNU Affero General Public License.
* Copyright (c) 2015-2018 Ronny Lorenz <[email protected]>
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.MarchingSquaresJS=e.MarchingSquaresJS||{})}(this,function(e){"use strict";function l(e,t,n){return e<t?(n-e)/(t-e):(e-n)/(e-t)}function i(e,t,n,o){var r;return o<n&&(r=n,n=o,o=r),e<t?e<n?(n-e)/(t-e):(o-e)/(t-e):o<e?(e-o)/(e-t):(e-n)/(e-t)}function s(e,t,n,o){return e<t?(n-e)/(t-e):(e-o)/(e-t)}function p(e,t,n,o){return e<t?(o-e)/(t-e):(e-n)/(e-t)}function g(){this.successCallback=null,this.verbose=!1,this.polygons=!1,this.polygons_full=!1,this.linearRing=!0,this.noQuadTree=!1}function L(e,t,n,o){var r=[];return e.polygons.forEach(function(e){e.forEach(function(e){e[0]+=t,e[1]+=n}),o.linearRing&&e.push(e[0]),r.push(e)}),r}function W(e,t,n,o){return 0===n?(e+=1,t+=o[0][1]):1===n?e+=o[0][0]:2===n?t+=o[0][1]:3===n&&(e+=o[0][0],t+=1),[e,t]}function O(e,t,n){return 0===n?e++:1===n||(2===n?t++:3===n&&(e++,t++)),[e,t]}function h(e,t,n,o,r){var a=o,l=r,i=0,s=0;if(this.x=t,this.y=n,this.lowerBound=null,this.upperBound=null,this.childA=null,this.childB=null,this.childC=null,this.childD=null,1===o&&1===r)this.lowerBound=Math.min(e[n][t],e[n][t+1],e[n+1][t+1],e[n+1][t]),this.upperBound=Math.max(e[n][t],e[n][t+1],e[n+1][t+1],e[n+1][t]);else{if(1<o){for(;0!==a;)a>>=1,i++;o===1<<i-1&&i--,a=1<<i-1}if(1<r){for(;0!==l;)l>>=1,s++;r===1<<s-1&&s--,l=1<<s-1}this.childA=new h(e,t,n,a,l),this.lowerBound=this.childA.lowerBound,this.upperBound=this.childA.upperBound,0<o-a&&(this.childB=new h(e,t+a,n,o-a,l),this.lowerBound=Math.min(this.lowerBound,this.childB.lowerBound),this.upperBound=Math.max(this.upperBound,this.childB.upperBound),0<r-l&&(this.childC=new h(e,t+a,n+l,o-a,r-l),this.lowerBound=Math.min(this.lowerBound,this.childC.lowerBound),this.upperBound=Math.max(this.upperBound,this.childC.upperBound))),0<r-l&&(this.childD=new h(e,t,n+l,a,r-l),this.lowerBound=Math.min(this.lowerBound,this.childD.lowerBound),this.upperBound=Math.max(this.upperBound,this.childD.upperBound))}}function a(e){var t,n;if(!e)throw new Error("data is required");if(!Array.isArray(e)||!Array.isArray(e[0]))throw new Error("data must be scalar field, i.e. array of arrays");if(e.length<2)throw new Error("data must contain at least two rows");if((n=e[0].length)<2)throw new Error("data must contain at least two columns");for(t=1;t<e.length;t++){if(!Array.isArray(e[t]))throw new Error("Row "+t+" is not an array");if(e[t].length!=n)throw new Error("unequal row lengths detected, please provide a regular grid")}this.data=e,this.root=new h(e,0,0,e[0].length-1,e.length-1)}function t(e,t,n){var A,o,N,q=!1,S=!1,r=null,M=null,T=null,j=null,C=null,D=[];if(!e)throw new Error("data is required");if(null==t)throw new Error("threshold is required");if(n&&"object"!=typeof n)throw new Error("options must be an object");if(A=function(e){var t,n,o,r,a;for(r=new g,e=e||{},a=Object.keys(r),t=0;t<a.length;t++)null!=(o=e[n=a[t]])&&(r[n]=o);return r.polygons_full=!r.polygons,r.interpolate=l,r}(n),e instanceof a)M=(r=e).root,T=e.data,A.noQuadTree||(q=!0);else{if(!Array.isArray(e)||!Array.isArray(e[0]))throw new Error("input is neither array of arrays nor object retrieved from 'QuadTree()'");T=e}if(Array.isArray(t)){for(S=!0,A.noQuadTree||(q=!0),o=0;o<t.length;o++)if(isNaN(+t[o]))throw new Error("threshold["+o+"] is not a number")}else{if(isNaN(+t))throw new Error("threshold must be a number or array of numbers");t=[t]}return q&&!M&&(r=new a(T),M=r.root,T=r.data),A.verbose&&(A.polygons?console.log("MarchingSquaresJS-isoLines: returning single lines (polygons) for each grid cell"):console.log("MarchingSquaresJS-isoLines: returning line paths (polygons) for entire data grid"),S&&console.log("MarchingSquaresJS-isoLines: multiple lines requested, returning array of line paths instead of lines for a single threshold")),t.forEach(function(e,t){if(C=[],A.threshold=e,A.verbose&&console.log("MarchingSquaresJS-isoLines: computing iso lines for threshold "+e),A.polygons)if(q)M.cellsBelowThreshold(A.threshold,!0).forEach(function(e){C=C.concat(L(J(T,e.x,e.y,A),e.x,e.y,A))});else for(N=0;N<T.length-1;++N)for(t=0;t<T[0].length-1;++t)C=C.concat(L(J(T,t,N,A),t,N,A));else{for(j=[],t=0;t<T[0].length-1;++t)j[t]=[];if(q)M.cellsBelowThreshold(A.threshold,!1).forEach(function(e){j[e.x][e.y]=J(T,e.x,e.y,A)});else for(t=0;t<T[0].length-1;++t)for(N=0;N<T.length-1;++N)j[t][N]=J(T,t,N,A);o=j,r=A,V=[],x=(n=T).length-1,v=n[0].length-1,k=["right","bottom","left","top"],w=[0,-1,0,1],B=[-1,0,1,0],E={bottom:1,left:2,top:3,right:0},function(e,t){var n,o,r,a,l;for(n=!0,o=e[0].length,r=e.length,l=0;l<r;l++)if(e[l][0]>=t||e[l][o-1]>=t){n=!1;break}if(n&&(e[r-1][0]>=t||e[r-1][o-1]>=t)&&(n=!1),n)for(a=0;a<o-1;a++)if(e[0][a]>=t||e[r-1][a]>t){n=!1;break}return n}(n,r.minV,r.maxV)&&(r.linearRing?V.push([[0,0],[0,x],[v,x],[v,0],[0,0]]):V.push([[0,0],[0,x],[v,x],[v,0]])),o.forEach(function(e,n){e.forEach(function(e,t){for(a=null,l=0;l<4;l++)if(a=k[l],"object"==typeof e.edges[a]){for(p=[],i=e.edges[a],g=a,m=t,u=!1,b=[(h=n)+i.path[0][0],t+i.path[0][1]],p.push(b);!u&&"object"==typeof(s=o[h][m]).edges[g];)if(i=s.edges[g],delete s.edges[g],(c=i.path[1])[0]+=h,c[1]+=m,p.push(c),g=i.move.enter,h+=i.move.x,m+=i.move.y,void 0===o[h]||void 0===o[h][m]){if(!r.linearRing)break;if(_=y=0,h===v?(h--,y=0):h<0?(h++,y=2):m===x?(m--,y=3):m<0&&(m++,y=1),h===n&&m===t&&y===E[a]){u=!0,g=a;break}for(;;){if(d=!1,4<_)throw new Error("Direction change counter overflow! This should never happen!");if(void 0!==o[h]&&void 0!==o[h][m]&&(s=o[h][m],f=k[y],"object"==typeof s.edges[f])){i=s.edges[f],p.push(W(h,m,y,i.path)),g=f,d=!0;break}if(d)break;if(p.push(O(h,m,y)),m+=B[y],void 0!==o[h+=w[y]]&&void 0!==o[h][m]||(0===y&&m<0||1===y&&h<0||2===y&&m===x||3===y&&h===v)&&(h-=w[y],m-=B[y],y=(y+1)%4,_++),h===n&&m===t&&y===E[a]){u=!0,g=a;break}}}!r.linearRing||p[p.length-1][0]===b[0]&&p[p.length-1][1]===b[1]||p.push(b),V.push(p)}})}),C=V}var n,o,r,a,l,i,s,p,g,h,m,u,b,c,y,_,d,f,V,x,v,k,w,B,E;S?D.push(C):D=C,"function"==typeof A.successCallback&&A.successCallback(D,e)}),D}function J(e,t,n,o){var r,a,l,i,s,p,g=0,h=e[n+1][t],m=e[n+1][t+1],u=e[n][t+1],b=e[n][t],c=o.threshold;if(!(isNaN(b)||isNaN(u)||isNaN(m)||isNaN(h))){switch(g|=c<=h?8:0,g|=c<=m?4:0,g|=c<=u?2:0,p={cval:g=+(g|=c<=b?1:0),polygons:[],edges:{},x0:b,x1:u,x2:m,x3:h},g){case 0:o.polygons&&p.polygons.push([[0,0],[0,1],[1,1],[1,0]]);break;case 15:break;case 14:r=o.interpolate(b,h,c),i=o.interpolate(b,u,c),o.polygons_full&&(p.edges.left={path:[[0,r],[i,0]],move:{x:0,y:-1,enter:"top"}}),o.polygons&&p.polygons.push([[0,0],[0,r],[i,0]]);break;case 13:i=o.interpolate(b,u,c),a=o.interpolate(u,m,c),o.polygons_full&&(p.edges.bottom={path:[[i,0],[1,a]],move:{x:1,y:0,enter:"left"}}),o.polygons&&p.polygons.push([[i,0],[1,a],[1,0]]);break;case 11:a=o.interpolate(u,m,c),l=o.interpolate(h,m,c),o.polygons_full&&(p.edges.right={path:[[1,a],[l,1]],move:{x:0,y:1,enter:"bottom"}}),o.polygons&&p.polygons.push([[1,a],[l,1],[1,1]]);break;case 7:r=o.interpolate(b,h,c),l=o.interpolate(h,m,c),o.polygons_full&&(p.edges.top={path:[[l,1],[0,r]],move:{x:-1,y:0,enter:"right"}}),o.polygons&&p.polygons.push([[l,1],[0,r],[0,1]]);break;case 1:r=o.interpolate(b,h,c),i=o.interpolate(b,u,c),o.polygons_full&&(p.edges.bottom={path:[[i,0],[0,r]],move:{x:-1,y:0,enter:"right"}}),o.polygons&&p.polygons.push([[i,0],[0,r],[0,1],[1,1],[1,0]]);break;case 2:i=o.interpolate(b,u,c),a=o.interpolate(u,m,c),o.polygons_full&&(p.edges.right={path:[[1,a],[i,0]],move:{x:0,y:-1,enter:"top"}}),o.polygons&&p.polygons.push([[0,0],[0,1],[1,1],[1,a],[i,0]]);break;case 4:a=o.interpolate(u,m,c),l=o.interpolate(h,m,c),o.polygons_full&&(p.edges.top={path:[[l,1],[1,a]],move:{x:1,y:0,enter:"left"}}),o.polygons&&p.polygons.push([[0,0],[0,1],[l,1],[1,a],[1,0]]);break;case 8:r=o.interpolate(b,h,c),l=o.interpolate(h,m,c),o.polygons_full&&(p.edges.left={path:[[0,r],[l,1]],move:{x:0,y:1,enter:"bottom"}}),o.polygons&&p.polygons.push([[0,0],[0,r],[l,1],[1,1],[1,0]]);break;case 12:r=o.interpolate(b,h,c),a=o.interpolate(u,m,c),o.polygons_full&&(p.edges.left={path:[[0,r],[1,a]],move:{x:1,y:0,enter:"left"}}),o.polygons&&p.polygons.push([[0,0],[0,r],[1,a],[1,0]]);break;case 9:i=o.interpolate(b,u,c),l=o.interpolate(h,m,c),o.polygons_full&&(p.edges.bottom={path:[[i,0],[l,1]],move:{x:0,y:1,enter:"bottom"}}),o.polygons&&p.polygons.push([[i,0],[l,1],[1,1],[1,0]]);break;case 3:r=o.interpolate(b,h,c),a=o.interpolate(u,m,c),o.polygons_full&&(p.edges.right={path:[[1,a],[0,r]],move:{x:-1,y:0,enter:"right"}}),o.polygons&&p.polygons.push([[0,r],[0,1],[1,1],[1,a]]);break;case 6:i=o.interpolate(b,u,c),l=o.interpolate(h,m,c),o.polygons_full&&(p.edges.top={path:[[l,1],[i,0]],move:{x:0,y:-1,enter:"top"}}),o.polygons&&p.polygons.push([[0,0],[0,1],[l,1],[i,0]]);break;case 10:r=o.interpolate(b,h,c),a=o.interpolate(u,m,c),i=o.interpolate(b,u,c),l=o.interpolate(h,m,c),s=(b+u+m+h)/4,o.polygons_full&&(s<c?(p.edges.left={path:[[0,r],[l,1]],move:{x:0,y:1,enter:"bottom"}},p.edges.right={path:[[1,a],[i,0]],move:{x:0,y:-1,enter:"top"}}):(p.edges.right={path:[[1,a],[l,1]],move:{x:0,y:1,enter:"bottom"}},p.edges.left={path:[[0,r],[i,0]],move:{x:0,y:-1,enter:"top"}})),o.polygons&&(s<c?p.polygons.push([[0,0],[0,r],[l,1],[1,1],[1,a],[i,0]]):(p.polygons.push([[0,0],[0,r],[i,0]]),p.polygons.push([[l,1],[1,1],[1,a]])));break;case 5:r=o.interpolate(b,h,c),a=o.interpolate(u,m,c),i=o.interpolate(b,u,c),l=o.interpolate(h,m,c),s=(b+u+m+h)/4,o.polygons_full&&(s<c?(p.edges.bottom={path:[[i,0],[0,r]],move:{x:-1,y:0,enter:"right"}},p.edges.top={path:[[l,1],[1,a]],move:{x:1,y:0,enter:"left"}}):(p.edges.top={path:[[l,1],[0,r]],move:{x:-1,y:0,enter:"right"}},p.edges.bottom={path:[[i,0],[1,a]],move:{x:1,y:0,enter:"left"}})),o.polygons&&(s<c?p.polygons.push([[0,r],[0,1],[l,1],[1,a],[1,0],[i,0]]):(p.polygons.push([[0,r],[0,1],[l,1]]),p.polygons.push([[i,0],[1,a],[1,0]])))}return p}}h.prototype.cellsInBand=function(e,t,n){var o=[];return n=void 0===n||n,this.lowerBound>t||this.upperBound<e||(this.childA||this.childB||this.childC||this.childD?(this.childA&&(o=o.concat(this.childA.cellsInBand(e,t,n))),this.childB&&(o=o.concat(this.childB.cellsInBand(e,t,n))),this.childD&&(o=o.concat(this.childD.cellsInBand(e,t,n))),this.childC&&(o=o.concat(this.childC.cellsInBand(e,t,n)))):(n||this.lowerBound<=e||this.upperBound>=t)&&o.push({x:this.x,y:this.y})),o},h.prototype.cellsBelowThreshold=function(e,t){var n=[];return t=void 0===t||t,this.lowerBound>e||(this.childA||this.childB||this.childC||this.childD?(this.childA&&(n=n.concat(this.childA.cellsBelowThreshold(e,t))),this.childB&&(n=n.concat(this.childB.cellsBelowThreshold(e,t))),this.childD&&(n=n.concat(this.childD.cellsBelowThreshold(e,t))),this.childC&&(n=n.concat(this.childC.cellsBelowThreshold(e,t)))):(t||this.upperBound>=e)&&n.push({x:this.x,y:this.y})),n};var u={square:function(e,t,n,o,r,a){a.polygons&&e.polygons.push([[0,0],[0,1],[1,1],[1,0]])},triangle_bl:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate(t,r,a.minV,a.maxV);a.polygons_full&&(e.edges.lb={path:[[0,i],[l,0]],move:{x:0,y:-1,enter:"tl"}}),a.polygons&&e.polygons.push([[0,i],[l,0],[0,0]])},triangle_br:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.br={path:[[l,0],[1,i]],move:{x:1,y:0,enter:"lb"}}),a.polygons&&e.polygons.push([[l,0],[1,i],[1,0]])},triangle_tr:function(e,t,n,o,r,a){var l=a.interpolate(n,o,a.minV,a.maxV),i=a.interpolate(r,o,a.minV,a.maxV);a.polygons_full&&(e.edges.rt={path:[[1,l],[i,1]],move:{x:0,y:1,enter:"br"}}),a.polygons&&e.polygons.push([[1,l],[i,1],[1,1]])},triangle_tl:function(e,t,n,o,r,a){var l=a.interpolate(r,o,a.minV,a.maxV),i=a.interpolate(t,r,a.minV,a.maxV);a.polygons_full&&(e.edges.tl={path:[[l,1],[0,i]],move:{x:-1,y:0,enter:"rt"}}),a.polygons&&e.polygons.push([[0,i],[0,1],[l,1]])},tetragon_t:function(e,t,n,o,r,a){var l=a.interpolate(n,o,a.minV,a.maxV),i=a.interpolate(t,r,a.minV,a.maxV);a.polygons_full&&(e.edges.rt={path:[[1,l],[0,i]],move:{x:-1,y:0,enter:"rt"}}),a.polygons&&e.polygons.push([[0,i],[0,1],[1,1],[1,l]])},tetragon_r:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate(r,o,a.minV,a.maxV);a.polygons_full&&(e.edges.br={path:[[l,0],[i,1]],move:{x:0,y:1,enter:"br"}}),a.polygons&&e.polygons.push([[l,0],[i,1],[1,1],[1,0]])},tetragon_b:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.lb={path:[[0,l],[1,i]],move:{x:1,y:0,enter:"lb"}}),a.polygons&&e.polygons.push([[0,0],[0,l],[1,i],[1,0]])},tetragon_l:function(e,t,n,o,r,a){var l=a.interpolate(r,o,a.minV,a.maxV),i=a.interpolate(t,n,a.minV,a.maxV);a.polygons_full&&(e.edges.tl={path:[[l,1],[i,0]],move:{x:0,y:-1,enter:"tl"}}),a.polygons&&e.polygons.push([[0,0],[0,1],[l,1],[i,0]])},tetragon_bl:function(e,t,n,o,r,a){var l=a.interpolate_a(t,n,a.minV,a.maxV),i=a.interpolate_b(t,n,a.minV,a.maxV),s=a.interpolate_a(t,r,a.minV,a.maxV),p=a.interpolate_b(t,r,a.minV,a.maxV);a.polygons_full&&(e.edges.bl={path:[[l,0],[0,s]],move:{x:-1,y:0,enter:"rb"}},e.edges.lt={path:[[0,p],[i,0]],move:{x:0,y:-1,enter:"tr"}}),a.polygons&&e.polygons.push([[l,0],[0,s],[0,p],[i,0]])},tetragon_br:function(e,t,n,o,r,a){var l=a.interpolate_a(t,n,a.minV,a.maxV),i=a.interpolate_b(t,n,a.minV,a.maxV),s=a.interpolate_a(n,o,a.minV,a.maxV),p=a.interpolate_b(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.bl={path:[[l,0],[1,p]],move:{x:1,y:0,enter:"lt"}},e.edges.rb={path:[[1,s],[i,0]],move:{x:0,y:-1,enter:"tr"}}),a.polygons&&e.polygons.push([[l,0],[1,p],[1,s],[i,0]])},tetragon_tr:function(e,t,n,o,r,a){var l=a.interpolate_a(r,o,a.minV,a.maxV),i=a.interpolate_b(r,o,a.minV,a.maxV),s=a.interpolate_b(n,o,a.minV,a.maxV),p=a.interpolate_a(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.rb={path:[[1,p],[l,1]],move:{x:0,y:1,enter:"bl"}},e.edges.tr={path:[[i,1],[1,s]],move:{x:1,y:0,enter:"lt"}}),a.polygons&&e.polygons.push([[1,p],[l,1],[i,1],[1,s]])},tetragon_tl:function(e,t,n,o,r,a){var l=a.interpolate_a(r,o,a.minV,a.maxV),i=a.interpolate_b(r,o,a.minV,a.maxV),s=a.interpolate_b(t,r,a.minV,a.maxV),p=a.interpolate_a(t,r,a.minV,a.maxV);a.polygons_full&&(e.edges.tr={path:[[i,1],[0,p]],move:{x:-1,y:0,enter:"rb"}},e.edges.lt={path:[[0,s],[l,1]],move:{x:0,y:1,enter:"bl"}}),a.polygons&&e.polygons.push([[i,1],[0,p],[0,s],[l,1]])},tetragon_lr:function(e,t,n,o,r,a){var l=a.interpolate_a(t,r,a.minV,a.maxV),i=a.interpolate_b(t,r,a.minV,a.maxV),s=a.interpolate_b(n,o,a.minV,a.maxV),p=a.interpolate_a(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.lt={path:[[0,i],[1,s]],move:{x:1,y:0,enter:"lt"}},e.edges.rb={path:[[1,p],[0,l]],move:{x:-1,y:0,enter:"rb"}}),a.polygons&&e.polygons.push([[0,l],[0,i],[1,s],[1,p]])},tetragon_tb:function(e,t,n,o,r,a){var l=a.interpolate_a(r,o,a.minV,a.maxV),i=a.interpolate_b(r,o,a.minV,a.maxV),s=a.interpolate_b(t,n,a.minV,a.maxV),p=a.interpolate_a(t,n,a.minV,a.maxV);a.polygons_full&&(e.edges.tr={path:[[i,1],[s,0]],move:{x:0,y:-1,enter:"tr"}},e.edges.bl={path:[[p,0],[l,1]],move:{x:0,y:1,enter:"bl"}}),a.polygons&&e.polygons.push([[p,0],[l,1],[i,1],[s,0]])},pentagon_tr:function(e,t,n,o,r,a){var l=a.interpolate(r,o,a.minV,a.maxV),i=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.tl={path:[[l,1],[1,i]],move:{x:1,y:0,enter:"lb"}}),a.polygons&&e.polygons.push([[0,0],[0,1],[l,1],[1,i],[1,0]])},pentagon_tl:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate(r,o,a.minV,a.maxV);a.polygons_full&&(e.edges.lb={path:[[0,l],[i,1]],move:{x:0,y:1,enter:"br"}}),a.polygons&&e.polygons.push([[0,0],[0,l],[i,1],[1,1],[1,0]])},pentagon_br:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.rt={path:[[1,i],[l,0]],move:{x:0,y:-1,enter:"tl"}}),a.polygons&&e.polygons.push([[0,0],[0,1],[1,1],[1,i],[l,0]])},pentagon_bl:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate(t,n,a.minV,a.maxV);a.polygons_full&&(e.edges.br={path:[[i,0],[0,l]],move:{x:-1,y:0,enter:"rt"}}),a.polygons&&e.polygons.push([[0,l],[0,1],[1,1],[1,0],[i,0]])},pentagon_tr_rl:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate(r,o,a.minV,a.maxV),s=a.interpolate_b(n,o,a.minV,a.maxV),p=a.interpolate_a(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.tl={path:[[i,1],[1,s]],move:{x:1,y:0,enter:"lt"}},e.edges.rb={path:[[1,p],[0,l]],move:{x:-1,y:0,enter:"rt"}}),a.polygons&&e.polygons.push([[0,l],[0,1],[i,1],[1,s],[1,p]])},pentagon_rb_bt:function(e,t,n,o,r,a){var l=a.interpolate(n,o,a.minV,a.maxV),i=a.interpolate_b(t,n,a.minV,a.maxV),s=a.interpolate_a(t,n,a.minV,a.maxV),p=a.interpolate(r,o,a.minV,a.maxV);a.polygons_full&&(e.edges.rt={path:[[1,l],[i,0]],move:{x:0,y:-1,enter:"tr"}},e.edges.bl={path:[[s,0],[p,1]],move:{x:0,y:1,enter:"br"}}),a.polygons&&e.polygons.push([[p,1],[1,1],[1,l],[i,0],[s,0]])},pentagon_bl_lr:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate_a(t,r,a.minV,a.maxV),s=a.interpolate_b(t,r,a.minV,a.maxV),p=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.br={path:[[l,0],[0,i]],move:{x:-1,y:0,enter:"rb"}},e.edges.lt={path:[[0,s],[1,p]],move:{x:1,y:0,enter:"lb"}}),a.polygons&&e.polygons.push([[l,0],[0,i],[0,s],[1,p],[1,0]])},pentagon_lt_tb:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate_a(r,o,a.minV,a.maxV),s=a.interpolate_b(r,o,a.minV,a.maxV),p=a.interpolate(t,n,a.minV,a.maxV);a.polygons_full&&(e.edges.lb={path:[[0,l],[i,1]],move:{x:0,y:1,enter:"bl"}},e.edges.tr={path:[[s,1],[p,0]],move:{x:0,y:-1,enter:"tl"}}),a.polygons&&e.polygons.push([[0,0],[0,l],[i,1],[s,1],[p,0]])},pentagon_bl_tb:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate(r,o,a.minV,a.maxV),s=a.interpolate_b(t,n,a.minV,a.maxV),p=a.interpolate_a(t,n,a.minV,a.maxV);a.polygons_full&&(e.edges.bl={path:[[p,0],[0,l]],move:{x:-1,y:0,enter:"rt"}},e.edges.tl={path:[[i,1],[s,0]],move:{x:0,y:-1,enter:"tr"}}),a.polygons&&e.polygons.push([[0,l],[0,1],[i,1],[s,0],[p,0]])},pentagon_lt_rl:function(e,t,n,o,r,a){var l=a.interpolate_a(t,r,a.minV,a.maxV),i=a.interpolate_b(t,r,a.minV,a.maxV),s=a.interpolate(r,o,a.minV,a.maxV),p=a.interpolate(n,r,a.minV,a.maxV);a.polygons_full&&(e.edges.lt={path:[[0,i],[s,1]],move:{x:0,y:1,enter:"br"}},e.edges.rt={path:[[1,p],[0,l]],move:{x:-1,y:0,enter:"rb"}}),a.polygons&&e.polygons.push([[0,l],[0,i],[s,1],[1,1],[1,p]])},pentagon_tr_bt:function(e,t,n,o,r,a){var l=a.interpolate_a(r,o,a.minV,a.maxV),i=a.interpolate_b(r,o,a.minV,a.maxV),s=a.interpolate(n,o,a.minV,a.maxV),p=a.interpolate(t,n,a.minV,a.maxV);a.polygons_full&&(e.edges.br={path:[[p,0],[l,1]],move:{x:0,y:1,enter:"bl"}},e.edges.tr={path:[[i,1],[1,s]],move:{x:1,y:0,enter:"lb"}}),a.polygons&&e.polygons.push([[l,1],[i,1],[1,s],[1,0],[p,0]])},pentagon_rb_lr:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate_b(n,o,a.minV,a.maxV),s=a.interpolate_a(n,o,a.minV,a.maxV),p=a.interpolate(t,n,a.minV,a.maxV);a.polygons_full&&(e.edges.lb={path:[[0,l],[1,i]],move:{x:1,y:0,enter:"lt"}},e.edges.rb={path:[[1,s],[p,0]],move:{x:0,y:-1,enter:"tl"}}),a.polygons&&e.polygons.push([[0,0],[0,l],[1,i],[1,s],[p,0]])},hexagon_lt_tr:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate_a(r,o,a.minV,a.maxV),s=a.interpolate_b(r,o,a.minV,a.maxV),p=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.lb={path:[[0,l],[i,1]],move:{x:0,y:1,enter:"bl"}},e.edges.tr={path:[[s,1],[1,p]],move:{x:1,y:0,enter:"lb"}}),a.polygons&&e.polygons.push([[0,0],[0,l],[i,1],[s,1],[1,p],[1,0]])},hexagon_bl_lt:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate_a(t,r,a.minV,a.maxV),s=a.interpolate_b(t,r,a.minV,a.maxV),p=a.interpolate(r,o,a.minV,a.maxV);a.polygons_full&&(e.edges.br={path:[[l,0],[0,i]],move:{x:-1,y:0,enter:"rb"}},e.edges.lt={path:[[0,s],[p,1]],move:{x:0,y:1,enter:"br"}}),a.polygons&&e.polygons.push([[l,0],[0,i],[0,s],[p,1],[1,1],[1,0]])},hexagon_bl_rb:function(e,t,n,o,r,a){var l=a.interpolate_a(t,n,a.minV,a.maxV),i=a.interpolate_b(t,n,a.minV,a.maxV),s=a.interpolate(t,r,a.minV,a.maxV),p=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.bl={path:[[l,0],[0,s]],move:{x:-1,y:0,enter:"rt"}},e.edges.rt={path:[[1,p],[i,0]],move:{x:0,y:-1,enter:"tr"}}),a.polygons&&e.polygons.push([[l,0],[0,s],[0,1],[1,1],[1,p],[i,0]])},hexagon_tr_rb:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate(r,o,a.minV,a.maxV),s=a.interpolate_b(n,o,a.minV,a.maxV),p=a.interpolate_a(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.tl={path:[[i,1],[1,s]],move:{x:1,y:0,enter:"lt"}},e.edges.rb={path:[[1,p],[l,0]],move:{x:0,y:-1,enter:"tl"}}),a.polygons&&e.polygons.push([[0,0],[0,1],[i,1],[1,s],[1,p],[l,0]])},hexagon_lt_rb:function(e,t,n,o,r,a){var l=a.interpolate(t,r,a.minV,a.maxV),i=a.interpolate(r,o,a.minV,a.maxV),s=a.interpolate(n,o,a.minV,a.maxV),p=a.interpolate(t,n,a.minV,a.maxV);a.polygons_full&&(e.edges.lb={path:[[0,l],[i,1]],move:{x:0,y:1,enter:"br"}},e.edges.rt={path:[[1,s],[p,0]],move:{x:0,y:-1,enter:"tl"}}),a.polygons&&e.polygons.push([[0,0],[0,l],[i,1],[1,1],[1,s],[p,0]])},hexagon_bl_tr:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate(t,r,a.minV,a.maxV),s=a.interpolate(r,o,a.minV,a.maxV),p=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.br={path:[[l,0],[0,i]],move:{x:-1,y:0,enter:"rt"}},e.edges.tl={path:[[s,1],[1,p]],move:{x:1,y:0,enter:"lb"}}),a.polygons&&e.polygons.push([[l,0],[0,i],[0,1],[s,1],[1,p],[1,0]])},heptagon_tr:function(e,t,n,o,r,a){var l=a.interpolate_a(t,n,a.minV,a.maxV),i=a.interpolate_b(t,n,a.minV,a.maxV),s=a.interpolate_a(t,r,a.minV,a.maxV),p=a.interpolate_b(t,r,a.minV,a.maxV),g=a.interpolate(r,o,a.minV,a.maxV),h=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.bl={path:[[l,0],[0,s]],move:{x:-1,y:0,enter:"rb"}},e.edges.lt={path:[[0,p],[g,1]],move:{x:0,y:1,enter:"br"}},e.edges.rt={path:[[1,h],[i,0]],move:{x:0,y:-1,enter:"tr"}}),a.polygons&&e.polygons.push([[l,0],[0,s],[0,p],[g,1],[1,1],[1,h],[i,0]])},heptagon_bl:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate(t,r,a.minV,a.maxV),s=a.interpolate_a(r,o,a.minV,a.maxV),p=a.interpolate_b(r,o,a.minV,a.maxV),g=a.interpolate_b(n,o,a.minV,a.maxV),h=a.interpolate_a(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.lb={path:[[0,i],[s,1]],move:{x:0,y:1,enter:"bl"}},e.edges.tr={path:[[p,1],[1,g]],move:{x:1,y:0,enter:"lt"}},e.edges.rb={path:[[1,h],[l,0]],move:{x:0,y:-1,enter:"tl"}}),a.polygons&&e.polygons.push([[0,0],[0,i],[s,1],[p,1],[1,g],[1,h],[l,0]])},heptagon_tl:function(e,t,n,o,r,a){var l=a.interpolate_a(t,n,a.minV,a.maxV),i=a.interpolate_b(t,n,a.minV,a.maxV),s=a.interpolate(t,r,a.minV,a.maxV),p=a.interpolate(r,o,a.minV,a.maxV),g=a.interpolate_b(n,o,a.minV,a.maxV),h=a.interpolate_a(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.bl={path:[[l,0],[0,s]],move:{x:-1,y:0,enter:"rt"}},e.edges.tl={path:[[p,1],[1,g]],move:{x:1,y:0,enter:"lt"}},e.edges.rb={path:[[1,h],[i,0]],move:{x:0,y:-1,enter:"tr"}}),a.polygons&&e.polygons.push([[l,0],[0,s],[0,1],[p,1],[1,g],[1,h],[i,0]])},heptagon_br:function(e,t,n,o,r,a){var l=a.interpolate(t,n,a.minV,a.maxV),i=a.interpolate_a(t,r,a.minV,a.maxV),s=a.interpolate_b(t,r,a.minV,a.maxV),p=a.interpolate_a(r,o,a.minV,a.maxV),g=a.interpolate_b(r,o,a.minV,a.maxV),h=a.interpolate(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.br={path:[[l,0],[0,i]],move:{x:-1,y:0,enter:"rb"}},e.edges.lt={path:[[0,s],[p,1]],move:{x:0,y:1,enter:"bl"}},e.edges.tr={path:[[g,1],[1,h]],move:{x:1,y:0,enter:"lb"}}),a.polygons&&e.polygons.push([[l,0],[0,i],[0,s],[p,1],[g,1],[1,h],[1,0]])},octagon:function(e,t,n,o,r,a){var l=a.interpolate_a(t,n,a.minV,a.maxV),i=a.interpolate_b(t,n,a.minV,a.maxV),s=a.interpolate_a(t,r,a.minV,a.maxV),p=a.interpolate_b(t,r,a.minV,a.maxV),g=a.interpolate_a(r,o,a.minV,a.maxV),h=a.interpolate_b(r,o,a.minV,a.maxV),m=a.interpolate_b(n,o,a.minV,a.maxV),u=a.interpolate_a(n,o,a.minV,a.maxV);a.polygons_full&&(e.edges.bl={path:[[l,0],[0,s]],move:{x:-1,y:0,enter:"rb"}},e.edges.lt={path:[[0,p],[g,1]],move:{x:0,y:1,enter:"bl"}},e.edges.tr={path:[[h,1],[1,m]],move:{x:1,y:0,enter:"lt"}},e.edges.rb={path:[[1,u],[i,0]],move:{x:0,y:-1,enter:"tr"}}),a.polygons&&e.polygons.push([[l,0],[0,s],[0,p],[g,1],[h,1],[1,m],[1,u],[i,0]])}};function b(e,t,n,o,r,a){var l=(o+n+t+e)/4;return a<l?2:l<r?0:1}function P(e,t,n,o){var r,a,l=0,i=e[n+1][t],s=e[n+1][t+1],p=e[n][t+1],g=e[n][t],h=o.minV,m=o.maxV;if(!(isNaN(g)||isNaN(p)||isNaN(s)||isNaN(i))){switch(l|=i<h?0:m<i?128:64,l|=s<h?0:m<s?32:16,l|=p<h?0:m<p?8:4,a=0,r={cval:l=+(l|=g<h?0:m<g?2:1),polygons:[],edges:{},x0:g,x1:p,x2:s,x3:i,x:t,y:n},l){case 85:u.square(r,g,p,s,i,o);case 0:case 170:break;case 169:u.triangle_bl(r,g,p,s,i,o);break;case 166:u.triangle_br(r,g,p,s,i,o);break;case 154:u.triangle_tr(r,g,p,s,i,o);break;case 106:u.triangle_tl(r,g,p,s,i,o);break;case 1:u.triangle_bl(r,g,p,s,i,o);break;case 4:u.triangle_br(r,g,p,s,i,o);break;case 16:u.triangle_tr(r,g,p,s,i,o);break;case 64:u.triangle_tl(r,g,p,s,i,o);break;case 168:u.tetragon_bl(r,g,p,s,i,o);break;case 162:u.tetragon_br(r,g,p,s,i,o);break;case 138:u.tetragon_tr(r,g,p,s,i,o);break;case 42:u.tetragon_tl(r,g,p,s,i,o);break;case 2:u.tetragon_bl(r,g,p,s,i,o);break;case 8:u.tetragon_br(r,g,p,s,i,o);break;case 32:u.tetragon_tr(r,g,p,s,i,o);break;case 128:u.tetragon_tl(r,g,p,s,i,o);break;case 5:u.tetragon_b(r,g,p,s,i,o);break;case 20:u.tetragon_r(r,g,p,s,i,o);break;case 80:u.tetragon_t(r,g,p,s,i,o);break;case 65:u.tetragon_l(r,g,p,s,i,o);break;case 165:u.tetragon_b(r,g,p,s,i,o);break;case 150:u.tetragon_r(r,g,p,s,i,o);break;case 90:u.tetragon_t(r,g,p,s,i,o);break;case 105:u.tetragon_l(r,g,p,s,i,o);break;case 160:u.tetragon_lr(r,g,p,s,i,o);break;case 130:u.tetragon_tb(r,g,p,s,i,o);break;case 10:u.tetragon_lr(r,g,p,s,i,o);break;case 40:u.tetragon_tb(r,g,p,s,i,o);break;case 101:u.pentagon_tr(r,g,p,s,i,o);break;case 149:u.pentagon_tl(r,g,p,s,i,o);break;case 86:u.pentagon_bl(r,g,p,s,i,o);break;case 89:u.pentagon_br(r,g,p,s,i,o);break;case 69:u.pentagon_tr(r,g,p,s,i,o);break;case 21:u.pentagon_tl(r,g,p,s,i,o);break;case 84:u.pentagon_bl(r,g,p,s,i,o);break;case 81:u.pentagon_br(r,g,p,s,i,o);break;case 96:u.pentagon_tr_rl(r,g,p,s,i,o);break;case 24:u.pentagon_rb_bt(r,g,p,s,i,o);break;case 6:u.pentagon_bl_lr(r,g,p,s,i,o);break;case 129:u.pentagon_lt_tb(r,g,p,s,i,o);break;case 74:u.pentagon_tr_rl(r,g,p,s,i,o);break;case 146:u.pentagon_rb_bt(r,g,p,s,i,o);break;case 164:u.pentagon_bl_lr(r,g,p,s,i,o);break;case 41:u.pentagon_lt_tb(r,g,p,s,i,o);break;case 66:u.pentagon_bl_tb(r,g,p,s,i,o);break;case 144:u.pentagon_lt_rl(r,g,p,s,i,o);break;case 36:u.pentagon_tr_bt(r,g,p,s,i,o);break;case 9:u.pentagon_rb_lr(r,g,p,s,i,o);break;case 104:u.pentagon_bl_tb(r,g,p,s,i,o);break;case 26:u.pentagon_lt_rl(r,g,p,s,i,o);break;case 134:u.pentagon_tr_bt(r,g,p,s,i,o);break;case 161:u.pentagon_rb_lr(r,g,p,s,i,o);break;case 37:u.hexagon_lt_tr(r,g,p,s,i,o);break;case 148:u.hexagon_bl_lt(r,g,p,s,i,o);break;case 82:u.hexagon_bl_rb(r,g,p,s,i,o);break;case 73:u.hexagon_tr_rb(r,g,p,s,i,o);break;case 133:u.hexagon_lt_tr(r,g,p,s,i,o);break;case 22:u.hexagon_bl_lt(r,g,p,s,i,o);break;case 88:u.hexagon_bl_rb(r,g,p,s,i,o);break;case 97:u.hexagon_tr_rb(r,g,p,s,i,o);break;case 145:case 25:u.hexagon_lt_rb(r,g,p,s,i,o);break;case 70:case 100:u.hexagon_bl_tr(r,g,p,s,i,o);break;case 17:0===(a=b(g,p,s,i,h,m))?(u.triangle_bl(r,g,p,s,i,o),u.triangle_tr(r,g,p,s,i,o)):u.hexagon_lt_rb(r,g,p,s,i,o);break;case 68:0===(a=b(g,p,s,i,h,m))?(u.triangle_tl(r,g,p,s,i,o),u.triangle_br(r,g,p,s,i,o)):u.hexagon_bl_tr(r,g,p,s,i,o);break;case 153:2===(a=b(g,p,s,i,h,m))?(u.triangle_bl(r,g,p,s,i,o),u.triangle_tr(r,g,p,s,i,o)):u.hexagon_lt_rb(r,g,p,s,i,o);break;case 102:2===(a=b(g,p,s,i,h,m))?(u.triangle_tl(r,g,p,s,i,o),u.triangle_br(r,g,p,s,i,o)):u.hexagon_bl_tr(r,g,p,s,i,o);break;case 152:2===(a=b(g,p,s,i,h,m))?(u.triangle_tr(r,g,p,s,i,o),u.tetragon_bl(r,g,p,s,i,o)):u.heptagon_tr(r,g,p,s,i,o);break;case 137:2===(a=b(g,p,s,i,h,m))?(u.triangle_bl(r,g,p,s,i,o),u.tetragon_tr(r,g,p,s,i,o)):u.heptagon_bl(r,g,p,s,i,o);break;case 98:2===(a=b(g,p,s,i,h,m))?(u.triangle_tl(r,g,p,s,i,o),u.tetragon_br(r,g,p,s,i,o)):u.heptagon_tl(r,g,p,s,i,o);break;case 38:2===(a=b(g,p,s,i,h,m))?(u.triangle_br(r,g,p,s,i,o),u.tetragon_tl(r,g,p,s,i,o)):u.heptagon_br(r,g,p,s,i,o);break;case 18:0===(a=b(g,p,s,i,h,m))?(u.triangle_tr(r,g,p,s,i,o),u.tetragon_bl(r,g,p,s,i,o)):u.heptagon_tr(r,g,p,s,i,o);break;case 33:0===(a=b(g,p,s,i,h,m))?(u.triangle_bl(r,g,p,s,i,o),u.tetragon_tr(r,g,p,s,i,o)):u.heptagon_bl(r,g,p,s,i,o);break;case 72:0===(a=b(g,p,s,i,h,m))?(u.triangle_tl(r,g,p,s,i,o),u.tetragon_br(r,g,p,s,i,o)):u.heptagon_tl(r,g,p,s,i,o);break;case 132:0===(a=b(g,p,s,i,h,m))?(u.triangle_br(r,g,p,s,i,o),u.tetragon_tl(r,g,p,s,i,o)):u.heptagon_br(r,g,p,s,i,o);break;case 136:0===(a=b(g,p,s,i,h,m))?(u.tetragon_tl(r,g,p,s,i,o),u.tetragon_br(r,g,p,s,i,o)):1===a?u.octagon(r,g,p,s,i,o):(u.tetragon_bl(r,g,p,s,i,o),u.tetragon_tr(r,g,p,s,i,o));break;case 34:0===(a=b(g,p,s,i,h,m))?(u.tetragon_bl(r,g,p,s,i,o),u.tetragon_tr(r,g,p,s,i,o)):1===a?u.octagon(r,g,p,s,i,o):(u.tetragon_tl(r,g,p,s,i,o),u.tetragon_br(r,g,p,s,i,o))}return r}}e.isoLines=t,e.isoContours=t,e.isoBands=function(e,t,q,n){var S,M,T,j=!1,o=null,C=null,D=null,J=null,Q=!1,r=[],R=[],I=[];if(!e)throw new Error("data is required");if(null==t)throw new Error("lowerBound is required");if(null==q)throw new Error("bandWidth is required");if(n&&"object"!=typeof n)throw new Error("options must be an object");if(T=function(e){var t,n,o,r,a;for(r=new g,e=e||{},a=Object.keys(r),t=0;t<a.length;t++)null!=(o=e[n=a[t]])&&(r[n]=o);return r.polygons_full=!r.polygons,r.interpolate=i,r.interpolate_a=s,r.interpolate_b=p,r}(n),e instanceof a)C=(o=e).root,D=e.data,T.noQuadTree||(j=!0);else{if(!Array.isArray(e)||!Array.isArray(e[0]))throw new Error("input is neither array of arrays nor object retrieved from 'QuadTree()'");D=e}if(Array.isArray(t)){for(Q=!0,T.noQuadTree||(j=!0),S=0;S<t.length;S++)if(isNaN(+t[S]))throw new Error("lowerBound["+S+"] is not a number");if(Array.isArray(q)){if(t.length!==q.length)throw new Error("lowerBound and bandWidth have unequal lengths");for(S=0;S<q.length;S++)if(isNaN(+q[S]))throw new Error("bandWidth["+S+"] is not a number")}else{if(isNaN(+q))throw new Error("bandWidth must be a number");for(r=[],S=0;S<t.length;S++)r.push(q);q=r}}else{if(isNaN(+t))throw new Error("lowerBound must be a number");if(t=[t],isNaN(+q))throw new Error("bandWidth must be a number");q=[q]}return j&&!C&&(o=new a(D),C=o.root,D=o.data),T.verbose&&(T.polygons?console.log("MarchingSquaresJS-isoBands: returning single polygons for each grid cell"):console.log("MarchingSquaresJS-isoBands: returning polygon paths for entire data grid"),Q&&console.log("MarchingSquaresJS-isoBands: multiple bands requested, returning array of band polygons instead of polygons for a single band")),t.forEach(function(e,t){if(R=[],T.minV=e,T.maxV=e+q[t],T.verbose&&console.log("MarchingSquaresJS-isoBands: computing isobands for ["+e+":"+(e+q[t])+"]"),T.polygons)if(j)C.cellsInBand(T.minV,T.maxV,!0).forEach(function(e){R=R.concat(L(P(D,e.x,e.y,T),e.x,e.y,T))});else for(M=0;M<D.length-1;++M)for(S=0;S<D[0].length-1;++S)R=R.concat(L(P(D,S,M,T),S,M,T));else{for(J=[],S=0;S<D[0].length-1;++S)J[S]=[];if(j)C.cellsInBand(T.minV,T.maxV,!1).forEach(function(e){J[e.x][e.y]=P(D,e.x,e.y,T)});else for(S=0;S<D[0].length-1;++S)for(M=0;M<D.length-1;++M)J[S][M]=P(D,S,M,T);o=J,r=T,x=[],v=(n=D).length-1,k=n[0].length-1,w=[["rt","rb"],["br","bl"],["lb","lt"],["tl","tr"]],B=[0,-1,0,1],E=[-1,0,1,0],A=["bl","lb","lt","tl","tr","rt","rb","br"],N={bl:1,br:1,lb:2,lt:2,tl:3,tr:3,rt:0,rb:0},function(e,t,n){var o,r,a,l,i;for(o=!0,r=e[0].length,a=e.length,i=0;i<a;i++)if(e[i][0]<t||e[i][0]>n||e[i][r-1]<t||e[i][r-1]>n){o=!1;break}if(o&&(e[a-1][0]<t||e[a-1][0]>n||e[a-1][r-1]<t||e[a-1][r-1]>n)&&(o=!1),o)for(l=0;l<r-1;l++)if(e[0][l]<t||e[0][l]>n||e[a-1][l]<t||e[a-1][l]>n){o=!1;break}return o}(n,r.minV,r.maxV)&&(r.linearRing?x.push([[0,0],[0,v],[k,v],[k,0],[0,0]]):x.push([[0,0],[0,v],[k,v],[k,0]])),o.forEach(function(e,n){e.forEach(function(e,t){for(a=null,i=0;i<8;i++)if(a=A[i],"object"==typeof e.edges[a]){for(l=[],s=e.edges[a],h=a,u=t,b=!1,c=[(m=n)+s.path[0][0],t+s.path[0][1]],l.push(c);!b&&"object"==typeof(y=o[m][u]).edges[h];)if(s=y.edges[h],delete y.edges[h],(f=s.path[1])[0]+=m,f[1]+=u,l.push(f),h=s.move.enter,m+=s.move.x,u+=s.move.y,void 0===o[m]||void 0===o[m][u]){if(d=_=0,m===k)m--,_=0;else if(m<0)m++,_=2;else if(u===v)u--,_=3;else{if(!(u<0))throw new Error("Left the grid somewhere in the interior!");u++,_=1}if(m===n&&u===t&&_===N[a]){b=!0,h=a;break}for(;;){if(V=!1,4<d)throw new Error("Direction change counter overflow! This should never happen!");if(void 0!==o[m]&&void 0!==o[m][u])for(y=o[m][u],p=0;p<w[_].length;p++)if(g=w[_][p],"object"==typeof y.edges[g]){s=y.edges[g],l.push(W(m,u,_,s.path)),h=g,V=!0;break}if(V)break;if(l.push(O(m,u,_)),u+=E[_],void 0!==o[m+=B[_]]&&void 0!==o[m][u]||(0===_&&u<0||1===_&&m<0||2===_&&u===v||3===_&&m===k)&&(m-=B[_],u-=E[_],_=(_+1)%4,d++),m===n&&u===t&&_===N[a]){b=!0,h=a;break}}}!r.linearRing||l[l.length-1][0]===c[0]&&l[l.length-1][1]===c[1]||l.push(c),x.push(l)}})}),R=x}var n,o,r,a,l,i,s,p,g,h,m,u,b,c,y,_,d,f,V,x,v,k,w,B,E,A,N;Q?I.push(R):I=R,"function"==typeof T.successCallback&&T.successCallback(I,e,q[t])}),I},e.QuadTree=a,e.quadTree=a,Object.defineProperty(e,"__esModule",{value:!0})});