78 lines
2.8 KiB
JavaScript
78 lines
2.8 KiB
JavaScript
/* 455 (433-13 ①) 종단 ▲▼ 자동 R — `B05_Profile_UI_Profile_Alignment.ts` adjustStation 을 Node 로 돌림.
|
|
* ① 누른 꼭짓점 R = 저장 자동 R → 지움 · 곡선 L = 기본 L ② 사용자 R(저장분과 다름) → 그대로
|
|
* ③ 자동 R 기준을 안 넘기면(옛 부름) → 그대로. 표준출력 = JSON.
|
|
*/
|
|
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();
|
|
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 (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
|
|
return require(request);
|
|
};
|
|
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
|
|
cache.set(full, box.exports);
|
|
return box.exports;
|
|
}
|
|
|
|
const align = loadTs(
|
|
path.join(ROOT, "B05_Profile", "logic", "B05_Profile_UI_Profile_Alignment.ts"),
|
|
);
|
|
|
|
// 20m 측점 · 100m 에 꺾임 하나(대수차 0.5 %)
|
|
const stations = Array.from({ length: 11 }, (_, i) => i * 20);
|
|
const ground = stations.map((s) => 100 + 0.02 * s + (s > 100 ? 0.005 * (s - 100) : 0));
|
|
const base = {
|
|
policy: {
|
|
station_interval_m: 20,
|
|
curve_radius_ratio: 1,
|
|
curve_tangent_max_ratio: 0.5,
|
|
curve_skip_legal_exception: false,
|
|
default_curve_length_m: 15,
|
|
default_curve_radius_m: 300,
|
|
balance_tolerance_percent: 10,
|
|
edit_step_m: 0.1,
|
|
grade_violation_policy: "warn",
|
|
max_grade_pct: 14,
|
|
curve_skip_delta_pct: 0,
|
|
paved: true,
|
|
},
|
|
onlyExplicitCurves: false,
|
|
basePvi: stations.map((s, i) => ({ chainage_m: s, elevation_m: ground[i] })),
|
|
chainage: stations,
|
|
ground,
|
|
stations: stations.map((s) => ({ station_id: `S${s}`, chainage_m: s })),
|
|
};
|
|
const KEY = "100.000";
|
|
const AUTO = 15 / 0.005; // 관 정착이 역산한 꼴(R = L / A)
|
|
|
|
function press(radius, autoRadii) {
|
|
const edits = { station_offsets: {}, curve_radii: { [KEY]: radius } };
|
|
const next =
|
|
autoRadii === undefined
|
|
? align.adjustStation(base, edits, 100, 0.1)
|
|
: align.adjustStation(base, edits, 100, 0.1, autoRadii);
|
|
const curve = align
|
|
.buildAlignment(base, next)
|
|
.curves.find((c) => Math.abs(c.chainage_m - 100) < 1e-6);
|
|
return { radius: next.curve_radii[KEY] ?? null, length: curve ? curve.l_m : null };
|
|
}
|
|
|
|
process.stdout.write(
|
|
JSON.stringify({
|
|
auto: press(AUTO, { [KEY]: AUTO }),
|
|
user: press(777, { [KEY]: AUTO }),
|
|
legacy: press(AUTO),
|
|
}),
|
|
);
|