nx_sdfprim_gate.nx source
↩ module page · 74 lines · 7079 B
1// nx_sdfprim_gate.nx -- KNOWN-ANSWER TEETH FOR THE IMPLICIT PRIMITIVE FAMILY nx_sdfprim_lib (anatomy AN17, 2026-09-19).
2// Every tooth is a distance a hand can check: a sphere is where the first-order ellipsoid estimator is EXACT, so its
3// values are asserted to the unit; the walled cylinder and the swept arch are asserted at points that lie on a
4// primitive's own construction (a polyline vertex, an axis crossing) where the answer is closed-form. The pitched
5// ellipsoid is held to the plain one at zero tilt (an identity) and to the axis swap at a quarter turn.
6// NEG-CONTROL: the detector "a point off the surface reads non-zero" must fire on a planted 5 mm shift and stay silent
7// on the surface point (gv_bite): a primitive that read zero everywhere would pass every equality tooth by accident.
8// license_tier: ORIGINAL. No hw writes (Rule 26).
9import "nx_syscalls.nx"
10import "nx_gate_verdict.nx"
11import "nx_sdfprim_lib.nx"
12
13const SG_R: i64 = 40 // the sphere every exact tooth uses, mm
14const SG_IN: i64 = 20 // a point this far inside the sphere (from the centre)
15const SG_OUT: i64 = 50 // a point this far from the centre, outside
16const SG_PLANT: i64 = 45 // the neg-control's planted off-surface radius
17const SG_TOL_Q: i64 = 1 // one output unit: the integer roots' own rounding
18
19func main(argc: i64, argv: *i64) -> i64 {
20 gv_head("nx_sdfprim_gate: the implicit primitive family against closed-form answers" as *u8)
21 let ctr: *i64 = gv_ctr()
22 // ---- the ellipsoid, on a sphere where the estimator is exact ----
23 gv_check_eq("sphere-surface-point-reads-zero" as *u8, sp_ellipsoid_q(SG_R,0,0, 0,0,0, SG_R,SG_R,SG_R), 0, ctr)
24 gv_check_near("sphere-point-20mm-inside-reads-minus-20mm" as *u8, sp_ellipsoid_q(SG_IN,0,0, 0,0,0, SG_R,SG_R,SG_R), (SG_IN-SG_R)*SP_FQ, SG_TOL_Q, ctr)
25 gv_check_near("sphere-point-10mm-outside-reads-plus-10mm" as *u8, sp_ellipsoid_q(0,SG_OUT,0, 0,0,0, SG_R,SG_R,SG_R), (SG_OUT-SG_R)*SP_FQ, SG_TOL_Q, ctr)
26 gv_check_eq("sphere-centre-reads-minus-the-smallest-semi-axis" as *u8, sp_ellipsoid_q(0,0,0, 0,0,0, SG_R,SG_R,SG_R), 0-SG_R*SP_FQ, ctr)
27 gv_check_eq("ellipsoid-centre-reads-minus-the-smallest-semi-axis-of-three" as *u8, sp_ellipsoid_q(3,-2,7, 3,-2,7, 30,12,50), 0-12*SP_FQ, ctr)
28 gv_check_eq("ellipsoid-axis-end-reads-zero-on-each-axis" as *u8, sp_ellipsoid_q(30,0,0, 0,0,0, 30,12,50) + sp_ellipsoid_q(0,12,0, 0,0,0, 30,12,50) + sp_ellipsoid_q(0,0,50, 0,0,0, 30,12,50), 0, ctr)
29 // ---- the capsule ----
30 gv_check_eq("capsule-point-5mm-off-the-axis-reads-plus-5mm" as *u8, sp_capsule_q(50,15,0, 0,0,0, 100,0,0, 10), 5*SP_FQ, ctr)
31 gv_check_eq("capsule-point-20mm-past-an-end-reads-plus-10mm" as *u8, sp_capsule_q(120,0,0, 0,0,0, 100,0,0, 10), 10*SP_FQ, ctr)
32 gv_check_eq("capsule-point-on-the-axis-at-a-grid-exact-parameter-reads-minus-the-radius" as *u8, sp_capsule_q(50,0,0, 0,0,0, 100,0,0, 10), 0-10*SP_FQ, ctr)
33 // THE IMPRECISION THIS FAMILY LIVES WITH, NAMED: the closest-point parameter is Q10 and the closest point is truncated
34 // to whole millimetres, so an axis point at an off-grid parameter can read up to one millimetre off the radius (the
35 // skull's arches and jaw were fitted through this for weeks; a gate that denied it would be lying about the ruler)
36 gv_check_near("capsule-closest-point-is-quantised-to-a-millimetre-at-an-off-grid-parameter" as *u8, sp_capsule_q(30,0,0, 0,0,0, 100,0,0, 10), 0-10*SP_FQ, SP_FQ, ctr)
37 // ---- the combinators ----
38 gv_check_eq("smin-of-equal-inputs-is-min-minus-a-quarter-k" as *u8, sp_smin(1000, 1000, SP_FQ), 1000 - SP_FQ/4, ctr)
39 gv_check_eq("smin-of-inputs-farther-apart-than-k-is-the-plain-min" as *u8, sp_smin(1000, 2000, SP_FQ), 1000, ctr)
40 gv_check_eq("sub-inside-both-reads-outside-the-carved-solid" as *u8, sp_sub(0-100, 0-300), 300, ctr)
41 gv_check_eq("sub-inside-a-outside-b-leaves-a" as *u8, sp_sub(0-100, 500), 0-100, ctr)
42 // ---- the swept arch: a semicircle of radius 50 in the xz plane, capsule radius 10 ----
43 gv_check_eq("arch-polyline-vertex-at-theta-zero-reads-minus-the-radius" as *u8, sp_arch_q(0,0,50, 0,0, 50,50, 90, 0, 10), 0-10*SP_FQ, ctr)
44 gv_check_eq("arch-point-15mm-beyond-that-vertex-reads-plus-5mm" as *u8, sp_arch_q(0,0,65, 0,0, 50,50, 90, 0, 10), 5*SP_FQ, ctr)
45 gv_check("arch-centre-of-the-arc-is-far-outside" as *u8, (sp_arch_q(0,0,0, 0,0, 50,50, 90, 0, 10) > 35*SP_FQ) as i64, ctr)
46 gv_check_eq("arch-ylift-raises-the-end-vertex-by-ylift" as *u8, sp_arch_q(50,20,0, 0,0, 50,50, 90, 20, 10), 0-10*SP_FQ, ctr)
47 // ---- the element ring: an element centre reads minus its smallest semi-axis ----
48 let ex: i64 = 30*sp_isin(0-60)/SP_PERMILLE
49 let ez: i64 = 30*sp_icos(0-60)/SP_PERMILLE
50 gv_check_eq("ring-first-element-centre-reads-minus-its-smallest-semi-axis" as *u8, sp_ring_q(ex,0,ez, 0,0, 30,30, 60, 4, 6, 8, 0), 0-4*SP_FQ, ctr)
51 // ---- the pitched ellipsoid ----
52 gv_check_eq("tiltx-zero-equals-the-plain-ellipsoid" as *u8, sp_ellipsoid_tiltx_q(7,-9,21, 1,2,3, 10,30,12, 0) - sp_ellipsoid_q(7,-9,21, 1,2,3, 10,30,12), 0, ctr)
53 gv_check_eq("tiltx-quarter-turn-maps-the-long-axis-onto-z" as *u8, sp_ellipsoid_tiltx_q(0,0,-30, 0,0,0, 10,30,10, 90), 0, ctr)
54 gv_check_eq("tiltx-quarter-turn-leaves-the-x-axis-end-on-the-surface" as *u8, sp_ellipsoid_tiltx_q(10,0,0, 0,0,0, 10,30,10, 90), 0, ctr)
55 // ---- the walled cylinder: ellipse 10 x 20 in xy, wall at z = 50, open toward +z ----
56 gv_check_eq("cylz-inside-the-ellipse-in-front-of-the-wall-is-inside" as *u8, sp_cylz_q(0,0,60, 0,0, 10,20, 50), 0-10*SP_FQ, ctr)
57 gv_check_eq("cylz-inside-the-ellipse-behind-the-wall-is-outside-by-the-wall-gap" as *u8, sp_cylz_q(0,0,40, 0,0, 10,20, 50), 10*SP_FQ, ctr)
58 gv_check_eq("cylz-outside-the-ellipse-on-its-axis-reads-the-axis-gap" as *u8, sp_cylz_q(15,0,60, 0,0, 10,20, 50), 5*SP_FQ, ctr)
59 gv_check_eq("cylz-has-no-front-wall" as *u8, sp_cylz_q(0,0,500, 0,0, 10,20, 50), 0-10*SP_FQ, ctr)
60 // ---- the sine ----
61 gv_check_eq("isin-exact-at-90" as *u8, sp_isin(90), SP_PERMILLE, ctr)
62 gv_check_eq("isin-odd" as *u8, sp_isin(0-30) + sp_isin(30), 0, ctr)
63 gv_check_eq("icos-zero-is-one" as *u8, sp_icos(0), SP_PERMILLE, ctr)
64 // ---- neg-control: the detector "off the surface reads non-zero" must fire on a planted shift ----
65 let planted: i64 = sp_ellipsoid_q(SG_PLANT,0,0, 0,0,0, SG_R,SG_R,SG_R)
66 let onsurf: i64 = sp_ellipsoid_q(SG_R,0,0, 0,0,0, SG_R,SG_R,SG_R)
67 gv_bite("neg-control-a-planted-5mm-shift-reads-nonzero-and-the-surface-reads-zero" as *u8, (planted != 0) as i64, (onsurf != 0) as i64, ctr)
68 gv_values_head()
69 gv_kv("planted_shift_q" as *u8, planted)
70 gv_kv("sphere_inside_q" as *u8, sp_ellipsoid_q(SG_IN,0,0, 0,0,0, SG_R,SG_R,SG_R))
71 gv_kv("arch_centre_q" as *u8, sp_arch_q(0,0,0, 0,0, 50,50, 90, 0, 10))
72 gv_kv("fq" as *u8, SP_FQ)
73 return gv_verdict("nx_sdfprim_gate" as *u8, ctr, "the implicit primitive family every anatomy field composes, held to closed-form distances" as *u8)
74}