diff --git a/src/components/floor-plan/modal/basic/BasicSetting.jsx b/src/components/floor-plan/modal/basic/BasicSetting.jsx index 20578b24..6d9f2a42 100644 --- a/src/components/floor-plan/modal/basic/BasicSetting.jsx +++ b/src/components/floor-plan/modal/basic/BasicSetting.jsx @@ -36,7 +36,7 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) { }, []) const placementRef = { - isChidori: useRef('true'), + isChidori: useRef('false'), setupLocation: useRef(null), isMaxSetup: useRef('false'), } diff --git a/src/components/floor-plan/modal/basic/step/Placement.jsx b/src/components/floor-plan/modal/basic/step/Placement.jsx index 8acaff70..e5acf6da 100644 --- a/src/components/floor-plan/modal/basic/step/Placement.jsx +++ b/src/components/floor-plan/modal/basic/step/Placement.jsx @@ -3,9 +3,7 @@ import { forwardRef, useState } from 'react' const Placement = forwardRef((props, refs) => { const { getMessage } = useMessage() - const [isChidori, setIsChidori] = useState('true') - - console.log(refs) + const [isChidori, setIsChidori] = useState('false') const moduleData = { header: [ @@ -107,19 +105,19 @@ const Placement = forwardRef((props, refs) => {
- +
- +
diff --git a/src/hooks/module/useModuleBasicSetting.js b/src/hooks/module/useModuleBasicSetting.js index 7d8ea54d..4f3e451d 100644 --- a/src/hooks/module/useModuleBasicSetting.js +++ b/src/hooks/module/useModuleBasicSetting.js @@ -10,6 +10,7 @@ import { useEvent } from '@/hooks/useEvent' import { POLYGON_TYPE, BATCH_TYPE } from '@/common/common' import * as turf from '@turf/turf' +import next from 'next' export function useModuleBasicSetting() { const canvas = useRecoilValue(canvasState) @@ -475,13 +476,6 @@ export function useModuleBasicSetting() { const bbox = turf.bbox(difference) - let surfaceBbox = { - minX: bbox[0], - maxX: bbox[2], - minY: bbox[1], - maxY: bbox[3], - } - let width = maxLengthLine.flowDirection === 'right' || maxLengthLine.flowDirection === 'left' ? 172.2 : 113.4 let height = maxLengthLine.flowDirection === 'right' || maxLengthLine.flowDirection === 'left' ? 113.4 : 172.2 @@ -490,6 +484,7 @@ export function useModuleBasicSetting() { width = moduleSetupSurface.flowDirection === 'south' || moduleSetupSurface.flowDirection === 'north' ? 172.2 : 113.4 height = moduleSetupSurface.flowDirection === 'south' || moduleSetupSurface.flowDirection === 'north' ? 113.4 : 172.2 } + let cols = Math.floor((bbox[2] - bbox[0]) / width) let rows = Math.floor((bbox[3] - bbox[1]) / height) @@ -599,6 +594,7 @@ export function useModuleBasicSetting() { parentId: moduleSetupSurface.parentId, lineCol: col, lineRow: row, + name: 'module', }) tempModule.setViewLengthText(false) canvas?.add(tempModule) @@ -619,6 +615,7 @@ export function useModuleBasicSetting() { parentId: moduleSetupSurface.parentId, lineCol: col, lineRow: row, + name: 'module', }) canvas?.add(tempModule) moduleSetupArray.push(tempModule) @@ -763,76 +760,41 @@ export function useModuleBasicSetting() { return hull } - function calculatePerpendicularLine(hypotenuseStart, hypotenuseEnd, height) { - const { x: x1, y: y1 } = hypotenuseStart - const { x: x2, y: y2 } = hypotenuseEnd + const calcMinXByHeightDistance = (nowSurface, index, reverse) => { + function calculateSlopeIntercept(x1, y1, x2, y2) { + console.log('Intercept', x1, y1, x2, y2) - // 1. 빗변의 기울기 계산 - const slope = (y2 - y1) / (x2 - x1) + const slope = (y2 - y1) / (x2 - x1) + const intercept = y1 - slope * x1 - // 2. 중점 계산 - const xC = (x1 + x2) / 2 - const yC = (y1 + y2) / 2 - - // 3. 수직 기울기의 정규화 인자 계산 - const norm = Math.sqrt(1 + Math.pow(slope, 2)) - - // 4. 수직선의 끝점 계산 - const xOffset = -height / norm - const yOffset = (height * slope) / norm - - const point1 = { x: xC + xOffset, y: yC + yOffset } - const point2 = { x: xC - xOffset, y: yC - yOffset } - - return { point1, point2 } - } - - // 예제 사용 - const hypotenuseStart = { x: 2, y: 3 } - const hypotenuseEnd = { x: 8, y: 9 } - const height = 4 - - const result = calculatePerpendicularLine(hypotenuseStart, hypotenuseEnd, height) - console.log(result) - - const calcMinXByHeightDistance = (surface) => { - let minXIndex = surface.lines.reduce((minIdx, current, index, arr) => { - console.log('reduce', minIdx, current, index, arr) - - return current.x1 < arr[minIdx].x1 ? index : minIdx - }, surface.lines[0].x1) - - console.log('minXIndex', minXIndex) - - function calculateIntersection(diagonalA, lineB) { - // Diagonal A coordinates - const { x1: ax1, y1: ay1, x2: ax2, y2: ay2 } = diagonalA - - // Line B coordinates - const { x2: bx2, y2: by2 } = lineB - - // Calculate slope (m) and intercept (c) for diagonal A - const slopeA = (ay2 - ay1) / (ax2 - ax1) - const interceptA = ay1 - slopeA * ax1 - - // Use fixed y (from lineB's y2) - const yFixed = by2 - - // Calculate x on diagonal A where y = yFixed - const xFixed = (yFixed - interceptA) / slopeA - - // Return the intersection point - return { x: xFixed, y: yFixed } + return { slope, intercept } } - console.log('line', line) + let prevLines = nowSurface.lines[(index - 1 + nowSurface.lines.length) % nowSurface.lines.length] + let nextLines = nowSurface.lines[index] - // Example usage: - const diagonalA = { x1: 490.4, y1: 94.7, x2: 303.7, y2: 654.7 } - const lineB = { x1: 303.7, y1: 654.7, x2: 303.7, y2: 541.3 } + // 선분 정보 + const l1 = prevLines + const l2 = nextLines + const lineLength = 172.2 - const intersection = calculateIntersection(diagonalA, lineB) - console.log(`Intersection point: x = ${intersection.x}, y = ${intersection.y}`) + // l1과 l2의 기울기 및 절편 + let { slope: m1, intercept: b1 } = calculateSlopeIntercept(l1.x1, l1.y1, l1.x2, l1.y2) + let { slope: m2, intercept: b2 } = calculateSlopeIntercept(l2.x1, l2.y1, l2.x2, l2.y2) + + console.log(m1, b1, m2, b2) + + // 가로선 x1 계산 + const x1 = (m2 * lineLength + b2 - b1) / (m1 - m2) + const x2 = x1 + lineLength // 끝점 x2 + + // 가로선 y값 계산 + const y0 = m1 * x1 + b1 + + // 결과 출력 + + console.log({ x1: x1, y1: y0, x2: x2, y2: y0 }) + return { x1: x1, y1: y0, x2: x2, y2: y0 } } return {