refactor(D 예정노선): 갈래 시점 지정 branchFromEnd 걷음 — 단추 걷음(598-3) 뒤 · 닿음 = 긋기 끝에서 저절로 갈래 (PLAN 599 · 요구 463-15)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 15:31:15 +09:00
co-authored by Claude Opus 5.5
parent ef99ba6806
commit bb791d3c67
@@ -2,7 +2,7 @@
* D03_PlanAnalysis_Plan.ts
* D 예정노선 2단계 손 긋기 꼴(PLAN 562-3 · 580) — 그은 선 · 갈래 · 조각(구역 × 연도) 다루기 ·
* 선 뒤집기 · 잇기 · 꺾임점 옮김 · 지움 · 선 지움 · 선 통째 연도 · 마크 옮김 · 여러 조각 연도 · 끌어 고르기 판정(585-2) ·
* 갈래 시점 지정 · 갈래 처음 해 = 붙은 자리 구간 해(585-3) · 선 이름 · 노드 기록 꼴 · 이름 검사(594-1) ·
* 갈래 처음 해 = 붙은 자리 구간 해(585-3) · 선 이름 · 노드 기록 꼴 · 이름 검사(594-1) ·
* 노드 기록이 꼭짓점과 같이 움직임(599-2 · 기록 만들기 · 어긋남 = `D03_PlanAnalysis_Span`).
* DOM · fetch · sessionStorage 없음 · 길이 셈 = 562-1 짝(`D03_PlanAnalysis_Draw`).
* [저장] 은 서버가 선 · 조각으로 연도 행을 다시 셈(562-2) — 여기 값을 받아 적지 않음.
@@ -659,27 +659,3 @@ export function piecesInBox(
})
.map((piece) => piece.id);
}
/** 갈래 시점 지정(585-3) — 본선 한 끝이 다른 선 꺾임점에 닿았으면 그 점을 시점(No.0)으로 그 선의 갈래로 ·
* 머리가 다른 선 꼬리면 한 선으로 이음(연속 구간 = 측점 차례). 닿은 끝 없음 · 이미 갈래 = 까닭 글. */
export function branchFromEnd(network: PlanNetwork, line: number): PlanNetwork | string {
const entry = network.lines[line];
if (!entry || entry.vertices.length < 2) return "선을 고르세요.";
if (entry.branch) return "이미 갈래입니다 — 갈라지는 점이 시점입니다.";
const own = family(network, entry.id);
const touches = (point: Vertex): boolean =>
network.lines.some(
(other) => !own.has(other.id) && other.vertices.some((v) => samePoint(v, point)),
);
if (touches(entry.vertices[0])) {
const next = attachHead(network, line);
if (next !== network) return next;
}
if (!touches(entry.vertices[entry.vertices.length - 1]))
return "다른 선에 닿은 끝이 없습니다 — 끝을 다른 선 위에 놓고 지정하세요.";
const turned = reverseLine(network, line);
if (typeof turned === "string") return turned;
const index = turned.lines.findIndex((other) => other.id === entry.id);
const next = attachHead(turned, index);
return next === turned ? "다른 선에 닿은 끝이 없습니다." : next;
}