code wiki / _hdl_build / nx_geo_segint_gate.nx
nx_geo_segint_gate.nx source
↩ module page · 70 lines · 3620 B
1// nx_geo_segint_gate.nx -- GATE for GEO-015b segment-segment intersection. Covers all 4 cases:
2// proper : (0,0)-(4e6,4e6) X (0,4e6)-(4e6,0) -> code 1, point (2e6,2e6)
3// touch : (0,0)-(4e6,0) X (4e6,0)-(4e6,4e6) -> code 2, point (4e6,0) [shared endpoint]
4// parallel : (0,0)-(4e6,0) X (0,1e6)-(4e6,1e6) -> code 0 (disjoint)
5// collinear: (0,0)-(4e6,0) X (2e6,0)-(6e6,0) -> code 3
6// outside : (0,0)-(1e6,1e6) X (0,4e6)-(1e6,3e6) -> code 0 (lines meet beyond both segments)
7//
8// Evidence -> knowledge/status/geo_segint.log (GEOSEGINTGATE authored=organ ... verdict=GREEN).
9// license_tier: ORIGINAL
10import "nx_geo_segint.nx"
11import "nx_syscalls.nx"
12import "nx_gate_verdict.nx"
13
14const GS_LOG: *u8 = "knowledge/status/geo_segint.log"
15
16func 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 }
17func 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 }
18
19func gs_emit(fd: i64, c1: i64, px: i64, py: i64, c2: i64, tx: i64, ty: i64, c3: i64, c4: i64, c5: i64, ok: i64) -> i64 {
20 gs_w(fd, "GEOSEGINTGATE authored=organ method=parametric-cross proper_code=" as *u8); gs_wn(fd, c1)
21 gs_w(fd, " proper_x=" as *u8); gs_wn(fd, px); gs_w(fd, " proper_y=" as *u8); gs_wn(fd, py)
22 gs_w(fd, " touch_code=" as *u8); gs_wn(fd, c2)
23 gs_w(fd, " touch_x=" as *u8); gs_wn(fd, tx); gs_w(fd, " touch_y=" as *u8); gs_wn(fd, ty)
24 gs_w(fd, " parallel_code=" as *u8); gs_wn(fd, c3)
25 gs_w(fd, " collinear_code=" as *u8); gs_wn(fd, c4)
26 gs_w(fd, " outside_code=" as *u8); gs_wn(fd, c5)
27 if ok == 1 { gs_w(fd, " verdict=GREEN\n" as *u8) } else { gs_w(fd, " verdict=RED\n" as *u8) }
28 return 0
29}
30
31func main() -> i64 {
32 let o: *i64 = sys_mmap(16) as *i64
33
34 let c1: i64 = geo_seg_intersect(0, 0, 4000000, 4000000, 0, 4000000, 4000000, 0, o) // proper
35 let px: i64 = o[0]
36 let py: i64 = o[1]
37
38 let c2: i64 = geo_seg_intersect(0, 0, 4000000, 0, 4000000, 0, 4000000, 4000000, o) // touch
39 let tx: i64 = o[0]
40 let ty: i64 = o[1]
41
42 let c3: i64 = geo_seg_intersect(0, 0, 4000000, 0, 0, 1000000, 4000000, 1000000, o) // parallel
43 let c4: i64 = geo_seg_intersect(0, 0, 4000000, 0, 2000000, 0, 6000000, 0, o) // collinear
44 let c5: i64 = geo_seg_intersect(0, 0, 1000000, 1000000, 0, 4000000, 1000000, 3000000, o) // outside
45
46 var ok: i64 = 1
47 if c1 != 1 { ok = 0 }
48 if px != 2000000 { ok = 0 }
49 if py != 2000000 { ok = 0 }
50 if c2 != 2 { ok = 0 }
51 if tx != 4000000 { ok = 0 }
52 if ty != 0 { ok = 0 }
53 if c3 != 0 { ok = 0 }
54 if c4 != 3 { ok = 0 }
55 if c5 != 0 { ok = 0 }
56
57 gs_emit(1, c1, px, py, c2, tx, ty, c3, c4, c5, ok)
58 let lf: i64 = sys_openat_append(GS_LOG, 420)
59 if lf >= 0 { gs_emit(lf, c1, px, py, c2, tx, ty, c3, c4, c5, ok); sys_close(lf) }
60
61 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
62 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
63 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
64 let ctr__dry: *i64 = gv_ctr()
65 ctr__dry[0] = ok
66 ctr__dry[1] = 1
67 let rc__dry: i64 = gv_verdict("GEO-SEGINT-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
68 sys_exit(rc__dry)
69 return rc__dry
70}