diff --git a/src/util/skeleton-utils.js b/src/util/skeleton-utils.js index 06208ddd..3b5e905a 100644 --- a/src/util/skeleton-utils.js +++ b/src/util/skeleton-utils.js @@ -543,28 +543,23 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => { //const orgWallLine = wall.lines //console.log("outLine:::::", p1, p2, line) - for(const orgLine of roof.lines){ - console.log("a::::",isSamePoint(p1,orgLine.startPoint), p1, orgLine.startPoint) - console.log("b::::",isSamePoint(p2,orgLine.endPoint), p2, orgLine.endPoint) - console.log("c::::",isSamePoint(p2,orgLine.startPoint), p2, orgLine.startPoint) - console.log("d::::",isSamePoint(p1,orgLine.endPoint), p1, orgLine.endPoint) - let isSampe1 = false - let isSampe2 = false - const orgOuterLine = orgLine - if(isSamePoint(p1,orgLine.startPoint) && isSamePoint(p2,orgLine.endPoint)){ - isSampe1 = true; - break; + let lineExists = false; + + for (const orgLine of roof.lines) { + const sameDirection = isSamePoint(p1, orgLine.startPoint) && isSamePoint(p2, orgLine.endPoint); + const oppositeDirection = isSamePoint(p2, orgLine.startPoint) && isSamePoint(p1, orgLine.endPoint); + + if (sameDirection || oppositeDirection) { + lineExists = true; + break; // 같은 라인이 발견되면 즉시 순환 종료 } + } - orgOuterLine.startPoint = orgLine.endPoint - orgOuterLine.endPoint = orgLine.startPoint - - if(isSamePoint(p1,orgLine.endPoint) && isSamePoint(p2,orgLine.startPoint)){ - isSampe2 = true - return; - } - - const innerLine2 = new QLine([orgOuterLine.startPoint.x, orgOuterLine.startPoint.y, orgOuterLine.endPoint.x, orgOuterLine.endPoint.y], { + if (!lineExists) { + // 같은 라인이 없으므로 새 다각형 라인 생성 + const newLine = new QLine( + [p1.x, p1.y, p2.x, p2.y], + { parentId : roof.id, fontSize : roof.fontSize, stroke : 'yellow', @@ -576,28 +571,35 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => { lineName : (line.attributes.isOuterEdge) ? 'addLine' : attributes.type, selectable : (!line.attributes.isOuterEdge), roofId : roofId, - }); - - //orgOuterLine.setCoords() - //canvas.renderAll() - canvas.add(innerLine2); + } + ); + let p1Line = findClosestRoofLine(p1, roof.lines) + let p2Line = findClosestRoofLine(p2, roof.lines) + if(p2Line.distance > p1Line.distance){ + p1Line = p2Line; + p2Line = p1Line; } - - - - for(const orgWallLine of wall.lines){ - // console.log("orgWallLine::::;",orgWallLine.startPoint, orgWallLine.endPoint); - // if(isSamePoint(orgWallLine.startPoint, p1) || - // isSamePoint(orgWallLine.endPoint, p2) || - // isSamePoint(orgWallLine.endPoint, p1) || - // isSamePoint(orgWallLine.startPoint, p2)){ - // idx = orgWallLine.idx - // break - // } + const newLine2 = new QLine( + [p1Line.line.x1, p1Line.line.y1, p2Line.line.x2, p2Line.line.y2], + { + parentId : roof.id, + fontSize : roof.fontSize, + stroke : 'red', + strokeWidth: lineStyle.width, + name : (line.attributes.isOuterEdge) ? 'eaves' : attributes.type, + attributes : attributes, + direction : direction, + isBaseLine : line.attributes.isOuterEdge, + lineName : (line.attributes.isOuterEdge) ? 'exLine' : attributes.type, + selectable : (!line.attributes.isOuterEdge), + roofId : roofId, + } + ); + canvas.add(newLine); + canvas.add(newLine2); } - //초기외곽라인? const coordinateText = new fabric.Text(`(${Math.round(p1.x)}, ${Math.round(p1.y)})`, { left: p1.x + 5, // 좌표점에서 약간 오른쪽으로 이동 @@ -617,6 +619,7 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => { canvas?.add(coordinateText) }else{ + canvas.add(innerLine); innerLine.bringToFront(); existingLines.add(lineKey); // 추가된 라인을 추적