Files
Aislo/resources/tester/helper_383_2_key_nudge.cjs
T
eomsangdonandClaude Sonnet 5.5 8bbdbb9f69 test(508-1b 옛 헬퍼 공용 불러오기 4/7): 헬퍼 28 곳 loadTs 베낌 걷고 makeLoader 로
- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침
- 확인: 이 묶음 헬퍼를 쓰는 시험 236 개 전 230 통과 → 후 230 통과 (시험별 junit 대조 · 어긋남 0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-21 17:11:59 +09:00

69 lines
2.1 KiB
JavaScript

/* 383-2 교각점 방향키 — `logic/B05_Profile_RouteEdit_KeyNudge.ts` 를 Node 로 돌려 JSON 한 줄을 냄
* (`test_383_2_route_keys.py` 가 판정). `.cjs` = 루트 package.json 이 "type": "module" 이라서.
*/
const fs = require("fs");
const path = require("path");
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const ROOT = path.join(__dirname, "..", "..");
const { loadTs } = makeLoader({
root: ROOT,
requireFor: (full) => (request) =>
request.startsWith(".")
? loadTs(path.join(path.dirname(full), `${request}.ts`))
: require(request),
});
const nudge = loadTs(path.join(ROOT, "B05_Profile", "logic", "B05_Profile_RouteEdit_KeyNudge.ts"));
// 화면 → 도면: 1 px = 0.5 m · 화면 y 아래 = 도면 y 위로 뒤집힘 · 지도 30° 돌림
const turn = (Math.PI / 180) * 30;
const plain = (x, y) => [x * 0.5, -y * 0.5];
const rotated = (x, y) => {
const [mx, my] = plain(x, y);
return [mx * Math.cos(turn) - my * Math.sin(turn), mx * Math.sin(turn) + my * Math.cos(turn)];
};
const keys = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
const steps = (metricAt, shift) =>
Object.fromEntries(keys.map((key) => [key, nudge.arrowStep(key, shift, metricAt)]));
const before = [
[0, 0],
[50, 0],
[100, 20],
[150, 0],
];
const snapped = [
[0, 0],
[50.8, 0],
[100, 20.6],
[150, 0],
];
const stayed = [
[0, 0],
[50.02, 0],
[100, 20],
[150, 0],
];
const merged = [
[0, 0],
[50.4, 0],
[150, 0],
];
const out = {
plain: steps(plain, false),
shift: steps(plain, true),
rotated: steps(rotated, false),
arrows: keys.map(nudge.isArrowKey).concat(nudge.isArrowKey("Enter")),
snapped: nudge.nudgeReport(before, snapped, 1, [50, 0], [50.3, 0]),
stayed: nudge.nudgeReport(before, stayed, 1, [50, 0], [50.3, 0]),
merged: nudge.nudgeReport(before, merged, 1, [50, 0], [50.3, 0]),
messages: {
snapped: nudge.nudgeMessage({ movedM: 0.8, pushed: 1 }, true),
stayed: nudge.nudgeMessage({ movedM: 0.02, pushed: 0 }, true),
free: nudge.nudgeMessage({ movedM: 0.3, pushed: 0 }, false),
},
};
process.stdout.write(JSON.stringify(out));