diff --git a/src/hooks/usePolygon.js b/src/hooks/usePolygon.js index 1bc2dffa..e1f127a5 100644 --- a/src/hooks/usePolygon.js +++ b/src/hooks/usePolygon.js @@ -859,6 +859,7 @@ export const usePolygon = () => { line.endPoint = endPoint }) + // polygon line에서 각각 출발한다. polygonLines.forEach((line) => { /*line.set({ strokeWidth: 5, stroke: 'green' }) canvas.add(line) @@ -872,9 +873,11 @@ export const usePolygon = () => { const startLine = line const visitPoints = [startPoint] const visitLines = [startLine] + let notVisitedLines = [] let cnt = 0 while (!isSamePoint(currentPoint, arrivalPoint)) { + //현재 점으로 부터 갈 수 있는 다른 라인을 찾는다. let nextLines = allLines.filter( (line2) => (isSamePoint(line2.startPoint, currentPoint) || isSamePoint(line2.endPoint, currentPoint)) && @@ -892,8 +895,13 @@ export const usePolygon = () => { ) } - if (!nextLines) { - break + if (nextLines.length === 0) { + //아직 안갔던 line중 0번째를 선택한다. + if (notVisitedLines.length === 0) { + break + } else { + // nextLines = [...notVisitedLines.shift().line] + } } let comparisonPoints = [] @@ -919,6 +927,14 @@ export const usePolygon = () => { nextLines.forEach((nextLine) => { if (isSamePoint(nextLine.startPoint, minDistancePoint) || isSamePoint(nextLine.endPoint, minDistancePoint)) { visitLines.push(nextLine) + } else { + notVisitedLines.push({ + line: nextLine, + endPoint: nextLine.endPoint, + startPoint: nextLine.startPoint, + currentPoint: { ...currentPoint }, + roofPoints: [...roofPoints], + }) } })