지붕 덮개 계산 오류 수정

This commit is contained in:
Jaeyoung Lee 2025-03-18 16:23:38 +09:00
parent 509c307e56
commit 3b41952070

View File

@ -854,6 +854,13 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
/** ⨆ 모양 처마에 추녀마루를 그린다. */
drawEavesFirstLines.forEach((current) => {
// 확인용 라인, 포인트 제거
/*canvas
.getObjects()
.filter((obj) => obj.name === 'checkPoint' || obj.name === 'checkLine')
.forEach((obj) => canvas.remove(obj))
canvas.renderAll()
*/
const { currentLine, prevLine, nextLine } = current
let { x1, x2, y1, y2 } = currentLine
let beforePrevLine, afterNextLine
@ -934,13 +941,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
},
}
/*const checkMidLine = new fabric.Line([midLineEdge.vertex1.x, midLineEdge.vertex1.y, midLineEdge.vertex2.x, midLineEdge.vertex2.y], {
stroke: 'blue',
strokeWidth: 2,
})
canvas.add(checkMidLine)
canvas.renderAll()*/
/** 현재 라인의 중심 지점에서 현재라인의 길이만큼 다음라인의 방향만큼 거리를 확인한다*/
baseLines
.filter((line) => line !== currentLine)
@ -981,7 +981,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
).length > 0
/** 6각 */
// console.log('isConnect : ', isConnect)
if (isConnect) {
const checkScale = currentSize.pow(2).plus(currentSize.pow(2)).sqrt()
const intersectBaseLine = []
@ -998,15 +997,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
{ vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } },
)
if (intersection && !intersection.isIntersectionOutside) {
/*const intersectCircle = new fabric.Circle({
left: intersection.x - 2,
top: intersection.y - 2,
radius: 4,
fill: 'red',
parentId: roof.id,
})
canvas.add(intersectCircle)
canvas.renderAll()*/
intersectBaseLine.push({
intersection,
distance: Big(intersection.x)
@ -1031,15 +1021,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
{ vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } },
)
if (intersection && !intersection.isIntersectionOutside) {
/*const intersectCircle = new fabric.Circle({
left: intersection.x - 2,
top: intersection.y - 2,
radius: 4,
fill: 'orange',
parentId: roof.id,
})
canvas.add(intersectCircle)
canvas.renderAll()*/
intersectBaseLine.push({
intersection,
distance: Big(intersection.x)
@ -1053,28 +1034,9 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
}
const intersection = intersectBaseLine.reduce((prev, current) => (prev.distance < current.distance ? prev : current), intersectBaseLine[0])
if (intersection) {
/*const intersectCircle = new fabric.Circle({
left: intersection.intersection.x - 2,
top: intersection.intersection.y - 2,
radius: 4,
fill: 'green',
parentId: roof.id,
})
canvas.add(intersectCircle)
canvas.renderAll()*/
hipLength = intersection.distance
}
} else {
//라인 확인용
/*const checkCurrentLine = new fabric.Line([x1, y1, x2, y2], {
stroke: 'yellow',
strokeWidth: 4,
parentId: roof.id,
})
canvas.add(checkCurrentLine)
canvas.renderAll()*/
const rightAngleLine = baseLines
.filter(
(line) =>
@ -1151,39 +1113,14 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
]
}
/* const checkHipLine = new fabric.Line(checkHipPoints, {
stroke: 'red',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkHipLine)
canvas.renderAll()*/
if (checkHipPoints) {
const intersectPoints = []
rightAngleLine.forEach((line) => {
/*const checkRightAngle = new fabric.Line([line.x1, line.y1, line.x2, line.y2], {
stroke: 'red',
strokeWidth: 4,
parentId: roof.id,
})
canvas.add(checkRightAngle)
canvas.renderAll()*/
const intersection = edgesIntersection(
{ vertex1: { x: checkHipPoints[0], y: checkHipPoints[1] }, vertex2: { x: checkHipPoints[2], y: checkHipPoints[3] } },
{ vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } },
)
if (intersection) {
/*const checkRightAngleCircle = new fabric.Circle({
left: intersection.x - 2,
top: intersection.y - 2,
radius: 4,
fill: 'red',
parentId: roof.id,
})
canvas.add(checkRightAngleCircle)
canvas.renderAll()*/
intersectPoints.push({
intersection,
distance: Big(intersection.x)
@ -1196,28 +1133,11 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
})
oppositeCurrentLine.forEach((line) => {
/*const checkOpposite = new fabric.Line([line.x1, line.y1, line.x2, line.y2], {
stroke: 'blue',
strokeWidth: 4,
parentId: roof.id,
})
canvas.add(checkOpposite)
canvas.renderAll()
*/
const intersection = edgesIntersection(
{ vertex1: { x: checkHipPoints[0], y: checkHipPoints[1] }, vertex2: { x: checkHipPoints[2], y: checkHipPoints[3] } },
{ vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } },
)
if (intersection) {
/*const checkOppositeCircle = new fabric.Circle({
left: intersection.x - 2,
top: intersection.y - 2,
radius: 4,
fill: 'blue',
parentId: roof.id,
})
canvas.add(checkOppositeCircle)
canvas.renderAll()*/
intersectPoints.push({
intersection,
distance: Big(intersection.x)
@ -1229,19 +1149,8 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
}
})
// console.log('intersectPoints : ', intersectPoints)
const intersection = intersectPoints.reduce((prev, current) => (prev.distance.lt(current.distance) ? prev : current), intersectPoints[0])
if (intersection) {
/*const checkHipCircle = new fabric.Circle({
left: intersection.intersection.x - 2,
top: intersection.intersection.y - 2,
radius: 4,
fill: 'green',
parentId: roof.id,
})
canvas.add(checkHipCircle)
canvas.renderAll()*/
hipLength = intersection.distance.div(2)
}
}
@ -1263,7 +1172,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
{ vertex1: { x: x1, y: y1 }, vertex2: prevEndPoint },
{ vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } },
)
// console.log('intersection : ', intersection, 'prevEndPoint : ', prevEndPoint.x.toNumber(), prevEndPoint.y.toNumber())
if (intersection && !intersection.isIntersectionOutside) {
intersectRidgeLine.push({
intersection,
@ -1276,7 +1184,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
}
})
const intersectRidge = intersectRidgeLine.reduce((prev, current) => (prev.distance < current.distance ? prev : current), intersectRidgeLine[0])
// console.log('intersectRidge : ', intersectRidge)
if (intersectRidge) {
prevEndPoint.x = Big(intersectRidge.intersection.x).round(1)
@ -1295,14 +1202,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
vertex2: prevEndPoint,
}
/*const checkLine = new fabric.Line([hipEdge.vertex1.x, hipEdge.vertex1.y, hipEdge.vertex2.x, hipEdge.vertex2.y], {
stroke: 'yellow',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()*/
let intersectPoints = []
/** 외벽선에서 추녀 마루가 겹치는 경우에 대한 확인*/
roof.lines.forEach((line) => {
@ -1314,16 +1213,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
Math.sign(prevEndPoint.x - x1) === Math.sign(prevEndPoint.x - intersection.x) &&
Math.sign(prevEndPoint.y - y1) === Math.sign(prevEndPoint.y - intersection.y)
) {
/* const intersectPoint = new fabric.Circle({
left: intersection.x - 2,
top: intersection.y - 2,
radius: 4,
fill: 'red',
parentId: roof.id,
})
canvas.add(intersectPoint)
canvas.renderAll()*/
const intersectSize = prevEndPoint.x
.minus(Big(intersection.x))
.pow(2)
@ -1367,13 +1256,11 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
const intersectRidgeLine = []
baseRidgeLines.forEach((line) => {
// console.log('nextEndPoint : ', nextEndPoint.x.toNumber(), nextEndPoint.y.toNumber())
// console.log('intersection : ', 'x : ', line.x1, 'y : ', line.y1, 'x : ', line.x2, 'y : ', line.y2)
const intersection = edgesIntersection(
{ vertex1: { x: x2, y: y2 }, vertex2: nextEndPoint },
{ vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } },
)
// console.log('intersection : ', intersection, 'nextEndPoint : ', nextEndPoint.x.toNumber(), nextEndPoint.y.toNumber())
if (intersection && !intersection.isIntersectionOutside) {
intersectRidgeLine.push({
intersection,
@ -1386,7 +1273,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
}
})
const intersectRidge = intersectRidgeLine.reduce((prev, current) => (prev.distance < current.distance ? prev : current), intersectRidgeLine[0])
// console.log('intersectRidge : ', intersectRidge)
if (intersectRidge) {
nextEndPoint.x = Big(intersectRidge.intersection.x).round(1)
@ -1403,38 +1289,16 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
vertex2: nextEndPoint,
}
/* const checkLine = new fabric.Line([hipEdge.vertex1.x, hipEdge.vertex1.y, hipEdge.vertex2.x, hipEdge.vertex2.y], {
stroke: 'yellow',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()*/
let intersectPoints = []
roof.lines.forEach((line) => {
const lineEdge = { vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } }
const intersection = edgesIntersection(hipEdge, lineEdge)
// console.log('intersection', intersection)
if (
intersection &&
!intersection.isIntersectionOutside &&
Math.sign(nextEndPoint.x - x2) === Math.sign(nextEndPoint.x - intersection.x) &&
Math.sign(nextEndPoint.y - y2) === Math.sign(nextEndPoint.y - intersection.y)
) {
/*const intersectPoint = new fabric.Circle({
left: intersection.x - 2,
top: intersection.y - 2,
radius: 4,
fill: 'blue',
parentId: roof.id,
})
canvas.add(intersectPoint)
canvas.renderAll()*/
// console.log('nextEndPoint', nextEndPoint.x.toNumber(), nextEndPoint.y.toNumber())
// console.log('intersection', intersection.x, intersection.y)
const intersectSize = nextEndPoint.x
.minus(Big(intersection.x))
.pow(2)
@ -1454,8 +1318,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
return prev.size < current.size ? prev : current
}, intersectPoints[0])
// console.log('intersectPoints : ', intersectPoints)
if (intersectPoints && intersectPoints.intersection) {
nextHipLine = drawHipLine(
[intersectPoints.intersection.x, intersectPoints.intersection.y, nextEndPoint.x.toNumber(), nextEndPoint.y.toNumber()],
@ -2154,44 +2016,80 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
}
})
/** baseHipLine 이 ridge에 붙지 않은 경우 확인 */
baseHipLines.forEach((hipLine) => {
const ridgeCount = baseRidgeLines.filter(
(ridgeLine) => (hipLine.x2 === ridgeLine.x1 && hipLine.y2 === ridgeLine.y1) || (hipLine.x2 === ridgeLine.x2 && hipLine.y2 === ridgeLine.y2),
).length
if (ridgeCount === 0) {
const hipXVector = Big(hipLine.x2).minus(hipLine.x1)
const hipYVector = Big(hipLine.y2).minus(hipLine.y1)
const hipSize = hipXVector.abs().pow(2).plus(hipYVector.abs().pow(2)).sqrt()
const intersectRidgePoints = []
const hipLineEdge = { vertex1: { x: hipLine.x1, y: hipLine.y1 }, vertex2: { x: hipLine.x2, y: hipLine.y2 } }
baseRidgeLines.forEach((ridgeLine) => {
const ridgeLineEdge = { vertex1: { x: ridgeLine.x1, y: ridgeLine.y1 }, vertex2: { x: ridgeLine.x2, y: ridgeLine.y2 } }
const intersection = edgesIntersection(hipLineEdge, ridgeLineEdge)
if (intersection) {
const intersectXVector = Big(intersection.x).minus(Big(hipLine.x1))
const intersectYVector = Big(intersection.y).minus(Big(hipLine.y1))
const intersectSize = intersectXVector.pow(2).plus(intersectYVector.pow(2)).sqrt()
if (!intersection.isIntersectionOutside) {
intersectRidgePoints.push({
x: intersection.x,
y: intersection.y,
size: intersectSize,
})
} else if (
((intersection.x === ridgeLine.x1 && intersection.y === ridgeLine.y1) ||
(intersection.x === ridgeLine.x2 && intersection.y === ridgeLine.y2)) &&
Math.sign(hipXVector.toNumber()) === Math.sign(intersectXVector.toNumber()) &&
Math.sign(hipYVector.toNumber()) === Math.sign(intersectYVector.toNumber()) &&
intersectSize.gt(0) &&
intersectSize.lt(hipSize)
) {
intersectRidgePoints.push({
x: intersection.x,
y: intersection.y,
size: intersectSize,
})
}
}
})
intersectRidgePoints.sort((prev, current) => prev.size.minus(current.size).toNumber())
if (intersectRidgePoints.length > 0) {
const oldPlaneSize = hipLine.line.attributes.planeSize
const oldActualSize = hipLine.line.attributes.actualSize
const theta = Big(Math.acos(Big(oldPlaneSize).div(oldActualSize)))
.times(180)
.div(Math.PI)
const planeSize = calcLinePlaneSize({ x1: hipLine.line.x1, y1: hipLine.line.y1, x2: hipLine.line.x2, y2: hipLine.line.y2 })
hipLine.x2 = intersectRidgePoints[0].x
hipLine.y2 = intersectRidgePoints[0].y
hipLine.line.set({ x2: intersectRidgePoints[0].x, y2: intersectRidgePoints[0].y })
hipLine.line.attributes.planeSize = planeSize
hipLine.line.attributes.actualSize = planeSize === oldActualSize ? 0 : Big(planeSize).div(theta).round(1).toNumber()
hipLine.line.fire('modified')
}
}
})
// console.log('baseHipLines : ', baseHipLines)
// console.log('baseRidgeLines : ', baseRidgeLines)
/** 지붕선에 맞닫지 않은 부분을 확인하여 처리 한다.*/
/** 1. 그려진 마루 중 추녀마루가 부재하는 경우를 판단. 부재는 연결된 라인이 홀수인 경우로 판단한다.*/
let unFinishedRidge = []
baseRidgeLines.forEach((current) => {
/*const checkLine = new fabric.Line([current.x1, current.y1, current.x2, current.y2], {
stroke: 'red',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()*/
let checkPoint = [
{ x: current.x1, y: current.y1, line: current, cnt: 0 },
{ x: current.x2, y: current.y2, line: current, cnt: 0 },
]
baseHipLines.forEach((line) => {
/*const checkPoint1 = new fabric.Circle({
left: line.x1,
top: line.y1,
radius: 4,
fill: 'red',
parentId: roof.id,
})
const checkPoint2 = new fabric.Circle({
left: line.x2,
top: line.y2,
radius: 4,
fill: 'blue',
})
canvas.add(checkPoint1)
canvas.add(checkPoint2)
canvas.renderAll()*/
// console.log('current : ', current.x1, current.y1, current.x2, current.y2)
// console.log('line : ', line.x1, line.y1, line.x2, line.y2)
if ((line.x1 === current.x1 && line.y1 === current.y1) || (line.x2 === current.x1 && line.y2 === current.y1)) {
checkPoint[0].cnt = checkPoint[0].cnt + 1
}
@ -2207,19 +2105,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
unFinishedRidge.push(checkPoint[1])
}
})
// console.log('unFinishedRidge : ', unFinishedRidge)
//포인트 확인
/*unFinishedRidge.forEach((current) => {
const checkCircle = new fabric.Circle({
left: current.x,
top: current.y,
radius: 4,
fill: 'green',
parentId: roof.id,
})
canvas.add(checkCircle)
canvas.renderAll()
})*/
/** 2. 그려진 추녀마루 중 완성되지 않은 것을 찾는다. 완성되지 않았다는 것은 연결된 포인트가 홀수인 경우로 판단한다.*/
const findUnFinishedPoints = (baseHipLines) => {
@ -2259,7 +2144,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
}
let unFinishedPoint = findUnFinishedPoints(baseHipLines)
// console.log('unFinishedPoint : ', unFinishedPoint)
/**3. 라인이 부재인 마루의 모자란 라인을 찾는다. 라인은 그려진 추녀마루 중에 완성되지 않은 추녀마루와 확인한다.*/
/**3-1 라인을 그릴때 각도가 필요하기 때문에 각도를 구한다. 각도는 전체 지부의 각도가 같다면 하나로 처리 */
@ -2267,50 +2151,18 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
baseLines.forEach((line) => {
const pitch = line.attributes.pitch
const degree = line.attributes.degree
// console.log('pitch : ', pitch, 'degree : ', degree)
degreeAllLine.push(pitch > 0 ? getDegreeByChon(pitch) : degree)
})
let currentDegree, prevDegree
degreeAllLine = [...new Set(degreeAllLine)]
// console.log('degreeAllLine : ', degreeAllLine)
currentDegree = degreeAllLine[0]
if (degreeAllLine.length === 1) {
prevDegree = currentDegree
}
/*unFinishedPoint.forEach((current) => {
const circle = new fabric.Circle({
left: current.x,
top: current.y,
radius: 4,
fill: 'red',
parentId: roof.id,
})
canvas.add(circle)
canvas.renderAll()
})*/
/** 라인이 부재한 마루에 라인을 찾아 그린다.*/
unFinishedRidge.forEach((current) => {
/*const checkLine = new fabric.Line([current.line.x1, current.line.y1, current.line.x2, current.line.y2], {
stroke: 'red',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()*/
/*const checkCircle = new fabric.Circle({
left: current.x,
top: current.y,
radius: 4,
fill: 'green',
parentId: roof.id,
})
canvas.add(checkCircle)
canvas.renderAll()*/
let checkPoints = []
unFinishedPoint
@ -2326,25 +2178,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
.lt(1),
)
.forEach((point) => {
/*console.log('point : ', point.x, point.y)
const circle = new fabric.Circle({
left: point.x,
top: point.y,
radius: 4,
fill: 'red',
parentId: roof.id,
})
canvas.add(circle)
canvas.renderAll()
const checkLine = new fabric.Line([current.x, current.y, point.x, point.y], {
stroke: 'green',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()*/
const pointEdge = { vertex1: { x: point.x, y: point.y }, vertex2: { x: current.x, y: current.y } }
let isIntersection = false
baseLines.forEach((line) => {
@ -2366,37 +2199,11 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
})
}
})
// console.log('checkPoints : ', checkPoints)
// console.log('current ridge: ', current)
/*const checkCurrent = new fabric.Circle({
left: current.x,
top: current.y,
radius: 4,
fill: 'blue',
parentId: roof.id,
})
canvas.add(checkCurrent)
canvas.renderAll()*/
if (checkPoints.length > 0) {
/*checkPoints.forEach((point) => {
const checkPoints = new fabric.Circle({
left: point.point.x,
top: point.point.y,
radius: 4,
fill: 'red',
parentId: roof.id,
})
canvas.add(checkPoints)
canvas.renderAll()
})*/
checkPoints.sort((a, b) => a.size - b.size)
// console.log('Big(2).minus(Big(current.cnt) : ', Big(2).minus(Big(current.cnt)).toNumber(), current.cnt)
const maxCnt = Big(2).minus(Big(current.cnt)).toNumber()
for (let i = 0; i < maxCnt; i++) {
const checkPoint = checkPoints[i]
// console.log('current : ', current.line.attributes.planeSize)
// console.log('1. checkPoint : ', checkPoint)
if (checkPoint) {
let point = [checkPoint.point.x, checkPoint.point.y, current.x, current.y]
let hipBasePoint
@ -2422,27 +2229,9 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
{ x: line.line.x2, y: line.line.y2 },
]
/** baseHipLines도 조정*/
/*const mergeBasePoint = [
{ x: point[0], y: point[1] },
{ x: point[2], y: point[3] },
{ x: line.x1, y: line.y1 },
{ x: line.x2, y: line.y2 },
]*/
mergePoint.sort((a, b) => a.x - b.x)
// mergeBasePoint.sort((a, b) => a.x - b.x)
/*const checkLine = new fabric.Line([mergeBasePoint[0].x, mergeBasePoint[0].y, mergeBasePoint[3].x, mergeBasePoint[3].y], {
stroke: 'red',
strokeWidth: 4,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()*/
hipBasePoint = { x1: line.x1, y1: line.y1, x2: line.x2, y2: line.y2 }
// line.x1 = mergeBasePoint[0].x
// line.y1 = mergeBasePoint[0].y
// line.x2 = mergeBasePoint[3].x
// line.y2 = mergeBasePoint[3].y
point = [mergePoint[0].x, mergePoint[0].y, mergePoint[3].x, mergePoint[3].y]
canvas.remove(line.line)
baseHipLines = baseHipLines.filter((baseLine) => baseLine.line !== line.line)
@ -2462,8 +2251,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
/** 라인이 다 그려지지 않은 경우 */
if (current.cnt % 2 !== 0) {
// console.log('no checkPoints :', current)
let basePoints = baseLinePoints
.filter((point) =>
Big(point.x)
@ -2624,8 +2411,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
((line.x1 === current.x1 && line.y1 === current.y1 && line.x2 === current.x2 && line.y2 === current.y2) ||
(line.x1 === current.x2 && line.y1 === current.y2 && line.x2 === current.x1 && line.y2 === current.y1)),
)
console.log('sameRidge : ', sameRidge)
if (sameRidge.length > 0) {
sameRidge.forEach((duplicateLine) => {
const index = baseRidgeLines.indexOf(duplicateLine)
@ -2640,15 +2425,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
/** 직교 하는 포인트가 없는 경우 남은 포인트 처리 */
const checkEdgeLines = []
noRidgeHipPoints.forEach((current) => {
/*const checkCircle = new fabric.Circle({
left: current.x2,
top: current.y2,
radius: 4,
fill: 'red',
parentId: roof.id,
})
canvas.add(checkCircle)
canvas.renderAll()*/
noRidgeHipPoints.forEach((current) => {
noRidgeHipPoints
.filter((point) => point !== current)
@ -2662,16 +2438,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
})
})
})
// 라인 확인용
/*checkEdgeLines.forEach((edge) => {
const checkLine = new fabric.Line([edge.vertex1.x, edge.vertex1.y, edge.vertex2.x, edge.vertex2.y], {
stroke: 'yellow',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()
})*/
/** 연결되지 않은 포인트를 찾아서 해당 포인트를 가지고 있는 라인을 찾는다. */
let unFinishedPoints = []
@ -2693,20 +2459,11 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
.forEach((line) => unFinishedLines.push(line))
})
unFinishedLines.forEach((line) => {
/*const checkLine = new fabric.Line([line.x1, line.y1, line.x2, line.y2], {
stroke: 'red',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()*/
const xVector = Math.sign(Big(line.x2).minus(Big(line.x1)))
const yVector = Math.sign(Big(line.y2).minus(Big(line.y1)))
let lineIntersectPoints = []
checkEdgeLines.forEach((edge) => {
const intersectEdge = edgesIntersection(edge, { vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } })
const intersection = []
if (intersectEdge) {
const isXVector = Math.sign(Big(intersectEdge.x).minus(Big(line.x1))) === xVector
const isYVector = Math.sign(Big(intersectEdge.y).minus(Big(line.y1))) === yVector
@ -2730,7 +2487,9 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
(point, index, self) => index === self.findIndex((p) => p.intersection.x === point.intersection.x && p.intersection.y === point.intersection.y),
)
lineIntersectPoints.sort((a, b) => a.size - b.size)
intersectPoints.push({ intersection: lineIntersectPoints[0].intersection, line })
if (lineIntersectPoints.length > 0) {
intersectPoints.push({ intersection: lineIntersectPoints[0].intersection, line })
}
})
intersectPoints.forEach((intersection) => {
@ -2776,40 +2535,15 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
})
})
console.log('baseRidgeLines :', baseRidgeLines)
const ridgeAllPoints = []
baseRidgeLines.forEach((line) => ridgeAllPoints.push({ x: line.x1, y: line.y1 }, { x: line.x2, y: line.y2 }))
console.log('ridgeAllPoints :', ridgeAllPoints)
console.log('지붕 마루 갯수 확인 : ', baseRidgeLines.length, baseRidgeCount, getMaxRidge(baseLines.length))
ridgeAllPoints.forEach((current) => {
const ridgeLines = [],
hipLines = []
ridgeAllPoints
.filter((point) => point !== current)
.forEach((point) => {
/*canvas
.getObjects()
.filter((obj) => obj.name === 'checkPoint' || obj.name === 'checkLine')
.forEach((obj) => canvas.remove(obj))
canvas.renderAll()
const checkPoint = new fabric.Circle({
left: current.x,
top: current.y,
radius: 4,
fill: 'blue',
parentId: roof.id,
name: 'checkPoint',
})
canvas.add(checkPoint)
canvas.renderAll()*/
let checkRidgeLine, checkHipLine
/** 직선인 경우 마루 확인*/
console.log('baseRidgeCount :', baseRidgeCount, baseRidgeLines.length)
if (
baseRidgeCount < getMaxRidge(baseLines.length) &&
((point.x === current.x && point.y !== current.y) || (point.x !== current.x && point.y === current.y))
@ -2868,9 +2602,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
const ridgeLine = drawRidgeLine(ridgePoints, canvas, roof, textMode)
baseRidgeLines.push(ridgeLine)
}
// checkLine1 = { x1: checkRidgeLine.x1, y1: checkRidgeLine.y1, x2: checkRidgeLine.x2, y2: checkRidgeLine.y2 }
// checkLine2 = { x1: checkRidgeLine.x2, y1: checkRidgeLine.y2, x2: checkRidgeLine.x1, y2: checkRidgeLine.y1 }
}
if (checkHipLine) {
const hipPoints = [checkHipLine.x1, checkHipLine.y1, checkHipLine.x2, checkHipLine.y2]
@ -2919,61 +2650,12 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
roof.innerLines = [...baseRidgeLines, ...baseHipLines.map((line) => line.line)]
/** 연결 되지 않은 마루 갯수*/
/*const missingCount = Big(baseRidgeLines.length)
.minus(connectRidgePoint.length + 1)
.toNumber()
console.log('missingCount :', missingCount)*/
/*baseRidgeLines.forEach((current) => {
baseRidgeLines
.filter((ridge) => ridge !== current)
.forEach((ridge) => {
/!** 직선인 경우 확인 *!/
let checkLineEdge
if (current.x1 === ridge.x1 || current.y1 === ridge.y1) {
checkLineEdge = { vertex1: { x: current.x1, y: current.y1 }, vertex2: { x: ridge.x1, y: ridge.y1 } }
} else if (current.x2 === ridge.x1 || current.y2 === ridge.y1) {
checkLineEdge = { vertex1: { x: current.x2, y: current.y2 }, vertex2: { x: ridge.x1, y: ridge.y1 } }
} else if (current.x1 === ridge.x2 || current.y1 === ridge.y2) {
checkLineEdge = { vertex1: { x: current.x1, y: current.y1 }, vertex2: { x: ridge.x2, y: ridge.y2 } }
} else if (current.x2 === ridge.x2 || current.y2 === ridge.y2) {
checkLineEdge = { vertex1: { x: current.x2, y: current.y2 }, vertex2: { x: ridge.x2, y: ridge.y2 } }
}
console.log('checkLineEdge :', checkLineEdge)
if (checkLineEdge) {
let hasIntersectLine = false
/!** 외벽선을 통과하는지 확인*!/
baseLines.forEach((line) => {
const lineEdge = { vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } }
const intersection = edgesIntersection(checkLineEdge, lineEdge)
if (intersection && !intersection.isIntersectionOutside) {
hasIntersectLine = true
}
})
/!** hipLines를 통과하는지 확인*!/
baseHipLines.forEach((line) => {
const lineEdge = { vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } }
const intersection = edgesIntersection(checkLineEdge, lineEdge)
if (intersection && !intersection.isIntersectionOutside) {
hasIntersectLine = true
}
})
// if (!hasIntersectLine) {
const checkLine = new fabric.Line([checkLineEdge.vertex1.x, checkLineEdge.vertex1.y, checkLineEdge.vertex2.x, checkLineEdge.vertex2.y], {
stroke: 'red',
strokeWidth: 2,
parentId: roof.id,
})
canvas.add(checkLine)
canvas.renderAll()
// }
}
})
})*/
/** 확인용 라인, 포인트 제거 */
canvas
.getObjects()
.filter((obj) => obj.name === 'checkPoint' || obj.name === 'checkLine')
.forEach((obj) => canvas.remove(obj))
canvas.renderAll()
/*drawRidge(roof, canvas, textMode)
drawHips(roof, canvas, textMode)
@ -2993,7 +2675,6 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
* @param currentDegree
*/
const drawHipLine = (points, canvas, roof, textMode, currentRoof, prevDegree, currentDegree) => {
// console.log('drawHipLine : ', points)
const hip = new QLine(points, {
parentId: roof.id,
fontSize: roof.fontSize,
@ -5882,16 +5563,9 @@ export const calcLinePlaneSize = (points) => {
* @returns number
*/
export const calcLineActualSize = (points, degree) => {
const { x1, y1, x2, y2 } = points
const planeSize = calcLinePlaneSize(points)
let height = Big(Math.tan(Big(degree).times(Math.PI / 180))).times(planeSize)
/**
* 대각선일 경우 높이 계산 변경
*/
if (x1 !== x2 && y1 !== y2) {
height = Big(Math.tan(Big(degree).times(Math.PI / 180))).times(Big(x1).minus(x2).times(10).round())
}
return Big(planeSize).pow(2).plus(height.pow(2)).sqrt().abs().round().toNumber()
const theta = Big(Math.cos(Big(degree).times(Math.PI).div(180)))
return Big(planeSize).div(theta).round(1).toNumber()
}
export const createLinesFromPolygon = (points) => {