nx_clipcap_lib.nx source
↩ module page · 58 lines · 2334 B
1// nx_clipcap_lib.nx -- THE TORSO-CAPSULE DEFINITION (shared ruler geometry).
2//
3// Extracted 2026-08-13 when the SECOND consumer appeared: nx_dance_emit's capsule-clearance
4// pass must avoid EXACTLY the capsule nx_clipcheck measures. Two derivations would be the
5// twin-ruler defect -- a corrector and a judge that disagree manufacture unfixable REDs.
6// ONE definition: a vertical capsule at the spine-band centroid (joints within CC_MAGIC_3000
7// of the bind midline laterally), z-span 40..80 permil of bind stature, radius CC_TORSO_R;
8// limb points carry CC_LIMB_R; eligibility margin CC_GRACE.
9// license_tier: ORIGINAL No hw writes (Rule 26).
10import "nx_syscalls.nx"
11import "nx_vecmath.nx"
12
13const CC_TORSO_R: i64 = 11000 // 110mm in 0.01mm units
14const CC_LIMB_R: i64 = 3000 // 30mm
15const CC_GRACE: i64 = 2000 // 20mm eligibility margin
16const CC_MAGIC_3000: i64 = 3000 // spine-band lateral half-width (30mm)
17
18func cc_isqrt(v: i64) -> i64 { return vm_isqrt(v) }
19// 3D distance from point p to the VERTICAL segment (ax, ay, z in [z1,z2]), 0.01mm units
20func cc_pseg(px: i64, py: i64, pz: i64, ax: i64, ay: i64, z1: i64, z2: i64) -> i64 {
21 let dx: i64 = px - ax
22 let dy: i64 = py - ay
23 var dz: i64 = 0
24 if pz < z1 { dz = z1 - pz }
25 if pz > z2 { dz = pz - z2 }
26 return cc_isqrt(dx*dx + dy*dy + dz*dz)
27}
28// Derive the capsule from an NXA SKEL's binds (W = file words, sow = SKEL payload offset).
29// AX out: [0]=ax [1]=ay [2]=z1 [3]=z2 [4]=floor_z [5]=stature. Returns 0, or -1 = no spine band.
30func cc_axis_skel(W: *i64, sow: i64, AX: *i64) -> i64 {
31 let nj: i64 = W[sow]
32 var zmn: i64 = W[sow+1+3]
33 var zmx: i64 = zmn
34 var sbx: i64 = 0
35 var sby: i64 = 0
36 var sbn: i64 = 0
37 var j: i64 = 0
38 while j < nj {
39 let bx: i64 = W[sow+1+j*8+1]
40 let by: i64 = W[sow+1+j*8+2]
41 let bz: i64 = W[sow+1+j*8+3]
42 if bz < zmn { zmn = bz }
43 if bz > zmx { zmx = bz }
44 var axb: i64 = bx
45 if axb < 0 { axb = 0 - axb }
46 if axb < CC_MAGIC_3000 { sbx = sbx + bx; sby = sby + by; sbn = sbn + 1 }
47 j = j + 1
48 }
49 if sbn == 0 { return 0 - 1 }
50 let stat: i64 = zmx - zmn
51 AX[0] = sbx / sbn
52 AX[1] = sby / sbn
53 AX[2] = zmn + stat*40/100
54 AX[3] = zmn + stat*80/100
55 AX[4] = zmn
56 AX[5] = stat
57 return 0
58}