Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.
/ node-morton Public archive
forked from kkaefer/node-morton

Calculates morton numbers for spatial indexing

License

Notifications You must be signed in to change notification settings

mapbox/node-morton

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

NAME

node-morton - Calculates morton numbers and Z-order codes for spatial indexing.

USAGE

Install with npm install morton.

var morton = require('morton');

morton(32, 436);          // => 167456

morton.code(1, 0, 1);     // => 140737488355328
morton.code(2, 0, 2);     // => 140737488355328
morton.code(3, 0, 4);     // => 140737488355328
morton.code(4, 0, 8);     // => 140737488355328

morton.range(1, 0, 0);    // => [              0,   70368744177663 ]
morton.range(1, 1, 0);    // => [  70368744177664, 140737488355327 ]
morton.range(1, 0, 1);    // => [ 140737488355328, 211106232532991 ]
morton.range(1, 1, 1);    // => [ 211106232532992, 281474976710655 ]

Note: input numbers must be smaller than 2^24 (16777216). Since the resulting output has twice as many bits, you'll get back numbers that are up to 2^48 (281474976710656). JavaScript can still represent these numbers without losing precision, however, you can't use bitwise operators on these numbers if your input numbers are potentially bigger than 2^15 (32768) because JavaScript only supports bitwise operators on 32 bit signed integers.

morton.code(z, x, y) returns a 48-bit Z-order code.

morton.range(z, x, y) will return an array of the lower and upper bound of the Z-order rectangle. See also Z-order curves in Wikipedia.

[x, y] = morton.reverse(c) reverses c = morton(x, y).

[x, y] = morton.decode(z, c) reverses c = morton.code(z, x, y).

TESTS

npm install
npm test

CONTRIBUTORS

ACKNOWLEDGEMENTS

Thanks to Sean Eron Anderson for his Bit Twiddling Hacks page.

LICENSE

node-morton is BSD licensed.

About

Calculates morton numbers for spatial indexing

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%