Compare commits

..

No commits in common. "61dc458250bb725eff40949e6407c01f99993ad8" and "4dafcc0274654a7baff37ac755c4d6d0ac5ece0d" have entirely different histories.

View File

@ -632,7 +632,7 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
canvas.renderAll();
});
if((roof.moveUpDown??0 > 0) ) {
if(roof.moveUpDown??0 > 0) {
// 같은 라인이 없으므로 새 다각형 라인 생성
//라인 편집
@ -773,8 +773,56 @@ if((roof.moveUpDown??0 > 0) ) {
// Check if wallBaseLine is inside the polygon formed by sortedWallLines
const isWallBaseLineInside = (() => {
if (!wallBaseLine || sortedWallLines.length < 3) return false;
// Get both endpoints of the wall base line
const p1 = { x: wallBaseLine.x1, y: wallBaseLine.y1 };
const p2 = { x: wallBaseLine.x2, y: wallBaseLine.y2 };
const midPoint = {
x: (p1.x + p2.x) / 2,
y: (p1.y + p2.y) / 2
};
// Create polygon points from wall lines
const polygonPoints = sortedWallLines.map(line => ({x: line.x1, y: line.y1}));
console.log('Polygon points:', polygonPoints);
// Close the polygon if needed
if (polygonPoints.length > 0) {
const first = polygonPoints[0];
const last = polygonPoints[polygonPoints.length - 1];
if (first.x !== last.x || first.y !== last.y) {
polygonPoints.push({...first});
}
}
// Check both endpoints and midpoint to be more accurate
const p1Inside = isPointInsidePolygon(p1, polygonPoints);
const p2Inside = isPointInsidePolygon(p2, polygonPoints);
const midPointInside = isPointInsidePolygon(midPoint, polygonPoints);
// If any of the points are inside, consider the line as inside
return p1Inside || p2Inside || midPointInside;
})();
// Debug information
console.log(`Wall base line at index ${index}:`,
JSON.parse(JSON.stringify({
p1: {x: wallBaseLine.x1, y: wallBaseLine.y1},
p2: {x: wallBaseLine.x2, y: wallBaseLine.y2},
isWallBaseLineInside
}))
);
if (isWallBaseLineInside) {
console.log(`Wall base line at index ${index} is INSIDE the polygon`);
// Your logic for inside case
} else {
console.log(`Wall base line at index ${index} is OUTSIDE the polygon`);
// Your logic for outside case
}
/*
console.log('=== Line Coordinates ===');
console.table({
'Point' : ['X', 'Y'],
@ -791,7 +839,7 @@ if((roof.moveUpDown??0 > 0) ) {
'moveLine' : [moveLine.x2, moveLine.y2],
'wallBaseLine' : [wallBaseLine.x2, wallBaseLine.y2]
});
*/
const origin = moveLine.attributes?.originPoint
if (!origin) return
@ -848,8 +896,7 @@ if((roof.moveUpDown??0 > 0) ) {
const getInnerLines = (lines, point) => {
}
let isIn = false
let isOut = false
//두 포인트가 변경된 라인인
if (fullyMoved) {
@ -868,7 +915,6 @@ if((roof.moveUpDown??0 > 0) ) {
findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 });
} else if (newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) { //top left
newPEnd.y = wallBaseLine.y2;
getAddLine({ x: newPEnd.x, y: wallBaseLine.y2 }, { x: wallBaseLine.x2, y: wallBaseLine.y2 })
findPoints.push({ x: wallBaseLine.x2, y: wallBaseLine.y2 });
@ -893,34 +939,17 @@ if((roof.moveUpDown??0 > 0) ) {
}
} else if (getOrientation(roofLine) === 'horizontal') { //red
} else if (getOrientation(roofLine) === 'horizontal') {
if(wallLine.y1 < wallBaseLine.y1 ) isIn = true
if(wallBaseLine.y1 < wallLine.y1 ) isOut = true
if (newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPStart.x && newPStart.x <= wallBaseLine.x1) { //in top left //out top left
if(isIn){
if (newPEnd.x <= wallBaseLine.x2 && wallBaseLine.x2 <= newPStart.x && newPStart.x <= wallBaseLine.x1) { //top left
newPStart.x = wallBaseLine.x1;
//추가 수직
getAddLine({ x: wallBaseLine.x1, y: newPEnd.y }, { x: wallBaseLine.x1, y: wallBaseLine.y1 }, )
//추가 라인?
findPoints.push({ x: wallBaseLine.x1, y: wallBaseLine.y1 });
}else if(isOut) {
const moveX = Math.abs(wallLine.y1 - wallBaseLine.y1)
const dist = Math.abs(roofLine.y1 - wallLine.y1)
newPStart.x += moveX
wallLine.x1 += moveX
findPoints.push({ x: newPStart.x , y: newPEnd.y});
getAddLine({ x: wallLine.x1, y: wallLine.y2 }, { x: roofLine.x1, y: wallLine.y2 }, )
}
} else if (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x) { //top right
newPEnd.x = wallBaseLine.x2;
//추가 수직
@ -1081,26 +1110,17 @@ if((roof.moveUpDown??0 > 0) ) {
//반시계방향 오렌지
if (getOrientation(roofLine) === 'vertical') { //수직 오렌지
if(wallLine.y1 <= wallBaseLine.y1 && wallLine.y2 <= wallBaseLine.y2) isIn = true
if(wallLine.y1 <= wallBaseLine.y1 && wallBaseLine.y2 <= wallBaseLine.y2 ) isOut = true
if (getOrientation(roofLine) === 'vertical') {
let isCross = false
if (Math.abs(currentRoofLine.x2 - roofLine.x1) < 0.1 || Math.abs(currentRoofLine.x1 - roofLine.x2) < 0.1) {
isCross = true;
}
if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 < wallBaseLine.y2 && wallBaseLine.y2 < newPEnd.y){//out top left
if(isIn) {
if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 < wallBaseLine.y2 && wallBaseLine.y2 < newPEnd.y){//bottom leftv
newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
newPEnd = { x: roofLine.x2, y: roofLine.y2 }
}else if(isOut) {
newPStart = { x: roofLine.x1, y: roofLine.y1 }
newPEnd = { x: roofLine.x2, y: wallLine.y2 }
}
}else if(newPEnd.y <= wallBaseLine.y2 && wallBaseLine.y2 < wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y){ //top /right
@ -1113,20 +1133,14 @@ if((roof.moveUpDown??0 > 0) ) {
newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
newPEnd ={ x: roofLine.x2, y: roofLine.y2 }
}else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//in top left/
}else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//top left / top / righty 오르쪽v
if(isIn) {
newPStart = { x: roofLine.x1, y: roofLine.y1 }
newPEnd = { x: roofLine.x2, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
//대각선 라인을 보조라인으로 그린다.
if(isCross){
getAddLine({ x: roofLine.x2, y: currentRoofLine.y2 }, {
x: wallBaseLine.x2,
y: wallBaseLine.y2
}, 'yellow')
}
getAddLine({ x: roofLine.x2, y: currentRoofLine.y2 }, { x: wallBaseLine.x2, y: wallBaseLine.y2 }, 'yellow')
}
}else if(wallBaseLine.y1 <= newPStart.y && newPStart.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPEnd.y) { //하단 오른쪽v
@ -1219,8 +1233,10 @@ if((roof.moveUpDown??0 > 0) ) {
// console.log("updateLines:::::", updateLines)
}
// --- 사용 예시 ---
// const polygons = findConnectedLines(movedLines, innerLines, canvas, roofId, roof);
// console.log("polygon", polygons);
// canvas.renderAll
if (findPoints.length > 0) {
// 모든 점에 대해 라인 업데이트를 누적
return findPoints.reduce((lines, point) => {
@ -3955,14 +3971,15 @@ function updateAndAddLine(innerLines, targetPoint) {
targetPoint.y - foundLine.y2
);
// 단순 거리 비교: 타겟 포인트가 시작점에 더 가까우면 시작점을 수정(isUpdatingStart = true)
//무조건 start
const isUpdatingStart = true //distanceToStart < distanceToEnd;
// Determine which endpoint is closer to the target point
const isUpdatingStart = distanceToStart < distanceToEnd;
const updatedLine = {
...foundLine,
left: isUpdatingStart ? targetPoint.x : foundLine.x1,
top: isUpdatingStart ? targetPoint.y : foundLine.y1,
// 수정된 부분: left와 top을 시작점(x1, y1)으로 설정
left: isUpdatingStart ? foundLine.x1 : foundLine.x2,
top: isUpdatingStart ? foundLine.y1 : foundLine.y2,
// 나머지 속성들은 그대로 유지
x1: isUpdatingStart ? targetPoint.x : foundLine.x1,
y1: isUpdatingStart ? targetPoint.y : foundLine.y1,
x2: isUpdatingStart ? foundLine.x2 : targetPoint.x,
@ -3993,7 +4010,6 @@ function updateAndAddLine(innerLines, targetPoint) {
return updatedLines;
}
/**
* A, B, C: 각각 QLine 1 (x1,y1,x2,y2 존재)
*
@ -4044,36 +4060,3 @@ function classifyLineABC(A, B, C) {
// 3) 나머지 -> out
return 'out';
}
function PointBasedOnBaseLength(x1, y1, x2, y2) {
// 밑변 중점 좌표 계산
const midX = (x1 + x2) / 2;
const midY = (y1 + y2) / 2;
// 밑변 길이 계산
const baseLength = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
// 밑변 벡터
const vecX = x2 - x1;
const vecY = y2 - y1;
// 벡터 길이 (밑변 길이)
const length = baseLength;
// 수직 방향 단위 벡터 계산 (벡터를 90도 회전)
const perpX = -vecY / length;
const perpY = vecX / length;
// 높이를 밑변 길이로 가정하여 나머지 꼭짓점 좌표 계산 (중점에서 수직 방향으로 이동)
const thirdX1 = midX + perpX * baseLength;
const thirdY1 = midY + perpY * baseLength;
const thirdX2 = midX - perpX * baseLength;
const thirdY2 = midY - perpY * baseLength;
// 두 가지 가능한 좌표 반환 (높이 방향 선택 가능하도록)
return [
{ x: thirdX1, y: thirdY1 },
{ x: thirdX2, y: thirdY2 }
];
}