feat(774-2): B05 예정노선 = 늘 노선 하나 — 끊긴 토막은 끝끼리만 붙고 맞닿으면 한 줄
- 한 선 페이지(기능 표 branch 숨김) 긋기 붙을 자리 = 다른 토막 끝만(가운데 노드 · 선 위 = 안 붙음 → 갈래 안 생김) - 긋기 마침 = 맞닿은 토막 모두 이음(joinTouching · 꼬리↔머리 · 꼬리↔꼬리 · 머리↔머리) · D03 = 지금대로 - 끊긴 채 수정 끝냄 = 기존 막음 · 안내 그대로 - 시험: test_771_2 에 joinTouching 대조 더함 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/* =============================================================================
|
||||
* D03_PlanAnalysis_OneLine.ts
|
||||
* 한 선 페이지(B05 · 기능 표 「branch」 숨김) 예정노선 = 늘 노선 하나(PLAN 774-2 · 요구 618).
|
||||
* `joinTouching` = 끝이 맞닿은 토막을 한 선으로 이음(꼬리 ↔ 머리 · 꼬리 ↔ 꼬리 · 머리 ↔ 머리 = 뒤집어 맞춤) ·
|
||||
* 갈래 · 점 하나 선은 안 건드림 · 남는 id = 앞 토막(`attachHead` 규칙). 노선 여럿 = D 그룹(D03)만.
|
||||
* DOM · fetch · sessionStorage 없음.
|
||||
* ========================================================================== */
|
||||
|
||||
import { attachHead, reverseLine, samePoint, type PlanNetwork } from "./D03_PlanAnalysis_Plan";
|
||||
|
||||
/** 끝이 맞닿은 토막을 모두 이어 한 선으로 — 못 이을 것만 남김. */
|
||||
export function joinTouching(network: PlanNetwork): PlanNetwork {
|
||||
let next = network;
|
||||
for (let again = true; again;) {
|
||||
again = false;
|
||||
const ends = next.lines.map((line) =>
|
||||
line.vertices.length > 1 && !line.branch ? [line.vertices[0], line.vertices.at(-1)!] : null,
|
||||
);
|
||||
for (let i = 0; i < ends.length && !again; i += 1)
|
||||
for (let j = 0; j < ends.length && !again; j += 1) {
|
||||
const [a, b] = [ends[i], ends[j]];
|
||||
if (i === j || !a || !b) continue;
|
||||
// j 머리가 i 꼬리에 오게 맞춤
|
||||
const turned = samePoint(a[1], b[0])
|
||||
? next
|
||||
: samePoint(a[1], b[1])
|
||||
? reverseLine(next, j)
|
||||
: samePoint(a[0], b[0])
|
||||
? reverseLine(next, i)
|
||||
: null;
|
||||
if (!turned || typeof turned === "string") continue;
|
||||
const joined = attachHead(turned, j);
|
||||
if (joined !== turned) [next, again] = [joined, true];
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
Reference in New Issue
Block a user