diff --git a/package.json b/package.json index 7be9b3f3..676d8f4f 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "chart.js": "^4.4.6", "dayjs": "^1.11.13", "env-cmd": "^10.1.0", - "fabric": "^5.3.0", + "fabric": "^5.5.2", "framer-motion": "^11.2.13", "fs": "^0.0.1-security", "iron-session": "^8.0.2", diff --git a/src/util/skeleton-utils.js b/src/util/skeleton-utils.js index 412b40b4..ded5c063 100644 --- a/src/util/skeleton-utils.js +++ b/src/util/skeleton-utils.js @@ -823,7 +823,7 @@ if((roof.moveUpDown??0 > 0) ) { movedLines.push({ index, p1, p2 }) // Usage: - let mergeLines = mergeMovedLines(movedLines); + // let mergeLines = mergeMovedLines(movedLines); //console.log("mergeLines:::::::", mergeLines); const line = new QLine([p1.x, p1.y, p2.x, p2.y], { parentId : roof.id, @@ -917,7 +917,7 @@ if((roof.moveUpDown??0 > 0) ) { const newPointX = Big(roofLine.x1).plus(moveDist).toNumber() const pDist = Big(wallLine.x1).minus(roofLine.x1).abs().toNumber() const pLineY = Big(roofLine.y2).minus(0).abs().toNumber() - let idx = (roofLine.length < index + 1)?0:index + let idx = (roofLines.length < index + 1)?0:index const pLineX = roofLines[idx+1].x2 getAddLine({ x: newPEnd.x, y: newPEnd.y }, { x: ePoint.x, y: ePoint.y }, 'blue') @@ -932,19 +932,46 @@ if((roof.moveUpDown??0 > 0) ) { break; case 'left_out': if(isStartEnd.start){ - const moveX = Math.abs(wallBaseLine.x1 - wallLine.x1) - const aStartY = Math.abs(newPEnd.y + moveX) - const bStartY = Math.abs(wallLine.y2 + moveX) - findPoints.push({ x: newPEnd.x, y: aStartY }); - const inLine = findLineContainingPoint(innerLines, { x: newPEnd.x, y: aStartY }) - // console.log("startLines:::::::", inLine); - getAddLine({ x: wallLine.x1, y: roofLine.y2 }, { x: wallLine.x1, y: bStartY }) - getAddLine({ x: wallLine.x2, y: bStartY }, { x: inLine.x2, y: inLine.y2 }, 'pink') - const eLineY = Math.abs(bStartY - wallLine.y2) - newPStart.y += eLineY - newPEnd.y = aStartY - }else if(isStartEnd.end){ + const moveDist = Big(wallLine.x1).minus(wallBaseLine.x1).abs().toNumber() + const aStartY = Big(roofLine.y1).minus(moveDist).abs().toNumber() + const bStartY = Big(wallLine.y1).minus(moveDist).abs().toNumber() + const inLine = findLineContainingPoint(innerLines, { y: aStartY, x: roofLine.x2 }) + console.log("startLines:::::::", inLine); + const eLineY = Big(bStartY).minus(wallLine.y1).abs().toNumber() + newPEnd.y = aStartY + newPStart.y = Big(roofLine.y2).minus(eLineY).toNumber() + let idx = (0 >= index - 1)?roofLines.length:index + const newLine = roofLines[idx-1]; + if(inLine){ + getAddLine({ y: bStartY, x: wallLine.x2 }, { y: inLine.y2, x: inLine.x2 }, 'pink') + } + if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + 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 }); + } + } + + if(isStartEnd.end){ + const moveDist = Big(wallLine.x1).minus(wallBaseLine.x1).abs().toNumber() + const aStartY = Big(roofLine.y2).plus(moveDist).toNumber() + const bStartY = Big(wallLine.y2).plus(moveDist).toNumber() + const inLine = findLineContainingPoint(innerLines, { y: aStartY, x: roofLine.x1 }) + console.log("startLines:::::::", inLine); + const eLineY = Big(bStartY).minus(wallLine.y2).abs().toNumber() + newPEnd.y = aStartY + newPStart.y = Big(roofLine.y1).plus(eLineY).toNumber() + let idx = (roofLines.length < index + 1)?0:index + const newLine = roofLines[idx+1]; + if(inLine){ + getAddLine({ y: bStartY, x: wallLine.x1 }, { y: inLine.y2, x: inLine.x2 }, 'pink') + } + if(Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) { + 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 }); + } } break; @@ -963,7 +990,7 @@ if((roof.moveUpDown??0 > 0) ) { const newPointX = Big(roofLine.x1).minus(moveDist).abs().toNumber() const pDist = Big(wallLine.x1).minus(roofLine.x1).abs().toNumber() const pLineY = Big(roofLine.y1).minus(0).abs().toNumber() - let idx = (0 > index - 1)?roofLines.length:index + let idx = (0 >= index - 1)?roofLines.length:index const pLineX = roofLines[idx-1].x1 getAddLine({ x: newPStart.x, y: newPStart.y }, { x: ePoint.x, y: ePoint.y }, 'blue') @@ -987,7 +1014,7 @@ if((roof.moveUpDown??0 > 0) ) { const newPointX = Big(roofLine.x1).minus(moveDist).toNumber() const pDist = Big(wallLine.x1).minus(roofLine.x1).abs().toNumber() const pLineY = Big(roofLine.y2).minus(0).abs().toNumber() - let idx = (roofLine.length < index + 1)?0:index + let idx = (roofLines.length < index + 1)?0:index const pLineX = roofLines[idx+1].x2 getAddLine({ x: newPEnd.x, y: newPEnd.y }, { x: ePoint.x, y: ePoint.y }, 'blue') @@ -1004,18 +1031,50 @@ if((roof.moveUpDown??0 > 0) ) { break; case 'right_out': - const moveX1 = Math.abs(wallBaseLine.x2 - wallLine.x2) - const aStartY1 = Math.abs(newPStart.y + moveX1) - const bStartY1 = Math.abs(wallLine.y1 + moveX1) - findPoints.push({ x: newPStart.x, y: aStartY1 }); - const inLine1 = findLineContainingPoint(innerLines, { x: newPStart.x, y: aStartY1}) - console.log("startLines:::::::", inLine1); - getAddLine({ x: wallLine.x2, y: roofLine.y1 }, {x: wallLine.x2 , y: bStartY1}) - getAddLine({ x: wallLine.x1, y: bStartY1 }, { x: inLine1.x2, y: inLine1.y2}, 'pink' ) - const eLineY1 = Math.abs( bStartY1 - wallLine.y1) - newPEnd.y += eLineY1 - newPStart.y = aStartY1 + + if (isStartEnd.start ) { + const moveDist = Big(wallLine.x1).minus(wallBaseLine.x1).abs().toNumber() + const aStartY = Big(roofLine.y1).plus(moveDist).toNumber() + const bStartY = Big(wallLine.y1).plus(moveDist).toNumber() + const inLine = findLineContainingPoint(innerLines, { y: aStartY, x: roofLine.x2 }) + console.log("startLines:::::::", inLine); + const eLineY = Big(bStartY).minus(wallLine.y1).abs().toNumber() + newPEnd.y = aStartY + newPStart.y = Big(roofLine.y2).plus(eLineY).toNumber() + let idx = (0 >= index - 1)?roofLines.length:index + const newLine = roofLines[idx-1]; + if(inLine){ + getAddLine({ y: bStartY, x: wallLine.x2 }, { y: inLine.y2, x: inLine.x2 }, 'pink') + } + if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + 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 }); + } + + } + + if(isStartEnd.end){ + const moveDist = Big(wallLine.x1).minus(wallBaseLine.x1).abs().toNumber() + const aStartY = Big(roofLine.y2).minus(moveDist).abs().toNumber() + const bStartY = Big(wallLine.y2).minus(moveDist).abs().toNumber() + const inLine = findLineContainingPoint(innerLines, { y: aStartY, x: roofLine.x1 }) + console.log("startLines:::::::", inLine); + const eLineY = Big(bStartY).minus(wallLine.y2).abs().toNumber() + newPEnd.y = aStartY + newPStart.y = Big(roofLine.y1).minus(eLineY).toNumber() + let idx = (roofLines.length < index + 1)?0:index + const newLine = roofLines[idx+1]; + if(inLine){ + getAddLine({ y: bStartY, x: wallLine.x1 }, { y: inLine.y2, x: inLine.x2 }, 'pink') + } + if(Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) { + 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 }); + } + } break; } } @@ -1053,7 +1112,7 @@ if((roof.moveUpDown??0 > 0) ) { const pDist = Big(wallLine.y2).minus(roofLine.y2).abs().toNumber() const pLineX = Big(roofLine.x1).minus(0).abs().toNumber() - let idx = (0 > index - 1)?roofLines.length:index + let idx = (0 >= index - 1)?roofLines.length:index const pLineY = roofLines[idx-1].y1 getAddLine({ x: newPStart.x, y: newPStart.y }, { x: sPoint.x, y: sPoint.y }, 'blue') findPoints.push({ x: sPoint.x, y: sPoint.y }); @@ -1074,7 +1133,7 @@ if((roof.moveUpDown??0 > 0) ) { const pDist = Big(wallLine.y1).minus(roofLine.y1).abs().toNumber() const pLineX = Big(roofLine.x2).minus(0).abs().toNumber() - let idx = roofLine.length < index + 1 ? 0 : index + let idx = roofLines.length < index + 1 ? 0 : index const pLineY = roofLines[idx + 1].y2 getAddLine({ x: newPEnd.x, y: newPEnd.y }, { x: sPoint.x, y: sPoint.y }, 'blue') findPoints.push({ x: sPoint.x, y: sPoint.y }) @@ -1088,26 +1147,46 @@ if((roof.moveUpDown??0 > 0) ) { break; case 'top_out': - console.log("findInteriorPoint result:::::::", isStartEnd); + //console.log("findInteriorPoint result:::::::", isStartEnd); if (isStartEnd.start ) { const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() - const dist = Math.abs(roofLine.y1 - wallLine.y1) - const aStartX = Big(newPStart.x).plus(moveDist).toNumber() + const aStartX = Big(roofLine.x1).plus(moveDist).toNumber() const bStartX = Big(wallLine.x1).plus(moveDist).toNumber() - - //newPStart.x += moveX - //wallLine.x1 += moveX - findPoints.push({ x: aStartX, y: newPEnd.y }); const inLine = findLineContainingPoint(innerLines, { x: aStartX, y: newPEnd.y }) console.log("startLines:::::::", inLine); - getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }, 'darkblue') - getAddLine({ x: bStartX, y: wallLine.y2 }, { x: inLine.x2, y: inLine.y2 }, 'pink') const eLineX = Big(bStartX).minus(wallLine.x1).abs().toNumber() - newPEnd.x += eLineX + newPEnd.x = Big(newPEnd.x).plus(eLineX).toNumber() newPStart.x = aStartX + let idx = (0 > index - 1)?roofLines.length:index + const newLine = roofLines[idx-1]; + if(inLine){ + getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') + } + if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + 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 }); + } } if(isStartEnd.end){ - + const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() + const aStartX = Big(roofLine.x2).minus(moveDist).abs().toNumber() + const bStartX = Big(wallLine.x2).minus(moveDist).abs().toNumber() + const inLine = findLineContainingPoint(innerLines, { x: aStartX, y: newPEnd.y }) + console.log("startLines:::::::", inLine); + const eLineX = Big(bStartX).minus(wallLine.x2).abs().toNumber() + newPStart.x = Big(newPStart.x).minus(eLineX).abs().toNumber() + newPEnd.x = aStartX + let idx = (roofLines.length < index + 1)?0:index + const newLine = roofLines[idx+1]; + if(inLine){ + getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') + } + if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + 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 }); + } } break; case 'bottom_in': @@ -1144,7 +1223,7 @@ if((roof.moveUpDown??0 > 0) ) { const pDist = Big(wallLine.y1).minus(roofLine.y1).abs().toNumber() const pLineX = Big(roofLine.x2).minus(0).abs().toNumber() - let idx = (roofLine.length < index + 1)?0:index + let idx = (roofLines.length < index + 1)?0:index const pLineY = roofLines[idx+1].y2 getAddLine({ x: newPEnd.x, y: newPEnd.y }, { x: sPoint.x, y: sPoint.y }, 'blue') findPoints.push({ x: sPoint.x, y: sPoint.y }); @@ -1159,488 +1238,59 @@ if((roof.moveUpDown??0 > 0) ) { break; case 'bottom_out': - // console.log("findInteriorPoint result:::::::", isStartEnd); - // - // const moveY = Math.abs(wallLine.y1 - wallBaseLine.y1) - // const dist = Math.abs(roofLine.y1 - wallLine.y1) - // const aStartX = Math.abs(newPStart.x + moveY) - // const bStartX = Math.abs(wallLine.x1 + moveY) - // - // //newPStart.x += moveX - // //wallLine.x1 += moveX - // findPoints.push({ x: aStartX, y: newPEnd.y }); - // const inLine = findLineContainingPoint(innerLines, { x: aStartX, y: newPEnd.y }) - // console.log("startLines:::::::", inLine); - // getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }) - // getAddLine({ x: bStartX, y: wallLine.y2 }, { x: inLine.x2, y: inLine.y2 }, 'pink') - // const eLineX = Math.abs(bStartX - wallLine.x1) - // newPEnd.x += eLineX - // newPStart.x = aStartX + + if (isStartEnd.start ) { + const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() + const aStartX = Big(roofLine.x1).minus(moveDist).abs().toNumber() + const bStartX = Big(wallLine.x1).minus(moveDist).abs().toNumber() + const inLine = findLineContainingPoint(innerLines, { x: aStartX, y: roofLine.y1 }) + console.log("startLines:::::::", inLine); + const eLineX = Big(bStartX).minus(wallLine.x1).abs().toNumber() + newPEnd.x = Big(roofLine.x2).minus(eLineX).toNumber() + newPStart.x = aStartX + let idx = (0 > index - 1)?roofLines.length:index + const newLine = roofLines[idx-1]; + + if(inLine){ + getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') + } + if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + 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 }); + } + } + + if(isStartEnd.end){ + const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() + const aStartX = Big(roofLine.x2).plus(moveDist).toNumber() + const bStartX = Big(wallLine.x2).plus(moveDist).toNumber() + const inLine = findLineContainingPoint(innerLines, { x: aStartX, y: roofLine.y1 }) + console.log("startLines:::::::", inLine); + const eLineX = Big(bStartX).minus(wallLine.x2).abs().toNumber() + newPEnd.x = aStartX + newPStart.x = Big(roofLine.x1).plus(eLineX).toNumber() + let idx = (0 > index - 1)?roofLines.length:index + const newLine = roofLines[idx-1]; + if(inLine){ + getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') + } + if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + 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 }); + } + } break; } } - - - if (newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPStart.x && newPStart.x <= wallBaseLine.x1) { //in top left //out top left - - // if (isIn) { - // newPStart.x = wallBaseLine.x1; - // //추가 수직 - // getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) - // //추가 라인? - // findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 }); - // - // } else if (isOut) { - // const moveY = Math.abs(wallLine.y1 - wallBaseLine.y1) - // const dist = Math.abs(roofLine.y1 - wallLine.y1) - // const aStartX = Math.abs(newPStart.x + moveY) - // const bStartX = Math.abs(wallLine.x1 + moveY) - // - // //newPStart.x += moveX - // //wallLine.x1 += moveX - // findPoints.push({ x: aStartX, y: newPEnd.y }); - // const inLine = findLineContainingPoint(innerLines, { x: aStartX, y: newPEnd.y }) - // console.log("startLines:::::::", inLine); - // getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }) - // getAddLine({ x: bStartX, y: wallLine.y2 }, { x: inLine.x2, y: inLine.y2 }, 'pink') - // const eLineX = Math.abs(bStartX - wallLine.x1) - // newPEnd.x += eLineX - // newPStart.x = aStartX - // } - -/* - } else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x) { //top right - newPEnd.x = wallBaseLine.x2; - //추가 수직 - getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) - //추가 라인? - findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 }); - - } else if (newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) { //bottom left - newPEnd.x = wallBaseLine.x2; - getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) - //추가 라인? - findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 }); - - } else if (wallBaseLine.x1 <= newPStart.x && newPStart.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPEnd.x) { //bottom right - newPStart.x = wallBaseLine.x1; - getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) - - //추가 라인? - findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 }); - - } else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= newPStart.x && newPStart.x <= wallBaseLine.x1) { // top center - - newPEnd.x = wallBaseLine.x2; - getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) - findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 }); - newPStart.x = wallBaseLine.x1; - getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) - findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 }); - //추가 라인? - - - } else if (wallBaseLine.x1 <= newPStart.x && newPStart.x <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) { // 아래가운데 - newPEnd.x = wallBaseLine.x1; - getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) - findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 }); - newPStart.x = wallBaseLine.x2; - getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) - findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 }); -*/ - } - } - getAddLine(newPStart, newPEnd, 'red') - - } /* else if (movedStart ) { //end 변경경 - - - if (getOrientation(roofLine) === 'vertical') { //brown 수직 - const mLine = getSelectLinePosition(wall, wallBaseLine) - if (['left', 'right'].includes(mLine.position)) { - const positionType = - (mLine.position === 'left' && wallLine.x1 <= wallBaseLine.x1) || - (mLine.position === 'right' && wallLine.x1 >= wallBaseLine.x1) - ? 'in' : 'out'; - - const condition = `${mLine.position}_${positionType}`; - let isStartEnd = findInteriorPoint(wallBaseLine, sortedWallBaseLines) - let sPoint, ePoint; - let isCross = false - if (Math.abs(currentRoofLine?.x2 - roofLine.x1) < 0.1 || Math.abs(currentRoofLine?.x1 - roofLine.x2) < 0.1) { - isCross = true; - } - - - switch (condition) { - case 'left_in': - - if(isStartEnd.start){ - - }else if(isStartEnd.end){ - newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 } - newPEnd ={ x: roofLine.x2, y: roofLine.y2 } - }else { - newPStart = { x: roofLine.x1, y: roofLine.y1 } - newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine?.y1 : wallBaseLine.y1 } - - } - break; - - - case 'left_out': - - break; - case 'right_in': - newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine?.y1 : wallBaseLine.y1 } - newPEnd ={ x: roofLine.x2, y: roofLine.y2 } - //대각선 라인을 보조라인으로 그린다. - if(isCross){ - getAddLine({ x: wallBaseLine.x1, y: wallBaseLine.y1 }, { x: roofLine.x1, y: currentRoofLine?.y1 }, 'purple') - } - - - break; - case 'right_out': - - break; - } - } - - if(mLine.position === 'left') isIn = true - if(mLine.position === 'right') isOut = true - - if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 < wallBaseLine.y2 && wallBaseLine.y2 < newPEnd.y){//in bottom left - // if(isIn){ - // newPStart = { x: roofLine.x1, y: roofLine.y1 } - // newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine?.y1 : wallBaseLine.y1 } - // } - - - }else if(newPEnd.y <= wallBaseLine.y2 && wallBaseLine.y2 < wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y){ //하단 오른쪽v - // newPStart = { x: roofLine.x1, y: roofLine.y1 } - // newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine?.y1 : wallBaseLine.y1 } - - }else if(newPEnd.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPStart.y && newPStart.y <= wallBaseLine.y1) { //top right - - // newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine?.y1 : wallBaseLine.y1 } - // newPEnd ={ x: roofLine.x2, y: roofLine.y2 } - // - // //대각선 라인을 보조라인으로 그린다. - // if(isCross){ - // getAddLine({ x: wallBaseLine.x1, y: wallBaseLine.y1 }, { x: roofLine.x1, y: currentRoofLine?.y1 }, 'purple') - // } - - }else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//상단 오르쪽 - - // newPStart = { x: roofLine.x1, y: roofLine.y1 } - // newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 } - - }else if(wallBaseLine.y1 <= newPStart.y && newPStart.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPEnd.y) { // out bottom left //bottom left - // if(isIn){ - // newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 } - // newPEnd = { x: roofLine.x2, y: roofLine.y2 } - // - // //대각선 라인을 보조라인으로 그린다. - // if(isCross){ - // getAddLine( { x: wallBaseLine.x1, y: wallBaseLine.y1 }, { x: roofLine.x1, y: currentRoofLine.y1 }, 'purple') - // } - // }else if(isOut){ - // - // } - - - - }else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y) { //하단 왼쪽 - - // newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 } - // newPEnd ={ x: roofLine.x2, y: roofLine.y2 } - } - - - - } else if (getOrientation(roofLine) === 'horizontal') { //magenta 수평 - - - const mLine = getSelectLinePosition(wall, wallBaseLine) - if(mLine.position === 'top') isIn = true - if(mLine.position === 'bottom') isOut = true - - let isCross = false - if (Math.abs(currentRoofLine.y1 - roofLine.y2) < 0.1 || Math.abs(currentRoofLine.y2 - roofLine.y1) < 0.1) { - isCross = true; - } - if(newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 < wallBaseLine.x2 && wallBaseLine.x2 < newPEnd.x){//가장 왼쪽v - newPStart = { y: roofLine.y1, x: roofLine.x1 } - newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } - - }else if(newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 < wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x){ //out top left / top right - if(isIn){ - newPStart = { y: roofLine.y1, x: roofLine.x1 } - newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } - }else if(isOut){ - newPEnd = { x: roofLine.x2, y: roofLine.y2 } - newPStart ={ x: wallLine.x1, y: roofLine.y1 } - } - - - - }else if(newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPStart.x && newPStart.x <= wallBaseLine.x1) { //in top left - if(isIn){ - newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } - newPEnd ={ y: roofLine.y2, x: roofLine.x2 } - - //대각선 라인을 보조라인으로 그린다. - if(isCross){ - getAddLine({ x: currentRoofLine.x1, y: roofLine.y1 }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }, 'purple') - } - }else if(isOut){ - - } - - - - }else if(newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) {//상단 오르쪽 - - newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } - newPEnd ={ y: roofLine.y2, x: roofLine.x2 } - - }else if(wallBaseLine.x1 <= newPStart.x && newPStart.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPEnd.x) { //bottom rightv - - newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.y1 } - newPEnd = { y: roofLine.y2, x: roofLine.x2 } - - //대각선 라인을 보조라인으로 그린다. - if(isCross){ - getAddLine({ x: wallBaseLine.x1, y: wallBaseLine.y1 },{ x: currentRoofLine.x1, y: roofLine.y1 }, 'purple') - } - - }else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x) { //right / top - - newPStart = { y: roofLine.y1, x: roofLine.x1 } - newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } - }else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= newPStart.x && newPStart.x <= wallBaseLine.x1) { //right / top - - newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } - newPEnd ={ y: roofLine.y2, x: roofLine.x2 } - } - - //newPEnd = { x: (isCross) ? currentRoofLine.x1 : origin.x1, y: roofLine.y1 } //수직라인 접점까지지 - } - - getAddLine(newPStart, newPEnd, 'magenta') -//movedLines.push({ index, newPStart, newPEnd }) - //console.log("moveStart:::::::::::::", origin, newPStart, newPEnd) - - } else if (movedEnd ) { //start변경 - - //반시계방향 오렌지 - - - if (getOrientation(roofLine) === 'vertical') { //수직 오렌지 - - const mLine = getSelectLinePosition(wall, wallBaseLine) - if (['left', 'right'].includes(mLine.position)) { - const positionType = - (mLine.position === 'left' && wallLine.x1 <= wallBaseLine.x1) || - (mLine.position === 'right' && wallLine.x1 >= wallBaseLine.x1) - ? 'in' : 'out'; - - const condition = `${mLine.position}_${positionType}`; - let isStartEnd = findInteriorPoint(wallBaseLine, sortedWallBaseLines) - let sPoint, ePoint; - let isCross = false - if (Math.abs(currentRoofLine.x2 - roofLine.x1) < 0.1 || Math.abs(currentRoofLine.x1 - roofLine.x2) < 0.1) { - isCross = true; - } - - switch (condition) { - case 'left_in': - - - newPStart = { x: roofLine.x1, y: roofLine.y1 } - - newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } - - //대각선 라인을 보조라인으로 그린다. - if (isCross) { - getAddLine({ x: roofLine.x2, y: currentRoofLine.y2 }, { - x: wallBaseLine.x2, - y: wallBaseLine.y2 - }, 'purple') - } - - break; - - - case 'left_out': - - break; - case 'right_in': - newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } - newPEnd = { x: roofLine.x2, y: roofLine.y2 } - - break; - case 'right_out': - - break; - } - } - - - // const mLine = getSelectLinePosition(wall, wallBaseLine) - // if(mLine.position === 'left') isIn = true - // if(mLine.position === 'right') isOut = true - - - - if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 < wallBaseLine.y2 && wallBaseLine.y2 < newPEnd.y){//out top left - - // if(isIn) { - // newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } - // newPEnd = { x: roofLine.x2, y: roofLine.y2 } - // }else if(isOut) { - // - // newPStart = { x: roofLine.x1, y: roofLine.y1 } - // newPEnd = { x: roofLine.x2, y: wallLine.y2 } - // - // } - - - }else if(newPEnd.y <= wallBaseLine.y2 && wallBaseLine.y2 < wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y){ //top /right - // newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } - // newPEnd = { x: roofLine.x2, y: roofLine.y2 } - - - }else if(newPEnd.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPStart.y && newPStart.y <= wallBaseLine.y1) { //top / left - - // newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } - // newPEnd ={ x: roofLine.x2, y: roofLine.y2 } - - }else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//in top left/ - - - // if(isIn) { - // newPStart = { x: roofLine.x1, y: roofLine.y1 } - // newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } - // - // //대각선 라인을 보조라인으로 그린다. - // if (isCross) { - // getAddLine({ x: roofLine.x2, y: currentRoofLine.y2 }, { - // x: wallBaseLine.x2, - // y: wallBaseLine.y2 - // }, 'purple') - // } - // } - - }else if(wallBaseLine.y1 <= newPStart.y && newPStart.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPEnd.y) { //하단 오른쪽v - - // newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 } - // newPEnd = { x: roofLine.x2, y: roofLine.y2 } - - }else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y) { //bottom right - - // newPStart = { x: roofLine.x1, y: roofLine.y1 } - // newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } - // - // //대각선 라인을 보조라인으로 그린다. - // if(isCross){ - // getAddLine({ x: roofLine.x2, y: currentRoofLine.y2 }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }, 'purple') - // } - } - - - - } else if (getOrientation(roofLine) === 'horizontal') { //오렌지 - - const mLine = getSelectLinePosition(wall, wallBaseLine) - if(mLine.position === 'top') isIn = true - if(mLine.position === 'bottom') isOut = true - - let isCross = false - if (Math.abs(currentRoofLine.y2 - roofLine.y1) < 0.1 || Math.abs(currentRoofLine.y1 - roofLine.y2) < 0.1) { - isCross = true; - } - - if(newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 < wallBaseLine.x2 && wallBaseLine.x2 < newPEnd.x){//right / bottom - newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } - newPEnd = { y: roofLine.y2, x: roofLine.x2 } - - }else if(newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 < wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x){ //in top left - - if(isIn){ - newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } - newPEnd = { y: roofLine.y2, x: roofLine.x2 } - } - - - }else if(newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPStart.x && newPStart.x <= wallBaseLine.x1) { //left top - - newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } - newPEnd ={ y: roofLine.y2, x: roofLine.x2 } - - }else if(newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) {//bottom left - - newPStart = { y: roofLine.y1, x: roofLine.x1 } - newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } - - //대각선 라인을 보조라인으로 그린다. - if(isCross){ - getAddLine({ x: currentRoofLine.x2, y: roofLine.y2 }, { x:wallBaseLine.x2 , y: wallBaseLine.y2 }, 'purple') - } - - - }else if(wallBaseLine.x1 <= newPStart.x && newPStart.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPEnd.x) { //하단 오른쪽v - - newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } - newPEnd = { y: roofLine.y2, x: roofLine.x2 } - - }else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x) { //out top left - - if(isIn){ - newPStart = { y: roofLine.y1, x: roofLine.x1 } - newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } - //대각선 라인을 보조라인으로 그린다. - if(isCross){ - getAddLine({ x: currentRoofLine.x2, y: roofLine.y2 }, { x:wallBaseLine.x2 , y: wallBaseLine.y2 }, 'purple') - } - }else if(isOut){ - // newPEnd = { x: roofLine.x2, y: roofLine.y2 } - // newPStart = { x: wallLine.x2, y: roofLine.y2 } - } - - - - }else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= newPStart.x && newPStart.x <= wallBaseLine.x1){ //top center - newPStart = { y: roofLine.y1, x: roofLine.x1 } - newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } - } - - // newPStart = { x: roofLine.x2, y: roofLine.y2 } - // newPEnd = { x: (isCross) ? currentRoofLine.x2 : origin.x2, y: roofLine.y2 } //수직라인 접점까지지 - - } - //console.log("movedEnd:::::::::::::", origin, newPStart, newPEnd) - getAddLine(newPStart, newPEnd, 'orange') - //movedLines.push({ index, newPStart, newPEnd }) - - }*/ - + } canvas.renderAll() - - }); - -//polygon 만들기 - //console.log("innerLines:::::", innerLines) - //console.log("movedLines", movedLines) - // console.log("updateLines:::::", updateLines) - } - if (findPoints.length > 0) { // 모든 점에 대해 라인 업데이트를 누적 return findPoints.reduce((lines, point) => {