import type { CadKernel, CadParameters } from "./kernel"; import { cardInsertDimensions, cardInsertNotch, cardInsertValues, validateCardInsert } from "../card-box-insert"; /** Original box-fitted insert. X follows the ordered sleeve-width list, Y the * deck rows, and Z the box depth. All cutouts are open upward for A1 printing. */ export function buildCardInsert(c: CadKernel, input: CadParameters) { validateCardInsert(input); const p = cardInsertValues(input), d = cardInsertDimensions(input), { x, y, z } = d.bbox; const body = c.move(c.box(x, y, z), [x / 2, y / 2, 0]); const cuts = d.bays.flatMap(bay => Array.from({ length: p.rows }, (_, row) => c.move(c.box(bay.width, d.bayLength, z - p.floor + 1), [bay.x + bay.width / 2, p.wall + row * (d.bayLength + p.wall) + d.bayLength / 2, p.floor]))); const outline = cardInsertNotch(input); // Extend only the cutter above the open top; the priced in-body profile is // exactly outline. Extrusion runs in -Y, overlapping each wall by .01 mm. const profile: [number, number][] = [[0, d.notchDepth + 1], ...outline, [p.notch_width, d.notchDepth + 1]]; const cutter = c.rotate(c.extrude(c.polygon(profile), p.wall + .02), [90, 0, 0]); for (const bay of d.bays) for (let row = 0; row <= p.rows; row++) { cuts.push(c.move(cutter, [bay.x + (bay.width - p.notch_width) / 2, row * (d.bayLength + p.wall) + p.wall + .01, d.notchBottom])); } return c.difference(body, ...cuts); }