(
position: { x: number; y: number },
gridSize: number | undefined
)
| 44 | * Returns the original position if gridSize is 0 or not provided. |
| 45 | */ |
| 46 | export function snapPositionToGrid( |
| 47 | position: { x: number; y: number }, |
| 48 | gridSize: number | undefined |
| 49 | ): { x: number; y: number } { |
| 50 | if (!gridSize || gridSize <= 0) { |
| 51 | return position |
| 52 | } |
| 53 | return { |
| 54 | x: snapToGrid(position.x, gridSize), |
| 55 | y: snapToGrid(position.y, gridSize), |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Snaps all node positions in a graph to grid positions and returns updated dimensions. |
no test coverage detected