code wiki / _hdl_build / nx_lipratio_gate.nx
nx_lipratio_gate.nx source
↩ module page · 301 lines · 18583 B
1// nx_lipratio_gate.nx -- GATE for the buildable half of aesthetictwin rung AT4: lip vermilion heights
2// and the upper-to-lower ratio, measured from the BLENDED SURFACE rather than from the part table.
3//
4// THE LOAD-BEARING TOOTH IS T4, AND IT IS THE RUNG'S DONE-RULE STATED AS AN EXPERIMENT. That rule says
5// the axis must be "read from mesh landmarks and NOT from slider positions". Those two are
6// indistinguishable on a healthy face -- both give a plausible number -- so the only way to tell them
7// apart is to CHANGE THE GEOMETRY AND SEE WHICH ONE MOVES. T4 halves the lip parts' vertical radius and
8// requires the measured ratio to change. The estate's existing nx_faceprofile_gate reads lip depth as
9// p[10*6+2], a part-table field that halving ry does not touch at all, so it would sail through T4
10// unchanged -- which is precisely the defect this rung exists to close.
11//
12// T3 is the other half of the same idea from the opposite direction: the stomion this gate EXTRACTED
13// from the surface must agree with the parameter that CARVED it, within a tolerance DERIVED from that
14// carve's own radius plus the blend width rather than typed as a constant. Extraction and parameter
15// are two independent routes to one landmark, so their agreement is a free audit and their
16// disagreement would locate a real defect in whichever is wrong.
17//
18// T5 is the negative control and it is REACHABLE, not decorative: shrunk to a tenth, the face no longer
19// intersects the midline band at all, every probe returns no-surface, and the measure must report
20// UNMEASURED rather than a number. A measure that answered anyway would be reading its own parameters.
21import "nx_syscalls.nx"
22import "nx_gate_verdict.nx"
23import "nx_gatekit_lib.nx"
24import "nx_faceanat.nx"
25
26const LG_ASCII0: i64 = 48
27const LG_MINUS: i64 = 45
28const LG_NL: i64 = 10
29const LG_MOUTH_CARVE: i64 = 20
30const LG_LIP_UPPER: i64 = 10
31const LG_LIP_LOWER: i64 = 11
32const LG_HALF: i64 = 50
33const LG_TENTH: i64 = 10
34const LG_PART_CY: i64 = 1
35const LG_PART_RY: i64 = 4
36const LG_FIELDS: i64 = 6
37const LG_PCT: i64 = 100 // the morphs' neutral percent
38
39func lg_pnum(tag: *u8, v: i64) -> i64 {
40 let b: *u8 = sys_mmap(96)
41 let d: *u8 = sys_mmap(64)
42 var n: i64 = 0
43 var x: i64 = v
44 if x < 0 { b[n] = LG_MINUS; n = n + 1; x = 0 - x }
45 var m: i64 = 0
46 if x == 0 { d[m] = LG_ASCII0; m = m + 1 }
47 while x > 0 {
48 let q: i64 = x / 10
49 d[m] = LG_ASCII0 + (x - q * 10)
50 m = m + 1
51 x = q
52 }
53 while m > 0 { m = m - 1; b[n] = d[m]; n = n + 1 }
54 b[n] = LG_NL
55 n = n + 1
56 sys_write(1, tag, gk_len(tag))
57 sys_write(1, b, n)
58 return 0
59}
60
61func lg_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
62
63func main(argc: i64, argv: *i64) -> i64 {
64 let ctr: *i64 = gv_ctr()
65 gv_head("=== NX-LIPRATIO-GATE -- AT4 lip vermilion ratio read from the surface, not from the sliders ===" as *u8)
66
67 let base: i64 = sys_mmap(sdf_bytes()) as i64
68 faceanat_build(base)
69 // DIAGNOSTIC FIRST, HYPOTHESIS SECOND. If the measure refuses, these say WHICH conjunct refused it:
70 // an interior point that is not inside means the arena is not what the caller thinks it is; a probe
71 // returning no-surface names the exact y where the midline ray missed.
72 lg_pnum("LIPDIAG eval_at_origin_should_be_negative=" as *u8, sdf_eval(base, 0, 0, 0))
73 lg_pnum("LIPDIAG eval_at_mouth_front=" as *u8, sdf_eval(base, 0, 0 - 390, 0 - 600))
74 lg_pnum("LIPDIAG midline_z_at_minus180=" as *u8, fa_midline_z(base, 0 - 180))
75 lg_pnum("LIPDIAG midline_z_at_minus390=" as *u8, fa_midline_z(base, 0 - 390))
76 lg_pnum("LIPDIAG midline_z_at_minus640=" as *u8, fa_midline_z(base, 0 - 640))
77 lg_pnum("LIPDIAG npart=" as *u8, (((base + O_NPART) as *i64))[0])
78 // PRINT THE PROFILE, DO NOT INFER IT. Whether the lower vermilion border is missing because the
79 // geometry has no mentolabial sulcus, or because a widened band let the under-chin win the stomion
80 // search, are two different defects with opposite fixes and identical symptoms from outside.
81 lg_pnum("LIPPROF z_at_440=" as *u8, fa_midline_z(base, 0 - 440))
82 lg_pnum("LIPPROF z_at_480=" as *u8, fa_midline_z(base, 0 - 480))
83 lg_pnum("LIPPROF z_at_520=" as *u8, fa_midline_z(base, 0 - 520))
84 lg_pnum("LIPPROF z_at_560=" as *u8, fa_midline_z(base, 0 - 560))
85 lg_pnum("LIPPROF z_at_600=" as *u8, fa_midline_z(base, 0 - 600))
86 lg_pnum("LIPPROF z_at_660=" as *u8, fa_midline_z(base, 0 - 660))
87 lg_pnum("LIPPROF z_at_692=" as *u8, fa_midline_z(base, 0 - 692))
88 let o: *i64 = sys_mmap(FA_LIP_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
89 let r: i64 = fa_lip_ratio(base, o)
90 lg_pnum("LIPGATE ratio_permil=" as *u8, r)
91 lg_pnum("LIPGATE upper_vermilion_h=" as *u8, o[FA_LIP_O_UPPER_H])
92 lg_pnum("LIPGATE lower_vermilion_h=" as *u8, o[FA_LIP_O_LOWER_H])
93 lg_pnum("LIPGATE upper_border_y=" as *u8, o[FA_LIP_O_UPBORDER])
94 lg_pnum("LIPGATE upper_peak_y=" as *u8, o[FA_LIP_O_UPPEAK])
95 lg_pnum("LIPGATE stomion_y=" as *u8, o[FA_LIP_O_STOMION])
96 lg_pnum("LIPGATE lower_peak_y=" as *u8, o[FA_LIP_O_LOPEAK])
97 lg_pnum("LIPGATE lower_border_y=" as *u8, o[FA_LIP_O_LOBORDER])
98
99 lg_pnum("LIPGATE reason_code=" as *u8, o[FA_LIP_O_REASON])
100 lg_pnum("LIPGATE upper_sulcus_y=" as *u8, o[FA_LIP_O_UPSULCUS])
101 lg_pnum("LIPGATE lower_sulcus_y=" as *u8, o[FA_LIP_O_LOSULCUS])
102 // THE CONSTRUCTION TRUTH (AT43): what the lip unit STATES, through the renderer's own outline function
103 let st: *i64 = sys_mmap(FA_LS_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
104 fa_lip_stated(base, st)
105 lg_pnum("LIPSTATED stomion_y=" as *u8, st[FA_LS_O_STOMION])
106 lg_pnum("LIPSTATED labrale_superius_y=" as *u8, st[FA_LS_O_LS])
107 lg_pnum("LIPSTATED labrale_inferius_y=" as *u8, st[FA_LS_O_LI])
108 lg_pnum("LIPSTATED upper_h=" as *u8, st[FA_LS_O_UPPER_H])
109 lg_pnum("LIPSTATED lower_h=" as *u8, st[FA_LS_O_LOWER_H])
110 lg_pnum("LIPSTATED ratio_permil=" as *u8, st[FA_LS_O_RATIO])
111 lg_pnum("LIPSTATED cheilion_halfw=" as *u8, st[FA_LS_O_CHEILION_X])
112 // T1 asserts the UPPER vermilion is measured at all -- the fixture reached the lips. The RATIO is T9's: until the lip unit
113 // (AT43) the canon face had no vermilion line the surface could show, and the ratio was refused on every build.
114 var t1: i64 = 0
115 if o[FA_LIP_O_UPPER_H] != FA_LIP_UNMEASURED { if o[FA_LIP_O_UPPER_H] > 0 { t1 = 1 } }
116 gv_check("fixture-reached-the-condition-the-upper-vermilion-height-is-measured" as *u8, t1, ctr)
117
118 // T2 -- the landmarks that WERE found must come out in anatomical order down the face. This is what
119 // separates a real lip profile from extrema of noise: noise does not arrive pre-sorted. The lower
120 // border is excluded on purpose -- it is the one this face does not have, and including it would
121 // make this tooth assert the very thing the organ correctly refuses.
122 var t2: i64 = 0
123 if o[FA_LIP_O_UPBORDER] > o[FA_LIP_O_UPPEAK] {
124 if o[FA_LIP_O_UPPEAK] > o[FA_LIP_O_STOMION] {
125 if o[FA_LIP_O_STOMION] > o[FA_LIP_O_LOPEAK] { t2 = 1 }
126 }
127 }
128 gv_check("landmarks-descend-in-anatomical-order-crease-peak-stomion-peak" as *u8, t2, ctr)
129
130 // T2b -- THE ABSTENTION IS SPECIFIC. A bare -1 would collapse "no lips", "face not in the band" and
131 // "the bounding crease is outside the window" into one word; this requires the organ to say WHICH.
132 var t2b: i64 = 0
133 if o[FA_LIP_O_REASON] == FA_LIP_R_NO_SULCUS_IN_BAND { t2b = 1 }
134 if o[FA_LIP_O_REASON] == FA_LIP_R_OK { t2b = 1 }
135 gv_check("refusal-names-its-reason-rather-than-returning-a-bare-unmeasured" as *u8, t2b, ctr)
136
137 // T3 -- the EXTRACTED stomion must agree with the PARAMETER that carved the oral fissure. The
138 // tolerance is derived from that carve's own half-height plus the blend radius that smooths it,
139 // never typed: widen the carve or the blend and the tolerance widens with it.
140 let p: *i64 = (base + O_PARTS) as *i64
141 let kb: *i64 = (base + O_KBLEND) as *i64
142 let carve_y: i64 = p[LG_MOUTH_CARVE * LG_FIELDS + LG_PART_CY]
143 let carve_ry: i64 = p[LG_MOUTH_CARVE * LG_FIELDS + LG_PART_RY]
144 let tol: i64 = carve_ry + kb[0]
145 let dev: i64 = lg_abs(o[FA_LIP_O_STOMION] - carve_y)
146 lg_pnum("LIPGATE carve_cy=" as *u8, carve_y)
147 lg_pnum("LIPGATE derived_tolerance=" as *u8, tol)
148 lg_pnum("LIPGATE stomion_deviation=" as *u8, dev)
149 var t3: i64 = 0
150 if dev <= tol { if tol > 0 { t3 = 1 } }
151 gv_check("extracted-stomion-agrees-with-the-carve-parameter-within-a-derived-tolerance" as *u8, t3, ctr)
152
153 // T4 -- THE RUNG. Halve the lip parts' vertical radius and the measured ratio must MOVE. A part-table
154 // read of lip depth is untouched by a change to ry, so this is the tooth a slider read-back fails.
155 let base2: i64 = sys_mmap(sdf_bytes()) as i64
156 faceanat_build(base2)
157 faceanat_morph_lips(base2, LG_HALF)
158 let o2: *i64 = sys_mmap(FA_LIP_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
159 let r2: i64 = fa_lip_ratio(base2, o2)
160 lg_pnum("LIPGATE halved_lips_ratio_permil=" as *u8, r2)
161 lg_pnum("LIPGATE halved_upper_h=" as *u8, o2[FA_LIP_O_UPPER_H])
162 lg_pnum("LIPGATE halved_lower_h=" as *u8, o2[FA_LIP_O_LOWER_H])
163 var t4: i64 = 0
164 if o2[FA_LIP_O_UPPER_H] != FA_LIP_UNMEASURED {
165 if o2[FA_LIP_O_UPPER_H] != o[FA_LIP_O_UPPER_H] { t4 = 1 }
166 }
167 gv_check("surface-not-slider-halving-the-lip-radius-moves-the-measured-vermilion" as *u8, t4, ctr)
168
169 // T5 -- NEGATIVE CONTROL, and reachable by construction: at a tenth scale the face no longer reaches
170 // the midline sampling band, every probe returns no-surface, and the answer must be UNMEASURED.
171 let base3: i64 = sys_mmap(sdf_bytes()) as i64
172 faceanat_build(base3)
173 faceanat_scale(base3, LG_TENTH)
174 let o3: *i64 = sys_mmap(FA_LIP_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
175 let r3: i64 = fa_lip_ratio(base3, o3)
176 lg_pnum("LIPGATE shrunk_face_return=" as *u8, r3)
177 lg_pnum("LIPGATE shrunk_face_reason=" as *u8, o3[FA_LIP_O_REASON])
178 // and it must say WHICH rule refused it: a refusal test that only asks "was it refused?" passes for a ruler that refuses
179 // everything
180 var t5: i64 = 0
181 if r3 == FA_LIP_UNMEASURED { if o3[FA_LIP_O_RATIO] == FA_LIP_UNMEASURED { if o3[FA_LIP_O_REASON] == FA_LIP_R_NOSURF { t5 = 1 } } }
182 gv_check("neg-control-a-face-absent-from-the-band-reports-unmeasured-not-a-number" as *u8, t5, ctr)
183
184 // T6 -- the mouth sits on the midline, so mirroring the face in x must not move any of these
185 // landmarks. An extractor that had drifted off the midline would fail this and nothing else would.
186 let base4: i64 = sys_mmap(sdf_bytes()) as i64
187 faceanat_build(base4)
188 let p4: *i64 = (base4 + O_PARTS) as *i64
189 let nb4: *i64 = (base4 + O_NPART) as *i64
190 var mi: i64 = 0
191 while mi < nb4[0] { p4[mi * LG_FIELDS] = 0 - p4[mi * LG_FIELDS]; mi = mi + 1 }
192 let o4: *i64 = sys_mmap(FA_LIP_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
193 let r4: i64 = fa_lip_ratio(base4, o4)
194 lg_pnum("LIPGATE mirrored_ratio_permil=" as *u8, r4)
195 // Compared on the MEASURED height, never on the return value: with the ratio refused both sides
196 // return the same UNMEASURED, so a tooth asserting r4 == r would pass on two absences and prove
197 // nothing at all. It must compare a number that exists.
198 lg_pnum("LIPGATE mirrored_upper_h=" as *u8, o4[FA_LIP_O_UPPER_H])
199 var t6: i64 = 0
200 if o4[FA_LIP_O_UPPER_H] == o[FA_LIP_O_UPPER_H] {
201 if o4[FA_LIP_O_STOMION] == o[FA_LIP_O_STOMION] {
202 if o[FA_LIP_O_UPPER_H] != FA_LIP_UNMEASURED { t6 = 1 }
203 }
204 }
205 gv_check("mirror-invariant-a-midline-landmark-does-not-move-when-x-is-negated" as *u8, t6, ctr)
206
207 // T7/T8 -- THE DISCRIMINATION PAIR FOR THE 2026-08-29 DIFFERENTIAL MORPH, added because the
208 // measured defect was an INVARIANCE: faceanat_morph_lips scales both vermilions by one pct, so the
209 // canon's lip_upper_over_lower steering row was unexpressible by the only lips morph that existed.
210 // Two teeth, opposite directions, and only both together prove the new knob is the RATIO knob:
211 // the ratio must MOVE under faceanat_morph_lipratio and must NOT move under faceanat_morph_lips --
212 // a single moves-tooth would also pass a morph that merely resized everything.
213 let b7: i64 = sys_mmap(sdf_bytes()) as i64
214 faceanat_build(b7)
215 faceanat_morph_lipratio(b7, 130)
216 let o7: *i64 = sys_mmap(FA_LIP_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
217 let r7: i64 = fa_lip_ratio(b7, o7)
218 lg_pnum("LIPGATE lipratio_morph_130_ratio_permil=" as *u8, r7)
219 var t7: i64 = 0
220 if o7[FA_LIP_O_UPPER_H] != FA_LIP_UNMEASURED {
221 if o7[FA_LIP_O_UPPER_H] != o[FA_LIP_O_UPPER_H] { t7 = 1 }
222 }
223 gv_check("differential-morph-moves-the-measured-vermilion-the-ratio-knob-is-real" as *u8, t7, ctr)
224
225 let b8: i64 = sys_mmap(sdf_bytes()) as i64
226 faceanat_build(b8)
227 faceanat_morph_lips(b8, 130)
228 let o8: *i64 = sys_mmap(FA_LIP_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
229 let r8: i64 = fa_lip_ratio(b8, o8)
230 lg_pnum("LIPGATE fullness_morph_130_upper_h=" as *u8, o8[FA_LIP_O_UPPER_H])
231 lg_pnum("LIPGATE fullness_morph_130_lower_h=" as *u8, o8[FA_LIP_O_LOWER_H])
232 lg_pnum("LIPGATE fullness_morph_130_ratio_permil=" as *u8, r8)
233 // THE INVARIANCE LEG IS ASSERTED ON THE STATED RATIO, whose only error is integer rounding. The first draft asserted the SURFACE
234 // ratios within "one part in twenty, derived from the 4-unit step against the ~150-unit vermilion" -- but the vermilions are 49
235 // and 78 units, where the step alone moves a surface ratio by up to an eighth, so that bound was neither derived nor passable
236 // (and the ratio was never measured, so the tooth never once ran). Each stated ratio carries at most one unit of upper height
237 // in rounding, i.e. PERMIL / lower_h; the two runs' bounds add. The surface's own agreement with the statement is T11's job.
238 let st8: *i64 = sys_mmap(FA_LS_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
239 fa_lip_stated(b8, st8)
240 lg_pnum("LIPSTATED fullness_morph_130_ratio_permil=" as *u8, st8[FA_LS_O_RATIO])
241 let tol8: i64 = FA_LIP_PERMIL / st[FA_LS_O_LOWER_H] + FA_LIP_PERMIL / st8[FA_LS_O_LOWER_H]
242 lg_pnum("LIPGATE fullness_morph_derived_tolerance_permil=" as *u8, tol8)
243 var t8: i64 = 0
244 if r8 != FA_LIP_UNMEASURED {
245 if r != FA_LIP_UNMEASURED {
246 if lg_abs(st8[FA_LS_O_RATIO] - st[FA_LS_O_RATIO]) <= tol8 { t8 = 1 }
247 }
248 }
249 gv_check("fullness-morph-holds-the-ratio-the-two-knobs-are-orthogonal" as *u8, t8, ctr)
250
251 // T9 -- THE AT43 DONE-RULE: on the canon face the ratio is MEASURED from the surface, with nothing refused.
252 var t9: i64 = 0
253 if r != FA_LIP_UNMEASURED { if o[FA_LIP_O_REASON] == FA_LIP_R_OK { if o[FA_LIP_O_LOWER_H] > 0 { t9 = 1 } } }
254 gv_check("the-canon-face-ratio-is-measured-from-the-surface-nothing-refused" as *u8, t9, ctr)
255
256 // T10 -- the STATEMENT is the canon row. Its only error is rounding one unit of upper height, PERMIL / lower_h.
257 let tol10: i64 = FA_LIP_PERMIL / st[FA_LS_O_LOWER_H]
258 gv_check_near("stated-ratio-is-the-canon-row-within-one-unit-of-rounding" as *u8, st[FA_LS_O_RATIO], FA_LIP_UL_CANON_PERMIL, tol10, ctr)
259
260 // T11 -- TWO ROUTES TO ONE LANDMARK: the surface's vermilion heights agree with the stated ones at the refinement resolution.
261 // A height has two ends. The BORDER lands on the stated outline EXACTLY: the outline is an integer y (seam plus an integer
262 // height) and the refine visits every integer y. Only the STOMION carries error, the centre of its deepest run truncated to the
263 // grid, i.e. under one refine step. So a height is within ONE step of its statement. The first cut allowed two -- and the bite
264 // that planted the fade's half level (a 2-unit inward bias on every border) survived it: a tolerance derived as "one per end"
265 // for an end that carries none is a loose derivation, and the surviving mutant was the measurement that said so.
266 let tol11: i64 = FA_LIP_REFINE_STEP
267 gv_check_near("surface-upper-vermilion-agrees-with-the-stated-line-at-the-refine-step" as *u8, o[FA_LIP_O_UPPER_H], st[FA_LS_O_UPPER_H], tol11, ctr)
268 gv_check_near("surface-lower-vermilion-agrees-with-the-stated-line-at-the-refine-step" as *u8, o[FA_LIP_O_LOWER_H], st[FA_LS_O_LOWER_H], tol11, ctr)
269
270 // T12 -- NEGATIVE CONTROL, REACHABLE: lips tall enough to put the upper vermilion line above the band, so the upward walk runs
271 // off the window while still inside the vermilion. The ruler must name that and never report the window as a height. The
272 // percent is DERIVED from the band and the canon face's own statement -- twice the percent at which the stated line would just
273 // reach the band top -- because a typed 500 cleared the band by 31 units and the bite that retyped the upper height to 49 left
274 // it short of the band entirely (the fixture tooth below caught it; the control would otherwise have "passed" unreached).
275 let pct12: i64 = 2 * LG_PCT * (FA_LIP_Y_TOP - st[FA_LS_O_STOMION]) / st[FA_LS_O_UPPER_H]
276 lg_pnum("LIPGATE tall_lips_pct=" as *u8, pct12)
277 let b12: i64 = sys_mmap(sdf_bytes()) as i64
278 faceanat_build(b12)
279 faceanat_morph_lips(b12, pct12)
280 let st12: *i64 = sys_mmap(FA_LS_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
281 fa_lip_stated(b12, st12)
282 let o12: *i64 = sys_mmap(FA_LIP_O_FIELDS * 8 + FA_LIP_SLACK) as *i64
283 let r12: i64 = fa_lip_ratio(b12, o12)
284 lg_pnum("LIPSTATED tall_lips_labrale_superius_y=" as *u8, st12[FA_LS_O_LS])
285 lg_pnum("LIPGATE tall_lips_return=" as *u8, r12)
286 lg_pnum("LIPGATE tall_lips_reason=" as *u8, o12[FA_LIP_O_REASON])
287 var t12a: i64 = 0
288 if st12[FA_LS_O_LS] > FA_LIP_Y_TOP { t12a = 1 }
289 gv_check("fixture-reached-the-condition-the-stated-upper-line-is-above-the-band" as *u8, t12a, ctr)
290 var t12: i64 = 0
291 if r12 == FA_LIP_UNMEASURED { if o12[FA_LIP_O_REASON] == FA_LIP_R_VERMILION_PAST_BAND { if o12[FA_LIP_O_UPPER_H] == FA_LIP_UNMEASURED { t12 = 1 } } }
292 gv_check("neg-control-a-vermilion-past-the-band-names-the-window-and-reports-no-height" as *u8, t12, ctr)
293
294 gv_values_head()
295 gv_kv("ratio_permil" as *u8, r)
296 gv_kv("stated_ratio_permil" as *u8, st[FA_LS_O_RATIO])
297 gv_kv("upper_h" as *u8, o[FA_LIP_O_UPPER_H])
298 gv_kv("lower_h" as *u8, o[FA_LIP_O_LOWER_H])
299 gv_kv("lower_sulcus_y" as *u8, o[FA_LIP_O_LOSULCUS])
300 return gv_verdict("NX-LIPRATIO-GATE" as *u8, ctr, "AT4/AT43 lip ratio read from the rendered surface and judged against the lip unit's stated vermilion lines" as *u8)
301}