"""계획노선 사용 범위 절단 (2026-09-04 사용자 지시) 단위 검증.""" import math import sys from pathlib import Path sys.path.append(str(Path(__file__).resolve().parents[2])) from common_util.common_util_route_geometry import clip_route_by_chainage def _length(points): return sum(math.dist(points[i - 1], points[i]) for i in range(1, len(points))) LINE = [(0.0, 0.0), (100.0, 0.0), (100.0, 100.0)] # 총 200m def test_no_range_keeps_all(): assert clip_route_by_chainage(LINE, None, None) == LINE def test_start_only(): out = clip_route_by_chainage(LINE, 50.0, None) assert out[0] == (50.0, 0.0) assert out[-1] == (100.0, 100.0) assert abs(_length(out) - 150.0) < 1e-6 def test_end_only(): out = clip_route_by_chainage(LINE, None, 150.0) assert out[0] == (0.0, 0.0) assert abs(out[-1][0] - 100.0) < 1e-6 and abs(out[-1][1] - 50.0) < 1e-6 assert abs(_length(out) - 150.0) < 1e-6 def test_both_ends_and_interpolated_vertex(): out = clip_route_by_chainage(LINE, 50.0, 150.0) assert abs(_length(out) - 100.0) < 1e-6 # 꺾임점(100,0)이 구간 안이면 그대로 남는다. assert (100.0, 0.0) in [(round(x, 6), round(y, 6)) for x, y in out] def test_range_outside_data_falls_back_to_full(): assert clip_route_by_chainage(LINE, 500.0, 900.0) == LINE def test_reversed_range_falls_back_to_full(): assert clip_route_by_chainage(LINE, 150.0, 50.0) == LINE