diff --git a/src/hooks/module/useTrestle.js b/src/hooks/module/useTrestle.js index 4e907c91..8c34ab6b 100644 --- a/src/hooks/module/useTrestle.js +++ b/src/hooks/module/useTrestle.js @@ -2287,17 +2287,21 @@ export const useTrestle = () => { const { width: currentWidth, height: currentHeight, moduleInfo: currentModuleInfo } = m1 const { width: neighborWidth, height: neighborHeight, moduleInfo: neighborModuleInfo } = m2 + const maxWidth = Math.max(currentWidth, neighborWidth) + const maxHeight = Math.max(currentHeight, neighborHeight) + const { moduleTpCd: currentModuleTpCd } = currentModuleInfo const { moduleTpCd: neighborModuleTpCd } = neighborModuleInfo const { x: m1X, y: m1Y } = m1.getCenterPoint() const { x: m2X, y: m2Y } = m2.getCenterPoint() + sizes.push({ width: currentWidth, height: currentHeight }) if (currentModuleTpCd !== neighborModuleTpCd) { sizes.push({ width: neighborWidth, height: neighborHeight }) } - - /*m1.set({ fill: m1Fill }) + /* + m1.set({ fill: m1Fill }) m2.set({ fill: m2Fill }) canvas.renderAll()*/ @@ -2331,13 +2335,13 @@ export const useTrestle = () => { // console.log(maxX, maxY, halfMaxX, halfMaxY) if (Math.abs(m1X - m2X) < 1) { - return Math.abs(Math.abs(m1Y - m2Y) - maxY) < 1 + return Math.abs(Math.abs(m1Y - m2Y) - maxY) < 1 || Math.abs(m2Y - m1Y) <= halfMaxY } else if (Math.abs(m1Y - m2Y) < 1) { - return Math.abs(Math.abs(m1X - m2X) - maxX) < 1 + return Math.abs(Math.abs(m1X - m2X) - maxX) < 1 || Math.abs(m2X - m1X) <= halfMaxX } return ( - (Math.abs(m1X - m2X) < maxX - moduleIntvlHor / 10 && Math.abs(m1Y - m2Y) < maxY - moduleIntvlVer / 10) || + (Math.abs(m1X - m2X) < maxX - moduleIntvlHor / 10 + 1 && Math.abs(m1Y - m2Y) < maxY - moduleIntvlVer / 10) || (Math.abs(Math.abs(m1X - m2X) - maxX / 2) < halfMaxX + 1 && Math.abs(Math.abs(m1Y - m2Y) - maxY) < halfMaxY + 1) || (Math.abs(Math.abs(m1X - m2X) - maxX) < halfMaxX + 1 && Math.abs(Math.abs(m1Y - m2Y) - maxY / 2) < halfMaxY + 1) ) @@ -2353,9 +2357,9 @@ export const useTrestle = () => { } if (Math.abs(m1X - m2X) < 1) { - return Math.abs(Math.abs(m1Y - m2Y) - maxX) < 1 + return Math.abs(Math.abs(m1Y - m2Y) - maxX) < 1 || Math.abs(m2Y - m1Y) <= halfMaxY } else if (Math.abs(m1Y - m2Y) < 1) { - return Math.abs(Math.abs(m1X - m2X) - maxY) < 1 + return Math.abs(Math.abs(m1X - m2X) - maxY) < 1 || Math.abs(m2X - m1X) <= halfMaxX } return ( @@ -3201,6 +3205,7 @@ export const useTrestle = () => { let cnt = 0 const surfaces = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE) const modules = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.MODULE) + debugger surfaces.forEach((surface) => { const modules = surface.modules const groups = groupByType(modules)