diff --git a/src/hooks/usePolygon.js b/src/hooks/usePolygon.js index 8822fd5f..bc63c50c 100644 --- a/src/hooks/usePolygon.js +++ b/src/hooks/usePolygon.js @@ -1,19 +1,7 @@ -import { - ANGLE_TYPE, - canvasState, - currentAngleTypeSelector, - globalPitchState, - pitchTextSelector, -} from '@/store/canvasAtom' +import { ANGLE_TYPE, canvasState, currentAngleTypeSelector, globalPitchState, pitchTextSelector } from '@/store/canvasAtom' import { useRecoilValue } from 'recoil' import { fabric } from 'fabric' -import { - calculateIntersection, - findAndRemoveClosestPoint, - getDegreeByChon, - getDegreeInOrientation, - isPointOnLine, -} from '@/util/canvas-util' +import { calculateIntersection, findAndRemoveClosestPoint, getDegreeByChon, getDegreeInOrientation, isPointOnLine } from '@/util/canvas-util' import { QPolygon } from '@/components/fabric/QPolygon' import { isSamePoint, removeDuplicatePolygons } from '@/util/qpolygon-utils' import { basicSettingState, flowDisplaySelector } from '@/store/settingAtom' @@ -1392,6 +1380,8 @@ export const usePolygon = () => { // 나눠서 중복 제거된 roof return let newRoofs = getSplitRoofsPoints(allLines) + const createdRoofs = [] + newRoofs = newRoofs.filter((roof) => roof.length !== 0) newRoofs.forEach((roofPoint, index) => { let defense, pitch @@ -1634,8 +1624,8 @@ export const usePolygon = () => { }) }) - canvas.add(roof) - addLengthText(roof) + // canvas.add(roof) + createdRoofs.push(roof) canvas.remove(polygon) canvas.renderAll() }) @@ -1645,6 +1635,11 @@ export const usePolygon = () => { auxiliaryLines.forEach((line) => { canvas.remove(line) }) + + createdRoofs.forEach((roof) => { + canvas.add(roof) + }) + canvas.renderAll() canvas.discardActiveObject() } @@ -1970,38 +1965,6 @@ export const usePolygon = () => { canvas.renderAll() } - /** - * 폴리곤의 라인 길이가 10 이하로 차이나는 경우 작은 값으로 통일 - * @param polygon - */ - const unifyLineLengths = (polygon) => { - if (!polygon.lines || polygon.lines.length === 0) { - return - } - - const lines = polygon.lines - - for (let i = 0; i < lines.length; i++) { - for (let j = i + 1; j < lines.length; j++) { - const length1 = lines[i].getLength() - const length2 = lines[j].getLength() - const diff = Math.abs(length1 - length2) - - if (diff > 0 && diff <= 10) { - const minLength = Math.min(length1, length2) - if (length1 > length2) { - lines[i].setLengthByValue(minLength) - } else { - lines[j].setLengthByValue(minLength) - } - } - } - } - - addLengthText(polygon) - canvas.renderAll() - } - /** * 폴리곤의 라인 속성을 복도치수, 실제치수에 따라 actualSize 설정 * @param polygon @@ -2010,7 +1973,23 @@ export const usePolygon = () => { if (!polygon.lines || polygon.lines.length === 0 || !polygon.roofMaterial) { return } - unifyLineLengths(polygon) + + // createdRoofs들의 모든 lines를 확인해서 length값이 1이하인 차이가 있으면 통일 시킨다. + const allRoofs = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.ROOF) + const allRoofLines = allRoofs.flatMap((roof) => roof.lines) + for (let i = 0; i < allRoofLines.length; i++) { + for (let j = i + 1; j < allRoofLines.length; j++) { + const line1 = allRoofLines[i] + const line2 = allRoofLines[j] + const diff = Math.abs(line1.length - line2.length) + if (diff > 0 && diff <= 1) { + const minLength = Math.min(line1.length, line2.length) + line1.setLengthByValue(minLength * 10) + line2.setLengthByValue(minLength * 10) + } + } + } + polygon.lines.forEach((line) => { setActualSize(line, polygon.direction, +polygon.roofMaterial?.pitch) }) @@ -2027,6 +2006,5 @@ export const usePolygon = () => { splitPolygonWithLines, splitPolygonWithSeparate, setPolygonLinesActualSize, - unifyLineLengths, } }