import { GRID_SPACING } from "../constants.js";
const snapToGrid = (value, gridSize = GRID_SPACING)=>Math.round(value / gridSize) * gridSize;
const calculateGridAlignedHandlePositions = (nodeSize, numHandles, gridSize = GRID_SPACING)=>{
    if (0 === numHandles) return [];
    if (nodeSize <= 0) return [];
    if (1 === numHandles) return [
        snapToGrid(nodeSize / 2, gridSize)
    ];
    const idealSpacing = nodeSize / (numHandles + 1);
    if (nodeSize % gridSize !== 0) {
        const positions = [];
        for(let i = 0; i < numHandles; i++)positions.push(idealSpacing * (i + 1));
        return positions;
    }
    const roundedSpacing = Math.round(idealSpacing / gridSize) * gridSize;
    let gridAlignedSpacing = Math.max(gridSize, roundedSpacing);
    let totalSpan = (numHandles - 1) * gridAlignedSpacing;
    let startPosition = (nodeSize - totalSpan) / 2;
    if (startPosition % gridSize !== 0 && gridAlignedSpacing > gridSize) {
        gridAlignedSpacing -= gridSize;
        totalSpan = (numHandles - 1) * gridAlignedSpacing;
        startPosition = (nodeSize - totalSpan) / 2;
    }
    const positions = [];
    for(let i = 0; i < numHandles; i++)positions.push(startPosition + i * gridAlignedSpacing);
    return positions;
};
export { calculateGridAlignedHandlePositions };
