From 46710533b5e52eb5feab660128b482188a1cda45 Mon Sep 17 00:00:00 2001 From: Jaeyoung Lee Date: Wed, 24 Sep 2025 10:46:36 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8F=99=EC=84=A0=EC=9D=B4=EB=8F=99=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/roofcover/useMovementSetting.js | 123 +++++++++++++--------- src/util/qpolygon-utils.js | 5 +- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/src/hooks/roofcover/useMovementSetting.js b/src/hooks/roofcover/useMovementSetting.js index e1fa2650..7d1d326a 100644 --- a/src/hooks/roofcover/useMovementSetting.js +++ b/src/hooks/roofcover/useMovementSetting.js @@ -411,6 +411,35 @@ export function useMovementSetting(id) { targetBaseLines.sort((a, b) => a.distance - b.distance) targetBaseLines = targetBaseLines.filter((line) => line.distance === targetBaseLines[0].distance) + + if (isGableRoof) { + const zeroLengthLines = targetBaseLines.filter( + (line) => Math.sqrt(Math.pow(line.line.x2 - line.line.x1, 2) + Math.pow(line.line.y2 - line.line.y1, 2)) < 1, + ) + if (zeroLengthLines.length > 0) { + zeroLengthLines.forEach((line) => { + const findLine = line.line + const findCoords = [ + { x: findLine.x1, y: findLine.y1 }, + { x: findLine.x2, y: findLine.y2 }, + ] + wall.baseLines + .filter((baseLine) => { + return findCoords.some( + (coord) => + (Math.abs(coord.x - baseLine.x1) < 0.1 && Math.abs(coord.y - baseLine.y1) < 0.1) || + (Math.abs(coord.x - baseLine.x2) < 0.1 && Math.abs(coord.y - baseLine.y2) < 0.1), + ) + }) + .forEach((baseLine) => { + const isAlready = targetBaseLines.find((target) => target.line === baseLine) + if (isAlready) return + targetBaseLines.push({ line: baseLine, distance: targetBaseLines[0].distance }) + }) + }) + } + } + let value if (typeRef.current === TYPE.FLOW_LINE) { value = @@ -445,58 +474,56 @@ export function useMovementSetting(id) { } } value = value.div(10) - targetBaseLines.forEach((target) => { - const currentLine = target.line - const index = baseLines.findIndex((line) => line === currentLine) - const nextLine = baseLines[(index + 1) % baseLines.length] - const prevLine = baseLines[(index - 1 + baseLines.length) % baseLines.length] - let deltaX = 0 - let deltaY = 0 - if (currentLine.y1 === currentLine.y2) { - deltaY = value.toNumber() - } else { - deltaX = value.toNumber() - } + targetBaseLines + .filter((line) => Math.sqrt(Math.pow(line.line.x2 - line.line.x1, 2) + Math.pow(line.line.y2 - line.line.y1, 2)) >= 1) + .forEach((target) => { + const currentLine = target.line + const index = baseLines.findIndex((line) => line === currentLine) + const nextLine = baseLines[(index + 1) % baseLines.length] + const prevLine = baseLines[(index - 1 + baseLines.length) % baseLines.length] + let deltaX = 0 + let deltaY = 0 + if (currentLine.y1 === currentLine.y2) { + deltaY = value.toNumber() + } else { + deltaX = value.toNumber() + } - currentLine.set({ - x1: currentLine.x1 + deltaX, - y1: currentLine.y1 + deltaY, - x2: currentLine.x2 + deltaX, - y2: currentLine.y2 + deltaY, - startPoint: { x: currentLine.x1 + deltaX, y: currentLine.y1 + deltaY }, - endPoint: { x: currentLine.x2 + deltaX, y: currentLine.y2 + deltaY }, - }) - const currentSize = calcLinePlaneSize({ - x1: currentLine.x1, - y1: currentLine.y1, - x2: currentLine.x2, - y2: currentLine.y2, - }) - currentLine.attributes.planeSize = currentSize - currentLine.attributes.actualSize = currentSize + currentLine.set({ + x1: currentLine.x1 + deltaX, + y1: currentLine.y1 + deltaY, + x2: currentLine.x2 + deltaX, + y2: currentLine.y2 + deltaY, + startPoint: { x: currentLine.x1 + deltaX, y: currentLine.y1 + deltaY }, + endPoint: { x: currentLine.x2 + deltaX, y: currentLine.y2 + deltaY }, + }) + const currentSize = calcLinePlaneSize({ + x1: currentLine.x1, + y1: currentLine.y1, + x2: currentLine.x2, + y2: currentLine.y2, + }) + currentLine.attributes.planeSize = currentSize + currentLine.attributes.actualSize = currentSize - const nextOldActualSize = nextLine.attributes.planeSize - nextLine.set({ - x1: nextLine.x1 + deltaX, - y1: nextLine.y1 + deltaY, - startPoint: { x: nextLine.x1 + deltaX, y: nextLine.y1 + deltaY }, - }) - const nextSize = calcLinePlaneSize({ x1: nextLine.x1, y1: nextLine.y1, x2: nextLine.x2, y2: nextLine.y2 }) - nextLine.attributes.planeSize = nextSize - nextLine.attributes.actualSize = nextSize + nextLine.set({ + x1: currentLine.x2, + y1: currentLine.y2, + startPoint: { x: currentLine.x2, y: currentLine.y2 }, + }) + const nextSize = calcLinePlaneSize({ x1: nextLine.x1, y1: nextLine.y1, x2: nextLine.x2, y2: nextLine.y2 }) + nextLine.attributes.planeSize = nextSize + nextLine.attributes.actualSize = nextSize - const prevOldActualSize = prevLine.attributes.planeSize - prevLine.set({ - x2: prevLine.x2 + deltaX, - y2: prevLine.y2 + deltaY, - endPoint: { x: prevLine.x2 + deltaX, y: prevLine.y2 + deltaY }, + prevLine.set({ + x2: currentLine.x1, + y2: currentLine.y1, + endPoint: { x: currentLine.x1, y: currentLine.y1 }, + }) + const prevSize = calcLinePlaneSize({ x1: prevLine.x1, y1: prevLine.y1, x2: prevLine.x2, y2: prevLine.y2 }) + prevLine.attributes.planeSize = prevSize + prevLine.attributes.actualSize = prevSize }) - const prevSize = calcLinePlaneSize({ x1: prevLine.x1, y1: prevLine.y1, x2: prevLine.x2, y2: prevLine.y2 }) - prevLine.attributes.planeSize = prevSize - prevLine.attributes.actualSize = prevSize - - canvas.renderAll() - }) roof.drawHelpLine() initEvent() diff --git a/src/util/qpolygon-utils.js b/src/util/qpolygon-utils.js index e29db805..7eed8fa9 100644 --- a/src/util/qpolygon-utils.js +++ b/src/util/qpolygon-utils.js @@ -600,9 +600,10 @@ export const drawGableRoof = (roofId, canvas, textMode) => { } }) - let currentRoof = intersectRoofLines.find((roof) => isPointOnLineNew(roof.roofLine, roof.intersect)) + intersectRoofLines.sort((a, b) => a.length - b.length) + let currentRoof = intersectRoofLines.find((roof) => isPointOnLineNew(roof.roofLine, roof.intersect) && roof.length - offset < 0.1) if (!currentRoof) { - currentRoof = intersectRoofLines.sort((a, b) => a.length - b.length)[0] + currentRoof = intersectRoofLines[0] } let startPoint, endPoint