- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침 - 확인: 이 묶음 헬퍼를 쓰는 시험 279 개 전 279 통과 → 후 279 통과 (시험별 junit 대조 · 어긋남 0) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
114 lines
4.7 KiB
JavaScript
114 lines
4.7 KiB
JavaScript
/* PLAN 209-1 단위검증 헬퍼 — [상세] 선 조각 고르기(`_Cross_Detail_Geom` · `_Cross_Detail_Select`).
|
|
* 화면 TS 를 그 자리에서 트랜스파일해 Node 로 돌림. 입력 = 표준입력 JSON {design, samples, axes} ·
|
|
* 결과 = 표준출력 JSON 한 벌. 짝 = `test_209_1_detail_select.py`(파이썬 `cell_value` 거울).
|
|
*/
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
const B06 = path.join(ROOT, "B06_Section");
|
|
const common = fs.readFileSync(path.join(B06, "B06_Section_UI_Section_Common.ts"), "utf8");
|
|
const CROSS_PAD = Function(`return ${/export const CROSS_PAD = (\{[^}]*\})/.exec(common)[1]}`)();
|
|
globalThis.window = { sessionStorage: new Map(), localStorage: new Map() };
|
|
globalThis.document = { addEventListener: () => {}, removeEventListener: () => {} };
|
|
|
|
const STUBS = {
|
|
"@ui/ui_template_context_menu": { createMapContextMenu: () => ({}) },
|
|
"./B06_Section_UI_Section_Common": { CROSS_PAD },
|
|
};
|
|
const resolve = (base) => (fs.existsSync(`${base}.ts`) ? `${base}.ts` : base);
|
|
const { loadTs } = makeLoader({
|
|
root: ROOT,
|
|
cache: false,
|
|
requireFor: (full) => (request) => {
|
|
if (STUBS[request]) return STUBS[request];
|
|
if (request.endsWith(".css")) return {};
|
|
if (request.startsWith("@util/"))
|
|
return loadTs(resolve(path.join(ROOT, "common_util", request.slice(6))));
|
|
return loadTs(resolve(path.join(path.dirname(full), request)));
|
|
},
|
|
});
|
|
const G = loadTs(path.join(B06, "logic/B06_Section_UI_Cross_Detail_Geom.ts"));
|
|
const S = loadTs(path.join(B06, "B06_Section_UI_Cross_Detail_Select.ts"));
|
|
const T = loadTs(path.join(B06, "B06_Section_UI_Cross_Detail_Table.ts"));
|
|
|
|
const { design, samples, axes } = JSON.parse(fs.readFileSync(0, "utf8"));
|
|
const out = {};
|
|
|
|
// ① 그림 요소(화면 px) → 조각(m) — 설계선(직선 토막 셋) · 원지반선 · 구조물 선 아님
|
|
const px = ([offset, elevation]) =>
|
|
[
|
|
CROSS_PAD.left + (axes.maxOffset - offset) * axes.pixelsPerMeter,
|
|
CROSS_PAD.top +
|
|
(axes.displayMax -
|
|
(axes.elevationMid + (elevation - axes.elevationMid) * axes.exaggeration)) *
|
|
axes.pixelsPerMeter,
|
|
].join(",");
|
|
const el = (classes, points, attrs = {}) => ({
|
|
tagName: "polyline",
|
|
classList: { contains: (name) => classes.includes(name) },
|
|
hasAttribute: (name) => name in attrs,
|
|
getAttribute: (name) => (name === "points" ? points.map(px).join(" ") : (attrs[name] ?? null)),
|
|
});
|
|
const designPts = design.design_line.map((p) => [p.offset_m, p.elevation_m]);
|
|
const groundPts = samples.filter((s) => s.valid !== false).map((s) => [s.offset_m, s.elevation_m]);
|
|
const pieces = S.collectPieces(
|
|
[
|
|
el(["b06-chart__design-cross"], designPts, { "data-design-line": "" }),
|
|
el(["b06-chart__cross-profile"], groundPts),
|
|
el(
|
|
["b06-chart__grid"],
|
|
[
|
|
[0, 0],
|
|
[1, 1],
|
|
],
|
|
),
|
|
],
|
|
axes,
|
|
);
|
|
out.pieces = pieces;
|
|
|
|
// ② 여러 고름 — 더하기 · 빼기 · 하나 · 다시 누르면 비움
|
|
out.toggle = {
|
|
single: S.toggleSelection([1, 2], 3, false),
|
|
again: S.toggleSelection([3], 3, false),
|
|
add: S.toggleSelection([1], 3, true),
|
|
remove: S.toggleSelection([1, 3], 3, true),
|
|
};
|
|
|
|
// ③ 닫힌 영역 — 땅 아래 설계 골(경사 둘 · 바닥) + 원지반 가운데 조각
|
|
const isGround = (p) => p.line === "ground";
|
|
const mid = (p) => (p.points[0][0] + p.points[p.points.length - 1][0]) / 2;
|
|
const below = pieces.filter(
|
|
(p) => !isGround(p) && Math.max(...p.points.map((q) => q[1])) <= 100.0001,
|
|
);
|
|
const groundMid = pieces.filter((p) => isGround(p) && Math.abs(mid(p)) < 1);
|
|
const ring = [...below, ...groundMid];
|
|
out.ringCount = ring.length;
|
|
out.label = {
|
|
ring: S.selectionLabel(design, ring),
|
|
open: S.selectionLabel(design, below),
|
|
single: S.selectionLabel(design, [below.find((p) => Math.abs(mid(p)) < 0.5)]),
|
|
ground: S.selectionLabel(design, groundMid),
|
|
};
|
|
out.area = G.ringArea(ring.map((p) => p.points));
|
|
out.open = G.ringArea(below.map((p) => p.points));
|
|
|
|
// ④ 칸 넣기 출처(저장 꼴) · 즉시 칸 값(짝 ①)
|
|
out.sourceArea = S.selectionSource("area", ring);
|
|
out.sourceOpen = S.selectionSource("area", below);
|
|
out.sourceLength = S.selectionSource("length", [...below, ...groundMid]);
|
|
const withStructure = {
|
|
src: "length",
|
|
pieces: [...out.sourceLength.pieces, { line: "structure", start: [20, 0], end: [23, 4] }],
|
|
};
|
|
const offLine = {
|
|
src: "length",
|
|
pieces: [{ line: "ground", start: [0, 101], end: [1, 100] }],
|
|
};
|
|
out.sources = [out.sourceArea, out.sourceLength, withStructure, offLine];
|
|
out.local = out.sources.map((source) => T.localCellValue(source, design, samples));
|
|
out.lengthSum = [...below, ...groundMid].reduce((sum, p) => sum + G.pathLength(p.points), 0);
|
|
process.stdout.write(JSON.stringify(out));
|