skeleton - 모든 선분과의 기하학적 교차점을 탐색하여 가장 가까운 유효한 점을 찾는2
This commit is contained in:
parent
c850dd3f13
commit
633f417548
@ -143,6 +143,11 @@ const createInnerLinesFromSkeleton = (skeleton, baseLines, roof, canvas, textMod
|
||||
}
|
||||
});
|
||||
|
||||
//2-1 확장된 스켈레톤 선이 연장되다가 서로 만나면 만난점(접점)에서 멈추어야 된다.
|
||||
trimIntersectingExtendedLines(skeletonLines, disconnectedLines);
|
||||
|
||||
|
||||
|
||||
// 3. 최종적으로 정리된 스켈레톤 선들을 QLine 객체로 변환하여 캔버스에 추가합니다.
|
||||
const innerLines = [];
|
||||
skeletonLines.forEach(line => {
|
||||
@ -553,6 +558,45 @@ export const findDisconnectedSkeletonLines = (skeletonLines, baseLines) => {
|
||||
return { disconnectedLines };
|
||||
};
|
||||
|
||||
/**
|
||||
* 연장된 스켈레톤 라인들이 서로 교차하는 경우, 교차점에서 잘라냅니다.
|
||||
* @param {Array} skeletonLines - (수정될) 전체 스켈레톤 라인 배열
|
||||
* @param {Array} disconnectedLines - 연장 정보가 담긴 배열
|
||||
*/
|
||||
const trimIntersectingExtendedLines = (skeletonLines, disconnectedLines) => {
|
||||
// disconnectedLines에는 연장된 선들의 정보가 들어있음
|
||||
for (let i = 0; i < disconnectedLines.length; i++) {
|
||||
for (let j = i + 1; j < disconnectedLines.length; j++) {
|
||||
const dLine1 = disconnectedLines[i];
|
||||
const dLine2 = disconnectedLines[j];
|
||||
|
||||
// 연장된 후의 선분 객체를 가져옴
|
||||
const line1 = skeletonLines[dLine1.index];
|
||||
const line2 = skeletonLines[dLine2.index];
|
||||
|
||||
if(!line1 || !line2) continue;
|
||||
|
||||
// 두 연장된 선분이 교차하는지 확인
|
||||
const intersection = getLineIntersection(line1.p1, line1.p2, line2.p1, line2.p2);
|
||||
|
||||
if (intersection) {
|
||||
// 교차점이 있다면, 각 선의 연장된 끝점을 교차점으로 업데이트
|
||||
if (!dLine1.p1Connected) { // p1이 연장된 점이었으면
|
||||
line1.p1 = intersection;
|
||||
} else { // p2가 연장된 점이었으면
|
||||
line1.p2 = intersection;
|
||||
}
|
||||
|
||||
if (!dLine2.p1Connected) { // p1이 연장된 점이었으면
|
||||
line2.p1 = intersection;
|
||||
} else { // p2가 연장된 점이었으면
|
||||
line2.p2 = intersection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* skeletonLines와 selectBaseLine을 이용하여 다각형이 되는 좌표를 구합니다.
|
||||
* selectBaseLine의 좌표는 제외합니다.
|
||||
@ -738,3 +782,4 @@ export {
|
||||
collectAllPoints,
|
||||
createPolygonsFromSkeletonLines
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user