code wiki / _hdl_build / nx_geo_centroid.nx

nx_geo_centroid.nx

buildroot/runtime/_hdl_build/nx_geo_centroid.nx

2417 B59 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic geo
docsdependenciesstructsconstsfunctions

about

nx_geo_centroid.nx -- LIB: GEO-011 POLYGON CENTROID, two integer-exact variants. geo_centroid_vertex -- mean of the vertices (= turf.centroid). Exact at ANY scale; but sensitive to how densely each edge is sampled with vertices. geo_centroid_area -- the AREA-WEIGHTED centroid (= PostGIS ST_Centroid / turf.centerOfMass): Cx = (1/(3*A2)) * sum (x_i+x_j)*cross, Cy likewise, cross = x_j*y_i-x_i*y_j. THE EXCEED ANGLE (measured): the area-weighted centroid is ROBUST -- it is unchanged by redundant collinear edge vertices, whereas the vertex-mean shifts toward densely-sampled edges. The gate proves they DIFFER on exactly such a polygon, and that the area-weighted one stays at the true center. Both integer-exact (no float drift). OVERFLOW: geo_centroid_area origin-shifts to vertex 0 so the sums stay in delta space -- i64-exact for regional polygons (sub-degree extent, modest vertex count = the geofence domain). Continental- scale area-weighted centroids need the 128-bit path (nx_mul_wide); a documented future hardening. Convention: poly = flat [lat0,lon0, ...], lat=Y, lon=X. license_tier: ORIGINAL

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_geo_centroid.nx nx_geo_centroid_gate.nx

imports: nx_syscalls.nx

imported by: nx_geo_centroid_gate.nx

structs

none

consts

none

functions

20func geo_centroid_vertex(poly: *i64, n: i64, out2: *i64) -> i64
called by 1: main
35func geo_centroid_area(poly: *i64, n: i64, out2: *i64) -> i64
called by 1: main