From a7ffc17eb9baf5aecbcf3e9a3fd5c282cc322231 Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Fri, 9 Aug 2024 16:20:51 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AA=A8=EC=9E=84=EC=A7=80=EB=B6=95=20?= =?UTF-8?q?=EB=8B=A8=EA=B3=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/qpolygon-utils.js | 72 +++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/src/util/qpolygon-utils.js b/src/util/qpolygon-utils.js index 258f5d97..f6162e54 100644 --- a/src/util/qpolygon-utils.js +++ b/src/util/qpolygon-utils.js @@ -9,6 +9,7 @@ import { getRoofHypotenuse, } from '@/util/canvas-util' import { QPolygon } from '@/components/fabric/QPolygon' +import * as turf from '@turf/turf' const TWO_PI = Math.PI * 2 @@ -983,6 +984,43 @@ export const splitPolygonWithLines = (polygon) => { }) }) + /** + * 좌표 테스트용 + */ + allLines.forEach((line) => { + const text = new fabric.Text(`(${line.startPoint.x},${line.startPoint.y})`, { + left: line.startPoint.x, + top: line.startPoint.y, + fontSize: 15, + }) + + polygon.canvas.add(text) + polygon.canvas.renderAll() + + const text2 = new fabric.Text(`(${line.endPoint.x},${line.endPoint.y})`, { + left: line.endPoint.x, + top: line.endPoint.y, + fontSize: 15, + }) + + polygon.canvas.add(text2) + polygon.canvas.renderAll() + }) + + polygon.points.forEach((point, index) => { + const text = new fabric.Text(`(${point.x},${point.y})`, { + left: point.x, + top: point.y, + fontSize: 15, + }) + + polygon.canvas.add(text) + polygon.canvas.renderAll() + }) + /** + * 좌표 테스트용 끝 + */ + polygon.points.forEach((point, index) => { allLines.forEach((line) => { if (line.endPoint.x === point.x && line.endPoint.y === point.y) { @@ -1007,22 +1045,39 @@ export const splitPolygonWithLines = (polygon) => { const arrivalPoint = endLine.endPoint routes.push(startLine.startPoint) routes.push(startLine.endPoint) + //hip끼리 만나는 경우는 아무것도 안해도됨 - let count = 0 if (!isSamePoint(startLine.endPoint, arrivalPoint)) { // polygon line까지 추가 const allLinesCopy = [...allLines, ...polygon.lines] // hip이 만나지 않는 경우 갈 수 있는 길을 다 돌아야함 let currentPoint = startLine.endPoint let currentLine = startLine - - while (!isSamePoint(currentPoint, arrivalPoint) && count <= polygon.points.length) { - count++ + let movedLines = [] + let subMovedLines = [] + while (!isSamePoint(currentPoint, arrivalPoint)) { // startHip에서 만나는 출발선 두개. 두개의 선을 출발하여 arrivalPoint에 도착할 때 까지 count를 세고, 더 낮은 count를 가진 길을 선택한다. let connectedLines = allLinesCopy.filter((line) => isSamePoint(line.startPoint, currentPoint) || isSamePoint(line.endPoint, currentPoint)) connectedLines = connectedLines.filter((line) => line !== currentLine) + connectedLines = connectedLines.filter((line) => !subMovedLines.includes(line)) + + //마지막 선이 endLine의 startPoint와 같은경우 그 전까지 movedLine을 제거한다. + const endLineMeetLineCnt = connectedLines.filter((line) => { + return isSamePoint(line.endPoint, endLine.startPoint) || isSamePoint(line.startPoint, endLine.startPoint) + }).length + + if (endLineMeetLineCnt !== 0) { + movedLines.push(subMovedLines) + + console.log(movedLines, index) + } + + connectedLines = connectedLines.filter((line) => { + return !isSamePoint(line.endPoint, endLine.startPoint) && !isSamePoint(line.startPoint, endLine.startPoint) + }) + if (connectedLines.length === 0) { return } @@ -1050,14 +1105,15 @@ export const splitPolygonWithLines = (polygon) => { currentPoint = tempPoints[minIndex].point currentLine = tempPoints[minIndex].line + if (currentLine !== startLine) { + subMovedLines.push(currentLine) + } routes.push(currentPoint) } } - if (count <= polygon.points.length - 1) { - routes.push(endLine.startPoint) - roofs.push(routes) - } + routes.push(endLine.startPoint) + roofs.push(routes) }) // 중복 제거