From b2f639a461736564b696d88739a19d9012e390bb Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Wed, 25 Jun 2025 13:46:15 +0900 Subject: [PATCH] =?UTF-8?q?=EC=96=91=EB=8B=A8=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20count=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/module/useTrestle.js | 47 ++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/hooks/module/useTrestle.js b/src/hooks/module/useTrestle.js index f6556af2..4da85212 100644 --- a/src/hooks/module/useTrestle.js +++ b/src/hooks/module/useTrestle.js @@ -2322,8 +2322,8 @@ export const useTrestle = () => { if (currentModuleTpCd !== neighborModuleTpCd) { sizes.push({ width: neighborWidth, height: neighborHeight }) } - /* - m1.set({ fill: m1Fill }) + + /*m1.set({ fill: m1Fill }) m2.set({ fill: m2Fill }) canvas.renderAll()*/ @@ -2349,6 +2349,24 @@ export const useTrestle = () => { halfMaxX = moduleIntvlHor / 10 halfMaxY = moduleIntvlVer / 10 + const leftTopPoint = { x: m1X - width - moduleIntvlHor / 10, y: m1Y - height - moduleIntvlVer / 10 } + const rightTopPoint = { x: m1X + width + moduleIntvlHor / 10, y: m1Y - height - moduleIntvlVer / 10 } + const leftBottomPoint = { x: m1X - width - moduleIntvlHor / 10, y: m1Y + height + moduleIntvlVer / 10 } + const rightBottomPoint = { x: m1X + width + moduleIntvlHor / 10, y: m1Y + height + moduleIntvlVer / 10 } + // {x: m2X, y: m2Y} 가 leftTopPoint, rightTopPoint, leftBottomPoint, rightBottomPoint 내부에 있는지 확인한다. + if ( + isPointInRect( + { + x: leftTopPoint.x, + y: leftTopPoint.y, + width: Math.abs(rightTopPoint.x - leftTopPoint.x), + height: Math.abs(leftTopPoint.y - leftBottomPoint.y), + }, + { x: m2X, y: m2Y }, + ) + ) { + return true + } if (currentModuleTpCd !== neighborModuleTpCd) { maxX = currentWidth / 2 + neighborWidth / 2 + moduleIntvlHor / 10 maxY = currentHeight / 2 + neighborHeight / 2 + moduleIntvlVer / 10 @@ -2373,6 +2391,27 @@ export const useTrestle = () => { halfMaxX = moduleIntvlVer / 10 halfMaxY = moduleIntvlHor / 10 + // 모듈을 기준으로 왼쪽 상, 오른쪽 상, 왼쪽 하, 오른쪽 하의 각 포인트를 계산 + const leftTopPoint = { x: m1X - width - moduleIntvlVer / 10, y: m1Y + height + moduleIntvlHor / 10 } + const rightTopPoint = { x: m1X - width - moduleIntvlVer / 10, y: m1Y - height - moduleIntvlHor / 10 } + const leftBottomPoint = { x: m1X + width + moduleIntvlVer / 10, y: m1Y + height + moduleIntvlHor / 10 } + const rightBottomPoint = { x: m1X + width + +moduleIntvlVer / 10, y: m1Y - height - moduleIntvlHor / 10 } + + // {x: m2X, y: m2Y} 가 leftTopPoint, rightTopPoint, leftBottomPoint, rightBottomPoint 내부에 있는지 확인한다. + if ( + isPointInRect( + { + x: rightTopPoint.x, + y: rightTopPoint.y, + width: Math.abs(rightBottomPoint.x - rightTopPoint.x), + height: Math.abs(leftTopPoint.y - rightTopPoint.y), + }, + { x: m2X, y: m2Y }, + ) + ) { + return true + } + if (currentModuleTpCd !== neighborModuleTpCd) { maxX = currentHeight / 2 + neighborHeight / 2 + moduleIntvlVer / 10 maxY = currentWidth / 2 + neighborWidth / 2 + moduleIntvlHor / 10 @@ -2393,6 +2432,10 @@ export const useTrestle = () => { }) } + function isPointInRect(rect, point) { + return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height + } + // 25-04-02 추가 // 그룹화 function groupPoints(modules, surface) {