diff --git a/src/hooks/usePolygon.js b/src/hooks/usePolygon.js index e846760b..b47de91a 100644 --- a/src/hooks/usePolygon.js +++ b/src/hooks/usePolygon.js @@ -1,7 +1,7 @@ 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, isPointOnLine } from '@/util/canvas-util' import { QPolygon } from '@/components/fabric/QPolygon' import { isSamePoint, removeDuplicatePolygons } from '@/util/qpolygon-utils' import { basicSettingState, flowDisplaySelector } from '@/store/settingAtom' @@ -344,6 +344,7 @@ export const usePolygon = () => { } //arrow의 compass 값으로 방향 글자 설정 필요 + // moduleCompass 각도와 direction(지붕면 방향)에 따라 한자 방위 텍스트 매핑 const drawDirectionStringToArrow2 = (polygon, showDirectionText) => { let { direction, surfaceCompass, moduleCompass, arrow } = polygon if (moduleCompass === null || moduleCompass === undefined) { @@ -371,153 +372,114 @@ export const usePolygon = () => { let text = '' - let compassType = (375 + getDegreeInOrientation(moduleCompass)) / 15 + // moduleCompass 각도와 direction에 따른 한자 방위 매핑 + // direction: south(↓), west(←), north(↑), east(→) + // 각도 범위별 매핑 테이블 (사진 기준) + const getDirectionText = (angle, dir) => { + // 각도를 정규화 (-180 ~ 180 범위로) + let normalizedAngle = Number(angle) + while (normalizedAngle > 180) normalizedAngle -= 360 + while (normalizedAngle < -180) normalizedAngle += 360 - moduleCompass = -1 * moduleCompass + // 매핑 테이블: { south(↓), west(←), north(↑), east(→) } + // 각도 0: 남, 서, 북, 동 + // 각도 45: 남서, 북서, 북동, 남동 + // 각도 90: 서, 북, 동, 남 + // 각도 135: 북서, 북동, 남동, 남서 + // 각도 180: 북, 동, 남, 서 + // 각도 -45: 남동, 남서, 북서, 북동 + // 각도 -90: 동, 남, 서, 북 + // 각도 -135: 북동, 남동, 남서, 북서 - if (moduleCompass === 0 || (moduleCompass < 0 && moduleCompass >= -6)) { - compassType = 1 - } else if (moduleCompass < 0 && moduleCompass >= -21) { - compassType = 2 - } else if (moduleCompass < 0 && moduleCompass >= -36) { - compassType = 3 - } else if (moduleCompass < 0 && moduleCompass >= -51) { - compassType = 4 - } else if (moduleCompass < 0 && moduleCompass >= -66) { - compassType = 5 - } else if (moduleCompass < 0 && moduleCompass >= -81) { - compassType = 6 - } else if (moduleCompass < 0 && moduleCompass >= -96) { - compassType = 7 - } else if (moduleCompass < 0 && moduleCompass >= -111) { - compassType = 8 - } else if (moduleCompass < 0 && moduleCompass >= -126) { - compassType = 9 - } else if (moduleCompass < 0 && moduleCompass >= -141) { - compassType = 10 - } else if (moduleCompass < 0 && moduleCompass >= -156) { - compassType = 11 - } else if (moduleCompass < 0 && moduleCompass >= -171) { - compassType = 12 - } else if (Math.abs(moduleCompass) === 180) { - compassType = 13 + let mapping + // 정확한 각도 먼저 체크 + if (normalizedAngle === 0) { + mapping = { south: '南', west: '西', north: '北', east: '東' } + } else if (normalizedAngle === 45) { + mapping = { south: '南西', west: '北西', north: '北東', east: '南東' } + } else if (normalizedAngle === 90) { + mapping = { south: '西', west: '北', north: '東', east: '南' } + } else if (normalizedAngle === 135) { + mapping = { south: '北西', west: '北東', north: '南東', east: '南西' } + } else if (normalizedAngle === 180 || normalizedAngle === -180) { + mapping = { south: '北', west: '東', north: '南', east: '西' } + } else if (normalizedAngle === -45) { + mapping = { south: '南東', west: '南西', north: '北西', east: '北東' } + } else if (normalizedAngle === -90) { + mapping = { south: '東', west: '南', north: '西', east: '北' } + } else if (normalizedAngle === -135) { + mapping = { south: '北東', west: '南東', north: '南西', east: '北西' } + } + // 범위 각도 체크 + else if (normalizedAngle >= 1 && normalizedAngle <= 44) { + // 1~44: 남남서, 서북서, 북북동, 동남동 + mapping = { south: '南南西', west: '西北西', north: '北北東', east: '東南東' } + } else if (normalizedAngle >= 46 && normalizedAngle <= 89) { + // 46~89: 서남서, 북북서, 동북동, 남남동 + mapping = { south: '西南西', west: '北北西', north: '東北東', east: '南南東' } + } else if (normalizedAngle >= 91 && normalizedAngle <= 134) { + // 91~134: 서북서, 북북동, 동남동, 남남서 + mapping = { south: '西北西', west: '北北東', north: '東南東', east: '南南西' } + } else if (normalizedAngle >= 136 && normalizedAngle <= 179) { + // 136~179: 북북서, 동북동, 남남동, 서남서 + mapping = { south: '北北西', west: '東北東', north: '南南東', east: '西南西' } + } else if (normalizedAngle >= -44 && normalizedAngle <= -1) { + // -1~-44: 남남동, 서남서, 북북서, 동북동 + mapping = { south: '南南東', west: '西南西', north: '北北西', east: '東北東' } + } else if (normalizedAngle >= -89 && normalizedAngle <= -46) { + // -46~-89: 동남동, 남남서, 서북서, 북북동 + mapping = { south: '東南東', west: '南南西', north: '西北西', east: '北北東' } + } else if (normalizedAngle >= -134 && normalizedAngle <= -91) { + // -91~-134: 동북동, 남남동, 서남서, 북북서 + mapping = { south: '東北東', west: '南南東', north: '西南西', east: '北北西' } + } else if (normalizedAngle >= -179 && normalizedAngle <= -136) { + // -136~-179: 북북동, 동남동, 남남서, 서북서 + mapping = { south: '北北東', west: '東南東', north: '南南西', east: '西北西' } + } else { + // 기본값: 0도 + mapping = { south: '南', west: '西', north: '北', east: '東' } + } + + return mapping[dir] || '南' } - if ([1, 25].includes(compassType)) { - direction === 'north' ? (text = '北') : direction === 'south' ? (text = '南') : direction === 'west' ? (text = '西') : (text = '東') - } else if ([2, 3].includes(compassType)) { - direction === 'north' - ? (text = '北北東') - : direction === 'south' - ? (text = '南南西') - : direction === 'west' - ? (text = '西北西') - : (text = '東南東') - } else if ([4].includes(compassType)) { - direction === 'north' ? (text = '北東') : direction === 'south' ? (text = '南西') : direction === 'west' ? (text = '北西') : (text = '南東') - } else if ([5, 6].includes(compassType)) { - direction === 'north' - ? (text = '東北東') - : direction === 'south' - ? (text = '西南西') - : direction === 'west' - ? (text = '北北西') - : (text = '南南東') - } else if ([7].includes(compassType)) { - direction === 'north' ? (text = '東') : direction === 'south' ? (text = '西') : direction === 'west' ? (text = '北') : (text = '南') - } else if ([8, 9].includes(compassType)) { - direction === 'north' - ? (text = '東南東') - : direction === 'south' - ? (text = '西北西') - : direction === 'west' - ? (text = '北北東') - : (text = '南南西') - } else if ([10].includes(compassType)) { - direction === 'north' ? (text = '南東') : direction === 'south' ? (text = '北西') : direction === 'west' ? (text = '北東') : (text = '南西') - } else if ([11, 12].includes(compassType)) { - direction === 'north' - ? (text = '南南東') - : direction === 'south' - ? (text = '北北西') - : direction === 'west' - ? (text = '東北東') - : (text = '西南西') - } else if ([13].includes(compassType)) { - direction === 'north' ? (text = '南') : direction === 'south' ? (text = '北') : direction === 'west' ? (text = '東') : (text = '西') - } else if ([14, 15].includes(compassType)) { - direction === 'north' - ? (text = '南南西') - : direction === 'south' - ? (text = '北北東') - : direction === 'west' - ? (text = '東南東') - : (text = '西北西') - } else if ([16].includes(compassType)) { - direction === 'north' ? (text = '南西') : direction === 'south' ? (text = '北東') : direction === 'west' ? (text = '南東') : (text = '北西') - } else if ([17, 18].includes(compassType)) { - direction === 'north' - ? (text = '西南西') - : direction === 'south' - ? (text = '東北東') - : direction === 'west' - ? (text = '南南東') - : (text = '北北西') - } else if ([19].includes(compassType)) { - direction === 'north' ? (text = '西') : direction === 'south' ? (text = '東') : direction === 'west' ? (text = '南') : (text = '北') - } else if ([20, 21].includes(compassType)) { - direction === 'north' - ? (text = '西北西') - : direction === 'south' - ? (text = '東南東') - : direction === 'west' - ? (text = '南南西') - : (text = '北北東') - } else if ([22].includes(compassType)) { - direction === 'north' ? (text = '北西') : direction === 'south' ? (text = '南東') : direction === 'west' ? (text = '南西') : (text = '北東') - } else if ([23, 24].includes(compassType)) { - direction === 'north' - ? (text = '北北西') - : direction === 'south' - ? (text = '南南東') - : direction === 'west' - ? (text = '西南西') - : (text = '東北東') - } + text = getDirectionText(moduleCompass, direction) - // 東,西,南,北 - if ([0].includes(surfaceCompass)) { - text = '南' - } else if ([15, 30].includes(surfaceCompass)) { - text = '南南東' - } else if ([45].includes(surfaceCompass)) { - text = '南東' - } else if ([60, 75].includes(surfaceCompass)) { - text = '東南東' - } else if ([90].includes(surfaceCompass)) { - text = '東' - } else if ([105, 120].includes(surfaceCompass)) { - text = '東北東' - } else if ([135].includes(surfaceCompass)) { - text = '北東' - } else if ([150, 165].includes(surfaceCompass)) { - text = '北北東' - } else if ([180].includes(surfaceCompass)) { - text = '北' - } else if ([-165, -150].includes(surfaceCompass)) { - text = '北北西' - } else if ([-135].includes(surfaceCompass)) { - text = '北西' - } else if ([-120, -105].includes(surfaceCompass)) { - text = '西北西' - } else if ([-90].includes(surfaceCompass)) { - text = '西' - } else if ([-75, -60].includes(surfaceCompass)) { - text = '西南西' - } else if ([-45].includes(surfaceCompass)) { - text = '西南' - } else if ([-30, -15].includes(surfaceCompass)) { - text = '西西南' + // surfaceCompass가 있으면 text를 덮어쓰기 (기존 로직 유지) + if (surfaceCompass !== null && surfaceCompass !== undefined) { + if ([0].includes(surfaceCompass)) { + text = '南' + } else if ([15, 30].includes(surfaceCompass)) { + text = '南南東' + } else if ([45].includes(surfaceCompass)) { + text = '南東' + } else if ([60, 75].includes(surfaceCompass)) { + text = '東南東' + } else if ([90].includes(surfaceCompass)) { + text = '東' + } else if ([105, 120].includes(surfaceCompass)) { + text = '東北東' + } else if ([135].includes(surfaceCompass)) { + text = '北東' + } else if ([150, 165].includes(surfaceCompass)) { + text = '北北東' + } else if ([180].includes(surfaceCompass)) { + text = '北' + } else if ([-165, -150].includes(surfaceCompass)) { + text = '北北西' + } else if ([-135].includes(surfaceCompass)) { + text = '北西' + } else if ([-120, -105].includes(surfaceCompass)) { + text = '西北西' + } else if ([-90].includes(surfaceCompass)) { + text = '西' + } else if ([-75, -60].includes(surfaceCompass)) { + text = '西南西' + } else if ([-45].includes(surfaceCompass)) { + text = '南西' + } else if ([-30, -15].includes(surfaceCompass)) { + text = '南南西' + } } const sameDirectionCnt = canvas.getObjects().filter((obj) => {