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 = [] }