"""곡선·직선을 지우고 더하고 반지름을 바꾸는 편집이 그대로 서는지. 사용자 지시(2026-09-07) — 「r과 직선 삭제나 추가가 있어야 하지 않을까?」 편집은 **꺾임점 목록 + 자리마다 곡선 켬끔 + 반지름**으로 표현한다: · 직선 삭제·추가 = 목록에서 점을 빼거나 더하기 · 곡선 삭제·추가 = `curve_flags` 를 끄고 켜기 · 반지름 변경 = `radii` 로 못박기 """ import math from common_util.common_util_route_polyline import build_planned_polyline MIN_RADIUS = 12.0 # 두 번 꺾이는 노선 — 꺾임점 두 개(색인 1·2). NODES = [(0.0, 0.0), (100.0, 0.0), (100.0, 100.0), (200.0, 100.0)] def _build(**kwargs): return build_planned_polyline(NODES, min_radius_m=MIN_RADIUS, simplify=False, **kwargs) def test_기본은_꺾임점마다_곡선(): result = _build() assert result.curve_count == 2 assert [c.node_first for c in result.curves] == [1, 2] def test_곡선_삭제(): """가운데 곡선을 끄면 그 자리는 직선이 그대로 꺾인다.""" result = _build(curve_flags=[True, False, True, True]) assert result.curve_count == 1 assert [c.node_first for c in result.curves] == [2] # 곡선을 지운 자리의 꺾임점은 선 위에 **그대로 남는다**. assert any(abs(v[0] - 100.0) < 1e-9 and abs(v[1]) < 1e-9 for v in result.vertices) def test_곡선_추가(): """껐다 켜면 곡선이 돌아온다 — 껐을 때와 켰을 때가 서로 다르다.""" off = _build(curve_flags=[True, False, True, True]) on = _build(curve_flags=[True, True, True, True]) assert on.curve_count == off.curve_count + 1 assert on.vertices != off.vertices def test_반지름_변경은_못박힌다(): result = _build(radii=[None, 30.0, None, None]) first = next(c for c in result.curves if c.node_first == 1) assert math.isclose(first.radius_m, 30.0, rel_tol=1e-9) # 접선 길이도 그 반지름을 따른다 — 직각이라 T = R. assert math.isclose(first.tangent_m, 30.0, rel_tol=1e-6) def test_반지름을_바꿔도_교각점은_안_움직인다(): """「곡선 반지름 변경 시 주변 직선 각도 구속」 — 직선이 고정이라 접선점만 미끄러진다.""" small = _build(radii=[None, 15.0, None, None]) large = _build(radii=[None, 35.0, None, None]) one = next(c for c in small.curves if c.node_first == 1) other = next(c for c in large.curves if c.node_first == 1) assert one.apex == other.apex assert one.start != other.start # 접선점은 움직인다 def test_직선_삭제는_점을_빼는_것(): """가운데 꺾임점을 빼면 앞뒤 직선이 하나로 합쳐진다.""" fewer = build_planned_polyline( [NODES[0], NODES[2], NODES[3]], min_radius_m=MIN_RADIUS, simplify=False ) assert fewer.curve_count == 1 assert len(fewer.nodes) == 3 def test_직선_추가는_점을_더하는_것(): """직선 위에 점을 더하면 그 자리에 곡선이 생긴다(그 점을 옮기기 전에는 거의 직선).""" more = build_planned_polyline( [NODES[0], (50.0, 0.0), *NODES[1:]], min_radius_m=MIN_RADIUS, simplify=False ) assert len(more.nodes) == len(NODES) + 1 # 새 점은 직선 위라 그 자리 곡선은 거의 펴져 있다 — 내각이 180°에 가깝다. added = [c for c in more.curves if c.node_first == 1] assert not added or added[0].inner_angle_deg > 179.0