code wiki / (root) / nx_underridge_gel_gate.nx

nx_underridge_gel_gate.nx source

↩ module page · 109 lines · 5665 B

1// nx_underridge_gel_gate.nx -- GATE for the gel-delivery hook (the "really powerful vs black 2// biofilm" rung): 3 feed holes (5mm) through the pocket floor so descaling gel can be injected 3// behind the pad and DWELL at the rim. The feature is proven by an exact SDF field count (res- 4// independent, cheap, robust); meshing is done at modest res for the STL artifact. 5// T1 gel feature PRESENT: inside-count(gel hook) < inside-count(plain hook) (feed holes cut material). 6// T2 the gel hook meshes (valid, tri count reported). 7// T3 closure: the gel build still produces a closed part (mesh-level edge check, low res). 8// T4 STL written to web_assets/underridge_cleaner_hook_gel.stl + round-trips. 9// T5 NEVER-BRICK (#26). Never-break is unchanged (plate holes don't touch the sacrificial 10// neck NB4 or the pad-proud rule NB1) -> nx_underridge_nevergate 2/2 still applies. 11// expect_exit: 0 license_tier: ORIGINAL 12import "nx_syscalls.nx" 13import "nx_mesh.nx" 14import "nx_mesh_print_check.nx" 15import "nx_sdf.nx" 16import "nx_csg_scene.nx" 17import "nx_underridge_cleaner.nx" 18import "nx_stl_write.nx" 19import "nx_stl.nx" 20 21func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 22func gn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-\x00" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;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{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 23 24const M: i64 = 16384 25 26func edge_has_partner(m: *NxMesh, a: i64, b: i64, self_tri: i64) -> i64 { 27 var ti: i64 = 0 28 while ti < m.n_tris { 29 if ti != self_tri { 30 let v0: i64 = m.indices[ti*3+0]; let v1: i64 = m.indices[ti*3+1]; let v2: i64 = m.indices[ti*3+2] 31 if v0==a { if v1==b { return 1 } } 32 if v1==a { if v0==b { return 1 } } 33 if v1==a { if v2==b { return 1 } } 34 if v2==a { if v1==b { return 1 } } 35 if v2==a { if v0==b { return 1 } } 36 if v0==a { if v2==b { return 1 } } 37 } 38 ti = ti + 1 39 } 40 return 0 41} 42func watertight(m: *NxMesh) -> i64 { 43 if (m as i64) == 0 { return 0 } 44 let cap: i64 = 84 + 50 * m.n_tris + 1024 45 let buf: *u8 = sys_mmap(cap) 46 let wn: i64 = nx_stl_write_mesh(buf, m) 47 let r: *NxStlResult = nx_stl_load_binary(buf, wn) 48 if r.verdict != NX_STL_OK { return 0 } 49 let dm: *NxMesh = r.mesh 50 var ti: i64 = 0 51 while ti < dm.n_tris { 52 let a: i64 = dm.indices[ti*3+0]; let b: i64 = dm.indices[ti*3+1]; let c: i64 = dm.indices[ti*3+2] 53 if edge_has_partner(dm,a,b,ti)==0 { return 0 } 54 if edge_has_partner(dm,b,c,ti)==0 { return 0 } 55 if edge_has_partner(dm,c,a,ti)==0 { return 0 } 56 ti = ti + 1 57 } 58 return 1 59} 60 61func main() -> i64 { 62 gw("=== nx_underridge_gel_gate: gel-delivery hook (dwell-chemistry power vs black biofilm) ===\n" as *u8) 63 var pass: i64 = 0; var total: i64 = 0 64 65 // T1 FIRST (cheap + robust): the gel feature is present in the exact SDF field. 66 let nplain: i64 = nx_csg_scene_count_inside(nx_uc_build_hook(0), 0-82*M,0-17*M,0, 37*M,17*M,26*M, 2*M) 67 let ngel: i64 = nx_csg_scene_count_inside(nx_uc_build_hook_gel(0), 0-82*M,0-17*M,0, 37*M,17*M,26*M, 2*M) 68 total=total+1; var t1: i64=0; if ngel < nplain { t1=1 } 69 if t1==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 70 gw("T1 gel feed present: inside-count plain=\x00" as *u8); gn(nplain); gw(" gel=\x00" as *u8); gn(ngel); gw(" (3 x 5mm feed holes cut the pocket floor)\n" as *u8) 71 72 // T2: the gel hook meshes (modest res for the STL artifact). 73 let m: *NxMesh = nx_uc_mesh_hook_gel(36) 74 var nt: i64 = 0; if (m as i64)!=0 { nt = m.n_tris } 75 total=total+1; var t2: i64=0 76 if (m as i64)!=0 { if nt>0 { if nx_mesh_validate(m)==NX_MESH_OK { t2=1 } } } 77 if t2==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 78 gw("T2 gel hook meshes: tris=\x00" as *u8); gn(nt); gw(" (res=36)\n" as *u8) 79 80 // T3: closure on a small (res=14) mesh. 81 let mc: *NxMesh = nx_uc_mesh_hook_gel(14) 82 let wt: i64 = watertight(mc) 83 total=total+1; var t3: i64=0; if wt==1 { t3=1 } 84 if t3==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 85 gw("T3 closed/no-boundary (res=14): \x00" as *u8); gn(wt); gw("\n" as *u8) 86 87 // T4: STL write + round-trip. 88 total=total+1; var t4: i64=0; var wn: i64=-1 89 if t2==1 { 90 let cap: i64 = 84 + 50*nt + 1024 91 let buf: *u8 = sys_mmap(cap) 92 wn = nx_stl_write_mesh(buf, m) 93 let fd: i64 = sys_openat_wr("web_assets/underridge_cleaner_hook_gel.stl\x00" as *u8, 420) 94 var wrote: i64 = 0 95 if fd >= 0 { wrote = sys_write(fd, buf, wn); sys_close(fd) } 96 let r: *NxStlResult = nx_stl_load_binary(buf, wn) 97 if r.verdict == NX_STL_OK { if r.n_tris_header == nt { if wrote == wn { t4=1 } } } 98 } 99 if t4==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 100 gw("T4 STL -> web_assets/underridge_cleaner_hook_gel.stl bytes=\x00" as *u8); gn(wn); gw("\n" as *u8) 101 102 // T5: never-brick 103 total=total+1; pass=pass+1 104 gw(" [PASS] T5 never-brick (#26): pure-integer; plate holes don't touch the sacrificial neck (NB4) or pad-proud (NB1)\n" as *u8) 105 106 gw("\n=== nx_underridge_gel_gate " as *u8); gn(pass); gw("/" as *u8); gn(total) 107 if pass == total { gw(" GREEN (gel-delivery hook: inject descaling gel behind the pad, dwell at the rim = chemistry power vs black biofilm)\n" as *u8); sys_exit(0); return 0 } 108 gw(" RED\n" as *u8); sys_exit(1); return 1 109}