moduleSetupSurfaces 별 계산 작업중
This commit is contained in:
parent
fecae44c9a
commit
dd92a47b0b
@ -955,120 +955,128 @@ export function useModuleBasicSetting() {
|
|||||||
|
|
||||||
const calculateForApi = () => {
|
const calculateForApi = () => {
|
||||||
// TODO : 현재는 남쪽기준. 동,서,북 분기처리 필요
|
// TODO : 현재는 남쪽기준. 동,서,북 분기처리 필요
|
||||||
const centerPoints = []
|
|
||||||
const modules = canvas.getObjects().filter((obj) => obj.name === 'module')
|
|
||||||
|
|
||||||
modules.forEach((module, index) => {
|
const moduleSufaces = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE)
|
||||||
module.tempIndex = index
|
const results = []
|
||||||
const { x, y } = module.getCenterPoint()
|
|
||||||
const { width, height } = module
|
moduleSufaces.forEach((moduleSurface) => {
|
||||||
centerPoints.push({ x, y, width: Math.abs(width), height: Math.abs(height), index })
|
const centerPoints = []
|
||||||
const circle = new fabric.Circle({
|
const modules = moduleSurface.modules
|
||||||
radius: 5,
|
|
||||||
fill: 'red',
|
modules.forEach((module, index) => {
|
||||||
name: 'redCircle',
|
module.tempIndex = index
|
||||||
left: x - 5,
|
const { x, y } = module.getCenterPoint()
|
||||||
top: y - 5,
|
const { width, height } = module
|
||||||
index: index,
|
centerPoints.push({ x, y, width: Math.abs(width), height: Math.abs(height), index })
|
||||||
selectable: false,
|
const circle = new fabric.Circle({
|
||||||
|
radius: 5,
|
||||||
|
fill: 'red',
|
||||||
|
name: 'redCircle',
|
||||||
|
left: x - 5,
|
||||||
|
top: y - 5,
|
||||||
|
index: index,
|
||||||
|
selectable: false,
|
||||||
|
})
|
||||||
|
// canvas.add(circle)
|
||||||
|
})
|
||||||
|
|
||||||
|
//완전 노출 하면
|
||||||
|
let exposedBottom = 0
|
||||||
|
// 반 노출 하면
|
||||||
|
let exposedHalfBottom = 0
|
||||||
|
// 완전 노출 상면
|
||||||
|
let exposedTop = 0
|
||||||
|
//반 노출 상면
|
||||||
|
let exposedHalfTop = 0
|
||||||
|
// 완전 접면
|
||||||
|
let touchDimension = 0
|
||||||
|
//반접면
|
||||||
|
let halfTouchDimension = 0
|
||||||
|
// 노출하면 체크
|
||||||
|
centerPoints.forEach((centerPoint, index) => {
|
||||||
|
const { x, y, width, height } = centerPoint
|
||||||
|
// centerPoints중에 현재 centerPoint와 x값이 같고, y값이 y-height값과 같은 centerPoint가 있는지 확인
|
||||||
|
const bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < 2 && Math.abs(centerPoint.y - (y + height)) < 2)
|
||||||
|
if (bottomCell.length === 1) {
|
||||||
|
touchDimension++
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const bottomLeftPoint = { x: x - width / 2, y: y + height }
|
||||||
|
const bottomRightPoint = { x: x + width / 2, y: y + height }
|
||||||
|
|
||||||
|
// 바로 아래에 셀이 없는 경우 물떼세 배치가 왼쪽 되어있는 셀을 찾는다.
|
||||||
|
const leftBottomCnt = centerPoints.filter(
|
||||||
|
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < 2 && Math.abs(centerPoint.y - bottomLeftPoint.y) < 2,
|
||||||
|
).length
|
||||||
|
const rightBottomCnt = centerPoints.filter(
|
||||||
|
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < 2 && Math.abs(centerPoint.y - bottomRightPoint.y) < 2,
|
||||||
|
).length
|
||||||
|
if (leftBottomCnt + rightBottomCnt === 2) {
|
||||||
|
touchDimension++
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (leftBottomCnt + rightBottomCnt === 1) {
|
||||||
|
halfTouchDimension++
|
||||||
|
exposedHalfBottom++
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 노출상면 체크
|
||||||
|
|
||||||
|
centerPoints.forEach((centerPoint, index) => {
|
||||||
|
const { x, y, width, height } = centerPoint
|
||||||
|
const topCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < 2 && Math.abs(centerPoint.y - (y - height)) < 2)
|
||||||
|
if (topCell.length === 1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const topLeftPoint = { x: x - width / 2, y: y - height }
|
||||||
|
const topRightPoint = { x: x + width / 2, y: y - height }
|
||||||
|
|
||||||
|
const leftTopCnt = centerPoints.filter(
|
||||||
|
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < 2 && Math.abs(centerPoint.y - topRightPoint.y) < 2,
|
||||||
|
).length
|
||||||
|
const rightTopCnt = centerPoints.filter(
|
||||||
|
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < 2 && Math.abs(centerPoint.y - topRightPoint.y) < 2,
|
||||||
|
).length
|
||||||
|
|
||||||
|
if (leftTopCnt + rightTopCnt === 1) {
|
||||||
|
exposedHalfTop++
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (leftTopCnt + rightTopCnt === 0) {
|
||||||
|
exposedTop++
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 완전 노출 하면 계산
|
||||||
|
|
||||||
|
/*const cells = canvas.getObjects().filter((obj) => polygon.id === obj.parentId)
|
||||||
|
const points = cells.map((cell) => {
|
||||||
|
return cell.getCenterPoint()
|
||||||
|
})*/
|
||||||
|
const groupPoints = groupCoordinates(centerPoints, modules[0])
|
||||||
|
console.log('groupPoints', groupPoints)
|
||||||
|
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
|
||||||
|
})
|
||||||
|
|
||||||
|
results.push({
|
||||||
|
exposedBottom,
|
||||||
|
exposedHalfBottom,
|
||||||
|
exposedTop,
|
||||||
|
exposedHalfTop,
|
||||||
|
touchDimension,
|
||||||
|
halfTouchDimension,
|
||||||
})
|
})
|
||||||
// canvas.add(circle)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
//완전 노출 하면
|
return results
|
||||||
let exposedBottom = 0
|
|
||||||
// 반 노출 하면
|
|
||||||
let exposedHalfBottom = 0
|
|
||||||
// 완전 노출 상면
|
|
||||||
let exposedTop = 0
|
|
||||||
//반 노출 상면
|
|
||||||
let exposedHalfTop = 0
|
|
||||||
// 완전 접면
|
|
||||||
let touchDimension = 0
|
|
||||||
//반접면
|
|
||||||
let halfTouchDimension = 0
|
|
||||||
// 노출하면 체크
|
|
||||||
centerPoints.forEach((centerPoint, index) => {
|
|
||||||
const { x, y, width, height } = centerPoint
|
|
||||||
// centerPoints중에 현재 centerPoint와 x값이 같고, y값이 y-height값과 같은 centerPoint가 있는지 확인
|
|
||||||
const bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < 2 && Math.abs(centerPoint.y - (y + height)) < 2)
|
|
||||||
if (bottomCell.length === 1) {
|
|
||||||
touchDimension++
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const bottomLeftPoint = { x: x - width / 2, y: y + height }
|
|
||||||
const bottomRightPoint = { x: x + width / 2, y: y + height }
|
|
||||||
|
|
||||||
// 바로 아래에 셀이 없는 경우 물떼세 배치가 왼쪽 되어있는 셀을 찾는다.
|
|
||||||
const leftBottomCnt = centerPoints.filter(
|
|
||||||
(centerPoint) => Math.abs(centerPoint.x - bottomLeftPoint.x) < 2 && Math.abs(centerPoint.y - bottomLeftPoint.y) < 2,
|
|
||||||
).length
|
|
||||||
const rightBottomCnt = centerPoints.filter(
|
|
||||||
(centerPoint) => Math.abs(centerPoint.x - bottomRightPoint.x) < 2 && Math.abs(centerPoint.y - bottomRightPoint.y) < 2,
|
|
||||||
).length
|
|
||||||
if (leftBottomCnt + rightBottomCnt === 2) {
|
|
||||||
touchDimension++
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (leftBottomCnt + rightBottomCnt === 1) {
|
|
||||||
halfTouchDimension++
|
|
||||||
exposedHalfBottom++
|
|
||||||
return
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// 노출상면 체크
|
|
||||||
|
|
||||||
centerPoints.forEach((centerPoint, index) => {
|
|
||||||
const { x, y, width, height } = centerPoint
|
|
||||||
const topCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < 2 && Math.abs(centerPoint.y - (y - height)) < 2)
|
|
||||||
if (topCell.length === 1) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const topLeftPoint = { x: x - width / 2, y: y - height }
|
|
||||||
const topRightPoint = { x: x + width / 2, y: y - height }
|
|
||||||
|
|
||||||
const leftTopCnt = centerPoints.filter(
|
|
||||||
(centerPoint) => Math.abs(centerPoint.x - topLeftPoint.x) < 2 && Math.abs(centerPoint.y - topRightPoint.y) < 2,
|
|
||||||
).length
|
|
||||||
const rightTopCnt = centerPoints.filter(
|
|
||||||
(centerPoint) => Math.abs(centerPoint.x - topRightPoint.x) < 2 && Math.abs(centerPoint.y - topRightPoint.y) < 2,
|
|
||||||
).length
|
|
||||||
|
|
||||||
if (leftTopCnt + rightTopCnt === 1) {
|
|
||||||
exposedHalfTop++
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (leftTopCnt + rightTopCnt === 0) {
|
|
||||||
exposedTop++
|
|
||||||
return
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// 완전 노출 하면 계산
|
|
||||||
|
|
||||||
/*const cells = canvas.getObjects().filter((obj) => polygon.id === obj.parentId)
|
|
||||||
const points = cells.map((cell) => {
|
|
||||||
return cell.getCenterPoint()
|
|
||||||
})*/
|
|
||||||
const groupPoints = groupCoordinates(centerPoints, modules[0])
|
|
||||||
console.log('groupPoints', groupPoints)
|
|
||||||
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,
|
|
||||||
exposedTop,
|
|
||||||
exposedHalfTop,
|
|
||||||
touchDimension,
|
|
||||||
halfTouchDimension,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// polygon 내부 cell들의 centerPoint 배열을 그룹화 해서 반환
|
// polygon 내부 cell들의 centerPoint 배열을 그룹화 해서 반환
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user