- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침 - 확인: 이 묶음 헬퍼를 쓰는 시험 233 개 전 233 통과 → 후 233 통과 (시험별 junit 대조 · 어긋남 0) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
/* 410 좌표 따라감 거울 — 진짜 TS(`common_util_route_follow`)를 Node 로 돌림.
|
|
* 입력 argv[2] JSON = { lines: [L1, L2, ...], structures, pipes, followed } · 표준출력 JSON 한 벌.
|
|
* 차례(구조물) = L1 에서 자리 붙임(placeOnLine) → L2 따라감 → L2 에서 자리 붙임 → L3 따라감 …
|
|
* 관 = 좌표 없는 초안 + 앞 따라감(followed) → L1 자리 붙임 → L2 투영.
|
|
*/
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
|
|
function loadTs(file, stubs = {}) {
|
|
return makeLoader({
|
|
root: ROOT,
|
|
cache: false,
|
|
requireFor: (full) => (request) => {
|
|
if (stubs[request]) return stubs[request];
|
|
throw new Error(`stub 없음: ${request} (${file})`);
|
|
},
|
|
}).loadTs(path.join(ROOT, file));
|
|
}
|
|
|
|
const catalog = require("./helper_322_catalog_module.cjs");
|
|
const station = loadTs("common_util/common_util_structure_station.ts", {
|
|
"./common_util_structure_catalog": catalog,
|
|
});
|
|
const follow = loadTs("common_util/common_util_route_follow.ts", {
|
|
"./common_util_structure_station": station,
|
|
});
|
|
|
|
const input = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
|
|
const lines = input.lines.map((line) => line.map(([x, y]) => ({ x, y })));
|
|
const steps = [];
|
|
let items = input.structures;
|
|
for (let i = 0; i + 1 < lines.length; i += 1) {
|
|
const placed = follow.placeOnLine(items, lines[i], [], input.interval);
|
|
items = follow
|
|
.followStructures(placed, lines[i + 1], undefined, input.interval)
|
|
.map((moved) => moved.item);
|
|
steps.push({ placed, followed: items });
|
|
}
|
|
const pipesPlaced = follow.placeOnLine(input.pipes, lines[0], input.followed);
|
|
const out = {
|
|
steps,
|
|
pipesPlaced,
|
|
pipesFollowed: follow.projectPipePoints(pipesPlaced, lines[1]),
|
|
};
|
|
process.stdout.write(JSON.stringify(out));
|