From 88a41236f40784848f32d693b65ffe5cb0dd0b7f Mon Sep 17 00:00:00 2001 From: yjnoh Date: Thu, 4 Jul 2024 16:51:54 +0900 Subject: [PATCH] =?UTF-8?q?=E3=84=B1=EC=9E=90=20=EB=AA=A8=EC=96=91=20shape?= =?UTF-8?q?=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useMode.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/hooks/useMode.js b/src/hooks/useMode.js index 1fac311d..2fa960ec 100644 --- a/src/hooks/useMode.js +++ b/src/hooks/useMode.js @@ -353,6 +353,47 @@ export function useMode() { // 캔버스에서 모든 라인 객체를 찾습니다. const lines = otherLines || historyLines.current if (!otherLines) { + + const sortedIndex = getStartIndex(lines) + const tmpArraySorted = rearrangeArray(lines, sortedIndex) + + function findTopTwoIndexesByDistance(objArr) { + if (objArr.length < 2) { + return []; // 배열의 길이가 2보다 작으면 빈 배열 반환 + } + + let firstIndex = -1; + let secondIndex = -1; + let firstDistance = -Infinity; + let secondDistance = -Infinity; + + for (let i = 0; i < objArr.length; i++) { + const distance = objArr[i].length; + + if (distance > firstDistance) { + secondDistance = firstDistance; + secondIndex = firstIndex; + firstDistance = distance; + firstIndex = i; + } else if (distance > secondDistance) { + secondDistance = distance; + secondIndex = i; + } + } + + return [firstIndex, secondIndex]; + } + + const topIndex = findTopTwoIndexesByDistance(tmpArraySorted); + + const shape = 0; + + if(topIndex[0] === 2) { + if(topIndex[1] === 3) shape = 1 + }else if(topIndex === 1){ + if(topIndex[1] === 2) shape = 4 + } + historyLines.current = [] }