From e7d83b727a45eec1331c0124a3f2ce494ea239cd Mon Sep 17 00:00:00 2001 From: ysCha Date: Wed, 17 Dec 2025 15:51:31 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8F=99->=ED=98=84=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/skeleton-utils.js | 1661 ++++++++++++++++++------------------ 1 file changed, 807 insertions(+), 854 deletions(-) diff --git a/src/util/skeleton-utils.js b/src/util/skeleton-utils.js index b3a59e79..383c82e0 100644 --- a/src/util/skeleton-utils.js +++ b/src/util/skeleton-utils.js @@ -159,7 +159,7 @@ const movingLineFromSkeleton = (roofId, canvas) => { // console.log("3333linePosition:::::", result.position); const position = movePosition //result.position; - const absMove = Big(moveUpDown).times(1).div(10); + const moveUpDownLength = Big(moveUpDown).times(1).div(10); const modifiedStartPoints = []; // oldPoints를 복사해서 새로운 points 배열 생성 let newPoints = oldPoints.map(point => ({...point})); @@ -181,64 +181,22 @@ const movingLineFromSkeleton = (roofId, canvas) => { const offset = line.attributes.offset // 새로운 좌표 계산 let newStartPoint = {...originalStartPoint}; - let newEndPoint = {...originalEndPoint}; - - // 위치와 방향에 따라 좌표 조정 - /* - switch (position) { - case 'left': - if (moveDirection === 'up') { - newStartPoint.x = Big(line.startPoint.x).minus(absMove).toNumber(); - newEndPoint.x = Big(line.endPoint.x).minus(absMove).toNumber(); - } else if (moveDirection === 'down') { - newStartPoint.x = Big(line.startPoint.x).plus(absMove).toNumber(); - newEndPoint.x = Big(line.endPoint.x).plus(absMove).toNumber(); - } - break; - case 'right': - if (moveDirection === 'up') { - newStartPoint.x = Big(line.startPoint.x).plus(absMove).toNumber(); - newEndPoint.x = Big(line.endPoint.x).plus(absMove).toNumber(); - } else if (moveDirection === 'down') { - newStartPoint.x = Big(line.startPoint.x).minus(absMove).toNumber(); - newEndPoint.x = Big(line.endPoint.x).minus(absMove).toNumber(); - } - break; - case 'top': - if (moveDirection === 'up') { - newStartPoint.y = Big(line.startPoint.y).minus(absMove).toNumber(); - newEndPoint.y = Big(line.endPoint.y).minus(absMove).toNumber(); - } else if (moveDirection === 'down') { - newStartPoint.y = Big(line.startPoint.y).plus(absMove).toNumber(); - newEndPoint.y = Big(line.endPoint.y).plus(absMove).toNumber(); - } - break; - case 'bottom': - if (moveDirection === 'up') { - newStartPoint.y = Big(line.startPoint.y).plus(absMove).toNumber(); - newEndPoint.y = Big(line.endPoint.y).plus(absMove).toNumber(); - } else if (moveDirection === 'down') { - newStartPoint.y = Big(line.startPoint.y).minus(absMove).toNumber(); - newEndPoint.y = Big(line.endPoint.y).minus(absMove).toNumber(); - } - break; - } - */ + let newEndPoint = {...originalEndPoint} // 원본 라인 업데이트 // newPoints 배열에서 일치하는 포인트들을 찾아서 업데이트 - console.log('absMove::', absMove); + console.log('absMove::', moveUpDownLength); newPoints.forEach((point, index) => { if(position === 'bottom'){ if (moveDirection === 'in') { if(isSamePoint(roof.basePoints[index], originalStartPoint) || isSamePoint(roof.basePoints[index], originalEndPoint)) { - point.y = Big(point.y).minus(absMove).toNumber(); + point.y = Big(point.y).minus(moveUpDownLength).toNumber(); } // if (isSamePoint(roof.basePoints[index], originalEndPoint)) { // point.y = Big(point.y).minus(absMove).toNumber(); // } }else if (moveDirection === 'out'){ if(isSamePoint(roof.basePoints[index], originalStartPoint) || isSamePoint(roof.basePoints[index], originalEndPoint)) { - point.y = Big(point.y).plus(absMove).toNumber(); + point.y = Big(point.y).plus(moveUpDownLength).toNumber(); } // if (isSamePoint(roof.basePoints[index], originalEndPoint)) { // point.y = Big(point.y).plus(absMove).toNumber(); @@ -248,31 +206,31 @@ const movingLineFromSkeleton = (roofId, canvas) => { }else if (position === 'top'){ if(moveDirection === 'in'){ if(isSamePoint(roof.basePoints[index], originalStartPoint)) { - point.y = Big(point.y).plus(absMove).toNumber(); + point.y = Big(point.y).plus(moveUpDownLength).toNumber(); } if (isSamePoint(roof.basePoints[index], originalEndPoint)) { - point.y = Big(point.y).plus(absMove).toNumber(); + point.y = Big(point.y).plus(moveUpDownLength).toNumber(); } }else if(moveDirection === 'out'){ if(isSamePoint(roof.basePoints[index], originalStartPoint)) { - point.y = Big(point.y).minus(absMove).toNumber(); + point.y = Big(point.y).minus(moveUpDownLength).toNumber(); } if (isSamePoint(roof.basePoints[index], originalEndPoint)) { - point.y = Big(point.y).minus(absMove).toNumber(); + point.y = Big(point.y).minus(moveUpDownLength).toNumber(); } } }else if(position === 'left'){ if(moveDirection === 'in'){ if(isSamePoint(roof.basePoints[index], originalStartPoint) || isSamePoint(roof.basePoints[index], originalEndPoint)) { - point.x = Big(point.x).plus(absMove).toNumber(); + point.x = Big(point.x).plus(moveUpDownLength).toNumber(); } // if (isSamePoint(roof.basePoints[index], originalEndPoint)) { // point.x = Big(point.x).plus(absMove).toNumber(); // } }else if(moveDirection === 'out'){ if(isSamePoint(roof.basePoints[index], originalStartPoint) || isSamePoint(roof.basePoints[index], originalEndPoint)) { - point.x = Big(point.x).minus(absMove).toNumber(); + point.x = Big(point.x).minus(moveUpDownLength).toNumber(); } // if (isSamePoint(roof.basePoints[index], originalEndPoint)) { // point.x = Big(point.x).minus(absMove).toNumber(); @@ -282,17 +240,17 @@ const movingLineFromSkeleton = (roofId, canvas) => { }else if(position === 'right'){ if(moveDirection === 'in'){ if(isSamePoint(roof.basePoints[index], originalStartPoint)) { - point.x = Big(point.x).minus(absMove).toNumber(); + point.x = Big(point.x).minus(moveUpDownLength).toNumber(); } if (isSamePoint(roof.basePoints[index], originalEndPoint)) { - point.x = Big(point.x).minus(absMove).toNumber(); + point.x = Big(point.x).minus(moveUpDownLength).toNumber(); } }else if(moveDirection === 'out'){ if(isSamePoint(roof.basePoints[index], originalStartPoint)) { - point.x = Big(point.x).plus(absMove).toNumber(); + point.x = Big(point.x).plus(moveUpDownLength).toNumber(); } if (isSamePoint(roof.basePoints[index], originalEndPoint)) { - point.x = Big(point.x).plus(absMove).toNumber(); + point.x = Big(point.x).plus(moveUpDownLength).toNumber(); } } @@ -440,8 +398,8 @@ export const skeletonBuilder = (roofId, canvas, textMode) => { */ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => { if (!skeleton?.Edges) return [] - let roof = canvas?.getObjects().find((object) => object.id === roofId) - let wall = canvas.getObjects().find((obj) => obj.name === POLYGON_TYPE.WALL && obj.attributes.roofId === roofId) + const roof = canvas?.getObjects().find((object) => object.id === roofId) + const wall = canvas.getObjects().find((obj) => obj.name === POLYGON_TYPE.WALL && obj.attributes.roofId === roofId) let skeletonLines = [] let findPoints = []; @@ -650,902 +608,897 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => { canvas.renderAll(); }); - //if((roof.moveUpDown??0 > 0) ) { + if((roof.moveUpDown??0 > 0) || (roof.moveFlowLine??0 > 0) ) { - // 같은 라인이 없으므로 새 다각형 라인 생성 - //라인 편집 - // let i = 0 - const currentRoofLines = canvas.getObjects().filter((obj) => obj.lineName === 'roofLine' && obj.attributes.roofId === roofId) - let roofLineRects = canvas.getObjects().filter((obj) => obj.name === 'roofLineRect' && obj.roofId === roofId) + const getMoveUpDownLine = () => { + // 같은 라인이 없으므로 새 다각형 라인 생성 + //라인 편집 + // let i = 0 + const currentRoofLines = canvas.getObjects().filter((obj) => obj.lineName === 'roofLine' && obj.attributes.roofId === roofId) + let roofLineRects = canvas.getObjects().filter((obj) => obj.name === 'roofLineRect' && obj.roofId === roofId) - roofLineRects.forEach((roofLineRect) => { - canvas.remove(roofLineRect) - canvas.renderAll() - }) + roofLineRects.forEach((roofLineRect) => { + canvas.remove(roofLineRect) + canvas.renderAll() + }) - let helpLines = canvas.getObjects().filter((obj) => obj.lineName === 'helpLine' && obj.roofId === roofId) - helpLines.forEach((helpLine) => { - canvas.remove(helpLine) - canvas.renderAll() - }) + let helpLines = canvas.getObjects().filter((obj) => obj.lineName === 'helpLine' && obj.roofId === roofId) + helpLines.forEach((helpLine) => { + canvas.remove(helpLine) + canvas.renderAll() + }) - function sortCurrentRoofLines(lines) { - return [...lines].sort((a, b) => { - // Get all coordinates in a consistent order - const getCoords = (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'); + function sortCurrentRoofLines(lines) { + return [...lines].sort((a, b) => { + // Get all coordinates in a consistent order + const getCoords = (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'); - // Sort points left-to-right, then top-to-bottom - return x1 < x2 || (x1 === x2 && y1 < y2) - ? [x1, y1, x2, y2] - : [x2, y2, x1, y1]; - }; + // Sort points left-to-right, then top-to-bottom + return x1 < x2 || (x1 === x2 && y1 < y2) + ? [x1, y1, x2, y2] + : [x2, y2, x1, y1]; + }; - const aCoords = getCoords(a); - const bCoords = getCoords(b); + const aCoords = getCoords(a); + const bCoords = getCoords(b); - // Compare each coordinate in order - for (let i = 0; i < 4; i++) { - if (Math.abs(aCoords[i] - bCoords[i]) > 0.1) { - return aCoords[i] - bCoords[i]; - } + // Compare each coordinate in order + for (let i = 0; i < 4; i++) { + if (Math.abs(aCoords[i] - bCoords[i]) > 0.1) { + return aCoords[i] - bCoords[i]; } - return 0; - }); - } - - - // function sortCurrentRoofLines(lines) { - // return [...lines].sort((a, b) => { - // const aX = a.x1 ?? a.get('x1') - // const aY = a.y1 ?? a.get('y1') - // const bX = b.x1 ?? b.get('x1') - // const bY = b.y1 ?? b.get('y1') - - // if (aX !== bX) return aX - bX - // return aY - bY - // }) - // } - + } + return 0; + }); + } // 각 라인 집합 정렬 - // 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 + // 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 targetVec = { - x: nearestTarget.x2 - nearestTarget.x1, - y: nearestTarget.y2 - nearestTarget.y1 + 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 + ); - const dotProduct = sourceVec.x * targetVec.x + sourceVec.y * targetVec.y; + return !nearest || distance < nearest.distance + ? { line: targetLine, distance } + : nearest; + }, null)?.line; - // 내적이 음수이면 방향이 반대이므로 뒤집기 - if (dotProduct < 0) { - return { - ...sourceLine, - x1: sourceLine.x2, - y1: sourceLine.y2, - x2: sourceLine.x1, - y2: sourceLine.y1 - }; - } + if (!nearestTarget) return sourceLine; - 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 sortedWallLines = sortCurrentRoofLines(wall.lines); - // roofLines의 방향에 맞춰 currentRoofLines 조정 후 정렬 - const alignedCurrentRoofLines = alignLineDirection(currentRoofLines, roofLines); - const sortedCurrentRoofLines = sortCurrentRoofLines(alignedCurrentRoofLines); - // const sortedRoofLines = sortCurrentRoofLines(roofLines); - const sortedWallBaseLines = sortCurrentRoofLines(wall.baseLines); - // const sortedBaseLines = sortBaseLinesByWallLines(wall.baseLines, wallLines); - const sortRoofLines = sortBaseLinesByWallLines(roofLines, wallLines); + const dotProduct = sourceVec.x * targetVec.x + sourceVec.y * targetVec.y; - // 원본 wallLines를 복사하여 사용 - const sortedWallLines = [...wallLines]; - const sortedBaseLines = sortBaseLinesByWallLines(wall.baseLines, sortedWallLines); - const sortedRoofLines = sortBaseLinesByWallLines(roofLines, sortedWallLines); - - //wall.lines 는 기본 벽 라인 - //wall.baseLine은 움직인라인 - const movedLines = [] - - - wallLines.forEach((wallLine, index) => { - - - // const roofLine = sortedRoofLines[index]; - // const currentRoofLine = sortedCurrentRoofLines[index]; - // const moveLine = sortedWallBaseLines[index] - // const wallBaseLine = sortedWallBaseLines[index] - - const roofLine = sortRoofLines[index]; - - if(roofLine.attributes.wallLine !== wallLine.id || (roofLine.idx - 1) !== index ){ - console.log("wallLine2::::", wallLine.id) - console.log('roofLine:::',roofLine.attributes.wallLine) - console.log("w:::",wallLine.startPoint, wallLine.endPoint) - console.log("R:::",roofLine.startPoint, roofLine.endPoint) - console.log("not matching roofLine", roofLine); - return false - }//roofLines.find(line => line.attributes.wallLineId === wallLine.attributes.wallId); - - const currentRoofLine = currentRoofLines[index]; - const moveLine = wall.baseLines[index] - const wallBaseLine = wall.baseLines[index] - //console.log("wallBaseLine", wallBaseLine); - - //roofline 외곽선 설정 - console.log("index::::", index) - console.log('roofLine:::',roofLine) - console.log('wallLine', wallLine) - console.log('wallBaseLine', wallBaseLine) - - - const origin = moveLine.attributes?.originPoint - if (!origin) return - - if (isSamePoint(moveLine, wallLine)) { - - return false + // 내적이 음수이면 방향이 반대이므로 뒤집기 + if (dotProduct < 0) { + return { + ...sourceLine, + x1: sourceLine.x2, + y1: sourceLine.y2, + x2: sourceLine.x1, + y2: sourceLine.y1 + }; } - const movedStart = Math.abs(moveLine.x1 - wallLine.x1) > EPSILON || Math.abs(moveLine.y1 - origin.y1) > EPSILON - const movedEnd = Math.abs(moveLine.x2 - wallLine.x2) > EPSILON || Math.abs(moveLine.y2 - origin.y2) > EPSILON + return sourceLine; + }); + }; + + // const sortedWallLines = sortCurrentRoofLines(wall.lines); + // roofLines의 방향에 맞춰 currentRoofLines 조정 후 정렬 + const alignedCurrentRoofLines = alignLineDirection(currentRoofLines, roofLines); + const sortedCurrentRoofLines = sortCurrentRoofLines(alignedCurrentRoofLines); + // const sortedRoofLines = sortCurrentRoofLines(roofLines); + const sortedWallBaseLines = sortCurrentRoofLines(wall.baseLines); + // const sortedBaseLines = sortBaseLinesByWallLines(wall.baseLines, wallLines); + const sortRoofLines = sortBaseLinesByWallLines(roofLines, wallLines); + + // 원본 wallLines를 복사하여 사용 + const sortedWallLines = [...wallLines]; + const sortedBaseLines = sortBaseLinesByWallLines(wall.baseLines, sortedWallLines); + const sortedRoofLines = sortBaseLinesByWallLines(roofLines, sortedWallLines); + + //wall.lines 는 기본 벽 라인 + //wall.baseLine은 움직인라인 + const movedLines = [] + + // 조건에 맞는 라인들만 필터링 + const validWallLines = wallLines.filter((wallLine, index) => wallLine.idx - 1 === index); - const fullyMoved = movedStart && movedEnd + validWallLines.forEach((wallLine, index) => { + + const originalIndex = wallLines.indexOf(wallLine); + const roofLine = sortRoofLines[originalIndex]; + const currentRoofLine = currentRoofLines[originalIndex]; + const moveLine = wall.baseLines[originalIndex]; + const wallBaseLine = wall.baseLines[originalIndex]; + + // const roofLine = sortRoofLines[index]; + + if (roofLine.attributes.wallLine !== wallLine.id || (roofLine.idx - 1) !== index) { + console.log("wallLine2::::", wallLine.id) + console.log('roofLine:::', roofLine.attributes.wallLine) + console.log("w:::", wallLine.startPoint, wallLine.endPoint) + console.log("R:::", roofLine.startPoint, roofLine.endPoint) + console.log("not matching roofLine", roofLine); + return false + }//roofLines.find(line => line.attributes.wallLineId === wallLine.attributes.wallId); + + // const currentRoofLine = currentRoofLines[index]; + // const moveLine = wall.baseLines[index] + // const wallBaseLine = wall.baseLines[index] + //console.log("wallBaseLine", wallBaseLine); + + //roofline 외곽선 설정 + console.log("index::::", index) + console.log('roofLine:::', roofLine) + console.log('wallLine', wallLine) + console.log('wallBaseLine', wallBaseLine) + + + const origin = moveLine.attributes?.originPoint + if (!origin) return + + if (isSamePoint(moveLine, wallLine)) { + + return false + } + + const movedStart = Math.abs(moveLine.x1 - wallLine.x1) > EPSILON || Math.abs(moveLine.y1 - origin.y1) > EPSILON + const movedEnd = Math.abs(moveLine.x2 - wallLine.x2) > EPSILON || Math.abs(moveLine.y2 - origin.y2) > EPSILON + + + const fullyMoved = movedStart && movedEnd //반시계 방향 - let newPStart //= {x:roofLine.x1, y:roofLine.y1} - let newPEnd //= {x:movedLines.x2, y:movedLines.y2} + let newPStart //= {x:roofLine.x1, y:roofLine.y1} + let newPEnd //= {x:movedLines.x2, y:movedLines.y2} //현재 roof는 무조건 시계방향 - const getAddLine = (p1, p2, stroke = '') => { - movedLines.push({ index, p1, p2 }) + const getAddLine = (p1, p2, stroke = '') => { + movedLines.push({ index, p1, p2 }) // Usage: - // let mergeLines = mergeMovedLines(movedLines); - //console.log("mergeLines:::::::", mergeLines); - const line = new QLine([p1.x, p1.y, p2.x, p2.y], { - parentId : roof.id, - fontSize : roof.fontSize, - stroke : '#3FBAE6', - strokeWidth: 2, - name : 'eaveHelpLine', - lineName : 'eaveHelpLine', - selectable : true, - visible : true, - roofId : roofId, - attributes : { - type: 'eaveHelpLine', - isStart : true, - pitch: wallLine.attributes.pitch, - } - }); - //coordinateText(line) - canvas.add(line) - canvas.renderAll(); - return line - } + // let mergeLines = mergeMovedLines(movedLines); + //console.log("mergeLines:::::::", mergeLines); + const line = new QLine([p1.x, p1.y, p2.x, p2.y], { + parentId : roof.id, + fontSize : roof.fontSize, + stroke : '#3FBAE6', + strokeWidth: 4, + name : 'eaveHelpLine', + lineName : 'eaveHelpLine', + visible : true, + roofId : roofId, + selectable: true, + hoverCursor: 'pointer', + attributes : { + type : 'eaveHelpLine', + isStart: true, + pitch : wallLine.attributes.pitch, + } + }); - //getAddLine(roofLine.startPoint, roofLine.endPoint, ) //외곽선을 그린다 + //coordinateText(line) + canvas.add(line) + line.bringToFront() + canvas.renderAll(); + return line + } - newPStart = { x: roofLine.x1, y: roofLine.y1 } - newPEnd = { x: roofLine.x2, y: roofLine.y2 } + //getAddLine(roofLine.startPoint, roofLine.endPoint, ) //외곽선을 그린다 - const getInnerLines = (lines, point) => { + newPStart = { x: roofLine.x1, y: roofLine.y1 } + newPEnd = { x: roofLine.x2, y: roofLine.y2 } - } - let isIn = false - let isOut = false + const getInnerLines = (lines, point) => { + + } + let isIn = false + let isOut = false //두 포인트가 변경된 라인인 - if (fullyMoved ) { - //반시계방향향 + if (fullyMoved) { + //반시계방향향 - const mLine = getSelectLinePosition(wall, wallBaseLine) + const mLine = getSelectLinePosition(wall, wallBaseLine) - if (getOrientation(roofLine) === 'vertical') { + if (getOrientation(roofLine) === 'vertical') { - if (['left', 'right'].includes(mLine.position)) { - if(Math.abs(wallLine.x1 - wallBaseLine.x1) < 0.1 || Math.abs(wallLine.x2 - wallBaseLine.x2) < 0.1) { - return false + if (['left', 'right'].includes(mLine.position)) { + if (Math.abs(wallLine.x1 - wallBaseLine.x1) < 0.1 || Math.abs(wallLine.x2 - wallBaseLine.x2) < 0.1) { + return false + } + 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, sortedBaseLines) + let sPoint, ePoint; + if (condition === 'left_in') { + isIn = true + + if (isStartEnd.start) { + newPEnd.y = roofLine.y2; + newPEnd.x = roofLine.x2; + + const moveDist = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber() + ePoint = { x: wallBaseLine.x1, y: wallBaseLine.y1 }; + newPStart.y = wallBaseLine.y1 + + findPoints.push({ x: ePoint.x, y: ePoint.y, position: 'left_in_start' }); + const newPointX = Big(roofLine.x1).plus(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 + const pLineX = roofLines[idx - 1].x1 + + getAddLine({ x: newPStart.x, y: newPStart.y }, { x: ePoint.x, y: ePoint.y }, 'blue') + getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange') + + if (Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + getAddLine({ x: pLineX, y: pLineY }, { x: newPointX, y: pLineY }, 'green') + getAddLine({ x: newPointX, y: pLineY }, { x: ePoint.x, y: ePoint.y }, 'pink') + } } - 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, sortedBaseLines) - let sPoint, ePoint; - if(condition === 'left_in') { - isIn = true - if (isStartEnd.start ) { - newPEnd.y = roofLine.y2; - newPEnd.x = roofLine.x2; + if (isStartEnd.end) { + newPStart.y = roofLine.y1; + newPStart.x = roofLine.x1; - const moveDist = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber() - ePoint = {x: wallBaseLine.x1, y: wallBaseLine.y1}; - newPStart.y = wallBaseLine.y1 + const moveDist = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber() + ePoint = { x: wallBaseLine.x2, y: wallBaseLine.y2 }; + newPEnd.y = wallBaseLine.y2 - findPoints.push({ x: ePoint.x, y: ePoint.y, position: 'left_in_start' }); - const newPointX = Big(roofLine.x1).plus(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 - const pLineX = roofLines[idx-1].x1 + findPoints.push({ x: ePoint.x, y: ePoint.y, position: 'left_in_end' }); + 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 = (roofLines.length < index + 1) ? 0 : index + const pLineX = roofLines[idx + 1].x2 - getAddLine({ x: newPStart.x, y: newPStart.y }, { x: ePoint.x, y: ePoint.y }, 'blue') - getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange') + getAddLine({ x: newPEnd.x, y: newPEnd.y }, { x: ePoint.x, y: ePoint.y }, 'blue') + getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: newPointX, y: roofLine.y1 }, 'orange') - if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { - getAddLine({ x: pLineX, y: pLineY }, { x: newPointX, y: pLineY }, 'green') - getAddLine({ x: newPointX, y: pLineY }, { x: ePoint.x, y: ePoint.y }, 'pink') - } + if (Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) { + getAddLine({ x: pLineX, y: pLineY }, { x: newPointX, y: pLineY }, 'green') + getAddLine({ x: newPointX, y: pLineY }, { x: ePoint.x, y: ePoint.y }, 'pink') } + //getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange') + } - if(isStartEnd.end) { - newPStart.y = roofLine.y1; - newPStart.x = roofLine.x1; + } else if (condition === 'left_out') { + console.log("left_out::::isStartEnd:::::", isStartEnd); + if (isStartEnd.start) { - const moveDist = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber() - ePoint = {x: wallBaseLine.x2, y: wallBaseLine.y2}; - newPEnd.y = wallBaseLine.y2 + 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 }) - findPoints.push({ x: ePoint.x, y: ePoint.y, position: 'left_in_end' }); - 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 = (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') - getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: newPointX, y: roofLine.y1 }, 'orange') - - if(Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) { - getAddLine({ x: pLineX, y: pLineY }, { x: newPointX, y: pLineY }, 'green') - getAddLine({ x: newPointX, y: pLineY }, { x: ePoint.x, y: ePoint.y }, 'pink') - } - //getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange') - } - - }else if(condition === 'left_out') { - console.log("left_out::::isStartEnd:::::", isStartEnd); - if(isStartEnd.start){ - - 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 }) - - const eLineY = Big(bStartY).minus(wallLine.y1).abs().toNumber() - newPStart.y = aStartY - newPEnd.y = roofLine.y2 //Big(roofLine.y2).minus(eLineY).toNumber() - let idx = (0 >= index - 1)?roofLines.length:index - const newLine = roofLines[idx-1]; - - if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { - if(inLine){ - if(inLine.x1 < inLine.x2) { - getAddLine({ y: bStartY, x: wallLine.x2 }, { y: inLine.y2, x: inLine.x2 }, 'pink') - }else{ - getAddLine({ y: inLine.y2, x: inLine.x2 },{ y: bStartY, x: wallLine.x2 }, 'pink') - } + const eLineY = Big(bStartY).minus(wallLine.y1).abs().toNumber() + newPStart.y = aStartY + newPEnd.y = roofLine.y2 //Big(roofLine.y2).minus(eLineY).toNumber() + let idx = (0 >= index - 1) ? roofLines.length : index + const newLine = roofLines[idx - 1]; + if (Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + if (inLine) { + if (inLine.x1 < inLine.x2) { + getAddLine({ y: bStartY, x: wallLine.x2 }, { y: inLine.y2, x: inLine.x2 }, 'pink') + } 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{ - const cLineY = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber() - newPStart.y = Big(newPStart.y).minus(cLineY).toNumber(); + + } + 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(); + const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) + if (inLine) { + if (inLine.x1 < inLine.x2) { + getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPStart.y, x: newPStart.x }, 'purple') + } + } else { + //newPStart.y = wallLine.y1; + //외곽 라인 그리기 + const rLineM = Big(wallBaseLine.x2).minus(roofLine.x2).abs().toNumber(); + newPStart.y = Big(wallBaseLine.y1).minus(rLineM).abs().toNumber(); const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) - if(inLine){ - if(inLine.x1 < inLine.x2) { + if (inLine) { + if (inLine.x2 > inLine.x1) { getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1},{ y: newPStart.y, x: newPStart.x }, 'purple') - } - }else { - //newPStart.y = wallLine.y1; - //외곽 라인 그리기 - const rLineM = Big(wallBaseLine.x2).minus(roofLine.x2).abs().toNumber(); - newPStart.y = Big(wallBaseLine.y1).minus(rLineM).abs().toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) - if(inLine) { - if (inLine.x2 > inLine.x1) { - getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - } else { - getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') - } - } - } - - } - } - - - 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 = roofLine.y1//Big(roofLine.y1).plus(eLineY).toNumber() - let idx = (roofLines.length < index + 1)?0:index - const newLine = roofLines[idx+1]; - - if(Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) { - if(inLine){ - if(inLine.x1 < inLine.x2) { - getAddLine({ y: bStartY, x: wallLine.x1 }, { y: inLine.y2, x: inLine.x2 }, 'pink') - }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{ - const cLineY = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber() - newPEnd.y = Big(newPEnd.y).plus(cLineY).toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) - if(inLine){ - if(inLine.x1 < inLine.x2) { - getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 },{ y: newPEnd.y, x: newPEnd.x }, 'purple') - } - }else { - - // newPEnd.y = wallLine.y2 - - //외곽 라인 그리기 - const rLineM = Big(wallBaseLine.x2).minus(roofLine.x2).abs().toNumber(); - newPEnd.y = Big(wallBaseLine.y2).plus(rLineM).abs().toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) - if(inLine) { - if (inLine.x2 > inLine.x1) { - getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - } else { - getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') - } - } - } - - } - findPoints.push({ y: newPStart.y, x: newPEnd.x, position: 'left_out_end' }); - } - }else if(condition === 'right_in') { - if (isStartEnd.start ) { - - newPEnd.y = roofLine.y2; - newPEnd.x = roofLine.x2; - - const moveDist = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber() - ePoint = {x: wallBaseLine.x1, y: wallBaseLine.y1}; - newPStart.y = wallBaseLine.y1 - - findPoints.push({ x: ePoint.x, y: ePoint.y, position: 'right_in_start'}); - 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 - const pLineX = roofLines[idx-1].x1 - - getAddLine({ x: newPStart.x, y: newPStart.y }, { x: ePoint.x, y: ePoint.y }, 'blue') - //getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange') - - if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { - getAddLine({ x: pLineX, y: pLineY }, { x: newPointX, y: pLineY }, 'green') - getAddLine({ x: newPointX, y: pLineY }, { x: ePoint.x, y: ePoint.y }, 'pink') - } - } - - if(isStartEnd.end) { - newPStart.y = roofLine.y1; - newPStart.x = roofLine.x1; - - const moveDist = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber() - ePoint = {x: wallBaseLine.x2, y: wallBaseLine.y2}; - newPEnd.y = wallBaseLine.y2 - - findPoints.push({ x: ePoint.x, y: ePoint.y, position: 'right_in_end' }); - 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 = (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') - getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: newPointX, y: roofLine.y1 }, 'orange') - - if(Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) { - getAddLine({ x: pLineX, y: pLineY }, { x: newPointX, y: pLineY }, 'green') - getAddLine({ x: newPointX, y: pLineY }, { x: ePoint.x, y: ePoint.y }, 'pink') - } - getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange') - } - - }else if(condition === 'right_out') { - console.log("right_out::::isStartEnd:::::", isStartEnd); - if (isStartEnd.start ) { //x1 inside - const moveDist = Big(wallLine.x1).minus(wallBaseLine.x1).abs().toNumber() - const aStartY = Big(roofLine.y1).plus(moveDist).abs().toNumber() - const bStartY = Big(wallLine.y1).plus(moveDist).abs().toNumber() - const inLine = findLineContainingPoint(innerLines, { y: aStartY, x: roofLine.x1 }) - console.log("startLines:::::::", inLine); - const eLineY = Big(bStartY).minus(wallLine.y1).abs().toNumber() - newPStart.y = aStartY - newPEnd.y = roofLine.y2//Big(roofLine.y2).plus(eLineY).toNumber() - let idx = (0 >= index - 1)?roofLines.length:index - const newLine = roofLines[idx-1]; - - if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { - if(inLine){ - if(inLine.x2 < inLine.x1) { - getAddLine({ y: bStartY, x: wallLine.x2 }, { y: inLine.y2, x: inLine.x2 }, 'pink') - }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{ - const cLineY = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber() - newPStart.y = Big(newPStart.y).plus(cLineY).toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) - if(inLine){ - if(inLine.x2 < inLine.x1 ) { - getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 },{ y: newPStart.y, x: newPStart.x }, 'purple') - } - }else { - //newPStart.y = wallLine.y1; - //외곽 라인 그리기 - const rLineM = Big(wallBaseLine.x1).minus(roofLine.x1).abs().toNumber(); - newPStart.y = Big(wallBaseLine.y1).plus(rLineM).abs().toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) - if(inLine){ - if(inLine.x2 > inLine.x1 ) { - getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y1, x: inLine.x1 }, 'purple') - }else{ - getAddLine({ y: inLine.y2, x: inLine.x2 }, { y: newPStart.y, x: newPStart.x } , 'purple') - } - } - - } - - } - - } - - 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 = roofLine.y1//Big(roofLine.y1).minus(eLineY).toNumber() - let idx = (roofLines.length < index + 1)?0:index - const newLine = roofLines[idx+1]; - if(inLine){ - if(inLine.x2 < inLine.x1) { - getAddLine({ y: bStartY, x: wallLine.x1 }, { y: inLine.y2, x: inLine.x2 }, 'pink') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 },{ y: bStartY, x: wallLine.x1 }, '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, position: 'right_out_end' }); - }else{ - const cLineY = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber() - newPEnd.y = Big(newPEnd.y).minus(cLineY).toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) - if(inLine){ - if(inLine.x2 < inLine.x1) { - getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ + } else { getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') } - }else { - //newPEnd.y = wallLine.y2; - - //외곽 라인 그리기 - const rLineM = Big(wallBaseLine.x2).minus(roofLine.x2).abs().toNumber(); - newPEnd.y = Big(wallBaseLine.y2).minus(rLineM).abs().toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) - if(inLine){ - if(inLine.x2 > inLine.x1 ) { - getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y1, x: inLine.x1 }, 'purple') - }else{ - getAddLine({ y: inLine.y2, x: inLine.x2}, { y: newPEnd.y, x: newPEnd.x } , 'purple') - } - } - } - } + } } - } - } else if (getOrientation(roofLine) === 'horizontal') { //red - if (['top', 'bottom'].includes(mLine.position)) { - if(Math.abs(wallLine.y1 - wallBaseLine.y1) < 0.1 || Math.abs(wallLine.y2 - wallBaseLine.y2) < 0.1) { - return false + + 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 = roofLine.y1//Big(roofLine.y1).plus(eLineY).toNumber() + let idx = (roofLines.length < index + 1) ? 0 : index + const newLine = roofLines[idx + 1]; + + if (Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) { + if (inLine) { + if (inLine.x1 < inLine.x2) { + getAddLine({ y: bStartY, x: wallLine.x1 }, { y: inLine.y2, x: inLine.x2 }, 'pink') + } 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 { + const cLineY = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber() + newPEnd.y = Big(newPEnd.y).plus(cLineY).toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) + if (inLine) { + if (inLine.x1 < inLine.x2) { + getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') + } + } else { + + // newPEnd.y = wallLine.y2 + + //외곽 라인 그리기 + const rLineM = Big(wallBaseLine.x2).minus(roofLine.x2).abs().toNumber(); + newPEnd.y = Big(wallBaseLine.y2).plus(rLineM).abs().toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) + if (inLine) { + if (inLine.x2 > inLine.x1) { + getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') + } + } + } + + } + findPoints.push({ y: newPStart.y, x: newPEnd.x, position: 'left_out_end' }); } - const positionType = - (mLine.position === 'top' && wallLine.y1 < wallBaseLine.y1) || - (mLine.position === 'bottom' && wallLine.y1 > wallBaseLine.y1) - ? 'in' : 'out'; + } else if (condition === 'right_in') { + if (isStartEnd.start) { - const condition = `${mLine.position}_${positionType}`; - let isStartEnd = findInteriorPoint(wallBaseLine, sortedBaseLines) + newPEnd.y = roofLine.y2; + newPEnd.x = roofLine.x2; - let sPoint, ePoint; + const moveDist = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber() + ePoint = { x: wallBaseLine.x1, y: wallBaseLine.y1 }; + newPStart.y = wallBaseLine.y1 - if(condition === 'top_in') { - if (isStartEnd.start ) { - const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() - sPoint = {x: wallBaseLine.x1, y: wallBaseLine.y1}; - newPStart.x = wallBaseLine.x1; + findPoints.push({ x: ePoint.x, y: ePoint.y, position: 'right_in_start' }); + 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 + const pLineX = roofLines[idx - 1].x1 + getAddLine({ x: newPStart.x, y: newPStart.y }, { x: ePoint.x, y: ePoint.y }, 'blue') + //getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange') - const newPointY = Big(roofLine.y2).plus(moveDist).toNumber() - - 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 - 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, position: 'top_in_start' }); - - if(Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) { - getAddLine({ x: pLineX, y: pLineY }, { x: pLineX, y: newPointY }, 'green') - getAddLine({ x: pLineX, y: newPointY }, { x: sPoint.x, y: sPoint.y }, 'pink') - } - //getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: roofLine.x2, y: newPointY }, 'orange') - + if (Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + getAddLine({ x: pLineX, y: pLineY }, { x: newPointX, y: pLineY }, 'green') + getAddLine({ x: newPointX, y: pLineY }, { x: ePoint.x, y: ePoint.y }, 'pink') } + } - if(isStartEnd.end){ - const moveDist = Big(wallLine.y2).minus(wallBaseLine.y2).abs().toNumber() - sPoint = { x: wallBaseLine.x2, y: wallBaseLine.y2 } - newPEnd.x = wallBaseLine.x2 + if (isStartEnd.end) { + newPStart.y = roofLine.y1; + newPStart.x = roofLine.x1; - const newPointY = Big(roofLine.y1).plus(moveDist).toNumber() + const moveDist = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber() + ePoint = { x: wallBaseLine.x2, y: wallBaseLine.y2 }; + newPEnd.y = wallBaseLine.y2 - const pDist = Big(wallLine.y1).minus(roofLine.y1).abs().toNumber() - const pLineX = Big(roofLine.x2).minus(0).abs().toNumber() - 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, position: 'top_in_end' }); + findPoints.push({ x: ePoint.x, y: ePoint.y, position: 'right_in_end' }); + 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 = (roofLines.length < index + 1) ? 0 : index + const pLineX = roofLines[idx + 1].x2 - if (Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) { - getAddLine({ x: pLineX, y: pLineY }, { x: pLineX, y: newPointY }, 'green') - getAddLine({ x: pLineX, y: newPointY }, { x: sPoint.x, y: sPoint.y }, 'pink') - } + getAddLine({ x: newPEnd.x, y: newPEnd.y }, { x: ePoint.x, y: ePoint.y }, 'blue') + getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: newPointX, y: roofLine.y1 }, 'orange') - - //getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: roofLine.x1, y: newPointY }, 'orange') + if (Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) { + getAddLine({ x: pLineX, y: pLineY }, { x: newPointX, y: pLineY }, 'green') + getAddLine({ x: newPointX, y: pLineY }, { x: ePoint.x, y: ePoint.y }, 'pink') } + getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange') + } - }else if(condition === 'top_out') { - console.log("top_out isStartEnd:::::::", isStartEnd); + } else if (condition === 'right_out') { + console.log("right_out::::isStartEnd:::::", isStartEnd); + if (isStartEnd.start) { //x1 inside + const moveDist = Big(wallLine.x1).minus(wallBaseLine.x1).abs().toNumber() + const aStartY = Big(roofLine.y1).plus(moveDist).abs().toNumber() + const bStartY = Big(wallLine.y1).plus(moveDist).abs().toNumber() + const inLine = findLineContainingPoint(innerLines, { y: aStartY, x: roofLine.x1 }) + console.log("startLines:::::::", inLine); + const eLineY = Big(bStartY).minus(wallLine.y1).abs().toNumber() + newPStart.y = aStartY + newPEnd.y = roofLine.y2//Big(roofLine.y2).plus(eLineY).toNumber() + let idx = (0 >= index - 1) ? roofLines.length : index + const newLine = roofLines[idx - 1]; - if (isStartEnd.start ) { - const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() - const aStartX = Big(roofLine.x1).plus(moveDist).toNumber() - const bStartX = Big(wallLine.x1).plus(moveDist).toNumber() - const inLine = findLineContainingPoint(innerLines, { x: aStartX, y: newPEnd.y }) - - const eLineX = Big(bStartX).minus(wallLine.x1).abs().toNumber() - newPEnd.x = roofLine.x2 //Big(newPEnd.x).plus(eLineX).toNumber() - newPStart.x = aStartX - let idx = (0 > index - 1)?roofLines.length:index - const newLine = roofLines[idx-1]; - - if(Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) { - if(inLine){ - if(inLine.y2 > inLine.y1 ) { - getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') - }else{ - getAddLine({ x: inLine.x1, y: inLine.y1 }, { x: bStartX, y: wallLine.y1 }, 'pink') - } + if (Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) { + if (inLine) { + if (inLine.x2 < inLine.x1) { + getAddLine({ y: bStartY, x: wallLine.x2 }, { y: inLine.y2, x: inLine.x2 }, 'pink') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: bStartY, x: wallLine.x2 }, '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{ - const cLineX = Big(wallBaseLine.y1).minus(wallLine.y1).abs().toNumber() - newPStart.x = Big(newPStart.x).plus(cLineX).toNumber(); + } + 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(); + const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) + if (inLine) { + if (inLine.x2 < inLine.x1) { + getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPStart.y, x: newPStart.x }, 'purple') + } + } else { + //newPStart.y = wallLine.y1; + //외곽 라인 그리기 + const rLineM = Big(wallBaseLine.x1).minus(roofLine.x1).abs().toNumber(); + newPStart.y = Big(wallBaseLine.y1).plus(rLineM).abs().toNumber(); const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) - if(inLine){ - if(inLine.y2 > inLine.y1 ) { - getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPStart.y, x: newPStart.x } , 'purple') - } - - }else { - //외곽 라인 그리기 - const rLineM = Big(wallBaseLine.y1).minus(roofLine.y1).abs().toNumber(); - newPStart.x = Big(wallBaseLine.x1).plus(rLineM).abs().toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) - if(inLine){ - if(inLine.y2 > inLine.y1 ) { - getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPStart.y, x: newPStart.x } , 'purple') - } + if (inLine) { + if (inLine.x2 > inLine.x1) { + getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y1, x: inLine.x1 }, 'purple') + } else { + getAddLine({ y: inLine.y2, x: inLine.x2 }, { y: newPStart.y, x: newPStart.x }, 'purple') } } } + } - 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 = roofLine.x1;//Big(newPStart.x).minus(eLineX).abs().toNumber() - newPEnd.x = aStartX - let idx = (roofLines.length < index + 1)?0:index - const newLine = roofLines[idx+1]; - if(Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) { - if(inLine){ - if(inLine.y2 > inLine.y1 ){ - getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') - }else{ - getAddLine({ x: inLine.x1, y: inLine.y1 },{ x: bStartX, y: wallLine.y1 }, 'pink') - } + } + 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 = roofLine.y1//Big(roofLine.y1).minus(eLineY).toNumber() + let idx = (roofLines.length < index + 1) ? 0 : index + const newLine = roofLines[idx + 1]; + if (inLine) { + if (inLine.x2 < inLine.x1) { + getAddLine({ y: bStartY, x: wallLine.x1 }, { y: inLine.y2, x: inLine.x2 }, 'pink') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: bStartY, x: wallLine.x1 }, '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, position: 'right_out_end' }); + } else { + const cLineY = Big(wallBaseLine.x2).minus(wallLine.x2).abs().toNumber() + newPEnd.y = Big(newPEnd.y).minus(cLineY).toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) + if (inLine) { + if (inLine.x2 < inLine.x1) { + getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') } - 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(); + } else { + //newPEnd.y = wallLine.y2; + + //외곽 라인 그리기 + const rLineM = Big(wallBaseLine.x2).minus(roofLine.x2).abs().toNumber(); + newPEnd.y = Big(wallBaseLine.y2).minus(rLineM).abs().toNumber(); const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) - if(inLine){ - if(inLine.y2 > inLine.y1 ) { - getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 },{ y: newPEnd.y, x: newPEnd.x }, 'purple') - } - }else { - //newPEnd.x = wallLine.x2; - //외곽 라인 그리기 - const rLineM = Big(wallBaseLine.y2).minus(roofLine.y2).abs().toNumber(); - newPEnd.x = Big(wallBaseLine.x2).minus(rLineM).abs().toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) - if(inLine){ - if(inLine.y1 > inLine.y2 ) { - getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y1, x: inLine.x1 }, 'purple') - }else{ - getAddLine({ y: inLine.y2, x: inLine.x2 }, { y: newPEnd.y, x: newPEnd.x } , 'purple') - } + if (inLine) { + if (inLine.x2 > inLine.x1) { + getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y1, x: inLine.x1 }, 'purple') + } else { + getAddLine({ y: inLine.y2, x: inLine.x2 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') } } } - } - }else if(condition === 'bottom_in') { - if (isStartEnd.start ) { - const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() - sPoint = {x: wallBaseLine.x1, y: wallBaseLine.y1}; - newPStart.x = wallBaseLine.x1; - - const newPointY = Big(roofLine.y2).minus(moveDist).toNumber() - - 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 - 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, position: 'bottom_in_start' }); - - if(Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) { - getAddLine({ x: pLineX, y: pLineY }, { x: pLineX, y: newPointY }, 'green') - getAddLine({ x: pLineX, y: newPointY }, { x: sPoint.x, y: sPoint.y }, 'pink') - } - getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: roofLine.x2, y: newPointY }, 'orange') - } - - if(isStartEnd.end){ - const moveDist = Big(wallLine.y2).minus(wallBaseLine.y2).abs().toNumber() - sPoint = {x: wallBaseLine.x2, y: wallBaseLine.y2}; - newPEnd.x = wallBaseLine.x2; - - - const newPointY = Big(roofLine.y1).minus(moveDist).toNumber() - - const pDist = Big(wallLine.y1).minus(roofLine.y1).abs().toNumber() - const pLineX = Big(roofLine.x2).minus(0).abs().toNumber() - 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, position: 'bottom_in_end' }); - - if(Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) { - getAddLine({ x: pLineX, y: pLineY }, { x: pLineX, y: newPointY }, 'green') - getAddLine({ x: pLineX, y: newPointY }, { x: sPoint.x, y: sPoint.y }, 'pink') - } - getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: roofLine.x1, y: newPointY }, 'orange') - - } - }else if(condition === 'bottom_out') { - console.log("bottom_out isStartEnd:::::::", isStartEnd); - 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 = roofLine.x2//Big(roofLine.x2).minus(eLineX).toNumber() - newPStart.x = aStartX - let idx = (0 > index - 1)?roofLines.length:index - const newLine = roofLines[idx-1]; - - - if(Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) { - if(inLine){ - if(inLine.y2 < inLine.y1 ) { - getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') - }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{ - const cLineX = Big(wallBaseLine.y1).minus(wallLine.y1).abs().toNumber() - newPStart.x = Big(newPStart.x).minus(cLineX).toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) - if(inLine){ - if(inLine.y2 < inLine.y1 ) { - getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPStart.y, x: newPStart.x }, 'purple') - } - }else{ - //newPStart.x = wallLine.x1; - //외곽 라인 그리기 - const rLineM = Big(wallBaseLine.y1).minus(roofLine.y1).abs().toNumber(); - newPStart.x = Big(wallBaseLine.x1).minus(rLineM).abs().toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) - if(inLine){ - if(inLine.y2 > inLine.y1 ) { - getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y1, x: inLine.x1 }, 'purple') - }else{ - getAddLine({ y: inLine.y2, x: inLine.x2 }, { y: newPStart.y, x: newPStart.x } , 'purple') - } - } - } - - } - } - - 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 = roofLine.x1;//Big(roofLine.x1).plus(eLineX).toNumber() - let idx = (roofLines.length < index + 1)?0:index - const newLine = roofLines[idx + 1]; - - if(Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) { - if(inLine){ - if(inLine.y2 < inLine.y1 ) { - getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') - }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{ - const cLineX = Big(wallBaseLine.y2).minus(wallLine.y2).abs().toNumber() - newPEnd.x = Big(newPEnd.x).plus(cLineX).toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) - if(inLine){ - if(inLine.y2 < inLine.y1 ) { - getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 },{ y: newPEnd.y, x: newPEnd.x }, 'purple') - } - }else{ - //newPEnd.x = wallLine.x2; - //외곽 라인 그리기 - const rLineM = Big(wallBaseLine.y2).minus(roofLine.y2).abs().toNumber(); - newPEnd.x = Big(wallBaseLine.x2).plus(rLineM).abs().toNumber(); - const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) - if(inLine){ - if(inLine.y1 > inLine.y2 ) { - getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') - }else{ - getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x } , 'purple') - } - } - } - - } } } } } + } else if (getOrientation(roofLine) === 'horizontal') { //red - getAddLine(newPStart, newPEnd, 'red') - //canvas.remove(roofLine) - }else{ - getAddLine(roofLine.startPoint, roofLine.endPoint, ) + if (['top', 'bottom'].includes(mLine.position)) { + if (Math.abs(wallLine.y1 - wallBaseLine.y1) < 0.1 || Math.abs(wallLine.y2 - wallBaseLine.y2) < 0.1) { + return false + } + const positionType = + (mLine.position === 'top' && wallLine.y1 < wallBaseLine.y1) || + (mLine.position === 'bottom' && wallLine.y1 > wallBaseLine.y1) + ? 'in' : 'out'; + + const condition = `${mLine.position}_${positionType}`; + let isStartEnd = findInteriorPoint(wallBaseLine, sortedBaseLines) + + let sPoint, ePoint; + + if (condition === 'top_in') { + if (isStartEnd.start) { + const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() + sPoint = { x: wallBaseLine.x1, y: wallBaseLine.y1 }; + newPStart.x = wallBaseLine.x1; + + + const newPointY = Big(roofLine.y2).plus(moveDist).toNumber() + + 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 + 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, position: 'top_in_start' }); + + if (Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) { + getAddLine({ x: pLineX, y: pLineY }, { x: pLineX, y: newPointY }, 'green') + getAddLine({ x: pLineX, y: newPointY }, { x: sPoint.x, y: sPoint.y }, 'pink') + } + //getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: roofLine.x2, y: newPointY }, 'orange') + + } + + if (isStartEnd.end) { + const moveDist = Big(wallLine.y2).minus(wallBaseLine.y2).abs().toNumber() + sPoint = { x: wallBaseLine.x2, y: wallBaseLine.y2 } + newPEnd.x = wallBaseLine.x2 + + const newPointY = Big(roofLine.y1).plus(moveDist).toNumber() + + const pDist = Big(wallLine.y1).minus(roofLine.y1).abs().toNumber() + const pLineX = Big(roofLine.x2).minus(0).abs().toNumber() + 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, position: 'top_in_end' }); + + if (Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) { + getAddLine({ x: pLineX, y: pLineY }, { x: pLineX, y: newPointY }, 'green') + getAddLine({ x: pLineX, y: newPointY }, { x: sPoint.x, y: sPoint.y }, 'pink') + } + + + //getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: roofLine.x1, y: newPointY }, 'orange') + } + + } else if (condition === 'top_out') { + console.log("top_out isStartEnd:::::::", isStartEnd); + + if (isStartEnd.start) { + const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() + const aStartX = Big(roofLine.x1).plus(moveDist).toNumber() + const bStartX = Big(wallLine.x1).plus(moveDist).toNumber() + const inLine = findLineContainingPoint(innerLines, { x: aStartX, y: newPEnd.y }) + + const eLineX = Big(bStartX).minus(wallLine.x1).abs().toNumber() + newPEnd.x = roofLine.x2 //Big(newPEnd.x).plus(eLineX).toNumber() + newPStart.x = aStartX + let idx = (0 > index - 1) ? roofLines.length : index + const newLine = roofLines[idx - 1]; + + if (Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) { + if (inLine) { + if (inLine.y2 > inLine.y1) { + getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') + } 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 { + const cLineX = Big(wallBaseLine.y1).minus(wallLine.y1).abs().toNumber() + newPStart.x = Big(newPStart.x).plus(cLineX).toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) + if (inLine) { + if (inLine.y2 > inLine.y1) { + getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPStart.y, x: newPStart.x }, 'purple') + } + + } else { + //외곽 라인 그리기 + const rLineM = Big(wallBaseLine.y1).minus(roofLine.y1).abs().toNumber(); + newPStart.x = Big(wallBaseLine.x1).plus(rLineM).abs().toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) + if (inLine) { + if (inLine.y2 > inLine.y1) { + getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPStart.y, x: newPStart.x }, 'purple') + } + } + } + + } + } + 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 = roofLine.x1;//Big(newPStart.x).minus(eLineX).abs().toNumber() + newPEnd.x = aStartX + let idx = (roofLines.length < index + 1) ? 0 : index + const newLine = roofLines[idx + 1]; + + if (Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) { + if (inLine) { + if (inLine.y2 > inLine.y1) { + getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') + } 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 { + const cLineX = Big(wallLine.y2).minus(wallBaseLine.y2).abs().toNumber() + newPEnd.x = Big(newPEnd.x).minus(cLineX).toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) + if (inLine) { + if (inLine.y2 > inLine.y1) { + getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') + } + } else { + //newPEnd.x = wallLine.x2; + //외곽 라인 그리기 + const rLineM = Big(wallBaseLine.y2).minus(roofLine.y2).abs().toNumber(); + newPEnd.x = Big(wallBaseLine.x2).minus(rLineM).abs().toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) + if (inLine) { + if (inLine.y1 > inLine.y2) { + getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y1, x: inLine.x1 }, 'purple') + } else { + getAddLine({ y: inLine.y2, x: inLine.x2 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') + } + } + } + + } + } + } else if (condition === 'bottom_in') { + if (isStartEnd.start) { + const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber() + sPoint = { x: wallBaseLine.x1, y: wallBaseLine.y1 }; + newPStart.x = wallBaseLine.x1; + + + const newPointY = Big(roofLine.y2).minus(moveDist).toNumber() + + 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 + 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, position: 'bottom_in_start' }); + + if (Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) { + getAddLine({ x: pLineX, y: pLineY }, { x: pLineX, y: newPointY }, 'green') + getAddLine({ x: pLineX, y: newPointY }, { x: sPoint.x, y: sPoint.y }, 'pink') + } + getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: roofLine.x2, y: newPointY }, 'orange') + } + + if (isStartEnd.end) { + const moveDist = Big(wallLine.y2).minus(wallBaseLine.y2).abs().toNumber() + sPoint = { x: wallBaseLine.x2, y: wallBaseLine.y2 }; + newPEnd.x = wallBaseLine.x2; + + + const newPointY = Big(roofLine.y1).minus(moveDist).toNumber() + + const pDist = Big(wallLine.y1).minus(roofLine.y1).abs().toNumber() + const pLineX = Big(roofLine.x2).minus(0).abs().toNumber() + 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, position: 'bottom_in_end' }); + + if (Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) { + getAddLine({ x: pLineX, y: pLineY }, { x: pLineX, y: newPointY }, 'green') + getAddLine({ x: pLineX, y: newPointY }, { x: sPoint.x, y: sPoint.y }, 'pink') + } + getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: roofLine.x1, y: newPointY }, 'orange') + + } + } else if (condition === 'bottom_out') { + console.log("bottom_out isStartEnd:::::::", isStartEnd); + 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 = roofLine.x2//Big(roofLine.x2).minus(eLineX).toNumber() + newPStart.x = aStartX + let idx = (0 > index - 1) ? roofLines.length : index + const newLine = roofLines[idx - 1]; + + + if (Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) { + if (inLine) { + if (inLine.y2 < inLine.y1) { + getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') + } 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 { + const cLineX = Big(wallBaseLine.y1).minus(wallLine.y1).abs().toNumber() + newPStart.x = Big(newPStart.x).minus(cLineX).toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) + if (inLine) { + if (inLine.y2 < inLine.y1) { + getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPStart.y, x: newPStart.x }, 'purple') + } + } else { + //newPStart.x = wallLine.x1; + //외곽 라인 그리기 + const rLineM = Big(wallBaseLine.y1).minus(roofLine.y1).abs().toNumber(); + newPStart.x = Big(wallBaseLine.x1).minus(rLineM).abs().toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x }) + if (inLine) { + if (inLine.y2 > inLine.y1) { + getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y1, x: inLine.x1 }, 'purple') + } else { + getAddLine({ y: inLine.y2, x: inLine.x2 }, { y: newPStart.y, x: newPStart.x }, 'purple') + } + } + } + + } + } + + 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 = roofLine.x1;//Big(roofLine.x1).plus(eLineX).toNumber() + let idx = (roofLines.length < index + 1) ? 0 : index + const newLine = roofLines[idx + 1]; + + if (Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) { + if (inLine) { + if (inLine.y2 < inLine.y1) { + getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink') + } 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 { + const cLineX = Big(wallBaseLine.y2).minus(wallLine.y2).abs().toNumber() + newPEnd.x = Big(newPEnd.x).plus(cLineX).toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) + if (inLine) { + if (inLine.y2 < inLine.y1) { + getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') + } + } else { + //newPEnd.x = wallLine.x2; + //외곽 라인 그리기 + const rLineM = Big(wallBaseLine.y2).minus(roofLine.y2).abs().toNumber(); + newPEnd.x = Big(wallBaseLine.x2).plus(rLineM).abs().toNumber(); + const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x }) + if (inLine) { + if (inLine.y1 > inLine.y2) { + getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple') + } else { + getAddLine({ y: inLine.y1, x: inLine.x1 }, { y: newPEnd.y, x: newPEnd.x }, 'purple') + } + } + } + + } + } + } + } } + getAddLine(newPStart, newPEnd, 'red') + //canvas.remove(roofLine) + } else { + getAddLine(roofLine.startPoint, roofLine.endPoint,) + } - canvas.renderAll() - }); - // } + canvas.renderAll() + }); +} + getMoveUpDownLine() + + } if (findPoints.length > 0) { // 모든 점에 대해 라인 업데이트를 누적