구조물은 보조말뚝을 박아 그 자리가 정본 측점이 된다. 규칙 격자(20m)와 0.1m 안에서 만나면 세로선·라벨이 두 겹으로 겹쳐 읽히지 않았다. - 공용 유틸 dropStationsNear 추가(B05_Profile_Util_Station). - 종단 그래프와 3D 측점 띠가 같은 규칙을 쓴다 — 두 화면의 측점이 어긋나지 않는다. 검증: tsc --noEmit 통과, tmp/tests/test_b05_station_merge.mjs 통과. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
76 lines
3.5 KiB
TypeScript
76 lines
3.5 KiB
TypeScript
/* =============================================================================
|
||
* B05_Profile_Util_Station.ts
|
||
* 측점 표기 공용 유틸 — 측점번호+잔여거리 ↔ 누가거리(chainage) 변환·서식.
|
||
*
|
||
* 구조물 위치는 저장은 누가거리(m)로 하되 **화면 입출력은 측점번호+잔여거리**로 한다
|
||
* (2026-08-17 사용자 확정). 근거: 중심선측량 측점 20m + 구조물 지점 보조말뚝
|
||
* (지식DB 설계제원_총괄 §8). 표기 예: "3+18.0" = 측점 3번에서 18.0m.
|
||
*
|
||
* 변환식은 비정규 측점 UI(`B05_Profile_UI_IrregularStations.ts`)와 같다 —
|
||
* chainage_m = 측점번호 × 측점간격(m) + 잔여거리(m). 측점간격은 호출 시점에 받는다
|
||
* (프로젝트 설정에 따라 바뀌므로 상수로 굳히지 않는다).
|
||
* ========================================================================== */
|
||
|
||
/** 측점번호 X + 잔여거리 XX(m) → 누가거리(m). */
|
||
export function stationToChainage(station: number, remainder: number, intervalM: number): number {
|
||
return station * intervalM + remainder;
|
||
}
|
||
|
||
/** 누가거리(m) → 측점번호 + 잔여거리. 잔여거리는 [0, 간격) 범위로 정규화한다. */
|
||
export function chainageToStation(
|
||
chainageM: number,
|
||
intervalM: number,
|
||
): { station: number; remainder: number } {
|
||
if (!(intervalM > 0)) return { station: 0, remainder: Math.max(0, chainageM) };
|
||
const clamped = Math.max(0, chainageM);
|
||
let station = Math.floor(clamped / intervalM);
|
||
let remainder = clamped - station * intervalM;
|
||
// 부동소수 잔여가 간격과 사실상 같으면 다음 측점의 0으로 올린다 (19.999… → 1+0.0).
|
||
if (intervalM - remainder < 0.005) {
|
||
station += 1;
|
||
remainder = 0;
|
||
}
|
||
return { station, remainder };
|
||
}
|
||
|
||
/** 누가거리 → "3+18.0" 표기. */
|
||
export function formatStation(chainageM: number, intervalM: number): string {
|
||
const { station, remainder } = chainageToStation(chainageM, intervalM);
|
||
return `${station}+${remainder.toFixed(1)}`;
|
||
}
|
||
|
||
/** "3+18.0" · "3 + 18" · "76.5"(누가거리 직접) 입력을 누가거리로 해석한다.
|
||
* 해석 불가하면 null — 호출부가 칸을 붉히고 진행을 멈춘다. */
|
||
export function parseStationText(text: string, intervalM: number): number | null {
|
||
const trimmed = text.trim();
|
||
if (!trimmed) return null;
|
||
const match = /^(\d+)\s*\+\s*(\d+(?:\.\d+)?)$/.exec(trimmed);
|
||
if (match) {
|
||
const chainage = stationToChainage(Number(match[1]), Number(match[2]), intervalM);
|
||
return Number.isFinite(chainage) ? chainage : null;
|
||
}
|
||
const direct = Number(trimmed);
|
||
return Number.isFinite(direct) && direct >= 0 ? direct : null;
|
||
}
|
||
|
||
/** 구조물 측점과 겹쳤다고 볼 거리(m) — 이보다 가까우면 규칙 측점을 지운다. */
|
||
export const STATION_MERGE_TOLERANCE_M = 0.1;
|
||
|
||
/**
|
||
* 구조물 측점과 **겹치는 규칙 측점을 지운다**(2026-09-06).
|
||
*
|
||
* 구조물은 보조말뚝을 박아 그 자리가 정본 측점이 된다. 규칙 격자(20m)와 0.1m 안에서
|
||
* 만나면 세로선·라벨이 두 겹으로 겹쳐 읽히지 않으므로 구조물 쪽만 남긴다.
|
||
*/
|
||
export function dropStationsNear<T extends { chainage_m: number }>(
|
||
stations: readonly T[],
|
||
anchors: ReadonlyArray<{ chainage_m: number }>,
|
||
toleranceM: number = STATION_MERGE_TOLERANCE_M,
|
||
): T[] {
|
||
if (anchors.length === 0) return [...stations];
|
||
return stations.filter(
|
||
(station) =>
|
||
!anchors.some((anchor) => Math.abs(anchor.chainage_m - station.chainage_m) <= toleranceM),
|
||
);
|
||
}
|