code wiki / (root) / nx_gcode_brim_test.nx

nx_gcode_brim_test.nx source

↩ module page · 79 lines · 2734 B

1// nx_gcode_brim_test.nx -- verify brim emission appears when 2// operator enables via nx_gemit_set_brim. 3// 4// Closed-form invariants: 5// (a) Default n_brim_loops == 0 6// (b) Setter accepts 0-30 range; rejects -1 and 31 7// (c) brim emit on disabled state: NO ";BRIM_START" in output 8// (d) brim emit on enabled (3 loops) on unit square: produces 9// ";BRIM_START" + at least 3 G1 X moves (one loop = 4 perim moves) 10// (e) Enabled brim adds bytes vs disabled (proves loops emit) 11// 12// expect_exit: 0 13// license_tier: ORIGINAL 14 15import "nx_syscalls.nx" 16import "nx_polygon.nx" 17import "nx_slice_contour.nx" 18import "nx_machine_graph.nx" 19import "nx_material_profile.nx" 20import "nx_gcode_emit.nx" 21 22const Q14: i64 = 16384 23 24func smoke_contains(buf: *u8, len: i64, needle: *u8) -> i64 { 25 var nlen: i64 = 0 26 while needle[nlen] != 0 { nlen = nlen + 1 } 27 if len < nlen { return 0 } 28 var i: i64 = 0 29 while i <= len - nlen { 30 var j: i64 = 0 31 var matched: i64 = 1 32 while j < nlen { 33 if buf[i + j] != needle[j] { matched = 0; j = nlen } 34 j = j + 1 35 } 36 if matched == 1 { return 1 } 37 i = i + 1 38 } 39 return 0 40} 41 42func main() -> i64 { 43 let qidi: *NxMachineGraph = nx_machine_graph_qidi_xmax3() 44 let pla: *NxMaterialProfile = nx_material_profile_generic_pla() 45 let lh: i64 = 3277 46 let lw: i64 = 6554 47 48 // --- (a) Default disabled --- 49 let e_off: *NxGcodeEmitter = nx_gemit_new(qidi, pla, lh, lw, 8192) 50 if e_off.n_brim_loops != 0 { return 10 } 51 52 // --- (b) Setter validation --- 53 if nx_gemit_set_brim(e_off, 5) != 0 { return 20 } 54 if e_off.n_brim_loops != 5 { return 21 } 55 if nx_gemit_set_brim(e_off, -1) != -1 { return 22 } 56 if nx_gemit_set_brim(e_off, 31) != -1 { return 23 } 57 if nx_gemit_set_brim(e_off, 0) != 0 { return 24 } // disable 58 59 // Test polygon: 10mm square 60 let sq: *NxPolygon = nx_polygon_make_square(0, 0, 10 * Q14, 10 * Q14) 61 62 // --- (c) Disabled: no brim marker --- 63 let e_dis: *NxGcodeEmitter = nx_gemit_new(qidi, pla, lh, lw, 8192) 64 nx_gemit_brim(e_dis, sq, lh) 65 if smoke_contains(e_dis.buf, e_dis.len, ";BRIM_START") == 1 { return 30 } 66 67 // --- (d) Enabled with 3 loops --- 68 let e_en: *NxGcodeEmitter = nx_gemit_new(qidi, pla, lh, lw, 16384) 69 nx_gemit_set_brim(e_en, 3) 70 nx_gemit_brim(e_en, sq, lh) 71 if smoke_contains(e_en.buf, e_en.len, ";BRIM_START") != 1 { return 40 } 72 if smoke_contains(e_en.buf, e_en.len, ";BRIM_END") != 1 { return 41 } 73 if smoke_contains(e_en.buf, e_en.len, "G1 X") != 1 { return 42 } 74 75 // --- (e) Enabled produces more bytes than disabled --- 76 if e_en.len <= e_dis.len { return 50 } 77 78 return 0 79}