code wiki / _hdl_build / nx_geo_s2.nx

nx_geo_s2.nx

buildroot/runtime/_hdl_build/nx_geo_s2.nx

3316 B95 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic geo
docsdependenciesstructsconstsfunctions

about

nx_geo_s2.nx -- LIB: GEO-005 S2-CLASS CELL INDEX via the HILBERT space-filling curve. The real exceed over GEO-002's geohash (which interleaves lon/lat bits = the Z-ORDER / Morton curve). THE EXCEED ANGLE (measured, not asserted): a Hilbert curve is CONTINUOUS -- consecutive 1D cell indices are ALWAYS 4-adjacent in 2D (Manhattan step exactly 1) -- so a 1D range scan never "tears" across distant 2D regions. The Z-order curve that geohash uses TEARS: its consecutive step jumps by up to the grid width N at every major quadrant boundary. Google's S2 chose Hilbert for exactly this locality; here it is sovereign + integer. (cell index quality is what makes range queries / tile coherence good; this is the measurable weakness of plain geohash.) Pure integer bit arithmetic (bit-tests via /,% to avoid the geohash const-index landmine), deterministic. (x,y) are integer cell coords in [0, 2^k); a real lon/lat first quantizes to that grid (GEO-002 already does the microdeg bisection). license_tier: ORIGINAL

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_geo_s2.nx nx_geo_s2_gate.nx

imports: nx_syscalls.nx

imported by: nx_geo_s2_gate.nx

structs

none

consts

none

functions

16func geo_s2_pow2(k: i64) -> i64 { var n: i64 = 1; var t: i64 = 0; while t < k { n = n * 2; t = t + 1 } return n }
19func geo_hilbert_xy2d(k: i64, x: i64, y: i64) -> i64
called by 1: main calls 1: geo_s2_pow2
50func geo_hilbert_d2xy(k: i64, d: i64, out2: *i64) -> i64
called by 1: main calls 1: geo_s2_pow2
81func geo_zorder_xy2d(k: i64, x: i64, y: i64) -> i64
called by 1: main