Files
Aislo/resources/tester/helper_209_1_detail_select.cjs
T
eomsangdonandClaude Opus 5.5 10eb54f5e5 feat(B06): [상세] 그래프 고르기 — 교차점 분할 · 여러 고름(원지반 포함) · 닫힌 넓이 · 고른 것 값 · 서버 조각 검산 (209-1)
- 선(설계 · 구조물 · 원지반 · 사토장)을 만나는 점에서 조각으로 나눔 · 조각마다 판정 선
- 누름 = 하나 · Shift/Ctrl+누름 = 더하기/빼기 · [+ − ⤢] 왼쪽 값 두 줄(길이 합 · 면적 · 닫히지 않음)
- 칸 넣기 = 우클릭 고르기 길 그대로 · 길이 한 번 누름 = 바로 · 여럿 = Enter · [칸에 넣기]
- 저장 = 조각 두 끝 목록(pieces) · 서버가 설계선 · 원지반선 · 사토장선 위 검산 · 구조물 선은 두 끝 직선 · 옛 두 끝 꼴 그대로

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JywHxQuWPk6UYXTebyrBoU
2026-10-10 15:21:50 +09:00

118 lines
5.0 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 ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
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);
function loadTs(full) {
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
const localRequire = (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)));
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
return box.exports;
}
const G = loadTs(path.join(B06, "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));