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

@thi.ng/morton

Package Overview
Dependencies
Maintainers
1
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/morton - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [1.1.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/morton@1.1.1...@thi.ng/morton@1.1.2) (2019-07-31)
**Note:** Version bump only for package @thi.ng/morton
## [1.1.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/morton@1.1.0...@thi.ng/morton@1.1.1) (2019-07-12)

@@ -8,0 +16,0 @@

165

lib/index.umd.js

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

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@thi.ng/binary'), require('@thi.ng/errors'), require('@thi.ng/math')) :
typeof define === 'function' && define.amd ? define(['exports', '@thi.ng/binary', '@thi.ng/errors', '@thi.ng/math'], factory) :
(global = global || self, factory((global.thi = global.thi || {}, global.thi.ng = global.thi.ng || {}, global.thi.ng.morton = {}), global.thi.ng.binary, global.thi.ng.errors, global.thi.ng.math));
}(this, function (exports, binary, errors, math) { 'use strict';
const MIN = [0, 0, 0];
const MAX = [1, 1, 1];
const encode5 = (x) => {
x &= 0x0000001f;
x = (x * 0x01041041) & 0x10204081;
x = (x * 0x00108421) & 0x15500000;
return x >>> 20;
};
const encode10 = (x) => {
x &= 0x000003ff;
x = (x | (x << 16)) & 0xff0000ff;
x = (x | (x << 8)) & 0x0300f00f;
x = (x | (x << 4)) & 0x030c30c3;
x = (x | (x << 2)) & 0x09249249;
return x >>> 0;
};
const encode16 = (x) => {
x &= 0x0000ffff;
x = (x | (x << 8)) & 0x00ff00ff;
x = (x | (x << 4)) & 0x0f0f0f0f;
x = (x | (x << 2)) & 0x33333333;
x = (x | (x << 1)) & 0x55555555;
return x >>> 0;
};
const decode5 = (x) => {
x &= 0x00000155;
x = (x | (x >> 1)) & 0x00000133;
x = (x | (x >> 2)) & 0x0000010f;
x = (x | (x >> 4)) & 0x0000001f;
return x;
};
const decode10 = (x) => {
x &= 0x09249249;
x = (x | (x >> 2)) & 0x030c30c3;
x = (x | (x >> 4)) & 0x0300f00f;
x = (x | (x >> 8)) & 0xff0000ff;
x = (x | (x >> 16)) & 0x000003ff;
return x;
};
const decode16 = (x) => {
x &= 0x55555555;
x = (x | (x >> 1)) & 0x33333333;
x = (x | (x >> 2)) & 0x0f0f0f0f;
x = (x | (x >> 4)) & 0x00ff00ff;
x = (x | (x >> 8)) & 0x0000ffff;
return x;
};
const prescale = (x, min, max, bits) => !math.inRange(x, min, max)
? errors.illegalArgs(`value ${x} not in range [${min}..${max}]`)
: Math.round(math.fit(x, min, max, 0, binary.MASKS[bits]));
const encodeScaled5 = (x, min = 0, max = 1) => encode5(prescale(x, min, max, 5));
const encodeScaled10 = (x, min = 0, max = 1) => encode10(prescale(x, min, max, 10));
const encodeScaled16 = (x, min = 0, max = 1) => encode16(prescale(x, min, max, 16));
const decodeScaled5 = (x, min = 0, max = 1) => math.fit01(decode5(x) / 0x1f, min, max);
const decodeScaled10 = (x, min = 0, max = 1) => math.fit01(decode10(x) / 0x3ff, min, max);
const decodeScaled16 = (x, min = 0, max = 1) => math.fit01(decode16(x) / 0xffff, min, max);
const mux2 = (x, y) => (encode16(x) | (encode16(y) << 1)) >>> 0;
const mux3 = (x, y, z) => (encode10(x) | (encode10(y) << 1) | (encode10(z) << 2)) >>> 0;
const demux2 = (n) => [decode16(n), decode16(n >>> 1)];
const demux3 = (n) => [
decode10(n),
decode10(n >>> 1),
decode10(n >>> 2)
];
const muxScaled2 = (x, y, minx = 0, maxx = 1, miny = minx, maxy = maxx) => (encodeScaled16(x, minx, maxx) | (encodeScaled16(y, miny, maxy) << 1)) >>>
0;
const muxScaled3 = (x, y, z, minx = 0, maxx = 1, miny = minx, maxy = maxx, minz = minx, maxz = maxx) => (encodeScaled10(x, minx, maxx) |
(encodeScaled10(y, miny, maxy) << 1) |
(encodeScaled10(z, minz, maxz) << 2)) >>>
0;
const demuxScaled2 = (n, minx = 0, maxx = 1, miny = minx, maxy = maxx) => [decodeScaled16(n, minx, maxx), decodeScaled16(n >>> 1, miny, maxy)];
const demuxScaled3 = (n, minx = 0, maxx = 1, miny = minx, maxy = maxx, minz = minx, maxz = maxx) => [
decodeScaled10(n, minx, maxx),
decodeScaled10(n >>> 1, miny, maxy),
decodeScaled10(n >>> 2, minz, maxz)
];
const muxScaled2v = (v, min = MIN, max = MAX) => muxScaled2(v[0], v[1], min[0], max[0], min[1], max[1]);
const muxScaled3v = (v, min = MIN, max = MAX) => muxScaled3(v[0], v[1], v[2], min[0], max[0], min[1], max[1], min[2], max[2]);
const demuxScaled2v = (n, min = MIN, max = MAX) => demuxScaled2(n, min[0], max[0], min[1], max[1]);
const demuxScaled3v = (n, min = MIN, max = MAX) => demuxScaled3(n, min[0], max[0], min[1], max[1], min[2], max[2]);
const treeToMorton = (t, dim) => {
let n = 0;
let m = 0;
let l = t.length;
dim = 1 << dim;
while (--l >= 0) {
m += t[l] * Math.pow(dim, n);
n++;
}
return m;
};
const mortonToTree = (m, dim) => {
const t = [];
dim = 1 << dim;
while (true) {
const d = Math.floor(m / dim);
t.unshift(m % dim);
if (!d)
break;
m = d;
}
return t;
};
const treeToCartesian = (t, dim) => {
const c = [];
for (let i = 0, x = t[0]; i < dim; i++) {
c[i] = (x >>> i) & 1;
}
if (t.length < 2)
return c;
const cn = treeToCartesian(t.slice(1), 2);
const m = 1 << (t.length - 1);
const res = new Array(dim);
for (let i = 0; i < dim; i++) {
res[i] = m * c[i] + cn[i];
}
return res;
};
const cartesianToTree = (v) => {
const $ = (v, half) => {
const t = v.reduce((t, x, i) => t + (1 << i) * (x >= half), 0);
return half > 1 ? [t, ...$(v.map((x) => x % half), half >>> 1)] : [t];
};
return $(v, Math.max(2, binary.ceilPow2(Math.max(...v) + 1)) >> 1);
};
exports.cartesianToTree = cartesianToTree;
exports.decode10 = decode10;
exports.decode16 = decode16;
exports.decode5 = decode5;
exports.decodeScaled10 = decodeScaled10;
exports.decodeScaled16 = decodeScaled16;
exports.decodeScaled5 = decodeScaled5;
exports.demux2 = demux2;
exports.demux3 = demux3;
exports.demuxScaled2 = demuxScaled2;
exports.demuxScaled2v = demuxScaled2v;
exports.demuxScaled3 = demuxScaled3;
exports.demuxScaled3v = demuxScaled3v;
exports.encode10 = encode10;
exports.encode16 = encode16;
exports.encode5 = encode5;
exports.encodeScaled10 = encodeScaled10;
exports.encodeScaled16 = encodeScaled16;
exports.encodeScaled5 = encodeScaled5;
exports.mortonToTree = mortonToTree;
exports.mux2 = mux2;
exports.mux3 = mux3;
exports.muxScaled2 = muxScaled2;
exports.muxScaled2v = muxScaled2v;
exports.muxScaled3 = muxScaled3;
exports.muxScaled3v = muxScaled3v;
exports.treeToCartesian = treeToCartesian;
exports.treeToMorton = treeToMorton;
Object.defineProperty(exports, '__esModule', { value: true });
}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/binary"),require("@thi.ng/errors"),require("@thi.ng/math")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/binary","@thi.ng/errors","@thi.ng/math"],t):t(((e=e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.morton={}),e.thi.ng.binary,e.thi.ng.errors,e.thi.ng.math)}(this,function(e,t,n,r){"use strict";const o=[0,0,0],d=[1,1,1],i=e=>(e=1082401*(e=17043521*(e&=31)&270549121)&357564416)>>>20,c=e=>(e=153391689&((e=51130563&((e=50393103&((e=4278190335&((e&=1023)|e<<16))|e<<8))|e<<4))|e<<2))>>>0,a=e=>(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e&=65535)|e<<8))|e<<4))|e<<2))|e<<1))>>>0,u=e=>e=31&((e=271&((e=307&((e&=341)|e>>1))|e>>2))|e>>4),l=e=>e=1023&((e=4278190335&((e=50393103&((e=51130563&((e&=153391689)|e>>2))|e>>4))|e>>8))|e>>16),h=e=>e=65535&((e=16711935&((e=252645135&((e=858993459&((e&=1431655765)|e>>1))|e>>2))|e>>4))|e>>8),f=(e,o,d,i)=>r.inRange(e,o,d)?Math.round(r.fit(e,o,d,0,t.MASKS[i])):n.illegalArgs(`value ${e} not in range [${o}..${d}]`),s=(e,t=0,n=1)=>c(f(e,t,n,10)),m=(e,t=0,n=1)=>a(f(e,t,n,16)),g=(e,t=0,n=1)=>r.fit01(l(e)/1023,t,n),x=(e,t=0,n=1)=>r.fit01(h(e)/65535,t,n),S=(e,t,n=0,r=1,o=n,d=r)=>(m(e,n,r)|m(t,o,d)<<1)>>>0,p=(e,t,n,r=0,o=1,d=r,i=o,c=r,a=o)=>(s(e,r,o)|s(t,d,i)<<1|s(n,c,a)<<2)>>>0,y=(e,t=0,n=1,r=t,o=n)=>[x(e,t,n),x(e>>>1,r,o)],M=(e,t=0,n=1,r=t,o=n,d=t,i=n)=>[g(e,t,n),g(e>>>1,r,o),g(e>>>2,d,i)],b=(e,t)=>{const n=[];for(let r=0,o=e[0];r<t;r++)n[r]=o>>>r&1;if(e.length<2)return n;const r=b(e.slice(1),2),o=1<<e.length-1,d=new Array(t);for(let e=0;e<t;e++)d[e]=o*n[e]+r[e];return d};e.cartesianToTree=e=>{const n=(e,t)=>{const r=e.reduce((e,n,r)=>e+(1<<r)*(n>=t),0);return t>1?[r,...n(e.map(e=>e%t),t>>>1)]:[r]};return n(e,Math.max(2,t.ceilPow2(Math.max(...e)+1))>>1)},e.decode10=l,e.decode16=h,e.decode5=u,e.decodeScaled10=g,e.decodeScaled16=x,e.decodeScaled5=(e,t=0,n=1)=>r.fit01(u(e)/31,t,n),e.demux2=e=>[h(e),h(e>>>1)],e.demux3=e=>[l(e),l(e>>>1),l(e>>>2)],e.demuxScaled2=y,e.demuxScaled2v=(e,t=o,n=d)=>y(e,t[0],n[0],t[1],n[1]),e.demuxScaled3=M,e.demuxScaled3v=(e,t=o,n=d)=>M(e,t[0],n[0],t[1],n[1],t[2],n[2]),e.encode10=c,e.encode16=a,e.encode5=i,e.encodeScaled10=s,e.encodeScaled16=m,e.encodeScaled5=(e,t=0,n=1)=>i(f(e,t,n,5)),e.mortonToTree=(e,t)=>{const n=[];for(t=1<<t;;){const r=Math.floor(e/t);if(n.unshift(e%t),!r)break;e=r}return n},e.mux2=(e,t)=>(a(e)|a(t)<<1)>>>0,e.mux3=(e,t,n)=>(c(e)|c(t)<<1|c(n)<<2)>>>0,e.muxScaled2=S,e.muxScaled2v=(e,t=o,n=d)=>S(e[0],e[1],t[0],n[0],t[1],n[1]),e.muxScaled3=p,e.muxScaled3v=(e,t=o,n=d)=>p(e[0],e[1],e[2],t[0],n[0],t[1],n[1],t[2],n[2]),e.treeToCartesian=b,e.treeToMorton=(e,t)=>{let n=0,r=0,o=e.length;for(t=1<<t;--o>=0;)r+=e[o]*Math.pow(t,n),n++;return r},Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "@thi.ng/morton",
"version": "1.1.1",
"version": "1.1.2",
"description": "Z-order-curve / Morton encoding & decoding for 1D, 2D, 3D",

@@ -17,23 +17,24 @@ "module": "./index.js",

"scripts": {
"build": "yarn clean && yarn build:es6 && yarn build:bundle",
"build": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module",
"build:release": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module all",
"build:es6": "tsc --declaration",
"build:bundle": "../../scripts/bundle-module",
"test": "rimraf build && tsc -p test/tsconfig.json && nyc mocha build/test/*.js",
"build:test": "rimraf build && tsc -p test/tsconfig.json",
"test": "yarn build:test && mocha build/test/*.js",
"cover": "yarn build:test && nyc mocha build/test/*.js && nyc report --reporter=lcov",
"clean": "rimraf *.js *.d.ts .nyc_output build coverage doc lib",
"cover": "yarn test && nyc report --reporter=lcov",
"doc": "node_modules/.bin/typedoc --mode modules --out doc --ignoreCompilerErrors src",
"pub": "yarn build && yarn publish --access public"
"pub": "yarn build:release && yarn publish --access public"
},
"devDependencies": {
"@types/mocha": "^5.2.6",
"@types/node": "^12.0.8",
"@types/node": "^12.6.3",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"typedoc": "^0.14.2",
"typescript": "^3.5.2"
"typescript": "^3.5.3"
},
"dependencies": {
"@thi.ng/binary": "^1.0.8",
"@thi.ng/errors": "^1.1.1",
"@thi.ng/math": "^1.4.1"
"@thi.ng/binary": "^1.1.0",
"@thi.ng/errors": "^1.1.2",
"@thi.ng/math": "^1.4.2"
},

@@ -53,3 +54,3 @@ "keywords": [

"sideEffects": false,
"gitHead": "47075afc37f3a16adee7c903a2935304c7cf5daf"
"gitHead": "53eec7988c378fc37ae140e7174f36ef9b6208fe"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc