모임지붕 단계 추가

This commit is contained in:
hyojun.choi 2024-08-09 16:20:51 +09:00
parent 22b9953401
commit a7ffc17eb9

View File

@ -9,6 +9,7 @@ import {
getRoofHypotenuse, getRoofHypotenuse,
} from '@/util/canvas-util' } from '@/util/canvas-util'
import { QPolygon } from '@/components/fabric/QPolygon' import { QPolygon } from '@/components/fabric/QPolygon'
import * as turf from '@turf/turf'
const TWO_PI = Math.PI * 2 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) => { polygon.points.forEach((point, index) => {
allLines.forEach((line) => { allLines.forEach((line) => {
if (line.endPoint.x === point.x && line.endPoint.y === point.y) { if (line.endPoint.x === point.x && line.endPoint.y === point.y) {
@ -1007,22 +1045,39 @@ export const splitPolygonWithLines = (polygon) => {
const arrivalPoint = endLine.endPoint const arrivalPoint = endLine.endPoint
routes.push(startLine.startPoint) routes.push(startLine.startPoint)
routes.push(startLine.endPoint) routes.push(startLine.endPoint)
//hip끼리 만나는 경우는 아무것도 안해도됨 //hip끼리 만나는 경우는 아무것도 안해도됨
let count = 0
if (!isSamePoint(startLine.endPoint, arrivalPoint)) { if (!isSamePoint(startLine.endPoint, arrivalPoint)) {
// polygon line까지 추가 // polygon line까지 추가
const allLinesCopy = [...allLines, ...polygon.lines] const allLinesCopy = [...allLines, ...polygon.lines]
// hip이 만나지 않는 경우 갈 수 있는 길을 다 돌아야함 // hip이 만나지 않는 경우 갈 수 있는 길을 다 돌아야함
let currentPoint = startLine.endPoint let currentPoint = startLine.endPoint
let currentLine = startLine let currentLine = startLine
let movedLines = []
while (!isSamePoint(currentPoint, arrivalPoint) && count <= polygon.points.length) { let subMovedLines = []
count++ while (!isSamePoint(currentPoint, arrivalPoint)) {
// startHip에서 만나는 출발선 두개. 두개의 선을 출발하여 arrivalPoint에 도착할 때 까지 count를 세고, 더 낮은 count를 가진 길을 선택한다. // startHip에서 만나는 출발선 두개. 두개의 선을 출발하여 arrivalPoint에 도착할 때 까지 count를 세고, 더 낮은 count를 가진 길을 선택한다.
let connectedLines = allLinesCopy.filter((line) => isSamePoint(line.startPoint, currentPoint) || isSamePoint(line.endPoint, currentPoint)) let connectedLines = allLinesCopy.filter((line) => isSamePoint(line.startPoint, currentPoint) || isSamePoint(line.endPoint, currentPoint))
connectedLines = connectedLines.filter((line) => line !== currentLine) 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) { if (connectedLines.length === 0) {
return return
} }
@ -1050,14 +1105,15 @@ export const splitPolygonWithLines = (polygon) => {
currentPoint = tempPoints[minIndex].point currentPoint = tempPoints[minIndex].point
currentLine = tempPoints[minIndex].line currentLine = tempPoints[minIndex].line
if (currentLine !== startLine) {
subMovedLines.push(currentLine)
}
routes.push(currentPoint) routes.push(currentPoint)
} }
} }
if (count <= polygon.points.length - 1) { routes.push(endLine.startPoint)
routes.push(endLine.startPoint) roofs.push(routes)
roofs.push(routes)
}
}) })
// 중복 제거 // 중복 제거