/* ============================================================================= * B05_Profile_UI_Drainage_Ford_Fill.ts * 우클릭으로 바로 추가한 세월교 · 물넘이포장의 빈 월류 높이 = 배수유역 재계산이 준 설계유량의 * 필요 수심(PLAN 126-1 · 폼 쪽 65-4 와 같은 풀이 `fordHeightM`). * * 기다리는 측점만 채움 · 사용자가 넣은 높이(응답 옵션에 있음)는 안 덮음 · 유량이 아직 없으면 다음 * 응답까지 기다림. 응답 옵션을 고쳐 두면 보관소(`replaceFromResponse`)가 그 값을 정본으로 받음. * ========================================================================== */ import { FORD_BRIDGE_DEFAULT_WIDTH_M, FORD_PAVEMENT_DEFAULT_WIDTH_M, } from "@config/config_frontend"; import { fordHeightM } from "../A00_Common/design/design_structure_ford_calc"; const FORD_KINDS: Record = { ford_bridge: FORD_BRIDGE_DEFAULT_WIDTH_M, ford_pavement: FORD_PAVEMENT_DEFAULT_WIDTH_M, }; /** 새로 놓으면 높이를 기다리는 종류 — 높이 칸이 빈 세월교 · 물넘이포장. */ export function waitsFordHeight( facility: string | undefined, options?: Record, ): boolean { return !!facility && facility in FORD_KINDS && options?.ford_height_m === undefined; } /** 기다리는 측점의 빈 높이를 채움 — 채운(또는 사용자 값이라 그만 기다릴) 측점은 `pending` 에서 뺌. * 채운 것이 있으면 true(세션 초안에 다시 담을 것). */ export function fillFordHeights( points: Array<{ chainage_m: number; facility?: string; options?: Record; }>, basins: ReadonlyArray<{ chainage_m: number; design_flow_m3s?: number | null }>, pending: Set, ): boolean { let filled = false; for (const wait of [...pending]) { const point = points.find((entry) => Math.abs(entry.chainage_m - wait) < 0.51); if (!point?.facility || !(point.facility in FORD_KINDS)) { pending.delete(wait); // 관이 사라졌거나 종류가 바뀜 continue; } if (point.options?.ford_height_m !== undefined && point.options.ford_height_m !== "") { pending.delete(wait); // 사용자가 넣은 값 — 안 덮음 continue; } const flow = basins.find((entry) => Math.abs(entry.chainage_m - point.chainage_m) < 0.51); const width = Number(point.options?.ford_width_m) || FORD_KINDS[point.facility]; const need = fordHeightM(flow?.design_flow_m3s ?? null, width); if (need === null) continue; // 유량 아직 없음 — 다음 응답까지 빈칸 point.options = { ...point.options, ford_height_m: need }; pending.delete(wait); filled = true; } return filled; }