polygonLines중 intersection 포인트가 있는 경우 처리 추가
This commit is contained in:
parent
78258fc9c1
commit
14764d295c
@ -869,14 +869,15 @@ export const usePolygon = () => {
|
|||||||
|
|
||||||
const divideLines = polygonLines.filter((line) => line.intersections?.length > 0)
|
const divideLines = polygonLines.filter((line) => line.intersections?.length > 0)
|
||||||
let newLines = []
|
let newLines = []
|
||||||
|
polygonLines = polygonLines.filter((line) => !line.intersections || line.intersections.length === 0)
|
||||||
divideLines.forEach((line) => {
|
for (let i = divideLines.length - 1; i >= 0; i--) {
|
||||||
|
const line = divideLines[i]
|
||||||
const { intersections, startPoint, endPoint } = line
|
const { intersections, startPoint, endPoint } = line
|
||||||
|
|
||||||
if (intersections.length === 1) {
|
if (intersections.length === 1) {
|
||||||
// 한 점만 교차하는 경우
|
|
||||||
const newLinePoint1 = [line.x1, line.y1, intersections[0].x, intersections[0].y]
|
const newLinePoint1 = [line.x1, line.y1, intersections[0].x, intersections[0].y]
|
||||||
const newLinePoint2 = [intersections[0].x, intersections[0].y, line.x2, line.y2]
|
const newLinePoint2 = [intersections[0].x, intersections[0].y, line.x2, line.y2]
|
||||||
|
|
||||||
const newLine1 = new QLine(newLinePoint1, {
|
const newLine1 = new QLine(newLinePoint1, {
|
||||||
stroke: 'blue',
|
stroke: 'blue',
|
||||||
strokeWidth: 3,
|
strokeWidth: 3,
|
||||||
@ -891,28 +892,27 @@ export const usePolygon = () => {
|
|||||||
attributes: line.attributes,
|
attributes: line.attributes,
|
||||||
name: 'newLine',
|
name: 'newLine',
|
||||||
})
|
})
|
||||||
|
|
||||||
newLine1.attributes = {
|
newLine1.attributes = {
|
||||||
...line.attributes,
|
...line.attributes,
|
||||||
planeSize: Math.round(Math.sqrt(Math.pow(newLine1.x1 - newLine1.x2, 2) + Math.pow(newLine1.y1 - newLine1.y2, 2))) * 10,
|
planeSize: Math.round(Math.hypot(newLine1.x1 - newLine1.x2, newLine1.y1 - newLine1.y2)) * 10,
|
||||||
actualSize: Math.round(Math.sqrt(Math.pow(newLine1.x1 - newLine1.x2, 2) + Math.pow(newLine1.y1 - newLine1.y2, 2))) * 10,
|
actualSize: Math.round(Math.hypot(newLine1.x1 - newLine1.x2, newLine1.y1 - newLine1.y2)) * 10,
|
||||||
}
|
}
|
||||||
newLine2.attributes = {
|
newLine2.attributes = {
|
||||||
...line.attributes,
|
...line.attributes,
|
||||||
planeSize: Math.round(Math.sqrt(Math.pow(newLine2.x1 - newLine2.x2, 2) + Math.pow(newLine2.y1 - newLine2.y2, 2))) * 10,
|
planeSize: Math.round(Math.hypot(newLine2.x1 - newLine2.x2, newLine2.y1 - newLine2.y2)) * 10,
|
||||||
actualSize: Math.round(Math.sqrt(Math.pow(newLine2.x1 - newLine2.x2, 2) + Math.pow(newLine2.y1 - newLine2.y2, 2))) * 10,
|
actualSize: Math.round(Math.hypot(newLine2.x1 - newLine2.x2, newLine2.y1 - newLine2.y2)) * 10,
|
||||||
}
|
}
|
||||||
newLines.push(newLine1)
|
|
||||||
newLines.push(newLine2)
|
|
||||||
} else {
|
|
||||||
// 두 점 이상 교차하는 경우
|
|
||||||
//1. intersections중에 startPoint와 가장 가까운 점을 찾는다.
|
|
||||||
//2. 가장 가까운 점을 기준으로 line을 나눈다.
|
|
||||||
|
|
||||||
|
newLines.push(newLine1, newLine2)
|
||||||
|
divideLines.splice(i, 1) // 기존 line 제거
|
||||||
|
} else {
|
||||||
let currentPoint = startPoint
|
let currentPoint = startPoint
|
||||||
|
|
||||||
while (intersections.length !== 0) {
|
while (intersections.length !== 0) {
|
||||||
const minDistancePoint = findAndRemoveClosestPoint(currentPoint, intersections)
|
const minDistancePoint = findAndRemoveClosestPoint(currentPoint, intersections)
|
||||||
const newLinePoint = [currentPoint.x, currentPoint.y, minDistancePoint.x, minDistancePoint.y]
|
const newLinePoint = [currentPoint.x, currentPoint.y, minDistancePoint.x, minDistancePoint.y]
|
||||||
|
|
||||||
const newLine = new QLine(newLinePoint, {
|
const newLine = new QLine(newLinePoint, {
|
||||||
stroke: 'blue',
|
stroke: 'blue',
|
||||||
strokeWidth: 3,
|
strokeWidth: 3,
|
||||||
@ -920,11 +920,13 @@ export const usePolygon = () => {
|
|||||||
attributes: line.attributes,
|
attributes: line.attributes,
|
||||||
name: 'newLine',
|
name: 'newLine',
|
||||||
})
|
})
|
||||||
|
|
||||||
newLine.attributes = {
|
newLine.attributes = {
|
||||||
...line.attributes,
|
...line.attributes,
|
||||||
planeSize: Math.round(Math.sqrt(Math.pow(newLine.x1 - newLine.x2, 2) + Math.pow(newLine.y1 - newLine.y2, 2))) * 10,
|
planeSize: Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10,
|
||||||
actualSize: Math.round(Math.sqrt(Math.pow(newLine.x1 - newLine.x2, 2) + Math.pow(newLine.y1 - newLine.y2, 2))) * 10,
|
actualSize: Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
newLines.push(newLine)
|
newLines.push(newLine)
|
||||||
currentPoint = minDistancePoint
|
currentPoint = minDistancePoint
|
||||||
}
|
}
|
||||||
@ -939,18 +941,18 @@ export const usePolygon = () => {
|
|||||||
})
|
})
|
||||||
newLine.attributes = {
|
newLine.attributes = {
|
||||||
...line.attributes,
|
...line.attributes,
|
||||||
planeSize: Math.round(Math.sqrt(Math.pow(newLine.x1 - newLine.x2, 2) + Math.pow(newLine.y1 - newLine.y2, 2))) * 10,
|
planeSize: Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10,
|
||||||
actualSize: Math.round(Math.sqrt(Math.pow(newLine.x1 - newLine.x2, 2) + Math.pow(newLine.y1 - newLine.y2, 2))) * 10,
|
actualSize: Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
newLines.push(newLine)
|
newLines.push(newLine)
|
||||||
|
divideLines.splice(i, 1) // 기존 line 제거
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
//polygonLines에서 divideLines를 제거하고 newLines를 추가한다.
|
//polygonLines에서 divideLines를 제거하고 newLines를 추가한다.
|
||||||
newLines = newLines.filter((line) => !(Math.abs(line.startPoint.x - line.endPoint.x) < 1 && Math.abs(line.startPoint.y - line.endPoint.y) < 1))
|
newLines = newLines.filter((line) => !(Math.abs(line.startPoint.x - line.endPoint.x) < 1 && Math.abs(line.startPoint.y - line.endPoint.y) < 1))
|
||||||
|
|
||||||
polygonLines = polygonLines.filter((line) => !line.intersections || line.intersections.length === 0)
|
|
||||||
|
|
||||||
polygonLines = [...polygonLines, ...newLines]
|
polygonLines = [...polygonLines, ...newLines]
|
||||||
|
|
||||||
let allLines = [...polygonLines, ...innerLines]
|
let allLines = [...polygonLines, ...innerLines]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user