Expand description
Variable-precision geographic location encoding.
NodeLocation represents a geographic position as a 1–7 byte grid code.
Each byte refines the location to a 16×16 sub-grid of the parent cell, with the
high nibble indexing latitude and the low nibble indexing longitude.
The encoding has a useful truncation property: dropping trailing bytes gives the correct lower-precision encoding of the same position — no recomputation needed.
Every coordinate pair in this module is (latitude, longitude), in that
order, without exception — parameters, return tuples, and rendered text alike.
§Encoding
For a given precision N (1–7 bytes), two 4N-bit indices are computed:
lat_index = floor((lat + 90) × 16^N / 180)
lon_index = floor((lon + 180) × 16^N / 360)Nibbles are extracted most-significant-first into bytes:
byte[k] = ((lat_index >> (4×(N-1-k))) & 0xF) << 4
| ((lon_index >> (4×(N-1-k))) & 0xF)§Precision
| Bytes | Equator cell, lat × lon (approx.) |
|---|---|
| 1 | 1,250 × 2,500 km |
| 2 | 78 × 156 km |
| 3 | 4.9 × 9.8 km |
| 4 | 305 × 610 m |
| 5 | 19 × 38 m |
| 6 | 1.2 × 2.4 m |
| 7 | 7.5 × 15 cm |
§Feature: f64
By default all floating-point arithmetic uses f32, which is adequate for
precisions 1–5 (cells ≥ 19 m). Enable the f64 crate feature for accurate
encoding and decoding at 6–7 byte precision.
Structs§
- Node
Location - A variable-precision geographic location encoded as a 1–7 byte grid code.
Constants§
- MAX_
PRECISION - Maximum supported precision in bytes.