Files
Aislo/resources/tester/helper_80_ford_pipe.cjs
T

152 lines
5.9 KiB
JavaScript

/* 80 세월교 흙막이 관 헬퍼 — 화면 TS 를 그 자리에서 트랜스파일해 Node 로 돌림.
* 입력 = 73-4 픽스처(세월교 173.09 · 박스 352.14 유입 · 유출 흙막이) · 결과 = 표준출력 JSON 한 벌. 짝 = `test_80_ford_pipe.py`.
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const ROOT = path.join(__dirname, "..", "..");
const cache = new Map();
// 화면 전용 모듈(토스트 · 글) — 기하 계산엔 안 쓰임
const STUBS = {
"@ui/ui_template_toast": { showToast: () => undefined },
};
function loadTs(file) {
const full = path.resolve(file);
if (cache.has(full)) return cache.get(full);
if (full.endsWith(".json")) {
const data = JSON.parse(fs.readFileSync(full, "utf8"));
cache.set(full, data);
return data;
}
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2020,
esModuleInterop: true,
},
}).outputText;
const box = { exports: {} };
cache.set(full, box.exports);
const localRequire = (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)));
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
cache.set(full, box.exports);
return box.exports;
}
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"),
);
const sections = fixture.cross_sections;
const FORD = sections.find((s) => Math.abs(s.chainage_m - 173.087) < 0.6);
const clone = (v) => JSON.parse(JSON.stringify(v));
const r3 = (v) => Math.round(v * 1000) / 1000;
/** 관 길이 · 쪽마다 관 끝 ↔ 흙막이 전면(관 invert 높이) · 바닥판 끝 ↔ 흙막이 배면. */
function pipeFit(edit) {
const section = clone(FORD);
edit(section);
const list = sections.map((s) => (s === FORD ? section : s));
const { ford, culvert } = computeStoredLayouts(section, list);
const [right, left] = ford.pipe.outer.slice(2);
const ends = { 1: left.offset, [-1]: right.offset };
const [topLeft, topRight] = ford.pipe.outer;
const tops = { 1: topLeft, [-1]: topRight };
const slab = ford.slabBridge.map((p) => p.offset);
const slabEnd = { 1: Math.max(...slab), [-1]: Math.min(...slab) };
return {
lengthM: r3(Math.hypot(left.offset - right.offset, left.elevation - right.elevation)),
label: ford.label.text,
sides: ford.sides.map((side) => {
const wall = culvert.walls.find((w) => w.role === side.role && w.outward === side.outward);
if (!wall) return { role: side.role, guard: false };
const front =
wall.points[2].offset +
wall.outward * wall.lean * (wall.topJoint.elevation - side.slabTopElevation);
return {
role: side.role,
guard: true,
pipeGap: r3(ends[side.outward] - front),
// 관 윗모서리 ↔ 그 높이의 흙막이 전면(사면 이용 · 89-1)
topGap: r3(
tops[side.outward].offset -
(wall.points[2].offset +
wall.outward * wall.lean * (wall.topJoint.elevation - tops[side.outward].elevation)),
),
lean: wall.lean,
slabGap: r3(slabEnd[side.outward] - wall.bottomBack.offset),
};
}),
};
}
const move = (role, x) => (s) => {
s.design.revet_adjust = { ...(s.design.revet_adjust ?? {}), [role]: { x, d: null, h: null } };
};
const out = {
both: pipeFit(() => undefined),
inletPlus1: pipeFit(move("inlet", 1)),
outletPlus2: pipeFit(move("outlet", 2)),
inletOnly: pipeFit((s) => {
s.culvert.outlet = { role: "outlet", structure: "" };
}),
};
// 107-1 — 유입 날개벽(측벽) 좌우 · 상하를 옮겨도 유출 흙막이 자리 그대로(관 1 m 맞춤 = 기본 자리 기준)
const outletWallAt = (inlet) => {
const section = clone(FORD);
section.culvert.inlet = { role: "inlet", structure: "" };
section.design.ford_adjust = { inlet: { heightM: null, ...inlet } };
const { ford, culvert } = computeStoredLayouts(
section,
sections.map((s) => (s === FORD ? section : s)),
);
const wall = culvert.walls.find((w) => w.role === "outlet");
const [right, left] = ford.pipe.outer.slice(2);
return {
back: r3(wall.bottomBack.offset),
label: ford.label.text,
lengthM: r3(Math.hypot(left.offset - right.offset, left.elevation - right.elevation)),
};
};
out.inletMoves = [0, 0.1, 0.2, 0.3, 0.5, 1.0].map((lateralM) =>
outletWallAt({ lateralM, slopeM: 0 }),
);
out.inletSlopes = [0.1, 0.5].map((slopeM) => outletWallAt({ lateralM: 0, slopeM }));
// 박스 352.14 — 흙막이를 바깥으로 밀면 본체 끝이 배면까지 따라감 · 안 밀면 그대로
const BOX = sections.find((s) => Math.abs(s.chainage_m - 352.14) < 0.6);
function boxFit(edit) {
const section = clone(BOX);
edit(section);
const { box, culvert } = computeStoredLayouts(
section,
sections.map((s) => (s === BOX ? section : s)),
);
const top = box.topSlab.map((p) => p.offset);
return {
bodyLengthM: r3(box.bodyLengthM),
gaps: culvert.walls
.filter((w) => w.role !== "extra")
.map((w) => r3((w.outward > 0 ? Math.max(...top) : Math.min(...top)) - w.bottomBack.offset)),
};
}
out.boxAuto = boxFit(() => undefined);
out.boxInletPlus1 = boxFit(move("inlet", 1));
process.stdout.write(JSON.stringify(out));