diff --git a/src/hooks/usePolygon.js b/src/hooks/usePolygon.js index 43a78eae..93659a08 100644 --- a/src/hooks/usePolygon.js +++ b/src/hooks/usePolygon.js @@ -754,7 +754,7 @@ export const usePolygon = () => { } const splitPolygonWithLines = (polygon) => { - polygon.set({ visible: false }) + // polygon.set({ visible: false }) let innerLines = [...polygon.innerLines] /*// innerLine이 세팅이 안되어있는경우 찾아서 세팅한다. @@ -934,8 +934,9 @@ export const usePolygon = () => { }) //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)) polygonLines = polygonLines.filter((line) => line.intersections?.length === 0) - + const originPolygonLines = [...polygonLines] polygonLines = [...polygonLines, ...newLines] let allLines = [...polygonLines, ...innerLines] @@ -1045,6 +1046,10 @@ export const usePolygon = () => { }) }) + if (startLines.length === 0) { + startLines = originPolygonLines + } + // 나눠서 중복 제거된 roof return const newRoofs = getSplitRoofsPoints(startLines, allLines, innerLines, uniquePoints) diff --git a/src/util/canvas-util.js b/src/util/canvas-util.js index 1146afa7..9eb6e0e5 100644 --- a/src/util/canvas-util.js +++ b/src/util/canvas-util.js @@ -515,26 +515,31 @@ export const sortedPointLessEightPoint = (points) => { * @param line * @param point * @returns {boolean} + * @param epsilon */ // 직선의 방정식. // 방정식은 ax + by + c = 0이며, 점의 좌표를 대입하여 계산된 값은 직선과 점 사이의 관계를 나타낸다. -export function isPointOnLine({ x1, y1, x2, y2 }, { x, y }) { - /*const a = line.y2 - line.y1 +export function isPointOnLine({ x1, y1, x2, y2 }, { x, y }, epsilon = 2) { + const a = y2 - y1 + const b = x1 - x2 + const c = x2 * y1 - x1 * y2 + return Math.abs(a * x + b * y + c) < 1000 + /*/!*const a = line.y2 - line.y1 const b = line.x1 - line.x2 const c = line.x2 * line.y1 - line.x1 * line.y2 const result = Math.abs(a * point.x + b * point.y + c) / 100 // 점이 선 위에 있는지 확인 - return result <= 10*/ + return result <= 10*!/ // 직선 방정식 만족 여부 확인 const crossProduct = (y - y1) * (x2 - x1) - (x - x1) * (y2 - y1) - if (Math.abs(crossProduct) > 5) return false // 작은 오차 허용 + if (Math.abs(crossProduct) > 10) return false // 작은 오차 허용 // 점이 선분의 범위 내에 있는지 확인 const withinXRange = Math.min(x1, x2) <= x && x <= Math.max(x1, x2) const withinYRange = Math.min(y1, y2) <= y && y <= Math.max(y1, y2) - return withinXRange && withinYRange + return withinXRange && withinYRange*/ } /** * 점과 가까운 line 찾기