diff --git a/src/hooks/module/useModuleBasicSetting.js b/src/hooks/module/useModuleBasicSetting.js index 7a72a379..980460dc 100644 --- a/src/hooks/module/useModuleBasicSetting.js +++ b/src/hooks/module/useModuleBasicSetting.js @@ -766,6 +766,7 @@ export function useModuleBasicSetting() { } const calculateForApi = (moduleSetupArray) => { + // TODO : 현재는 남쪽기준. 동,서,북 분기처리 필요 const centerPoints = [] moduleSetupArray.forEach((module, index) => { module.tempIndex = index @@ -825,10 +826,6 @@ export function useModuleBasicSetting() { exposedHalfBottom++ return } - if (leftBottomCnt + rightBottomCnt === 0) { - exposedBottom++ - return - } }) // 노출상면 체크 @@ -858,6 +855,22 @@ export function useModuleBasicSetting() { return } }) + // 완전 노출 하면 계산 + + /*const cells = canvas.getObjects().filter((obj) => polygon.id === obj.parentId) + const points = cells.map((cell) => { + return cell.getCenterPoint() + })*/ + const groupPoints = groupCoordinates(centerPoints) + + groupPoints.forEach((group) => { + // 각 그룹에서 y값이 큰 값을 찾는다. + // 그리고 그 y값과 같은 값을 가지는 centerPoint를 찾는다. + const maxY = group.reduce((acc, cur) => (acc.y > cur.y ? acc : cur)).y + const maxYCenterPoint = group.filter((centerPoint) => Math.abs(centerPoint.y - maxY) < 2) + exposedBottom += maxYCenterPoint.length + }) + return { exposedBottom, exposedHalfBottom, @@ -868,6 +881,49 @@ export function useModuleBasicSetting() { } } + // polygon 내부 cell들의 centerPoint 배열을 그룹화 해서 반환 + const groupCoordinates = (points) => { + const groups = [] + const visited = new Set() + const width = 100 + const height = 100 + const horizonPadding = 5 // 가로 패딩 + const verticalPadding = 3 // 세로 패딩 + + function isAdjacent(p1, p2) { + const dx = Math.abs(p1.x - p2.x) + const dy = Math.abs(p1.y - p2.y) + return ( + (dx === width + horizonPadding && dy === 0) || + (dx === 0 && dy === height + verticalPadding) || + (dx === width / 2 + horizonPadding / 2 && dy === height + verticalPadding) + ) + } + + function dfs(point, group) { + visited.add(`${point.x},${point.y}`) + group.push(point) + + for (const nextPoint of points) { + const key = `${nextPoint.x},${nextPoint.y}` + if (!visited.has(key) && isAdjacent(point, nextPoint)) { + dfs(nextPoint, group) + } + } + } + + for (const point of points) { + const key = `${point.x},${point.y}` + if (!visited.has(key)) { + const group = [] + dfs(point, group) + groups.push(group) + } + } + + return groups + } + const coordToTurfPolygon = (points) => { const coordinates = points.map((point) => [point.x, point.y]) coordinates.push(coordinates[0])