케라바 지붕 출폭 0일때 문제 발생 사항 처리. #649

Merged
ysCha merged 1 commits from dev into dev-deploy 2026-02-09 17:48:59 +09:00

View File

@ -608,39 +608,53 @@ export const drawGableRoof = (roofId, canvas, textMode) => {
} }
} }
const findEdge = { vertex1: { x: midX, y: midY }, vertex2: { x: midX + roofVector.x * offset, y: midY + roofVector.y * offset } } let currentRoof
const edgeDx = if (line.attributes.offset === 0) {
Big(findEdge.vertex2.x).minus(Big(findEdge.vertex1.x)).abs().toNumber() < 0.1 checkRoofLines.forEach((roofLine) => {
? 0 const isVerticalSame = line.y1 === roofLine.y1 && line.y2 === roofLine.y2
: Big(findEdge.vertex2.x).minus(Big(findEdge.vertex1.x)).toNumber() const isHorizontalSame = line.x1 === roofLine.x1 && line.x2 === roofLine.x2
const edgeDy = if (
Big(findEdge.vertex2.y).minus(Big(findEdge.vertex1.y)).abs().toNumber() < 0.1 (isVerticalSame || isHorizontalSame) &&
? 0 (isPointOnLineNew(roofLine, { x: line.x1, y: line.y1 }) || isPointOnLineNew(roofLine, { x: line.x2, y: line.y2 }))
: Big(findEdge.vertex2.y).minus(Big(findEdge.vertex1.y)).toNumber() ) {
const edgeLength = Math.sqrt(edgeDx * edgeDx + edgeDy * edgeDy) currentRoof = { roofLine }
const edgeVector = { x: edgeDx / edgeLength, y: edgeDy / edgeLength }
const intersectRoofLines = []
checkRoofLines.forEach((roofLine) => {
const lineEdge = { vertex1: { x: roofLine.x1, y: roofLine.y1 }, vertex2: { x: roofLine.x2, y: roofLine.y2 } }
const intersect = edgesIntersection(lineEdge, findEdge)
if (intersect) {
const intersectDx =
Big(intersect.x).minus(Big(findEdge.vertex1.x)).abs().toNumber() < 0.1 ? 0 : Big(intersect.x).minus(Big(findEdge.vertex1.x)).toNumber()
const intersectDy =
Big(intersect.y).minus(Big(findEdge.vertex1.y)).abs().toNumber() < 0.1 ? 0 : Big(intersect.y).minus(Big(findEdge.vertex1.y)).toNumber()
const intersectLength = Math.sqrt(intersectDx * intersectDx + intersectDy * intersectDy)
const intersectVector = { x: intersectDx / intersectLength, y: intersectDy / intersectLength }
if (edgeVector.x === intersectVector.x && edgeVector.y === intersectVector.y) {
intersectRoofLines.push({ roofLine, intersect, length: intersectLength })
} }
} })
}) } else {
const findEdge = { vertex1: { x: midX, y: midY }, vertex2: { x: midX + roofVector.x * offset, y: midY + roofVector.y * offset } }
const edgeDx =
Big(findEdge.vertex2.x).minus(Big(findEdge.vertex1.x)).abs().toNumber() < 0.1
? 0
: Big(findEdge.vertex2.x).minus(Big(findEdge.vertex1.x)).toNumber()
const edgeDy =
Big(findEdge.vertex2.y).minus(Big(findEdge.vertex1.y)).abs().toNumber() < 0.1
? 0
: Big(findEdge.vertex2.y).minus(Big(findEdge.vertex1.y)).toNumber()
const edgeLength = Math.sqrt(edgeDx * edgeDx + edgeDy * edgeDy)
const edgeVector = { x: edgeDx / edgeLength, y: edgeDy / edgeLength }
intersectRoofLines.sort((a, b) => a.length - b.length) const intersectRoofLines = []
let currentRoof = intersectRoofLines.find((roof) => isPointOnLineNew(roof.roofLine, roof.intersect) && roof.length - offset < 0.1) checkRoofLines.forEach((roofLine) => {
if (!currentRoof) { const lineEdge = { vertex1: { x: roofLine.x1, y: roofLine.y1 }, vertex2: { x: roofLine.x2, y: roofLine.y2 } }
currentRoof = intersectRoofLines[0] const intersect = edgesIntersection(lineEdge, findEdge)
if (intersect) {
const intersectDx =
Big(intersect.x).minus(Big(findEdge.vertex1.x)).abs().toNumber() < 0.1 ? 0 : Big(intersect.x).minus(Big(findEdge.vertex1.x)).toNumber()
const intersectDy =
Big(intersect.y).minus(Big(findEdge.vertex1.y)).abs().toNumber() < 0.1 ? 0 : Big(intersect.y).minus(Big(findEdge.vertex1.y)).toNumber()
const intersectLength = Math.sqrt(intersectDx * intersectDx + intersectDy * intersectDy)
const intersectVector = { x: intersectDx / intersectLength, y: intersectDy / intersectLength }
if (edgeVector.x === intersectVector.x && edgeVector.y === intersectVector.y) {
intersectRoofLines.push({ roofLine, intersect, length: intersectLength })
}
}
})
intersectRoofLines.sort((a, b) => a.length - b.length)
currentRoof = intersectRoofLines.find((roof) => isPointOnLineNew(roof.roofLine, roof.intersect) && roof.length - offset < 0.1)
if (!currentRoof) {
currentRoof = intersectRoofLines[0]
}
} }
let startPoint, endPoint let startPoint, endPoint
@ -924,11 +938,16 @@ export const drawGableRoof = (roofId, canvas, textMode) => {
const y2 = analyze.endPoint.y const y2 = analyze.endPoint.y
const lineVector = { x: 0, y: 0 } const lineVector = { x: 0, y: 0 }
if (analyze.isHorizontal) { if (currentLine.attributes.offset === 0) {
lineVector.x = Math.sign(analyze.roofLine.y1 - currentLine.attributes.originPoint.y1) lineVector.x = analyze.roofVector.y
} lineVector.y = analyze.roofVector.x
if (analyze.isVertical) { } else {
lineVector.y = Math.sign(analyze.roofLine.x1 - currentLine.attributes.originPoint.x1) if (analyze.isHorizontal) {
lineVector.x = Math.sign(analyze.roofLine.y1 - currentLine.attributes.originPoint.y1)
}
if (analyze.isVertical) {
lineVector.y = Math.sign(analyze.roofLine.x1 - currentLine.attributes.originPoint.x1)
}
} }
const overlapLines = [] const overlapLines = []
@ -1904,40 +1923,53 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
roofVector = { x: 1, y: 0 } roofVector = { x: 1, y: 0 }
} }
} }
let currentRoof
const findEdge = { vertex1: { x: midX, y: midY }, vertex2: { x: midX + roofVector.x * offset, y: midY + roofVector.y * offset } } if (line.attributes.offset === 0) {
const edgeDx = checkRoofLines.forEach((roofLine) => {
Big(findEdge.vertex2.x).minus(Big(findEdge.vertex1.x)).abs().toNumber() < 0.1 const isVerticalSame = line.y1 === roofLine.y1 && line.y2 === roofLine.y2
? 0 const isHorizontalSame = line.x1 === roofLine.x1 && line.x2 === roofLine.x2
: Big(findEdge.vertex2.x).minus(Big(findEdge.vertex1.x)).toNumber() if (
const edgeDy = (isVerticalSame || isHorizontalSame) &&
Big(findEdge.vertex2.y).minus(Big(findEdge.vertex1.y)).abs().toNumber() < 0.1 (isPointOnLineNew(roofLine, { x: line.x1, y: line.y1 }) || isPointOnLineNew(roofLine, { x: line.x2, y: line.y2 }))
? 0 ) {
: Big(findEdge.vertex2.y).minus(Big(findEdge.vertex1.y)).toNumber() currentRoof = { roofLine }
const edgeLength = Math.sqrt(edgeDx * edgeDx + edgeDy * edgeDy)
const edgeVector = { x: edgeDx / edgeLength, y: edgeDy / edgeLength }
const intersectRoofLines = []
checkRoofLines.forEach((roofLine) => {
const lineEdge = { vertex1: { x: roofLine.x1, y: roofLine.y1 }, vertex2: { x: roofLine.x2, y: roofLine.y2 } }
const intersect = edgesIntersection(lineEdge, findEdge)
if (intersect) {
const intersectDx =
Big(intersect.x).minus(Big(findEdge.vertex1.x)).abs().toNumber() < 0.1 ? 0 : Big(intersect.x).minus(Big(findEdge.vertex1.x)).toNumber()
const intersectDy =
Big(intersect.y).minus(Big(findEdge.vertex1.y)).abs().toNumber() < 0.1 ? 0 : Big(intersect.y).minus(Big(findEdge.vertex1.y)).toNumber()
const intersectLength = Math.sqrt(intersectDx * intersectDx + intersectDy * intersectDy)
const intersectVector = { x: intersectDx / intersectLength, y: intersectDy / intersectLength }
if (edgeVector.x === intersectVector.x && edgeVector.y === intersectVector.y) {
intersectRoofLines.push({ roofLine, intersect, length: intersectLength })
} }
} })
}) } else {
const findEdge = { vertex1: { x: midX, y: midY }, vertex2: { x: midX + roofVector.x * offset, y: midY + roofVector.y * offset } }
const edgeDx =
Big(findEdge.vertex2.x).minus(Big(findEdge.vertex1.x)).abs().toNumber() < 0.1
? 0
: Big(findEdge.vertex2.x).minus(Big(findEdge.vertex1.x)).toNumber()
const edgeDy =
Big(findEdge.vertex2.y).minus(Big(findEdge.vertex1.y)).abs().toNumber() < 0.1
? 0
: Big(findEdge.vertex2.y).minus(Big(findEdge.vertex1.y)).toNumber()
const edgeLength = Math.sqrt(edgeDx * edgeDx + edgeDy * edgeDy)
const edgeVector = { x: edgeDx / edgeLength, y: edgeDy / edgeLength }
intersectRoofLines.sort((a, b) => a.length - b.length) const intersectRoofLines = []
let currentRoof = intersectRoofLines.find((roof) => isPointOnLineNew(roof.roofLine, roof.intersect) && roof.length - offset < 0.1) checkRoofLines.forEach((roofLine) => {
if (!currentRoof) { const lineEdge = { vertex1: { x: roofLine.x1, y: roofLine.y1 }, vertex2: { x: roofLine.x2, y: roofLine.y2 } }
currentRoof = intersectRoofLines[0] const intersect = edgesIntersection(lineEdge, findEdge)
if (intersect) {
const intersectDx =
Big(intersect.x).minus(Big(findEdge.vertex1.x)).abs().toNumber() < 0.1 ? 0 : Big(intersect.x).minus(Big(findEdge.vertex1.x)).toNumber()
const intersectDy =
Big(intersect.y).minus(Big(findEdge.vertex1.y)).abs().toNumber() < 0.1 ? 0 : Big(intersect.y).minus(Big(findEdge.vertex1.y)).toNumber()
const intersectLength = Math.sqrt(intersectDx * intersectDx + intersectDy * intersectDy)
const intersectVector = { x: intersectDx / intersectLength, y: intersectDy / intersectLength }
if (edgeVector.x === intersectVector.x && edgeVector.y === intersectVector.y) {
intersectRoofLines.push({ roofLine, intersect, length: intersectLength })
}
}
})
intersectRoofLines.sort((a, b) => a.length - b.length)
currentRoof = intersectRoofLines.find((roof) => isPointOnLineNew(roof.roofLine, roof.intersect) && roof.length - offset < 0.1)
if (!currentRoof) {
currentRoof = intersectRoofLines[0]
}
} }
let startPoint, endPoint let startPoint, endPoint
@ -3289,6 +3321,8 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
prevLine = baseLines[(index - 1 + baseLines.length) % baseLines.length] prevLine = baseLines[(index - 1 + baseLines.length) % baseLines.length]
} }
}) })
const prevIndex = baseLines.findIndex((line) => line === prevLine)
const nextIndex = baseLines.findIndex((line) => line === nextLine)
//양옆이 처마가 아닐때 패스 //양옆이 처마가 아닐때 패스
if (prevLine.attributes.type !== LINE_TYPE.WALLLINE.EAVES || nextLine.attributes.type !== LINE_TYPE.WALLLINE.EAVES) { if (prevLine.attributes.type !== LINE_TYPE.WALLLINE.EAVES || nextLine.attributes.type !== LINE_TYPE.WALLLINE.EAVES) {
@ -3377,14 +3411,24 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
ridgePoint[2] += ridgeVector.x * offset ridgePoint[2] += ridgeVector.x * offset
ridgePoint[3] += ridgeVector.y * offset ridgePoint[3] += ridgeVector.y * offset
linesAnalysis.push({ const alreadyRidge = linesAnalysis.find(
start: { x: ridgePoint[0], y: ridgePoint[1] }, (line) =>
end: { x: ridgePoint[2], y: ridgePoint[3] }, line.type === TYPES.RIDGE &&
left: baseLines.findIndex((line) => line === prevLine), line.start.x === ridgePoint[0] &&
right: baseLines.findIndex((line) => line === nextLine), line.start.y === ridgePoint[1] &&
type: TYPES.RIDGE, line.end.x === ridgePoint[2] &&
degree: 0, line.end.y === ridgePoint[3],
}) )
if (!alreadyRidge) {
linesAnalysis.push({
start: { x: ridgePoint[0], y: ridgePoint[1] },
end: { x: ridgePoint[2], y: ridgePoint[3] },
left: prevIndex,
right: nextIndex,
type: TYPES.RIDGE,
degree: 0,
})
}
} else { } else {
if (beforePrevLine.attributes.type === LINE_TYPE.WALLLINE.GABLE) { if (beforePrevLine.attributes.type === LINE_TYPE.WALLLINE.GABLE) {
const beforeVector = { const beforeVector = {
@ -3983,14 +4027,24 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
endPoint = { x: point[0], y: point[1] } endPoint = { x: point[0], y: point[1] }
} }
} }
linesAnalysis.push({ const alreadyRidge = linesAnalysis.find(
start: startPoint, (line) =>
end: endPoint, line.type === TYPES.RIDGE &&
left: baseLines.findIndex((line) => line === r.left), line.start.x === startPoint.x &&
right: baseLines.findIndex((line) => line === r.right), line.start.y === startPoint.y &&
type: TYPES.RIDGE, line.end.x === endPoint.x &&
degree: 0, line.end.y === endPoint.y,
}) )
if (!alreadyRidge) {
linesAnalysis.push({
start: startPoint,
end: endPoint,
left: prevIndex,
right: nextIndex,
type: TYPES.RIDGE,
degree: 0,
})
}
} }
}) })
} }
@ -4036,8 +4090,8 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
linesAnalysis.push({ linesAnalysis.push({
start: startPoint, start: startPoint,
end: { x: correctPoint.x, y: correctPoint.y }, end: { x: correctPoint.x, y: correctPoint.y },
left: baseLines.findIndex((line) => line === prevLine), left: prevIndex,
right: baseLines.findIndex((line) => line === nextLine), right: nextIndex,
type: TYPES.GABLE_LINE, type: TYPES.GABLE_LINE,
degree: getDegreeByChon(prevLine.attributes.pitch), degree: getDegreeByChon(prevLine.attributes.pitch),
gableId: baseLines.findIndex((line) => line === currentLine), gableId: baseLines.findIndex((line) => line === currentLine),
@ -4464,14 +4518,13 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
if (isOpposite) { if (isOpposite) {
const points = [currentLine.start.x, currentLine.start.y, partnerLine.start.x, partnerLine.start.y] const points = [currentLine.start.x, currentLine.start.y, partnerLine.start.x, partnerLine.start.y]
const length = Math.sqrt((points[0] - points[2]) ** 2 + (points[1] - points[3]) ** 2) const length = Math.sqrt((points[0] - points[2]) ** 2 + (points[1] - points[3]) ** 2)
const isDiagonal = Math.abs(points[0] - points[2]) >= 1 && Math.abs(points[1] - points[3]) >= 1
if (length > 0) { if (length > EPSILON) {
if (currentLine.type === TYPES.HIP) { if (currentLine.type === TYPES.HIP) {
innerLines.push(drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree)) innerLines.push(drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree))
} else if (currentLine.type === TYPES.RIDGE) { } else if (currentLine.type === TYPES.RIDGE && !isDiagonal) {
innerLines.push(drawRidgeLine(points, canvas, roof, textMode)) innerLines.push(drawRidgeLine(points, canvas, roof, textMode))
} else if (currentLine.type === TYPES.NEW) { } else if (currentLine.type === TYPES.NEW) {
const isDiagonal = Math.abs(points[0] - points[2]) >= 1 && Math.abs(points[1] - points[3]) >= 1
if (isDiagonal && almostEqual(Math.abs(points[0] - points[2]), Math.abs(points[1] - points[3]))) { if (isDiagonal && almostEqual(Math.abs(points[0] - points[2]), Math.abs(points[1] - points[3]))) {
innerLines.push(drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree)) innerLines.push(drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree))
} }
@ -4496,11 +4549,12 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
const length = Math.sqrt((points[0].x - points[1].x) ** 2 + (points[0].y - points[1].y) ** 2) const length = Math.sqrt((points[0].x - points[1].x) ** 2 + (points[0].y - points[1].y) ** 2)
if (length < EPSILON) return if (length < EPSILON) return
const isDiagonal = Math.abs(points[0].x - points[1].x) >= 1 && Math.abs(points[0].y - points[1].y) >= 1 const isDiagonal = Math.abs(points[0].x - points[1].x) >= 1 && Math.abs(points[0].y - points[1].y) >= 1
if (isDiagonal) { if (isDiagonal && almostEqual(Math.abs(points[0] - points[2]), Math.abs(points[1] - points[3]))) {
innerLines.push( innerLines.push(
drawHipLine([points[0].x, points[0].y, points[1].x, points[1].y], canvas, roof, textMode, currentDegree, currentDegree), drawHipLine([points[0].x, points[0].y, points[1].x, points[1].y], canvas, roof, textMode, currentDegree, currentDegree),
) )
} else { }
if (!isDiagonal) {
innerLines.push(drawRidgeLine([points[0].x, points[0].y, points[1].x, points[1].y], canvas, roof, textMode)) innerLines.push(drawRidgeLine([points[0].x, points[0].y, points[1].x, points[1].y], canvas, roof, textMode))
} }
proceedAnalysis.push(currentLine, partnerLine) proceedAnalysis.push(currentLine, partnerLine)
@ -4545,7 +4599,6 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
} }
}) })
} }
//케라바에서 파생된 하단 지붕 라인처리 //케라바에서 파생된 하단 지붕 라인처리
const downRoofGable = [] const downRoofGable = []
//처마에서 파생된 하단 지붕 라인 처리 //처마에서 파생된 하단 지붕 라인 처리