@thi.ng/morton
Advanced tools
Comparing version 2.0.25 to 2.0.26
@@ -6,2 +6,10 @@ # Change Log | ||
## [2.0.26](https://github.com/thi-ng/umbrella/compare/@thi.ng/morton@2.0.25...@thi.ng/morton@2.0.26) (2020-11-24) | ||
**Note:** Version bump only for package @thi.ng/morton | ||
## [2.0.25](https://github.com/thi-ng/umbrella/compare/@thi.ng/morton@2.0.24...@thi.ng/morton@2.0.25) (2020-09-22) | ||
@@ -8,0 +16,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/api"),require("@thi.ng/binary"),require("@thi.ng/math")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/api","@thi.ng/binary","@thi.ng/math"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.morton={}),e.thi.ng.api,e.thi.ng.binary,e.thi.ng.math)}(this,(function(e,t,n,o){"use strict";const i=e=>(e=1082401*(e=17043521*(e&=31)&270549121)&357564416)>>>20,r=e=>(e=153391689&((e=51130563&((e=50393103&((e=4278190335&((e&=1023)|e<<16))|e<<8))|e<<4))|e<<2))>>>0,s=e=>(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e&=65535)|e<<8))|e<<4))|e<<2))|e<<1))>>>0,d=e=>e=31&((e=271&((e=307&((e&=341)|e>>1))|e>>2))|e>>4),c=e=>e=1023&((e=4278190335&((e=50393103&((e=51130563&((e&=153391689)|e>>2))|e>>4))|e>>8))|e>>16),a=e=>e=65535&((e=16711935&((e=252645135&((e=858993459&((e&=1431655765)|e>>1))|e>>2))|e>>4))|e>>8),l=(e,i,r,s)=>(t.assert(o.inRange(e,i,r),`value ${e} not in range [${i}..${r}]`),Math.round(o.fit(e,i,r,0,n.MASKS[s]))),h=(e,t=0,n=1)=>r(l(e,t,n,10)),u=(e,t=0,n=1)=>s(l(e,t,n,16)),m=(e,t=0,n=1)=>o.fit01(c(e)/1023,t,n),p=(e,t=0,n=1)=>o.fit01(a(e)/65535,t,n),f=[0,0,0],g=[1,1,1],x=(e,t,n=0,o=1,i=n,r=o)=>(u(e,n,o)|u(t,i,r)<<1)>>>0,b=(e,t,n,o=0,i=1,r=o,s=i,d=o,c=i)=>(h(e,o,i)|h(t,r,s)<<1|h(n,d,c)<<2)>>>0,C=(e,t=0,n=1,o=t,i=n)=>[p(e,t,n),p(e>>>1,o,i)],S=(e,t=0,n=1,o=t,i=n,r=t,s=n)=>[m(e,t,n),m(e>>>1,o,i),m(e>>>2,r,s)],M=(e,t)=>{const n=[];for(let o=0,i=e[0]-1;o<t;o++)n[o]=1+(i>>>o&1);if(e.length<2)return n;const o=M(e.slice(1),t),i=1<<e.length-1,r=new Array(t);for(let e=0;e<t;e++)r[e]=i*(n[e]-1)+o[e];return r},B=BigInt(0),I=BigInt(1),w=BigInt(-1);class y{constructor(e,n,o){if(t.assert(e>=2,"unsupported dimensions"),t.assert(n>=1&&n<=32,"unsupported bits per component"),this.dim=e,this.bits=n,!o){o=[];for(let t=0;t<e;t++)o[t]=t}this.order=o,this.initMasks()}static encodeComponent(e,t,n,o,i=B){for(let r=t;--r>=0;)e>>>r&1&&(i|=I<<BigInt(r*n+o));return i}static decodeComponent(e,t,n,o){let i=0;for(let r=t;--r>=0;)e>>BigInt(r*n+o)&I&&(i|=1<<r);return i>>>0}encode(e){let t=B;const{dim:n,bits:o,order:i}=this;for(let r=n;--r>=0;)t=y.encodeComponent(e[r],o,n,i[r],t);return t}decode(e,t=[]){const{dim:n,bits:o,order:i}=this;for(let r=n;--r>=0;)t[r]=y.decodeComponent(e,o,n,i[r]);return t}split(e,t=[]){for(let n=this.dim;--n>=0;)t[n]=e&this.masks[n];return t}merge(e){let t=B;for(let n=e.length;--n>=0;)t|=e[n];return t}*range(e,t){const n=this.encode(e),o=this.encode(t),i=new Array(this.dim);let r=n;for(;r!==w;)this.decode(r,i),this.pointInBox(i,e,t)?(yield r,r++):r=this.bigMin(r,n,o)}bigMin(e,t,n){const o=this.dim;let i=w,r=o*this.bits-1,s=I<<BigInt(r);do{const d=t&s,c=n&s,a=1<<(r/o|0);if(e&s)if(d){if(!c)throw new Error("illegal BIGMIN state")}else{if(!c)return i;t=this.loadBits(a,r,t)}else if(!d&&c)i=this.loadBits(a,r,t),n=this.loadBits(a-1,r,n);else if(d){if(c)return t;throw new Error("illegal BIGMIN state")}r--,s>>=I}while(s);return i}pointInBox(e,t,n){for(let o=this.dim;--o>=0;){const i=e[o];if(i<t[o]||i>n[o])return!1}return!0}initMasks(){const{bits:e,dim:t,order:o}=this;this.masks=[];for(let i=t;--i>=0;)this.masks[i]=y.encodeComponent(n.MASKS[e],e,t,o[i]);this.wipeMasks=[];const i=(I<<BigInt(t*e))-I;for(let o=t*e;--o>=0;)this.wipeMasks[o]=y.encodeComponent(n.MASKS[e]>>>e-(1+(o/t|0)),e,t,o%t)^i}loadBits(e,t,n){const o=this.dim;return n&this.wipeMasks[t]|y.encodeComponent(e,this.bits,o,t%o)}}e.ZCurve=y,e.ZCurve2=class extends y{constructor(e,t){super(2,e,t)}encode(e){const{dim:t,bits:n,order:o}=this;return y.encodeComponent(e[1],n,t,o[1],y.encodeComponent(e[0],n,t,o[0]))}decode(e,t=[]){const{dim:n,bits:o,order:i}=this;return t[0]=y.decodeComponent(e,o,n,i[0]),t[1]=y.decodeComponent(e,o,n,i[1]),t}pointInBox(e,t,n){const o=e[0],i=e[1];return o>=t[0]&&o<=n[0]&&i>=t[1]&&i<=n[1]}},e.ZCurve3=class extends y{constructor(e,t){super(3,e,t)}encode(e){const{dim:t,bits:n,order:o}=this;return y.encodeComponent(e[2],n,t,o[2],y.encodeComponent(e[1],n,t,o[1],y.encodeComponent(e[0],n,t,o[0])))}decode(e,t=[]){const{dim:n,bits:o,order:i}=this;return t[0]=y.decodeComponent(e,o,n,i[0]),t[1]=y.decodeComponent(e,o,n,i[1]),t[2]=y.decodeComponent(e,o,n,i[2]),t}pointInBox(e,t,n){const o=e[0],i=e[1],r=e[2];return o>=t[0]&&o<=n[0]&&i>=t[1]&&i<=n[1]&&r>=t[2]&&r<=n[2]}},e.cartesianToTree=e=>{const t=(e,n)=>{const o=e.reduce((e,t,o)=>e+(1<<o)*(t>n),1);return n>1?[o,...t(e.map(e=>(e-1)%n+1),n>>>1)]:[o]};return t(e,Math.max(2,n.ceilPow2(Math.max(...e)))>>>1)},e.decode10=c,e.decode16=a,e.decode5=d,e.decodeScaled10=m,e.decodeScaled16=p,e.decodeScaled5=(e,t=0,n=1)=>o.fit01(d(e)/31,t,n),e.demux2=e=>[a(e),a(e>>>1)],e.demux3=e=>[c(e),c(e>>>1),c(e>>>2)],e.demuxScaled2=C,e.demuxScaled2v=(e,t=f,n=g)=>C(e,t[0],n[0],t[1],n[1]),e.demuxScaled3=S,e.demuxScaled3v=(e,t=f,n=g)=>S(e,t[0],n[0],t[1],n[1],t[2],n[2]),e.encode10=r,e.encode16=s,e.encode5=i,e.encodeScaled10=h,e.encodeScaled16=u,e.encodeScaled5=(e,t=0,n=1)=>i(l(e,t,n,5)),e.mortonToTree=(e,t)=>{const n=[];for(t=1<<t;;){const o=1+(--e/t|0),i=e%t+1;if(n.unshift(i),1===o)break;e=o}return n},e.mux2=(e,t)=>(s(e)|s(t)<<1)>>>0,e.mux3=(e,t,n)=>(r(e)|r(t)<<1|r(n)<<2)>>>0,e.muxScaled2=x,e.muxScaled2v=(e,t=f,n=g)=>x(e[0],e[1],t[0],n[0],t[1],n[1]),e.muxScaled3=b,e.muxScaled3v=(e,t=f,n=g)=>b(e[0],e[1],e[2],t[0],n[0],t[1],n[1],t[2],n[2]),e.treeToCartesian=M,e.treeToMorton=(e,t)=>{let n=0,o=0,i=e.length;for(t=1<<t;--i>=0;)o+=(e[i]-1)*Math.pow(t,n),n++;return o+1},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/api"),require("@thi.ng/binary"),require("@thi.ng/math")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/api","@thi.ng/binary","@thi.ng/math"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.morton={}),e.thi.ng.api,e.thi.ng.binary,e.thi.ng.math)}(this,(function(e,t,n,o){"use strict";const i=e=>(e=1082401*(e=17043521*(e&=31)&270549121)&357564416)>>>20,r=e=>(e=153391689&((e=51130563&((e=50393103&((e=4278190335&((e&=1023)|e<<16))|e<<8))|e<<4))|e<<2))>>>0,s=e=>(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e&=65535)|e<<8))|e<<4))|e<<2))|e<<1))>>>0,d=e=>e=31&((e=271&((e=307&((e&=341)|e>>1))|e>>2))|e>>4),c=e=>e=1023&((e=4278190335&((e=50393103&((e=51130563&((e&=153391689)|e>>2))|e>>4))|e>>8))|e>>16),a=e=>e=65535&((e=16711935&((e=252645135&((e=858993459&((e&=1431655765)|e>>1))|e>>2))|e>>4))|e>>8),l=(e,i,r,s)=>(t.assert(o.inRange(e,i,r),`value ${e} not in range [${i}..${r}]`),Math.round(o.fit(e,i,r,0,n.MASKS[s]))),h=(e,t=0,n=1)=>r(l(e,t,n,10)),u=(e,t=0,n=1)=>s(l(e,t,n,16)),m=(e,t=0,n=1)=>o.fit01(c(e)/1023,t,n),p=(e,t=0,n=1)=>o.fit01(a(e)/65535,t,n),f=[0,0,0],g=[1,1,1],x=(e,t,n=0,o=1,i=n,r=o)=>(u(e,n,o)|u(t,i,r)<<1)>>>0,b=(e,t,n,o=0,i=1,r=o,s=i,d=o,c=i)=>(h(e,o,i)|h(t,r,s)<<1|h(n,d,c)<<2)>>>0,C=(e,t=0,n=1,o=t,i=n)=>[p(e,t,n),p(e>>>1,o,i)],S=(e,t=0,n=1,o=t,i=n,r=t,s=n)=>[m(e,t,n),m(e>>>1,o,i),m(e>>>2,r,s)],M=(e,t)=>{const n=[];for(let o=0,i=e[0]-1;o<t;o++)n[o]=1+(i>>>o&1);if(e.length<2)return n;const o=M(e.slice(1),t),i=1<<e.length-1,r=new Array(t);for(let e=0;e<t;e++)r[e]=i*(n[e]-1)+o[e];return r},B=BigInt(0),I=BigInt(1),w=BigInt(-1);class y{constructor(e,n,o){if(t.assert(e>=2,"unsupported dimensions"),t.assert(n>=1&&n<=32,"unsupported bits per component"),this.dim=e,this.bits=n,!o){o=[];for(let t=0;t<e;t++)o[t]=t}this.order=o,this.initMasks()}static encodeComponent(e,t,n,o,i=B){for(let r=t;--r>=0;)e>>>r&1&&(i|=I<<BigInt(r*n+o));return i}static decodeComponent(e,t,n,o){let i=0;for(let r=t;--r>=0;)e>>BigInt(r*n+o)&I&&(i|=1<<r);return i>>>0}encode(e){let t=B;const{dim:n,bits:o,order:i}=this;for(let r=n;--r>=0;)t=y.encodeComponent(e[r],o,n,i[r],t);return t}decode(e,t=[]){const{dim:n,bits:o,order:i}=this;for(let r=n;--r>=0;)t[r]=y.decodeComponent(e,o,n,i[r]);return t}split(e,t=[]){for(let n=this.dim;--n>=0;)t[n]=e&this.masks[n];return t}merge(e){let t=B;for(let n=e.length;--n>=0;)t|=e[n];return t}*range(e,t){const n=this.encode(e),o=this.encode(t),i=new Array(this.dim);let r=n;for(;r!==w;)this.decode(r,i),this.pointInBox(i,e,t)?(yield r,r++):r=this.bigMin(r,n,o)}bigMin(e,t,n){const o=this.dim;let i=w,r=o*this.bits-1,s=I<<BigInt(r);do{const d=t&s,c=n&s,a=1<<(r/o|0);if(e&s)if(d){if(!c)throw new Error("illegal BIGMIN state")}else{if(!c)return i;t=this.loadBits(a,r,t)}else if(!d&&c)i=this.loadBits(a,r,t),n=this.loadBits(a-1,r,n);else if(d){if(c)return t;throw new Error("illegal BIGMIN state")}r--,s>>=I}while(s);return i}pointInBox(e,t,n){for(let o=this.dim;--o>=0;){const i=e[o];if(i<t[o]||i>n[o])return!1}return!0}initMasks(){const{bits:e,dim:t,order:o}=this;this.masks=[];for(let i=t;--i>=0;)this.masks[i]=y.encodeComponent(n.MASKS[e],e,t,o[i]);this.wipeMasks=[];const i=(I<<BigInt(t*e))-I;for(let o=t*e;--o>=0;)this.wipeMasks[o]=y.encodeComponent(n.MASKS[e]>>>e-(1+(o/t|0)),e,t,o%t)^i}loadBits(e,t,n){const o=this.dim;return n&this.wipeMasks[t]|y.encodeComponent(e,this.bits,o,t%o)}}e.ZCurve=y,e.ZCurve2=class extends y{constructor(e,t){super(2,e,t)}encode(e){const{dim:t,bits:n,order:o}=this;return y.encodeComponent(e[1],n,t,o[1],y.encodeComponent(e[0],n,t,o[0]))}decode(e,t=[]){const{dim:n,bits:o,order:i}=this;return t[0]=y.decodeComponent(e,o,n,i[0]),t[1]=y.decodeComponent(e,o,n,i[1]),t}pointInBox(e,t,n){const o=e[0],i=e[1];return o>=t[0]&&o<=n[0]&&i>=t[1]&&i<=n[1]}},e.ZCurve3=class extends y{constructor(e,t){super(3,e,t)}encode(e){const{dim:t,bits:n,order:o}=this;return y.encodeComponent(e[2],n,t,o[2],y.encodeComponent(e[1],n,t,o[1],y.encodeComponent(e[0],n,t,o[0])))}decode(e,t=[]){const{dim:n,bits:o,order:i}=this;return t[0]=y.decodeComponent(e,o,n,i[0]),t[1]=y.decodeComponent(e,o,n,i[1]),t[2]=y.decodeComponent(e,o,n,i[2]),t}pointInBox(e,t,n){const o=e[0],i=e[1],r=e[2];return o>=t[0]&&o<=n[0]&&i>=t[1]&&i<=n[1]&&r>=t[2]&&r<=n[2]}},e.cartesianToTree=e=>{const t=(e,n)=>{const o=e.reduce(((e,t,o)=>e+(1<<o)*(t>n)),1);return n>1?[o,...t(e.map((e=>(e-1)%n+1)),n>>>1)]:[o]};return t(e,Math.max(2,n.ceilPow2(Math.max(...e)))>>>1)},e.decode10=c,e.decode16=a,e.decode5=d,e.decodeScaled10=m,e.decodeScaled16=p,e.decodeScaled5=(e,t=0,n=1)=>o.fit01(d(e)/31,t,n),e.demux2=e=>[a(e),a(e>>>1)],e.demux3=e=>[c(e),c(e>>>1),c(e>>>2)],e.demuxScaled2=C,e.demuxScaled2v=(e,t=f,n=g)=>C(e,t[0],n[0],t[1],n[1]),e.demuxScaled3=S,e.demuxScaled3v=(e,t=f,n=g)=>S(e,t[0],n[0],t[1],n[1],t[2],n[2]),e.encode10=r,e.encode16=s,e.encode5=i,e.encodeScaled10=h,e.encodeScaled16=u,e.encodeScaled5=(e,t=0,n=1)=>i(l(e,t,n,5)),e.mortonToTree=(e,t)=>{const n=[];for(t=1<<t;;){const o=1+(--e/t|0),i=e%t+1;if(n.unshift(i),1===o)break;e=o}return n},e.mux2=(e,t)=>(s(e)|s(t)<<1)>>>0,e.mux3=(e,t,n)=>(r(e)|r(t)<<1|r(n)<<2)>>>0,e.muxScaled2=x,e.muxScaled2v=(e,t=f,n=g)=>x(e[0],e[1],t[0],n[0],t[1],n[1]),e.muxScaled3=b,e.muxScaled3v=(e,t=f,n=g)=>b(e[0],e[1],e[2],t[0],n[0],t[1],n[1],t[2],n[2]),e.treeToCartesian=M,e.treeToMorton=(e,t)=>{let n=0,o=0,i=e.length;for(t=1<<t;--i>=0;)o+=(e[i]-1)*Math.pow(t,n),n++;return o+1},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@thi.ng/morton", | ||
"version": "2.0.25", | ||
"version": "2.0.26", | ||
"description": "Z-order curve / Morton encoding, decoding & range extraction for arbitrary dimensions", | ||
@@ -42,15 +42,15 @@ "module": "./index.js", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@microsoft/api-extractor": "^7.9.11", | ||
"@microsoft/api-extractor": "^7.12.0", | ||
"@types/mocha": "^8.0.3", | ||
"@types/node": "^14.6.1", | ||
"mocha": "^8.1.2", | ||
"mocha": "^8.2.1", | ||
"nyc": "^15.1.0", | ||
"ts-node": "^9.0.0", | ||
"typedoc": "^0.18.0", | ||
"typescript": "^4.0.2" | ||
"typedoc": "^0.19.2", | ||
"typescript": "^4.1.2" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/api": "^6.13.1", | ||
"@thi.ng/binary": "^2.0.16", | ||
"@thi.ng/math": "^2.1.1" | ||
"@thi.ng/api": "^6.13.2", | ||
"@thi.ng/binary": "^2.0.17", | ||
"@thi.ng/math": "^2.2.0" | ||
}, | ||
@@ -63,5 +63,10 @@ "files": [ | ||
"keywords": [ | ||
"2d", | ||
"3d", | ||
"acceleration", | ||
"bbox", | ||
"bigint", | ||
"binary", | ||
"bbox", | ||
"conversion", | ||
"datastructure", | ||
"decode", | ||
@@ -73,4 +78,4 @@ "encode", | ||
"query", | ||
"sort", | ||
"spatial", | ||
"sort", | ||
"typescript", | ||
@@ -90,3 +95,3 @@ "z-curve" | ||
}, | ||
"gitHead": "130dff672b56f789205177c2243169d33d479948" | ||
"gitHead": "3a89bdfa4c58983d5e005b3e9fb056b0351198fe" | ||
} |
Sorry, the diff of this file is not supported yet
97149
Updated@thi.ng/api@^6.13.2
Updated@thi.ng/binary@^2.0.17
Updated@thi.ng/math@^2.2.0