지붕 분할 작업 추가
This commit is contained in:
parent
960056c17d
commit
7162b3c4fb
@ -963,8 +963,25 @@ export default function offsetPolygon(vertices, offset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const splitPolygonWithLines = (polygon) => {
|
export const splitPolygonWithLines = (polygon) => {
|
||||||
//todo: polygon의 모든 line들 모음 hip, ridge, connectRidge
|
const roofs = []
|
||||||
const allLines = [...polygon.hips, ...polygon.ridges, ...polygon.connectRidges]
|
const allLines = [...polygon.innerLines]
|
||||||
|
|
||||||
|
// allLines에 x1,y1,x2,y2를 비교해서 중복되는 값을 제거한다.
|
||||||
|
allLines.forEach((line, index) => {
|
||||||
|
const startPoint = line.startPoint
|
||||||
|
const endPoint = line.endPoint
|
||||||
|
|
||||||
|
allLines.forEach((line2, index2) => {
|
||||||
|
if (index !== index2) {
|
||||||
|
if (
|
||||||
|
(isSamePoint(startPoint, line2.startPoint) && isSamePoint(endPoint, line2.endPoint)) ||
|
||||||
|
(isSamePoint(endPoint, line2.startPoint) && isSamePoint(startPoint, line2.endPoint))
|
||||||
|
) {
|
||||||
|
allLines.splice(index2, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
polygon.points.forEach((point, index) => {
|
polygon.points.forEach((point, index) => {
|
||||||
allLines.forEach((line) => {
|
allLines.forEach((line) => {
|
||||||
@ -979,10 +996,6 @@ export const splitPolygonWithLines = (polygon) => {
|
|||||||
polygon.points.forEach((point, index) => {
|
polygon.points.forEach((point, index) => {
|
||||||
const routes = []
|
const routes = []
|
||||||
|
|
||||||
const polygonPoints = [...polygon.points].map((point, index) => {
|
|
||||||
return { ...point, index }
|
|
||||||
})
|
|
||||||
|
|
||||||
// 시작점은 시작 hip라인의 출발점
|
// 시작점은 시작 hip라인의 출발점
|
||||||
const startPoint = point
|
const startPoint = point
|
||||||
// 도착점은 마지막 hip라인의 끝나는 점
|
// 도착점은 마지막 hip라인의 끝나는 점
|
||||||
@ -1004,12 +1017,12 @@ export const splitPolygonWithLines = (polygon) => {
|
|||||||
|
|
||||||
while (!isSamePoint(currentPoint, arrivalPoint)) {
|
while (!isSamePoint(currentPoint, arrivalPoint)) {
|
||||||
// startHip에서 만나는 출발선 두개. 두개의 선을 출발하여 arrivalPoint에 도착할 때 까지 count를 세고, 더 낮은 count를 가진 길을 선택한다.
|
// startHip에서 만나는 출발선 두개. 두개의 선을 출발하여 arrivalPoint에 도착할 때 까지 count를 세고, 더 낮은 count를 가진 길을 선택한다.
|
||||||
let connectedLines = allLinesCopy.filter(
|
let connectedLines = allLinesCopy.filter((line) => isSamePoint(line.startPoint, currentPoint) || isSamePoint(line.endPoint, currentPoint))
|
||||||
(line) => isSamePoint(line.startPoint, currentPoint) || (isSamePoint(line.endPoint, currentPoint) && line !== currentLine),
|
|
||||||
)
|
connectedLines = connectedLines.filter((line) => line !== currentLine)
|
||||||
|
|
||||||
if (connectedLines.length === 0) {
|
if (connectedLines.length === 0) {
|
||||||
throw new Error('connectedLines is empty')
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let tempPoints = []
|
let tempPoints = []
|
||||||
@ -1040,7 +1053,22 @@ export const splitPolygonWithLines = (polygon) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
routes.push(endLine.startPoint)
|
routes.push(endLine.startPoint)
|
||||||
const roof = new QPolygon(routes, {
|
roofs.push(routes)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 중복 제거
|
||||||
|
roofs.forEach((roofPoint, index) => {
|
||||||
|
const samePointLengthRoofPoints = roofs.filter((roof) => roof.length === roofPoint.length && roof !== roofPoint)
|
||||||
|
|
||||||
|
samePointLengthRoofPoints.forEach((samePointRoof) => {
|
||||||
|
if (arraysHaveSamePoints(samePointRoof, roofPoint)) {
|
||||||
|
roofs.splice(roofs.indexOf(samePointRoof), 1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
roofs.forEach((roofPoint) => {
|
||||||
|
const roof = new QPolygon(roofPoint, {
|
||||||
fontSize: polygon.fontSize,
|
fontSize: polygon.fontSize,
|
||||||
stroke: 'black',
|
stroke: 'black',
|
||||||
fill: 'transparent',
|
fill: 'transparent',
|
||||||
@ -2504,3 +2532,22 @@ const getLineDirection = (line) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function arePointsEqual(point1, point2) {
|
||||||
|
return point1.x === point2.x && point1.y === point2.y
|
||||||
|
}
|
||||||
|
|
||||||
|
function arraysHaveSamePoints(array1, array2) {
|
||||||
|
if (array1.length !== array2.length) return false
|
||||||
|
|
||||||
|
const sortedArray1 = array1.slice().sort((a, b) => a.x - b.x || a.y - b.y)
|
||||||
|
const sortedArray2 = array2.slice().sort((a, b) => a.x - b.x || a.y - b.y)
|
||||||
|
|
||||||
|
for (let i = 0; i < sortedArray1.length; i++) {
|
||||||
|
if (!arePointsEqual(sortedArray1[i], sortedArray2[i])) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user