Module morton

Module morton 

Source
Expand description

The fixed lookup grid.

Longitude and latitude are each mapped onto 16 bits and interleaved into a 32-bit Z-order key, so that a quadtree cell at any depth is one contiguous range of keys and a lookup is a single indexed query.

Every operation here has an exact counterpart in the Python builder (tools/regiondb-build/src/regiondb_build/morton.py). Both are written as the same two floating-point operations rather than in whichever idiom each language finds natural, because a position that lands in different cells on different platforms would be a lookup that disagrees with itself.

Enums§

MortonError
A coordinate that cannot be placed on the grid.

Constants§

GRID
Cells per axis at maximum depth.
MAX_DEPTH
Depth of the grid: 16 bits per axis, so cells are roughly 600 m by 300 m at the equator.

Functions§

cell_xy
Grid coordinates of the cell containing a position.
check_latitude
Validate latitude, which is clamped into the grid rather than wrapped.
interleave
Interleave two 16-bit values, x into the even bits.
key
The maximum-depth Morton key for a position.
normalize_longitude
Wrap longitude into [-180, 180).