code wiki / (root) / nx_twinfit_lib.nx

nx_twinfit_lib.nx

buildroot/runtime/nx_twinfit_lib.nx

44515 B870 linesdepth 11pulls 63 transitivereach 8 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_twinfit_lib.nx -- aesthetictwin AT34/AT35 (2026-09-17): THE TWIN LOOP'S SUBSTRATE. One library that (1) builds a face from explicit morph percents over the inside-out nx_faceanat face, (2) renders it through the sovereign SDF renderer, (3) hands the framebuffer to the photo ruler IN-PROCESS (no PNG round trip) so a render is judged exactly as a photograph is, (4) renders a persongen identity to a PNG for the file door, (5) reads a target file of card axes and decides REACHABLE against an envelope. Consumers: nx_twinfit (envelope / axes), nx_twinface (render to PNG), nx_twinfit_gate (planted controls). The seven ranges are persongen_build's declared identity ranges (nx_persongen.nx pg_range calls), copied here as DATA with that provenance; a morph outside its range is not a face the generator would ever emit. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 5 imports · 6 importers

nx_syscalls.nx nx_persongen.nx nx_sdfrender_mt.nx nx_png.nx nx_photomark_lib.nx nx_twinfit_lib.nx nx_mediajudge_gate.nx nx_twinface.nx nx_twinfit.nx nx_twinfit_gate.nx nx_twinreport_lib.nx nx_twintruth_gate.nx

imports: nx_syscalls.nxnx_persongen.nxnx_sdfrender_mt.nxnx_png.nxnx_photomark_lib.nx

imported by: nx_mediajudge_gate.nxnx_twinface.nxnx_twinfit.nxnx_twinfit_gate.nxnx_twinreport_lib.nxnx_twintruth_gate.nx

structs

none

consts

15const TW_GENES: i64 = 7
16const TW_LEVELS: i64 = 3
17const TW_AXES: i64 = 5
18const TW_I64: i64 = 8
19const TW_SLOTS: i64 = 8
20const TW_CAMZ_UNITS: i64 = 4 // the camera distance every face gate renders at
23const TW_RENDER_WORKERS: i64 = 0
24const TW_YAW_FRONTAL: i64 = 0
25const TW_SKIN_R: i64 = 232 // persongen's fair-medium tone family, the default so a sweep moves geometry only
26const TW_SKIN_G: i64 = 196
27const TW_SKIN_B: i64 = 166
28const TW_SKIN_FIELDS: i64 = 3
29const TW_SKIN_SLOT_R: i64 = 0
30const TW_SKIN_SLOT_G: i64 = 1
31const TW_SKIN_SLOT_B: i64 = 2
32const TW_BYTE: i64 = 255
33const TW_SHIFT_G: i64 = 8
34const TW_SHIFT_B: i64 = 16
35const TW_RGB_BPP: i64 = 3
36const TW_PERMIL: i64 = 1000
37const TW_HALF: i64 = 2
38const TW_NL: i64 = 10
39const TW_UNSET: i64 = 0 - 1
40const TW_BIG: i64 = 1000000000
41const TW_PNG_ANNOUNCE: i64 = 1
43const TW_W_LO: i64 = 85
44const TW_W_HI: i64 = 118
45const TW_L_LO: i64 = 88
46const TW_L_HI: i64 = 114
47const TW_J_LO: i64 = 80
48const TW_J_HI: i64 = 126
49const TW_E_LO: i64 = 85
50const TW_E_HI: i64 = 120
51const TW_P_LO: i64 = 78
52const TW_P_HI: i64 = 132
53const TW_N_LO: i64 = 84
54const TW_N_HI: i64 = 122
55const TW_C_LO: i64 = 82
56const TW_C_HI: i64 = 128
58const TW_AX_TILT_R: i64 = 0
59const TW_AX_TILT_L: i64 = 1
60const TW_AX_ICI: i64 = 2
61const TW_AX_ICF: i64 = 3
62const TW_AX_LIP: i64 = 4
63const TW_FIELD_NAME: i64 = 1
64const TW_FIELD_VALUE: i64 = 2
65const TW_FIELD_ERR: i64 = 3
269const TW_DECI: i64 = 10
270const TW_PIX_CENTRE_DECI: i64 = 5 // the renderer shoots through pixel centres: index = position - one half
271const TW_T_RLAT_X: i64 = 0 // the order the ruler uses (PM_R_RLAT_X ..): RLAT, RMED, LMED, LLAT, each x then y
272const TW_T_RLAT_Y: i64 = 1
273const TW_T_RMED_X: i64 = 2
274const TW_T_RMED_Y: i64 = 3
275const TW_T_LMED_X: i64 = 4
276const TW_T_LMED_Y: i64 = 5
277const TW_T_LLAT_X: i64 = 6
278const TW_T_LLAT_Y: i64 = 7
279const TW_T_OK: i64 = 8
280const TW_T_EXO: i64 = 9
281const TW_T_TILT_R: i64 = 10
282const TW_T_TILT_L: i64 = 11
283const TW_T_REASON_R: i64 = 12
284const TW_T_REASON_L: i64 = 13
285const TW_T_ASYM_PERMIL: i64 = 14 // mean mirror error of the four closures, permil of the mean fissure width
286const TW_T_MODEL_R: i64 = 16 // model units, per eye: med x, med y, lat x, lat y, aperture height, fissure width, surface gap
287const TW_T_MODEL_L: i64 = 23
288const TW_TM_MED_X: i64 = 0
289const TW_TM_MED_Y: i64 = 1
290const TW_TM_LAT_X: i64 = 2
291const TW_TM_LAT_Y: i64 = 3
292const TW_TM_HEIGHT: i64 = 4
293const TW_TM_WIDTH: i64 = 5
294const TW_TM_GAP: i64 = 6 // the larger stated-to-found distance of the two corners, model units
295const TW_T_N: i64 = 32
296const TW_LANDMARKS: i64 = 4
297const TW_XY: i64 = 2
298const TW_EYE_IMAGE_LEFT: i64 = 0 - 1 // model x < 0 lands in the left half of the image at yaw 0: the R eye of the ruler
299const TW_EYE_IMAGE_RIGHT: i64 = 1
300const TW_TRUTH_NO_SURFACE: i64 = FA_PF_R_NO_SURFACE
302const TW_J_FIELDS: i64 = 3
303const TW_J_DX: i64 = 0
304const TW_J_DY: i64 = 1
305const TW_J_NME: i64 = 2
306const TW_J_NMAX: i64 = 12
307const TW_J_NMEAN: i64 = 13
308const TW_J_N: i64 = 16
396const TW_MILLI: i64 = 1000
397const TW_T_ROLL: i64 = 15
525const TW_ALL_GENES: i64 = TW_GENES + FA_EG_N
526const TW_CANON_PCT: i64 = 100
527const TW_FIT_BAND_WEIGHT: i64 = 16 // one unit outside an error band costs as much as sixteen units of distance inside it
528const TW_FIT_STEP_FIRST: i64 = 8
529const TW_FIT_MAX_PASSES: i64 = 12
530const TW_FIT_DIAGONALS: i64 = 4 // the four sign pairs of a two-gene move
531const TW_AXIS_REACHED: i64 = 1
532const TW_AXIS_UNREACHED: i64 = 0
533const TW_AXIS_UNSTATED: i64 = 2
534const TW_AXIS_NO_TARGET: i64 = 3
734const TW_LT_LS_X: i64 = 0 // image order: labrale superius, stomion, labrale inferius, image-left and image-right cheilion
735const TW_LT_STO_X: i64 = 2
736const TW_LT_LI_X: i64 = 4
737const TW_LT_CHR_X: i64 = 6 // image left: the subject's right commissure (model x < 0)
738const TW_LT_CHL_X: i64 = 8
739const TW_LT_OK: i64 = 10
740const TW_LT_REASON: i64 = 11
741const TW_LT_RATIO_STATED: i64 = 12 // upper over lower in model units, permil (fa_lip_stated's own ratio)
742const TW_LT_RATIO_PIXEL: i64 = 13 // the same ratio on the projected points, permil
743const TW_LT_EXO: i64 = 14 // the stated eye unit's outer-canthal span, deci-pixels
744const TW_LT_MODEL: i64 = 16 // + 3k: landmark k in MODEL units -- x, y and the depth z it was lifted to
745const TW_LT_MODEL_FIELDS: i64 = 3
746const TW_LT_N: i64 = 32
747const TW_LIP_LANDMARKS: i64 = 5
748const TW_LT_R_OK: i64 = 0
749const TW_LT_R_NO_SURFACE: i64 = 1 // a stated lip point has no surface under it on the march
750const TW_LT_R_NO_EYES: i64 = 2 // the eye unit states no canthi, so there is no span to normalise by
751const TW_LT_R_BEHIND: i64 = 3 // a lifted lip point is not in front of the camera
753const TW_LJ_NMAX: i64 = 15
754const TW_LJ_NMEAN: i64 = 16
755const TW_LJ_RATIO_RULER: i64 = 17
756const TW_LJ_RATIO_TRUTH: i64 = 18
757const TW_LJ_N: i64 = 20

functions

67func tw_gene_name(k: i64) -> *u8
76func tw_axis_name(a: i64) -> *u8
83func tw_level_name(l: i64) -> *u8
called by 2: twc_truthrefmain
88func tw_lo(k: i64) -> i64
97func tw_hi(k: i64) -> i64
106func tw_mid(k: i64) -> i64 { return (tw_lo(k) + tw_hi(k)) / TW_HALF }
107func tw_level_pct(k: i64, l: i64) -> i64
112func tw_kv(k: *u8, v: i64) -> i64 { ri_puts(k); ri_putn(v); return 0 }
113func tw_atoi(s: *u8) -> i64
called by 3: mainmainmain
126func tw_skin_default(skin: *i64) -> i64
131func tw_build(base: i64, g: *i64) -> i64
143func tw_unpack(fb: *i64, n: i64, rgb: *u8) -> i64
155func tw_render_rgb(base: i64, g: *i64, skin: *i64, rgb: *u8) -> i64
163func tw_measure(base: i64, g: *i64, skin: *i64, rgb: *u8, res: *i64, face_c: *HaarCascade, eye_c: *HaarCascade) -> i64
169func tw_render_png(base: i64, seed: i64, yaw: i64, path: *u8, skin: *i64, idv: *i64) -> i64
175func tw_axis_value(res: *i64, a: i64) -> i64
called by 1: main
182func tw_print_axes(res: *i64) -> i64
called by 1: main calls 1: tw_kv
190func tw_streq_span(buf: *u8, s: i64, e: i64, lit: *u8) -> i64
called by 1: tw_load_target
200func tw_target_clear(tv: *i64, te: *i64) -> i64
called by 2: maintw_load_target
206func tw_load_target(path: *u8, tv: *i64, te: *i64) -> i64
244func tw_reach(target: i64, err: i64, amin: i64, amax: i64) -> i64
called by 2: mainmain
249func tw_load_cascades(out: *i64) -> i64
310func tw_landmark_name(k: i64) -> *u8
316func tw_truth_reason_name(r: i64) -> *u8
called by 1: tw_print_truth
326func tw_project(px: i64, py: i64, pz: i64, yaw: i64, out2: *i64) -> i64
346func tw_truth_eye(base: i64, eye_sign: i64, yaw: i64, pf: *i64, p2: *i64, t: *i64, slot_med: i64, slot_lat: i64, slot_model: i64) -> i64
377func tw_project_s(px: i64, py: i64, pz: i64, yaw: i64, scale: i64, out2: *i64) -> i64
called by 1: tw_fine_tilts calls 2: it_cos4096it_sin4096
398func tw_fine_tilts(base: i64, yaw: i64, t: *i64) -> i64
434func tw_truth_landmarks(base: i64, yaw: i64, t: *i64) -> i64
456func tw_judge(res: *i64, t: *i64, j: *i64) -> i64
480func tw_measure_seed(base: i64, seed: i64, skin: *i64, idv: *i64, rgb: *u8, res: *i64, face_c: *HaarCascade, eye_c: *HaarCascade) -> i64
489func tw_print_truth(t: *i64) -> i64
509func tw_render_genome_png(base: i64, g: *i64, skin: *i64, yaw: i64, camz_units: i64, path: *u8) -> i64
536func tw_all_name(k: i64) -> *u8 { if k < TW_GENES { return tw_gene_name(k) } return fa_eye_gene_name(k - TW_GENES) }
called by 1: main calls 2: tw_gene_namefa_eye_gene_name
537func tw_all_lo(k: i64) -> i64 { if k < TW_GENES { return tw_lo(k) } return fa_eye_gene_lo(k - TW_GENES) }
538func tw_all_hi(k: i64) -> i64 { if k < TW_GENES { return tw_hi(k) } return fa_eye_gene_hi(k - TW_GENES) }
539func tw_all_canon(k: i64) -> i64 { if k < TW_GENES { return TW_CANON_PCT } return fa_eye_gene_canon(k - TW_GENES) }
540func tw_all_canon_fill(ga: *i64) -> i64 { var k: i64 = 0; while k < TW_ALL_GENES { ga[k] = tw_all_canon(k); k = k + 1 } return 0 }
542func tw_build_all(base: i64, ga: *i64) -> i64
549func tw_stated_landmarks(base: i64, yaw: i64, t: *i64) -> i64
584func tw_axes_from_landmarks(t: *i64, ax: *i64) -> i64
called by 2: tg_at40tw_fit_eval calls 2: pm_distpm_max
598func tw_fit_cost(ax: *i64, tv: *i64, te: *i64) -> i64
called by 2: tg_at40tw_fit_eval calls 1: pm_abs
612func tw_fit_eval(base: i64, ga: *i64, tv: *i64, te: *i64, t: *i64, ax: *i64) -> i64
621func tw_fit_pair_pass(base: i64, tv: *i64, te: *i64, ga: *i64, t: *i64, axt: *i64, step: i64, best: *i64, evals: *i64) -> i64
659func tw_fit_single_pass(base: i64, tv: *i64, te: *i64, ga: *i64, t: *i64, axt: *i64, step: i64, best: *i64, evals: *i64) -> i64
682func tw_fit(base: i64, tv: *i64, te: *i64, ga: *i64, ax: *i64, cost_out: *i64) -> i64
707func tw_axis_state(ax: *i64, tv: *i64, te: *i64, a: i64) -> i64
called by 3: maintg_at40twr_fit_report calls 1: pm_abs
713func tw_axis_state_name(s: i64) -> *u8
called by 2: maintwr_fit_report
720func tw_render_all_png(base: i64, ga: *i64, skin: *i64, yaw: i64, camz_units: i64, path: *u8) -> i64
759func tw_lip_landmark_name(k: i64) -> *u8
766func tw_lip_reason_name(r: i64) -> *u8
called by 1: tw_print_lip_truth
774func tw_lip_point(base: i64, x: i64, y: i64, zin: i64, yaw: i64, lt: *i64, slot: i64, p2: *i64) -> i64
called by 1: tw_lip_truth calls 2: fa_surface_ztw_project
793func tw_lip_front_z(base: i64, part: i64, t: i64) -> i64
called by 1: tw_lip_seam_z
800func tw_lip_seam_z(base: i64, t: i64) -> i64 { return (tw_lip_front_z(base, FA_LIP_U, t) + tw_lip_front_z(base, FA_LIP_L, t)) / TW_HALF }
803func tw_lip_truth(base: i64, yaw: i64, lt: *i64) -> i64
834func tw_lip_judge(res: *i64, lt: *i64, j: *i64) -> i64
859func tw_print_lip_truth(lt: *i64) -> i64