nx_bvh_nearest_math_gate_t284.nx source
↩ module page · 41 lines · 2633 B
1import "nx_bvh_nearest_candidate_t284.nx"
2import "nx_gate_verdict.nx"
3func bq_case(ctr:*i64,out:*f64,scratch:*f64,x:i64,y:i64,z:i64,ex:i64,ey:i64,ez:i64,d2:i64)->i64{
4 bq_triangle(out,scratch,bq_f(x),bq_f(y),bq_f(z),0.0,0.0,0.0,10.0,0.0,0.0,0.0,10.0,0.0)
5 gv_check_eq("nearest x" as *u8,nx_f64_to_i64(out[0] as i64),ex,ctr)
6 gv_check_eq("nearest y" as *u8,nx_f64_to_i64(out[1] as i64),ey,ctr)
7 gv_check_eq("nearest z" as *u8,nx_f64_to_i64(out[2] as i64),ez,ctr)
8 gv_check_eq("squared distance" as *u8,nx_f64_to_i64(out[3] as i64),d2,ctr)
9 return 0
10}
11func main()->i64{
12 let ctr:*i64=gv_ctr();gv_head("nearest triangle controls" as *u8)
13 let o:*f64=sys_mmap(32) as *f64;let s:*f64=sys_mmap(32) as *f64
14 bq_case(ctr,o,s,2,3,4,2,3,0,16)
15 bq_case(ctr,o,s,0-3,0-4,0,0,0,0,25)
16 bq_case(ctr,o,s,6,6,0,5,5,0,2)
17 bq_case(ctr,o,s,2,3,0-4,2,3,0,16)
18 let d:i64=bq_triangle(o,s,5.0,3.0,0.0,0.0,0.0,0.0,10.0,0.0,0.0,20.0,0.0,0.0)
19 gv_check_eq("collinear reported" as *u8,d,1,ctr)
20 gv_check_eq("collinear segment distance" as *u8,nx_f64_to_i64(o[3] as i64),9,ctr)
21 let p:i64=bq_triangle(o,s,1.0,2.0,2.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
22 gv_check_eq("point triangle reported" as *u8,p,1,ctr)
23 gv_check_eq("point triangle distance" as *u8,nx_f64_to_i64(o[3] as i64),9,ctr)
24 // Independent tilted-plane fixture: x+y+z=6; P is centroid+(2,2,2).
25 bq_triangle(o,s,4.0,4.0,4.0,6.0,0.0,0.0,0.0,6.0,0.0,0.0,0.0,6.0)
26 gv_check_eq("tilted plane x exact" as *u8,o[0] as i64,nx_i64_to_f64(2),ctr)
27 gv_check_eq("tilted plane y exact" as *u8,o[1] as i64,nx_i64_to_f64(2),ctr)
28 gv_check_eq("tilted plane z exact" as *u8,o[2] as i64,nx_i64_to_f64(2),ctr)
29 gv_check_eq("tilted plane distance exact" as *u8,o[3] as i64,nx_i64_to_f64(12),ctr)
30 // Duplicate-vertex degenerate triangle is a segment, including endpoint region.
31 let dup:i64=bq_triangle(o,s,13.0,4.0,0.0,0.0,0.0,0.0,10.0,0.0,0.0,10.0,0.0,0.0)
32 gv_check_eq("duplicate vertex degeneracy" as *u8,dup,1,ctr)
33 gv_check_eq("duplicate endpoint x" as *u8,o[0] as i64,nx_i64_to_f64(10),ctr)
34 gv_check_eq("duplicate endpoint distance" as *u8,o[3] as i64,nx_i64_to_f64(25),ctr)
35 // Opposite winding preserves the independently known edge midpoint.
36 bq_triangle(o,s,6.0,6.0,0.0,0.0,10.0,0.0,10.0,0.0,0.0,0.0,0.0,0.0)
37 gv_check_eq("reverse winding edge x" as *u8,o[0] as i64,nx_i64_to_f64(5),ctr)
38 gv_check_eq("reverse winding edge y" as *u8,o[1] as i64,nx_i64_to_f64(5),ctr)
39 gv_check_eq("reverse winding distance" as *u8,o[3] as i64,nx_i64_to_f64(2),ctr)
40 return gv_verdict("nx_bvh_nearest_math_gate_t284" as *u8,ctr,"finite representative triangle controls; not full BVH or near-degenerate robustness" as *u8)
41}