diff --git a/D03_PlanAnalysis/logic/D03_PlanAnalysis_Select.ts b/D03_PlanAnalysis/logic/D03_PlanAnalysis_Select.ts index bea304984..ba25df693 100644 --- a/D03_PlanAnalysis/logic/D03_PlanAnalysis_Select.ts +++ b/D03_PlanAnalysis/logic/D03_PlanAnalysis_Select.ts @@ -134,15 +134,13 @@ function nextPieceId(pieces: ReadonlyArray): string { return `p${Math.max(0, ...used) + 1}`; } -/** 꼭짓점 [a, b) 만 남긴 선 — 꼭짓점과 같은 길이 덧 칸(노드 기록 594-1)도 같이 자름 · 첫 기록 = 없음. */ +/** 꼭짓점 [a, b) 만 남긴 선 — 노드 기록(594-1)도 같이 자름 · 뒤쪽 첫 기록 = 없음(앞 노드가 사라짐). */ function cutVertices(entry: PlanLine, a: number, b: number): PlanLine { - const out: PlanLine & { nodes?: unknown[] } = { ...entry, vertices: entry.vertices.slice(a, b) }; - const nodes = (entry as { nodes?: unknown }).nodes; - if (Array.isArray(nodes) && nodes.length === entry.vertices.length) { - out.nodes = nodes.slice(a, b); - if (a > 0 && out.nodes.length) out.nodes[0] = null; - } - return out; + const vertices = entry.vertices.slice(a, b); + if (!entry.nodes) return { ...entry, vertices }; + const nodes = entry.nodes.slice(a, b); + if (a > 0 && nodes.length) nodes[0] = null; + return { ...entry, vertices, nodes }; } /** 토막 하나 지움 — 하나뿐 = 구역 지움 · 끝 토막 = 끝 점 뺌 · 가운데 = 구역 둘(뒤쪽 = 새 구역 · 갈래 아님) · diff --git a/resources/tester/test_598_1_plan_select_layers.py b/resources/tester/test_598_1_plan_select_layers.py index 3643d0aca..0ae23beea 100644 --- a/resources/tester/test_598_1_plan_select_layers.py +++ b/resources/tester/test_598_1_plan_select_layers.py @@ -52,6 +52,12 @@ writeFileSync(process.argv[2], JSON.stringify({ all: show(sel.removeAll(n)), nodes: sel.nodesAt(n, [200, 0]), moved: sel.movePointsAt([[200, 0], [5, 5]], [200, 0], [210, 5]), + nodes594: (() => { + const r = { kind: "length", length_m: 100, slope_pct: null }; + const withNodes = { ...n, lines: n.lines.map((l, i) => (i ? l : { ...l, nodes: [null, r, r, r] })) }; + const out = sel.removeSegment(withNodes, seg("main", 1)); + return out.lines.filter((l) => l.id !== "branch-1").map((l) => [l.id, l.nodes]); + })(), })); """ @@ -127,3 +133,8 @@ def test_끌어_고르기_전체_지점_노드(tmp_path: Path) -> None: assert got["all"] == {"lines": [], "pieces": []} assert got["nodes"] == [{"line": "main", "vertex": 2}] # 갈래 첫 점 뺌 assert got["moved"] == [[210, 5], [5, 5]] + rec = {"kind": "length", "length_m": 100, "slope_pct": None} + assert got["nodes594"] == [ + ["main", [None, rec]], + ["line-2", [None, rec]], + ] # 노드 기록 같이 · 뒤쪽 첫 = 없음