From 9b8727a63a7cbc8a35b62ab63ef44f9fda3ca449 Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Thu, 19 Jun 2025 15:04:29 +0900 Subject: [PATCH] =?UTF-8?q?QPolygon=20=EA=B8=B0=EB=B3=B8=20=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80(isMultipleOf45)=20-=20polygon?= =?UTF-8?q?=EC=9D=B4=20=EC=9D=B4=EB=A3=A8=EB=8A=94=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?=EA=B0=81=EB=8F=84=EA=B0=80=2045=EB=8F=84=EC=9D=98=20=EB=B0=B0?= =?UTF-8?q?=EC=88=98=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=BB=AC=EB=9F=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/fabric/QPolygon.js | 18 ++++++++++++++++++ src/hooks/usePolygon.js | 20 -------------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/components/fabric/QPolygon.js b/src/components/fabric/QPolygon.js index def5f45e..0315ac76 100644 --- a/src/components/fabric/QPolygon.js +++ b/src/components/fabric/QPolygon.js @@ -210,8 +210,26 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, { line.startPoint = point line.endPoint = nextPoint this.lines.push(line) + this.calculateDegree() }) }, + calculateDegree() { + const degrees = [] + // polygon.lines를 순회하며 각도를 구해 출력 + this.lines.forEach((line, idx) => { + const dx = line.x2 - line.x1 + const dy = line.y2 - line.y1 + const rad = Math.atan2(dy, dx) + const degree = (rad * 180) / Math.PI + degrees.push(degree) + }) + + function isMultipleOf45(degree, epsilon = 1) { + return Math.abs(degree % 45) <= epsilon || Math.abs((degree % 45) - 45) <= epsilon + } + + this.isMultipleOf45 = degrees.every((degree) => isMultipleOf45(degree)) + }, /** * 보조선 그리기 diff --git a/src/hooks/usePolygon.js b/src/hooks/usePolygon.js index 5ceae5f1..b83d4ac4 100644 --- a/src/hooks/usePolygon.js +++ b/src/hooks/usePolygon.js @@ -1162,8 +1162,6 @@ export const usePolygon = () => { pitch: pitch, }) - roof.isMultipleOf45 = calculateDegree(roof) - //allLines중 생성된 roof와 관련있는 line을 찾는다. const roofLines = [...polygonLines, ...polygon.innerLines].filter((line) => { @@ -1210,24 +1208,6 @@ export const usePolygon = () => { canvas.discardActiveObject() } - const calculateDegree = (polygon) => { - const degrees = [] - // polygon.lines를 순회하며 각도를 구해 출력 - polygon.lines.forEach((line, idx) => { - const dx = line.x2 - line.x1 - const dy = line.y2 - line.y1 - const rad = Math.atan2(dy, dx) - const degree = (rad * 180) / Math.PI - degrees.push(degree) - }) - - function isMultipleOf45(degree, epsilon = 1) { - return Math.abs(degree % 45) <= epsilon || Math.abs((degree % 45) - 45) <= epsilon - } - - return degrees.every((degree) => isMultipleOf45(degree)) - } - const getSplitRoofsPoints = (allLines) => { // ==== Utility functions ====