Compare commits

..

No commits in common. "cbf7e9119c05eaef0f2f090c56c444b85f500711" and "2ac1e80964cff3845b0e34de49e595c1ff660c5c" have entirely different histories.

2 changed files with 71 additions and 211 deletions

View File

@ -1059,7 +1059,7 @@ export const usePolygon = () => {
for (let i = divideLines.length - 1; i >= 0; i--) { for (let i = divideLines.length - 1; i >= 0; i--) {
const line = divideLines[i] const line = divideLines[i]
const { intersections, startPoint, endPoint } = line const { intersections, startPoint, endPoint } = line
console.log("intersections::::::::::", intersections)
if (intersections.length === 1) { if (intersections.length === 1) {
const newLinePoint1 = [line.x1, line.y1, intersections[0].x, intersections[0].y] const newLinePoint1 = [line.x1, line.y1, intersections[0].x, intersections[0].y]
const newLinePoint2 = [intersections[0].x, intersections[0].y, line.x2, line.y2] const newLinePoint2 = [intersections[0].x, intersections[0].y, line.x2, line.y2]
@ -1387,7 +1387,7 @@ export const usePolygon = () => {
let representLine let representLine
// 지붕을 그리면서 기존 polygon의 line중 연결된 line을 찾는다. // 지붕을 그리면서 기존 polygon의 line중 연결된 line을 찾는다.
[...polygonLines, ...innerLines].forEach((line) => { ;[...polygonLines, ...innerLines].forEach((line) => {
let startFlag = false let startFlag = false
let endFlag = false let endFlag = false
const startPoint = line.startPoint const startPoint = line.startPoint
@ -1490,7 +1490,6 @@ export const usePolygon = () => {
}) })
roofLines.forEach((line) => { roofLines.forEach((line) => {
console.log("::::::::::",line);
roof.lines.forEach((roofLine) => { roof.lines.forEach((roofLine) => {
if ( if (
(isSamePoint(line.startPoint, roofLine.startPoint) && isSamePoint(line.endPoint, roofLine.endPoint)) || (isSamePoint(line.startPoint, roofLine.startPoint) && isSamePoint(line.endPoint, roofLine.endPoint)) ||
@ -1584,126 +1583,52 @@ export const usePolygon = () => {
// ==== Dijkstra pathfinding ==== // ==== Dijkstra pathfinding ====
// function findShortestPath(start, end, graph, epsilon = 1) {
// const startKey = pointToKey(start, epsilon)
// const endKey = pointToKey(end, epsilon)
//
// const distances = {}
// const previous = {}
// const visited = new Set()
// const queue = [{ key: startKey, dist: 0 }]
//
// for (const key in graph) distances[key] = Infinity
// distances[startKey] = 0
//
// while (queue.length > 0) {
// queue.sort((a, b) => a.dist - b.dist)
// const { key } = queue.shift()
// if (visited.has(key)) continue
// visited.add(key)
//
// for (const neighbor of graph[key] || []) {
// const neighborKey = pointToKey(neighbor.point, epsilon)
// const alt = distances[key] + neighbor.distance
// if (alt < distances[neighborKey]) {
// distances[neighborKey] = alt
// previous[neighborKey] = key
// queue.push({ key: neighborKey, dist: alt })
// }
// }
// }
//
// const path = []
// let currentKey = endKey
//
// if (!previous[currentKey]) return null
//
// while (currentKey !== startKey) {
// const [x, y] = currentKey.split(',').map(Number)
// path.unshift({ x, y })
// currentKey = previous[currentKey]
// }
//
// const [sx, sy] = startKey.split(',').map(Number)
// path.unshift({ x: sx, y: sy })
//
// return path
// }
function findShortestPath(start, end, graph, epsilon = 1) { function findShortestPath(start, end, graph, epsilon = 1) {
const startKey = pointToKey(start, epsilon); const startKey = pointToKey(start, epsilon)
const endKey = pointToKey(end, epsilon); const endKey = pointToKey(end, epsilon)
// 거리와 이전 노드 추적 const distances = {}
const distances = { [startKey]: 0 }; const previous = {}
const previous = {}; const visited = new Set()
const visited = new Set(); const queue = [{ key: startKey, dist: 0 }]
// 우선순위 큐 (거리가 짧은 순으로 정렬) for (const key in graph) distances[key] = Infinity
const queue = [{ key: startKey, dist: 0 }]; distances[startKey] = 0
// 모든 노드 초기화 while (queue.length > 0) {
for (const key in graph) { queue.sort((a, b) => a.dist - b.dist)
if (key !== startKey) { const { key } = queue.shift()
distances[key] = Infinity; if (visited.has(key)) continue
} visited.add(key)
}
// 우선순위 큐에서 다음 노드 선택 for (const neighbor of graph[key] || []) {
const getNextNode = () => { const neighborKey = pointToKey(neighbor.point, epsilon)
if (queue.length === 0) return null; const alt = distances[key] + neighbor.distance
queue.sort((a, b) => a.dist - b.dist); if (alt < distances[neighborKey]) {
return queue.shift(); distances[neighborKey] = alt
}; previous[neighborKey] = key
queue.push({ key: neighborKey, dist: alt })
let current;
while ((current = getNextNode())) {
const currentKey = current.key;
// 목적지에 도달하면 종료
if (currentKey === endKey) break;
// 이미 방문한 노드는 건너뜀
if (visited.has(currentKey)) continue;
visited.add(currentKey);
// 인접 노드 탐색
for (const neighbor of graph[currentKey] || []) {
const neighborKey = pointToKey(neighbor.point, epsilon);
if (visited.has(neighborKey)) continue;
const alt = distances[currentKey] + neighbor.distance;
// 더 짧은 경로를 찾은 경우 업데이트
if (alt < (distances[neighborKey] || Infinity)) {
distances[neighborKey] = alt;
previous[neighborKey] = currentKey;
// 우선순위 큐에 추가
queue.push({ key: neighborKey, dist: alt });
} }
} }
} }
// 경로 재구성 const path = []
const path = []; let currentKey = endKey
let currentKey = endKey;
// 시작점에 도달할 때까지 역추적 if (!previous[currentKey]) return null
while (previous[currentKey] !== undefined) {
const [x, y] = currentKey.split(',').map(Number); while (currentKey !== startKey) {
path.unshift({ x, y }); const [x, y] = currentKey.split(',').map(Number)
currentKey = previous[currentKey]; path.unshift({ x, y })
currentKey = previous[currentKey]
} }
// 시작점 추가 const [sx, sy] = startKey.split(',').map(Number)
if (path.length > 0) { path.unshift({ x: sx, y: sy })
const [sx, sy] = startKey.split(',').map(Number);
path.unshift({ x: sx, y: sy }); return path
} }
return path.length > 0 ? path : null;
}
// 최종 함수 // 최종 함수
function getPath(start, end, graph, epsilon = 1) { function getPath(start, end, graph, epsilon = 1) {
// startPoint와 arrivalPoint가 될 수 있는 점은 line.attributes.type이 'default' 혹은 null이 아닌 line인 경우에만 가능 // startPoint와 arrivalPoint가 될 수 있는 점은 line.attributes.type이 'default' 혹은 null이 아닌 line인 경우에만 가능

View File

@ -857,21 +857,18 @@ if(roof.moveUpDown??0 > 0) {
newPStart.y = wallBaseLine.y1; newPStart.y = wallBaseLine.y1;
getAddLine({ x: newPEnd.x, y: wallBaseLine.y1 }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) getAddLine({ x: newPEnd.x, y: wallBaseLine.y1 }, { x: wallBaseLine.x1, y: wallBaseLine.y1 })
findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 }); findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 });
} else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y) { //bottom right } else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y) {
newPEnd.y = wallBaseLine.y2; newPEnd.y = wallBaseLine.y2;
getAddLine({ x: newPEnd.x, y: wallBaseLine.y2 }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) getAddLine({ x: newPEnd.x, y: wallBaseLine.y2 }, { x: wallBaseLine.x2, y: wallBaseLine.y2 })
findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 });
} else if (newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) { //top left } else if (newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) { //top left
newPEnd.y = wallBaseLine.y2; newPEnd.y = wallBaseLine.y2;
getAddLine({ x: newPEnd.x, y: wallBaseLine.y2 }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) getAddLine({ x: newPEnd.x, y: wallBaseLine.y2 }, { x: wallBaseLine.x2, y: wallBaseLine.y2 })
findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 }); findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 });
} else if (wallBaseLine.y1 <= newPStart.y && newPStart.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPEnd.y) { //bottom left } else if (wallBaseLine.y1 <= newPStart.y && newPStart.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPEnd.y) {
newPStart.y = wallBaseLine.y1; newPStart.y = wallBaseLine.y1;
getAddLine({ x: newPEnd.x, y: wallBaseLine.y1 }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) getAddLine({ x: newPEnd.x, y: wallBaseLine.y1 }, { x: wallBaseLine.x1, y: wallBaseLine.y1 })
findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 });
} else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= newPStart.y && newPStart.y <= wallBaseLine.y1) { // 위가운데 } else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= newPStart.y && newPStart.y <= wallBaseLine.y1) { // 위가운데
newPEnd.y = wallBaseLine.y2; newPEnd.y = wallBaseLine.y2;
@ -904,39 +901,28 @@ if(roof.moveUpDown??0 > 0) {
getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 })
//추가 라인? //추가 라인?
findPoints.push({ 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) { //위 오른쪽
} else if (newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) { //bottom left
newPEnd.x = wallBaseLine.x2; newPEnd.x = wallBaseLine.x2;
getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) 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 } else if (wallBaseLine.x1 <= newPStart.x && newPStart.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPEnd.x) { //아래 왼쪽
newPStart.x = wallBaseLine.x1; newPStart.x = wallBaseLine.x1;
getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) 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 } else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= newPStart.x && newPStart.x <= wallBaseLine.x1) { // top center
newPEnd.x = wallBaseLine.x2; newPEnd.x = wallBaseLine.x2;
getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) 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; newPStart.x = wallBaseLine.x1;
getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 })
findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 });
//추가 라인? //추가 라인?
findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 });
findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 });
} else if (wallBaseLine.x1 <= newPStart.x && newPStart.x <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) { // 아래가운데 } else if (wallBaseLine.x1 <= newPStart.x && newPStart.x <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) { // 아래가운데
newPEnd.x = wallBaseLine.x1; newPEnd.x = wallBaseLine.x1;
getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }) 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; newPStart.x = wallBaseLine.x2;
getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }) getAddLine({ x: wallBaseLine.x2, y: newPEnd.y }, { x: wallBaseLine.x2, y: wallBaseLine.y2 })
findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 });
} }
} }
@ -946,7 +932,7 @@ if(roof.moveUpDown??0 > 0) {
} else if (movedStart) { //end 변경경 } else if (movedStart) { //end 변경경
if (getOrientation(roofLine) === 'vertical') { //green 수직 if (getOrientation(roofLine) === 'vertical') {
let isCross = false let isCross = false
if (Math.abs(currentRoofLine.x2 - roofLine.x1) < 0.1 || Math.abs(currentRoofLine.x1 - roofLine.x2) < 0.1) { if (Math.abs(currentRoofLine.x2 - roofLine.x1) < 0.1 || Math.abs(currentRoofLine.x1 - roofLine.x2) < 0.1) {
@ -968,7 +954,7 @@ if(roof.moveUpDown??0 > 0) {
//대각선 라인을 보조라인으로 그린다. //대각선 라인을 보조라인으로 그린다.
if(isCross){ if(isCross){
getAddLine({ x: wallBaseLine.x1, y: wallBaseLine.y1 }, { x: roofLine.x1, y: currentRoofLine.y1 }, 'yellow') getAddLine({ x: roofLine.x1, y: currentRoofLine.y1 }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }, 'yellow')
} }
}else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//상단 오르쪽 }else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//상단 오르쪽
@ -976,17 +962,11 @@ if(roof.moveUpDown??0 > 0) {
newPStart = { x: roofLine.x1, y: roofLine.y1 } newPStart = { x: roofLine.x1, y: roofLine.y1 }
newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.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) { // bottom left }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 } newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 }
newPEnd = { x: roofLine.x2, y: roofLine.y2 } newPEnd = { x: roofLine.x2, y: roofLine.y2 }
//대각선 라인을 보조라인으로 그린다.
if(isCross){
getAddLine( { x: wallBaseLine.x1, y: wallBaseLine.y1 }, { x: roofLine.x1, y: currentRoofLine.y1 }, 'yellow')
}
}else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y) { //하단 왼쪽 }else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y) { //하단 왼쪽
newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 } newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 }
@ -995,7 +975,7 @@ if(roof.moveUpDown??0 > 0) {
} else if (getOrientation(roofLine) === 'horizontal') { //green 수평 } else if (getOrientation(roofLine) === 'horizontal') {
let isCross = false let isCross = false
if (Math.abs(currentRoofLine.y1 - roofLine.y2) < 0.1 || Math.abs(currentRoofLine.y2 - roofLine.y1) < 0.1) { if (Math.abs(currentRoofLine.y1 - roofLine.y2) < 0.1 || Math.abs(currentRoofLine.y2 - roofLine.y1) < 0.1) {
@ -1005,37 +985,25 @@ if(roof.moveUpDown??0 > 0) {
newPStart = { y: roofLine.y1, x: roofLine.x1 } newPStart = { y: roofLine.y1, x: roofLine.x1 }
newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.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){ //top right }else if(newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 < wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x){ //하단 오른쪽v
newPStart = { y: roofLine.y1, x: roofLine.x1 } newPStart = { y: roofLine.y1, x: roofLine.x1 }
newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 }
}else if(newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPStart.x && newPStart.x <= wallBaseLine.x1) { //상단 왼쪽v }else if(newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPStart.x && newPStart.x <= wallBaseLine.x1) { //상단 왼쪽v
newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 }
newPEnd ={ y: roofLine.y2, x: roofLine.x2 } newPEnd ={ y: roofLine.y2, x: roofLine.x2 }
//대각선 라인을 보조라인으로 그린다.
if(isCross){
getAddLine({ x: currentRoofLine.x1, y: roofLine.y1 }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }, 'yellow')
}
}else if(newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) {//상단 오르쪽 }else if(newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) {//상단 오르쪽
newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 } newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 }
newPEnd ={ y: roofLine.y2, x: roofLine.x2 } newPEnd ={ y: roofLine.y2, x: roofLine.x2 }
}else if(wallBaseLine.x1 <= newPStart.x && newPStart.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPEnd.x) { //bottom rightv }else if(wallBaseLine.x1 <= newPStart.x && newPStart.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPEnd.x) { //하단 오른쪽v
newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.y1 } newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.y1 : wallBaseLine.x1 }
newPEnd = { y: roofLine.y2, x: roofLine.x2 } newPEnd = { y: roofLine.y2, x: roofLine.x2 }
//대각선 라인을 보조라인으로 그린다.
if(isCross){
getAddLine({ x: wallBaseLine.x1, y: wallBaseLine.y1 },{ x: currentRoofLine.x1, y: roofLine.y1 }, 'yellow')
}
}else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x) { //right / top }else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x) { //right / top
newPStart = { y: roofLine.y1, x: roofLine.x1 } newPStart = { y: roofLine.y1, x: roofLine.x1 }
@ -1069,19 +1037,18 @@ if(roof.moveUpDown??0 > 0) {
newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
newPEnd = { x: roofLine.x2, y: roofLine.y2 } newPEnd = { x: roofLine.x2, y: roofLine.y2 }
}else if(newPEnd.y <= wallBaseLine.y2 && wallBaseLine.y2 < wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y){ //top /right }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 } newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
newPEnd = { x: roofLine.x2, y: roofLine.y2 } newPEnd = { x: roofLine.x2, y: roofLine.y2 }
}else if(newPEnd.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPStart.y && newPStart.y <= wallBaseLine.y1) { //top / left }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 } newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
newPEnd ={ x: roofLine.x2, y: roofLine.y2 } newPEnd ={ x: roofLine.x2, y: roofLine.y2 }
}else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//top left / top / righty 오르쪽v }else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//top / righty 오르쪽v
newPStart = { x: roofLine.x1, y: roofLine.y1 } newPStart = { x: roofLine.x1, y: roofLine.y1 }
newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
@ -1096,15 +1063,10 @@ if(roof.moveUpDown??0 > 0) {
newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 } newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y1 : wallBaseLine.y1 }
newPEnd = { x: roofLine.x2, y: roofLine.y2 } newPEnd = { x: roofLine.x2, y: roofLine.y2 }
}else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y) { //bottom right }else if (wallBaseLine.y2 <= newPEnd.y && newPEnd.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y) { //하단 왼쪽
newPStart = { x: roofLine.x1, y: roofLine.y1 } newPStart = { x: roofLine.x1, y: roofLine.y1 }
newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 } 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 }, 'yellow')
}
} }
@ -1129,17 +1091,11 @@ if(roof.moveUpDown??0 > 0) {
newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 }
newPEnd ={ y: roofLine.y2, x: roofLine.x2 } newPEnd ={ y: roofLine.y2, x: roofLine.x2 }
}else if(newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) {//bottom left }else if(newPStart.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPEnd.x && newPEnd.x <= wallBaseLine.x2) {//상단 오르쪽v
newPStart = { y: roofLine.y1, x: roofLine.x1 } newPStart = { y: roofLine.y1, x: roofLine.x1 }
newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } 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 }, 'yellow')
}
}else if(wallBaseLine.x1 <= newPStart.x && newPStart.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPEnd.x) { //하단 오른쪽v }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 } newPStart = { y: roofLine.y1, x: (isCross) ? currentRoofLine.x1 : wallBaseLine.x1 }
@ -1150,11 +1106,6 @@ if(roof.moveUpDown??0 > 0) {
newPStart = { y: roofLine.y1, x: roofLine.x1 } newPStart = { y: roofLine.y1, x: roofLine.x1 }
newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } 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 }, 'yellow')
}
}else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= newPStart.x && newPStart.x <= wallBaseLine.x1){ //top center }else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= newPStart.x && newPStart.x <= wallBaseLine.x1){ //top center
newPStart = { y: roofLine.y1, x: roofLine.x1 } newPStart = { y: roofLine.y1, x: roofLine.x1 }
newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 } newPEnd = { y: roofLine.y2, x: (isCross) ? currentRoofLine.x2 : wallBaseLine.x2 }
@ -3909,51 +3860,35 @@ function updateAndAddLine(innerLines, targetPoint) {
line.y2 === foundLine.y2) line.y2 === foundLine.y2)
); );
// Calculate distances to both endpoints let isCurrentLine = false;
const distanceToStart = Math.hypot( if(foundLine.y1 <= targetPoint.y && targetPoint.y <= foundLine.y2){
targetPoint.x - foundLine.x1, isCurrentLine = true;
targetPoint.y - foundLine.y1 }
);
const distanceToEnd = Math.hypot(
targetPoint.x - foundLine.x2,
targetPoint.y - foundLine.y2
);
// Determine which endpoint is closer to the target point
const isUpdatingStart = distanceToStart < distanceToEnd;
const updatedLine = { const updatedLine = {
...foundLine, ...foundLine,
// 수정된 부분: left와 top을 시작점(x1, y1)으로 설정 left: (isCurrentLine)?targetPoint.x:foundLine.left,
left: isUpdatingStart ? foundLine.x1 : foundLine.x2, top: (isCurrentLine)?targetPoint.y:foundLine.top,
top: isUpdatingStart ? foundLine.y1 : foundLine.y2, x1: (isCurrentLine)?targetPoint.x:foundLine.x1,
// 나머지 속성들은 그대로 유지 y1: (isCurrentLine)?targetPoint.y:foundLine.y1,
x1: isUpdatingStart ? targetPoint.x : foundLine.x1, x2: (isCurrentLine)?foundLine.x2:targetPoint.x,
y1: isUpdatingStart ? targetPoint.y : foundLine.y1, y2: (isCurrentLine)?foundLine.y2:targetPoint.y,
x2: isUpdatingStart ? foundLine.x2 : targetPoint.x, startPoint: (isCurrentLine)?{ x: targetPoint.x, y: targetPoint.y }:foundLine.startPoint,
y2: isUpdatingStart ? foundLine.y2 : targetPoint.y, endPoint: (isCurrentLine)?foundLine.endPoint : { x: targetPoint.x, y: targetPoint.y}
startPoint: {
x: isUpdatingStart ? targetPoint.x : foundLine.x1,
y: isUpdatingStart ? targetPoint.y : foundLine.y1
},
endPoint: {
x: isUpdatingStart ? foundLine.x2 : targetPoint.x,
y: isUpdatingStart ? foundLine.y2 : targetPoint.y
}
}; };
// 4. If it's a Fabric.js object, use set method if available // 4. If it's a Fabric.js object, use set method if available
if (typeof foundLine.set === 'function') { if (typeof foundLine.set === 'function') {
foundLine.set({ foundLine.set({
x1: isUpdatingStart ? targetPoint.x : foundLine.x1, x1: (isCurrentLine)?targetPoint.x:foundLine.x1,
y1: isUpdatingStart ? targetPoint.y : foundLine.y1, y1: (isCurrentLine)?targetPoint.y:foundLine.y1,
x2: isUpdatingStart ? foundLine.x2 : targetPoint.x, x2: (isCurrentLine)?foundLine.x2:targetPoint.x,
y2: isUpdatingStart ? foundLine.y2 : targetPoint.y y2: (isCurrentLine)?foundLine.y2:targetPoint.y,
}); });
updatedLines.push(foundLine); updatedLines.push(foundLine);
} else { } else {
updatedLines.push(updatedLine); updatedLines.push(updatedLine);
} }
return updatedLines; return updatedLines;
} }