12 그리드 스냅 시스템 적용

This commit is contained in:
dohyeons 2025-10-13 17:16:44 +09:00
parent f73229eeeb
commit 3d48c0f7cb
2 changed files with 6 additions and 3 deletions

View File

@ -279,6 +279,8 @@ export function CanvasElement({
top: displayPosition.y,
width: displaySize.width,
height: displaySize.height,
padding: `${GRID_CONFIG.ELEMENT_PADDING}px`,
boxSizing: "border-box",
}}
onMouseDown={handleMouseDown}
>

View File

@ -11,6 +11,7 @@ export const GRID_CONFIG = {
CELL_SIZE: 60, // 60px 정사각형 셀
GAP: 8, // 셀 간격
SNAP_THRESHOLD: 15, // 스냅 임계값 (px)
ELEMENT_PADDING: 4, // 요소 주위 여백 (px)
} as const;
/**
@ -29,15 +30,15 @@ export const getCanvasWidth = () => {
};
/**
*
* ( )
* @param value -
* @param cellSize - (, GRID_CONFIG.CELL_SIZE)
* @returns
* @returns ( )
*/
export const snapToGrid = (value: number, cellSize: number = GRID_CONFIG.CELL_SIZE): number => {
const cellWithGap = cellSize + GRID_CONFIG.GAP;
const gridIndex = Math.round(value / cellWithGap);
return gridIndex * cellWithGap;
return gridIndex * cellWithGap + GRID_CONFIG.ELEMENT_PADDING;
};
/**