code wiki / _hdl_build / nx_geo_hull.nx
nx_geo_hull.nx
buildroot/runtime/_hdl_build/nx_geo_hull.nx
about
nx_geo_hull.nx -- LIB: GEO-012 CONVEX HULL (Andrew's monotone chain), INTEGER-EXACT.
THE EXCEED ANGLE (measured, not asserted): the turn-direction test is a single INTEGER cross
product over microdegree coordinates -- ZERO floating point. So the orientation predicate is EXACT,
and collinear / duplicate points are classified deterministically (cross == 0 is decided, never a
float epsilon coin-flip). Those are exactly the inputs where Turf.js / Shapely / qhull (float) emit
non-deterministic hulls or spurious near-collinear vertices. We drop collinear edge points (pop on
cross <= 0) for a minimal, exact hull.
Convention (matches nx_geo): pts = flat [lat0,lon0, ...], n points, lat = Y, lon = X. Writes the
hull vertex INDICES (into pts) in counter-clockwise order to out_idx; returns the hull size.
Overflow-safe for Earth coords in i64 (cross of two deltas <= 3.6e8^2 ~ 1.3e17, no accumulation).
Selection-sort O(n^2) for now (exactness first; an O(n log n) sort is a later perf rung). license_tier: ORIGINAL
dependencies 1 imports · 1 importers
imports: nx_syscalls.nx
imported by: nx_geo_hull_gate.nx
structs
| none |
consts
| none |
functions
| 17 | func geo_cmp_lonlat(pts: *i64, i: i64, j: i64) -> i64 called by 1: geo_convex_hull |
| 29 | func geo_cross3(pts: *i64, o: i64, a: i64, b: i64) -> i64 called by 1: geo_convex_hull |
| 39 | func geo_convex_hull(pts: *i64, n: i64, out_idx: *i64) -> i64 |