/** * 구조물 목록 순서 (2026-11-03, 교대 AB): 시점 교대(A1) → 교각 P1 … Pn → 종점 교대(A2), 교대가 여럿이면 번호 순. * Pure. Used by the 구조물 목록 so the abutments sit at the two ends of the bridge. */ export interface StructureRef { kind: 'pier' | 'abut'; name: string; /** 교대 형식 (A1 · A2), only for abutments. */ type?: 'A1' | 'A2'; } const numberOf = (name: string) => Number(name.replace(/\D/g, '')) || 0; export function structureOrder(abutments: { name: string; type: 'A1' | 'A2' }[], piers: string[]): StructureRef[] { const start = abutments.filter((a) => a.type === 'A1').sort((a, b) => numberOf(a.name) - numberOf(b.name)); const end = abutments.filter((a) => a.type === 'A2').sort((a, b) => numberOf(a.name) - numberOf(b.name)); const others = abutments.filter((a) => a.type !== 'A1' && a.type !== 'A2'); return [ ...start.map((a) => ({ kind: 'abut' as const, name: a.name, type: a.type })), ...piers.map((name) => ({ kind: 'pier' as const, name })), ...end.map((a) => ({ kind: 'abut' as const, name: a.name, type: a.type })), ...others.map((a) => ({ kind: 'abut' as const, name: a.name, type: a.type })), ]; }