out 완성

This commit is contained in:
ysCha 2025-12-02 18:37:03 +09:00
parent c650610d93
commit 61dc458250

View File

@ -773,56 +773,8 @@ 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'],
@ -839,7 +791,7 @@ if((roof.moveUpDown??0 > 0) ) {
'moveLine' : [moveLine.x2, moveLine.y2],
'wallBaseLine' : [wallBaseLine.x2, wallBaseLine.y2]
});
*/
const origin = moveLine.attributes?.originPoint
if (!origin) return
@ -896,10 +848,11 @@ if((roof.moveUpDown??0 > 0) ) {
const getInnerLines = (lines, point) => {
}
let isIn = false
let isOut = false
//두 포인트가 변경된 라인인
if (fullyMoved && (roof.moveDirect === 'in')) {
if (fullyMoved ) {
//반시계방향향
console.log("moveFully:::::::::::::", wallBaseLine, newPStart, newPEnd)
@ -915,6 +868,7 @@ 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 });
@ -939,16 +893,33 @@ if((roof.moveUpDown??0 > 0) ) {
}
} else if (getOrientation(roofLine) === 'horizontal') {
} else if (getOrientation(roofLine) === 'horizontal') { //red
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){
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 }, )
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 (wallBaseLine.x2 <= newPEnd.x && newPEnd.x <= wallBaseLine.x1 && wallBaseLine.x1 <= newPStart.x) { //top right
newPEnd.x = wallBaseLine.x2;
@ -995,7 +966,7 @@ if((roof.moveUpDown??0 > 0) ) {
getAddLine(newPStart, newPEnd, 'red')
} else if (movedStart && (roof.moveDirect === 'in')) { //end 변경경
} else if (movedStart ) { //end 변경경
if (getOrientation(roofLine) === 'vertical') { //green 수직
@ -1105,22 +1076,31 @@ if((roof.moveUpDown??0 > 0) ) {
//movedLines.push({ index, newPStart, newPEnd })
console.log("moveStart:::::::::::::", origin, newPStart, newPEnd)
} else if (movedEnd && (roof.moveDirect === 'in')) { //start변경
} else if (movedEnd ) { //start변경
//반시계방향 오렌지
if (getOrientation(roofLine) === 'vertical') {
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
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){//bottom leftv
newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
newPEnd = { x: roofLine.x2, y: roofLine.y2 }
if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 < wallBaseLine.y2 && wallBaseLine.y2 < newPEnd.y){//out top left
if(isIn) {
newPStart = { x: roofLine.x1, y: (isCross) ? currentRoofLine.y2 : wallBaseLine.y2 }
newPEnd = { x: roofLine.x2, y: roofLine.y2 }
}else if(isOut) {
newPStart = { x: roofLine.x1, y: roofLine.y1 }
newPEnd = { x: roofLine.x2, y: wallLine.y2 }
}
}else if(newPEnd.y <= wallBaseLine.y2 && wallBaseLine.y2 < wallBaseLine.y1 && wallBaseLine.y1 <= newPStart.y){ //top /right
@ -1133,14 +1113,20 @@ 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) {//top left / top / righty 오르쪽v
}else if(newPStart.y <= wallBaseLine.y1 && wallBaseLine.y1 <= newPEnd.y && newPEnd.y <= wallBaseLine.y2) {//in top left/
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')
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')
}
}
}else if(wallBaseLine.y1 <= newPStart.y && newPStart.y <= wallBaseLine.y2 && wallBaseLine.y2 <= newPEnd.y) { //하단 오른쪽v
@ -3968,16 +3954,15 @@ function updateAndAddLine(innerLines, targetPoint) {
targetPoint.x - foundLine.x2,
targetPoint.y - foundLine.y2
);
// Determine which endpoint is closer to the target point
const isUpdatingStart = distanceToStart < distanceToEnd;
// 단순 거리 비교: 타겟 포인트가 시작점에 더 가까우면 시작점을 수정(isUpdatingStart = true)
//무조건 start
const isUpdatingStart = true //distanceToStart < distanceToEnd;
const updatedLine = {
...foundLine,
// 수정된 부분: left와 top을 시작점(x1, y1)으로 설정
left: isUpdatingStart ? foundLine.x1 : foundLine.x2,
top: isUpdatingStart ? foundLine.y1 : foundLine.y2,
// 나머지 속성들은 그대로 유지
left: isUpdatingStart ? targetPoint.x : foundLine.x1,
top: isUpdatingStart ? targetPoint.y : foundLine.y1,
x1: isUpdatingStart ? targetPoint.x : foundLine.x1,
y1: isUpdatingStart ? targetPoint.y : foundLine.y1,
x2: isUpdatingStart ? foundLine.x2 : targetPoint.x,
@ -4008,6 +3993,7 @@ function updateAndAddLine(innerLines, targetPoint) {
return updatedLines;
}
/**
* A, B, C: 각각 QLine 1 (x1,y1,x2,y2 존재)
*
@ -4058,3 +4044,36 @@ 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 }
];
}