code wiki / _hdl_build / nx_slice_bridge_gate.nx
nx_slice_bridge_gate.nx source
↩ module page · 102 lines · 5576 B
1// nx_slice_bridge_gate.nx -- GATE: R1-FULL. The slicer's NxPolygon type drives the multi-material emitter.
2// T1 bridge Q14->mm correct, T2 a sliced SQUARE prints in concrete (bridged verts present, cold), T3 a sliced
3// HEXAGON prints in filament (off-axis vert, hot), T4 never-brick both, T5 the JOIN (real NxPolygon -> any
4// material G-code). The production slice pipeline (nx_slice_plane->nx_slice_contour) emits exactly this
5// NxPolygon type, so any STL now reaches any material. license_tier: ORIGINAL
6import "nx_slice_bridge.nx"
7import "nx_polygon.nx"
8import "nx_print_material.nx"
9import "nx_food_science.nx"
10import "nx_seg_store.nx"
11import "nx_syscalls.nx"
12import "nx_gate_verdict.nx"
13
14const SB_PRINT: *u8 = "knowledge/store/print-"
15
16func 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 }
17func g_i(v: i64) -> i64 {
18 let bb: *u8 = sys_mmap(28); var m: i64 = v
19 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
20 let t: *u8 = sys_mmap(28); var k: i64 = 0
21 if m == 0 { t[0] = 48 as u8; k = 1 }
22 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
23 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
24}
25func g_nobrick(g: *u8, n: i64) -> i64 {
26 if as_contains(g, n, "M997" as *u8) != 0 { return 0 }
27 if as_contains(g, n, "M500" as *u8) != 0 { return 0 }
28 if as_contains(g, n, "M502" as *u8) != 0 { return 0 }
29 return 1
30}
31
32func main() -> i64 {
33 g_p("=== nx_slice_bridge_gate (R1-FULL: slicer NxPolygon -> any material) ===\n" as *u8)
34 pm_seed(SB_PRINT)
35
36 // a real slicer polygon: 80x60 mm square, built with the slicer's own constructor (Q14)
37 let sq: *NxPolygon = nx_polygon_make_square(0, 0, 80 * NX_POLYGON_Q14_ONE, 60 * NX_POLYGON_Q14_ONE)
38 let xs: *i64 = sys_mmap(8 * 64) as *i64
39 let ys: *i64 = sys_mmap(8 * 64) as *i64
40 let nv: i64 = cb_polygon_to_contour(sq, xs, ys)
41 g_p("bridged square: verts=" as *u8); g_i(nv); g_p(" xs[1]=" as *u8); g_i(xs[1]); g_p(" ys[2]=" as *u8); g_i(ys[2]); g_p("\n" as *u8)
42
43 var pass: i64 = 0
44 var tot: i64 = 0
45
46 // T1 bridge Q14 -> mm
47 tot = tot + 1
48 var ok1: i64 = 1
49 if nv != 4 { ok1 = 0 }
50 if xs[1] != 80 { ok1 = 0 }
51 if ys[2] != 60 { ok1 = 0 }
52 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 bridge Q14->mm (square: 4 verts, xs[1]=80, ys[2]=60)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
53
54 // T2 sliced square -> concrete
55 let gsq: *u8 = sys_mmap(131072); let nsq: i64 = cb_emit_polygon(SB_PRINT, "concrete" as *u8, sq, 100, gsq)
56 tot = tot + 1
57 var ok2: i64 = 1
58 if nsq <= 0 { ok2 = 0 }
59 if as_contains(gsq, nsq, "X80 Y0" as *u8) != 1 { ok2 = 0 }
60 if as_contains(gsq, nsq, "X80 Y60" as *u8) != 1 { ok2 = 0 }
61 if as_contains(gsq, nsq, "M104" as *u8) != 0 { ok2 = 0 } // concrete: cold
62 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 sliced square -> concrete G-code (bridged verts present, cold paste)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) }
63
64 // a real slicer polygon: hexagon (non-rectangular), built vertex by vertex (Q14)
65 let hx: *NxPolygon = nx_polygon_alloc(8)
66 nx_polygon_add_vert(hx, 150 * NX_POLYGON_Q14_ONE, 100 * NX_POLYGON_Q14_ONE)
67 nx_polygon_add_vert(hx, 125 * NX_POLYGON_Q14_ONE, 143 * NX_POLYGON_Q14_ONE)
68 nx_polygon_add_vert(hx, 75 * NX_POLYGON_Q14_ONE, 143 * NX_POLYGON_Q14_ONE)
69 nx_polygon_add_vert(hx, 50 * NX_POLYGON_Q14_ONE, 100 * NX_POLYGON_Q14_ONE)
70 nx_polygon_add_vert(hx, 75 * NX_POLYGON_Q14_ONE, 57 * NX_POLYGON_Q14_ONE)
71 nx_polygon_add_vert(hx, 125 * NX_POLYGON_Q14_ONE, 57 * NX_POLYGON_Q14_ONE)
72 let ghx: *u8 = sys_mmap(131072); let nhx: i64 = cb_emit_polygon(SB_PRINT, "pla" as *u8, hx, 20, ghx)
73 tot = tot + 1
74 var ok3: i64 = 1
75 if nhx <= 0 { ok3 = 0 }
76 if as_contains(ghx, nhx, "X125 Y143" as *u8) != 1 { ok3 = 0 } // off-axis hex vertex (arbitrary geometry)
77 if as_contains(ghx, nhx, "M104" as *u8) != 1 { ok3 = 0 } // filament: hot
78 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 sliced hexagon -> filament G-code (off-axis vertex X125 Y143, hot)\n" as *u8) } else { g_p("FAIL T3\n" as *u8) }
79
80 // T4 never-brick both
81 tot = tot + 1
82 if g_nobrick(gsq, nsq) == 1 { if g_nobrick(ghx, nhx) == 1 { pass = pass + 1; g_p("PASS T4 never-brick (both sliced parts)\n" as *u8) } else { g_p("FAIL T4 hex\n" as *u8) } } else { g_p("FAIL T4 square\n" as *u8) }
83
84 // T5 the join
85 tot = tot + 1
86 if nsq > 0 { if nhx > 0 { pass = pass + 1; g_p("PASS T5 JOIN: the slicer's NxPolygon type -> any material G-code (any STL -> any material)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } } else { g_p("FAIL T5\n" as *u8) }
87
88 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
89 sys_mkdir("knowledge/staging/print" as *u8, 0x1ed)
90 let fd: i64 = sys_openat_wr("knowledge/staging/print/sliced_hexagon_pla.gcode" as *u8, 420); if fd >= 0 { sys_write(fd, ghx, nhx); sys_close(fd) }
91
92 g_p("nx_slice_bridge_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
93 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
94 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
95 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
96 let ctr__dry: *i64 = gv_ctr()
97 ctr__dry[0] = pass
98 ctr__dry[1] = tot
99 let rc__dry: i64 = gv_verdict("SLICE-BRIDGE-GATE" as *u8, ctr__dry, "R1-FULL: sliced geometry -> any material, the pipeline is joined)" as *u8)
100 sys_exit(rc__dry)
101 return rc__dry
102}