Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F3mdb91125mPoC6tpsQx4P
305 lines
11 KiB
JavaScript
305 lines
11 KiB
JavaScript
/* PLAN 108 단위검증 헬퍼 — 조정창 끌기 두 축 · 걸음 맞춤 · 미리 보기 = 결과 · BOX 끝 판정면.
|
|
* TS 를 그 자리에서 트랜스파일해 Node 로 돌린다. 결과는 표준출력에 JSON 한 벌.
|
|
* 끌기 손잡이(`bindDragHandle`)는 가로채서 창이 넘긴 `snap` 을 그대로 부른다.
|
|
*
|
|
* ⚠ 확장자가 `.cjs` 인 까닭은 `helper_b05_curve_radius_floor.cjs` 머리와 같다.
|
|
*/
|
|
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();
|
|
/** 가로챌 모듈 — 아래에서 채운다(창 모듈을 부르기 전에). */
|
|
let STUBS = {};
|
|
|
|
// ── 화면 그릇 흉내 — 조정창이 쓰는 만큼만 ─────────────────────────────────────
|
|
class FakeNode {
|
|
constructor(tag) {
|
|
this.tagName = tag.toUpperCase();
|
|
this.children = [];
|
|
this.dataset = {};
|
|
this._text = "";
|
|
this._classes = new Set();
|
|
const self = this;
|
|
this.classList = {
|
|
add: (...names) => names.forEach((n) => self._classes.add(n)),
|
|
remove: (...names) => names.forEach((n) => self._classes.delete(n)),
|
|
toggle: (name, force) => {
|
|
const on = force === undefined ? !self._classes.has(name) : !!force;
|
|
on ? self._classes.add(name) : self._classes.delete(name);
|
|
return on;
|
|
},
|
|
contains: (name) => self._classes.has(name),
|
|
};
|
|
}
|
|
set className(value) {
|
|
this._classes = new Set(String(value).split(/\s+/).filter(Boolean));
|
|
}
|
|
get className() {
|
|
return [...this._classes].join(" ");
|
|
}
|
|
set textContent(value) {
|
|
this._text = String(value);
|
|
}
|
|
get textContent() {
|
|
return this._text + this.children.map((c) => c.textContent).join("");
|
|
}
|
|
append(...kids) {
|
|
kids.forEach((k) => this.children.push(k));
|
|
}
|
|
setAttribute(name, value) {
|
|
this[name] = value;
|
|
}
|
|
addEventListener() {}
|
|
querySelectorAll(selector) {
|
|
const found = [];
|
|
const walk = (node) =>
|
|
node.children.forEach((kid) => {
|
|
if (kid.classList && kid.classList.contains(selector.slice(1))) found.push(kid);
|
|
walk(kid);
|
|
});
|
|
walk(this);
|
|
return found;
|
|
}
|
|
querySelector(selector) {
|
|
return this.querySelectorAll(selector)[0] ?? null;
|
|
}
|
|
}
|
|
globalThis.document = {
|
|
createElement: (tag) => new FakeNode(tag),
|
|
addEventListener: () => {},
|
|
removeEventListener: () => {},
|
|
};
|
|
globalThis.window = { addEventListener: () => {}, removeEventListener: () => {} };
|
|
globalThis.requestAnimationFrame = (fn) => fn();
|
|
|
|
function loadTs(file) {
|
|
const full = path.resolve(file);
|
|
if (cache.has(full)) return cache.get(full);
|
|
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
}).outputText;
|
|
const box = { exports: {} };
|
|
cache.set(full, box.exports);
|
|
const localRequire = (request) => {
|
|
if (STUBS[request]) return STUBS[request];
|
|
if (request.startsWith("@util/"))
|
|
return loadTs(path.join(ROOT, "common_util", `${request.slice(6)}.ts`));
|
|
return loadTs(path.join(path.dirname(full), `${request}.ts`));
|
|
};
|
|
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
|
|
return box.exports;
|
|
}
|
|
|
|
const B06 = (name) => path.join(ROOT, "B06_Section", `${name}.ts`);
|
|
const base = loadTs(B06("B06_Section_UI_Cross_Panel_Base"));
|
|
/** 창이 넘긴 끌기 deps — 마지막 것이 지금 창. */
|
|
const drags = [];
|
|
STUBS = {
|
|
"./B06_Section_UI_Section_Common": { L: (key) => key },
|
|
"@ui/ui_template_elements": { showToast: () => {} },
|
|
"./B06_Section_UI_Cross_Panel_Base": {
|
|
...base,
|
|
bindDragHandle: (root, deps) => {
|
|
drags.push(deps);
|
|
return { attach: () => {}, detach: () => {} };
|
|
},
|
|
},
|
|
};
|
|
const { buildStructurePanel } = loadTs(B06("B06_Section_UI_Cross_Structure_Panel"));
|
|
const { buildBoxPanel } = loadTs(B06("B06_Section_UI_Cross_Box_Panel"));
|
|
const { buildFordPanel } = loadTs(B06("B06_Section_UI_Cross_Ford_Panel"));
|
|
const { structurePanelDeps } = loadTs(B06("B06_Section_UI_Cross_View_Structure"));
|
|
const { placePipeWall } = loadTs(B06("B06_Section_UI_Cross_Culvert_Solve"));
|
|
const { boxHitBands } = loadTs(B06("B06_Section_UI_Cross_Box"));
|
|
|
|
const r3 = (v) => Math.round(v * 1000) / 1000;
|
|
const snapOut = (s) => (s ? { leftM: r3(s.leftM), downM: r3(s.downM), text: s.text } : null);
|
|
|
|
// ── 벽 · 집수정 창 — 실제 배선(structurePanelDeps)으로 ─────────────────────────
|
|
function wallCase({ key, structure = "revet", outward, adjust, appliedD = 0, basin, guard }) {
|
|
const updates = [];
|
|
const ctx = {
|
|
section: { chainage_m: 100 },
|
|
adjustChainage: () => 100,
|
|
isLinked: false,
|
|
revetOffset: { update: (at, role, patch) => updates.push({ role, ...patch }) },
|
|
inletStructure: {
|
|
valueFor: () => structure,
|
|
adjustFor: () => basin ?? { innerWidthM: 1, innerHeightM: 1.2, lateralM: 0, slopeM: 0 },
|
|
updateAdjust: (at, next) => updates.push({ basin: next }),
|
|
},
|
|
adjustOf: () => adjust,
|
|
outwardOf: () => outward,
|
|
heightOfWall: () => 2,
|
|
drawnWallKeys: () => [key],
|
|
formOfWall: () => "돌쌓기(메)",
|
|
appliedD: () => new Map([[key, appliedD]]),
|
|
inletIsBasin: () => structure !== "revet",
|
|
hiddenPipe: () => false,
|
|
bodyGuard: () => !!guard,
|
|
fordGuard: () => false,
|
|
inletOptions: () => ({ revetAllowed: true, basinLUAllowed: true }),
|
|
extraState: () => ({ canAdd: true, count: 1 }),
|
|
basinExtraState: () => ({ canAdd: false, count: 0 }),
|
|
activeRevet: () => key,
|
|
setActiveRevet: () => {},
|
|
toggleRevet: () => {},
|
|
scrollKey: "t",
|
|
};
|
|
const panel = buildStructurePanel(structurePanelDeps(ctx));
|
|
panel.show(key);
|
|
const drag = drags[drags.length - 1];
|
|
return {
|
|
panel,
|
|
snap: (leftM, downM) => {
|
|
const s = drag.snap(leftM, downM);
|
|
if (s?.text) s.apply();
|
|
return { snap: snapOut(s), update: updates.pop() ?? null };
|
|
},
|
|
};
|
|
}
|
|
|
|
/** 배관 기준벽 자리(`placePipeWall`) — 미리 보기 = 결과 판정용. 화면 왼쪽 = offset +. */
|
|
const wallAt = (outward, adjust) =>
|
|
placePipeWall({
|
|
autoOffset: 5 * outward,
|
|
outward,
|
|
height: 2,
|
|
baseElevation0: 98,
|
|
edgeElevation: 100,
|
|
invertCap: 99,
|
|
adjust: { x: adjust.x, d: adjust.d, h: null, m: null },
|
|
defaultD: 0,
|
|
});
|
|
const shiftOf = (outward, from, to) => {
|
|
const a = wallAt(outward, from);
|
|
const b = wallAt(outward, to);
|
|
return { leftM: r3(b.anchorOffset - a.anchorOffset), downM: r3(a.topElevation - b.topElevation) };
|
|
};
|
|
|
|
const out = { wall: {}, box: {}, ford: {} };
|
|
for (const outward of [1, -1]) {
|
|
const from = { x: 0, d: 2, h: null, m: null };
|
|
const { snap, panel } = wallCase({ key: "outlet", outward, adjust: from });
|
|
// 대각 끌기 — 화면 왼쪽 3.3 · 아래 1.7 (outward = 1 기준), 반대편은 화면 좌우만 뒤집음
|
|
const got = snap(3.3 * outward, 1.7);
|
|
out.wall[`diag${outward}`] = {
|
|
...got,
|
|
result: got.update ? shiftOf(outward, from, got.update) : null,
|
|
overlayHead: panel.root.children[0].children.map((c) => c.className),
|
|
};
|
|
}
|
|
// 한계 — 사면 위로 넘김 · 안쪽으로 넘김 → 가장 가까운 허용 자리(d 0 · x 0)
|
|
out.wall.limit = wallCase({
|
|
key: "outlet",
|
|
outward: 1,
|
|
adjust: { x: 0.5, d: 0.5, h: null, m: null },
|
|
}).snap(-5, -3);
|
|
// 흙막이(세월교 · BOX) — 본체 끝이 0점이라 안쪽(음수 x)도 됨 · ±10 m 끝
|
|
out.wall.guard = wallCase({
|
|
key: "outlet",
|
|
outward: 1,
|
|
adjust: { x: 0, d: 0, h: null, m: null },
|
|
guard: true,
|
|
}).snap(-14, 0);
|
|
// 다단 벽 — ▲▼ 순수 수직 · 0.1 걸음 · 선반 x ≥ 1.2·d 가 따라 나감
|
|
out.wall.extra = wallCase({
|
|
key: "extra0",
|
|
outward: 1,
|
|
adjust: { x: 0, d: 0, h: null, m: null },
|
|
}).snap(0.04, 1.0);
|
|
// 집수정 — 1:1.2 사면 · 0.1 걸음 · 좌우 · 사면 ≥ 0
|
|
out.wall.basin = wallCase({
|
|
key: "inlet",
|
|
structure: "L",
|
|
outward: -1,
|
|
adjust: { x: 0, d: null, h: null, m: null },
|
|
basin: { innerWidthM: 1, innerHeightM: 1.2, lateralM: 0.3, slopeM: 0 },
|
|
}).snap(-0.86, 0.25);
|
|
out.wall.basinNone = wallCase({
|
|
key: "inlet",
|
|
structure: "L",
|
|
outward: -1,
|
|
adjust: { x: 0, d: null, h: null, m: null },
|
|
}).snap(0.02, -0.01);
|
|
|
|
// ── BOX 창 — 길이(화면 좌 +) · 표고 ───────────────────────────────────────────
|
|
function boxCase(role, adjust, leftM, downM) {
|
|
const moves = [];
|
|
const panel = buildBoxPanel({
|
|
adjustFor: () => adjust,
|
|
nudgeLength: () => {},
|
|
nudgeRise: () => {},
|
|
move: (r, screen, rise) => moves.push({ role: r, screen: r3(screen), rise: r3(rise) }),
|
|
reset: () => {},
|
|
wingRoleFor: () => "inlet",
|
|
bodyLengthM: () => 5,
|
|
slopeRatio: () => null,
|
|
close: () => {},
|
|
});
|
|
panel.show(role);
|
|
const s = drags[drags.length - 1].snap(leftM, downM);
|
|
if (s?.text) s.apply();
|
|
return {
|
|
snap: snapOut(s),
|
|
move: moves[0] ?? null,
|
|
value: panel.root.children[1].children.map((c) => c.className || "line"),
|
|
};
|
|
}
|
|
out.box.left = boxCase("left", { lengthM: 0, riseM: 0 }, 0.47, 0.33);
|
|
out.box.right = boxCase("right", { lengthM: 1, riseM: 0 }, -0.47, -0.21);
|
|
out.box.shorten = boxCase("left", { lengthM: 0.2, riseM: 9.9 }, -0.9, -0.5);
|
|
|
|
// ── 세월교 창 — 좌우 + 수직 내림(양쪽 한 값 · 아래로만 · 139-3) · 0.1 걸음 ─────────────
|
|
function fordCase(outward, adjust, leftM, downM, dropM = 0) {
|
|
const moves = [];
|
|
const panel = buildFordPanel({
|
|
adjustFor: () => adjust,
|
|
heightFor: () => 1.5,
|
|
nudge: () => {},
|
|
nudgeSlope: () => {},
|
|
dropFor: () => dropM,
|
|
outwardOf: () => outward,
|
|
move: (r, screen, slope) => moves.push({ role: r, screen: r3(screen), slope: r3(slope) }),
|
|
reset: () => {},
|
|
slabLengthM: () => 3.2,
|
|
close: () => {},
|
|
});
|
|
panel.show("inlet");
|
|
const s = drags[drags.length - 1].snap(leftM, downM);
|
|
if (s?.text) s.apply();
|
|
return {
|
|
snap: snapOut(s),
|
|
move: moves[0] ?? null,
|
|
value: panel.root.children[1].children.map((c) => c.className || "line"),
|
|
};
|
|
}
|
|
out.ford = {
|
|
diag: fordCase(1, { heightM: null, lateralM: 0, slopeM: 0 }, 0.53, 0.27),
|
|
inward: fordCase(-1, { heightM: null, lateralM: 0.2, slopeM: 0 }, 0.9, 0),
|
|
up: fordCase(1, { heightM: null, lateralM: 0, slopeM: 0 }, 0, -0.5, 0.2),
|
|
};
|
|
|
|
// ── BOX 판정면 — 좌측 끝 날개벽(에이프런 4 → 6) · 우측 끝 날개벽 없음 ───────────
|
|
const layout = {
|
|
sides: [
|
|
{ role: "left", offset: 4, apron: [{ offset: 4 }, { offset: 6 }] },
|
|
{ role: "right", offset: -4, apron: [] },
|
|
],
|
|
topSlab: [{ elevation: 99 }, { elevation: 99 }],
|
|
bottomSlab: [{ elevation: 96.5 }, { elevation: 96.5 }],
|
|
};
|
|
out.hit = Object.fromEntries(
|
|
boxHitBands(layout).map(([role, points]) => [
|
|
role,
|
|
{
|
|
offsets: [...new Set(points.map((p) => r3(p.offset)))].sort((a, b) => a - b),
|
|
elevations: [...new Set(points.map((p) => p.elevation))].sort((a, b) => a - b),
|
|
},
|
|
]),
|
|
);
|
|
|
|
process.stdout.write(JSON.stringify(out));
|