nx_twinfit_lib.nx
buildroot/runtime/nx_twinfit_lib.nx
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
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
| 15 | const TW_GENES: i64 = 7 |
| 16 | const TW_LEVELS: i64 = 3 |
| 17 | const TW_AXES: i64 = 5 |
| 18 | const TW_I64: i64 = 8 |
| 19 | const TW_SLOTS: i64 = 8 |
| 20 | const TW_CAMZ_UNITS: i64 = 4 // the camera distance every face gate renders at |
| 23 | const TW_RENDER_WORKERS: i64 = 0 |
| 24 | const TW_YAW_FRONTAL: i64 = 0 |
| 25 | const TW_SKIN_R: i64 = 232 // persongen's fair-medium tone family, the default so a sweep moves geometry only |
| 26 | const TW_SKIN_G: i64 = 196 |
| 27 | const TW_SKIN_B: i64 = 166 |
| 28 | const TW_SKIN_FIELDS: i64 = 3 |
| 29 | const TW_SKIN_SLOT_R: i64 = 0 |
| 30 | const TW_SKIN_SLOT_G: i64 = 1 |
| 31 | const TW_SKIN_SLOT_B: i64 = 2 |
| 32 | const TW_BYTE: i64 = 255 |
| 33 | const TW_SHIFT_G: i64 = 8 |
| 34 | const TW_SHIFT_B: i64 = 16 |
| 35 | const TW_RGB_BPP: i64 = 3 |
| 36 | const TW_PERMIL: i64 = 1000 |
| 37 | const TW_HALF: i64 = 2 |
| 38 | const TW_NL: i64 = 10 |
| 39 | const TW_UNSET: i64 = 0 - 1 |
| 40 | const TW_BIG: i64 = 1000000000 |
| 41 | const TW_PNG_ANNOUNCE: i64 = 1 |
| 43 | const TW_W_LO: i64 = 85 |
| 44 | const TW_W_HI: i64 = 118 |
| 45 | const TW_L_LO: i64 = 88 |
| 46 | const TW_L_HI: i64 = 114 |
| 47 | const TW_J_LO: i64 = 80 |
| 48 | const TW_J_HI: i64 = 126 |
| 49 | const TW_E_LO: i64 = 85 |
| 50 | const TW_E_HI: i64 = 120 |
| 51 | const TW_P_LO: i64 = 78 |
| 52 | const TW_P_HI: i64 = 132 |
| 53 | const TW_N_LO: i64 = 84 |
| 54 | const TW_N_HI: i64 = 122 |
| 55 | const TW_C_LO: i64 = 82 |
| 56 | const TW_C_HI: i64 = 128 |
| 58 | const TW_AX_TILT_R: i64 = 0 |
| 59 | const TW_AX_TILT_L: i64 = 1 |
| 60 | const TW_AX_ICI: i64 = 2 |
| 61 | const TW_AX_ICF: i64 = 3 |
| 62 | const TW_AX_LIP: i64 = 4 |
| 63 | const TW_FIELD_NAME: i64 = 1 |
| 64 | const TW_FIELD_VALUE: i64 = 2 |
| 65 | const TW_FIELD_ERR: i64 = 3 |
| 269 | const TW_DECI: i64 = 10 |
| 270 | const TW_PIX_CENTRE_DECI: i64 = 5 // the renderer shoots through pixel centres: index = position - one half |
| 271 | const TW_T_RLAT_X: i64 = 0 // the order the ruler uses (PM_R_RLAT_X ..): RLAT, RMED, LMED, LLAT, each x then y |
| 272 | const TW_T_RLAT_Y: i64 = 1 |
| 273 | const TW_T_RMED_X: i64 = 2 |
| 274 | const TW_T_RMED_Y: i64 = 3 |
| 275 | const TW_T_LMED_X: i64 = 4 |
| 276 | const TW_T_LMED_Y: i64 = 5 |
| 277 | const TW_T_LLAT_X: i64 = 6 |
| 278 | const TW_T_LLAT_Y: i64 = 7 |
| 279 | const TW_T_OK: i64 = 8 |
| 280 | const TW_T_EXO: i64 = 9 |
| 281 | const TW_T_TILT_R: i64 = 10 |
| 282 | const TW_T_TILT_L: i64 = 11 |
| 283 | const TW_T_REASON_R: i64 = 12 |
| 284 | const TW_T_REASON_L: i64 = 13 |
| 285 | const TW_T_ASYM_PERMIL: i64 = 14 // mean mirror error of the four closures, permil of the mean fissure width |
| 286 | const TW_T_MODEL_R: i64 = 16 // model units, per eye: med x, med y, lat x, lat y, aperture height, fissure width, surface gap |
| 287 | const TW_T_MODEL_L: i64 = 23 |
| 288 | const TW_TM_MED_X: i64 = 0 |
| 289 | const TW_TM_MED_Y: i64 = 1 |
| 290 | const TW_TM_LAT_X: i64 = 2 |
| 291 | const TW_TM_LAT_Y: i64 = 3 |
| 292 | const TW_TM_HEIGHT: i64 = 4 |
| 293 | const TW_TM_WIDTH: i64 = 5 |
| 294 | const TW_TM_GAP: i64 = 6 // the larger stated-to-found distance of the two corners, model units |
| 295 | const TW_T_N: i64 = 32 |
| 296 | const TW_LANDMARKS: i64 = 4 |
| 297 | const TW_XY: i64 = 2 |
| 298 | const 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 |
| 299 | const TW_EYE_IMAGE_RIGHT: i64 = 1 |
| 300 | const TW_TRUTH_NO_SURFACE: i64 = FA_PF_R_NO_SURFACE |
| 302 | const TW_J_FIELDS: i64 = 3 |
| 303 | const TW_J_DX: i64 = 0 |
| 304 | const TW_J_DY: i64 = 1 |
| 305 | const TW_J_NME: i64 = 2 |
| 306 | const TW_J_NMAX: i64 = 12 |
| 307 | const TW_J_NMEAN: i64 = 13 |
| 308 | const TW_J_N: i64 = 16 |
| 396 | const TW_MILLI: i64 = 1000 |
| 397 | const TW_T_ROLL: i64 = 15 |
| 525 | const TW_ALL_GENES: i64 = TW_GENES + FA_EG_N |
| 526 | const TW_CANON_PCT: i64 = 100 |
| 527 | const TW_FIT_BAND_WEIGHT: i64 = 16 // one unit outside an error band costs as much as sixteen units of distance inside it |
| 528 | const TW_FIT_STEP_FIRST: i64 = 8 |
| 529 | const TW_FIT_MAX_PASSES: i64 = 12 |
| 530 | const TW_FIT_DIAGONALS: i64 = 4 // the four sign pairs of a two-gene move |
| 531 | const TW_AXIS_REACHED: i64 = 1 |
| 532 | const TW_AXIS_UNREACHED: i64 = 0 |
| 533 | const TW_AXIS_UNSTATED: i64 = 2 |
| 534 | const TW_AXIS_NO_TARGET: i64 = 3 |
| 734 | const TW_LT_LS_X: i64 = 0 // image order: labrale superius, stomion, labrale inferius, image-left and image-right cheilion |
| 735 | const TW_LT_STO_X: i64 = 2 |
| 736 | const TW_LT_LI_X: i64 = 4 |
| 737 | const TW_LT_CHR_X: i64 = 6 // image left: the subject's right commissure (model x < 0) |
| 738 | const TW_LT_CHL_X: i64 = 8 |
| 739 | const TW_LT_OK: i64 = 10 |
| 740 | const TW_LT_REASON: i64 = 11 |
| 741 | const TW_LT_RATIO_STATED: i64 = 12 // upper over lower in model units, permil (fa_lip_stated's own ratio) |
| 742 | const TW_LT_RATIO_PIXEL: i64 = 13 // the same ratio on the projected points, permil |
| 743 | const TW_LT_EXO: i64 = 14 // the stated eye unit's outer-canthal span, deci-pixels |
| 744 | const TW_LT_MODEL: i64 = 16 // + 3k: landmark k in MODEL units -- x, y and the depth z it was lifted to |
| 745 | const TW_LT_MODEL_FIELDS: i64 = 3 |
| 746 | const TW_LT_N: i64 = 32 |
| 747 | const TW_LIP_LANDMARKS: i64 = 5 |
| 748 | const TW_LT_R_OK: i64 = 0 |
| 749 | const TW_LT_R_NO_SURFACE: i64 = 1 // a stated lip point has no surface under it on the march |
| 750 | const TW_LT_R_NO_EYES: i64 = 2 // the eye unit states no canthi, so there is no span to normalise by |
| 751 | const TW_LT_R_BEHIND: i64 = 3 // a lifted lip point is not in front of the camera |
| 753 | const TW_LJ_NMAX: i64 = 15 |
| 754 | const TW_LJ_NMEAN: i64 = 16 |
| 755 | const TW_LJ_RATIO_RULER: i64 = 17 |
| 756 | const TW_LJ_RATIO_TRUTH: i64 = 18 |
| 757 | const TW_LJ_N: i64 = 20 |
functions
| 67 | func tw_gene_name(k: i64) -> *u8 |
| 76 | func tw_axis_name(a: i64) -> *u8 |
| 83 | func tw_level_name(l: i64) -> *u8 |
| 88 | func tw_lo(k: i64) -> i64 |
| 97 | func tw_hi(k: i64) -> i64 |
| 106 | func tw_mid(k: i64) -> i64 { return (tw_lo(k) + tw_hi(k)) / TW_HALF } |
| 107 | func tw_level_pct(k: i64, l: i64) -> i64 |
| 112 | func tw_kv(k: *u8, v: i64) -> i64 { ri_puts(k); ri_putn(v); return 0 } |
| 113 | func tw_atoi(s: *u8) -> i64 |
| 126 | func tw_skin_default(skin: *i64) -> i64 |
| 131 | func tw_build(base: i64, g: *i64) -> i64 |
| 143 | func tw_unpack(fb: *i64, n: i64, rgb: *u8) -> i64 |
| 155 | func tw_render_rgb(base: i64, g: *i64, skin: *i64, rgb: *u8) -> i64 |
| 163 | func tw_measure(base: i64, g: *i64, skin: *i64, rgb: *u8, res: *i64, face_c: *HaarCascade, eye_c: *HaarCascade) -> i64 |
| 169 | func tw_render_png(base: i64, seed: i64, yaw: i64, path: *u8, skin: *i64, idv: *i64) -> i64 |
| 175 | func tw_axis_value(res: *i64, a: i64) -> i64 called by 1: main |
| 182 | func tw_print_axes(res: *i64) -> i64 |
| 190 | func tw_streq_span(buf: *u8, s: i64, e: i64, lit: *u8) -> i64 called by 1: tw_load_target |
| 200 | func tw_target_clear(tv: *i64, te: *i64) -> i64 |
| 206 | func tw_load_target(path: *u8, tv: *i64, te: *i64) -> i64 called by 3: mainmaintwr_fit_report calls 7: tw_target_clearsys_mmapri_loadpm_fieldtw_streq_spantw_axis_name+1 |
| 244 | func tw_reach(target: i64, err: i64, amin: i64, amax: i64) -> i64 |
| 249 | func tw_load_cascades(out: *i64) -> i64 |
| 310 | func tw_landmark_name(k: i64) -> *u8 |
| 316 | func tw_truth_reason_name(r: i64) -> *u8 called by 1: tw_print_truth |
| 326 | func tw_project(px: i64, py: i64, pz: i64, yaw: i64, out2: *i64) -> i64 |
| 346 | func 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 called by 1: tw_truth_landmarks calls 6: fa_palpebral_fissurefa_lid_cornerpm_distpm_maxfa_lid_corner_ztw_project |
| 377 | func tw_project_s(px: i64, py: i64, pz: i64, yaw: i64, scale: i64, out2: *i64) -> i64 |
| 398 | func tw_fine_tilts(base: i64, yaw: i64, t: *i64) -> i64 |
| 434 | func tw_truth_landmarks(base: i64, yaw: i64, t: *i64) -> i64 called by 4: twc_truth_rowmaintwr_fit_reporttg_at39 calls 6: sys_mmaptw_truth_eyepm_disttw_fine_tiltspm_abspm_max |
| 456 | func tw_judge(res: *i64, t: *i64, j: *i64) -> i64 |
| 480 | func tw_measure_seed(base: i64, seed: i64, skin: *i64, idv: *i64, rgb: *u8, res: *i64, face_c: *HaarCascade, eye_c: *HaarCascade) -> i64 |
| 489 | func tw_print_truth(t: *i64) -> i64 |
| 509 | func tw_render_genome_png(base: i64, g: *i64, skin: *i64, yaw: i64, camz_units: i64, path: *u8) -> i64 |
| 536 | func tw_all_name(k: i64) -> *u8 { if k < TW_GENES { return tw_gene_name(k) } return fa_eye_gene_name(k - TW_GENES) } |
| 537 | func tw_all_lo(k: i64) -> i64 { if k < TW_GENES { return tw_lo(k) } return fa_eye_gene_lo(k - TW_GENES) } |
| 538 | func tw_all_hi(k: i64) -> i64 { if k < TW_GENES { return tw_hi(k) } return fa_eye_gene_hi(k - TW_GENES) } |
| 539 | func tw_all_canon(k: i64) -> i64 { if k < TW_GENES { return TW_CANON_PCT } return fa_eye_gene_canon(k - TW_GENES) } |
| 540 | func 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 } |
| 542 | func tw_build_all(base: i64, ga: *i64) -> i64 called by 5: maintg_at40tw_fit_evaltw_render_all_pngtwr_fit_report calls 2: tw_buildfaceanat_eye_genes |
| 549 | func tw_stated_landmarks(base: i64, yaw: i64, t: *i64) -> i64 |
| 584 | func tw_axes_from_landmarks(t: *i64, ax: *i64) -> i64 |
| 598 | func tw_fit_cost(ax: *i64, tv: *i64, te: *i64) -> i64 |
| 612 | func tw_fit_eval(base: i64, ga: *i64, tv: *i64, te: *i64, t: *i64, ax: *i64) -> i64 |
| 621 | func tw_fit_pair_pass(base: i64, tv: *i64, te: *i64, ga: *i64, t: *i64, axt: *i64, step: i64, best: *i64, evals: *i64) -> i64 |
| 659 | func tw_fit_single_pass(base: i64, tv: *i64, te: *i64, ga: *i64, t: *i64, axt: *i64, step: i64, best: *i64, evals: *i64) -> i64 |
| 682 | func tw_fit(base: i64, tv: *i64, te: *i64, ga: *i64, ax: *i64, cost_out: *i64) -> i64 called by 3: maintg_at40twr_fit_report calls 4: sys_mmaptw_fit_evaltw_fit_single_passtw_fit_pair_pass |
| 707 | func tw_axis_state(ax: *i64, tv: *i64, te: *i64, a: i64) -> i64 |
| 713 | func tw_axis_state_name(s: i64) -> *u8 |
| 720 | func tw_render_all_png(base: i64, ga: *i64, skin: *i64, yaw: i64, camz_units: i64, path: *u8) -> i64 |
| 759 | func tw_lip_landmark_name(k: i64) -> *u8 |
| 766 | func tw_lip_reason_name(r: i64) -> *u8 called by 1: tw_print_lip_truth |
| 774 | func tw_lip_point(base: i64, x: i64, y: i64, zin: i64, yaw: i64, lt: *i64, slot: i64, p2: *i64) -> i64 |
| 793 | func tw_lip_front_z(base: i64, part: i64, t: i64) -> i64 called by 1: tw_lip_seam_z |
| 800 | func 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 } |
| 803 | func tw_lip_truth(base: i64, yaw: i64, lt: *i64) -> i64 |
| 834 | func tw_lip_judge(res: *i64, lt: *i64, j: *i64) -> i64 |
| 859 | func tw_print_lip_truth(lt: *i64) -> i64 |