code wiki / _hdl_build / nx_meshview_projection_canonical_gate_t332.nx

nx_meshview_projection_canonical_gate_t332.nx source

↩ module page · 31 lines · 2362 B

1import "nx_mesh2glb.nx" 2import "nx_tool_run.nx" 3import "nx_gate_verdict.nx" 4func mpg_fixture(path:*u8,value:i64,den:i64)->i64{ 5 if st_fix(path)!=0{return -1};let sz:*i64=sys_mmap(16) as *i64;let b:*u8=sys_read_file(path,sz) 6 if (b as i64)==0||sz[0]!=128{return -1} 7 mg_w32(b,52,mg_f32_frac(value,den));mg_w32(b,68,mg_f32_frac(value,den)) 8 let fd:i64=sys_openat_wr(path,420);if fd<0{return -1};let n:i64=sys_write(fd,b,128);sys_close(fd);if n!=128{return -1};return 0 9} 10func mpg_render(elf:*u8,input:*u8,output:*u8)->i64{ 11 let a:*i64=sys_mmap(40) as *i64;a[0]=elf as i64;a[1]=input as i64;a[2]=output as i64;a[3]="0" as *u8 as i64;a[4]=0 12 let o:*u8=sys_mmap(4096);let n:*i64=sys_mmap(8) as *i64;*n=0;let r:i64=tr_run_capture_to(elf,a,o,4096,n,30000);sys_write(1,o,*n);return r 13} 14func mpg_equal(a:*u8,b:*u8)->i64{ 15 let an:*i64=sys_mmap(8) as *i64;let bn:*i64=sys_mmap(8) as *i64;let ap:*u8=sys_read_file(a,an);let bp:*u8=sys_read_file(b,bn) 16 if (ap as i64)==0||(bp as i64)==0||*an!=*bn||*an<100{return 0};var i:i64=0;while i<*an{if ap[i]!=bp[i]{return 0};i=i+1};return 1 17} 18func main()->i64{ 19 let c:*i64=gv_ctr();gv_head("Native mesh projection scale invariance") 20 let root:*u8=sys_mmap(128);var n:i64=mg_cat(root,0,"/tmp/nishi-projection-t332-");n=mg_num(root,n,sys_now_ms());root[n]=0 as u8 21 if sys_mkdir(root,493)!=0||sys_chdir(root)!=0{return 3} 22 if mpg_fixture("small.nxmesh",500,1000)!=0||mpg_fixture("large.nxmesh",65536,1)!=0{return 3} 23 let candidate:*u8="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_meshview.sov.elf" 24 let old:*u8="/volume1/homes/elderwesto/nishihost/knowledge/gates/nx_meshview-before-projection-t332.elf" 25 gv_check("small0.5source-unit fixture renders",mpg_render(candidate,"small.nxmesh","small.png")==0,c) 26 gv_check("large65536source-unit fixture renders",mpg_render(candidate,"large.nxmesh","large.png")==0,c) 27 gv_check("integer-projection-equivalent fixture PNG bytes identical",mpg_equal("small.png","large.png")==1,c) 28 gv_check("incumbent large fixture executes",mpg_render(old,"large.nxmesh","old-large.png")==0,c) 29 gv_check("negative control catches old ratio collapse",mpg_equal("small.png","old-large.png")==0,c) 30 return gv_verdict("mesh-projection",c,"Exact all-view integer projection equivalent source spans; candidate PNG equality plus live-old negative control. Arbitrary float overflow domain not claimed.") 31}