code wiki / _hdl_build / nx_geo_centroid_gate.nx
nx_geo_centroid_gate.nx source
↩ module page · 64 lines · 3313 B
1// nx_geo_centroid_gate.nx -- GATE for GEO-011 polygon centroid. Polygon = the 6e5 square with an EXTRA
2// collinear vertex (0,3e5) on its bottom edge (5 vertices). Proves:
3// area-weighted : centroid == (300000, 300000) -- the true center, UNCHANGED by the redundant vertex
4// vertex-mean : centroid == (240000, 300000) -- pulled toward the densely-sampled bottom edge
5// => the two DIFFER (lat 300000 vs 240000): area-weighted is the robust/correct centroid.
6// Both exact integers (no float drift).
7//
8// Evidence -> knowledge/status/geo_centroid.log (GEOCENTROIDGATE authored=organ ... verdict=GREEN).
9// license_tier: ORIGINAL
10import "nx_geo_centroid.nx"
11import "nx_syscalls.nx"
12import "nx_gate_verdict.nx"
13
14const GC_LOG: *u8 = "knowledge/status/geo_centroid.log"
15
16func gc_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
17func gc_wn(fd: i64, v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(fd, bb, k); return 0 }
18
19func gc_set(p: *i64, i: i64, lat: i64, lon: i64) -> i64 { p[i * 2] = lat; p[i * 2 + 1] = lon; return 0 }
20
21func gc_emit(fd: i64, alat: i64, alon: i64, vlat: i64, vlon: i64, ok: i64) -> i64 {
22 gc_w(fd, "GEOCENTROIDGATE authored=organ area_lat=" as *u8); gc_wn(fd, alat)
23 gc_w(fd, " area_lon=" as *u8); gc_wn(fd, alon)
24 gc_w(fd, " vertex_lat=" as *u8); gc_wn(fd, vlat)
25 gc_w(fd, " vertex_lon=" as *u8); gc_wn(fd, vlon)
26 if ok == 1 { gc_w(fd, " verdict=GREEN\n" as *u8) } else { gc_w(fd, " verdict=RED\n" as *u8) }
27 return 0
28}
29
30func main() -> i64 {
31 // CCW square [0,6e5]^2 with extra collinear vertex (0, 3e5) on the bottom (lat=0) edge.
32 let poly: *i64 = sys_mmap(8 * 10) as *i64
33 gc_set(poly, 0, 0, 0)
34 gc_set(poly, 1, 0, 300000) // redundant collinear bottom-edge vertex
35 gc_set(poly, 2, 0, 600000)
36 gc_set(poly, 3, 600000, 600000)
37 gc_set(poly, 4, 600000, 0)
38
39 let ca: *i64 = sys_mmap(16) as *i64
40 geo_centroid_area(poly, 5, ca)
41 let cv: *i64 = sys_mmap(16) as *i64
42 geo_centroid_vertex(poly, 5, cv)
43
44 var ok: i64 = 1
45 if ca[0] != 300000 { ok = 0 } // area-weighted true center
46 if ca[1] != 300000 { ok = 0 }
47 if cv[0] != 240000 { ok = 0 } // vertex-mean pulled down
48 if cv[1] != 300000 { ok = 0 }
49 if ca[0] == cv[0] { ok = 0 } // they MUST differ (robustness vs sampling)
50
51 gc_emit(1, ca[0], ca[1], cv[0], cv[1], ok)
52 let lf: i64 = sys_openat_append(GC_LOG, 420)
53 if lf >= 0 { gc_emit(lf, ca[0], ca[1], cv[0], cv[1], ok); sys_close(lf) }
54
55 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
56 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
57 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
58 let ctr__dry: *i64 = gv_ctr()
59 ctr__dry[0] = ok
60 ctr__dry[1] = 1
61 let rc__dry: i64 = gv_verdict("GEO-CENTROID-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
62 sys_exit(rc__dry)
63 return rc__dry
64}