모듈 계산 작업중

This commit is contained in:
hyojun.choi 2024-12-03 16:40:35 +09:00
parent eae52410e7
commit 3b72acce81

View File

@ -932,16 +932,19 @@ export function useModuleBasicSetting() {
moduleSetupSurface.set({ modules: setupedModules }) moduleSetupSurface.set({ modules: setupedModules })
// setModuleIsSetup(moduleSetupArray) // setModuleIsSetup(moduleSetupArray)
}) })
console.log(calculateForApi())
} }
const calculateForApi = (moduleSetupArray) => { const calculateForApi = () => {
// TODO : 현재는 남쪽기준. 동,서,북 분기처리 필요 // TODO : 현재는 남쪽기준. 동,서,북 분기처리 필요
const centerPoints = [] const centerPoints = []
moduleSetupArray.forEach((module, index) => { const modules = canvas.getObjects().filter((obj) => obj.name === 'module')
modules.forEach((module, index) => {
module.tempIndex = index module.tempIndex = index
const { x, y } = module.getCenterPoint() const { x, y } = module.getCenterPoint()
const { width, height } = module const { width, height } = module
centerPoints.push({ x, y, width, height, index }) centerPoints.push({ x, y, width: Math.abs(width), height: Math.abs(height), index })
const circle = new fabric.Circle({ const circle = new fabric.Circle({
radius: 5, radius: 5,
fill: 'red', fill: 'red',
@ -951,7 +954,7 @@ export function useModuleBasicSetting() {
index: index, index: index,
selectable: false, selectable: false,
}) })
canvas.add(circle) // canvas.add(circle)
}) })
//완전 노출 하면 //완전 노출 하면
@ -970,7 +973,7 @@ export function useModuleBasicSetting() {
centerPoints.forEach((centerPoint, index) => { centerPoints.forEach((centerPoint, index) => {
const { x, y, width, height } = centerPoint const { x, y, width, height } = centerPoint
// centerPoints중에 현재 centerPoint와 x값이 같고, y값이 y-height값과 같은 centerPoint가 있는지 확인 // centerPoints중에 현재 centerPoint와 x값이 같고, y값이 y-height값과 같은 centerPoint가 있는지 확인
const bottomCell = centerPoints.filter((centerPoint) => centerPoint.x === x && Math.abs(centerPoint.y - (y + height)) < 2) const bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < 2 && Math.abs(centerPoint.y - (y + height)) < 2)
if (bottomCell.length === 1) { if (bottomCell.length === 1) {
touchDimension++ touchDimension++
return return
@ -1000,7 +1003,7 @@ export function useModuleBasicSetting() {
centerPoints.forEach((centerPoint, index) => { centerPoints.forEach((centerPoint, index) => {
const { x, y, width, height } = centerPoint const { x, y, width, height } = centerPoint
const topCell = centerPoints.filter((centerPoint) => centerPoint.x === x && Math.abs(centerPoint.y - (y - height)) < 2) const topCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < 2 && Math.abs(centerPoint.y - (y - height)) < 2)
if (topCell.length === 1) { if (topCell.length === 1) {
return return
} }
@ -1030,8 +1033,8 @@ export function useModuleBasicSetting() {
const points = cells.map((cell) => { const points = cells.map((cell) => {
return cell.getCenterPoint() return cell.getCenterPoint()
})*/ })*/
const groupPoints = groupCoordinates(centerPoints) const groupPoints = groupCoordinates(centerPoints, modules[0])
console.log('groupPoints', groupPoints)
groupPoints.forEach((group) => { groupPoints.forEach((group) => {
// 각 그룹에서 y값이 큰 값을 찾는다. // 각 그룹에서 y값이 큰 값을 찾는다.
// 그리고 그 y값과 같은 값을 가지는 centerPoint를 찾는다. // 그리고 그 y값과 같은 값을 가지는 centerPoint를 찾는다.
@ -1051,21 +1054,21 @@ export function useModuleBasicSetting() {
} }
// polygon 내부 cell들의 centerPoint 배열을 그룹화 해서 반환 // polygon 내부 cell들의 centerPoint 배열을 그룹화 해서 반환
const groupCoordinates = (points) => { const groupCoordinates = (points, moduleExample) => {
const groups = [] const groups = []
const visited = new Set() const visited = new Set()
const width = 100 const width = Math.floor(moduleExample.width)
const height = 100 const height = Math.floor(moduleExample.height)
const horizonPadding = 5 // 가로 패딩 const horizonPadding = 0 // 가로 패딩
const verticalPadding = 3 // 세로 패딩 const verticalPadding = 0 // 세로 패딩
function isAdjacent(p1, p2) { function isAdjacent(p1, p2) {
const dx = Math.abs(p1.x - p2.x) const dx = Math.abs(p1.x - p2.x)
const dy = Math.abs(p1.y - p2.y) const dy = Math.abs(p1.y - p2.y)
return ( return (
(dx === width + horizonPadding && dy === 0) || (Math.abs(width + horizonPadding - dx) < 2 && dy < 2) ||
(dx === 0 && dy === height + verticalPadding) || (dx < 2 && Math.abs(dy - height + verticalPadding)) < 2 ||
(dx === width / 2 + horizonPadding / 2 && dy === height + verticalPadding) (Math.abs(dx - width / 2 + horizonPadding / 2) < 2 && Math.abs(dy - height + verticalPadding) < 2)
) )
} }