Files
Aislo/common_util/common_util_structure_station.ts
T
eomsangdonandClaude Opus 5.5 bbd6254892 feat(구조물표): 322-1 부품 상자 · 표 읽기 — 목록 · 측점 · 카드 이름 · 형상 고르기 · 3D 몸체 · 알약 띠가 종류 키 · 군 글자 · 자리꼴 · managed_by 대신 구조물 표(catalog) 한 줄을 읽음 · 코드 숨김 목록 걷음 · ★ 넷 + 관 공식 한 벌
- 부품 상자 common_util_structure_parts.json(갈래마다 부품 · 읽는 칸 · 자리꼴 · 정본 · 42종 처음값) · 표 읽기 common_util_structure_catalog.ts / .py 짝(정의 반영 ⊕ 처음값 ⊕ 부품 끔) · 거울 시험 test_322_1_catalog_mirror
- 목록: pickGroups 군 차례 = 구조물군 열쇠 · 페이지 거르기 listPick(B05 both · B06 both + b06) · HIDDEN_PICK_GROUPS · HIDDEN_PICK_TYPES · pickable 걷음(옛 대피 셋 asRoad 그대로)
- 측점: structureStationMarks · pipeStationMarks · is_station_planting_type · resolve_extra_stations = 표 횡단도(anchor · span3 · none)
- 카드 이름: cardTitle / card_title 한 공식(빈칸 = 그 종류 정의 기본값) · 표시 이름이 정의 관종도 앎
- 형상: 벽 = shape wall(형태 = 형상칸.form · 물빼기 = 형상칸.weep) · 포장 = shape pavement(「사용 중」 거르기 없앰) · 맹암거 · 사토 · 관 지점 시설 세트 = shape
- 3D 몸체 = 그림 자료 주인 종류의 표 3D 부품 · 알약 띠 = 표 자리꼴 구간(관 지점 시설은 알약만)
- ★1 노출형 · 개거 횡단도 none · ★2 쇄석 화면에서도 포장층 · ★3 기슭막이 표 자리꼴 interval(정의 파일 그대로) · ★4 코드 숨김 10종 list hidden · ★5 관 빈칸 D800 → 정의 기본 D1000
- 옛 시험: 도움 파일 로더 27개가 표 모듈 공용 한 벌(helper_322_catalog_module) 씀 · 기대값 고침(272_1 · b05_extra_stations · roundtrip · 314 · 52_7 · walls 거울 · wall_drain_pipe)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ji4nuyLVHcxrXWHTdb5nRD
2026-10-14 15:09:45 +09:00

208 lines
8.6 KiB
TypeScript

/* =============================================================================
* common_util/common_util_structure_station.ts
* 구조물 · 관 기준 측점 = 정수 m(반올림 · .5 는 올림) · 노선 끝 안쪽(요구 167 · 272).
*
* 측점 값(측점 + 거리 · 누가거리)에 소수를 안 씀 — 일반 측점(격자)과 같은 m 면 서버 측점 만들기가
* 한 측점으로 합침(구조물 측점이 위). 234-1 의 「일반 측점 1 m 안 붙기」는 뺌(그냥 정수 · 사용자 167).
* 파이썬 짝 = `common_util/common_util_structure_station.py`(서버 자동 배치 · 노선 재투영).
* 거울 시험 = `resources/tester/test_234_1_structure_station.py`.
* 일반 측점 = 격자 · 시종점(구조물 측점 kind "irregular" 은 뺌) — 끝(노선 길이)을 넘지 않게 자르는 데만 ·
* 상세를 읽을 때 한 번 둔다.
*
* 심는 측점 = 구조물 표(catalog) 횡단도 부품(322-1) — anchor = 기준 하나 · span3 = 시작 · 기준 · 끝 · none = 없음.
*
* 측점 한 벌(272) — 측점을 심는 관 · 구조물(`plantedChainages`) = 서버 `resolve_extra_stations`
* (B05_Profile_Engine_Sections.py) 짝 · 같은 m 면 측점 하나 · 구조물이 위(`oneStationList`) = 서버
* `_merge_irregular_into_longitudinal`(B05_Profile_Router_Confirm.py) 짝. 거울 시험 =
* `resources/tester/test_272_1_station_list.py`. 종단 그래프 · 3D · 계획선 측점 줄(표 · ▲▼)이
* 이 목록 하나를 씀.
* ========================================================================== */
import { catalogRow } from "./common_util_structure_catalog";
const EPS = 1e-6;
/** 같은 측점으로 볼 거리(m) — 서버 측점 만들기의 격자 붙임 폭(`Engine_Sections_Core`)과 같음. */
export const SAME_STATION_M = 0.005;
let general: number[] = [];
/** 일반 측점 목록을 둔다 — 횡단 상세를 읽을 때마다(B05 · B06 한 노선). */
export function setGeneralStations(
stations: ReadonlyArray<{ chainage_m: number; kind?: string }> | null | undefined,
): void {
general = (stations ?? [])
.filter((station) => station.kind !== "irregular")
.map((station) => station.chainage_m);
}
export const generalStations = (): readonly number[] => general;
/** 기준 측점 = 정수 m(.5 는 올림) · 0 ~ 노선 끝(소수 끝은 그 아래 정수) 안. 두 번 맞춰도 같다. */
export function snapStructureStation(
chainageM: number,
stations: readonly number[] = general,
): number {
if (!Number.isFinite(chainageM)) return chainageM;
const end = stations.length ? Math.max(...stations) : Infinity;
const whole = Math.floor(chainageM + 0.5);
return Math.max(0, Math.min(whole, Math.floor(end + EPS)));
}
/** 방향키 한 걸음(1 m) — 맞춘 값이 제자리면 한 걸음 더 · 노선 밖이면 제자리. */
export function stepStructureStation(
fromM: number,
direction: 1 | -1,
stations: readonly number[] = general,
): number {
for (let steps = 1; steps <= 3; steps += 1) {
const next = snapStructureStation(fromM + direction * steps, stations);
if ((next - fromM) * direction > EPS) return next;
}
return fromM;
}
/** 이미 정수 m 인가(옛 소수 자료를 옮길 것을 가름). */
export const isSnappedStation = (
chainageM: number,
stations: readonly number[] = general,
): boolean => Math.abs(snapStructureStation(chainageM, stations) - chainageM) < EPS;
/* ── 측점을 심는 자리(272 · 서버 `resolve_extra_stations` · `is_station_planting_type` 짝) ── */
export interface PlantingPipe {
chainage_m: number;
facility?: string | null;
start_m?: number | null;
end_m?: number | null;
}
export interface PlantingStructure {
type_id: string;
chainage_m?: number | null;
start_m?: number | null;
end_m?: number | null;
}
export interface PlantingType {
type_id: string;
group: string;
placement: string;
managed_by?: string | null;
}
/** 측점 하나 — 구간형(독립 기슭막이 · C · D군)은 시작 · 기준 · 끝 셋, 그 밖은 기준 하나. */
export interface StationMark {
chainage_m: number;
role: "start" | "anchor" | "end";
}
function marksOf(
start: number | null | undefined,
anchor: number | null | undefined,
end: number | null | undefined,
interval: boolean,
): StationMark[] {
const marks: Array<[StationMark["role"], number | null | undefined]> = interval
? [
["start", start],
["anchor", anchor],
["end", end],
]
: [["anchor", anchor]];
return marks.flatMap(([role, at]) =>
typeof at === "number" && Number.isFinite(at) ? [{ chainage_m: at, role }] : [],
);
}
/** 관 시설 하나가 심는 측점 — 표 횡단도(독립 기슭막이 = span3 · 물넘이포장 포함 그 밖 = anchor · 286-1). */
export function pipeStationMarks(pipe: PlantingPipe): StationMark[] {
const station = catalogRow(pipe.facility ?? "pipe")?.station ?? "anchor";
if (station === "none") return [];
return marksOf(pipe.start_m, pipe.chainage_m, pipe.end_m, station === "span3");
}
/** 구조물 하나가 심는 측점 — 표 횡단도(anchor = 기준 · span3 = 시작 · 기준 · 끝) · 관 지점 정본 소관 · 모르는 종류 = 없음. */
export function structureStationMarks(
structure: PlantingStructure,
type: PlantingType | undefined,
): StationMark[] {
const row = type && catalogRow(type.type_id);
if (!row || row.owner === "pipe_points" || row.station === "none") return [];
const anchor = structure.chainage_m ?? structure.start_m;
return marksOf(structure.start_m, anchor, structure.end_m, row.station === "span3");
}
/** 측점을 심는 자리 전부(오름차순 · 겹침 그대로) — 서버 `resolve_extra_stations` 의 누가거리. */
export function plantedChainages(
pipes: ReadonlyArray<PlantingPipe>,
structures: ReadonlyArray<PlantingStructure>,
types: ReadonlyArray<PlantingType>,
): number[] {
const byId = new Map(types.map((type) => [type.type_id, type]));
return [
...pipes.flatMap(pipeStationMarks),
...structures.flatMap((structure) =>
structureStationMarks(structure, byId.get(structure.type_id)),
),
]
.map((mark) => mark.chainage_m)
.sort((a, b) => a - b);
}
/* ── 측점 한 벌(272 · 서버 `_merge_irregular_into_longitudinal` 짝) ── */
export interface ListedStation {
chainage_m: number;
kind?: string;
/** 구조물 측점이 얹힌 격자 자리 — 구조물이 떠나면 일반 측점으로 돌아옴(서버 표시). */
grid?: boolean;
structure?: string;
}
/**
* 측점 한 벌 = 서버 측점 중 일반 측점(격자 · 시종점 · 구조물이 떠난 격자 자리는 글 떼고 일반으로) +
* 지금 심긴 구조물 측점(`planted`). 같은 m 면 구조물 측점 하나(일반은 숨김) · 서버의 구조물 측점은
* 지금 목록이 갈음(옮긴 관의 옛 자리가 안 남음).
*/
export function oneStationList<S extends ListedStation, P extends { chainage_m: number }>(
server: ReadonlyArray<S>,
planted: ReadonlyArray<P>,
): Array<S | P> {
const general = server
.filter((station) => station.kind !== "irregular" || station.grid)
.filter((station) =>
planted.every((mark) => Math.abs(mark.chainage_m - station.chainage_m) >= SAME_STATION_M),
)
.map((station) => {
if (!station.grid && station.structure === undefined) return station;
const { grid: _grid, structure: _structure, ...rest } = station;
return { ...rest, kind: station.kind === "irregular" ? "regular" : station.kind } as S;
});
return [...general, ...planted].sort((a, b) => a.chainage_m - b.chainage_m);
}
/**
* 사라진 구조물 측점(`gone`)의 계획선 꼭짓점을 새 측점(`born`)으로 옮기거나 지운다 — 서버
* `_follow_moved_stations`(B05_Profile_Router_Confirm.py) 짝: 0.006m 안 반올림 차이 · 옛 소수 측점의
* 정수 m 맞춤 자리(272)면 높이 그대로 옮기고, 나머지는 지움(측점 없는 꼭짓점이 계획선을 꺾지 않게).
*/
export function followMovedNodes<N extends { chainage_m: number }>(
nodes: ReadonlyArray<N>,
gone: ReadonlyArray<number>,
born: ReadonlyArray<number>,
): N[] {
const target = (old: number): number | null => {
const near = born.find((value) => Math.abs(value - old) < 0.006);
if (near !== undefined) return near;
const snapped = Math.floor(old + 0.5);
return born.some((value) => Math.abs(value - snapped) < EPS) ? snapped : null;
};
return nodes.flatMap((node) => {
const old = gone.find((value) => Math.abs(value - node.chainage_m) < 0.006);
if (old === undefined) return [node];
const to = target(old);
return to === null ? [] : [{ ...node, chainage_m: to }];
});
}