code wiki / _hdl_build / nx_geo_simplify_gate.nx
nx_geo_simplify_gate.nx source
↩ module page · 74 lines · 3651 B
1// nx_geo_simplify_gate.nx -- GATE for GEO-014 line simplify (Douglas-Peucker, integer). A 5-vertex
2// polyline along y=0 with a single 1e6-microdeg bump at the middle vertex. Three tolerances prove the
3// keep/drop decision tracks eps deterministically:
4// eps = 5e5 -> keep {P0,P2,P4} (count 3): the bump (perp 1e6) survives, the two flat vertices (perp
5// ~447213 < eps) are dropped
6// eps = 2e6 -> keep {P0,P4} (count 2): even the bump is below tolerance -> straight line
7// eps = 1e5 -> keep all 5 (count 5): every vertex exceeds the tiny tolerance
8// Output order/indices are checked exactly for the eps=5e5 case ([0,2,4]).
9//
10// Evidence -> knowledge/status/geo_simplify.log (GEOSIMPGATE authored=organ ... verdict=GREEN).
11// license_tier: ORIGINAL
12import "nx_geo_simplify.nx"
13import "nx_syscalls.nx"
14import "nx_gate_verdict.nx"
15
16const GS_LOG: *u8 = "knowledge/status/geo_simplify.log"
17
18func gs_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 }
19func gs_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 }
20
21func gs_set(p: *i64, i: i64, lat: i64, lon: i64) -> i64 { p[i * 2] = lat; p[i * 2 + 1] = lon; return 0 }
22
23func gs_emit(fd: i64, c1: i64, o0: i64, o1: i64, o2: i64, c2: i64, c3: i64, ok: i64) -> i64 {
24 gs_w(fd, "GEOSIMPGATE authored=organ method=integer-douglas-peucker eps5e5_count=" as *u8); gs_wn(fd, c1)
25 gs_w(fd, " kept=[" as *u8); gs_wn(fd, o0); gs_w(fd, "," as *u8); gs_wn(fd, o1); gs_w(fd, "," as *u8); gs_wn(fd, o2)
26 gs_w(fd, "] eps2e6_count=" as *u8); gs_wn(fd, c2)
27 gs_w(fd, " eps1e5_count=" as *u8); gs_wn(fd, c3)
28 if ok == 1 { gs_w(fd, " verdict=GREEN\n" as *u8) } else { gs_w(fd, " verdict=RED\n" as *u8) }
29 return 0
30}
31
32func main() -> i64 {
33 // polyline (x=lon,y=lat): (0,0),(1e6,0),(2e6,1e6 bump),(3e6,0),(4e6,0).
34 let pts: *i64 = sys_mmap(8 * 10) as *i64
35 gs_set(pts, 0, 0, 0)
36 gs_set(pts, 1, 0, 1000000)
37 gs_set(pts, 2, 1000000, 2000000)
38 gs_set(pts, 3, 0, 3000000)
39 gs_set(pts, 4, 0, 4000000)
40
41 let out: *i64 = sys_mmap(8 * 5) as *i64
42 let c1: i64 = geo_simplify(pts, 5, 500000, out) // expect 3, [0,2,4]
43 let o0: i64 = out[0]
44 let o1: i64 = out[1]
45 let o2: i64 = out[2]
46
47 let out2: *i64 = sys_mmap(8 * 5) as *i64
48 let c2: i64 = geo_simplify(pts, 5, 2000000, out2) // expect 2
49
50 let out3: *i64 = sys_mmap(8 * 5) as *i64
51 let c3: i64 = geo_simplify(pts, 5, 100000, out3) // expect 5
52
53 var ok: i64 = 1
54 if c1 != 3 { ok = 0 }
55 if o0 != 0 { ok = 0 }
56 if o1 != 2 { ok = 0 }
57 if o2 != 4 { ok = 0 }
58 if c2 != 2 { ok = 0 }
59 if c3 != 5 { ok = 0 }
60
61 gs_emit(1, c1, o0, o1, o2, c2, c3, ok)
62 let lf: i64 = sys_openat_append(GS_LOG, 420)
63 if lf >= 0 { gs_emit(lf, c1, o0, o1, o2, c2, c3, ok); sys_close(lf) }
64
65 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
66 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
67 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
68 let ctr__dry: *i64 = gv_ctr()
69 ctr__dry[0] = ok
70 ctr__dry[1] = 1
71 let rc__dry: i64 = gv_verdict("GEO-SIMPLIFY-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
72 sys_exit(rc__dry)
73 return rc__dry
74}