From 3ab518e1881f353697c7aa7982537e070795b4af Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Fri, 23 Aug 2024 16:42:17 +0900 Subject: [PATCH] =?UTF-8?q?=EB=91=98=EB=8B=A4=20=EC=B2=B4=ED=81=AC?= =?UTF-8?q?=EC=8B=9C=EB=8F=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useMode.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/hooks/useMode.js b/src/hooks/useMode.js index ffca9f48..3b24d85f 100644 --- a/src/hooks/useMode.js +++ b/src/hooks/useMode.js @@ -140,6 +140,33 @@ export function useMode() { let newY = pointer.y if (isGuideLineMode && isGuideDotMode && mode === Mode.EDIT) { + const closestHorizontalLine = getClosestHorizontalLine(pointer, horizontalLineArray) + const closetVerticalLine = getClosestVerticalLine(pointer, verticalLineArray) + const xDiff = Math.abs(pointer.x - closetVerticalLine.x1) + const yDiff = Math.abs(pointer.y - closestHorizontalLine.y1) + + const x = pointer.x - guideLineLength * Math.floor(pointer.x / guideLineLength) + const y = pointer.y - guideLineLength * Math.floor(pointer.y / guideLineLength) + + const xRate = x / guideLineLength + const yRate = y / guideLineLength + const isAttachX = xRate >= 0.4 && xRate <= 0.7 + const isAttachY = yRate >= 0.4 && yRate <= 0.7 + + if (isAttachX && isAttachY) { + newX = Math.floor(pointer.x / guideLineLength) * guideLineLength + guideLineLength / 2 + newY = Math.floor(pointer.y / guideLineLength) * guideLineLength + guideLineLength / 2 + } else { + if (Math.min(xDiff, yDiff) <= 20) { + if (xDiff < yDiff) { + newX = closetVerticalLine.x1 + newY = pointer.y + } else { + newX = pointer.x + newY = closestHorizontalLine.y1 + } + } + } } else if (isGuideDotMode && mode === Mode.EDIT) { const x = pointer.x - guideDotLength * Math.floor(pointer.x / guideDotLength) const y = pointer.y - guideDotLength * Math.floor(pointer.y / guideDotLength)