mirror of
https://github.com/sotam0316/drawNET_test.git
synced 2026-04-25 12:08:37 +09:00
9 lines
330 B
JavaScript
9 lines
330 B
JavaScript
/**
|
|
* Snap a position to the nearest grid interval, accounting for the object's dimension
|
|
* to ensure its edges or center align properly with the grid.
|
|
*/
|
|
export function snapPosition(pos, dimension, spacing) {
|
|
const offset = (dimension / 2) % spacing;
|
|
return Math.round((pos - offset) / spacing) * spacing + offset;
|
|
}
|