New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

quadbin

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quadbin - npm Package Compare versions

Comparing version

to
0.1.6

test/data/PolygonAntimeridianGeometry.json

2

dist/umd/index.js

@@ -1,1 +0,1 @@

!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.quadbin=t():n.quadbin=t()}(this,(()=>(()=>{"use strict";var n={701:(n,t,e)=>{var o=e(768);function r(n){return{type:"Feature",geometry:o.tileToGeoJSON(n),properties:{}}}function f(n,t){var e,r,f=n.coordinates,u=t.max_zoom,s={},h=[];if("Point"===n.type)return[o.pointToTile(f[0],f[1],u)];if("MultiPoint"===n.type)for(e=0;e<f.length;e++)s[c((r=o.pointToTile(f[e][0],f[e][1],u))[0],r[1],r[2])]=!0;else if("LineString"===n.type)a(s,f,u);else if("MultiLineString"===n.type)for(e=0;e<f.length;e++)a(s,f[e],u);else if("Polygon"===n.type)i(s,h,f,u);else{if("MultiPolygon"!==n.type)throw new Error("Geometry type not implemented");for(e=0;e<f.length;e++)i(s,h,f[e],u)}if(t.min_zoom!==u){var p=h.length;for(l(s,h),e=0;e<p;e++){var v=h[e];s[c(v[0],v[1],v[2])]=!0}return function(n,t,e){for(var o=[],r=e.max_zoom;r>e.min_zoom;r--){for(var f={},i=[],u=0;u<t.length;u++){var a=t[u];if(a[0]%2==0&&a[1]%2==0){var l=c(a[0]+1,a[1],r),s=c(a[0],a[1]+1,r),h=c(a[0]+1,a[1]+1,r);if(n[l]&&n[s]&&n[h]){n[c(a[0],a[1],a[2])]=!1,n[l]=!1,n[s]=!1,n[h]=!1;var p=[a[0]/2,a[1]/2,r-1];r-1===e.min_zoom?o.push(p):(f[c(a[0]/2,a[1]/2,r-1)]=!0,i.push(p))}}}for(u=0;u<t.length;u++)n[c((a=t[u])[0],a[1],a[2])]&&o.push(a);n=f,t=i}return o}(s,h,t)}return l(s,h),h}function i(n,t,e,o){for(var r=[],f=0;f<e.length;f++){var i=[];a(n,e[f],o,i);for(var l=0,s=i.length,h=s-1;l<s;h=l++){var p=(l+1)%s,v=i[l][1];(v>i[h][1]||v>i[p][1])&&(v<i[h][1]||v<i[p][1])&&v!==i[p][1]&&r.push(i[l])}}for(r.sort(u),f=0;f<r.length;f+=2){v=r[f][1];for(var g=r[f][0]+1;g<r[f+1][0];g++)n[c(g,v,o)]||t.push([g,v,o])}}function u(n,t){return n[1]-t[1]||n[0]-t[0]}function a(n,t,e,r){for(var f,i,u=0;u<t.length-1;u++){var a=o.pointToTileFraction(t[u][0],t[u][1],e),l=o.pointToTileFraction(t[u+1][0],t[u+1][1],e),s=a[0],h=a[1],p=l[0]-s,v=l[1]-h;if(0!==v||0!==p){var g=p>0?1:-1,x=v>0?1:-1,T=Math.floor(s),m=Math.floor(h),y=0===p?1/0:Math.abs(((p>0?1:0)+T-s)/p),d=0===v?1/0:Math.abs(((v>0?1:0)+m-h)/v),M=Math.abs(g/p),b=Math.abs(x/v);for(T===f&&m===i||(n[c(T,m,e)]=!0,r&&m!==i&&r.push([T,m]),f=T,i=m);y<1||d<1;)y<d?(y+=M,T+=g):(d+=b,m+=x),n[c(T,m,e)]=!0,r&&m!==i&&r.push([T,m]),f=T,i=m}}r&&m===r[0][1]&&r.pop()}function l(n,t){for(var e,o,r,f,i,u=Object.keys(n),a=0;a<u.length;a++)t.push((void 0,void 0,void 0,void 0,[i=(f=((e=+u[a])-(o=e%32))/32)%(r=2*(1<<o)),(f-i)/r%r,o]))}function c(n,t,e){return 32*(2*(1<<e)*t+n)+e}t.geojson=function(n,t){return{type:"FeatureCollection",features:f(n,t).map(r)}},t.tiles=f,t.indexes=function(n,t){return f(n,t).map(o.tileToQuadkey)}},768:n=>{var t=Math.PI/180,e=180/Math.PI;function o(n){var t=r(n[0]+1,n[2]);return[r(n[0],n[2]),f(n[1]+1,n[2]),t,f(n[1],n[2])]}function r(n,t){return n/Math.pow(2,t)*360-180}function f(n,t){var o=Math.PI-2*Math.PI*n/Math.pow(2,t);return e*Math.atan(.5*(Math.exp(o)-Math.exp(-o)))}function i(n,t,e){var o=h(n,t,e);return o[0]=Math.floor(o[0]),o[1]=Math.floor(o[1]),o}function u(n){return[[2*n[0],2*n[1],n[2]+1],[2*n[0]+1,2*n[1],n[2]+1],[2*n[0]+1,2*n[1]+1,n[2]+1],[2*n[0],2*n[1]+1,n[2]+1]]}function a(n){return[n[0]>>1,n[1]>>1,n[2]-1]}function l(n){return u(a(n))}function c(n,t){for(var e=0;e<n.length;e++)if(s(n[e],t))return!0;return!1}function s(n,t){return n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]}function h(n,e,o){var r=Math.sin(e*t),f=Math.pow(2,o),i=f*(n/360+.5);return(i%=f)<0&&(i+=f),[i,f*(.5-.25*Math.log((1+r)/(1-r))/Math.PI),o]}n.exports={tileToGeoJSON:function(n){var t=o(n);return{type:"Polygon",coordinates:[[[t[0],t[3]],[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]]]]}},tileToBBOX:o,getChildren:u,getParent:a,getSiblings:l,hasTile:c,hasSiblings:function(n,t){for(var e=l(n),o=0;o<e.length;o++)if(!c(t,e[o]))return!1;return!0},tilesEqual:s,tileToQuadkey:function(n){for(var t="",e=n[2];e>0;e--){var o=0,r=1<<e-1;0!=(n[0]&r)&&o++,0!=(n[1]&r)&&(o+=2),t+=o.toString()}return t},quadkeyToTile:function(n){for(var t=0,e=0,o=n.length,r=o;r>0;r--){var f=1<<r-1,i=+n[o-r];1===i&&(t|=f),2===i&&(e|=f),3===i&&(t|=f,e|=f)}return[t,e,o]},pointToTile:i,bboxToTile:function(n){var t=i(n[0],n[1],32),e=i(n[2],n[3],32),o=[t[0],t[1],e[0],e[1]],r=function(n){for(var t=0;t<28;t++){var e=1<<32-(t+1);if((n[0]&e)!=(n[2]&e)||(n[1]&e)!=(n[3]&e))return t}return 28}(o);return 0===r?[0,0,0]:[o[0]>>>32-r,o[1]>>>32-r,r]},pointToTileFraction:h}}},t={};function e(o){var r=t[o];if(void 0!==r)return r.exports;var f=t[o]={exports:{}};return n[o](f,f.exports,e),f.exports}var o={};return(()=>{var n=o;Object.defineProperty(n,"__esModule",{value:!0}),n.geometryToCells=n.cellToParent=n.getResolution=n.cellToTile=n.tileToCell=n.bigIntToHex=n.hexToBigInt=void 0;const t=e(701),r=[0x5555555555555555n,0x3333333333333333n,0x0f0f0f0f0f0f0f0fn,0x00ff00ff00ff00ffn,0x0000ffff0000ffffn,0x00000000ffffffffn],f=[0n,1n,2n,4n,8n,16n];function i(n){if(n.z<0||n.z>26)throw new Error("Wrong zoom");const t=BigInt(n.z);let e=BigInt(n.x)<<32n-t,o=BigInt(n.y)<<32n-t;for(let n=0;n<5;n++){const t=f[5-n],i=r[4-n];e=(e|e<<t)&i,o=(o|o<<t)&i}return 0x4000000000000000n|1n<<59n|t<<52n|(e|o<<1n)>>12n|0xfffffffffffffn>>2n*t}function u(n){return n>>52n&0x1fn}n.hexToBigInt=function(n){return BigInt(`0x${n}`)},n.bigIntToHex=function(n){return n.toString(16)},n.tileToCell=i,n.cellToTile=function(n){const t=n>>52n&0x1fn,e=(0xfffffffffffffn&n)<<12n;if(1n!==(n>>59n&7n)&&0n!==(n>>57n&3n))throw new Error("Wrong mode");let o=e,i=e>>1n;for(let n=0;n<6;n++){const t=f[n],e=r[n];o=(o|o>>t)&e,i=(i|i>>t)&e}return o>>=32n-t,i>>=32n-t,{z:Number(t),x:Number(o),y:Number(i)}},n.getResolution=u,n.cellToParent=function(n){const t=u(n)-1n;return n&~(0x1fn<<52n)|t<<52n|0xfffffffffffffn>>2n*t},n.geometryToCells=function(n,e){const o=Number(e);return(0,t.tiles)(n,{min_zoom:o,max_zoom:o}).map((([n,t,e])=>i({x:n,y:t,z:e})))}})(),o})()));
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.quadbin=t():n.quadbin=t()}(this,(()=>(()=>{"use strict";var n={701:(n,t,e)=>{var o=e(768);function r(n){return{type:"Feature",geometry:o.tileToGeoJSON(n),properties:{}}}function f(n,t){var e,r,f=n.coordinates,u=t.max_zoom,s={},h=[];if("Point"===n.type)return[o.pointToTile(f[0],f[1],u)];if("MultiPoint"===n.type)for(e=0;e<f.length;e++)s[c((r=o.pointToTile(f[e][0],f[e][1],u))[0],r[1],r[2])]=!0;else if("LineString"===n.type)a(s,f,u);else if("MultiLineString"===n.type)for(e=0;e<f.length;e++)a(s,f[e],u);else if("Polygon"===n.type)i(s,h,f,u);else{if("MultiPolygon"!==n.type)throw new Error("Geometry type not implemented");for(e=0;e<f.length;e++)i(s,h,f[e],u)}if(t.min_zoom!==u){var p=h.length;for(l(s,h),e=0;e<p;e++){var v=h[e];s[c(v[0],v[1],v[2])]=!0}return function(n,t,e){for(var o=[],r=e.max_zoom;r>e.min_zoom;r--){for(var f={},i=[],u=0;u<t.length;u++){var a=t[u];if(a[0]%2==0&&a[1]%2==0){var l=c(a[0]+1,a[1],r),s=c(a[0],a[1]+1,r),h=c(a[0]+1,a[1]+1,r);if(n[l]&&n[s]&&n[h]){n[c(a[0],a[1],a[2])]=!1,n[l]=!1,n[s]=!1,n[h]=!1;var p=[a[0]/2,a[1]/2,r-1];r-1===e.min_zoom?o.push(p):(f[c(a[0]/2,a[1]/2,r-1)]=!0,i.push(p))}}}for(u=0;u<t.length;u++)n[c((a=t[u])[0],a[1],a[2])]&&o.push(a);n=f,t=i}return o}(s,h,t)}return l(s,h),h}function i(n,t,e,o){for(var r=[],f=0;f<e.length;f++){var i=[];a(n,e[f],o,i);for(var l=0,s=i.length,h=s-1;l<s;h=l++){var p=(l+1)%s,v=i[l][1];(v>i[h][1]||v>i[p][1])&&(v<i[h][1]||v<i[p][1])&&v!==i[p][1]&&r.push(i[l])}}for(r.sort(u),f=0;f<r.length;f+=2){v=r[f][1];for(var g=r[f][0]+1;g<r[f+1][0];g++)n[c(g,v,o)]||t.push([g,v,o])}}function u(n,t){return n[1]-t[1]||n[0]-t[0]}function a(n,t,e,r){for(var f,i,u=0;u<t.length-1;u++){var a=o.pointToTileFraction(t[u][0],t[u][1],e),l=o.pointToTileFraction(t[u+1][0],t[u+1][1],e),s=a[0],h=a[1],p=l[0]-s,v=l[1]-h;if(0!==v||0!==p){var g=p>0?1:-1,x=v>0?1:-1,T=Math.floor(s),m=Math.floor(h),y=0===p?1/0:Math.abs(((p>0?1:0)+T-s)/p),d=0===v?1/0:Math.abs(((v>0?1:0)+m-h)/v),M=Math.abs(g/p),b=Math.abs(x/v);for(T===f&&m===i||(n[c(T,m,e)]=!0,r&&m!==i&&r.push([T,m]),f=T,i=m);y<1||d<1;)y<d?(y+=M,T+=g):(d+=b,m+=x),n[c(T,m,e)]=!0,r&&m!==i&&r.push([T,m]),f=T,i=m}}r&&m===r[0][1]&&r.pop()}function l(n,t){for(var e,o,r,f,i,u=Object.keys(n),a=0;a<u.length;a++)t.push((void 0,void 0,void 0,void 0,[i=(f=((e=+u[a])-(o=e%32))/32)%(r=2*(1<<o)),(f-i)/r%r,o]))}function c(n,t,e){return 32*(2*(1<<e)*t+n)+e}t.geojson=function(n,t){return{type:"FeatureCollection",features:f(n,t).map(r)}},t.tiles=f,t.indexes=function(n,t){return f(n,t).map(o.tileToQuadkey)}},768:n=>{var t=Math.PI/180,e=180/Math.PI;function o(n){var t=r(n[0]+1,n[2]);return[r(n[0],n[2]),f(n[1]+1,n[2]),t,f(n[1],n[2])]}function r(n,t){return n/Math.pow(2,t)*360-180}function f(n,t){var o=Math.PI-2*Math.PI*n/Math.pow(2,t);return e*Math.atan(.5*(Math.exp(o)-Math.exp(-o)))}function i(n,t,e){var o=h(n,t,e);return o[0]=Math.floor(o[0]),o[1]=Math.floor(o[1]),o}function u(n){return[[2*n[0],2*n[1],n[2]+1],[2*n[0]+1,2*n[1],n[2]+1],[2*n[0]+1,2*n[1]+1,n[2]+1],[2*n[0],2*n[1]+1,n[2]+1]]}function a(n){return n[0]%2==0&&n[1]%2==0?[n[0]/2,n[1]/2,n[2]-1]:n[0]%2==0&&!n[1]%2==0?[n[0]/2,(n[1]-1)/2,n[2]-1]:!n[0]%2==0&&n[1]%2==0?[(n[0]-1)/2,n[1]/2,n[2]-1]:[(n[0]-1)/2,(n[1]-1)/2,n[2]-1]}function l(n){return u(a(n))}function c(n,t){for(var e=0;e<n.length;e++)if(s(n[e],t))return!0;return!1}function s(n,t){return n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]}function h(n,e,o){var r=Math.sin(e*t),f=Math.pow(2,o);return[f*(n/360+.5),f*(.5-.25*Math.log((1+r)/(1-r))/Math.PI),o]}n.exports={tileToGeoJSON:function(n){var t=o(n);return{type:"Polygon",coordinates:[[[t[0],t[1]],[t[0],t[3]],[t[2],t[3]],[t[2],t[1]],[t[0],t[1]]]]}},tileToBBOX:o,getChildren:u,getParent:a,getSiblings:l,hasTile:c,hasSiblings:function(n,t){for(var e=l(n),o=0;o<e.length;o++)if(!c(t,e[o]))return!1;return!0},tilesEqual:s,tileToQuadkey:function(n){for(var t="",e=n[2];e>0;e--){var o=0,r=1<<e-1;0!=(n[0]&r)&&o++,0!=(n[1]&r)&&(o+=2),t+=o.toString()}return t},quadkeyToTile:function(n){for(var t=0,e=0,o=n.length,r=o;r>0;r--){var f=1<<r-1,i=+n[o-r];1===i&&(t|=f),2===i&&(e|=f),3===i&&(t|=f,e|=f)}return[t,e,o]},pointToTile:i,bboxToTile:function(n){var t=i(n[0],n[1],32),e=i(n[2],n[3],32),o=[t[0],t[1],e[0],e[1]],r=function(n){for(var t=0;t<28;t++){var e=1<<32-(t+1);if((n[0]&e)!=(n[2]&e)||(n[1]&e)!=(n[3]&e))return t}return 28}(o);return 0===r?[0,0,0]:[o[0]>>>32-r,o[1]>>>32-r,r]},pointToTileFraction:h}}},t={};function e(o){var r=t[o];if(void 0!==r)return r.exports;var f=t[o]={exports:{}};return n[o](f,f.exports,e),f.exports}var o={};return(()=>{var n=o;Object.defineProperty(n,"__esModule",{value:!0}),n.geometryToCells=n.cellToParent=n.getResolution=n.cellToTile=n.tileToCell=n.bigIntToHex=n.hexToBigInt=void 0;const t=e(701),r=[0x5555555555555555n,0x3333333333333333n,0x0f0f0f0f0f0f0f0fn,0x00ff00ff00ff00ffn,0x0000ffff0000ffffn,0x00000000ffffffffn],f=[0n,1n,2n,4n,8n,16n];function i(n){if(n.z<0||n.z>26)throw new Error("Wrong zoom");const t=BigInt(n.z);let e=BigInt(n.x)<<32n-t,o=BigInt(n.y)<<32n-t;for(let n=0;n<5;n++){const t=f[5-n],i=r[4-n];e=(e|e<<t)&i,o=(o|o<<t)&i}return 0x4000000000000000n|1n<<59n|t<<52n|(e|o<<1n)>>12n|0xfffffffffffffn>>2n*t}function u(n){return n>>52n&0x1fn}n.hexToBigInt=function(n){return BigInt(`0x${n}`)},n.bigIntToHex=function(n){return n.toString(16)},n.tileToCell=i,n.cellToTile=function(n){const t=n>>52n&0x1fn,e=(0xfffffffffffffn&n)<<12n;if(1n!==(n>>59n&7n)&&0n!==(n>>57n&3n))throw new Error("Wrong mode");let o=e,i=e>>1n;for(let n=0;n<6;n++){const t=f[n],e=r[n];o=(o|o>>t)&e,i=(i|i>>t)&e}return o>>=32n-t,i>>=32n-t,{z:Number(t),x:Number(o),y:Number(i)}},n.getResolution=u,n.cellToParent=function(n){const t=u(n)-1n;return n&~(0x1fn<<52n)|t<<52n|0xfffffffffffffn>>2n*t},n.geometryToCells=function(n,e){const o=Number(e);return(0,t.tiles)(n,{min_zoom:o,max_zoom:o}).map((([n,t,e])=>i({x:n,y:t,z:e})))}})(),o})()));
{
"name": "quadbin",
"version": "0.1.5",
"version": "0.1.6",
"description": "Utility functions for working with Quadbins",

@@ -53,3 +53,6 @@ "license": "MIT",

"@mapbox/tile-cover": "^3.0.2"
},
"resolutions": {
"@mapbox/tilebelt": "1.0.1"
}
}

@@ -55,2 +55,3 @@ import test from 'tape';

import PolygonGeometry from './data/PolygonGeometry.json';
import PolygonAntimeridianGeometry from './data/PolygonAntimeridianGeometry.json';
import MultiPolygonGeometry from './data/MultiPolygonGeometry.json';

@@ -62,2 +63,3 @@ const testCases = [

PolygonGeometry,
PolygonAntimeridianGeometry,
MultiPolygonGeometry

@@ -64,0 +66,0 @@ ];