모듈 그룹화 작업중
This commit is contained in:
parent
d386c42c08
commit
265593f6dd
@ -2131,12 +2131,13 @@ export const useTrestle = () => {
|
||||
const visited = new Set()
|
||||
const width = Math.floor(moduleExample.width)
|
||||
const height = Math.floor(moduleExample.height)
|
||||
const horizonPadding = 0 // 가로 패딩
|
||||
const verticalPadding = 0 // 세로 패딩
|
||||
const horizonPadding = 3 // 가로 패딩
|
||||
const verticalPadding = 7 // 세로 패딩
|
||||
|
||||
function isAdjacent(p1, p2) {
|
||||
const dx = Math.abs(p1.x - p2.x)
|
||||
const dy = Math.abs(p1.y - p2.y)
|
||||
|
||||
return (
|
||||
(Math.abs(width + horizonPadding - dx) < 2 && dy < 2) ||
|
||||
(dx < 2 && Math.abs(dy - height + verticalPadding)) < 2 ||
|
||||
@ -2168,6 +2169,128 @@ export const useTrestle = () => {
|
||||
return groups
|
||||
}
|
||||
|
||||
function areConnected(m1, m2, surface) {
|
||||
/*const m1Fill = m1.fill
|
||||
const m2Fill = m2.fill
|
||||
m1.set({ fill: 'red' })
|
||||
m2.set({ fill: 'blue' })
|
||||
canvas.renderAll()*/
|
||||
|
||||
let sizes = []
|
||||
|
||||
const { width: currentWidth, height: currentHeight, moduleInfo: currentModuleInfo } = m1
|
||||
const { width: neighborWidth, height: neighborHeight, moduleInfo: neighborModuleInfo } = m2
|
||||
|
||||
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 })
|
||||
m2.set({ fill: m2Fill })
|
||||
canvas.renderAll()*/
|
||||
|
||||
return sizes.some(({ width, height }) => {
|
||||
let maxX
|
||||
let maxY
|
||||
let halfMaxX
|
||||
let halfMaxY
|
||||
const { direction, trestleDetail } = surface
|
||||
const { moduleIntvlHor, moduleIntvlVer } = trestleDetail
|
||||
|
||||
if (direction === 'south' || direction === 'north') {
|
||||
maxX = width + moduleIntvlHor / 10
|
||||
maxY = height + moduleIntvlVer / 10
|
||||
halfMaxX = moduleIntvlHor / 10
|
||||
halfMaxY = moduleIntvlVer / 10
|
||||
|
||||
if (currentModuleTpCd !== neighborModuleTpCd) {
|
||||
maxX = currentWidth / 2 + neighborWidth / 2 + moduleIntvlHor / 10
|
||||
maxY = currentHeight / 2 + neighborHeight / 2 + moduleIntvlVer / 10
|
||||
}
|
||||
|
||||
// console.log(maxX, maxY, halfMaxX, halfMaxY)
|
||||
|
||||
if (Math.abs(m1X - m2X) < 1) {
|
||||
return Math.abs(Math.abs(m1Y - m2Y) - maxY) < 1
|
||||
} else if (Math.abs(m1Y - m2Y) < 1) {
|
||||
return Math.abs(Math.abs(m1X - m2X) - maxX) < 1
|
||||
}
|
||||
|
||||
return (
|
||||
(Math.abs(m1X - m2X) <= maxX && Math.abs(m1Y - m2Y) <= maxY) ||
|
||||
(Math.abs(Math.abs(m1X - m2X) - maxX / 2) <= halfMaxX && Math.abs(Math.abs(m1Y - m2Y) - maxY) <= halfMaxY) ||
|
||||
(Math.abs(Math.abs(m1X - m2X) - maxX) <= halfMaxX && Math.abs(Math.abs(m1Y - m2Y) - maxY / 2) <= halfMaxY)
|
||||
)
|
||||
} else if (direction === 'east' || direction === 'west') {
|
||||
maxX = height + moduleIntvlHor / 10
|
||||
maxY = width + moduleIntvlVer / 10
|
||||
halfMaxX = moduleIntvlVer / 10
|
||||
halfMaxY = moduleIntvlHor / 10
|
||||
|
||||
if (currentModuleTpCd !== neighborModuleTpCd) {
|
||||
maxX = currentHeight / 2 + neighborHeight / 2 + moduleIntvlVer / 10
|
||||
maxY = currentWidth / 2 + neighborWidth / 2 + moduleIntvlHor / 10
|
||||
}
|
||||
|
||||
if (Math.abs(m1X - m2X) < 1) {
|
||||
return Math.abs(Math.abs(m1Y - m2Y) - maxX) < 1
|
||||
} else if (Math.abs(m1Y - m2Y) < 1) {
|
||||
return Math.abs(Math.abs(m1X - m2X) - maxY) < 1
|
||||
}
|
||||
|
||||
return (
|
||||
(Math.abs(m1X - m2X) <= maxY && Math.abs(m1Y - m2Y) <= maxX) ||
|
||||
(Math.abs(Math.abs(m1X - m2X) - maxY / 2) <= halfMaxY && Math.abs(Math.abs(m1Y - m2Y) - maxX) <= halfMaxX) ||
|
||||
(Math.abs(Math.abs(m1X - m2X) - maxY) <= halfMaxY && Math.abs(Math.abs(m1Y - m2Y) - maxX / 2) <= halfMaxX)
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 25-04-02 추가
|
||||
// 그룹화
|
||||
function groupPoints(modules, surface) {
|
||||
const groups = []
|
||||
const visited = new Set()
|
||||
|
||||
for (const point of modules) {
|
||||
const { x: pointX, y: pointY } = point.getCenterPoint()
|
||||
const key = `${pointX},${pointY}`
|
||||
if (visited.has(key)) continue
|
||||
|
||||
const queue = [point]
|
||||
const group = []
|
||||
|
||||
while (queue.length > 0) {
|
||||
const current = queue.shift()
|
||||
const { x: currentX, y: currentY } = current.getCenterPoint()
|
||||
const currentKey = `${currentX},${currentY}`
|
||||
if (visited.has(currentKey)) continue
|
||||
|
||||
visited.add(currentKey)
|
||||
group.push(current)
|
||||
|
||||
for (const neighbor of modules) {
|
||||
const { x: neighborX, y: neighborY } = neighbor.getCenterPoint()
|
||||
const neighborKey = `${neighborX},${neighborY}`
|
||||
if (!visited.has(neighborKey) && areConnected(current, neighbor, surface)) {
|
||||
queue.push(neighbor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
groups.push(group)
|
||||
}
|
||||
|
||||
return groups
|
||||
}
|
||||
|
||||
// 각도에 따른 길이 반환
|
||||
function getTrestleLength(length, degree) {
|
||||
if (roofSizeSet !== 1) {
|
||||
@ -2865,5 +2988,15 @@ export const useTrestle = () => {
|
||||
return surfaces.every((surface) => surface.isComplete)
|
||||
}
|
||||
|
||||
return { apply, getTrestleParams, clear, setViewCircuitNumberTexts, getEstimateData, setAllModuleSurfaceIsComplete, isAllComplete }
|
||||
return {
|
||||
apply,
|
||||
getTrestleParams,
|
||||
clear,
|
||||
setViewCircuitNumberTexts,
|
||||
getEstimateData,
|
||||
setAllModuleSurfaceIsComplete,
|
||||
isAllComplete,
|
||||
groupCoordinates,
|
||||
groupPoints,
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user