code wiki / (root) / nx_sdf.nx

nx_sdf.nx

buildroot/runtime/nx_sdf.nx

5661 B120 linesdepth 3pulls 3 transitivereach 27 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_sdf.nx -- signed distance fields for solid primitives + boolean combinators, the algebra under CSG (Constructive Solid Geometry). A primitive returns a Q14-mm signed distance (negative = inside). Booleans are min/max combinators -- which is why SDF CSG is UNCONDITIONALLY robust: union/difference/intersection can never fail or self-intersect the way B-rep mesh booleans do on degenerate geometry. Sign- correct fields (the zero-isosurface is the exact surface) are all marching needs. Reuses nx_isqrt. No dup: grepped, no nx_sdf/csg existed. license_tier: ORIGINAL

dependencies 2 imports · 23 importers

nx_syscalls.nx nx_isqrt.nx nx_sdf.nx nx_cad_exceed.nx nx_cad_page.nx nx_cad_prims2_test.nx nx_csg.nx nx_csg_fillet_test.nx nx_csg_rot_gate.nx nx_csg_rotxz_gate.nx nx_csg_scene.nx nx_csg_scene_gate.nx nx_csg_test.nx

diagram shows first 10 each side; +0 more imports, +13 more importers in the complete lists below.

imports: nx_syscalls.nxnx_isqrt.nx

imported by: nx_cad_exceed.nxnx_cad_page.nxnx_cad_prims2_test.nxnx_csg.nxnx_csg_fillet_test.nxnx_csg_rot_gate.nxnx_csg_rotxz_gate.nxnx_csg_scene.nxnx_csg_scene_gate.nxnx_csg_test.nxnx_csg_torus_test.nxnx_mesh_decimate_gate.nxnx_underridge_cleaner.nxnx_underridge_cleaner_gate.nxnx_underridge_gel_gate.nxnx_underridge_hook_gate.nxnx_underridge_hook_gcode_gate.nxnx_underridge_hook_petg_gate.nxnx_underridge_master_gate.nxnx_vessel_csg.nxnx_vessel_csg_test.nxnx_vessel_emit.nxnx_vessel_gcode.nx

structs

22struct NxSdfPrim { kind: i64, cx: i64, cy: i64, cz: i64, a: i64, b: i64, c: i64, d: i64 }

consts

12const NX_SDF_SPHERE: i64 = 0
13const NX_SDF_BOX: i64 = 1
14const NX_SDF_CYL: i64 = 2 // axis = Z
15const NX_SDF_TORUS: i64 = 3 // hole along Z; a = major R, b = minor r
16const NX_SDF_ROUNDBOX: i64 = 4 // a,b,c = half extents; d = corner round radius
77const NX_CSG_UNION: i64 = 0
78const NX_CSG_INTERSECT: i64 = 1
79const NX_CSG_DIFF: i64 = 2 // A minus B

functions

24func sdf_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
called by 1: nx_sdf_eval
25func sdf_max(a: i64, b: i64) -> i64 { if a > b { return a } return b }
26func sdf_min(a: i64, b: i64) -> i64 { if a < b { return a } return b }
28func nx_sdf_make(kind: i64, cx: i64, cy: i64, cz: i64, a: i64, b: i64, c: i64) -> *NxSdfPrim
36func nx_sdf_make4(kind: i64, cx: i64, cy: i64, cz: i64, a: i64, b: i64, c: i64, d: i64) -> *NxSdfPrim
43func nx_sdf_eval(p: *NxSdfPrim, x: i64, y: i64, z: i64) -> i64
82func nx_csg_combine(op: i64, da: i64, db: i64) -> i64
89func nx_csg_field(a: *NxSdfPrim, b: *NxSdfPrim, op: i64, x: i64, y: i64, z: i64) -> i64
called by 1: main calls 2: nx_csg_combinenx_sdf_eval
99func nx_csg_smin(a: i64, b: i64, k: i64) -> i64
called by 1: nx_csg_combine_k
111func nx_csg_combine_k(op: i64, da: i64, db: i64, k: i64) -> i64
118func nx_csg_field_k(a: *NxSdfPrim, b: *NxSdfPrim, op: i64, k: i64, x: i64, y: i64, z: i64) -> i64