lliiun-z / MortonLib

Java library to encode/decode Morton codes (Z-order curve)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MortonLib

Java library to encode/decode Morton codes (Z-order curve). The library maps 2D/3D data to one dimension. This encoding can be used to store the data in various data structures (hash tables, B-trees, ..). The Z-ordering is often used to build quadtrees of point sets.

More information: Z-order curve

Usage

Morton2D mortonTest = new Morton2D();

//range for (x,y) is (0,0) to (16777215,16777215) 
long mortonCode = mortonTest.encode(15, 3);          // => 95

int[] xy = mortonTest.decode(mortonCode); 			// => [15,3]
Morton3D mortonTest = new Morton3D();

//range for (x,y,z) is (0,0,0) to (2097151,2097151,2097151) 
long mortonCode = mortonTest.encode(15, 15, 15); //4095

int xyz[] = mortonTest.decode(mortonCode); // => [15,15,15]

Source

Bit Twiddling Hacks

libmorton

License

MIT licensed

About

Java library to encode/decode Morton codes (Z-order curve)

License:MIT License


Languages

Language:Java 100.0%