Compare commits

..

No commits in common. "149842547cae94eeb6c6198621d35106648a6326" and "d35230cb9bb6b91f99942956d6d82c1b9dde769c" have entirely different histories.

2 changed files with 15 additions and 56 deletions

View File

@ -1,7 +1,14 @@
import { ANGLE_TYPE, canvasState, currentAngleTypeSelector, pitchTextSelector } from '@/store/canvasAtom'
import { useRecoilValue } from 'recoil'
import { fabric } from 'fabric'
import { findAndRemoveClosestPoint, getDegreeByChon, getDegreeInOrientation, isPointOnLine } from '@/util/canvas-util'
import {
distanceBetweenPoints,
findAndRemoveClosestPoint,
getDegreeByChon,
getDegreeInOrientation,
isPointOnLine,
toFixedWithoutRounding,
} from '@/util/canvas-util'
import { QPolygon } from '@/components/fabric/QPolygon'
import { isSamePoint, removeDuplicatePolygons } from '@/util/qpolygon-utils'
import { flowDisplaySelector } from '@/store/settingAtom'
@ -1066,14 +1073,8 @@ export const usePolygon = () => {
)
})
allLines = allLines.filter((line) => {
return Math.abs(line.startPoint.x - line.endPoint.x) > 2 || Math.abs(line.startPoint.y - line.endPoint.y) > 2
})
// 나눠서 중복 제거된 roof return
let newRoofs = getSplitRoofsPoints(allLines)
newRoofs = newRoofs.filter((roof) => roof.length !== 0)
const newRoofs = getSplitRoofsPoints(allLines)
newRoofs.forEach((roofPoint, index) => {
let defense, pitch
@ -1211,45 +1212,10 @@ export const usePolygon = () => {
}
const getSplitRoofsPoints = (allLines) => {
// 모든 좌표점들을 수집
const allPoints = []
allLines.forEach((line, lineIndex) => {
allPoints.push({ point: line.startPoint, lineIndex, pointType: 'start' })
allPoints.push({ point: line.endPoint, lineIndex, pointType: 'end' })
})
// X 좌표 통일
for (let i = 0; i < allPoints.length; i++) {
for (let j = i + 1; j < allPoints.length; j++) {
const point1 = allPoints[i].point
const point2 = allPoints[j].point
if (Math.abs(point1.x - point2.x) < 1) {
const maxX = Math.max(point1.x, point2.x)
point1.x = maxX
point2.x = maxX
}
}
}
// Y 좌표 통일
for (let i = 0; i < allPoints.length; i++) {
for (let j = i + 1; j < allPoints.length; j++) {
const point1 = allPoints[i].point
const point2 = allPoints[j].point
if (Math.abs(point1.y - point2.y) < 1) {
const maxY = Math.max(point1.y, point2.y)
point1.y = maxY
point2.y = maxY
}
}
}
// ==== Utility functions ====
function isSamePoint(p1, p2, epsilon = 1) {
return Math.abs(p1.x - p2.x) <= epsilon && Math.abs(p1.y - p2.y) <= epsilon
return Math.abs(p1.x - p2.x) <= 2 && Math.abs(p1.y - p2.y) <= 2
}
function normalizePoint(p, epsilon = 1) {
@ -1275,7 +1241,6 @@ export const usePolygon = () => {
const startKey = pointToKey(start, epsilon)
return (graph[startKey] || []).some((neighbor) => isSamePoint(neighbor.point, end, epsilon))
}
// ==== Dijkstra pathfinding ====
function findShortestPath(start, end, graph, epsilon = 1) {
@ -1364,15 +1329,11 @@ export const usePolygon = () => {
}
const startPoint = { ...line.startPoint } // 시작점
let arrivalPoint = { ...line.endPoint } // 도착점
roofs.push(getPath(startPoint, arrivalPoint, graph))
})
return removeDuplicatePolygons(
roofs.filter((roof) => roof.length < 100),
allLines.some((line) => line.name === 'auxiliaryLine'),
)
return removeDuplicatePolygons(roofs.filter((roof) => roof.length < 100))
}
const splitPolygonWithSeparate = (separates) => {

View File

@ -292,7 +292,7 @@ function arePolygonsEqual(polygon1, polygon2) {
return normalizedPolygon1.every((point, index) => arePointsEqual(point, normalizedPolygon2[index]))
}
export function removeDuplicatePolygons(polygons, hasAuxiliaryLine = false) {
export function removeDuplicatePolygons(polygons) {
let uniquePolygons = []
// x가 전부 같거나, y가 전부 같은 경우 제거
@ -303,11 +303,9 @@ export function removeDuplicatePolygons(polygons, hasAuxiliaryLine = false) {
}
})
if (!hasAuxiliaryLine) {
uniquePolygons = uniquePolygons.filter((polygon) => {
return isValidPoints(polygon)
})
}
uniquePolygons = uniquePolygons.filter((polygon) => {
return isValidPoints(polygon)
})
return uniquePolygons
}