code wiki / (root) / nx_mesh_print_check_test.nx

nx_mesh_print_check_test.nx source

↩ module page · 55 lines · 1912 B

1// nx_mesh_print_check_test.nx -- exercise bbox + manifold check 2// on a synthetic tetrahedron and a deliberately broken mesh. 3// 4// Closed-form invariants: 5// (a) Tetrahedron factory returns non-null mesh with 4 verts + 4 tris. 6// (b) Bbox of unit tetrahedron = (0,0,0) to (EDGE,EDGE,EDGE). 7// (c) Manifold check returns OK on the tetrahedron. 8// (d) Manifold check returns NOT_MANIFOLD when one triangle is 9// deleted (now 3 tris, three edges have no reverse partner). 10// (e) Existing nx_mesh_validate still accepts the tetrahedron 11// (no out-of-range indices). 12// 13// expect_exit: 0 14// license_tier: ORIGINAL 15 16import "nx_mesh.nx" 17import "nx_mesh_print_check.nx" 18 19const EDGE_Q14: i64 = 16384 // 1.0 in Q14 20 21func main() -> i64 { 22 // --- (a) Factory --- 23 let m: *NxMesh = nx_mesh_make_tetrahedron(EDGE_Q14, 0) 24 if (m as i64) == 0 { return 10 } 25 if m.n_verts != 4 { return 11 } 26 if m.n_tris != 4 { return 12 } 27 28 // --- (b) Bbox --- 29 let bb: *NxMeshBBox = nx_mesh_bbox_compute(m) 30 if bb.valid != 1 { return 20 } 31 if bb.min_x != 0 { return 21 } 32 if bb.min_y != 0 { return 22 } 33 if bb.min_z != 0 { return 23 } 34 if bb.max_x != EDGE_Q14 { return 24 } 35 if bb.max_y != EDGE_Q14 { return 25 } 36 if bb.max_z != EDGE_Q14 { return 26 } 37 38 // --- (c) Manifold OK --- 39 let mv: i64 = nx_mesh_is_manifold(m) 40 if mv != NX_MESH_PRINT_OK { return 30 } 41 42 // --- (d) Manifold FAIL after deletion --- 43 // Pretend the last triangle was never added by dropping n_tris 44 // -- existing index buffer entries remain in memory but the 45 // manifold scan only considers tris [0, n_tris). 46 m.n_tris = 3 47 let mv2: i64 = nx_mesh_is_manifold(m) 48 if mv2 != NX_MESH_PRINT_ERR_NOT_MANIFOLD { return 40 } 49 m.n_tris = 4 // restore 50 51 // --- (e) Existing validate still passes --- 52 if nx_mesh_validate(m) != NX_MESH_OK { return 50 } 53 54 return 0 55}