From 3871c7d0d1eba1b244bc8d86bc26b26554c56dc3 Mon Sep 17 00:00:00 2001 From: yjnoh Date: Mon, 26 Aug 2024 12:36:15 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B7=B8=EB=A6=AC=EB=93=9C=20=EC=9E=84?= =?UTF-8?q?=EC=9D=98=20=EC=84=A4=EC=A0=95=20=ED=9D=A1=EC=B0=A9=EC=A0=90=20?= =?UTF-8?q?=EC=9E=91=EC=97=85,=20=EA=B7=B8=EB=A6=AC=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Roof2.jsx | 3 +- src/components/SettingsModal.jsx | 180 +++++++++++-------------------- src/hooks/useMode.js | 48 +++++---- 3 files changed, 90 insertions(+), 141 deletions(-) diff --git a/src/components/Roof2.jsx b/src/components/Roof2.jsx index 7467a634..3fce8640 100644 --- a/src/components/Roof2.jsx +++ b/src/components/Roof2.jsx @@ -80,7 +80,6 @@ export default function Roof2(props) { setMode, changeMode, handleClear, - fillCellInPolygon, zoomIn, zoomOut, zoom, @@ -580,7 +579,7 @@ export default function Roof2(props) { > 그리드 설정 - + ) diff --git a/src/hooks/useMode.js b/src/hooks/useMode.js index 11cc0ec2..c7f2f5b2 100644 --- a/src/hooks/useMode.js +++ b/src/hooks/useMode.js @@ -123,9 +123,13 @@ export function useMode() { }, [guideLineInfo]) const drawMouseLines = (e) => { + console.log('guideLineInfo', guideLineInfo) + let isGuideLineMode = false, isGuideDotMode = false - let guideDotLength, guideLineLength, horizontalLineArray, verticalLineArray + let guideDotLength, guideLineLengthHori, guideLineLengthVert, horizontalLineArray, verticalLineArray + + console.log() if (isObjectNotEmpty(guideLineInfo)) { const guideLineState = guideLineInfo.filter((item) => item.guideMode === 'guideLine') @@ -136,13 +140,15 @@ export function useMode() { isGuideDotMode = guideDotState.length > 0 if (isGuideDotMode) { - guideDotLength = Number(guideDotState[0].moduleLength) + guideLineLengthHori = Number(guideDotState[0].moduleHoriLength) + guideLineLengthVert = Number(guideDotState[0].moduleVertLength) } if (isGuideLineMode) { horizontalLineArray = [...guideLineState[0].horizontalLineArray] verticalLineArray = [...guideLineState[0].verticalLineArray] - guideLineLength = Number(guideLineState[0].moduleLength) + guideLineLengthHori = Number(guideLineState[0].moduleHoriLength) + guideLineLengthVert = Number(guideLineState[0].moduleVertLength) } } @@ -161,17 +167,17 @@ export function useMode() { 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 x = pointer.x - guideLineLengthHori * Math.floor(pointer.x / guideLineLengthHori) + const y = pointer.y - guideLineLengthVert * Math.floor(pointer.y / guideLineLengthVert) - const xRate = x / guideLineLength - const yRate = y / guideLineLength + const xRate = x / guideLineLengthHori + const yRate = y / guideLineLengthVert 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 + newX = Math.floor(pointer.x / guideLineLengthHori) * guideLineLengthHori + guideLineLengthHori / 2 + newY = Math.floor(pointer.y / guideLineLengthVert) * guideLineLengthVert + guideLineLengthVert / 2 } else { if (Math.min(xDiff, yDiff) <= 20) { if (xDiff < yDiff) { @@ -184,17 +190,17 @@ export function useMode() { } } } 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) + const x = pointer.x - guideLineLengthHori * Math.floor(pointer.x / guideLineLengthHori) + const y = pointer.y - guideLineLengthVert * Math.floor(pointer.y / guideLineLengthVert) - const xRate = x / guideDotLength - const yRate = y / guideDotLength + const xRate = x / guideLineLengthHori + const yRate = y / guideLineLengthVert const isAttachX = xRate >= 0.4 && xRate <= 0.7 const isAttachY = yRate >= 0.4 && yRate <= 0.7 if (isAttachX && isAttachY) { - newX = Math.floor(pointer.x / guideDotLength) * guideDotLength + guideDotLength / 2 - newY = Math.floor(pointer.y / guideDotLength) * guideDotLength + guideDotLength / 2 + newX = Math.floor(pointer.x / guideLineLengthHori) * guideLineLengthHori + guideLineLengthHori / 2 + newY = Math.floor(pointer.y / guideLineLengthVert) * guideLineLengthVert + guideLineLengthVert / 2 } } else if (isGuideLineMode && mode === Mode.EDIT) { const closestHorizontalLine = getClosestHorizontalLine(pointer, horizontalLineArray) @@ -202,17 +208,17 @@ export function useMode() { 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 x = pointer.x - guideLineLengthHori * Math.floor(pointer.x / guideLineLengthHori) + const y = pointer.y - guideLineLengthVert * Math.floor(pointer.y / guideLineLengthVert) - const xRate = x / guideLineLength - const yRate = y / guideLineLength + const xRate = x / guideLineLengthHori + const yRate = y / guideLineLengthVert 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 + newX = Math.floor(pointer.x / guideLineLengthHori) * guideLineLengthHori + guideLineLengthHori / 2 + newY = Math.floor(pointer.y / guideLineLengthVert) * guideLineLengthVert + guideLineLengthVert / 2 } else { if (Math.min(xDiff, yDiff) <= 20) { if (xDiff < yDiff) {