import type { CadKernel, CadParameters, Vec2 } from "./kernel"; import { DRAWER_PLATE_CHAMFER, drawerSocketDimensions, validateDrawerSocket } from "../drawer-rail-socket"; /** Original measured rear socket. XY is the cabinet mounting plane; Z points * toward the rail. This orientation is also the support-free print orientation. */ export function buildDrawerSocket(c: CadKernel, parameters: CadParameters) { validateDrawerSocket(parameters); const p = parameters as Record; const { insideWidth: w, insideHeight: h, outsideWidth: ow, outsideHeight: oh, plateWidth, plateHeight } = drawerSocketDimensions(p); const x = plateWidth / 2, y = plateHeight / 2, b = DRAWER_PLATE_CHAMFER; const outline: Vec2[] = [[-x + b, -y], [x - b, -y], [x, -y + b], [x, y - b], [x - b, y], [-x + b, y], [-x, y - b], [-x, -y + b]]; const screwHoles = [-p.screw_spacing / 2, p.screw_spacing / 2].map(sx => c.move2(c.circle(p.screw_diameter / 2), [sx, 0])); const plate = c.extrude(c.sub2(c.polygon(outline), ...screwHoles), p.flange_thickness); const outer = c.box(ow, oh, p.insertion_depth); const inner = c.box(w, h, p.insertion_depth + 1); // Four corresponding rectangle vertices give a true 45-degree entry bevel. const mouth = c.move(c.keep(c.rect(w, h).extrude(p.lead_in, 0, 0, [(w + 2 * p.lead_in) / w, (h + 2 * p.lead_in) / h])), [0, 0, p.insertion_depth - p.lead_in]); const sleeve = c.difference(outer, inner, mouth); return c.union(plate, c.move(sleeve, [0, p.vertical_offset, p.flange_thickness])); }