code wiki / _hdl_build / nx_contour_print_gate.nx
nx_contour_print_gate.nx source
↩ module page · 100 lines · 5895 B
1// nx_contour_print_gate.nx -- GATE: 3D-printing R1b. ARBITRARY GEOMETRY x ANY MATERIAL through one unified
2// contour emitter. T1 arbitrary geometry (a 12-gon ROUND cistern has off-axis vertices, not a rectangle), T2
3// material-appropriate (round concrete = cold; box filament = hot; round metal = arc), T3 never-brick all, T4
4// unification (one cp_emit_prism -> every geometry/material combo), T5 decimal Z works across materials.
5// license_tier: ORIGINAL
6import "nx_contour_print.nx"
7import "nx_print_material.nx"
8import "nx_food_science.nx"
9import "nx_seg_store.nx"
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12
13const CP_PRINT: *u8 = "knowledge/store/print-"
14
15func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
16func g_i(v: i64) -> i64 {
17 let bb: *u8 = sys_mmap(28); var m: i64 = v
18 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
19 let t: *u8 = sys_mmap(28); var k: i64 = 0
20 if m == 0 { t[0] = 48 as u8; k = 1 }
21 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
22 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
23}
24func g_nobrick(g: *u8, n: i64) -> i64 {
25 if as_contains(g, n, "M997" as *u8) != 0 { return 0 }
26 if as_contains(g, n, "M500" as *u8) != 0 { return 0 }
27 if as_contains(g, n, "M502" as *u8) != 0 { return 0 }
28 return 1
29}
30
31func main() -> i64 {
32 g_p("=== nx_contour_print_gate (R1b: arbitrary geometry x any material, one emitter) ===\n" as *u8)
33 pm_seed(CP_PRINT)
34
35 let xs: *i64 = sys_mmap(8 * 64) as *i64
36 let ys: *i64 = sys_mmap(8 * 64) as *i64
37
38 // ROUND cistern (12-gon) in concrete
39 let ncirc: i64 = cg_circle(xs, ys, 2000, 2000, 2000)
40 let gcis: *u8 = sys_mmap(524288); let ncis: i64 = cp_emit_prism(CP_PRINT, "concrete" as *u8, xs, ys, ncirc, 2000, gcis)
41 // rectangular box in filament
42 let xs2: *i64 = sys_mmap(8 * 16) as *i64; let ys2: *i64 = sys_mmap(8 * 16) as *i64
43 let nrect: i64 = cg_rect(xs2, ys2, 50, 50)
44 let gbox: *u8 = sys_mmap(131072); let nbox: i64 = cp_emit_prism(CP_PRINT, "pla" as *u8, xs2, ys2, nrect, 20, gbox)
45 // ROUND tube in metal
46 let xs3: *i64 = sys_mmap(8 * 16) as *i64; let ys3: *i64 = sys_mmap(8 * 16) as *i64
47 let ntu: i64 = cg_circle(xs3, ys3, 100, 100, 50)
48 let gtube: *u8 = sys_mmap(131072); let ntube: i64 = cp_emit_prism(CP_PRINT, "steel_waam" as *u8, xs3, ys3, ntu, 20, gtube)
49 g_p("emitted: round-concrete-cistern=" as *u8); g_i(ncis); g_p("B filament-box=" as *u8); g_i(nbox); g_p("B metal-tube=" as *u8); g_i(ntube); g_p("B\n" as *u8)
50
51 var pass: i64 = 0
52 var tot: i64 = 0
53
54 // T1 arbitrary geometry: the round cistern has off-axis (non-rectangular) vertices
55 tot = tot + 1
56 var ok1: i64 = 1
57 if ncis <= 0 { ok1 = 0 }
58 if as_contains(gcis, ncis, "X4000 Y2000" as *u8) != 1 { ok1 = 0 } // 0deg vertex
59 if as_contains(gcis, ncis, "X3732 Y3000" as *u8) != 1 { ok1 = 0 } // 30deg vertex -- OFF-AXIS = round, not a box
60 if as_contains(gcis, ncis, "X2000 Y4000" as *u8) != 1 { ok1 = 0 } // 90deg vertex
61 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 arbitrary geometry: a 12-gon ROUND cistern (off-axis vertices, not a rectangle)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
62
63 // T2 material-appropriate across geometries
64 tot = tot + 1
65 var ok2: i64 = 1
66 if as_contains(gcis, ncis, "M104" as *u8) != 0 { ok2 = 0 } // concrete cistern: cold
67 if as_contains(gbox, nbox, "M104" as *u8) != 1 { ok2 = 0 } // filament box: hot
68 if as_contains(gtube, ntube, "M3 S" as *u8) != 1 { ok2 = 0 } // metal tube: arc
69 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 material-appropriate (round concrete cold / filament box hot / metal tube arc)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) }
70
71 // T3 never-brick all
72 tot = tot + 1
73 if g_nobrick(gcis, ncis) == 1 { if g_nobrick(gbox, nbox) == 1 { if g_nobrick(gtube, ntube) == 1 { pass = pass + 1; g_p("PASS T3 never-brick across all geometry/material combos\n" as *u8) } else { g_p("FAIL T3 tube\n" as *u8) } } else { g_p("FAIL T3 box\n" as *u8) } } else { g_p("FAIL T3 cistern\n" as *u8) }
74
75 // T4 unification: one emitter, every combo
76 tot = tot + 1
77 if ncis > 0 { if nbox > 0 { if ntube > 0 { pass = pass + 1; g_p("PASS T4 unification: ONE cp_emit_prism -> {round,box} x {concrete,filament,metal}\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } } else { g_p("FAIL T4\n" as *u8) } } else { g_p("FAIL T4\n" as *u8) }
78
79 // T5 decimal Z works across materials
80 tot = tot + 1
81 var ok5: i64 = 1
82 if as_contains(gcis, ncis, "Z10.000" as *u8) != 1 { ok5 = 0 } // concrete 10mm -> 10.000
83 if as_contains(gbox, nbox, "Z0.200" as *u8) != 1 { ok5 = 0 } // filament 0.2mm -> 0.200
84 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 decimal Z across materials (concrete 10.000mm, filament 0.200mm)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
85
86 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
87 sys_mkdir("knowledge/staging/print" as *u8, 0x1ed)
88 let fd: i64 = sys_openat_wr("knowledge/staging/print/round_cistern.gcode" as *u8, 420); if fd >= 0 { sys_write(fd, gcis, ncis); sys_close(fd); g_p("wrote knowledge/staging/print/round_cistern.gcode\n" as *u8) }
89
90 g_p("nx_contour_print_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
91 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
92 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
93 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
94 let ctr__dry: *i64 = gv_ctr()
95 ctr__dry[0] = pass
96 ctr__dry[1] = tot
97 let rc__dry: i64 = gv_verdict("CONTOUR-PRINT-GATE" as *u8, ctr__dry, "arbitrary geometry x any material, one unified emitter, never-brick)" as *u8)
98 sys_exit(rc__dry)
99 return rc__dry
100}