NAME
ttypt/morton.h - Morton code (Z-order) encoding and decoding utilities.
SYNOPSIS
#include <stdint.h>
#include <limits.h>
Functions
Encode multi-dimensional coordinates into Morton codes.
Encode a 2D point. See morton_set_1() for the family docs.
Encode a 3D point. See morton_set_1() for the family docs.
Encode a 4D point. See morton_set_1() for the family docs.
Encode a 2D x 32-bit point. Dense full-64-bit layout (2 x 32 bits); part of the dense config family, not the legacy 16-bit-lane sparse layout that morton_set_2() uses.
Decode a Morton code into a multi-dimensional coordinate.
Decode a 2D Morton code. See morton_get_1() for the family docs.
Decode a 3D Morton code. See morton_get_1() for the family docs.
Decode a 4D Morton code. See morton_get_1() for the family docs.
Decode a 2D x 32-bit Morton code. Inverse of morton_set_2_32().
Detailed Description
Morton code (Z-order) encoding and decoding utilities.
Morton codes, also known as Z-order codes, are a way to map multi-dimensional coordinates to a single dimension while preserving spatial locality. They interleave the binary representations of each coordinate dimension, creating a space-filling curve that visits all points in a recursive Z pattern.
Benefits:
- Preserves spatial locality: nearby points in N-D space have nearby Morton codes
- Enables efficient range queries on 1D data structures (hash tables, B-trees)
- Simple bitwise operations for encoding/decoding
This implementation is optimized for 3D coordinates (int16_t per dimension) and produces 64-bit Morton codes (48 bits used for 3D, 16 bits reserved). 4D coordinates use a dense stride-4 packing that fills all 64 bits. The 2D x 32-bit config (int32_t per dimension) is the dense stride-2 partner: 2 x 32 = 64 bits, no reserved bits.
Prefer the config objects (pointcfg.h: Point1_2..Point4_2, Point2_4) in application code; these inlines remain the tight-loop fast path.
References:
- Morton, G.M. (1966). "A computer Oriented Geodetic Data Base"
- http://www.vision-tools.com/h-tropf/multidimensionalrangequery.pdf
- https://en.wikipedia.org/wiki/Z-order_curve
See also
Islet core API
Author
Generated automatically by Doxygen for islet from the source code.