Compare commits
No commits in common. "ebfc7da6a3b8d0feae6191935302183d5ac4d4f4" and "273f62bd0c1c0d51d294c454da8d2c28ea2fcf95" have entirely different histories.
ebfc7da6a3
...
273f62bd0c
@ -875,9 +875,10 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
(mLine.position === 'right' && wallLine.x1 > wallBaseLine.x1)
|
||||
? 'in' : 'out';
|
||||
const condition = `${mLine.position}_${positionType}`;
|
||||
let isStartEnd = findInteriorPoint(wallBaseLine, wall.baseLines)
|
||||
let isStartEnd = findInteriorPoint(wallBaseLine, sortedWallBaseLines)
|
||||
let sPoint, ePoint;
|
||||
if(condition === 'left_in') {
|
||||
switch (condition) {
|
||||
case 'left_in':
|
||||
isIn = true
|
||||
|
||||
if (isStartEnd.start ) {
|
||||
@ -928,42 +929,29 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
}
|
||||
//getAddLine({ x: roofLine.x2, y: roofLine.y2 }, { x: newPointX, y: roofLine.y2 }, 'orange')
|
||||
}
|
||||
|
||||
}else if(condition === 'left_out') {
|
||||
console.log("left_out::::isStartEnd:::::", isStartEnd);
|
||||
break;
|
||||
case 'left_out':
|
||||
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 })
|
||||
|
||||
console.log("startLines:::::::", inLine);
|
||||
const eLineY = Big(bStartY).minus(wallLine.y1).abs().toNumber()
|
||||
newPEnd.y = aStartY
|
||||
newPStart.y = Big(roofLine.y2).minus(eLineY).toNumber()
|
||||
let idx = (0 >= index - 1)?roofLines.length:index
|
||||
const newLine = roofLines[idx-1];
|
||||
|
||||
if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) {
|
||||
if(inLine){
|
||||
getAddLine({ y: bStartY, x: wallLine.x2 }, { y: inLine.y2, x: inLine.x2 }, 'pink')
|
||||
}
|
||||
if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) {
|
||||
getAddLine({ y: bStartY, x: wallLine.x2 }, { y: roofLine.y1, x: wallLine.x1 }, 'magenta')
|
||||
getAddLine({ y: newLine.y1, x: newLine.x1 }, { y: newLine.y2, x: wallLine.x2 }, 'Gray')
|
||||
findPoints.push({ y: aStartY, x: newPEnd.x });
|
||||
}else{
|
||||
const cLineY = Big(wallBaseLine.y1).minus(wallLine.y1).abs().toNumber()
|
||||
newPEnd.y = Big(newPEnd.y).minus(cLineY).toNumber();
|
||||
const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x })
|
||||
if(inLine){
|
||||
getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple')
|
||||
}
|
||||
if(Math.abs(newPEnd.y - roofLine.y1) > 0.1) {
|
||||
//newPEnd.y = roofLine.y1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(isStartEnd.end){
|
||||
const moveDist = Big(wallLine.x1).minus(wallBaseLine.x1).abs().toNumber()
|
||||
@ -976,25 +964,19 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
newPStart.y = 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){
|
||||
getAddLine({ y: bStartY, x: wallLine.x1 }, { y: inLine.y2, x: inLine.x2 }, 'pink')
|
||||
}
|
||||
if(Math.abs(wallBaseLine.y2 - wallLine.y2) < 0.1) {
|
||||
getAddLine({ y: bStartY, x: wallLine.x1 }, { y: roofLine.y2, x: wallLine.x2 }, 'magenta')
|
||||
getAddLine({ y: newLine.y2, x: newLine.x2 }, { y: newLine.y1, x: wallLine.x1 }, 'Gray')
|
||||
findPoints.push({ y: aStartY, x: newPEnd.x });
|
||||
}else{
|
||||
const cLineY = Big(wallBaseLine.y2).minus(wallLine.y2).abs().toNumber()
|
||||
newPEnd.y = Big(newPEnd.y).plus(cLineY).toNumber();
|
||||
const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x })
|
||||
if(inLine){
|
||||
getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}else if(condition === 'right_in') {
|
||||
break;
|
||||
case 'right_in':
|
||||
|
||||
if (isStartEnd.start ) {
|
||||
|
||||
newPEnd.y = roofLine.y2;
|
||||
@ -1045,9 +1027,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
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
|
||||
|
||||
|
||||
break;
|
||||
case 'right_out':
|
||||
|
||||
|
||||
if (isStartEnd.start ) {
|
||||
const moveDist = Big(wallLine.x1).minus(wallBaseLine.x1).abs().toNumber()
|
||||
const aStartY = Big(roofLine.y1).plus(moveDist).toNumber()
|
||||
const bStartY = Big(wallLine.y1).plus(moveDist).toNumber()
|
||||
@ -1058,22 +1044,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
newPStart.y = 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){
|
||||
getAddLine({ y: bStartY, x: wallLine.x2 }, { y: inLine.y2, x: inLine.x2 }, 'pink')
|
||||
}
|
||||
if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) {
|
||||
getAddLine({ y: bStartY, x: wallLine.x2 }, { y: roofLine.y1, x: wallLine.x1 }, 'magenta')
|
||||
getAddLine({ y: newLine.y1, x: newLine.x1 }, { y: newLine.y2, x: wallLine.x2 }, 'Gray')
|
||||
findPoints.push({ y: aStartY, x: newPEnd.x });
|
||||
}else{
|
||||
const cLineY = Big(wallBaseLine.y1).minus(wallLine.y1).abs().toNumber()
|
||||
newPEnd.y = Big(newPEnd.y).plus(cLineY).toNumber();
|
||||
const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x })
|
||||
if(inLine){
|
||||
getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'pink')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1096,28 +1073,10 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
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 });
|
||||
}else{
|
||||
const cLineY = Big(wallBaseLine.y2).minus(wallLine.y2).abs().toNumber()
|
||||
newPEnd.y = Big(newPEnd.y).minus(cLineY).toNumber();
|
||||
const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x })
|
||||
if(inLine){
|
||||
getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'pink')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// switch (condition) {
|
||||
// case 'left_in':
|
||||
// break;
|
||||
// case 'left_out':
|
||||
// break;
|
||||
// case 'right_in':
|
||||
// break;
|
||||
// case 'right_out':
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -1133,11 +1092,16 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
? 'in' : 'out';
|
||||
|
||||
const condition = `${mLine.position}_${positionType}`;
|
||||
let isStartEnd = findInteriorPoint(wallBaseLine, wall.baseLines)
|
||||
let isStartEnd = findInteriorPoint(wallBaseLine, sortedWallBaseLines)
|
||||
|
||||
let sPoint, ePoint;
|
||||
|
||||
if(condition === 'top_in') {
|
||||
switch (condition) {
|
||||
case 'top_in':
|
||||
|
||||
console.log("findInteriorPoint result:::::::", isStartEnd);
|
||||
|
||||
|
||||
if (isStartEnd.start ) {
|
||||
const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber()
|
||||
sPoint = {x: wallBaseLine.x1, y: wallBaseLine.y1};
|
||||
@ -1181,35 +1145,27 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
//getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: roofLine.x1, y: newPointY }, 'orange')
|
||||
}
|
||||
|
||||
}else if(condition === 'top_out') {
|
||||
console.log("top_out isStartEnd:::::::", isStartEnd);
|
||||
break;
|
||||
case 'top_out':
|
||||
//console.log("findInteriorPoint result:::::::", 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 })
|
||||
|
||||
console.log("startLines:::::::", inLine);
|
||||
const eLineX = Big(bStartX).minus(wallLine.x1).abs().toNumber()
|
||||
newPEnd.x = Big(newPEnd.x).plus(eLineX).toNumber()
|
||||
newPStart.x = aStartX
|
||||
let idx = (0 > index - 1)?roofLines.length:index
|
||||
const newLine = roofLines[idx-1];
|
||||
|
||||
if(Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) {
|
||||
if(inLine){
|
||||
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink')
|
||||
}
|
||||
if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) {
|
||||
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }, 'magenta')
|
||||
getAddLine({ x: newLine.x1, y: newLine.y1 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
|
||||
findPoints.push({ x: aStartX, y: newPEnd.y });
|
||||
}else{
|
||||
const cLineX = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber()
|
||||
newPStart.x = Big(newPStart.x).plus(cLineX).toNumber();
|
||||
const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x })
|
||||
if(inLine){
|
||||
getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(isStartEnd.end){
|
||||
@ -1223,25 +1179,18 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
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){
|
||||
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink')
|
||||
}
|
||||
if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) {
|
||||
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x2, y: wallLine.y2 }, 'magenta')
|
||||
getAddLine({ x: newLine.x2, y: newLine.y2 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
|
||||
findPoints.push({ x: aStartX, y: newPEnd.y });
|
||||
}else{
|
||||
const cLineX = Big(wallLine.x2).minus(wallBaseLine.x2).abs().toNumber()
|
||||
newPEnd.x = Big(newPEnd.x).minus(cLineX).toNumber();
|
||||
const inLine = findLineContainingPoint(innerLines, { y: newPEnd.y, x: newPEnd.x })
|
||||
if(inLine){
|
||||
getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple')
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'bottom_in':
|
||||
|
||||
}
|
||||
}
|
||||
}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};
|
||||
@ -1286,8 +1235,10 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
getAddLine({ x: roofLine.x1, y: roofLine.y1 }, { x: roofLine.x1, y: newPointY }, 'orange')
|
||||
|
||||
}
|
||||
}else if(condition === 'bottom_out') {
|
||||
console.log("bottom_out isStartEnd:::::::", isStartEnd);
|
||||
|
||||
break;
|
||||
case 'bottom_out':
|
||||
|
||||
if (isStartEnd.start ) {
|
||||
const moveDist = Big(wallLine.y1).minus(wallBaseLine.y1).abs().toNumber()
|
||||
const aStartX = Big(roofLine.x1).minus(moveDist).abs().toNumber()
|
||||
@ -1300,22 +1251,13 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
let idx = (0 > index - 1)?roofLines.length:index
|
||||
const newLine = roofLines[idx-1];
|
||||
|
||||
|
||||
if(Math.abs(wallBaseLine.x1 - wallLine.x1) < 0.1) {
|
||||
if(inLine){
|
||||
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink')
|
||||
}
|
||||
if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) {
|
||||
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x1, y: wallLine.y1 }, 'magenta')
|
||||
getAddLine({ x: newLine.x1, y: newLine.y1 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
|
||||
findPoints.push({ x: aStartX, y: newPEnd.y });
|
||||
}else{
|
||||
const cLineX = Big(wallBaseLine.x1).minus(wallLine.x1).abs().toNumber()
|
||||
newPStart.x = Big(newPStart.x).minus(cLineX).toNumber();
|
||||
const inLine = findLineContainingPoint(innerLines, { y: newPStart.y, x: newPStart.x })
|
||||
if(inLine){
|
||||
getAddLine({ y: newPStart.y, x: newPStart.x }, { y: inLine.y2, x: inLine.x2 }, 'purple')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1330,38 +1272,17 @@ const createInnerLinesFromSkeleton = (roofId, canvas, skeleton, textMode) => {
|
||||
newPStart.x = Big(roofLine.x1).plus(eLineX).toNumber()
|
||||
let idx = (0 > index - 1)?roofLines.length:index
|
||||
const newLine = roofLines[idx-1];
|
||||
|
||||
if(Math.abs(wallBaseLine.x2 - wallLine.x2) < 0.1) {
|
||||
if(inLine){
|
||||
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: inLine.x2, y: inLine.y2 }, 'pink')
|
||||
}
|
||||
if(Math.abs(wallBaseLine.y1 - wallLine.y1) < 0.1) {
|
||||
getAddLine({ x: bStartX, y: wallLine.y1 }, { x: roofLine.x2, y: wallLine.y2 }, 'magenta')
|
||||
getAddLine({ x: newLine.x2, y: newLine.y2 }, { x: newLine.x1, y: wallLine.y1 }, 'Gray')
|
||||
findPoints.push({ x: aStartX, y: newPEnd.y });
|
||||
}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){
|
||||
getAddLine({ y: newPEnd.y, x: newPEnd.x }, { y: inLine.y2, x: inLine.x2 }, 'purple')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// switch (condition) {
|
||||
// case 'top_in':
|
||||
// //console.log("findInteriorPoint result:::::::", isStartEnd);
|
||||
// break;
|
||||
// case 'top_out':
|
||||
// //console.log("findInteriorPoint result:::::::", isStartEnd);
|
||||
// break;
|
||||
// case 'bottom_in':
|
||||
// break;
|
||||
// case 'bottom_out':
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
getAddLine(newPStart, newPEnd, 'red')
|
||||
@ -2096,7 +2017,6 @@ export {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Finds the opposite line in a polygon based on the given line
|
||||
* @param {Array} edges - The polygon edges from canvas.skeleton.Edges
|
||||
@ -2347,6 +2267,7 @@ function clipLineToRoofBoundary(p1, p2, roofLines, selectLine) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
function isPointInsidePolygon(point, roofLines) {
|
||||
// 1. 먼저 경계선 위에 있는지 확인 (방향 무관)
|
||||
if (isOnBoundaryDirectionIndependent(point, roofLines)) {
|
||||
@ -2467,39 +2388,6 @@ function getLineDirection(p1, p2) {
|
||||
|
||||
|
||||
|
||||
|
||||
// selectLine과 baseLines 비교하여 방향 찾기
|
||||
function findLineDirection(selectLine, baseLines) {
|
||||
for (const baseLine of baseLines) {
|
||||
// baseLine의 시작점과 끝점
|
||||
const baseStart = baseLine.startPoint;
|
||||
const baseEnd = baseLine.endPoint;
|
||||
|
||||
// selectLine의 시작점과 끝점
|
||||
const selectStart = selectLine.startPoint;
|
||||
const selectEnd = selectLine.endPoint;
|
||||
|
||||
// 정방향 또는 역방향으로 일치하는지 확인
|
||||
if ((isSamePoint(baseStart, selectStart) && isSamePoint(baseEnd, selectEnd)) ||
|
||||
(isSamePoint(baseStart, selectEnd) && isSamePoint(baseEnd, selectStart))) {
|
||||
|
||||
// baseLine의 방향 계산
|
||||
const dx = baseEnd.x - baseStart.x;
|
||||
const dy = baseEnd.y - baseStart.y;
|
||||
|
||||
// 기울기를 바탕으로 방향 판단
|
||||
if (Math.abs(dx) > Math.abs(dy)) {
|
||||
return dx > 0 ? 'right' : 'left';
|
||||
} else {
|
||||
return dy > 0 ? 'down' : 'up';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null; // 일치하는 라인이 없는 경우
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* baseLines를 연결하여 다각형 순서로 정렬된 점들 반환
|
||||
* @param {Array} baseLines - 라인 배열
|
||||
@ -2821,54 +2709,89 @@ const analyzeLineOrientation = (x1, y1, x2, y2, epsilon = 0.5) => {
|
||||
};
|
||||
};
|
||||
|
||||
function extendLineToBoundary(p1, p2, roofLines) {
|
||||
// 1. Calculate line direction and length
|
||||
const dx = p2.x - p1.x;
|
||||
const dy = p2.y - p1.y;
|
||||
const length = Math.sqrt(dx * dx + dy * dy);
|
||||
if (length === 0) return { p1: { ...p1 }, p2: { ...p2 } };
|
||||
|
||||
// 점에서 선분까지의 최단 거리를 계산하는 도우미 함수
|
||||
function pointToLineDistance(point, lineP1, lineP2) {
|
||||
const A = point.x - lineP1.x;
|
||||
const B = point.y - lineP1.y;
|
||||
const C = lineP2.x - lineP1.x;
|
||||
const D = lineP2.y - lineP1.y;
|
||||
// 2. Get all polygon points
|
||||
const points = [];
|
||||
const seen = new Set();
|
||||
|
||||
const dot = A * C + B * D;
|
||||
const lenSq = C * C + D * D;
|
||||
let param = -1;
|
||||
for (const line of roofLines) {
|
||||
const p1 = { x: line.x1, y: line.y1 };
|
||||
const p2 = { x: line.x2, y: line.y2 };
|
||||
|
||||
if (lenSq !== 0) {
|
||||
param = dot / lenSq;
|
||||
const key1 = `${p1.x},${p1.y}`;
|
||||
const key2 = `${p2.x},${p2.y}`;
|
||||
|
||||
if (!seen.has(key1)) {
|
||||
points.push(p1);
|
||||
seen.add(key1);
|
||||
}
|
||||
if (!seen.has(key2)) {
|
||||
points.push(p2);
|
||||
seen.add(key2);
|
||||
}
|
||||
}
|
||||
|
||||
let xx, yy;
|
||||
// 3. Find the bounding box
|
||||
let minX = Infinity, minY = Infinity;
|
||||
let maxX = -Infinity, maxY = -Infinity;
|
||||
|
||||
if (param < 0) {
|
||||
xx = lineP1.x;
|
||||
yy = lineP1.y;
|
||||
} else if (param > 1) {
|
||||
xx = lineP2.x;
|
||||
yy = lineP2.y;
|
||||
} else {
|
||||
xx = lineP1.x + param * C;
|
||||
yy = lineP1.y + param * D;
|
||||
for (const p of points) {
|
||||
minX = Math.min(minX, p.x);
|
||||
minY = Math.min(minY, p.y);
|
||||
maxX = Math.max(maxX, p.x);
|
||||
maxY = Math.max(maxY, p.y);
|
||||
}
|
||||
|
||||
const dx = point.x - xx;
|
||||
const dy = point.y - yy;
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
// 4. Extend line to bounding box
|
||||
const bboxLines = [
|
||||
{ x1: minX, y1: minY, x2: maxX, y2: minY }, // top
|
||||
{ x1: maxX, y1: minY, x2: maxX, y2: maxY }, // right
|
||||
{ x1: maxX, y1: maxY, x2: minX, y2: maxY }, // bottom
|
||||
{ x1: minX, y1: maxY, x2: minX, y2: minY } // left
|
||||
];
|
||||
|
||||
const intersections = [];
|
||||
|
||||
// 5. Find intersections with bounding box
|
||||
for (const line of bboxLines) {
|
||||
const intersect = getLineIntersection(
|
||||
p1, p2,
|
||||
{ x: line.x1, y: line.y1 },
|
||||
{ x: line.x2, y: line.y2 }
|
||||
);
|
||||
|
||||
if (intersect) {
|
||||
const t = ((intersect.x - p1.x) * dx + (intersect.y - p1.y) * dy) / (length * length);
|
||||
if (t >= 0 && t <= 1) {
|
||||
intersections.push({ x: intersect.x, y: intersect.y, t });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 6. If we have two intersections, use them
|
||||
if (intersections.length >= 2) {
|
||||
// Sort by t value
|
||||
intersections.sort((a, b) => a.t - b.t);
|
||||
return {
|
||||
p1: { x: intersections[0].x, y: intersections[0].y },
|
||||
p2: {
|
||||
x: intersections[intersections.length - 1].x,
|
||||
y: intersections[intersections.length - 1].y
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 7. Fallback to original points
|
||||
return { p1: { ...p1 }, p2: { ...p2 } };
|
||||
}
|
||||
|
||||
|
||||
const getOrientation = (line, eps = 0.1) => {
|
||||
const x1 = line.get('x1')
|
||||
const y1 = line.get('y1')
|
||||
const x2 = line.get('x2')
|
||||
const y2 = line.get('y2')
|
||||
const dx = Math.abs(x2 - x1)
|
||||
const dy = Math.abs(y2 - y1)
|
||||
|
||||
if (dx < eps && dy >= eps) return 'vertical'
|
||||
if (dy < eps && dx >= eps) return 'horizontal'
|
||||
if (dx < eps && dy < eps) return 'point'
|
||||
return 'diagonal'
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3052,35 +2975,9 @@ function updateAndAddLine(innerLines, targetPoint) {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 점이 선분 위에 있는지 확인
|
||||
* @param {Object} point - 확인할 점 {x, y}
|
||||
* @param {Object} lineStart - 선분의 시작점 {x, y}
|
||||
* @param {Object} lineEnd - 선분의 끝점 {x, y}
|
||||
* @param {number} tolerance - 오차 허용 범위
|
||||
* @returns {boolean} - 점이 선분 위에 있으면 true, 아니면 false
|
||||
*/
|
||||
function isPointOnLineSegment2(point, lineStart, lineEnd, tolerance = 0.1) {
|
||||
const { x: px, y: py } = point;
|
||||
const { x: x1, y: y1 } = lineStart;
|
||||
const { x: x2, y: y2 } = lineEnd;
|
||||
|
||||
// 선분의 길이
|
||||
const lineLength = Math.hypot(x2 - x1, y2 - y1);
|
||||
|
||||
// 점에서 선분의 양 끝점까지의 거리
|
||||
const dist1 = Math.hypot(px - x1, py - y1);
|
||||
const dist2 = Math.hypot(px - x2, py - y2);
|
||||
|
||||
// 점이 선분 위에 있는지 확인 (오차 허용 범위 내에서)
|
||||
const isOnSegment = Math.abs((dist1 + dist2) - lineLength) <= tolerance;
|
||||
|
||||
if (isOnSegment) {
|
||||
console.log(`점 (${px}, ${py})은 선분 [(${x1}, ${y1}), (${x2}, ${y2})] 위에 있습니다.`);
|
||||
}
|
||||
|
||||
return isOnSegment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 세 점(p1 -> p2 -> p3)의 방향성을 계산합니다. (2D 외적)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user