nx_anatomy_measure_test.nx source
↩ module page · 70 lines · 2273 B
1// Minimal smoke for nx_anatomy_measure primitives.
2// Tests the cross-section math leaf-primitive only; full pipeline
3// requires inline-in-main due to nxc2 codegen bug with multi-call
4// composition.
5
6import "nx_syscalls.nx"
7import "nx_image.nx"
8import "nx_canon_proportions.nx"
9import "nx_anatomy_measure.nx"
10
11func paint_row(mask: *Image, y: i64, x_center: i64, half_w: i64) -> i64 {
12 var x: i64 = x_center - half_w
13 let x1: i64 = x_center + half_w
14 while x < x1 {
15 if x >= 0 { if x < mask.width {
16 nx_image_set(mask, x, y, 0, 255)
17 } }
18 x = x + 1
19 }
20 return 0
21}
22
23func main() -> i64 {
24 let w: i64 = 200
25 let h: i64 = 300
26 let mask: *Image = nx_image_alloc(w, h, 1)
27 var y: i64 = 0
28 while y < h {
29 var x: i64 = 0
30 while x < w { nx_image_set(mask, x, y, 0, 0); x = x + 1 }
31 y = y + 1
32 }
33 // Hourglass torso: bust band 70..90 (90px wide), waist 120..140 (56px),
34 // hip 170..190 (90px).
35 var ty: i64 = 70
36 while ty < 90 { paint_row(mask, ty, 100, 45); ty = ty + 1 }
37 var wy: i64 = 120
38 while wy < 140 { paint_row(mask, wy, 100, 28); wy = wy + 1 }
39 var hy: i64 = 170
40 while hy < 190 { paint_row(mask, hy, 100, 45); hy = hy + 1 }
41
42 // T1: bust row at y=80 should measure ~90 px wide
43 let bust_w: i64 = nx_mask_longest_run_at_y(mask, 80, 0, w)
44 if bust_w < 80 { return 1 }
45 if bust_w > 100 { return 2 }
46
47 // T2: waist row at y=130 should measure ~56 px wide
48 let waist_w: i64 = nx_mask_longest_run_at_y(mask, 130, 0, w)
49 if waist_w < 48 { return 10 }
50 if waist_w > 64 { return 11 }
51
52 // T3: hip row at y=180 should match bust ~90 px
53 let hip_w: i64 = nx_mask_longest_run_at_y(mask, 180, 0, w)
54 if hip_w < 80 { return 20 }
55 if hip_w > 100 { return 21 }
56
57 // T4: phi-distance bust:waist = 90/56 = 1.607, close to phi=1.618.
58 // Q10 ratio of bust to waist:
59 let ratio_q10: i64 = (bust_w * 1024) / waist_w
60 // |ratio - 1657| should be < 100 (within ~10% phi-band)
61 var dist: i64 = ratio_q10 - 1657
62 if dist < 0 { dist = -dist }
63 if dist > 100 { return 30 }
64
65 // T5: empty row outside body returns 0
66 let empty: i64 = nx_mask_longest_run_at_y(mask, 250, 0, w)
67 if empty != 0 { return 40 }
68
69 return 0
70}