nx_sim_coverage.nx source
↩ module page · 92 lines · 4164 B
1// nx_sim_coverage.nx -- GENERIC tool-vs-target coverage / efficiency simulation (sovereign, pure
2// integer). Answers "does the tool actually reach + conform to the surface where it matters, and
3// how much of what matters does it service?" Tool/target-agnostic by construction:
4// * toilet cleaner vs under-rim black-mold (clean the deep, near-vertical rim underside)
5// * massager vs a human body (knead the high-tension, contoured regions)
6// ... are the SAME engine with different site lists + tool params.
7//
8// TARGET = parallel arrays over n sites:
9// depth[i] -- how far into the recess the site sits (mm); a tool must REACH this depth.
10// slope[i] -- local surface angle in degrees (0 = flat/horizontal .. 90 = vertical); a tool's
11// working face must CONFORM to this angle to actually scrub/press there.
12// value[i] -- how much it matters to service this site (mold concentration / muscle tension).
13// TOOL = a working face that can present any tilt in [tilt_lo, tilt_hi], reaches depth <= reach_max,
14// and conforms to a surface within +/- conform_tol degrees.
15//
16// serviced(site) = (depth <= reach_max) AND ([tilt_lo,tilt_hi] intersects [slope-tol, slope+tol]).
17// EFFICIENCY (permil 0..1000) = 1000 * sum(value | serviced) / sum(value).
18//
19// This is a first-order GEOMETRIC reachability+conformance model, not full contact physics -- the
20// honest scope. license_tier: ORIGINAL
21import "nx_syscalls.nx"
22
23// is a single site serviced by the tool?
24func sim_serviced(depth: i64, slope: i64, tilt_lo: i64, tilt_hi: i64, reach_max: i64, tol: i64) -> i64 {
25 if depth > reach_max { return 0 }
26 let slo: i64 = slope - tol
27 let shi: i64 = slope + tol
28 if tilt_hi < slo { return 0 }
29 if tilt_lo > shi { return 0 }
30 return 1
31}
32
33// efficiency (permil) of a tool over a target site list.
34func sim_efficiency(n: i64, dep: *i64, slp: *i64, val: *i64,
35 tilt_lo: i64, tilt_hi: i64, reach_max: i64, tol: i64) -> i64 {
36 var tot: i64 = 0
37 var srv: i64 = 0
38 var i: i64 = 0
39 while i < n {
40 tot = tot + val[i]
41 if sim_serviced(dep[i], slp[i], tilt_lo, tilt_hi, reach_max, tol) == 1 { srv = srv + val[i] }
42 i = i + 1
43 }
44 if tot <= 0 { return 0 }
45 return srv * 1000 / tot
46}
47
48// generate a toilet UNDER-RIM target: K depth steps across `overhang` mm. The rim underside curls
49// up (slope 0 at the inner edge -> 90 deg vertical at the back) and black mold concentrates deep
50// (value rises with depth = the hard-to-reach zone where mold thrives).
51func sim_toilet_underrim(K: i64, overhang: i64, dep: *i64, slp: *i64, val: *i64) -> i64 {
52 if K < 2 { return 0 }
53 var i: i64 = 0
54 while i < K {
55 dep[i] = overhang * i / (K - 1)
56 slp[i] = 90 * i / (K - 1)
57 val[i] = 1 + 9 * i / (K - 1)
58 i = i + 1
59 }
60 return 0
61}
62
63// generate a BODY-region target (shoulder / upper back): K samples across `span` mm. Surface
64// curvature rises toward the shoulder (slope 0 = flat mid-back .. ~60 deg at the shoulder), and
65// muscle TENSION concentrates in that curved upper region (value rises) -- the spots a flat
66// massager head misses but a contoured/articulated one reaches. SAME problem shape as the toilet
67// under-rim => the engine is tool/target-agnostic by construction.
68func sim_body_surface(K: i64, span: i64, dep: *i64, slp: *i64, val: *i64) -> i64 {
69 if K < 2 { return 0 }
70 var i: i64 = 0
71 while i < K {
72 dep[i] = span * i / (K - 1)
73 slp[i] = 60 * i / (K - 1)
74 val[i] = 1 + 9 * i / (K - 1)
75 i = i + 1
76 }
77 return 0
78}
79
80// find the fixed face-tilt (0..90, step 5) that services the MOST value -- design guidance for the
81// best scrub-face angle, given the tool's reach + conform tolerance.
82func sim_best_tilt(n: i64, dep: *i64, slp: *i64, val: *i64, reach_max: i64, tol: i64) -> i64 {
83 var best_tilt: i64 = 0
84 var best_eff: i64 = 0 - 1
85 var t: i64 = 0
86 while t <= 90 {
87 let e: i64 = sim_efficiency(n, dep, slp, val, t, t, reach_max, tol)
88 if e > best_eff { best_eff = e; best_tilt = t }
89 t = t + 5
90 }
91 return best_tilt
92}