From 6a5ba732741fa60bce52389db16cfe2b5e155ca1 Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Wed, 30 Jul 2025 18:01:45 +0900 Subject: [PATCH] =?UTF-8?q?degree=20=EA=B3=84=EC=82=B0=EC=8B=9D=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/util/canvas-util.js | 50 ++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/util/canvas-util.js b/src/util/canvas-util.js index d012f837..0af492a1 100644 --- a/src/util/canvas-util.js +++ b/src/util/canvas-util.js @@ -1004,24 +1004,44 @@ export const getAllRelatedObjects = (id, canvas) => { return result } -// 모듈,회로 구성에서 사용하는 degree 범위 별 값 +// degree 범위별로 정확한 각도를 return하는 함수 export const getDegreeInOrientation = (degree) => { - if (degree === 180 || degree === -180) { - return 180 - } - if (degree >= 180 || degree < -180) { - return 0 - } - if (degree % 15 === 0) return degree + // 범위를 벗어나는 경우 처리 + if (degree > 180 || degree < -180) return 0 - let value = Math.floor(degree / 15) - const remain = ((degree / 15) % 1).toFixed(5) + // 범위별 각도 매핑 테이블 + const degreeRanges = [ + { min: 0, max: 6, value: 0 }, + { min: 7, max: 21, value: 15 }, + { min: 22, max: 36, value: 30 }, + { min: 37, max: 51, value: 45 }, + { min: 52, max: 66, value: 60 }, + { min: 67, max: 81, value: 75 }, + { min: 82, max: 96, value: 90 }, + { min: 97, max: 111, value: 105 }, + { min: 112, max: 126, value: 120 }, + { min: 127, max: 141, value: 135 }, + { min: 142, max: 156, value: 150 }, + { min: 157, max: 171, value: 165 }, + { min: 172, max: 180, value: 180 }, + { min: -180, max: -172, value: 180 }, + { min: -171, max: -157, value: -165 }, + { min: -156, max: -142, value: -150 }, + { min: -141, max: -127, value: -135 }, + { min: -126, max: -112, value: -120 }, + { min: -111, max: -97, value: -105 }, + { min: -96, max: -82, value: -90 }, + { min: -81, max: -67, value: -75 }, + { min: -66, max: -52, value: -60 }, + { min: -51, max: -37, value: -45 }, + { min: -36, max: -22, value: -30 }, + { min: -21, max: -7, value: -15 }, + { min: -6, max: 0, value: 0 } + ] - if (remain > 0.4) { - value++ - } - - return value * 15 + // 해당 범위에 맞는 값 찾기 + const range = degreeRanges.find(range => degree >= range.min && degree <= range.max) + return range ? range.value : degree } export function findAndRemoveClosestPoint(targetPoint, points) {