dev #536

Merged
ysCha merged 3 commits from dev into prd-deploy 2025-12-30 11:00:44 +09:00
2 changed files with 574 additions and 209 deletions

View File

@ -1375,7 +1375,7 @@ export const drawGableRoof = (roofId, canvas, textMode) => {
innerLines.push(drawRoofLine(points, canvas, roof, textMode))
} else {
//다른방향 처리
innerLines.push(drawHipLine(points, canvas, roof, textMode, null, currentDegree, currentDegree))
innerLines.push(drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree))
}
} else if (analyze.isVertical) {
//현재라인이 수직선일때
@ -1384,7 +1384,7 @@ export const drawGableRoof = (roofId, canvas, textMode) => {
innerLines.push(drawRoofLine(points, canvas, roof, textMode))
} else {
//다른방향 처리
innerLines.push(drawHipLine(points, canvas, roof, textMode, null, currentDegree, currentDegree))
innerLines.push(drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree))
}
}
})
@ -2521,8 +2521,8 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
]
const gablePoint = [prevHipPoint[2], prevHipPoint[3], nextHipPoint[2], nextHipPoint[3]]
innerLines.push(drawHipLine(prevHipPoint, canvas, roof, textMode, null, prevDegree, prevDegree))
innerLines.push(drawHipLine(nextHipPoint, canvas, roof, textMode, null, nextDegree, nextDegree))
innerLines.push(drawHipLine(prevHipPoint, canvas, roof, textMode, prevDegree, prevDegree))
innerLines.push(drawHipLine(nextHipPoint, canvas, roof, textMode, nextDegree, nextDegree))
// innerLines.push(drawRoofLine(gablePoint, canvas, roof, textMode))
//양옆이 처마일경우 두개의 선, 아닐때 한개의 선, 좌우가 처마가 아닐때 안그려져야하는데 기존에 그려지는 경우가 있음 이유를 알 수 없음.
@ -2537,10 +2537,10 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
const nextDy = nextGablePoint[1] - nextGablePoint[3]
const nextGableLength = Math.sqrt(nextDx * nextDx + nextDy * nextDy)
if (prevGableLength >= 1) {
innerLines.push(drawHipLine(prevGablePoint, canvas, roof, textMode, null, prevDegree, prevDegree))
innerLines.push(drawHipLine(prevGablePoint, canvas, roof, textMode, prevDegree, prevDegree))
}
if (nextGableLength >= 1) {
innerLines.push(drawHipLine(nextGablePoint, canvas, roof, textMode, null, nextDegree, nextDegree))
innerLines.push(drawHipLine(nextGablePoint, canvas, roof, textMode, nextDegree, nextDegree))
}
const checkEdge = {
vertex1: { x: midPoint.x, y: midPoint.y },
@ -2690,13 +2690,13 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
let proceedRidges = [] // left: 이전, right:다음, point:그려지는 포인트, length:길이
let hipLines = []
ridgeEaves.forEach((currentLine) => {
/*const checkLine = new fabric.Line([currentLine.x1, currentLine.y1, currentLine.x2, currentLine.y2], {
const checkLine = new fabric.Line([currentLine.x1, currentLine.y1, currentLine.x2, currentLine.y2], {
stroke: 'red',
strokeWidth: 4,
parentId: roofId,
name: 'check',
})
canvas.add(checkLine).renderAll()*/
canvas.add(checkLine).renderAll()
let prevLine, nextLine, currentI, prevI, nextI
baseLines.forEach((baseLine, index) => {
if (baseLine === currentLine) {
@ -2741,6 +2741,10 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
const prevCheckPoint = [currentLine.x1, currentLine.y1, currentLine.x1 + pHipVector.x * 1000, currentLine.y1 + pHipVector.y * 1000]
const nextCheckPoint = [currentLine.x2, currentLine.y2, currentLine.x2 + nHipVector.x * 1000, currentLine.y2 + nHipVector.y * 1000]
/* const checkLine1 = new fabric.Line(prevCheckPoint, { stroke: 'red', strokeWidth: 4, parentId: roofId, name: 'check' })
const checkLine2 = new fabric.Line(nextCheckPoint, { stroke: 'green', strokeWidth: 4, parentID: roofId, name: 'check' })
canvas.add(checkLine1, checkLine2).renderAll()*/
const findRoofPoints = (points) => {
const hipEdge = { vertex1: { x: points[0], y: points[1] }, vertex2: { x: points[2], y: points[3] } }
const hipForwardVector = { x: Math.sign(hipEdge.vertex1.x - hipEdge.vertex2.x), y: Math.sign(hipEdge.vertex1.y - hipEdge.vertex2.y) }
@ -2772,7 +2776,15 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
})
isForwardPoints.sort((a, b) => a.length - b.length)
isBackwardPoints.sort((a, b) => a.length - b.length)
return { forward: isForwardPoints[0].intersect, backward: isBackwardPoints[0].intersect }
if (isForwardPoints.length > 0 && isBackwardPoints.length > 0) {
return { forward: isForwardPoints[0].intersect, backward: isBackwardPoints[0].intersect }
} else if (isForwardPoints.length === 0 && isBackwardPoints.length > 1) {
return { forward: isBackwardPoints[0].intersect, backward: isBackwardPoints[1].intersect }
} else if (isForwardPoints.length > 1 && isBackwardPoints.length === 0) {
return { forward: isForwardPoints[1].intersect, backward: isForwardPoints[0].intersect }
} else {
return null
}
}
const pRoofPoints = findRoofPoints(prevCheckPoint)
@ -3140,7 +3152,7 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
.filter((e) => e !== eaves)
.filter((e) => almostEqual(e.point.x2, eaves.point.x2) && almostEqual(e.point.y2, eaves.point.y2))
if (jointEaves.length === 1 && ridgeEaves.length > 1) {
innerLines.push(drawHipLine([point.x1, point.y1, point.x2, point.y2], canvas, roof, textMode, null, currentDegree, currentDegree))
innerLines.push(drawHipLine([point.x1, point.y1, point.x2, point.y2], canvas, roof, textMode, currentDegree, currentDegree))
pIndexEaves.push(index)
} else if (jointEaves.length === 2) {
console.log('jointEaves : ', jointEaves)
@ -3152,7 +3164,7 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
jointIndex.forEach((i) => {
const ev = proceedEaves[i]
const degree = getDegreeByChon(baseLines[ev.current].attributes.pitch)
innerLines.push(drawHipLine([ev.point.x1, ev.point.y1, ev.point.x2, ev.point.y2], canvas, roof, textMode, null, degree, degree))
innerLines.push(drawHipLine([ev.point.x1, ev.point.y1, ev.point.x2, ev.point.y2], canvas, roof, textMode, degree, degree))
pIndexEaves.push(i)
jointLines.push(ev.prev, ev.current)
jointVectors.push({ x: Math.sign(ev.point.x2 - ev.point.x1), y: Math.sign(ev.point.y2 - ev.point.y1) })
@ -3289,13 +3301,13 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
const gableLength2 = Math.sqrt(Math.pow(gablePoint2[2] - gablePoint2[0], 2) + Math.pow(gablePoint2[3] - gablePoint2[1], 2))
const gableLength3 = Math.sqrt(Math.pow(gablePoint3[2] - gablePoint3[0], 2) + Math.pow(gablePoint3[3] - gablePoint3[1], 2))
if (gableLength1 >= 1) {
innerLines.push(drawHipLine(gablePoint1, canvas, roof, textMode, null, prevDegree, prevDegree))
innerLines.push(drawHipLine(gablePoint1, canvas, roof, textMode, prevDegree, prevDegree))
}
if (gableLength2 >= 1) {
innerLines.push(drawRoofLine(gablePoint2, canvas, roof, textMode))
}
if (gableLength3 >= 1) {
innerLines.push(drawHipLine(gablePoint3, canvas, roof, textMode, null, nextDegree, nextDegree))
innerLines.push(drawHipLine(gablePoint3, canvas, roof, textMode, nextDegree, nextDegree))
}
const currentRoofLine = analyze.roofLine
@ -3350,8 +3362,8 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
if (hipIntersection) {
const prevHipPoint = [prevHipEdge.vertex1.x, prevHipEdge.vertex1.y, hipIntersection.x, hipIntersection.y]
const nextHipPoint = [nextHipEdge.vertex1.x, nextHipEdge.vertex1.y, hipIntersection.x, hipIntersection.y]
innerLines.push(drawHipLine(prevHipPoint, canvas, roof, textMode, null, currentDegree, currentDegree))
innerLines.push(drawHipLine(nextHipPoint, canvas, roof, textMode, null, currentDegree, currentDegree))
innerLines.push(drawHipLine(prevHipPoint, canvas, roof, textMode, currentDegree, currentDegree))
innerLines.push(drawHipLine(nextHipPoint, canvas, roof, textMode, currentDegree, currentDegree))
const midPoint = { x: hipIntersection.x, y: hipIntersection.y }
const checkEdge = {
@ -4426,19 +4438,19 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
if (length1 > 0 && !alreadyPoints(innerLines, point1)) {
if (cLine.type === TYPES.HIP) {
innerLines.push(drawHipLine(point1, canvas, roof, textMode, null, cLine.degree, cLine.degree))
innerLines.push(drawHipLine(point1, canvas, roof, textMode, cLine.degree, cLine.degree))
} else if (cLine.type === TYPES.RIDGE) {
innerLines.push(drawRidgeLine(point1, canvas, roof, textMode))
} else if (cLine.type === TYPES.NEW) {
const isDiagonal = Math.abs(point1[0] - point1[2]) >= 1 && Math.abs(point1[1] - point1[3]) >= 1
if (isDiagonal) {
innerLines.push(drawHipLine(point1, canvas, roof, textMode, null, cLine.degree, cLine.degree))
innerLines.push(drawHipLine(point1, canvas, roof, textMode, cLine.degree, cLine.degree))
} else {
innerLines.push(drawRidgeLine(point1, canvas, roof, textMode))
}
} else if (cLine.type === TYPES.GABLE_LINE) {
if (cLine.degree > 0) {
innerLines.push(drawHipLine(point1, canvas, roof, textMode, null, cLine.degree, cLine.degree))
innerLines.push(drawHipLine(point1, canvas, roof, textMode, cLine.degree, cLine.degree))
} else {
innerLines.push(drawRidgeLine(point1, canvas, roof, textMode))
}
@ -4447,19 +4459,19 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
if (length2 > 0 && !alreadyPoints(innerLines, point2)) {
if (pLine.type === TYPES.HIP) {
innerLines.push(drawHipLine(point2, canvas, roof, textMode, null, pLine.degree, pLine.degree))
innerLines.push(drawHipLine(point2, canvas, roof, textMode, pLine.degree, pLine.degree))
} else if (pLine.type === TYPES.RIDGE) {
innerLines.push(drawRidgeLine(point2, canvas, roof, textMode))
} else if (pLine.type === TYPES.NEW) {
const isDiagonal = Math.abs(point2[0] - point2[2]) >= 1 && Math.abs(point2[1] - point2[3]) >= 1
if (isDiagonal) {
innerLines.push(drawHipLine(point2, canvas, roof, textMode, null, pLine.degree, pLine.degree))
innerLines.push(drawHipLine(point2, canvas, roof, textMode, pLine.degree, pLine.degree))
} else {
innerLines.push(drawRidgeLine(point2, canvas, roof, textMode))
}
} else if (pLine.type === TYPES.GABLE_LINE) {
if (pLine.degree > 0) {
innerLines.push(drawHipLine(point2, canvas, roof, textMode, null, pLine.degree, pLine.degree))
innerLines.push(drawHipLine(point2, canvas, roof, textMode, pLine.degree, pLine.degree))
} else {
innerLines.push(drawRidgeLine(point2, canvas, roof, textMode))
}
@ -4486,13 +4498,13 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
} else if (oLine.type === TYPES.NEW) {
const isDiagonal = Math.abs(oPoint[0] - oPoint[2]) >= 1 && Math.abs(oPoint[1] - oPoint[3]) >= 1
if (isDiagonal) {
innerLines.push(drawHipLine(oPoint, canvas, roof, textMode, null, oLine.degree, oLine.degree))
innerLines.push(drawHipLine(oPoint, canvas, roof, textMode, oLine.degree, oLine.degree))
} else {
innerLines.push(drawRidgeLine(oPoint, canvas, roof, textMode))
}
} else if (oLine.type === TYPES.GABLE_LINE) {
if (oLine.degree > 0) {
innerLines.push(drawHipLine(oPoint, canvas, roof, textMode, null, oLine.degree, oLine.degree))
innerLines.push(drawHipLine(oPoint, canvas, roof, textMode, oLine.degree, oLine.degree))
} else {
innerLines.push(drawRidgeLine(oPoint, canvas, roof, textMode))
}
@ -4757,13 +4769,13 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
if (length > 0) {
if (currentLine.type === TYPES.HIP) {
innerLines.push(drawHipLine(points, canvas, roof, textMode, null, currentDegree, currentDegree))
innerLines.push(drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree))
} else if (currentLine.type === TYPES.RIDGE) {
innerLines.push(drawRidgeLine(points, canvas, roof, textMode))
} 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]))) {
innerLines.push(drawHipLine(points, canvas, roof, textMode, null, currentDegree, currentDegree))
innerLines.push(drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree))
}
if (!isDiagonal) {
innerLines.push(drawRidgeLine(points, canvas, roof, textMode))
@ -4788,7 +4800,7 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
const isDiagonal = Math.abs(points[0].x - points[1].x) >= 1 && Math.abs(points[0].y - points[1].y) >= 1
if (isDiagonal) {
innerLines.push(
drawHipLine([points[0].x, points[0].y, points[1].x, points[1].y], canvas, roof, textMode, null, currentDegree, currentDegree),
drawHipLine([points[0].x, points[0].y, points[1].x, points[1].y], canvas, roof, textMode, currentDegree, currentDegree),
)
} else {
innerLines.push(drawRidgeLine([points[0].x, points[0].y, points[1].x, points[1].y], canvas, roof, textMode))
@ -4829,9 +4841,7 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
if (line.degree === 0) {
innerLines.push(drawRoofLine([line.start.x, line.start.y, line.end.x, line.end.y], canvas, roof, textMode))
} else {
innerLines.push(
drawHipLine([line.start.x, line.start.y, line.end.x, line.end.y], canvas, roof, textMode, null, line.degree, line.degree),
)
innerLines.push(drawHipLine([line.start.x, line.start.y, line.end.x, line.end.y], canvas, roof, textMode, line.degree, line.degree))
}
}
}
@ -4841,6 +4851,8 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
//케라바에서 파생된 하단 지붕 라인처리
const downRoofGable = []
//처마에서 파생된 하단 지붕 라인 처리
let downRoofEaves = []
baseLines.forEach((baseLine, index) => {
const nextLine = baseLines[(index + 1) % baseLines.length]
const prevLine = baseLines[(index - 1 + baseLines.length) % baseLines.length]
@ -4856,7 +4868,8 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
prevLineVector.x === nextLineVector.x &&
prevLineVector.y === nextLineVector.y &&
baseLine.attributes.type === LINE_TYPE.WALLLINE.EAVES &&
(prevLine.attributes.type === LINE_TYPE.WALLLINE.GABLE || nextLine.attributes.type === LINE_TYPE.WALLLINE.GABLE)
prevLine.attributes.type === LINE_TYPE.WALLLINE.GABLE &&
nextLine.attributes.type === LINE_TYPE.WALLLINE.GABLE
) {
downRoofGable.push({ currLine: baseLine, currIndex: index, type: 'A' })
}
@ -4869,6 +4882,17 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
) {
downRoofGable.push({ currLine: baseLine, currIndex: index, type: 'B' })
}
const originPoint = baseLine.attributes.originPoint
if (
prevLineVector.x === nextLineVector.x &&
prevLineVector.y === nextLineVector.y &&
baseLine.attributes.type === LINE_TYPE.WALLLINE.EAVES &&
(prevLine.attributes.type === LINE_TYPE.WALLLINE.EAVES || nextLine.attributes.type === LINE_TYPE.WALLLINE.EAVES) &&
((originPoint.x1 !== baseLine.x1 && originPoint.x2 !== baseLine.x2) || (originPoint.y1 !== baseLine.y1 && originPoint.y2 !== baseLine.y2))
) {
downRoofEaves.push({ currLine: baseLine, currIndex: index })
}
})
const downRoofLines = [] // 하단지붕 파생 라인 처리후 innerLines에 추가.
@ -5046,7 +5070,7 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
if (minPoint) {
const hipPoint = [roofLinePoint[0], roofLinePoint[1], minPoint.x, minPoint.y]
downRoofLines.push(
drawHipLine(hipPoint, canvas, roof, textMode, null, getDegreeByChon(currLine.attributes.pitch), getDegreeByChon(currLine.attributes.pitch)),
drawHipLine(hipPoint, canvas, roof, textMode, getDegreeByChon(currLine.attributes.pitch), getDegreeByChon(currLine.attributes.pitch)),
)
if (isLine) {
@ -5067,14 +5091,6 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
downRoofGable
.filter((l) => l.type === 'B')
.forEach(({ currLine, currIndex }) => {
const checkLine = new fabric.Line([currLine.x1, currLine.y1, currLine.x2, currLine.y2], {
stroke: 'red',
strokeWidth: 4,
parentId: roofId,
name: 'check',
})
canvas.add(checkLine).renderAll()
// 라인의 방향
const currVector = { x: Math.sign(clamp01(currLine.x1 - currLine.x2)), y: Math.sign(clamp01(currLine.y1 - currLine.y2)) }
@ -5148,9 +5164,6 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
orthogonalEndDistance = Infinity,
orthogonalEndLine
oppLines.forEach((line) => {
const checkLine = new fabric.Line([line.x1, line.y1, line.x2, line.y2], { stroke: 'red', strokeWidth: 4, parentId: roofId, name: 'check' })
canvas.add(checkLine).renderAll()
if (currVector.x === 0) {
//세로선
// 시작포인트와 가까운 포인트의 길이
@ -5242,7 +5255,7 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
getDegreeByChon(currLine.attributes.pitch),
getDegreeByChon(currLine.attributes.pitch),
),
@ -5253,7 +5266,7 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
getDegreeByChon(currLine.attributes.pitch),
getDegreeByChon(currLine.attributes.pitch),
),
@ -5261,6 +5274,226 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
}
})
//처마에서 파생된 하단 지붕 라인 처리.
downRoofEaves.forEach(({ currLine, currIndex }) => {
const prevIndex = (currIndex - 1 + baseLines.length) % baseLines.length
const nextIndex = (currIndex + 1) % baseLines.length
const analyze = analyzeLine(currLine)
const currMidX = (currLine.x1 + currLine.x2) / 2
const currMidY = (currLine.y1 + currLine.y2) / 2
const roofLine = analyze.roofLine
const roofVector = { x: Math.sign(clamp01(roofLine.x2 - roofLine.x1)), y: Math.sign(clamp01(roofLine.y2 - roofLine.y1)) }
const originPoint = currLine.attributes.originPoint
let isFlowInside // 조정된 형이 안쪽인지 바깥쪽인지 판단.
let flowDistance = 0 // 조정된 거리
if (analyze.isVertical) {
//세로선
flowDistance = Math.abs(currLine.x1 - originPoint.x1)
const isLeftIn = checkWallPolygon.inPolygon({ x: currMidX - 1, y: currMidY })
const vector = Math.sign(currLine.x1 - originPoint.x1)
isFlowInside = isLeftIn ? vector < 0 : vector > 0
} else if (analyze.isHorizontal) {
//가로선
flowDistance = Math.abs(currLine.y1 - originPoint.y1)
const isTopIn = checkWallPolygon.inPolygon({ x: currMidX, y: currMidY - 1 })
const vector = Math.sign(currLine.y1 - originPoint.y1)
isFlowInside = isTopIn ? vector < 0 : vector > 0
}
console.log('isFlowInside', isFlowInside)
const roofCheckPoint = { x: roofLine.x2 + roofVector.x, y: roofLine.y2 + roofVector.y }
console.log('roofCheck : ', roof.inPolygon(roofCheckPoint))
let otherLine = roof.inPolygon(roofCheckPoint) ? baseLines[nextIndex] : baseLines[prevIndex]
//상단 지붕
const upLine = isFlowInside ? otherLine : currLine
//하단 지붕
const downLine = isFlowInside ? currLine : otherLine
const allLinePoint = [
{ x: upLine.x1, y: upLine.y1 },
{ x: upLine.x2, y: upLine.y2 },
{ x: downLine.x1, y: downLine.y1 },
{ x: downLine.x2, y: downLine.y2 },
]
//두 라인이 만나는 포인트
let joinPoint
allLinePoint.forEach((point, i) => {
allLinePoint.forEach((point2, j) => {
if (i !== j && point.x === point2.x && point.y === point2.y) {
joinPoint = point
}
})
})
const upDegree = getDegreeByChon(upLine.attributes.pitch)
const upAnalyze = analyzeLine(upLine)
const upRoofLine = upAnalyze.roofLine
const addUpOffset = flowDistance //상단 지붕선의 추가길이
const upRoofVector = { x: Math.sign(clamp01(upRoofLine.x2 - upRoofLine.x1)), y: Math.sign(clamp01(upRoofLine.y2 - upRoofLine.y1)) }
const upRoofPoint = [] //상단 지붕선
let upHipStartPoint
if (roof.inPolygon({ x: upRoofLine.x2 + upRoofVector.x * addUpOffset, y: upRoofLine.y2 + upRoofVector.y * addUpOffset })) {
upRoofPoint.push(upRoofLine.x1, upRoofLine.y1, upRoofLine.x2 + upRoofVector.x * addUpOffset, upRoofLine.y2 + upRoofVector.y * addUpOffset)
upHipStartPoint = { x: upRoofLine.x1, y: upRoofLine.y1 }
} else {
upRoofPoint.push(upRoofLine.x1 - upRoofVector.x * addUpOffset, upRoofLine.y1 - upRoofVector.y * addUpOffset, upRoofLine.x2, upRoofLine.y2)
upHipStartPoint = { x: upRoofLine.x2, y: upRoofLine.y2 }
}
const downDegree = getDegreeByChon(downLine.attributes.pitch)
const downAnalyze = analyzeLine(downLine)
const downRoofLine = downAnalyze.roofLine
const addDownOffset = upLine.attributes.offset // 하단 지붕선의 추가길이
const downRoofVector = { x: Math.sign(clamp01(downRoofLine.x2 - downRoofLine.x1)), y: Math.sign(clamp01(downRoofLine.y2 - downRoofLine.y1)) }
const downRoofPoint = [] // 하단 지붕선
let downHipStartPoint
if (roof.inPolygon({ x: downRoofLine.x2 + downRoofVector.x * addDownOffset, y: downRoofLine.y2 + downRoofVector.y * addDownOffset })) {
downRoofPoint.push(
downRoofLine.x1,
downRoofLine.y1,
downRoofLine.x2 + downRoofVector.x * addDownOffset,
downRoofLine.y2 + downRoofVector.y * addDownOffset,
)
downHipStartPoint = { x: downRoofPoint[2], y: downRoofPoint[3] }
} else {
downRoofPoint.push(
downRoofLine.x1 - downRoofVector.x * addDownOffset,
downRoofLine.y1 - downRoofVector.y * addDownOffset,
downRoofLine.x2,
downRoofLine.y2,
)
downHipStartPoint = { x: downRoofPoint[0], y: downRoofPoint[1] }
}
const checkUpLine = new fabric.Line(upRoofPoint, { stroke: 'red', strokeWidth: 4, parentId: roofId, name: 'check' })
const checkDownLine = new fabric.Line(downRoofPoint, { stroke: 'yellow', strokeWidth: 4, parentId: roofId, name: 'check' })
canvas.add(checkUpLine, checkDownLine).renderAll()
//상단지붕선과 만나는 innerLines 조정
const upRoofEdge = { vertex1: { x: upRoofPoint[0], y: upRoofPoint[1] }, vertex2: { x: upRoofPoint[2], y: upRoofPoint[3] } }
let upHipVector = getHalfAngleVector(upLine, downLine)
const vectorCheckPoint = { x: joinPoint.x + upHipVector.x, y: joinPoint.y + upHipVector.y }
if (!checkWallPolygon.inPolygon(vectorCheckPoint)) {
upHipVector = { x: -upHipVector.x, y: -upHipVector.y }
}
const findUpP1 = { x: joinPoint.x, y: joinPoint.y }
const findUpP2 = { x: joinPoint.x + upHipVector.x, y: joinPoint.y + upHipVector.y }
// 상하단 지붕이 만나는 교점에서 파생되는 추녀마루 확인.
let joinHipLine = innerLines.find((line) => {
return isPointOnLineNew(line, findUpP1) && isPointOnLineNew(line, findUpP2)
})
if (joinHipLine) {
// 상단 지붕선과 추녀마루의 교점 파악.
const joinHipEdge = { vertex1: { x: joinHipLine.x1, y: joinHipLine.y1 }, vertex2: { x: joinHipLine.x2, y: joinHipLine.y2 } }
const intersectJoin = edgesIntersection(upRoofEdge, joinHipEdge)
// 연결된 추녀마루 포인트 조정
const pointVector1 = { x: Math.sign(clamp01(joinHipLine.x1 - intersectJoin.x)), y: Math.sign(clamp01(joinHipLine.y1 - intersectJoin.y)) }
const pointVector2 = { x: Math.sign(clamp01(joinHipLine.x2 - intersectJoin.x)), y: Math.sign(clamp01(joinHipLine.y2 - intersectJoin.y)) }
let joinEndPoint
if (pointVector1.x === upHipVector.x && pointVector1.y === upHipVector.y) {
joinHipLine.set({
x1: intersectJoin.x,
y1: intersectJoin.y,
x2: joinHipLine.x1,
y2: joinHipLine.y1,
})
joinHipLine.setCoords()
joinEndPoint = { x: joinHipLine.x1, y: joinHipLine.y1 }
} else if (pointVector2.x === upHipVector.x && pointVector2.y === upHipVector.y) {
joinHipLine.set({
x1: intersectJoin.x,
y1: intersectJoin.y,
x2: joinHipLine.x2,
y2: joinHipLine.y2,
})
joinHipLine.setCoords()
joinEndPoint = { x: joinHipLine.x2, y: joinHipLine.y2 }
}
let upSideLine
baseLines.forEach((line, index) => {
if (line === upLine) {
const upPrevLine = baseLines[(index - 1 + baseLines.length) % baseLines.length]
const upNextLine = baseLines[(index + 1) % baseLines.length]
upSideLine = upPrevLine === downLine ? upNextLine : upPrevLine
}
})
//상단 지붕선과 붙어있는 다른 지붕선이 처마일때 추녀마루가 포함될수 있기 때문에 확인하여 라인조정
if (upSideLine && upSideLine.attributes.type === LINE_TYPE.WALLLINE.EAVES) {
const hipDegree = getDegreeByChon(upSideLine.attributes.pitch)
let minDistance = Infinity
let connectPoint
innerLines
.filter((line) => line !== joinHipLine)
.forEach((line) => {
const lineEdge = { vertex1: { x: line.x1, y: line.y1 }, vertex2: { x: line.x2, y: line.y2 } }
const intersect = edgesIntersection(upRoofEdge, lineEdge)
if (
intersect &&
isPointOnLineNew(line, intersect) &&
isPointOnLineNew({ x1: upRoofPoint[0], y1: upRoofPoint[1], x2: upRoofPoint[2], y2: upRoofPoint[3] }, intersect)
) {
const distance = Math.sqrt(Math.pow(intersect.x - upHipStartPoint.x, 2) + Math.pow(intersect.y - upHipStartPoint.y, 2))
if (distance < minDistance) {
minDistance = distance
connectPoint = intersect
}
}
})
if (connectPoint && minDistance > EPSILON) {
let upHipPoint
if (upHipStartPoint.x === upRoofLine.x1 && upHipStartPoint.y === upRoofLine.y1) {
upHipPoint = [upHipStartPoint.x, upHipStartPoint.y, connectPoint.x, connectPoint.y]
} else {
upHipPoint = [connectPoint.x, connectPoint.y, upHipStartPoint.x, upHipStartPoint.y]
}
downRoofLines.push(drawHipLine(upHipPoint, canvas, roof, textMode, hipDegree, hipDegree)) //각도 있는 처마지붕선
downRoofLines.push(drawRoofLine([connectPoint.x, connectPoint.y, intersectJoin.x, intersectJoin.y], canvas, roof, textMode)) //각도 없는 처마지붕선
} else {
downRoofLines.push(drawRoofLine([upHipStartPoint.x, upHipStartPoint.y, intersectJoin.x, intersectJoin.y], canvas, roof, textMode))
}
} else {
downRoofLines.push(drawRoofLine([upHipStartPoint.x, upHipStartPoint.y, intersectJoin.x, intersectJoin.y], canvas, roof, textMode))
}
//하단지붕선 추가.
const downHipEdge = {
vertex1: { x: downHipStartPoint.x, y: downHipStartPoint.y },
vertex2: { x: downHipStartPoint.x + upRoofVector.x, y: downHipStartPoint.y + upRoofVector.y },
}
const intersectDownJoin = edgesIntersection(downHipEdge, joinHipEdge)
//하단 지붕선에는 지붕선, 추녀마루1, 추녀마루2 가 생성되는것이 기본모양임.
if (intersectDownJoin && isPointOnLineNew(joinHipLine, intersectDownJoin)) {
//지붕선
downRoofLines.push(drawRoofLine(downRoofPoint, canvas, roof, textMode))
//지붕선에서 올라가는 추녀마루1
downRoofLines.push(
drawHipLine(
[downHipStartPoint.x, downHipStartPoint.y, intersectDownJoin.x, intersectDownJoin.y],
canvas,
roof,
textMode,
downDegree,
downDegree,
),
)
//추녀마루에서 마루로 연결되는 추녀마루2
downRoofLines.push(
drawHipLine([intersectDownJoin.x, intersectDownJoin.y, joinEndPoint.x, joinEndPoint.y], canvas, roof, textMode, downDegree, downDegree),
)
}
}
})
// canvas.renderAll()
//추가된 하단 지붕 라인 innerLines에 추가.
innerLines.push(...downRoofLines)
@ -5314,7 +5547,7 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
for (let i = 0; i < splitPoint.length; i++) {
const point = splitPoint[i].point
if (i === 0) {
innerLines.push(drawHipLine([startPoint.x, startPoint.y, point.x, point.y], canvas, roof, textMode, null, prevDegree, prevDegree))
innerLines.push(drawHipLine([startPoint.x, startPoint.y, point.x, point.y], canvas, roof, textMode, prevDegree, prevDegree))
} else {
innerLines.push(drawRoofLine([startPoint.x, startPoint.y, point.x, point.y], canvas, roof, textMode))
}
@ -5323,15 +5556,14 @@ export const drawRoofByAttribute = (roofId, canvas, textMode) => {
if (splitPoint.length === 1) {
innerLines.push(drawRoofLine([startPoint.x, startPoint.y, currentLine.x2, currentLine.y2], canvas, roof, textMode))
} else {
innerLines.push(
drawHipLine([startPoint.x, startPoint.y, currentLine.x2, currentLine.y2], canvas, roof, textMode, null, nextDegree, nextDegree),
)
innerLines.push(drawHipLine([startPoint.x, startPoint.y, currentLine.x2, currentLine.y2], canvas, roof, textMode, nextDegree, nextDegree))
}
} else {
innerLines.push(drawRoofLine([currentLine.x1, currentLine.y1, currentLine.x2, currentLine.y2], canvas, roof, textMode))
}
})
console.log('innerLines : ', innerLines)
//지붕 innerLines에 추가.
roof.innerLines = innerLines
@ -6202,7 +6434,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
prevDegree,
prevDegree,
)
@ -6250,7 +6482,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
nextDegree,
nextDegree,
)
@ -6311,10 +6543,10 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
connectHipPoint = [firstHipPoint[0], firstHipPoint[1], secondHipPoint[0], secondHipPoint[1]]
firstRoofPoint = [currentRoof.x1, currentRoof.y1, firstHipPoint[0], firstHipPoint[1]]
secondRoofPoint = [currentRoof.x2, currentRoof.y2, secondHipPoint[0], secondHipPoint[1]]
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, null, degree, degree)
const firstRoofLine = drawHipLine(firstRoofPoint, canvas, roof, textMode, null, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, null, degree, degree)
const secondRoofLine = drawHipLine(secondRoofPoint, canvas, roof, textMode, null, nextDegree, nextDegree)
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, degree, degree)
const firstRoofLine = drawHipLine(firstRoofPoint, canvas, roof, textMode, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, degree, degree)
const secondRoofLine = drawHipLine(secondRoofPoint, canvas, roof, textMode, nextDegree, nextDegree)
const connectHipLine = drawRoofLine(connectHipPoint, canvas, roof, textMode)
baseHipLines.push({ x1: firstHipLine.x1, y1: firstHipLine.y1, x2: firstHipLine.x2, y2: firstHipLine.y2, line: firstHipLine })
baseHipLines.push({ x1: firstRoofLine.x1, y1: firstRoofLine.y1, x2: firstRoofLine.x2, y2: firstRoofLine.y2, line: firstRoofLine })
@ -6324,8 +6556,8 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
} else {
const firstHipPoint = [currentRoof.x1, currentRoof.y1, currentMidX.toNumber(), currentMidY.toNumber()]
const secondHipPoint = [currentRoof.x2, currentRoof.y2, currentMidX.toNumber(), currentMidY.toNumber()]
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, null, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, null, nextDegree, nextDegree)
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, nextDegree, nextDegree)
baseHipLines.push({ x1: firstHipLine.x1, y1: firstHipLine.y1, x2: firstHipLine.x2, y2: firstHipLine.y2, line: firstHipLine })
baseHipLines.push({ x1: secondHipLine.x1, y1: secondHipLine.y1, x2: secondHipLine.x2, y2: secondHipLine.y2, line: secondHipLine })
}
@ -6413,7 +6645,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
nextDegree,
afterNextDegree,
)
@ -6431,7 +6663,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
prevDegree,
afterNextDegree,
)
@ -6586,10 +6818,10 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
connectHipPoint = [firstHipPoint[0], firstHipPoint[1], secondHipPoint[0], secondHipPoint[1]]
firstRoofPoint = [currentRoof.x1, currentRoof.y1, firstHipPoint[0], firstHipPoint[1]]
secondRoofPoint = [currentRoof.x2, currentRoof.y2, secondHipPoint[0], secondHipPoint[1]]
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, null, degree, degree)
const firstRoofLine = drawHipLine(firstRoofPoint, canvas, roof, textMode, null, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, null, degree, degree)
const secondRoofLine = drawHipLine(secondRoofPoint, canvas, roof, textMode, null, nextDegree, nextDegree)
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, degree, degree)
const firstRoofLine = drawHipLine(firstRoofPoint, canvas, roof, textMode, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, degree, degree)
const secondRoofLine = drawHipLine(secondRoofPoint, canvas, roof, textMode, nextDegree, nextDegree)
const connectHipLine = drawRoofLine(connectHipPoint, canvas, roof, textMode)
baseHipLines.push({ x1: firstHipLine.x1, y1: firstHipLine.y1, x2: firstHipLine.x2, y2: firstHipLine.y2, line: firstHipLine })
baseHipLines.push({ x1: firstRoofLine.x1, y1: firstRoofLine.y1, x2: firstRoofLine.x2, y2: firstRoofLine.y2, line: firstRoofLine })
@ -6599,8 +6831,8 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
} else {
const firstHipPoint = [currentRoof.x1, currentRoof.y1, currentMidX.toNumber(), currentMidY.toNumber()]
const secondHipPoint = [currentRoof.x2, currentRoof.y2, currentMidX.toNumber(), currentMidY.toNumber()]
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, null, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, null, nextDegree, nextDegree)
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, nextDegree, nextDegree)
baseHipLines.push({ x1: firstHipLine.x1, y1: firstHipLine.y1, x2: firstHipLine.x2, y2: firstHipLine.y2, line: firstHipLine })
baseHipLines.push({ x1: secondHipLine.x1, y1: secondHipLine.y1, x2: secondHipLine.x2, y2: secondHipLine.y2, line: secondHipLine })
}
@ -6915,7 +7147,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
degree,
degree,
)
@ -6978,7 +7210,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
degree,
degree,
)
@ -7116,10 +7348,10 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
connectHipPoint = [firstHipPoint[0], firstHipPoint[1], secondHipPoint[0], secondHipPoint[1]]
firstRoofPoint = [currentRoof.x1, currentRoof.y1, firstHipPoint[0], firstHipPoint[1]]
secondRoofPoint = [currentRoof.x2, currentRoof.y2, secondHipPoint[0], secondHipPoint[1]]
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, null, degree, degree)
const firstRoofLine = drawHipLine(firstRoofPoint, canvas, roof, textMode, null, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, null, degree, degree)
const secondRoofLine = drawHipLine(secondRoofPoint, canvas, roof, textMode, null, nextDegree, nextDegree)
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, degree, degree)
const firstRoofLine = drawHipLine(firstRoofPoint, canvas, roof, textMode, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, degree, degree)
const secondRoofLine = drawHipLine(secondRoofPoint, canvas, roof, textMode, nextDegree, nextDegree)
const connectHipLine = drawRoofLine(connectHipPoint, canvas, roof, textMode)
baseHipLines.push({ x1: firstHipLine.x1, y1: firstHipLine.y1, x2: firstHipLine.x2, y2: firstHipLine.y2, line: firstHipLine })
baseHipLines.push({ x1: firstRoofLine.x1, y1: firstRoofLine.y1, x2: firstRoofLine.x2, y2: firstRoofLine.y2, line: firstRoofLine })
@ -7129,8 +7361,8 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
} else {
const firstHipPoint = [currentRoof.x1, currentRoof.y1, currentMidX.toNumber(), currentMidY.toNumber()]
const secondHipPoint = [currentRoof.x2, currentRoof.y2, currentMidX.toNumber(), currentMidY.toNumber()]
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, null, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, null, nextDegree, nextDegree)
const firstHipLine = drawHipLine(firstHipPoint, canvas, roof, textMode, prevDegree, prevDegree)
const secondHipLine = drawHipLine(secondHipPoint, canvas, roof, textMode, nextDegree, nextDegree)
baseHipLines.push({ x1: firstHipLine.x1, y1: firstHipLine.y1, x2: firstHipLine.x2, y2: firstHipLine.y2, line: firstHipLine })
baseHipLines.push({ x1: secondHipLine.x1, y1: secondHipLine.y1, x2: secondHipLine.x2, y2: secondHipLine.y2, line: secondHipLine })
}
@ -7457,7 +7689,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
prevDegree,
prevDegree,
)
@ -7475,7 +7707,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
nextDegree,
nextDegree,
)
@ -8259,7 +8491,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
line = drawRoofLine(points, canvas, roof, textMode)
baseGableLines.push(line)
} else {
line = drawHipLine(points, canvas, roof, textMode, null, currentDegree, currentDegree)
line = drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree)
baseHipLines.push({ x1: line.x1, y1: line.y1, x2: line.x2, y2: line.y2, line })
}
})
@ -8653,7 +8885,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
return
}
const hipLine = drawHipLine(points, canvas, roof, textMode, null, currentDegree, currentDegree)
const hipLine = drawHipLine(points, canvas, roof, textMode, currentDegree, currentDegree)
if (currentVectorX === 0) {
if (Math.sign(currentPoint.x - nextPoint.x) === 0) {
hipLine.attributes.actualSize = hipLine.attributes.planeSize
@ -8789,7 +9021,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
)
if (gableLines.length === 0 && hipLines.length === 0) {
const hipLine1 = drawHipLine(hipPoint1, canvas, roof, textMode, null, degree1, degree1)
const hipLine1 = drawHipLine(hipPoint1, canvas, roof, textMode, degree1, degree1)
baseHipLines.push({ x1: hipLine1.x1, y1: hipLine1.y1, x2: hipLine1.x2, y2: hipLine1.y2, line: hipLine1 })
}
}
@ -8805,7 +9037,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
(line.x2 === hipPoint2[0] && line.y2 === hipPoint2[1] && line.x1 === hipPoint2[2] && line.y1 === hipPoint2[3]),
)
if (hipLines.length === 0 && gableLines.length === 0) {
const hipLine2 = drawHipLine(hipPoint2, canvas, roof, textMode, null, degree2, degree2)
const hipLine2 = drawHipLine(hipPoint2, canvas, roof, textMode, degree2, degree2)
baseHipLines.push({ x1: hipLine2.x1, y1: hipLine2.y1, x2: hipLine2.x2, y2: hipLine2.y2, line: hipLine2 })
}
}
@ -8873,7 +9105,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
)
if (hipLines.length === 0 && gableLines.length === 0) {
const hipLine1 = drawHipLine(hipPoint1, canvas, roof, textMode, null, degree1, degree1)
const hipLine1 = drawHipLine(hipPoint1, canvas, roof, textMode, degree1, degree1)
baseHipLines.push({ x1: hipLine1.x1, y1: hipLine1.y1, x2: hipLine1.x2, y2: hipLine1.y2, line: hipLine1 })
}
}
@ -8889,7 +9121,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
(line.x2 === hipPoint2[0] && line.y2 === hipPoint2[1] && line.x1 === hipPoint2[2] && line.y1 === hipPoint2[3]),
)
if (hipLines.length === 0 && gableLines.length === 0) {
const hipLine2 = drawHipLine(hipPoint2, canvas, roof, textMode, null, degree2, degree2)
const hipLine2 = drawHipLine(hipPoint2, canvas, roof, textMode, degree2, degree2)
baseHipLines.push({ x1: hipLine2.x1, y1: hipLine2.y1, x2: hipLine2.x2, y2: hipLine2.y2, line: hipLine2 })
}
}
@ -9024,8 +9256,8 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
Big(currentRoof.x2).plus(Big(nextHipVector.x).times(lineWidth)).toNumber(),
Big(currentRoof.y2).plus(Big(nextHipVector.y).times(lineWidth)).toNumber(),
]
const prevHipLine = drawHipLine(prevPoint, canvas, roof, textMode, null, prevDegree, currentDegree)
const nextHipLine = drawHipLine(nextPoint, canvas, roof, textMode, null, currentDegree, nextDegree)
const prevHipLine = drawHipLine(prevPoint, canvas, roof, textMode, prevDegree, currentDegree)
const nextHipLine = drawHipLine(nextPoint, canvas, roof, textMode, currentDegree, nextDegree)
baseHipLines.push({ x1, y1, x2: prevHipLine.x1, y2: prevHipLine.y1, line: prevHipLine })
baseHipLines.push({ x1: x2, y1: y2, x2: nextHipLine.x1, y2: nextHipLine.y1, line: nextHipLine })
@ -9041,8 +9273,8 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
const prevGablePoint = [prevHipLine.x2, prevHipLine.y2, midX, midY]
const nextGablePoint = [nextHipLine.x2, nextHipLine.y2, midX, midY]
const prevGableLine = drawHipLine(prevGablePoint, canvas, roof, textMode, null, prevDegree, currentDegree)
const nextGableLine = drawHipLine(nextGablePoint, canvas, roof, textMode, null, currentDegree, nextDegree)
const prevGableLine = drawHipLine(prevGablePoint, canvas, roof, textMode, prevDegree, currentDegree)
const nextGableLine = drawHipLine(nextGablePoint, canvas, roof, textMode, currentDegree, nextDegree)
baseHipLines.push({ x1: prevGableLine.x1, y1: prevGableLine.y1, x2: prevGableLine.x2, y2: prevGableLine.y2, line: prevGableLine })
baseHipLines.push({ x1: nextGableLine.x1, y1: nextGableLine.y1, x2: nextGableLine.x2, y2: nextGableLine.y2, line: nextGableLine })
@ -9809,8 +10041,8 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
const prevHipPoint = [currentRoof.x1, currentRoof.y1, currentMidX, currentMidY]
const nextHipPoint = [currentRoof.x2, currentRoof.y2, currentMidX, currentMidY]
const prevHipLine = drawHipLine(prevHipPoint, canvas, roof, textMode, null, prevDegree, prevDegree)
const nextHipLine = drawHipLine(nextHipPoint, canvas, roof, textMode, null, nextDegree, nextDegree)
const prevHipLine = drawHipLine(prevHipPoint, canvas, roof, textMode, prevDegree, prevDegree)
const nextHipLine = drawHipLine(nextHipPoint, canvas, roof, textMode, nextDegree, nextDegree)
baseHipLines.push({ x1: prevHipLine.x1, y1: prevHipLine.y1, x2: prevHipLine.x2, y2: prevHipLine.y2, line: prevHipLine })
baseHipLines.push({ x1: nextHipLine.x1, y1: nextHipLine.y1, x2: nextHipLine.x2, y2: nextHipLine.y2, line: nextHipLine })
}
@ -10258,7 +10490,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
prevDegree,
currentDegree,
)
@ -10402,7 +10634,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
prevDegree,
currentDegree,
)
@ -10847,7 +11079,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
ridgeLine.x1 === firstHipLine.x1 ? firstHipLine.x2 : firstHipLine.x1,
ridgeLine.y2,
]
const oppositeRoofLine = drawHipLine(oppositeRoofPoints, canvas, roof, textMode, null, firstDegree, firstDegree)
const oppositeRoofLine = drawHipLine(oppositeRoofPoints, canvas, roof, textMode, firstDegree, firstDegree)
baseHipLines.push({
x1: oppositeRoofLine.x1,
y1: oppositeRoofLine.y1,
@ -10905,7 +11137,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
const intersection = intersections[0].intersection
const intersectRidge = intersections[0].ridge
const oppositeRoofPoints = [ridgeLine.x2, ridgeLine.y2, intersection.x, intersection.y]
const oppositeRoofLine = drawHipLine(oppositeRoofPoints, canvas, roof, textMode, null, secondDegree, secondDegree)
const oppositeRoofLine = drawHipLine(oppositeRoofPoints, canvas, roof, textMode, secondDegree, secondDegree)
baseHipLines.push({
x1: oppositeLine.x1,
y1: oppositeLine.y1,
@ -10948,7 +11180,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
ridgeLine.x2,
ridgeLine.y1 === firstHipLine.y1 ? firstHipLine.y2 : firstHipLine.y1,
]
const oppositeRoofLine = drawHipLine(oppositeRoofPoints, canvas, roof, textMode, null, firstDegree, firstDegree)
const oppositeRoofLine = drawHipLine(oppositeRoofPoints, canvas, roof, textMode, firstDegree, firstDegree)
baseHipLines.push({
x1: oppositeRoofLine.x1,
y1: oppositeRoofLine.y1,
@ -11005,7 +11237,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
const intersection = intersections[0].intersection
const intersectRidge = intersections[0].ridge
const oppositeRoofPoints = [ridgeLine.x2, ridgeLine.y2, intersection.x, intersection.y]
const oppositeRoofLine = drawHipLine(oppositeRoofPoints, canvas, roof, textMode, null, secondDegree, secondDegree)
const oppositeRoofLine = drawHipLine(oppositeRoofPoints, canvas, roof, textMode, secondDegree, secondDegree)
baseHipLines.push({
x1: oppositeLine.x1,
y1: oppositeLine.y1,
@ -11242,7 +11474,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
prevDegree,
currentDegree,
)
@ -11384,7 +11616,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
prevDegree,
currentDegree,
)
@ -11671,7 +11903,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
}
})
const hipLine = drawHipLine(point, canvas, roof, textMode, null, prevDegree, currentDegree)
const hipLine = drawHipLine(point, canvas, roof, textMode, prevDegree, currentDegree)
if (hipBasePoint) {
baseHipLines.push({ x1: hipBasePoint.x1, y1: hipBasePoint.y1, x2: point[2], y2: point[3], line: hipLine })
} else {
@ -11854,7 +12086,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
canvas,
roof,
textMode,
null,
prevDegree,
currentDegree,
)
@ -12158,7 +12390,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
.lt(1)
) {
// console.log('힙1')
const hipLine = drawHipLine(hipStartPoint, canvas, roof, textMode, null, prevDegree, currentDegree)
const hipLine = drawHipLine(hipStartPoint, canvas, roof, textMode, prevDegree, currentDegree)
baseHipLines.push({
x1: hipStartPoint[0],
y1: hipStartPoint[1],
@ -12192,7 +12424,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
.abs()
.lt(1)
) {
const hipLine = drawHipLine(isStartPoint, canvas, roof, textMode, null, prevDegree, currentDegree)
const hipLine = drawHipLine(isStartPoint, canvas, roof, textMode, prevDegree, currentDegree)
baseHipLines.push({
x1: isStartPoint[0],
y1: isStartPoint[1],
@ -12348,14 +12580,14 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
const overlapLine = overlapLineX[0]
const maxX = Math.max(overlapLine.x1, overlapLine.x2)
const point = [hipLine.x2, hipLine.y2, maxX, hipLine.y2]
const addLine = drawHipLine(point, canvas, roof, textMode, null, prevDegree, currentDegree)
const addLine = drawHipLine(point, canvas, roof, textMode, prevDegree, currentDegree)
baseHipLines.push({ x1: point[0], y1: point[1], x2: point[2], y2: point[3], line: addLine })
}
if (overlapLineY.length > 0) {
const overlapLine = overlapLineY[0]
const maxY = Math.max(overlapLine.y1, overlapLine.y2)
const point = [hipLine.x2, hipLine.y2, hipLine.x2, maxY]
const addLine = drawHipLine(point, canvas, roof, textMode, null, prevDegree, currentDegree)
const addLine = drawHipLine(point, canvas, roof, textMode, prevDegree, currentDegree)
baseHipLines.push({ x1: point[0], y1: point[1], x2: point[2], y2: point[3], line: addLine })
}
}
@ -12403,7 +12635,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
hipLine.x1 === horizonPoint[0] && hipLine.y1 === horizonPoint[1] && hipLine.x2 === horizonPoint[2] && hipLine.y2 === horizonPoint[3],
)
if (!alreadyHorizonLines) {
addLine = drawHipLine(horizonPoint, canvas, roof, textMode, null, prevDegree, currentDegree)
addLine = drawHipLine(horizonPoint, canvas, roof, textMode, prevDegree, currentDegree)
baseHipLines.push({
x1: horizonPoint[0],
y1: horizonPoint[1],
@ -12426,7 +12658,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
hipLine.x1 === verticalPoint[0] && hipLine.y1 === verticalPoint[1] && hipLine.x2 === verticalPoint[2] && hipLine.y2 === verticalPoint[3],
)
if (!alreadyVerticalLine) {
addLine = drawHipLine(verticalPoint, canvas, roof, textMode, null, prevDegree, currentDegree)
addLine = drawHipLine(verticalPoint, canvas, roof, textMode, prevDegree, currentDegree)
baseHipLines.push({
x1: verticalPoint[0],
y1: verticalPoint[1],
@ -12567,7 +12799,7 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
)
if (!baseIntersection && alreadyHips.length === 0 && otherHipInterSection.length === 0) {
const hipLine = drawHipLine(hipPoints, canvas, roof, textMode, null, prevDegree, currentDegree)
const hipLine = drawHipLine(hipPoints, canvas, roof, textMode, prevDegree, currentDegree)
baseHipLines.push({ x1: hipPoints[0], y1: hipPoints[1], x2: hipPoints[2], y2: hipPoints[3], line: hipLine })
}
}
@ -12619,11 +12851,10 @@ export const drawRidgeRoof = (roofId, canvas, textMode) => {
* @param canvas
* @param roof
* @param textMode
* @param currentRoof
* @param prevDegree
* @param currentDegree
*/
const drawHipLine = (points, canvas, roof, textMode, currentRoof, prevDegree, currentDegree) => {
const drawHipLine = (points, canvas, roof, textMode, prevDegree, currentDegree) => {
/** 대각선인 경우 경사를 조정해서 계산*/
const baseX = Big(points[0]).minus(Big(points[2])).abs()
const baseY = Big(points[1]).minus(Big(points[3])).abs()

View File

@ -212,12 +212,14 @@ const movingLineFromSkeleton = (roofId, canvas) => {
point.y = Big(point.y).plus(moveUpDownLength).toNumber();
}
}else if(moveDirection === 'out'){
if(isSamePoint(roof.basePoints[index], originalStartPoint)) {
point.y = Big(point.y).minus(moveUpDownLength).toNumber();
}
if (isSamePoint(roof.basePoints[index], originalEndPoint)) {
if(isSamePoint(roof.basePoints[index], originalStartPoint) || isSamePoint(roof.basePoints[index], originalEndPoint)) {
point.y = Big(point.y).minus(moveUpDownLength).toNumber();
// console.log('roof.basePoints[index]', roof.basePoints[index])
// console.log('point.x::::', point)
// console.log('originalStartPoint', originalStartPoint)
// console.log('originalEndPoint', originalEndPoint)
}
}
}else if(position === 'left'){
@ -262,7 +264,69 @@ const movingLineFromSkeleton = (roofId, canvas) => {
line.startPoint = newStartPoint;
line.endPoint = newEndPoint;
});
return newPoints;
/**
* 직선다각형을 이루지 못하는 좌표를 삭제합니다.
* @param {Array<object>} points - 폴리곤 좌표 배열
* @returns {Array<object>} 정리된 좌표 배열
*/
function removeNonOrthogonalPoints(points) {
if (!points || points.length < 3) return points;
const EPSILON = 1.0;
const isOrthogonal = (p1, p2) =>
Math.abs(p1.x - p2.x) < EPSILON || Math.abs(p1.y - p2.y) < EPSILON;
let current = [...points];
let changed = true;
// 1. 대각선을 만드는 점 제거
while (changed && current.length >= 3) {
changed = false;
for (let i = 0; i < current.length; i++) {
const pPrev = current[(i - 1 + current.length) % current.length];
const pCurr = current[i];
const pNext = current[(i + 1) % current.length];
// 현재 점(pCurr)을 기준으로 앞뒤 연결이 모두 직교하지 않거나,
// 현재 점을 제거했을 때 앞뒤 점(pPrev, pNext)이 직교하게 된다면 현재 점이 불필요한 "꺾임"일 수 있음.
if (!isOrthogonal(pPrev, pCurr) || !isOrthogonal(pCurr, pNext)) {
if (isOrthogonal(pPrev, pNext)) {
current.splice(i, 1);
changed = true;
break;
}
}
}
}
// 2. 일직선상의 중간 점 제거 (수평 또는 수직선상에 세 점이 있는 경우)
changed = true;
while (changed && current.length >= 3) {
changed = false;
for (let i = 0; i < current.length; i++) {
const p1 = current[i];
const p2 = current[(i + 1) % current.length];
const p3 = current[(i + 2) % current.length];
if ((Math.abs(p1.x - p2.x) < EPSILON && Math.abs(p2.x - p3.x) < EPSILON) ||
(Math.abs(p1.y - p2.y) < EPSILON && Math.abs(p2.y - p3.y) < EPSILON)) {
current.splice((i + 1) % current.length, 1);
changed = true;
break;
}
}
}
return current;
}
const cleaned = removeNonOrthogonalPoints(newPoints);
console.log(cleaned); // 결과: 4개의 점만 남음 (P1, P2, P3, P4)
return cleaned;
}
}
@ -376,7 +440,7 @@ export const skeletonBuilder = (roofId, canvas, textMode) => {
canvas.set('skeleton', cleanSkeleton)
canvas.renderAll()
console.log('skeleton rendered.', canvas)
//console.log('skeleton rendered.', canvas)
} catch (e) {
console.error('스켈레톤 생성 중 오류 발생:', e)
if (canvas.skeletonStates) {
@ -470,9 +534,14 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
line.attributes.type === 'gable' && isSameLine(Begin.X, Begin.Y, End.X, End.Y, line)
);
if (gableBaseLine) {
// Store current state before processing
const beforeGableProcessing = JSON.parse(JSON.stringify(skeletonLines));
if (gableBaseLine) {
// Store current state before processing - avoid circular refs by only picking needed data
const beforeGableProcessing = skeletonLines.map(line => ({
p1: { x: line.p1.x, y: line.p1.y },
p2: { x: line.p2.x, y: line.p2.y },
attributes: { ...line.attributes },
lineStyle: { ...line.lineStyle }
}));
// if(canvas.skeletonLines.length > 0){
// skeletonLines = canvas.skeletonLines;
@ -623,51 +692,51 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
const sortRoofLines = ensureCounterClockwiseLines(roofLines)
// roofLines의 방향에 맞춰 currentRoofLines의 방향을 조정
const alignLineDirection = (sourceLines, targetLines) => {
return sourceLines.map((sourceLine) => {
// 가장 가까운 targetLine 찾기
const nearestTarget = targetLines.reduce((nearest, targetLine) => {
const sourceCenter = {
x: (sourceLine.x1 + sourceLine.x2) / 2,
y: (sourceLine.y1 + sourceLine.y2) / 2,
}
const targetCenter = {
x: (targetLine.x1 + targetLine.x2) / 2,
y: (targetLine.y1 + targetLine.y2) / 2,
}
const distance = Math.hypot(sourceCenter.x - targetCenter.x, sourceCenter.y - targetCenter.y)
return !nearest || distance < nearest.distance ? { line: targetLine, distance } : nearest
}, null)?.line
if (!nearestTarget) return sourceLine
// 방향이 반대인지 확인 (벡터 내적을 사용)
const sourceVec = {
x: sourceLine.x2 - sourceLine.x1,
y: sourceLine.y2 - sourceLine.y1,
}
const targetVec = {
x: nearestTarget.x2 - nearestTarget.x1,
y: nearestTarget.y2 - nearestTarget.y1,
}
const dotProduct = sourceVec.x * targetVec.x + sourceVec.y * targetVec.y
// 내적이 음수이면 방향이 반대이므로 뒤집기
if (dotProduct < 0) {
return {
...sourceLine,
x1: sourceLine.x2,
y1: sourceLine.y2,
x2: sourceLine.x1,
y2: sourceLine.y1,
}
}
return sourceLine
})
}
// const alignLineDirection = (sourceLines, targetLines) => {
// return sourceLines.map((sourceLine) => {
// // 가장 가까운 targetLine 찾기
// const nearestTarget = targetLines.reduce((nearest, targetLine) => {
// const sourceCenter = {
// x: (sourceLine.x1 + sourceLine.x2) / 2,
// y: (sourceLine.y1 + sourceLine.y2) / 2,
// }
// const targetCenter = {
// x: (targetLine.x1 + targetLine.x2) / 2,
// y: (targetLine.y1 + targetLine.y2) / 2,
// }
// const distance = Math.hypot(sourceCenter.x - targetCenter.x, sourceCenter.y - targetCenter.y)
//
// return !nearest || distance < nearest.distance ? { line: targetLine, distance } : nearest
// }, null)?.line
//
// if (!nearestTarget) return sourceLine
//
// // 방향이 반대인지 확인 (벡터 내적을 사용)
// const sourceVec = {
// x: sourceLine.x2 - sourceLine.x1,
// y: sourceLine.y2 - sourceLine.y1,
// }
// const targetVec = {
// x: nearestTarget.x2 - nearestTarget.x1,
// y: nearestTarget.y2 - nearestTarget.y1,
// }
//
// const dotProduct = sourceVec.x * targetVec.x + sourceVec.y * targetVec.y
//
// // 내적이 음수이면 방향이 반대이므로 뒤집기
// if (dotProduct < 0) {
// return {
// ...sourceLine,
// x1: sourceLine.x2,
// y1: sourceLine.y2,
// x2: sourceLine.x1,
// y2: sourceLine.y1,
// }
// }
//
// return sourceLine
// })
// }
console.log('wallBaseLines', wall.baseLines)
@ -693,10 +762,32 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
console.log('wallBaseLine:', wallBaseLine.x1, wallBaseLine.y1, wallBaseLine.x2, wallBaseLine.y2)
console.log('isSamePoint result:', isSameLine2(wallBaseLine, wallLine))
const isCollinear = (l1, l2, tolerance = 0.1) => {
const slope1 = Math.abs(l1.x2 - l1.x1) < tolerance ? Infinity : (l1.y2 - l1.y1) / (l1.x2 - l1.x1)
const slope2 = Math.abs(l2.x2 - l2.x1) < tolerance ? Infinity : (l2.y2 - l2.y1) / (l2.x2 - l2.x1)
if (slope1 === Infinity && slope2 === Infinity) {
return Math.abs(l1.x1 - l2.x1) < tolerance
}
if (Math.abs(slope1 - slope2) > tolerance) return false
const yIntercept1 = l1.y1 - slope1 * l1.x1
const yIntercept2 = l2.y1 - slope2 * l2.x1
return Math.abs(yIntercept1 - yIntercept2) < tolerance
}
if (isCollinear(wallBaseLine, wallLine)) {
return
}
if (isSameLine2(wallBaseLine, wallLine)) {
return
}
const movedStart = Math.abs(wallBaseLine.x1 - wallLine.x1) > EPSILON || Math.abs(wallBaseLine.y1 - wallLine.y1) > EPSILON
const movedEnd = Math.abs(wallBaseLine.x2 - wallLine.x2) > EPSILON || Math.abs(wallBaseLine.y2 - wallLine.y2) > EPSILON
@ -854,10 +945,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
} else {
getAddLine({ y: inLine.y2, x: inLine.x2 }, { y: bStartY, x: wallLine.x2 }, 'pink')
}
getAddLine({ y: bStartY, x: wallLine.x2 }, { y: roofLine.y1, x: wallLine.x1 }, 'magenta')
getAddLine({ y: newLine.y1, x: newLine.x1 }, { y: newLine.y2, x: wallLine.x2 }, 'Gray')
findPoints.push({ y: aStartY, x: newPStart.x, position: 'left_out_start' })
}else{
newPStart.y = roofLine.y1
}
getAddLine({ y: bStartY, x: wallLine.x2 }, { y: roofLine.y1, x: wallLine.x1 }, 'magenta')
getAddLine({ y: newLine.y1, x: newLine.x1 }, { y: newLine.y2, x: wallLine.x2 }, 'Gray')
findPoints.push({ y: aStartY, x: newPStart.x, position: 'left_out_start' })
} else {
const cLineY = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber()
newPStart.y = Big(newPStart.y).minus(cLineY).toNumber()
@ -909,10 +1003,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
} else {
getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: bStartY, x: wallLine.x1 }, 'pink')
}
getAddLine({ y: bStartY, x: wallLine.x1 }, { y: roofLine.y2, x: wallLine.x2 }, 'magenta')
getAddLine({ y: newLine.y2, x: newLine.x2 }, { y: newLine.y1, x: wallLine.x1 }, 'Gray')
findPoints.push({ y: aStartY, x: newPEnd.x, position: 'left_out_end' })
}else{
newPEnd.y = roofLine.y2
}
getAddLine({ y: bStartY, x: wallLine.x1 }, { y: roofLine.y2, x: wallLine.x2 }, 'magenta')
getAddLine({ y: newLine.y2, x: newLine.x2 }, { y: newLine.y1, x: wallLine.x1 }, 'Gray')
findPoints.push({ y: aStartY, x: newPEnd.x, position: 'left_out_end' })
} else {
const cLineY = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber()
newPEnd.y = Big(newPEnd.y).plus(cLineY).toNumber()
@ -1024,10 +1121,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
} else {
getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: bStartY, x: wallLine.x2 }, 'pink')
}
getAddLine({ y: bStartY, x: wallLine.x2 }, { y: roofLine.y1, x: wallLine.x1 }, 'magenta')
getAddLine({ y: newLine.y1, x: newLine.x1 }, { y: newLine.y2, x: wallLine.x2 }, 'Gray')
findPoints.push({ y: aStartY, x: newPEnd.x, position: 'right_out_start' })
}else{
newPStart.y = roofLine.y1
}
getAddLine({ y: bStartY, x: wallLine.x2 }, { y: roofLine.y1, x: wallLine.x1 }, 'magenta')
getAddLine({ y: newLine.y1, x: newLine.x1 }, { y: newLine.y2, x: wallLine.x2 }, 'Gray')
findPoints.push({ y: aStartY, x: newPEnd.x, position: 'right_out_start' })
} else {
const cLineY = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber()
newPStart.y = Big(newPStart.y).plus(cLineY).toNumber()
@ -1213,10 +1313,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
} else {
getAddLine({ x: inLine.x1, y: inLine.y1 }, { x: bStartX, y: wallLine.y1 }, 'pink')
}
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }, 'magenta')
getAddLine({ x: newLine.x1, y: newLine.y1 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
findPoints.push({ x: aStartX, y: newPEnd.y, position: 'top_out_start' })
}else{ //라인머지
newPStart.x = roofLine.x1
}
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }, 'magenta')
getAddLine({ x: newLine.x1, y: newLine.y1 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
findPoints.push({ x: aStartX, y: newPEnd.y, position: 'top_out_start' })
} else {
const cLineX = Big(wallBaseLine.y1).minus(wallLine.y1).abs().toNumber()
newPStart.x = Big(newPStart.x).plus(cLineX).toNumber()
@ -1265,10 +1368,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
} else {
getAddLine({ x: inLine.x1, y: inLine.y1 }, { x: bStartX, y: wallLine.y1 }, 'pink')
}
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x2, y: wallLine.y2 }, 'magenta')
getAddLine({ x: newLine.x2, y: newLine.y2 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
findPoints.push({ x: aStartX, y: newPEnd.y, position: 'top_out_end' })
}else{
newPEnd.x = roofLine.x2
}
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x2, y: wallLine.y2 }, 'magenta')
getAddLine({ x: newLine.x2, y: newLine.y2 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
findPoints.push({ x: aStartX, y: newPEnd.y, position: 'top_out_end' })
} else {
const cLineX = Big(wallLine.y2).minus(wallBaseLine.y2).abs().toNumber()
newPEnd.x = Big(newPEnd.x).minus(cLineX).toNumber()
@ -1375,10 +1481,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
} else {
getAddLine({ x: inLine.x1, y: inLine.y1 }, { x: bStartX, y: wallLine.y1 }, 'pink')
}
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }, 'magenta')
getAddLine({ x: newLine.x1, y: newLine.y1 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
findPoints.push({ x: aStartX, y: newPEnd.y, position: 'bottom_out_start' })
}else {
newPStart.x = roofLine.x1
}
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }, 'magenta')
getAddLine({ x: newLine.x1, y: newLine.y1 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
findPoints.push({ x: aStartX, y: newPEnd.y, position: 'bottom_out_start' })
} else {
const cLineX = Big(wallBaseLine.y1).minus(wallLine.y1).abs().toNumber()
newPStart.x = Big(newPStart.x).minus(cLineX).toNumber()
@ -1429,10 +1538,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
} else {
getAddLine({ x: inLine.x1, y: inLine.y1 }, { x: bStartX, y: wallLine.y1 }, 'pink')
}
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x2, y: wallLine.y2 }, 'magenta')
getAddLine({ x: newLine.x2, y: newLine.y2 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
findPoints.push({ x: aStartX, y: newPEnd.y, position: 'bottom_out_end' })
}else{
newPEnd.x = roofLine.x2
}
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x2, y: wallLine.y2 }, 'magenta')
getAddLine({ x: newLine.x2, y: newLine.y2 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
findPoints.push({ x: aStartX, y: newPEnd.y, position: 'bottom_out_end' })
} else {
const cLineX = Big(wallBaseLine.y2).minus(wallLine.y2).abs().toNumber()
newPEnd.x = Big(newPEnd.x).plus(cLineX).toNumber()
@ -3424,58 +3536,78 @@ function getTurnDirection(p1, p2, p3) {
function isValleyVertex(targetPoint, connectedLine, allLines, isStartVertex) {
const tolerance = 0.1;
// 1. 연결된 '다른' 라인을 찾습니다.
// isStartVertex가 true면 : 이 점으로 '들어오는' 라인(Previous Line)을 찾아야 함
// isStartVertex가 false면 : 이 점에서 '나가는' 라인(Next Line)을 찾아야 함
const connectedLineData = {
x1: connectedLine.x1 ?? connectedLine.get?.('x1'),
y1: connectedLine.y1 ?? connectedLine.get?.('y1'),
x2: connectedLine.x2 ?? connectedLine.get?.('x2'),
y2: connectedLine.y2 ?? connectedLine.get?.('y2'),
startPoint: connectedLine.startPoint,
endPoint: connectedLine.endPoint
};
let neighborLine = null;
if (isStartVertex) {
// targetPoint가 Start이므로, 어떤 라인의 End가 targetPoint와 같아야 함 (Previous Line)
neighborLine = allLines.find(l =>
l !== connectedLine &&
isSamePoint(l.endPoint || {x:l.x2, y:l.y2}, targetPoint, tolerance)
);
neighborLine = allLines.find(l => {
if (l === connectedLine) return false;
const lx1 = l.x1 ?? l.get?.('x1');
const ly1 = l.y1 ?? l.get?.('y1');
const lx2 = l.x2 ?? l.get?.('x2');
const ly2 = l.y2 ?? l.get?.('y2');
const end = l.endPoint || { x: lx2, y: ly2 };
return isSamePoint(end, targetPoint, tolerance);
});
} else {
// targetPoint가 End이므로, 어떤 라인의 Start가 targetPoint와 같아야 함 (Next Line)
neighborLine = allLines.find(l =>
l !== connectedLine &&
isSamePoint(l.startPoint || {x:l.x1, y:l.y1}, targetPoint, tolerance)
);
neighborLine = allLines.find(l => {
if (l === connectedLine) return false;
const lx1 = l.x1 ?? l.get?.('x1');
const ly1 = l.y1 ?? l.get?.('y1');
const lx2 = l.x2 ?? l.get?.('x2');
const ly2 = l.y2 ?? l.get?.('y2');
const start = l.startPoint || { x: lx1, y: ly1 };
return isSamePoint(start, targetPoint, tolerance);
});
}
// 연결된 라인을 못 찾았거나 끊겨있으면 판단 불가 (일단 false)
if (!neighborLine) return false;
// 2. 세 점을 구성하여 회전 방향(Turn) 계산
// 순서: PrevLine.Start -> [TargetVertex] -> NextLine.End
const nlx1 = neighborLine.x1 ?? neighborLine.get?.('x1');
const nly1 = neighborLine.y1 ?? neighborLine.get?.('y1');
const nlx2 = neighborLine.x2 ?? neighborLine.get?.('x2');
const nly2 = neighborLine.y2 ?? neighborLine.get?.('y2');
const clx1 = connectedLineData.x1;
const cly1 = connectedLineData.y1;
const clx2 = connectedLineData.x2;
const cly2 = connectedLineData.y2;
let p1, p2, p3;
if (isStartVertex) {
// neighbor(Prev) -> connected(Current)
p1 = neighborLine.startPoint || {x: neighborLine.x1, y: neighborLine.y1};
p2 = targetPoint; // 접점
p3 = connectedLine.endPoint || {x: connectedLine.x2, y: connectedLine.y2};
p1 = neighborLine.startPoint || { x: nlx1, y: nly1 };
p2 = targetPoint;
p3 = connectedLineData.endPoint || { x: clx2, y: cly2 };
} else {
// connected(Current) -> neighbor(Next)
p1 = connectedLine.startPoint || {x: connectedLine.x1, y: connectedLine.y1};
p2 = targetPoint; // 접점
p3 = neighborLine.endPoint || {x: neighborLine.x2, y: neighborLine.y2};
p1 = connectedLineData.startPoint || { x: clx1, y: cly1 };
p2 = targetPoint;
p3 = neighborLine.endPoint || { x: nlx2, y: nly2 };
}
// 3. 외적 계산 (Y축이 아래로 증가하는 캔버스 좌표계 + CCW 진행 기준)
// 값이 양수(+)면 오른쪽 턴 = 골짜기
const crossProduct = getTurnDirection(p1, p2, p3);
console.log('crossProduct:', crossProduct);
return crossProduct > 0;
}
function findInteriorPoint(line, polygonLines) {
const { x1, y1, x2, y2 } = line;
const x1 = line.x1 ?? line.get?.('x1');
const y1 = line.y1 ?? line.get?.('y1');
const x2 = line.x2 ?? line.get?.('x2');
const y2 = line.y2 ?? line.get?.('y2');
// line 객체 포맷 통일
// line 객체 포맷 통일 (함수 내부용)
const currentLine = {
...line,
x1, y1, x2, y2,
startPoint: { x: x1, y: y1 },
endPoint: { x: x2, y: y2 }
};
@ -3486,6 +3618,8 @@ function findInteriorPoint(line, polygonLines) {
// 2. 끝점이 골짜기인지 확인
const endIsValley = isValleyVertex(currentLine.endPoint, currentLine, polygonLines, false);
return {
start: startIsValley,
end: endIsValley