- helper_ts_stub_loader: 옛 헬퍼가 저마다 다르게 쓰던 것(풀이 함수 직접 · esModuleInterop · 캐시 끔 · 파일 통째 대역)을 옵션으로 · 기본 풀이는 그대로 - 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침 - 확인: 이 묶음 헬퍼를 쓰는 시험 241 개 전 241 통과 → 후 241 통과 (비교 = 시험별 junit) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
81 lines
3.2 KiB
JavaScript
81 lines
3.2 KiB
JavaScript
/* 152-2 연동 흙막이 높이 헬퍼 — 높이 칸 빈 박스 흙막이(73-4 픽스처 352.14)의 연동 옆 측점(340 · 360)이
|
|
* 소유 측점이 그린 순수 높이를 물려받는지 · 연동을 푼 카드만 자기 높이로 서는지. 결과 = 표준출력 JSON.
|
|
* 짝 = `test_152_2_link_height.py`.
|
|
*/
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
// 화면 전용 모듈(토스트 · 글) — 기하 계산엔 안 쓰임
|
|
const STUBS = {
|
|
"@ui/ui_template_toast": { showToast: () => undefined },
|
|
};
|
|
|
|
const { loadTs } = makeLoader({
|
|
root: ROOT,
|
|
interop: true,
|
|
requireFor: (full) => (request) => {
|
|
if (STUBS[request]) return STUBS[request];
|
|
const alias = { "@util/": "common_util", "@ui/": "ui_template", "@config/": "config" };
|
|
for (const [prefix, dir] of Object.entries(alias))
|
|
if (request.startsWith(prefix))
|
|
return loadTs(resolve(path.join(ROOT, dir, request.slice(prefix.length))));
|
|
return loadTs(resolve(path.join(path.dirname(full), request)));
|
|
},
|
|
});
|
|
const resolve = (base) =>
|
|
[base, `${base}.ts`, path.join(base, "index.ts")].find(
|
|
(p) => fs.existsSync(p) && fs.statSync(p).isFile(),
|
|
) ?? `${base}.ts`;
|
|
|
|
const B06 = (f) => path.join(ROOT, "B06_Section", f);
|
|
const { computeStoredLayouts } = loadTs(B06("B06_Section_Structure_Layouts.ts"));
|
|
|
|
const fixture = JSON.parse(
|
|
fs.readFileSync(path.join(__dirname, "fixtures", "b06_73_4_body_guard_sections.json"), "utf8"),
|
|
);
|
|
// 높이 칸 비움(= 자동 · 세월교 · 박스 흙막이 기본) — 원본은 3.5 를 넣은 상태
|
|
const sections = fixture.cross_sections.map((s) => {
|
|
if (!s.culvert?.body) return s;
|
|
const copy = JSON.parse(JSON.stringify(s));
|
|
copy.culvert.inlet.revet_height_m = null;
|
|
copy.culvert.outlet.revet_height_m = null;
|
|
return copy;
|
|
});
|
|
const at = (list, c) => list.find((s) => Math.abs(s.chainage_m - c) < 0.6);
|
|
const round = (v) => Math.round(v * 1000) / 1000;
|
|
const heightsOf = (list, c) => {
|
|
const culvert = computeStoredLayouts(at(list, c), list)?.culvert;
|
|
return {
|
|
pure: culvert?.pureHeights
|
|
? { inlet: round(culvert.pureHeights.inlet), outlet: round(culvert.pureHeights.outlet) }
|
|
: null,
|
|
walls: (culvert?.walls ?? []).map((w) => ({ role: w.role, height: round(w.height) })),
|
|
shift: culvert?.revetShift ?? null,
|
|
};
|
|
};
|
|
|
|
const out = { owner: heightsOf(sections, 352.14), linked: {} };
|
|
for (const c of [340, 360]) out.linked[c] = heightsOf(sections, c);
|
|
|
|
// 340 연동 풂 + 유출 흙막이만 +0.1 m(좌측 「이 측점 높이」 줄이 그 측점 값을 고친 것)
|
|
const shift = out.linked[340].shift;
|
|
const detached = sections.map((s) => {
|
|
if (Math.abs(s.chainage_m - 340) >= 0.6) return s;
|
|
const copy = JSON.parse(JSON.stringify(s));
|
|
copy.design.revet_link_detached = true;
|
|
copy.design.revet_adjust = {
|
|
...(copy.design.revet_adjust ?? {}),
|
|
inlet: { ...shift.inlet },
|
|
outlet: { ...shift.outlet, h: round(shift.outlet.h + 0.1) },
|
|
};
|
|
return copy;
|
|
});
|
|
out.detached = {
|
|
340: heightsOf(detached, 340),
|
|
360: heightsOf(detached, 360),
|
|
owner: heightsOf(detached, 352.14),
|
|
};
|
|
process.stdout.write(JSON.stringify(out));
|