nx_region_edge_gate_t278.nx source
↩ module page · 44 lines · 2645 B
1import "nx_nxa_texbake_region_lib.nx"
2func eg_eq(a:*i64,b:*i64)->i64 {return a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]}
3func eg_old(h:*i64,res:i64,x:i64,y:i64,ft:i64,o:*i64)->i64{
4 let xp:i64=ntr_min(x+1,res-1);let xm:i64=ntr_max(x-1,0)
5 let yp:i64=ntr_min(y+1,res-1);let ym:i64=ntr_max(y-1,0)
6 return ntb_encode_normal_um(h[y*res+xp]-h[y*res+xm],h[yp*res+x]-h[ym*res+x],2*ft,o)
7}
8func eg_check(ok:i64,label:*u8)->i64{if ok==1{nt_outs("PASS ");nt_outs(label);nt_outs("\n");return 0};nt_err("FAIL ");nt_err(label);nt_err("\n");return 1}
9func main()->i64{
10 let res:i64=7;let tp:i64=3
11 let h:*i64=sys_mmap_try(res*res*__size_of(i64)) as *i64
12 let actual:*i64=sys_mmap_try(3*__size_of(i64)) as *i64
13 let expect:*i64=sys_mmap_try(3*__size_of(i64)) as *i64
14 let before:*i64=sys_mmap_try(3*__size_of(i64)) as *i64
15 var fail:i64=0;var y:i64=0
16 while y<res{var x:i64=0;while x<res{h[y*res+x]=(x%tp)*10+(y%tp)*20+(x/tp)*1000+(y/tp)*2000;x=x+1};y=y+1}
17 ntb_encode_normal_um(20,40,20,expect)
18 var allplanar:i64=1;var oldwrong:i64=0;y=0
19 while y<6{var x:i64=0;while x<6{
20 ntr_normal_chart(h,res,tp,x,y,10,actual);if eg_eq(actual,expect)==0{allplanar=0}
21 eg_old(h,res,x,y,10,before);if eg_eq(before,expect)==0{oldwrong=oldwrong+1}
22 x=x+1};y=y+1}
23 fail=fail+eg_check(allplanar,"planar slopes preserved at every edge and corner")
24 fail=fail+eg_check(oldwrong>0,"negative control old stencil fails planar chart boundaries")
25 var poisonok:i64=1
26 ntr_normal_chart(h,res,tp,2,2,10,before)
27 y=0;while y<res{var x:i64=0;while x<res{if x>=tp||y>=tp{h[y*res+x]=(0-16000)};x=x+1};y=y+1}
28 ntr_normal_chart(h,res,tp,2,2,10,actual)
29 fail=fail+eg_check(eg_eq(actual,before),"neighbor chart and odd-size padding poison has no effect")
30 y=0;while y<res{var x:i64=0;while x<res{h[y*res+x]=(x*19+y*71+x*y*13)%97;x=x+1};y=y+1}
31 var interior:i64=1;var ry:i64=0
32 while ry<2{var rx:i64=0;while rx<2{
33 let sample_x:i64=rx*tp+1;let sample_y:i64=ry*tp+1
34 ntr_normal_chart(h,res,tp,sample_x,sample_y,17,actual);eg_old(h,res,sample_x,sample_y,17,before)
35 if eg_eq(actual,before)==0{interior=0};rx=rx+1};ry=ry+1}
36 fail=fail+eg_check(interior,"nonlinear chart interiors remain byte-identical")
37 ntr_normal_chart(h,res,1,3,3,17,actual);ntb_encode_normal_um(0,0,34,expect)
38 fail=fail+eg_check(eg_eq(actual,expect),"single-texel chart has zero unsupported slope")
39 y=0;while y<res{var x:i64=0;while x<res{h[y*res+x]=700;x=x+1};y=y+1}
40 ntr_normal_chart(h,res,tp,0,0,31,actual)
41 fail=fail+eg_check(eg_eq(actual,expect),"constant field remains flat at atlas corner")
42 nt_outs("CHART-NORMAL failures=");nt_outn(fail);nt_outs(" old_planar_failures=");nt_outn(oldwrong);nt_outs("\n")
43 return fail
44}