29 lines
629 B
TypeScript
29 lines
629 B
TypeScript
export const CANVAS_GRID_SNAP_SIZE = 10;
|
|
export const CANVAS_GRID_SNAP_STORAGE_KEY = "video-canvas:grid-snap-enabled:v1";
|
|
|
|
export function resolveCanvasGridSnapPosition({
|
|
deltaX,
|
|
deltaY,
|
|
enabled,
|
|
startX,
|
|
startY,
|
|
}: {
|
|
deltaX: number;
|
|
deltaY: number;
|
|
enabled: boolean;
|
|
startX: number;
|
|
startY: number;
|
|
}) {
|
|
if (!enabled) {
|
|
return {
|
|
x: Math.round(startX + deltaX),
|
|
y: Math.round(startY + deltaY),
|
|
};
|
|
}
|
|
|
|
return {
|
|
x: startX + Math.round(deltaX / CANVAS_GRID_SNAP_SIZE) * CANVAS_GRID_SNAP_SIZE,
|
|
y: startY + Math.round(deltaY / CANVAS_GRID_SNAP_SIZE) * CANVAS_GRID_SNAP_SIZE,
|
|
};
|
|
}
|