export interface GridfinitySpec { gridSize: number; // e.g., 42mm heightUnit: number; // e.g., 7mm baseThickness: number; // Height of baseplate above drawer surface } export const DEFAULT_SPEC: GridfinitySpec = { gridSize: 42, heightUnit: 7, baseThickness: 4.8, // Standard baseplate height is 5mm, but usually 4.8mm-5mm }; export interface CalculatorInputs { width: number; length: number; height: number; unit: 'mm' | 'in'; spec: GridfinitySpec; } export interface CalculatorResults { widthGrids: number; lengthGrids: number; fullGridsX: number; fullGridsY: number; maxBinUnits: number; remainingWidth: number; remainingLength: number; remainingHeight: number; } const INCH_TO_MM = 25.4; export function calculateGridfinity(inputs: CalculatorInputs): CalculatorResults { const { width, length, height, unit, spec } = inputs; // Convert all to mm for internal calculation const w = unit === 'in' ? width * INCH_TO_MM : width; const l = unit === 'in' ? length * INCH_TO_MM : length; const h = unit === 'in' ? height * INCH_TO_MM : height; const widthGrids = w / spec.gridSize; const lengthGrids = l / spec.gridSize; const fullGridsX = Math.floor(widthGrids); const fullGridsY = Math.floor(lengthGrids); // Height calculation: (Available Height - Baseplate Thickness) / 7mm // We floor this because bins come in whole unit increments const maxBinUnits = Math.max(0, Math.floor((h - spec.baseThickness) / spec.heightUnit)); const remainingWidth = w % spec.gridSize; const remainingLength = l % spec.gridSize; const remainingHeight = (h - spec.baseThickness) % spec.heightUnit; return { widthGrids, lengthGrids, fullGridsX, fullGridsY, maxBinUnits, remainingWidth, remainingLength, remainingHeight }; }