UNPKG

node-red-contrib-tak-registration

Version:

A Node-RED node to register to TAK and to help wrap files as datapackages to send to TAK

10 lines (9 loc) 10.9 kB
/*! * MarchingSquaresJS * version 1.3.3 * https://github.com/RaumZeit/MarchingSquares.js * * @license GNU Affero General Public License. * Copyright (c) 2015-2019 Ronny Lorenz <ronny@tbi.univie.ac.at> */ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o(e.MarchingSquaresJS=e.MarchingSquaresJS||{})}(this,function(e){"use strict";function p(e,o,t){return e<o?(t-e)/(o-e):(e-t)/(e-o)}function u(){this.successCallback=null,this.verbose=!1,this.polygons=!1,this.polygons_full=!1,this.linearRing=!0,this.noQuadTree=!1,this.noFrame=!1}function L(e,o,t,r){var n=[];return e.polygons.forEach(function(e){e.forEach(function(e){e[0]+=o,e[1]+=t}),r.linearRing&&e.push(e[0]),n.push(e)}),n}function a(e,o,t,r,n){var l=r,s=n,i=0,h=0;if(this.x=o,this.y=t,this.lowerBound=null,this.upperBound=null,this.childA=null,this.childB=null,this.childC=null,this.childD=null,1===r&&1===n)this.lowerBound=Math.min(e[t][o],e[t][o+1],e[t+1][o+1],e[t+1][o]),this.upperBound=Math.max(e[t][o],e[t][o+1],e[t+1][o+1],e[t+1][o]);else{if(1<r){for(;0!==l;)l>>=1,i++;r===1<<i-1&&i--,l=1<<i-1}if(1<n){for(;0!==s;)s>>=1,h++;n===1<<h-1&&h--,s=1<<h-1}this.childA=new a(e,o,t,l,s),this.lowerBound=this.childA.lowerBound,this.upperBound=this.childA.upperBound,0<r-l&&(this.childB=new a(e,o+l,t,r-l,s),this.lowerBound=Math.min(this.lowerBound,this.childB.lowerBound),this.upperBound=Math.max(this.upperBound,this.childB.upperBound),0<n-s&&(this.childC=new a(e,o+l,t+s,r-l,n-s),this.lowerBound=Math.min(this.lowerBound,this.childC.lowerBound),this.upperBound=Math.max(this.upperBound,this.childC.upperBound))),0<n-s&&(this.childD=new a(e,o,t+s,l,n-s),this.lowerBound=Math.min(this.lowerBound,this.childD.lowerBound),this.upperBound=Math.max(this.upperBound,this.childD.upperBound))}}function d(e){var o,t;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((t=e[0].length)<2)throw new Error("data must contain at least two columns");for(o=1;o<e.length;o++){if(!Array.isArray(e[o]))throw new Error("Row "+o+" is not an array");if(e[o].length!=t)throw new Error("unequal row lengths detected, please provide a regular grid")}this.data=e,this.root=new a(e,0,0,e[0].length-1,e.length-1)}function o(e,o,t){var r,n,l,s=!1,i=!1,h=null,a=null,j=null,J=null,R=null,I=[];if(!e)throw new Error("data is required");if(null==o)throw new Error("threshold is required");if(t&&"object"!=typeof t)throw new Error("options must be an object");if(r=function(e){var o,t,r,n,l;for(n=new u,e=e||{},l=Object.keys(n),o=0;o<l.length;o++)null!=(r=e[t=l[o]])&&(n[t]=r);return n.polygons_full=!n.polygons,n.interpolate=p,n}(t),e instanceof d)a=(h=e).root,j=e.data,r.noQuadTree||(s=!0);else{if(!Array.isArray(e)||!Array.isArray(e[0]))throw new Error("input is neither array of arrays nor object retrieved from 'QuadTree()'");j=e}if(Array.isArray(o)){for(i=!0,r.noQuadTree||(s=!0),n=0;n<o.length;n++)if(isNaN(+o[n]))throw new Error("threshold["+n+"] is not a number")}else{if(isNaN(+o))throw new Error("threshold must be a number or array of numbers");o=[o]}return s&&!a&&(h=new d(j),a=h.root,j=h.data),r.verbose&&(r.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"),i&&console.log("MarchingSquaresJS-isoLines: multiple lines requested, returning array of line paths instead of lines for a single threshold")),o.forEach(function(e,o){if(R=[],r.threshold=e,r.verbose&&console.log("MarchingSquaresJS-isoLines: computing iso lines for threshold "+e),r.polygons)if(s)a.cellsBelowThreshold(r.threshold,!0).forEach(function(e){R=R.concat(L(Q(j,e.x,e.y,r),e.x,e.y,r))});else for(l=0;l<j.length-1;++l)for(o=0;o<j[0].length-1;++o)R=R.concat(L(Q(j,o,l,r),o,l,r));else{for(J=[],o=0;o<j[0].length-1;++o)J[o]=[];if(s)a.cellsBelowThreshold(r.threshold,!1).forEach(function(e){J[e.x][e.y]=Q(j,e.x,e.y,r)});else for(o=0;o<j[0].length-1;++o)for(l=0;l<j.length-1;++l)J[o][l]=Q(j,o,l,r);p=J,u=r,M=[],C=(t=j).length-1,N=t[0].length-1,S=["right","bottom","left","top"],T=[0,-1,0,1],q=[-1,0,1,0],D={bottom:1,left:2,top:3,right:0},u.noFrame||function(e,o){var t,r,n,l,s;for(t=!0,r=e[0].length,n=e.length,s=0;s<n;s++)if(e[s][0]>=o||e[s][r-1]>=o){t=!1;break}if(t&&(e[n-1][0]>=o||e[n-1][r-1]>=o)&&(t=!1),t)for(l=0;l<r-1;l++)if(e[0][l]>=o||e[n-1][l]>o){t=!1;break}return t}(t,u.threshold)&&(u.linearRing?M.push([[0,0],[0,C],[N,C],[N,0],[0,0]]):M.push([[0,0],[0,C],[N,C],[N,0]])),p.forEach(function(e,a){e.forEach(function(e,o){for(d=null,c=0;c<4;c++)if(d=S[c],"object"==typeof e.edges[d]){for(y=[],g=e.edges[d],w=d,b=o,B=!1,v=[(m=a)+g.path[0][0],o+g.path[0][1]],y.push(v);!B&&"object"==typeof(f=p[m][b]).edges[w];)if(g=f.edges[w],delete f.edges[w],(x=g.path[1])[0]+=m,x[1]+=b,y.push(x),w=g.move.enter,m+=g.move.x,b+=g.move.y,void 0===p[m]||void 0===p[m][b]){if(!u.linearRing)break;if(A=k=0,m===N?(m--,k=0):m<0?(m++,k=2):b===C?(b--,k=3):b<0&&(b++,k=1),m===a&&b===o&&k===D[d]){B=!0,w=d;break}for(;;){if(E=!1,4<A)throw new Error("Direction change counter overflow! This should never happen!");if(void 0!==p[m]&&void 0!==p[m][b]&&(f=p[m][b],_=S[k],"object"==typeof f.edges[_])){g=f.edges[_],y.push((l=m,s=b,i=k,h=g.path,0===i?(l+=1,s+=h[0][1]):1===i?l+=h[0][0]:2===i?s+=h[0][1]:3===i&&(l+=h[0][0],s+=1),[l,s])),w=_,E=!0;break}if(E)break;if(y.push((t=m,r=b,0===(n=k)?t++:1===n||(2===n?r++:3===n&&(t++,r++)),[t,r])),b+=q[k],void 0!==p[m+=T[k]]&&void 0!==p[m][b]||(0===k&&b<0||1===k&&m<0||2===k&&b===C||3===k&&m===N)&&(m-=T[k],b-=q[k],k=(k+1)%4,A++),m===a&&b===o&&k===D[d]){B=!0,w=d;break}}}!u.linearRing||y[y.length-1][0]===v[0]&&y[y.length-1][1]===v[1]||y.push(v),M.push(y)}var t,r,n,l,s,i,h})}),R=M}var t,p,u,d,c,g,f,y,w,m,b,B,v,x,k,A,E,_,M,C,N,S,T,q,D;i?I.push(R):I=R,"function"==typeof r.successCallback&&r.successCallback(I,e)}),I}function Q(e,o,t,r){var n,l,s,i,h,a,p=0,u=e[t+1][o],d=e[t+1][o+1],c=e[t][o+1],g=e[t][o],f=r.threshold;if(!(isNaN(g)||isNaN(c)||isNaN(d)||isNaN(u))){switch(p|=f<=u?8:0,p|=f<=d?4:0,p|=f<=c?2:0,a={cval:p=+(p|=f<=g?1:0),polygons:[],edges:{},x0:g,x1:c,x2:d,x3:u},p){case 0:r.polygons&&a.polygons.push([[0,0],[0,1],[1,1],[1,0]]);break;case 15:break;case 14:n=r.interpolate(g,u,f),i=r.interpolate(g,c,f),r.polygons_full&&(a.edges.left={path:[[0,n],[i,0]],move:{x:0,y:-1,enter:"top"}}),r.polygons&&a.polygons.push([[0,0],[0,n],[i,0]]);break;case 13:i=r.interpolate(g,c,f),l=r.interpolate(c,d,f),r.polygons_full&&(a.edges.bottom={path:[[i,0],[1,l]],move:{x:1,y:0,enter:"left"}}),r.polygons&&a.polygons.push([[i,0],[1,l],[1,0]]);break;case 11:l=r.interpolate(c,d,f),s=r.interpolate(u,d,f),r.polygons_full&&(a.edges.right={path:[[1,l],[s,1]],move:{x:0,y:1,enter:"bottom"}}),r.polygons&&a.polygons.push([[1,l],[s,1],[1,1]]);break;case 7:n=r.interpolate(g,u,f),s=r.interpolate(u,d,f),r.polygons_full&&(a.edges.top={path:[[s,1],[0,n]],move:{x:-1,y:0,enter:"right"}}),r.polygons&&a.polygons.push([[s,1],[0,n],[0,1]]);break;case 1:n=r.interpolate(g,u,f),i=r.interpolate(g,c,f),r.polygons_full&&(a.edges.bottom={path:[[i,0],[0,n]],move:{x:-1,y:0,enter:"right"}}),r.polygons&&a.polygons.push([[i,0],[0,n],[0,1],[1,1],[1,0]]);break;case 2:i=r.interpolate(g,c,f),l=r.interpolate(c,d,f),r.polygons_full&&(a.edges.right={path:[[1,l],[i,0]],move:{x:0,y:-1,enter:"top"}}),r.polygons&&a.polygons.push([[0,0],[0,1],[1,1],[1,l],[i,0]]);break;case 4:l=r.interpolate(c,d,f),s=r.interpolate(u,d,f),r.polygons_full&&(a.edges.top={path:[[s,1],[1,l]],move:{x:1,y:0,enter:"left"}}),r.polygons&&a.polygons.push([[0,0],[0,1],[s,1],[1,l],[1,0]]);break;case 8:n=r.interpolate(g,u,f),s=r.interpolate(u,d,f),r.polygons_full&&(a.edges.left={path:[[0,n],[s,1]],move:{x:0,y:1,enter:"bottom"}}),r.polygons&&a.polygons.push([[0,0],[0,n],[s,1],[1,1],[1,0]]);break;case 12:n=r.interpolate(g,u,f),l=r.interpolate(c,d,f),r.polygons_full&&(a.edges.left={path:[[0,n],[1,l]],move:{x:1,y:0,enter:"left"}}),r.polygons&&a.polygons.push([[0,0],[0,n],[1,l],[1,0]]);break;case 9:i=r.interpolate(g,c,f),s=r.interpolate(u,d,f),r.polygons_full&&(a.edges.bottom={path:[[i,0],[s,1]],move:{x:0,y:1,enter:"bottom"}}),r.polygons&&a.polygons.push([[i,0],[s,1],[1,1],[1,0]]);break;case 3:n=r.interpolate(g,u,f),l=r.interpolate(c,d,f),r.polygons_full&&(a.edges.right={path:[[1,l],[0,n]],move:{x:-1,y:0,enter:"right"}}),r.polygons&&a.polygons.push([[0,n],[0,1],[1,1],[1,l]]);break;case 6:i=r.interpolate(g,c,f),s=r.interpolate(u,d,f),r.polygons_full&&(a.edges.top={path:[[s,1],[i,0]],move:{x:0,y:-1,enter:"top"}}),r.polygons&&a.polygons.push([[0,0],[0,1],[s,1],[i,0]]);break;case 10:n=r.interpolate(g,u,f),l=r.interpolate(c,d,f),i=r.interpolate(g,c,f),s=r.interpolate(u,d,f),h=(g+c+d+u)/4,r.polygons_full&&(h<f?(a.edges.left={path:[[0,n],[s,1]],move:{x:0,y:1,enter:"bottom"}},a.edges.right={path:[[1,l],[i,0]],move:{x:0,y:-1,enter:"top"}}):(a.edges.right={path:[[1,l],[s,1]],move:{x:0,y:1,enter:"bottom"}},a.edges.left={path:[[0,n],[i,0]],move:{x:0,y:-1,enter:"top"}})),r.polygons&&(h<f?a.polygons.push([[0,0],[0,n],[s,1],[1,1],[1,l],[i,0]]):(a.polygons.push([[0,0],[0,n],[i,0]]),a.polygons.push([[s,1],[1,1],[1,l]])));break;case 5:n=r.interpolate(g,u,f),l=r.interpolate(c,d,f),i=r.interpolate(g,c,f),s=r.interpolate(u,d,f),h=(g+c+d+u)/4,r.polygons_full&&(h<f?(a.edges.bottom={path:[[i,0],[0,n]],move:{x:-1,y:0,enter:"right"}},a.edges.top={path:[[s,1],[1,l]],move:{x:1,y:0,enter:"left"}}):(a.edges.top={path:[[s,1],[0,n]],move:{x:-1,y:0,enter:"right"}},a.edges.bottom={path:[[i,0],[1,l]],move:{x:1,y:0,enter:"left"}})),r.polygons&&(h<f?a.polygons.push([[0,n],[0,1],[s,1],[1,l],[1,0],[i,0]]):(a.polygons.push([[0,n],[0,1],[s,1]]),a.polygons.push([[i,0],[1,l],[1,0]])))}return a}}a.prototype.cellsInBand=function(e,o,t){var r=[];return t=void 0===t||t,this.lowerBound>o||this.upperBound<e||(this.childA||this.childB||this.childC||this.childD?(this.childA&&(r=r.concat(this.childA.cellsInBand(e,o,t))),this.childB&&(r=r.concat(this.childB.cellsInBand(e,o,t))),this.childD&&(r=r.concat(this.childD.cellsInBand(e,o,t))),this.childC&&(r=r.concat(this.childC.cellsInBand(e,o,t)))):(t||this.lowerBound<=e||this.upperBound>=o)&&r.push({x:this.x,y:this.y})),r},a.prototype.cellsBelowThreshold=function(e,o){var t=[];return o=void 0===o||o,this.lowerBound>e||(this.childA||this.childB||this.childC||this.childD?(this.childA&&(t=t.concat(this.childA.cellsBelowThreshold(e,o))),this.childB&&(t=t.concat(this.childB.cellsBelowThreshold(e,o))),this.childD&&(t=t.concat(this.childD.cellsBelowThreshold(e,o))),this.childC&&(t=t.concat(this.childC.cellsBelowThreshold(e,o)))):(o||this.upperBound>=e)&&t.push({x:this.x,y:this.y})),t},e.isoLines=o,e.isoContours=o,Object.defineProperty(e,"__esModule",{value:!0})});