보조선 작성 수정
This commit is contained in:
parent
6a1416a7c6
commit
57fbcea3a1
@ -22,6 +22,7 @@ import { useSwal } from '@/hooks/useSwal'
|
||||
import { booleanPointInPolygon } from '@turf/turf'
|
||||
import { usePopup } from '@/hooks/usePopup'
|
||||
import { calculateAngle } from '@/util/qpolygon-utils'
|
||||
import { QPolygon } from '@/components/fabric/QPolygon'
|
||||
|
||||
// 보조선 작성
|
||||
export function useAuxiliaryDrawing(id) {
|
||||
@ -742,15 +743,38 @@ export function useAuxiliaryDrawing(id) {
|
||||
}
|
||||
|
||||
const roofBases = canvas.getObjects().filter((obj) => obj.name === 'roofBase')
|
||||
const innerLines = [...lineHistory.current]
|
||||
|
||||
//lineHistory.current에 있는 선들 중 startPoint와 endPoint가 겹치는 line은 제거
|
||||
// 겹치는 선 하나는 canvas에서 제거한다.
|
||||
|
||||
const tempLines = [...lineHistory.current]
|
||||
lineHistory.current = []
|
||||
tempLines.forEach((line) => {
|
||||
if (
|
||||
lineHistory.current.some(
|
||||
(history) =>
|
||||
JSON.stringify(history.startPoint) === JSON.stringify(line.startPoint) &&
|
||||
JSON.stringify(history.endPoint) === JSON.stringify(line.endPoint),
|
||||
)
|
||||
) {
|
||||
canvas.remove(line)
|
||||
return
|
||||
}
|
||||
|
||||
lineHistory.current.push(line)
|
||||
})
|
||||
|
||||
const innerLines = lineHistory.current
|
||||
|
||||
roofBases.forEach((roofBase) => {
|
||||
const tempPolygonPoints = [...roofBase.points].map((obj) => {
|
||||
return { x: Math.round(obj.x), y: Math.round(obj.y) }
|
||||
})
|
||||
const roofInnerLines = innerLines.filter((line) => {
|
||||
const turfPolygon = polygonToTurfPolygon(roofBase)
|
||||
|
||||
// innerLines의 두 점이 모두 polygon 안에 있는지 확인
|
||||
const inPolygon1 = booleanPointInPolygon([line.x1, line.y1], turfPolygon)
|
||||
const inPolygon2 = booleanPointInPolygon([line.x2, line.y2], turfPolygon)
|
||||
const inPolygon1 =
|
||||
tempPolygonPoints.some((point) => point.x === line.x1 && point.y === line.y1) || roofBase.inPolygon({ x: line.x1, y: line.y1 })
|
||||
const inPolygon2 =
|
||||
tempPolygonPoints.some((point) => point.x === line.x2 && point.y === line.y2) || roofBase.inPolygon({ x: line.x2, y: line.y2 })
|
||||
|
||||
if (inPolygon1 && inPolygon2) {
|
||||
line.attributes = { ...line.attributes, roofId: roofBase.id }
|
||||
@ -759,6 +783,8 @@ export function useAuxiliaryDrawing(id) {
|
||||
})
|
||||
|
||||
roofBase.innerLines = [...roofInnerLines]
|
||||
|
||||
canvas.renderAll()
|
||||
})
|
||||
|
||||
closePopup(id)
|
||||
|
||||
@ -1034,9 +1034,10 @@ export const splitPolygonWithLines = (polygon) => {
|
||||
const routes = []
|
||||
|
||||
// 시작점은 시작 hip라인의 출발점
|
||||
const startPoint = point
|
||||
const startPoint = { x: Math.round(point.x), y: Math.round(point.y) }
|
||||
// 도착점은 마지막 hip라인의 끝나는 점
|
||||
const endPoint = polygon.points[(index + 1) % polygon.points.length]
|
||||
let endPoint = polygon.points[(index + 1) % polygon.points.length]
|
||||
endPoint = { x: Math.round(endPoint.x), y: Math.round(endPoint.y) }
|
||||
|
||||
const startLine = allLines.find((line) => line.startPoint.x === startPoint.x && line.startPoint.y === startPoint.y)
|
||||
const endLine = allLines.find((line) => line.startPoint.x === endPoint.x && line.startPoint.y === endPoint.y)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user