code wiki / _hdl_build / nx_step_tess2_gate.nx

nx_step_tess2_gate.nx source

↩ module page · 204 lines · 9959 B

1// nx_step_tess2_gate.nx -- COMPLETE planar tessellation on the real as1: B-spline curve edges (Cox-de Boor, 2// degree up to 5 non-uniform) + keyhole hole bridging. Target: ALL 25 planar faces tessellate (v1 managed 12; 3// the 13 missing = 9 hole-faces + 4 spline-loop faces) -> whole model 53/53 with the sgn round faces. The v1 4// EXACT invariant (ear sum == shoelace) must hold on every bridged keyhole too (bridges cancel exactly). 5// Metrology: nut hole rim (file's own spline of the R=5.000mm circle at (10,7.5)) -- sampled deviation MEASURED 6// and reported in um. expect_exit: 0 license_tier: ORIGINAL 7import "nx_step_tess2.nx" 8 9func t2g_tooth(name: *u8, pass: i64, fails: *i64) -> i64 { 10 sp_puts(" " as *u8); sp_puts(name); sp_puts(" -> " as *u8) 11 if pass == 1 { sp_puts("PASS\n" as *u8); return 0 } 12 sp_puts("FAIL\n" as *u8) 13 fails[0] = fails[0] + 1 14 return 0 15} 16 17func main() -> i64 { 18 sp_puts("=== nx_step_tess2_gate -- B-spline edges + hole bridging: planar tessellation COMPLETE ===\n" as *u8) 19 let fails: *i64 = sys_mmap(8) as *i64 20 fails[0] = 0 21 let buf: *u8 = sys_mmap(4194304) 22 let aid: *i64 = sys_mmap(524288) as *i64 23 let anm: *i64 = sys_mmap(524288) as *i64 24 let anl: *i64 = sys_mmap(524288) as *i64 25 let aao: *i64 = sys_mmap(524288) as *i64 26 let aal: *i64 = sys_mmap(524288) as *i64 27 let st: *i64 = sys_mmap(256) as *i64 28 let n: i64 = sp_read_file("knowledge/fetched/step_as1.stp" as *u8, buf, 4194304) 29 if n <= 0 { sp_puts("MISSING step_as1.stp\nRED\n" as *u8); return 1 } 30 sp_init(st, buf, n, aid, anm, anl, aao, aal) 31 let cnt: i64 = sp_scan(st) 32 33 // tt ctx with BIG buffers (keyhole polygons ~150 verts) 34 let tt: *i64 = sys_mmap(128) as *i64 35 let c: *i64 = sys_mmap(128) as *i64 36 var z: i64 = 0 37 while z < 16 { c[z] = 0; z = z + 1 } 38 let mesh: i64 = sys_mmap(m3_bytes()) as i64 39 m3_init(mesh) 40 tt[0] = st as i64 41 tt[1] = mesh 42 tt[2] = c as i64 43 tt[3] = sys_mmap(768) as i64 44 tt[4] = 0 // repointed per-face by sgt2 45 tt[5] = sys_mmap(8192) as i64 // 2D (256 verts) 46 tt[6] = sys_mmap(4096) as i64 // alive (256) 47 tt[7] = sys_mmap(128) as i64 48 tt[8] = sys_mmap(16) as i64 49 tt[9] = 0 50 // t2 curve ctx (shares the counter table) 51 let t2: *i64 = sys_mmap(128) as *i64 52 t2[0] = st as i64 53 t2[1] = c as i64 54 t2[2] = sys_mmap(32) as i64 // bc 55 t2[3] = sys_mmap(960) as i64 // cpts (40) 56 t2[4] = sys_mmap(1024) as i64 // kn + parse scratch 57 t2[5] = sys_mmap(128) as i64 // ev/ra/kind/rb scratch 58 t2[6] = sys_mmap(512) as i64 // edge refs 59 t2[7] = sys_mmap(256) as i64 // eval scratch 60 t2[8] = sys_mmap(8192) as i64 // merged 3D (256 verts) 61 t2[9] = sys_mmap(128) as i64 // circle parse + scratch 62 t2[10] = sys_mmap(768) as i64 // reversed-arc temp 63 t2[11] = sys_mmap(128) as i64 // arc walk scratch 64 t2[12] = sys_mmap(256) as i64 // rational-Bezier-curve parse 65 let slab: *i64 = sys_mmap(20480) as *i64 // 8 bounds x 96 verts x 3 + refs/counts/areas 66 67 // T1 whole-model v2 planar sweep: ALL 25 planar faces 68 c[14] = 1 69 let nv2: i64 = sgt2_tessellate(tt, t2, slab) 70 c[14] = 0 71 // diagnostic: name the failing faces (ISOLATED: scratch mesh + counter snapshot -- must not touch the run) 72 if c[13] > 0 { 73 let aidv: *i64 = st[2] as *i64 74 let dref: *i64 = sys_mmap(128) as *i64 75 let dv: *i64 = sys_mmap(4096) as *i64 76 let snap: *i64 = sys_mmap(128) as *i64 77 var sz: i64 = 0 78 while sz < 16 { snap[sz] = c[sz]; sz = sz + 1 } 79 let dmesh: i64 = sys_mmap(m3_bytes()) as i64 80 m3_init(dmesh) 81 let savemesh: i64 = tt[1] 82 tt[1] = dmesh 83 var di: i64 = 0 84 while di < cnt { 85 if sp_name_is(st, di, "ADVANCED_FACE" as *u8) == 1 { 86 if sgt_face_plane(tt, di) == 1 { 87 let oc: i64 = c[11] 88 let of: i64 = c[13] 89 sgt2_face(tt, t2, di, slab) 90 if c[13] > of { 91 sp_puts(" FAIL-DIAG face #" as *u8); sp_putn(aidv[di]) 92 let o2: *i64 = tt[8] as *i64 93 if sp_arg_span(st, di, 1, o2) == 1 { 94 let nbd: i64 = sgt_refs(st[0] as *u8, o2[0], o2[1], dref, 8) 95 sp_puts(" bounds=" as *u8); sp_putn(nbd) 96 var bd: i64 = 0 97 while bd < nbd { 98 let bix: i64 = sp_find(st, dref[bd]) 99 var lid: i64 = 0 - 1 100 if bix >= 0 { lid = sgt_arg_ref(st, bix, 1, o2) } 101 var nvv: i64 = 0 - 1 102 if lid >= 0 { nvv = sgt2_loop_verts(t2, lid, dv, 96) } 103 sp_puts(" b" as *u8); sp_putn(bd); sp_puts("=" as *u8); sp_putn(nvv) 104 bd = bd + 1 105 } 106 } 107 sp_puts("\n" as *u8) 108 } 109 } 110 } 111 di = di + 1 112 } 113 // restore: counters + mesh (diag must be invisible to the teeth) 114 sz = 0 115 while sz < 16 { c[sz] = snap[sz]; sz = sz + 1 } 116 tt[1] = savemesh 117 } 118 sp_puts("v2 planar: tessellated=" as *u8); sp_putn(c[11]) 119 sp_puts(" holes-bridged=" as *u8); sp_putn(c[12]) 120 sp_puts(" fails=" as *u8); sp_putn(c[13]) 121 sp_puts(" curve-edges-sampled=" as *u8); sp_putn(c[9]) 122 sp_puts(" endpoint-verify-fallbacks=" as *u8); sp_putn(c[10]) 123 sp_puts(" AREA-MISMATCH=" as *u8); sp_putn(c[6]); sp_puts("\n" as *u8) 124 var t1: i64 = 0 125 if c[11] == 25 { if c[13] == 0 { t1 = 1 } } 126 let ig1: i64 = t2g_tooth("T1 ALL 25/25 planar faces tessellated (v1 did 12; +9 hole-faces +4 spline-loop)" as *u8, t1, fails) 127 128 var t2t: i64 = 0 129 if c[6] == 0 { if c[12] >= 9 { t2t = 1 } } 130 let ig2: i64 = t2g_tooth("T2 EXACT ear==shoelace invariant on every keyhole (bridges cancel); >=9 holes bridged" as *u8, t2t, fails) 131 132 // T3 METROLOGY: nut hole rim = loop #186 (bound #185 of face #65) -- the file's spline of circle R=5 @ (10,7.5) 133 let hv: *i64 = sys_mmap(4096) as *i64 134 let nh: i64 = sgt2_loop_verts(t2, 186, hv, 96) 135 var maxd2: i64 = 0 - 1 136 var i: i64 = 0 137 while i < nh { 138 let dx: i64 = hv[i * 3] - 2560 139 let dy: i64 = hv[i * 3 + 1] - 1920 140 var d2: i64 = dx * dx + dy * dy - 1638400 141 if d2 < 0 { d2 = 0 - d2 } 142 if d2 > maxd2 { maxd2 = d2 } 143 i = i + 1 144 } 145 var devfx: i64 = 0 146 if maxd2 > 0 { devfx = maxd2 / 2560 } 147 let devnm: i64 = devfx * 3906 148 sp_puts(" nut hole rim: " as *u8); sp_putn(nh) 149 sp_puts(" sampled verts; max radial deviation from EXACT 5.000mm = " as *u8); sp_putn(devnm) 150 sp_puts(" nm (file's own spline approx + our sampling)\n" as *u8) 151 var t3: i64 = 0 152 if nh >= 20 { if devfx <= 4 { t3 = 1 } } // within 4 fx = 15.6 um, MEASURED 153 let ig3: i64 = t2g_tooth("T3 nut hole rim sampled >=20 verts, radius within 15.6um of exact 5.000mm (measured)" as *u8, t3, fails) 154 155 // T4 whole model 53/53: v2 planar mesh + sgn round faces into ONE mesh -> STL round-trip 156 let nt: *i64 = sys_mmap(128) as *i64 157 let c2: *i64 = sys_mmap(128) as *i64 158 z = 0 159 while z < 16 { c2[z] = 0; z = z + 1 } 160 nt[0] = st as i64 161 nt[1] = mesh 162 nt[2] = c2 as i64 163 nt[3] = sys_mmap(256) as i64 164 nt[4] = sys_mmap(64) as i64 165 nt[5] = sys_mmap(16) as i64 166 nt[6] = sys_mmap(128) as i64 167 nt[7] = sys_mmap(128) as i64 168 let nr: i64 = sgn_tessellate_all(nt) 169 let h: *i64 = m3_hdr(mesh) 170 sp_puts(" FULL MODEL: planar " as *u8); sp_putn(c[11]) 171 sp_puts(" + round " as *u8); sp_putn(c2[2]) 172 sp_puts(" = " as *u8); sp_putn(c[11] + c2[2]) 173 sp_puts("/53 faces, tris=" as *u8); sp_putn(h[1]); sp_puts("\n" as *u8) 174 let wr: i64 = m3_write_stl(mesh, "knowledge/step_full53.stl" as *u8) 175 let mesh2: i64 = sys_mmap(m3_bytes()) as i64 176 let rd: i64 = m3_read_stl(mesh2, "knowledge/step_full53.stl" as *u8) 177 let h2: *i64 = m3_hdr(mesh2) 178 var t4: i64 = 0 179 if c[11] + c2[2] == 53 { if c2[7] == 0 { if h2[1] == h[1] { if h[1] > 900 { t4 = 1 } } } } 180 let ig4: i64 = t2g_tooth("T4 WHOLE MODEL 53/53 faces file-true -> STL round-trip" as *u8, t4, fails) 181 182 // T5 determinism (re-run the v2 sweep on a fresh mesh -> same tessellated/bridged/tris) 183 let mesh3b: i64 = sys_mmap(m3_bytes()) as i64 184 m3_init(mesh3b) 185 let c3: *i64 = sys_mmap(128) as *i64 186 z = 0 187 while z < 16 { c3[z] = 0; z = z + 1 } 188 tt[1] = mesh3b 189 tt[2] = c3 as i64 190 t2[1] = c3 as i64 191 let nv2b: i64 = sgt2_tessellate(tt, t2, slab) 192 let h3: *i64 = m3_hdr(mesh3b) 193 var t5: i64 = 0 194 if c3[11] == c[11] { if c3[12] == c[12] { if c3[6] == 0 { t5 = 1 } } } 195 let ig5: i64 = t2g_tooth("T5 deterministic" as *u8, t5, fails) 196 197 sp_puts("\nP3a READ-SIDE GEOMETRY COMPLETE: every face of the model tessellates from the file's own topology --\n" as *u8) 198 sp_puts("lines, degree-5 B-spline outlines (Cox-de Boor fixed-point), spline hole rims, keyhole bridging --\n" as *u8) 199 sp_puts("with the EXACT area invariant guarding every face. Remaining for P3a=2: STEP WRITE.\n" as *u8) 200 sp_puts("\nfails=" as *u8); sp_putn(fails[0]); sp_puts("\n" as *u8) 201 if fails[0] == 0 { sp_puts("GREEN -- complete planar tessellation 5/5 (53/53 whole model, invariants exact)\n" as *u8); return 0 } 202 sp_puts("RED\n" as *u8) 203 return 1 204}