"""구조물 · 관 기준 측점 = 정수 m(반올림 · .5 는 올림) · 노선 끝 안쪽(요구 167 · 272). 측점 값(측점 + 거리 · 누가거리)에 소수를 안 씀 — 일반 측점(격자)과 같은 m 면 서버 측점 만들기가 한 측점으로 합침(구조물 측점이 위 · `B05_Profile_Engine_Sections_Core`). 234-1 의 「일반 측점 1 m 안 붙기」는 뺌(그냥 정수 · 사용자 167). TS 짝 = `common_util/common_util_structure_station.ts` (화면 입력 · 끌기 · 방향키 · 옛 자료 정수 옮김). 거울 시험 = `resources/tester/test_234_1_structure_station.py`. 일반 측점 = 격자(간격) · 시종점 — 끝(노선 길이)을 넘지 않게 자르는 데만 씀. """ from __future__ import annotations import math from collections.abc import Sequence from dataclasses import replace from typing import TypeVar from common_util.common_util_route_geometry import RouteVertex, interpolate_vertex from config.config_system_design import SECTION_STATION_INTERVAL_M _Candidate = TypeVar("_Candidate") _EPS = 1e-6 def general_stations(total_m: float, interval_m: float) -> list[float]: """격자 측점 + 끝 측점(`Sections_Core._chainages` 와 같은 줄).""" if not (total_m > 0 and interval_m > 0): return [0.0] values = [index * interval_m for index in range(int(total_m // interval_m) + 1)] if total_m - values[-1] > _EPS: values.append(float(total_m)) return values def snap_structure_station(chainage_m: float, stations: Sequence[float]) -> float: """기준 측점 = 정수 m(.5 는 올림) · 0 ~ 노선 끝(소수 끝은 그 아래 정수) 안 · 멱등.""" value = float(chainage_m) if not math.isfinite(value): return value end = max(stations) if stations else math.inf whole = float(math.floor(value + 0.5)) return max(0.0, min(whole, float(math.floor(end + _EPS)))) def route_general_stations(total_m: float) -> list[float]: """노선 길이의 일반 측점 — 서버 측점 간격(`SECTION_STATION_INTERVAL_M`).""" return general_stations(total_m, SECTION_STATION_INTERVAL_M) def snap_candidates( candidates: Sequence[_Candidate], vertices: Sequence[RouteVertex] ) -> list[_Candidate]: """자동 배치 관 자리 맞춤 — 좌표는 맞춘 자리로 다시 찍고, 같은 자리로 모이면 앞선 것만. `candidates` 는 `chainage_m · x · y` 를 가진 dataclass(`StructureCandidate`).""" total_m = float(vertices[-1].chainage_m) stations = route_general_stations(total_m) snapped: list[_Candidate] = [] taken: set[float] = set() for candidate in candidates: at = snap_structure_station(candidate.chainage_m, stations) if at in taken: continue taken.add(at) x, y, _ = interpolate_vertex(list(vertices), at) snapped.append(replace(candidate, chainage_m=at, x=x, y=y)) return snapped