code wiki / _hdl_build / nx_step_geom_gate.nx

nx_step_geom_gate.nx source

↩ module page · 115 lines · 5678 B

1// nx_step_geom_gate.nx -- benchmark REAL GEOMETRY extraction from the as1 STEP file (cadtwin P3a: structure -> 2// coordinates). Extract every CARTESIAN_POINT -> fixed-point cloud; verify (a) a KNOWN point is present with the 3// exact model coordinate, (b) the bounding box is real+non-degenerate, (c) the cloud feeds nx_partid (shape 4// descriptor on REAL geometry, not synthetic boxes). = the STEP model's actual 3D geometry, sovereign. expect_exit: 0 5// license_tier: ORIGINAL 6import "nx_step_geom.nx" 7import "nx_partid.nx" 8 9func gg_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_geom_gate -- real geometry (CARTESIAN_POINT cloud) from the as1 STEP file ===\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 -- run nx_step_sample_fetch\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 let maxp: i64 = 4000 34 let pts: *i64 = sys_mmap(maxp * 24 + 64) as *i64 35 let npts: i64 = sg_extract_points(st, pts, maxp) 36 sp_puts("entities=" as *u8); sp_putn(cnt); sp_puts(" CARTESIAN_POINTs extracted=" as *u8); sp_putn(npts); sp_puts("\n" as *u8) 37 38 // T1 extracted a real cloud 39 var t1: i64 = 0 40 if npts > 100 { t1 = 1 } 41 let ig1: i64 = gg_tooth("T1 extracted a real point cloud (>100 pts)" as *u8, t1, fails) 42 43 // T2 known model point present: #16 = CARTESIAN_POINT('',(-10.,75.,60.)) -> fx256 (-2560,19200,15360) 44 var found: i64 = 0 45 var found0: i64 = 0 46 var i: i64 = 0 47 while i < npts { 48 let x: i64 = pts[i * 3] 49 let y: i64 = pts[i * 3 + 1] 50 let z: i64 = pts[i * 3 + 2] 51 if x == 0 - 2560 { if y == 19200 { if z == 15360 { found = 1 } } } 52 if x == 0 { if y == 0 { if z == 0 { found0 = 1 } } } 53 i = i + 1 54 } 55 var t2: i64 = 0 56 if found == 1 { if found0 == 1 { t2 = 1 } } 57 sp_puts(" known point (-10,75,60) present=" as *u8); sp_putn(found); sp_puts(" origin (0,0,0) present=" as *u8); sp_putn(found0); sp_puts("\n" as *u8) 58 let ig2: i64 = gg_tooth("T2 exact known model coordinates recovered" as *u8, t2, fails) 59 60 // T3 real, non-degenerate bounding box (fx256), plausible mm scale 61 var mnx: i64 = pts[0] 62 var mxx: i64 = pts[0] 63 var mny: i64 = pts[1] 64 var mxy: i64 = pts[1] 65 var mnz: i64 = pts[2] 66 var mxz: i64 = pts[2] 67 i = 1 68 while i < npts { 69 let x: i64 = pts[i * 3] 70 let y: i64 = pts[i * 3 + 1] 71 let z: i64 = pts[i * 3 + 2] 72 if x < mnx { mnx = x } 73 if x > mxx { mxx = x } 74 if y < mny { mny = y } 75 if y > mxy { mxy = y } 76 if z < mnz { mnz = z } 77 if z > mxz { mxz = z } 78 i = i + 1 79 } 80 sp_puts(" bbox fx256 x[" as *u8); sp_putn(mnx); sp_puts("," as *u8); sp_putn(mxx); sp_puts("] y[" as *u8); sp_putn(mny); sp_puts("," as *u8); sp_putn(mxy); sp_puts("] z[" as *u8); sp_putn(mnz); sp_puts("," as *u8); sp_putn(mxz); sp_puts("]\n" as *u8) 81 var t3: i64 = 0 82 if mxx > mnx { if mxy > mny { if mxz > mnz { 83 if mxx < 2560000 { if mnx > 0 - 2560000 { t3 = 1 } } // |x| < 10000mm : sane, catches parse garbage 84 } } } 85 let ig3: i64 = gg_tooth("T3 real non-degenerate bounding box at plausible mm scale" as *u8, t3, fails) 86 87 // T4 COMPOSE: load the real cloud into a mesh -> nx_partid descriptor (shape signature on REAL geometry) 88 let mesh: i64 = sys_mmap(m3_bytes()) as i64 89 m3_init(mesh) 90 var vcap: i64 = npts 91 if vcap > 4096 { vcap = 4096 } 92 i = 0 93 while i < vcap { m3_add_vert(mesh, pts[i * 3], pts[i * 3 + 1], pts[i * 3 + 2]); i = i + 1 } 94 let desc: *i64 = sys_mmap(16) as *i64 95 pid_descriptor(mesh, desc) 96 sp_puts(" nx_partid descriptor of the real cloud = (" as *u8); sp_putn(desc[0]); sp_puts("," as *u8); sp_putn(desc[1]); sp_puts(")\n" as *u8) 97 var t4: i64 = 0 98 if desc[0] >= 0 { if desc[0] <= 1000 { if desc[1] >= 0 { if desc[1] <= desc[0] { if desc[0] > 0 { t4 = 1 } } } } } 99 let ig4: i64 = gg_tooth("T4 real cloud feeds nx_partid (valid shape descriptor on REAL geometry)" as *u8, t4, fails) 100 101 // T5 determinism 102 let pts2: *i64 = sys_mmap(maxp * 24 + 64) as *i64 103 let npts2: i64 = sg_extract_points(st, pts2, maxp) 104 var t5: i64 = 0 105 if npts2 == npts { if pts2[3] == pts[3] { if pts2[npts * 3 - 1] == pts[npts * 3 - 1] { t5 = 1 } } } 106 let ig5: i64 = gg_tooth("T5 deterministic" as *u8, t5, fails) 107 108 sp_puts("\nP3a REAL GEOMETRY: the STEP model's actual coordinates, sovereign fixed-point -- not just the assembly\n" as *u8) 109 sp_puts("tree. Feeds bbox + nx_partid (shape ID now runs on REAL CAD geometry). NEXT: planar-face tessellation\n" as *u8) 110 sp_puts("(ADVANCED_FACE->EDGE_LOOP->verts, real triangles) then B-spline surfaces = full from-file geometry.\n" as *u8) 111 sp_puts("\nfails=" as *u8); sp_putn(fails[0]); sp_puts("\n" as *u8) 112 if fails[0] == 0 { sp_puts("GREEN -- real geometry extraction 5/5 (STEP CARTESIAN_POINT cloud, known coords + partid compose)\n" as *u8); return 0 } 113 sp_puts("RED\n" as *u8) 114 return 1 115}