nx_infill.nx
buildroot/runtime/nx_infill.nx
about
nx_infill.nx -- scan-line infill pattern generator for closed
NxPolygon contours. Produces line segments that the G-code
emitter prints as rectilinear infill inside the perimeter.
Algorithm: classical scan-line fill (Foley/van Dam 1990).
1. compute polygon bbox
2. for each horizontal scan line at y = bbox.min_y + k*spacing:
a. find x-coord where each polygon edge crosses y
(skip horizontal edges; integer cross-multiply form)
b. sort x-coords ascending
c. pair consecutive crossings; emit segment per pair
Spacing derived from line_width + density_pct:
spacing_mm = (line_width_mm * 100) / density_pct
Density 100% = touching lines, 50% = 50% air, 25% = 75% air.
Grid pattern (perpendicular alternation per layer for better
mechanical isotropy): when called with vertical=1, the algorithm
runs on a transposed (x<->y) coordinate system, producing
vertical scan lines. Caller toggles `vertical` per layer index.
Reuses NxSliceSoup as output (same flat-segment shape as
nx_slice_plane; downstream G-code emitter consumes either).
Composes nx_polygon (closed contour input) + nx_qsort_i64
(crossing-coord sort) + nx_slice_plane (segment soup output type).
Per cardinal NISHI_3D_PRINT_ROADMAP ยง2.x infill: lines pattern v1
is the substrate floor. Honeycomb / gyroid / cubic are future
patterns queued for after this primitive validates on real prints.
Per cardinal feedback-bits-up-exceed-never-match: substrate ships
the universal scan-line core; richer patterns layer on top, NOT
instead of, this primitive.
Pure i64 arithmetic throughout (integer cross-multiply avoids
division during the straddle test; one division per crossing for
the x-coord computation).
license_tier: ORIGINAL
dependencies 4 imports · 2 importers
imports: nx_syscalls.nxnx_polygon.nxnx_slice_plane.nxnx_qsort.nx
imported by: nx_infill_test.nxnx_slice_pipeline.nx
structs
| none |
consts
| 48 | const NX_INFILL_PATTERN_LINES: i64 = 0 |
| 49 | const NX_INFILL_PATTERN_GRID: i64 = 1 // alternating dir/layer |
| 50 | const NX_INFILL_PATTERN_HONEYCOMB: i64 = 2 // queued |
| 51 | const NX_INFILL_PATTERN_GYROID: i64 = 3 // queued |
| 55 | const NX_INFILL_OK: i64 = 0 |
| 56 | const NX_INFILL_ERR_BAD_POLYGON: i64 = 1 |
| 57 | const NX_INFILL_ERR_BAD_DENSITY: i64 = 2 |
| 58 | const NX_INFILL_ERR_BAD_PATTERN: i64 = 3 |
| 59 | const NX_INFILL_ERR_CAPACITY: i64 = 4 |
functions
| 61 | func nx_infill_verdict_name(v: i64) -> *u8 |
| 81 | func nx_infill_scanline_xs(poly: *NxPolygon, y: i64, |
| 119 | func nx_infill_scanline_ys(poly: *NxPolygon, x: i64, |
| 161 | func nx_infill_lines(poly: *NxPolygon, density_pct: i64, |