code wiki / _hdl_build / nx_geo_clip.nx
nx_geo_clip.nx
buildroot/runtime/_hdl_build/nx_geo_clip.nx
about
nx_geo_clip.nx -- LIB: GEO-015 POLYGON INTERSECTION (Sutherland-Hodgman convex clip).
THE EXCEED ANGLE (measured, not asserted): the inside/outside classification of every vertex against
every clip edge is the SIGN of an INTEGER cross product -- ZERO floating point, so the topology of
the result (which vertices survive, where edges cross) is EXACT and DETERMINISTIC. That is the part
float clippers (Turf/PostGIS) get wrong on touching/collinear edges. HONEST SCOPE: the intersection
VERTEX itself is S + (E-S)*dS/(dS-dE) computed in integer arithmetic and ROUNDED to microdegrees --
deterministic-integer, NOT exact-rational geometry. To stay overflow-safe at any scale the fraction
(num,den) is normalized (shifted down in lockstep) before the multiply, since (E-S)*dS would
otherwise exceed i64 at continental scale; the ratio is preserved to sub-microdegree.
Convention (matches nx_geo): polygons = flat [lat0,lon0, ...], lat=Y, lon=X. The CLIP polygon must be
CONVEX and CCW. Writes the clipped polygon to out (caller sizes it >= (ns+nc+8) vertices); returns
the output vertex count (0 = no overlap). license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_geo_clip_gate.nxnx_geo_union.nx
structs
| none |
consts
| 16 | const K_MAGIC_17179869184: i64 = 17179869184 |
functions
| 18 | func geo_cabs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } called by 1: geo_intersect_into |
| 21 | func geo_clip_inside(ax: i64, ay: i64, bx: i64, by: i64, px: i64, py: i64) -> i64 called by 1: geo_poly_clip |
| 29 | func geo_intersect_into(buf: *i64, pos: i64, sx: i64, sy: i64, ex: i64, ey: i64, ax: i64, ay: i64, bx: i64, by: i64) -> i64 |
| 50 | func geo_poly_clip(subj: *i64, ns: i64, clip: *i64, nc: i64, out: *i64) -> i64 |