견적서 item 멀티모듈 대응 추가

This commit is contained in:
hyojun.choi 2025-02-11 13:09:47 +09:00
parent c253cfe07e
commit 4e1b7cc010

View File

@ -359,8 +359,8 @@ export const useTrestle = () => {
return (
rack.value.moduleTpCd === leftRowsInfo.moduleTotalTp &&
rack.value.moduleRows === leftRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) &&
rack.value.moduleTpRows1 === leftRowsInfo.rowsInfo[0].count &&
rack.value.moduleTpRows2 === leftRowsInfo.rowsInfo[1].count
Number(rack.value.moduleTpRows1) === leftRowsInfo.rowsInfo[0].count &&
Number(rack.value.moduleTpRows2) === leftRowsInfo.rowsInfo[1].count
)
}
})?.value.racks
@ -376,8 +376,8 @@ export const useTrestle = () => {
return (
rack.value.moduleTpCd === rightRowsInfo.moduleTotalTp &&
rack.value.moduleRows === rightRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) &&
rack.value.moduleTpRows1 === rightRowsInfo.rowsInfo[0].count &&
rack.value.moduleTpRows2 === rightRowsInfo.rowsInfo[1].count
Number(rack.value.moduleTpRows1) === rightRowsInfo.rowsInfo[0].count &&
Number(rack.value.moduleTpRows2) === rightRowsInfo.rowsInfo[1].count
)
}
})?.value.racks
@ -393,8 +393,8 @@ export const useTrestle = () => {
return (
rack.value.moduleTpCd === centerRowsInfo.moduleTotalTp &&
rack.value.moduleRows === centerRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) &&
rack.value.moduleTpRows1 === centerRowsInfo.rowsInfo[0].count &&
rack.value.moduleTpRows2 === centerRowsInfo.rowsInfo[1].count
Number(rack.value.moduleTpRows1) === centerRowsInfo.rowsInfo[0].count &&
Number(rack.value.moduleTpRows2) === centerRowsInfo.rowsInfo[1].count
)
}
})?.value.racks
@ -488,8 +488,8 @@ export const useTrestle = () => {
return (
rack.value.moduleTpCd === leftRowsInfo.moduleTotalTp &&
rack.value.moduleRows === leftRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) &&
rack.value.moduleTpRows1 === leftRowsInfo.rowsInfo[0].count &&
rack.value.moduleTpRows2 === leftRowsInfo.rowsInfo[1].count
Number(rack.value.moduleTpRows1) === leftRowsInfo.rowsInfo[0].count &&
Number(rack.value.moduleTpRows2) === leftRowsInfo.rowsInfo[1].count
)
}
})?.value.racks
@ -564,8 +564,8 @@ export const useTrestle = () => {
return (
rack.value.moduleTpCd === rightRowsInfo.moduleTotalTp &&
rack.value.moduleRows === rightRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) &&
rack.value.moduleTpRows1 === rightRowsInfo.rowsInfo[0].count &&
rack.value.moduleTpRows2 === rightRowsInfo.rowsInfo[1].count
Number(rack.value.moduleTpRows1) === rightRowsInfo.rowsInfo[0].count &&
Number(rack.value.moduleTpRows2) === rightRowsInfo.rowsInfo[1].count
)
}
})?.value.racks
@ -743,19 +743,32 @@ export const useTrestle = () => {
let result
switch (direction) {
case 'south': {
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - height)) < maxY)
heightArr.forEach((height) => {
if (result) return
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - height)) < maxY)
})
break
}
case 'north': {
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + height)) < maxY)
heightArr.forEach((height) => {
if (result) return
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + height)) < maxY)
})
break
}
case 'east': {
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x - width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
widthArr.forEach((width) => {
if (result) return
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x - width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
})
break
}
case 'west': {
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x + width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
widthArr.forEach((width) => {
if (result) return
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x + width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
})
break
}
}
@ -779,27 +792,47 @@ export const useTrestle = () => {
case 'south': {
width = width + horizontal
height = height + vertical
topLeftPoint = { x: x - width / 2, y: y - height }
heightArr.forEach((h) => {
topLeftPoint = { x: x - width / 2, y: y - h }
if (result) return
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y))
})
break
}
case 'north': {
width = width + horizontal
height = height + vertical
topLeftPoint = { x: x + width / 2, y: y + height }
heightArr.forEach((h) => {
topLeftPoint = { x: x + width / 2, y: y + h }
if (result) return
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y))
})
break
}
case 'east': {
topLeftPoint = { x: x - width, y: y + height / 2 }
widthArr.forEach((w) => {
topLeftPoint = { x: x - w, y: y + height / 2 }
if (result) return
result = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y) < maxY,
)
})
break
}
case 'west': {
topLeftPoint = { x: x + width, y: y - height / 2 }
widthArr.forEach((w) => {
topLeftPoint = { x: x + w, y: y - height / 2 }
if (result) return
result = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y) < maxY,
)
})
break
}
}
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y) < maxY)
return result
}
const findNextRightModule = (currentPoint, centerPoints, direction) => {
@ -816,25 +849,44 @@ export const useTrestle = () => {
switch (direction) {
case 'south': {
topRightPoint = { x: x + width / 2, y: y - height }
heightArr.forEach((h) => {
topRightPoint = { x: x + width / 2, y: y - h }
if (result) return
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y))
})
break
}
case 'north': {
topRightPoint = { x: x - width / 2, y: y + height }
heightArr.forEach((h) => {
topRightPoint = { x: x - width / 2, y: y + h }
if (result) return
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y))
})
break
}
case 'east': {
topRightPoint = { x: x - width, y: y - height / 2 }
widthArr.forEach((w) => {
topRightPoint = { x: x + w, y: y + height / 2 }
if (result) return
result = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y) < maxY,
)
})
break
}
case 'west': {
topRightPoint = { x: x + width, y: y + height / 2 }
widthArr.forEach((w) => {
topRightPoint = { x: x - w, y: y - height / 2 }
if (result) return
result = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y) < maxY,
)
})
break
}
}
result = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y) < maxY)
return result
}
@ -1575,8 +1627,13 @@ export const useTrestle = () => {
//widthArr 중복 제거 1이상 차이가 나지 않으면 같은 너비로 간주
widthArr = removeCloseValues(Array.from(new Set(widthArr)))
heightArr = removeCloseValues(Array.from(new Set(heightArr)))
const widthAvg = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length
const heightAvg = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length
widthArr.push(widthAvg)
heightArr.push(heightAvg)
centerPoints.forEach((centerPoint, index) => {
// widthArr의 평균값을 추가한다.
centerPoint.widthArr = [...widthArr]
centerPoint.heightArr = [...heightArr]
@ -1610,8 +1667,8 @@ export const useTrestle = () => {
const vertical = ['south', 'north'].includes(direction) ? moduleSurface.trestleDetail.moduleIntvlVer : moduleSurface.trestleDetail.moduleIntvlHor
const maxX = 2 + horizontal * 3
const maxY = 2 + vertical * 3
const maxX = 2 + (horizontal / 10) * 3
const maxY = 2 + (vertical / 10) * 3
if (centerPoints.length === 0) return
@ -1643,50 +1700,97 @@ export const useTrestle = () => {
let bottomCell
let bottomLeftPoint
let bottomRightPoint
let leftBottomCnt
let rightBottomCnt
let leftBottomCnt = 0
let rightBottomCnt = 0
switch (direction) {
case 'south':
//widthArr의 값을 전부 더한 후 widthArr의 길이로 나누어 평균값을 구한다.
width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal
height = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length + vertical
bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + height)) < maxY)
bottomLeftPoint = { x: x - width / 2, y: y + height }
bottomRightPoint = { x: x + width / 2, y: y + height }
heightArr.forEach((h) => {
if (bottomCell) return
bottomCell = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + h)) < maxY)
if (leftBottomCnt === 0) {
bottomLeftPoint = { x: x - width / 2, y: y + h }
leftBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
).length
}
if (rightBottomCnt === 0) {
bottomRightPoint = { x: x + width / 2, y: y + h }
rightBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
).length
}
})
break
case 'north':
width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal
height = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length + vertical
bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - height)) < maxY)
bottomLeftPoint = { x: x + width / 2, y: y - height }
bottomRightPoint = { x: x - width / 2, y: y - height }
heightArr.forEach((h) => {
if (bottomCell) return
bottomCell = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - h)) < maxY)
if (leftBottomCnt === 0) {
bottomLeftPoint = { x: x + width / 2, y: y - h }
leftBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
).length
}
if (rightBottomCnt === 0) {
bottomRightPoint = { x: x - width / 2, y: y - h }
rightBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
).length
}
})
break
case 'east':
bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - (x + width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal
bottomLeftPoint = { x: x + width, y: y + height / 2 }
bottomRightPoint = { x: x + width, y: y - height / 2 }
widthArr.forEach((w) => {
if (bottomCell) return
bottomCell = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x + w)) < maxX && Math.abs(centerPoint.y - y) < maxY)
if (leftBottomCnt === 0) {
bottomLeftPoint = { x: x + w, y: y + height / 2 }
leftBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
).length
}
if (rightBottomCnt === 0) {
bottomRightPoint = { x: x + w, y: y - height / 2 }
rightBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
).length
}
})
break
case 'west':
bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - (x - width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal
bottomLeftPoint = { x: x - width, y: y - height / 2 }
bottomRightPoint = { x: x - width, y: y + height / 2 }
widthArr.forEach((w) => {
if (bottomCell) return
bottomCell = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x - w)) < maxX && Math.abs(centerPoint.y - y) < maxY)
if (leftBottomCnt === 0) {
bottomLeftPoint = { x: x - w, y: y - height / 2 }
leftBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
).length
}
if (rightBottomCnt === 0) {
bottomRightPoint = { x: x - w, y: y + height / 2 }
rightBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
).length
}
})
break
}
if (bottomCell.length === 1) {
if (bottomCell) {
return
}
// 바로 아래에 셀이 없는 경우 물떼세 배치가 왼쪽 되어있는 셀을 찾는다.
leftBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
).length
rightBottomCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
).length
if (leftBottomCnt + rightBottomCnt === 1) {
exposedHalfBottom++
@ -1703,54 +1807,100 @@ export const useTrestle = () => {
// 노출상면 및 접면 체크
centerPoints.forEach((centerPoint, index) => {
let { x, y, width, height } = { ...centerPoint }
let { x, y, width, height, widthArr, heightArr } = { ...centerPoint }
let topCell
let topLeftPoint
let topRightPoint
let leftTopCnt
let rightTopCnt
let leftTopCnt = 0
let rightTopCnt = 0
switch (direction) {
case 'south':
width = width + horizontal
height = height + vertical
topCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - height)) < maxY)
topLeftPoint = { x: x - width / 2, y: y - height }
topRightPoint = { x: x + width / 2, y: y - height }
heightArr.forEach((h) => {
if (topCell) return
topCell = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + h)) < maxY)
if (leftTopCnt === 0) {
topLeftPoint = { x: x - width / 2, y: y - h }
leftTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y) < maxY,
).length
}
if (rightTopCnt === 0) {
topRightPoint = { x: x + width / 2, y: y - h }
rightTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y) < maxY,
).length
}
})
break
case 'north':
height = height + vertical
topCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + height)) < maxY)
topLeftPoint = { x: x + width / 2, y: y + height }
topRightPoint = { x: x - width / 2, y: y + height }
heightArr.forEach((h) => {
if (topCell) return
topCell = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - h)) < maxY)
if (leftTopCnt === 0) {
topLeftPoint = { x: x + width / 2, y: y + h }
leftTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y) < maxY,
).length
}
if (rightTopCnt === 0) {
topRightPoint = { x: x - width / 2, y: y + h }
rightTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y) < maxY,
).length
}
})
break
case 'east':
width = width + horizontal
topCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - (x - width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
topLeftPoint = { x: x - width, y: y + height / 2 }
topRightPoint = { x: x - width, y: y - height / 2 }
widthArr.forEach((w) => {
if (topCell) return
topCell = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x + w)) < maxX && Math.abs(centerPoint.y - y) < maxY)
if (leftTopCnt === 0) {
topLeftPoint = { x: x - w, y: y + height / 2 }
leftTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y) < maxY,
).length
}
if (rightTopCnt === 0) {
topRightPoint = { x: x - w, y: y - height / 2 }
rightTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y) < maxY,
).length
}
})
break
case 'west':
width = width + horizontal
topCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - (x + width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
topLeftPoint = { x: x + width, y: y - height / 2 }
topRightPoint = { x: x + width, y: y + height / 2 }
widthArr.forEach((w) => {
if (topCell) return
topCell = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x - w)) < maxX && Math.abs(centerPoint.y - y) < maxY)
if (leftTopCnt === 0) {
topLeftPoint = { x: x + w, y: y - height / 2 }
leftTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y) < maxY,
).length
}
if (rightTopCnt === 0) {
topRightPoint = { x: x + w, y: y + height / 2 }
rightTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y) < maxY,
).length
}
})
break
}
if (topCell.length === 1) {
if (topCell) {
touchDimension++
return
}
leftTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < maxX && Math.abs(centerPoint.y - topLeftPoint.y) < maxY,
).length
rightTopCnt = centerPoints.filter(
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < maxX && Math.abs(centerPoint.y - topRightPoint.y) < maxY,
).length
if (leftTopCnt + rightTopCnt === 2) {
touchDimension++
return
@ -1981,6 +2131,34 @@ export const useTrestle = () => {
})
}
// 키값의 차이가 2이하인 경우 한개로 합침
function mergeCloseKeys(data) {
// 키 값을 숫자로 변환 후 정렬
const keys = Object.keys(data)
.map(parseFloat)
.sort((a, b) => a - b)
const result = {}
let baseKey = keys[0]
result[baseKey.toString()] = [...data[baseKey.toString()]]
for (let i = 1; i < keys.length; i++) {
const currentKey = keys[i]
const prevKey = baseKey
if (Math.abs(currentKey - prevKey) <= 2) {
// 키 차이가 2 이하인 경우 병합
result[baseKey.toString()].push(...data[currentKey.toString()])
} else {
// 새로운 그룹 시작
baseKey = currentKey
result[baseKey.toString()] = [...data[currentKey.toString()]]
}
}
return result
}
// 가장 왼쪽에 있는 모듈을 기준으로 같은 단에 있는 모듈들 파라미터 생성
const getMostLeftModules = (surface, exposedBottomModules) => {
const { direction, modules, isChidory } = surface
@ -2001,7 +2179,7 @@ export const useTrestle = () => {
if (direction === 'south') {
// 모듈의 top으로 groupBy
const groupedByTop = modules.reduce((acc, module) => {
let groupedByTop = modules.reduce((acc, module) => {
const key = module.top
if (!acc[key]) {
acc[key] = []
@ -2009,10 +2187,11 @@ export const useTrestle = () => {
acc[key].push(module)
return acc
}, {})
groupedByTop = mergeCloseKeys(groupedByTop)
// groupedByTop의 키값을 기준으로 정렬한 데이터를 배열로 변환
sameLineModuleList = Object.values(groupedByTop).sort((a, b) => b[0].top - a[0].top)
} else if (direction === 'north') {
const groupedByTop = modules.reduce((acc, module) => {
let groupedByTop = modules.reduce((acc, module) => {
const key = module.top
if (!acc[key]) {
acc[key] = []
@ -2020,9 +2199,10 @@ export const useTrestle = () => {
acc[key].push(module)
return acc
}, {})
groupedByTop = mergeCloseKeys(groupedByTop)
sameLineModuleList = Object.values(groupedByTop).sort((a, b) => a[0].top - b[0].top)
} else if (direction === 'east') {
const groupedByLeft = modules.reduce((acc, module) => {
let groupedByLeft = modules.reduce((acc, module) => {
const key = module.left
if (!acc[key]) {
acc[key] = []
@ -2030,9 +2210,10 @@ export const useTrestle = () => {
acc[key].push(module)
return acc
}, {})
groupedByLeft = mergeCloseKeys(groupedByLeft)
sameLineModuleList = Object.values(groupedByLeft).sort((a, b) => b[0].left - a[0].left)
} else if (direction === 'west') {
const groupedByLeft = modules.reduce((acc, module) => {
let groupedByLeft = modules.reduce((acc, module) => {
const key = module.left
if (!acc[key]) {
acc[key] = []
@ -2040,6 +2221,8 @@ export const useTrestle = () => {
acc[key].push(module)
return acc
}, {})
//groupedByLeft의 키값의 차이가 2이하인 경우 같은 라인으로 합친다.
groupedByLeft = mergeCloseKeys(groupedByLeft)
sameLineModuleList = Object.values(groupedByLeft).sort((a, b) => a[0].left - b[0].left)
}
@ -2219,80 +2402,243 @@ export const useTrestle = () => {
case 'south':
width = width + horizontal
height = height + vertical
bottomModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + height)) < maxY)
halfBottomLeftPoint = { x: x - width / 2, y: y + height }
halfBottomRightPoint = { x: x + width / 2, y: y + height }
topModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - height)) < maxY)
halfTopLeftPoint = { x: x - width / 2, y: y - height }
halfTopRightPoint = { x: x + width / 2, y: y - height }
leftPoint = { x: x - width, y: y }
rightPoint = { x: x + width, y: y }
bottomLeftModule = { x: x - width, y: y + height }
bottomRightModule = { x: x + width, y: y + height }
heightArr.forEach((h) => {
if (!bottomModule) {
bottomModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + h)) < maxY)
}
if (!topModule) {
topModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - h)) < maxY)
}
if (!halfBottomLeftModule) {
halfBottomLeftPoint = { x: x - width / 2, y: y + h }
halfBottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomLeftPoint.y) < maxY,
)
}
if (!halfBottomRightModule) {
halfBottomRightPoint = { x: x + width / 2, y: y + h }
halfBottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomRightPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomRightPoint.y) < maxY,
)
}
if (!halfTopLeftModule) {
halfTopLeftPoint = { x: x - width / 2, y: y - h }
halfTopLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfTopLeftPoint.y) < maxY,
)
}
if (!halfTopRightModule) {
halfTopRightPoint = { x: x + width / 2, y: y - h }
halfTopRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopRightPoint.x) < maxX && Math.abs(centerPoint.y - halfTopRightPoint.y) < maxY,
)
}
if (leftModule) {
leftPoint = { x: x - width, y: y }
leftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - leftPoint.x) < maxX && Math.abs(centerPoint.y - leftPoint.y) < maxY,
)
}
if (rightModule) {
rightPoint = { x: x + width, y: y }
rightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - rightPoint.x) < maxX && Math.abs(centerPoint.y - rightPoint.y) < maxY,
)
}
if (bottomLeftModule) {
bottomLeftPoint = { x: x - width, y: y + h }
bottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
)
}
if (bottomRightModule) {
bottomRightPoint = { x: x + width, y: y + h }
bottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
)
}
})
break
case 'north':
width = width + horizontal
height = height + vertical
bottomModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - height)) < maxY)
halfBottomLeftPoint = { x: x + width / 2, y: y - height }
halfBottomRightPoint = { x: x - width / 2, y: y - height }
topModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + height)) < maxY)
halfTopLeftPoint = { x: x + width / 2, y: y + height }
halfTopRightPoint = { x: x - width / 2, y: y + height }
leftPoint = { x: x + width, y: y }
rightPoint = { x: x - width, y: y }
bottomLeftModule = { x: x + width, y: y - height }
bottomRightModule = { x: x - width, y: y - height }
heightArr.forEach((h) => {
if (!bottomModule) {
bottomModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - h)) < maxY)
}
if (!topModule) {
topModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + h)) < maxY)
}
if (!halfBottomLeftModule) {
halfBottomLeftPoint = { x: x + width / 2, y: y - h }
halfBottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomLeftPoint.y) < maxY,
)
}
if (!halfBottomRightModule) {
halfBottomRightPoint = { x: x - width / 2, y: y - h }
halfBottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomRightPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomRightPoint.y) < maxY,
)
}
if (!halfTopLeftModule) {
halfTopLeftPoint = { x: x + width / 2, y: y + h }
halfTopLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfTopLeftPoint.y) < maxY,
)
}
if (!halfTopRightModule) {
halfTopRightPoint = { x: x - width / 2, y: y + h }
halfTopRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopRightPoint.x) < maxX && Math.abs(centerPoint.y - halfTopRightPoint.y) < maxY,
)
}
if (leftModule) {
leftPoint = { x: x + width, y: y }
leftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - leftPoint.x) < maxX && Math.abs(centerPoint.y - leftPoint.y) < maxY,
)
}
if (rightModule) {
rightPoint = { x: x - width, y: y }
rightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - rightPoint.x) < maxX && Math.abs(centerPoint.y - rightPoint.y) < maxY,
)
}
if (bottomLeftModule) {
bottomLeftPoint = { x: x + width, y: y - h }
bottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
)
}
if (bottomRightModule) {
bottomRightPoint = { x: x - width, y: y - h }
bottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
)
}
})
break
case 'east':
bottomModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x + width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
width = width + horizontal
halfBottomLeftPoint = { x: x + width, y: y + height / 2 }
halfBottomRightPoint = { x: x + width, y: y - height / 2 }
topModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x - width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
halfTopLeftPoint = { x: x - width, y: y + height / 2 }
halfTopRightPoint = { x: x - width, y: y - height / 2 }
leftPoint = { x: x, y: y + height }
rightPoint = { x: x, y: y - height }
bottomLeftModule = { x: x + width, y: y + height }
bottomRightModule = { x: x + width, y: y - height }
widthArr.forEach((w) => {
if (!bottomModule) {
bottomModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x + w)) < maxX && Math.abs(centerPoint.y - y) < maxY)
}
if (!topModule) {
topModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x - w)) < maxX && Math.abs(centerPoint.y - y) < maxY)
}
if (!halfBottomLeftModule) {
halfBottomLeftPoint = { x: x + w, y: y - height / 2 }
halfBottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomLeftPoint.y) < maxY,
)
}
if (!halfBottomRightModule) {
halfBottomRightPoint = { x: x + w, y: y - height / 2 }
halfBottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomRightPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomRightPoint.y) < maxY,
)
}
if (!halfTopLeftModule) {
halfTopLeftPoint = { x: x - w, y: y + height / 2 }
halfTopLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfTopLeftPoint.y) < maxY,
)
}
if (!halfTopRightModule) {
halfTopRightPoint = { x: x - w, y: y - height / 2 }
halfTopRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopRightPoint.x) < maxX && Math.abs(centerPoint.y - halfTopRightPoint.y) < maxY,
)
}
if (!leftModule) {
leftPoint = { x: x, y: y + height }
leftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - leftPoint.x) < maxX && Math.abs(centerPoint.y - leftPoint.y) < maxY,
)
}
if (!rightModule) {
rightPoint = { x: x, y: y - height }
rightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - rightPoint.x) < maxX && Math.abs(centerPoint.y - rightPoint.y) < maxY,
)
}
if (!bottomLeftModule) {
bottomLeftPoint = { x: x + w, y: y + height }
bottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
)
}
if (!bottomRightModule) {
bottomRightPoint = { x: x + w, y: y - height }
bottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
)
}
})
break
case 'west':
bottomModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x - width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
width = width + horizontal
halfBottomLeftPoint = { x: x - width, y: y - height / 2 }
halfBottomRightPoint = { x: x - width, y: y + height / 2 }
topModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x + width)) < maxX && Math.abs(centerPoint.y - y) < maxY)
halfTopLeftPoint = { x: x + width, y: y - height / 2 }
halfTopRightPoint = { x: x + width, y: y + height / 2 }
leftPoint = { x: x, y: y - height }
rightPoint = { x: x, y: y + height }
bottomLeftModule = { x: x - width, y: y - height }
bottomRightModule = { x: x - width, y: y + height }
widthArr.forEach((w) => {
if (!bottomModule) {
bottomModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x - w)) < maxX && Math.abs(centerPoint.y - y) < maxY)
}
if (!topModule) {
topModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - (x + w)) < maxX && Math.abs(centerPoint.y - y) < maxY)
}
if (!halfBottomLeftModule) {
halfBottomLeftPoint = { x: x - w, y: y - height / 2 }
halfBottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomLeftPoint.y) < maxY,
)
}
if (!halfBottomRightModule) {
halfBottomRightPoint = { x: x - w, y: y + height / 2 }
halfBottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomRightPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomRightPoint.y) < maxY,
)
}
if (!halfTopLeftModule) {
halfTopLeftPoint = { x: x + w, y: y - height / 2 }
halfTopLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfTopLeftPoint.y) < maxY,
)
}
if (!halfTopRightModule) {
halfTopRightPoint = { x: x + w, y: y + height / 2 }
halfTopRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopRightPoint.x) < maxX && Math.abs(centerPoint.y - halfTopRightPoint.y) < maxY,
)
}
if (!leftModule) {
leftPoint = { x: x, y: y - height }
leftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - leftPoint.x) < maxX && Math.abs(centerPoint.y - leftPoint.y) < maxY,
)
}
if (!rightModule) {
rightPoint = { x: x, y: y + height }
rightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - rightPoint.x) < maxX && Math.abs(centerPoint.y - rightPoint.y) < maxY,
)
}
if (!bottomLeftModule) {
bottomLeftPoint = { x: x - w, y: y - height }
bottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - bottomLeftPoint.y) < maxY,
)
}
if (!bottomRightModule) {
bottomRightPoint = { x: x - w, y: y + height }
bottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < maxX && Math.abs(centerPoint.y - bottomRightPoint.y) < maxY,
)
}
})
break
}
halfTopLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfTopLeftPoint.y) < maxY,
)
halfTopRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfTopRightPoint.x) < maxX && Math.abs(centerPoint.y - halfTopRightPoint.y) < maxY,
)
halfBottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomLeftPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomLeftPoint.y) < maxY,
)
halfBottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - halfBottomRightPoint.x) < maxX && Math.abs(centerPoint.y - halfBottomRightPoint.y) < maxY,
)
leftModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - leftPoint.x) < maxX && Math.abs(centerPoint.y - leftPoint.y) < maxY)
rightModule = centerPoints.find((centerPoint) => Math.abs(centerPoint.x - rightPoint.x) < maxX && Math.abs(centerPoint.y - rightPoint.y) < maxY)
bottomLeftModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomLeftModule.x) < maxX && Math.abs(centerPoint.y - bottomLeftModule.y) < maxY,
)
bottomRightModule = centerPoints.find(
(centerPoint) => Math.abs(centerPoint.x - bottomRightModule.x) < maxX && Math.abs(centerPoint.y - bottomRightModule.y) < maxY,
)
return {
bottomModule,
topModule,