code wiki / _hdl_build / nx_slice_bridge_gate.nx

nx_slice_bridge_gate.nx source

↩ module page · 95 lines · 5175 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" 12 13const SB_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_slice_bridge_gate (R1-FULL: slicer NxPolygon -> any material) ===\n" as *u8) 33 pm_seed(SB_PRINT) 34 35 // a real slicer polygon: 80x60 mm square, built with the slicer's own constructor (Q14) 36 let sq: *NxPolygon = nx_polygon_make_square(0, 0, 80 * NX_POLYGON_Q14_ONE, 60 * NX_POLYGON_Q14_ONE) 37 let xs: *i64 = sys_mmap(8 * 64) as *i64 38 let ys: *i64 = sys_mmap(8 * 64) as *i64 39 let nv: i64 = cb_polygon_to_contour(sq, xs, ys) 40 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) 41 42 var pass: i64 = 0 43 var tot: i64 = 0 44 45 // T1 bridge Q14 -> mm 46 tot = tot + 1 47 var ok1: i64 = 1 48 if nv != 4 { ok1 = 0 } 49 if xs[1] != 80 { ok1 = 0 } 50 if ys[2] != 60 { ok1 = 0 } 51 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) } 52 53 // T2 sliced square -> concrete 54 let gsq: *u8 = sys_mmap(131072); let nsq: i64 = cb_emit_polygon(SB_PRINT, "concrete" as *u8, sq, 100, gsq) 55 tot = tot + 1 56 var ok2: i64 = 1 57 if nsq <= 0 { ok2 = 0 } 58 if as_contains(gsq, nsq, "X80 Y0" as *u8) != 1 { ok2 = 0 } 59 if as_contains(gsq, nsq, "X80 Y60" as *u8) != 1 { ok2 = 0 } 60 if as_contains(gsq, nsq, "M104" as *u8) != 0 { ok2 = 0 } // concrete: cold 61 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) } 62 63 // a real slicer polygon: hexagon (non-rectangular), built vertex by vertex (Q14) 64 let hx: *NxPolygon = nx_polygon_alloc(8) 65 nx_polygon_add_vert(hx, 150 * NX_POLYGON_Q14_ONE, 100 * NX_POLYGON_Q14_ONE) 66 nx_polygon_add_vert(hx, 125 * NX_POLYGON_Q14_ONE, 143 * NX_POLYGON_Q14_ONE) 67 nx_polygon_add_vert(hx, 75 * NX_POLYGON_Q14_ONE, 143 * NX_POLYGON_Q14_ONE) 68 nx_polygon_add_vert(hx, 50 * NX_POLYGON_Q14_ONE, 100 * NX_POLYGON_Q14_ONE) 69 nx_polygon_add_vert(hx, 75 * NX_POLYGON_Q14_ONE, 57 * NX_POLYGON_Q14_ONE) 70 nx_polygon_add_vert(hx, 125 * NX_POLYGON_Q14_ONE, 57 * NX_POLYGON_Q14_ONE) 71 let ghx: *u8 = sys_mmap(131072); let nhx: i64 = cb_emit_polygon(SB_PRINT, "pla" as *u8, hx, 20, ghx) 72 tot = tot + 1 73 var ok3: i64 = 1 74 if nhx <= 0 { ok3 = 0 } 75 if as_contains(ghx, nhx, "X125 Y143" as *u8) != 1 { ok3 = 0 } // off-axis hex vertex (arbitrary geometry) 76 if as_contains(ghx, nhx, "M104" as *u8) != 1 { ok3 = 0 } // filament: hot 77 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) } 78 79 // T4 never-brick both 80 tot = tot + 1 81 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) } 82 83 // T5 the join 84 tot = tot + 1 85 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) } 86 87 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 88 sys_mkdir("knowledge/staging/print" as *u8, 0x1ed) 89 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) } 90 91 g_p("nx_slice_bridge_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 92 if pass == tot { g_p(" verdict=GREEN (R1-FULL: sliced geometry -> any material, the pipeline is joined)\n" as *u8); return 0 } 93 g_p(" verdict=RED\n" as *u8) 94 return 1 95}