code wiki / _hdl_build / nx_twinbench.nx

nx_twinbench.nx

buildroot/runtime/_hdl_build/nx_twinbench.nx

36072 B672 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind bench
docsdependenciesstructsconstsfunctions

about

nx_twinbench.nx -- ★★★THE METRIC RULER, AND THE PRIMARY INSTRUMENT OF THE DIGITAL-TWIN PROGRAM. WHY THIS COMES FIRST. The program's governing law is capability = MIN(statistical, perceptual), and the perceptual term has always been an OPERATOR'S GLANCE -- no organ emits it, so every "we moved 175 -> X" has been unfalsifiable by construction. Aiming at a photoreal PLAUSIBLE human made that unavoidable: "does this look real" is a matter of judgement. Aiming at a 1:1 TWIN OF A SPECIFIC PERSON does not. "Is this surface within one millimetre of that person's face" is arithmetic. ★★THE TWIN TARGET MAKES MEASUREMENT EASIER, NOT HARDER -- it hands us a hard ruler the aesthetic target never could, and this organ is that ruler. WHAT IT MEASURES: the deviation of a candidate surface from a reference surface, as a distribution rather than one number -- mean, RMS, p95, and max (a one-sided Hausdorff). Reported in MILLIMETRES, because a surgeon does not plan in per-mille and a bench number that cannot be compared to a caliper is decoration. ★POINT-TO-TRIANGLE, NOT POINT-TO-VERTEX, AND THE DIFFERENCE IS NOT PEDANTRY. Nearest-VERTEX distance is the easy version and it is BIASED: it reports error proportional to the reference's tessellation, so a coarser reference scores worse for reasons that have nothing to do with the subject. A ruler whose reading depends on how finely you happened to triangulate the truth is not a ruler. So every query point is measured to the nearest point ON A TRIANGLE -- face interior, edge, or vertex, whichever is closest. ★A UNIFORM GRID, BECAUSE THE HONEST ALGORITHM MUST ALSO TERMINATE. Brute force is O(N*M): 35k vertices against 35k triangles is 1.2 billion point-triangle tests per comparison, and a ruler nobody runs is a ruler that does not exist. Reference triangles are bucketed into a uniform grid; a query expands its search radius ring by ring and STOPS ONLY when the next ring cannot contain anything closer than the best found so far. That last clause is what keeps it EXACT rather than approximate -- the grid changes the cost, never the answer, and T6 proves it against brute force on a small mesh. nx_twinbench cmp <candidate.nxmesh> <reference.nxmesh> [stature_mm] [layer] nx_twinbench selftest license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26).

dependencies 1 imports · 0 importers

nx_gate_verdict.nx nx_twinbench.nx

imports: nx_gate_verdict.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main tb_streq tb_gate gv_ctr sys_mmap gv_head gv_puts sys_write tb_fx_quad tb_cmp tb_grid_build tb_nearest2 tb_ptri2 tb_max6 tb_absi tb_shift_for tb_sh tb_frac tb_absi ↻ tb_sh ↻ tb_pseg2 tb_shift_for ↻ tb_max6 ↻ tb_sh ↻ tb_frac ↻ tb_isqrt gv_check gv_puts ↻ tb_grid_build ↻ tb_nearest2 ↻ tb_isqrt ↻ tb_ptri2 ↻ gv_verdict gv_puts ↻ gv_num sys_mmap ↻ sys_write ↻ sys_munmap gv_journal sys_openat_append

structs

none

consts

32const TB_MAGIC_16383: i64 = 16383
33const TB_MAGIC_4000000000: i64 = 4000000000
34const TB_MAGIC_1750: i64 = 1750
35const TB_MAGIC_4950: i64 = 4950
36const TB_MAGIC_5050: i64 = 5050
37const TB_MAGIC_4000: i64 = 4000
38const TB_MAGIC_1000000: i64 = 1000000
40const TB_M8388607: i64 = 8388607
41const TB_M8388608: i64 = 8388608
42const TB_HDR: i64 = 16
43const TB_LAYENT: i64 = 24
44const TB_TRI: i64 = 84
45const TB_LID: i64 = 4
46const TB_Q: i64 = 1000
51const TB_SCALE: i64 = 1024
52const TB_UM: i64 = 1000
53const TB_STATURE: i64 = 1750
54const TB_GRID: i64 = 48
55const TB_CELLS: i64 = 110592
56const TB_MAXTRI: i64 = 400000
57const TB_MAXQ: i64 = 200000
58const TB_BIG: i64 = 4611686018427387903
59const TB_OUT: i64 = 24
60const TB_FRAC: i64 = 1048576
62const TB_TARGET: i64 = 40000
236const TB_MH: i64 = 8

functions

64func tb_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 2: tb_pmmmain
65func tb_pn(v: i64) -> i64
called by 2: tb_pmmmain
75func tb_pmm(um: i64) -> i64
called by 1: main calls 2: tb_putstb_pn
87func tb_streq(a: *u8, b: *u8) -> i64
called by 1: main
92func tb_atoi(s: *u8) -> i64
called by 1: main
98func tb_rd32(b: *u8, o: i64) -> i64
called by 2: tb_f32multb_load
101func tb_f32mul(b: *u8, o: i64, mul: i64) -> i64
called by 1: tb_load calls 1: tb_rd32
114func tb_isqrt(v: i64) -> i64
called by 2: tb_cmptb_gate
137func tb_shift_for(m: i64) -> i64
called by 2: tb_pseg2tb_ptri2
143func tb_sh(v: i64, sh: i64) -> i64
147func tb_absi(v: i64) -> i64 { if v < 0 { return 0-v } return v }
called by 2: tb_max6tb_frac
148func tb_max6(a: i64, b: i64, c: i64, d: i64, e: i64, f: i64) -> i64
called by 2: tb_pseg2tb_ptri2 calls 1: tb_absi
158func tb_frac(num: i64, den: i64) -> i64
called by 2: tb_pseg2tb_ptri2 calls 2: tb_absitb_sh
167func tb_pseg2(px: i64, py: i64, pz: i64, ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64) -> i64
189func tb_ptri2(px: i64, py: i64, pz: i64,
237func tb_load(path: *u8, M: *i64, cap: i64) -> i64
called by 1: main calls 3: sys_read_filetb_rd32tb_f32mul
292func tb_cbrt(v: i64) -> i64
297func tb_grid_build(M: *i64, G: *i64, head: *i64, nxt: *i64) -> i64
called by 2: tb_cmptb_gate
330func tb_nearest2(px: i64, py: i64, pz: i64, M: *i64, G: *i64, head: *i64, nxt: *i64) -> i64
called by 2: tb_cmptb_gate calls 1: tb_ptri2
385func tb_cmp(candA: *i64, refB: *i64, out: *i64, stature: i64, target: i64) -> i64
480func tb_fx_quad(M: *i64, h: i64, dz: i64) -> i64
called by 1: tb_gate
494func tb_gate() -> i64
590func main(argc: i64, argv: *i64) -> i64