code wiki / _hdl_build / nx_geo_clip_gate.nx

nx_geo_clip_gate.nx source

↩ module page · 85 lines · 3812 B

1// nx_geo_clip_gate.nx -- GATE for GEO-015 polygon intersection (Sutherland-Hodgman). Subject = the 2// 4e6-microdeg square [0,4e6]^2. Three clips prove the three code paths, correctness checked by 3// REUSING GEO-010 geo_area2 on the clipped result (no hard-coded vertex order): 4// overlap : clip by [2e6,6e6]^2 -> overlap square [2e6,4e6]^2, doubled area = 8e12 (4 verts) 5// disjoint : clip by [10e6,12e6]^2 -> no overlap -> 0 verts 6// contains : clip by [-10e6,10e6]^2 -> subject unchanged, doubled area = 3.2e13 7// 8// Evidence -> knowledge/status/geo_clip.log (GEOCLIPGATE authored=organ ... verdict=GREEN). 9// license_tier: ORIGINAL 10import "nx_geo_clip.nx" 11import "nx_geo_area.nx" 12import "nx_syscalls.nx" 13import "nx_gate_verdict.nx" 14 15const GC_LOG: *u8 = "knowledge/status/geo_clip.log" 16 17func 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 } 18func 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 } 19 20func gc_set(p: *i64, i: i64, lat: i64, lon: i64) -> i64 { p[i * 2] = lat; p[i * 2 + 1] = lon; return 0 } 21 22// fill a CCW axis-aligned square [lo,hi]^2 (in both lat and lon) into p (4 verts). 23func gc_square(p: *i64, lo: i64, hi: i64) -> i64 { 24 gc_set(p, 0, lo, lo) 25 gc_set(p, 1, lo, hi) 26 gc_set(p, 2, hi, hi) 27 gc_set(p, 3, hi, lo) 28 return 0 29} 30 31func gc_emit(fd: i64, no: i64, ao: i64, nd: i64, ncn: i64, ac: i64, ok: i64) -> i64 { 32 gc_w(fd, "GEOCLIPGATE authored=organ method=sutherland-hodgman overlap_nverts=" as *u8); gc_wn(fd, no) 33 gc_w(fd, " overlap_area2=" as *u8); gc_wn(fd, ao) 34 gc_w(fd, " disjoint_nverts=" as *u8); gc_wn(fd, nd) 35 gc_w(fd, " contains_nverts=" as *u8); gc_wn(fd, ncn) 36 gc_w(fd, " contains_area2=" as *u8); gc_wn(fd, ac) 37 if ok == 1 { gc_w(fd, " verdict=GREEN\n" as *u8) } else { gc_w(fd, " verdict=RED\n" as *u8) } 38 return 0 39} 40 41func main() -> i64 { 42 let subj: *i64 = sys_mmap(8 * 8) as *i64 43 gc_square(subj, 0, 4000000) 44 45 // overlap 46 let clipO: *i64 = sys_mmap(8 * 8) as *i64 47 gc_square(clipO, 2000000, 6000000) 48 let outO: *i64 = sys_mmap(8 * 40) as *i64 49 let no: i64 = geo_poly_clip(subj, 4, clipO, 4, outO) 50 let ao: i64 = geo_area2(outO, no) 51 52 // disjoint 53 let clipD: *i64 = sys_mmap(8 * 8) as *i64 54 gc_square(clipD, 10000000, 12000000) 55 let outD: *i64 = sys_mmap(8 * 40) as *i64 56 let nd: i64 = geo_poly_clip(subj, 4, clipD, 4, outD) 57 58 // contains 59 let clipC: *i64 = sys_mmap(8 * 8) as *i64 60 gc_square(clipC, 0 - 10000000, 10000000) 61 let outC: *i64 = sys_mmap(8 * 40) as *i64 62 let ncn: i64 = geo_poly_clip(subj, 4, clipC, 4, outC) 63 let ac: i64 = geo_area2(outC, ncn) 64 65 var ok: i64 = 1 66 if no != 4 { ok = 0 } 67 if ao != 8000000000000 { ok = 0 } 68 if nd != 0 { ok = 0 } 69 if ncn != 4 { ok = 0 } 70 if ac != 32000000000000 { ok = 0 } 71 72 gc_emit(1, no, ao, nd, ncn, ac, ok) 73 let lf: i64 = sys_openat_append(GC_LOG, 420) 74 if lf >= 0 { gc_emit(lf, no, ao, nd, ncn, ac, ok); sys_close(lf) } 75 76 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 77 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 78 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 79 let ctr__dry: *i64 = gv_ctr() 80 ctr__dry[0] = ok 81 ctr__dry[1] = 1 82 let rc__dry: i64 = gv_verdict("GEO-CLIP-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 83 sys_exit(rc__dry) 84 return rc__dry 85}