From 1fafe2548ce4594e51f05b94cc806452be45b864 Mon Sep 17 00:00:00 2001 From: umsangdon Date: Sat, 12 Sep 2026 21:48:39 +0900 Subject: [PATCH] =?UTF-8?q?fix(b05):=20=EA=B3=A1=EC=84=A0=20=EA=B8=B8?= =?UTF-8?q?=EC=9D=B4(L)=20=ED=95=98=ED=95=9C=EB=8F=84=20=EC=A7=80=ED=82=A4?= =?UTF-8?q?=EA=B2=8C=20=E2=80=94=20=EB=82=B4=EA=B0=81=20155=C2=B0=20?= =?UTF-8?q?=EC=9D=B4=EC=83=81=EC=9D=80=20=EC=98=88=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R 하한만 막고 L 하한은 칸 입력에서만 막던 것을 고침. L = R·Δ 라 한 자리의 하한을 반지름 하나로 모아 봄(`radiusFloorM` = max(R 하한, L 하한/Δ)) — 값 끌어올리기· 모자란 양 판정·칸 막기가 모두 이 값을 씀. 내각 155° 이상은 별표2 Ⅰ.2.다.(1) 상 곡선을 안 둬도 되는 자리라 L 하한을 안 걺 — 걸면 교각이 0 에 가까워 R 이 수십 배로 부풀어 안 고친 구간이 휨. 그 자리는 곡선 패널에 「155° 이상 — 곡선 생략 가능」으로 적어 냄. `deflectionRad` 를 화면 파일(`_Label`)에서 셈 파일(`_Edits`)로 옮김 — 순수 함수가 DOM 파일에 얹혀 있어 시험이 화면째 들여와야 했음(부르던 자리는 재수출로 지킴). Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01DJffo4VwgTumVUM3kdbJzd --- B05_Profile/B05_Profile_UI_RouteEdit.ts | 14 ++- .../B05_Profile_UI_RouteEdit_CurveBar.ts | 19 +++- B05_Profile/B05_Profile_UI_RouteEdit_Edits.ts | 73 +++++++++++--- B05_Profile/B05_Profile_UI_RouteEdit_Label.ts | 19 ++-- .../tester/helper_b05_curve_radius_floor.cjs | 95 +++++++++++++++++++ .../tester/test_b05_curve_radius_floor.py | 76 +++++++++++++++ 6 files changed, 266 insertions(+), 30 deletions(-) create mode 100644 resources/tester/helper_b05_curve_radius_floor.cjs create mode 100644 resources/tester/test_b05_curve_radius_floor.py diff --git a/B05_Profile/B05_Profile_UI_RouteEdit.ts b/B05_Profile/B05_Profile_UI_RouteEdit.ts index ada357e2..5f33de25 100644 --- a/B05_Profile/B05_Profile_UI_RouteEdit.ts +++ b/B05_Profile/B05_Profile_UI_RouteEdit.ts @@ -53,6 +53,7 @@ import { applyArcLocks, applyCurveLimits, curveShortfalls, + radiusFloorM, curveSummary, flattenServerPlan, shortfallCrossed, @@ -336,7 +337,8 @@ export async function openRouteEditModal( // 길이를 붙든 자리는 교각이 바뀌었을 수 있다 — 그리기 전에 R 부터 다시 잡는다. applyArcLocks(planned, curveLock, curveArc, curveRadius); // 지정해 둔 값이 하한을 밑돌면 하한까지 끌어올린다(계획서 0-9 ④). - applyCurveLimits(planned, curveOn, curveRadius, limitRadiusM); + // 하한은 **R 과 L 을 함께 본 값**이다 — 내각 155° 이상은 R 만 본다(2026-09-12 확정). + applyCurveLimits(planned, curveOn, curveRadius, limitRadiusM, limitArcM); const built = buildEditedPolyline(planned, curveOn, curveRadius, minRadiusM); plannedLine = built.vertices; curveInfo = built.curves; @@ -516,7 +518,11 @@ export async function openRouteEditModal( if (moved) { planned[node] = moved.apex; // 손으로 끌어도 하한 아래로는 안 내려간다 — 거기서 멈춘다(계획서 0-9 ④). - curveRadius[node] = Math.max(limitRadiusM, Math.round(moved.radius * 100) / 100); + // 하한은 그 자리의 교각까지 본 값이라 L 하한도 함께 지켜진다. + curveRadius[node] = Math.max( + radiusFloorM(nodeInfo[node]?.inner_angle_deg, limitRadiusM, limitArcM), + Math.round(moved.radius * 100) / 100, + ); curveOn[node] = true; picked = node; // 손잡이 자리는 다시 셈한 곡선에서 나온다 — 접선 자리가 모자라 R 이 눌리면 손이 @@ -532,12 +538,12 @@ export async function openRouteEditModal( if (dragNode >= 0) { // 옮기기 **전**에 하한을 지키던 자리 — 이미 밑돌던 자리는 그대로 고칠 수 있어야 하므로 // **지키던 자리가 넘어가는 것만** 막는다(계획서 0-9 ④). - const before = curveShortfalls(nodeInfo, limitRadiusM); + const before = curveShortfalls(nodeInfo, limitRadiusM, limitArcM); const previous = planned[dragNode]; dragMoved = true; planned[dragNode] = toMetric(px, py); markEdited(); // 곡선을 그 자리에서 다시 그린다 — 나머지 곡선은 그대로 남는다. - if (shortfallCrossed(before, curveShortfalls(nodeInfo, limitRadiusM))) { + if (shortfallCrossed(before, curveShortfalls(nodeInfo, limitRadiusM, limitArcM))) { // 접선 자리가 모자라 R 이 하한 아래로 눌리는 자리다 — 그 걸음만 되돌린다. planned[dragNode] = previous; markEdited(); diff --git a/B05_Profile/B05_Profile_UI_RouteEdit_CurveBar.ts b/B05_Profile/B05_Profile_UI_RouteEdit_CurveBar.ts index 49170ef7..bd0ba920 100644 --- a/B05_Profile/B05_Profile_UI_RouteEdit_CurveBar.ts +++ b/B05_Profile/B05_Profile_UI_RouteEdit_CurveBar.ts @@ -11,11 +11,15 @@ * ========================================================================== */ import type { EditedCurve, EditedNode, Vertex } from "./B05_Profile_UI_RouteEdit_Curve"; -import type { CurveLock } from "./B05_Profile_UI_RouteEdit_Edits"; +import { + curveOptionalAt, + deflectionRad, + radiusFloorM, + type CurveLock, +} from "./B05_Profile_UI_RouteEdit_Edits"; import { centerDirectionOf, createCurveLabel, - deflectionRad, type CurveLabel, } from "./B05_Profile_UI_RouteEdit_Label"; @@ -130,7 +134,9 @@ export function createCurveBar(params: CurveBarParams): CurveBar { } const pickedCurve = curveInfo.find((entry) => entry.node_first === picked); const shown = curveRadius[picked] ?? pickedCurve?.radius_m ?? null; - const deflection = deflectionRad(nodeInfo[picked]?.inner_angle_deg); + const innerAngle = nodeInfo[picked]?.inner_angle_deg ?? null; + const optional = curveOptionalAt(innerAngle); + const deflection = deflectionRad(innerAngle); const rect = params.canvas.getBoundingClientRect(); const [screenX, screenY] = params.toScreen(planned[picked]); label.show({ @@ -158,8 +164,11 @@ export function createCurveBar(params: CurveBarParams): CurveBar { lock: curveLock[picked] ?? null, apexLocked: apexLock[picked] === true, innerAngleDeg: nodeInfo[picked]?.inner_angle_deg ?? null, - limitRadiusM, - limitArcM, + curveOptional: optional, + // 칸이 막는 하한은 **그 자리 값**이다 — R 칸은 L 하한까지 환산해 함께 보고, + // 곡선을 생략해도 되는 자리(내각 155° 이상)는 L 하한을 안 건다(2026-09-12 확정). + limitRadiusM: radiusFloorM(innerAngle, limitRadiusM, limitArcM), + limitArcM: optional ? 0 : limitArcM, }); } diff --git a/B05_Profile/B05_Profile_UI_RouteEdit_Edits.ts b/B05_Profile/B05_Profile_UI_RouteEdit_Edits.ts index af68eb9e..b8922cfc 100644 --- a/B05_Profile/B05_Profile_UI_RouteEdit_Edits.ts +++ b/B05_Profile/B05_Profile_UI_RouteEdit_Edits.ts @@ -12,6 +12,12 @@ * * ⚠ 접선 자리가 모자라면 그리기 단계에서 R 을 줄이는 것은 그대로다(`buildEditedPolyline`). * 그것은 **그려지는 값**만 줄이고 잠가 둔 값은 안 건드린다 — 자리를 넓히면 되돌아온다. + * + * **하한은 R 과 L 둘 다 본다**(2026-09-12 사용자 확정 「둘 다 지켜야 함」). L = R·Δ 라 + * 한 자리의 하한은 결국 **반지름 하나**로 모인다 — `radiusFloorM` 이 그 값을 낸다. + * 다만 **내각 155° 이상은 뺀다**(별표2 Ⅰ.2.다.(1) 「내각 155도 이상 되는 장소는 곡선을 + * 설치하지 아니할 수 있다」). 거기서 L 을 채우라고 하면 교각이 0 에 가까워 R 이 수십 배로 + * 부풀고, **아무것도 안 고쳤는데 노선이 휜다**(실측: 내각 174.8° 자리가 R 12m → 55m). * ========================================================================== */ import { @@ -20,11 +26,43 @@ import { type EditedNode, type Vertex, } from "./B05_Profile_UI_RouteEdit_Curve"; -import { deflectionRad } from "./B05_Profile_UI_RouteEdit_Label"; /** 무엇을 붙들고 있나. */ export type CurveLock = "radius" | "arc" | null; +/** 그 꺾임점의 **교각 Δ**(라디안) — 내각의 나머지. 곡선 길이 L = R·Δ 에 쓴다. */ +export function deflectionRad(innerAngleDeg: number | null | undefined): number { + if (innerAngleDeg === null || innerAngleDeg === undefined) return 0; + return ((180 - innerAngleDeg) * Math.PI) / 180; +} + +/** 곡선을 **안 둘 수 있는** 내각(도) — 별표2 Ⅰ.2.다.(1) · Ⅰ.3.라.(1). */ +export const CURVE_OPTIONAL_INNER_ANGLE_DEG = 155; + +/** 그 자리에서 곡선을 생략해도 되나 — 내각이 155° 이상이면 그렇다. */ +export function curveOptionalAt(innerAngleDeg: number | null | undefined): boolean { + return innerAngleDeg !== null && innerAngleDeg !== undefined + ? innerAngleDeg >= CURVE_OPTIONAL_INNER_ANGLE_DEG + : false; +} + +/** + * 그 꺾임점의 **못 넘는 반지름 하한**(m) — R 하한과 L 하한을 함께 본 값. + * + * L = R·Δ 이므로 「L ≥ 하한」은 「R ≥ 하한/Δ」와 같다. 둘 중 큰 쪽이 그 자리의 하한이다. + * 내각 155° 이상(곡선 생략 가능)이거나 교각을 모르면 **R 하한만** 본다. + */ +export function radiusFloorM( + innerAngleDeg: number | null | undefined, + limitRadiusM: number, + limitArcM: number, +): number { + if (!(limitArcM > 0) || curveOptionalAt(innerAngleDeg)) return limitRadiusM; + const deflection = deflectionRad(innerAngleDeg); + if (!(deflection > 1e-9)) return limitRadiusM; + return Math.max(limitRadiusM, limitArcM / deflection); +} + /** * **곡선 길이를 잠근 자리**의 반지름을 지금 교각에 맞춰 다시 잡는다(`curveRadius` 를 고침). * @@ -49,36 +87,37 @@ export function applyArcLocks( } /** - * **반지름 하한을 지키도록 지정값을 끌어올린다**(계획서 0-9 ④, 2026-09-12 사용자 확정). + * **하한(R·L)을 지키도록 지정값을 끌어올린다**(계획서 0-9 ④, 2026-09-12 사용자 확정). * * **비워 둔(자동) 자리는 건드리지 않는다** — 자동은 이미 기본 반지름을 쓰고 있고, 여기서 * 값을 적어 넣으면 아무것도 안 고쳤는데 「R 지정」이 늘어난다. * - * ⚠ **곡선 길이(L) 하한은 여기서 안 건다.** L = R·Δ 라, 내각이 179° 처럼 거의 곧은 자리는 - * L 5m 를 채우려면 R 이 286m 로 부풀어 **아무것도 안 고쳤는데 노선이 바뀐다**(2026-09-12 - * 실화면: 길이 1017.5m → 1017.2m). 별표2 도 내각 155° 이상은 곡선을 안 둘 수 있다고 한다. - * L 하한은 **사용자가 칸에 적을 때만** 막고(`_Label`), 패널에 「L ≥ 5m」으로 보이기만 한다. + * 하한은 `radiusFloorM` 이 R·L 을 함께 본 값이다 — 내각 155° 이상은 R 하한만 본다. */ export function applyCurveLimits( planned: Vertex[], curveOn: ReadonlyArray, curveRadius: Array, limitRadiusM: number, + limitArcM = 0, ): void { - if (limitRadiusM <= 0) return; + if (limitRadiusM <= 0 && limitArcM <= 0) return; for (let seat = 1; seat < planned.length - 1; seat += 1) { if (curveOn[seat] === false) continue; const current = curveRadius[seat]; if (current === null || current === undefined) continue; - if (current < limitRadiusM) curveRadius[seat] = limitRadiusM; + const inner = innerAngleDeg(planned[seat - 1], planned[seat], planned[seat + 1]); + const floor = radiusFloorM(inner, limitRadiusM, limitArcM); + if (current < floor) curveRadius[seat] = floor; } } /** - * 노드마다 **반지름 하한**을 얼마나 밑돌고 있나(m). 다 지키고 있으면 0. + * 노드마다 **하한(R·L)** 을 얼마나 밑돌고 있나(m). 다 지키고 있으면 0. * - * 곡선 길이(L) 하한은 여기서도 안 본다 — 까닭은 `applyCurveLimits` 설명에 있다. 거의 곧은 - * 자리에서 L 을 채우라고 막으면 **노드를 한 뼘도 못 옮긴다**. + * 재는 자는 `radiusFloorM` 이다 — L 하한도 반지름으로 환산해 함께 본다. 거의 곧은 자리 + * (내각 155° 이상)는 곡선을 안 둬도 되는 자리라 R 하한만 본다. 그 예외가 없으면 그런 + * 자리에서 **노드를 한 뼘도 못 옮긴다**. * * 노드를 옮기면 접선 자리가 모자라 그리기 단계에서 R 이 눌릴 수 있다. 그 눌림까지 막으려면 * 옮기기 자체를 되돌려야 하므로, **옮기기 전보다 나빠진 자리가 있는지**만 견준다 — 이미 @@ -88,10 +127,16 @@ export function applyCurveLimits( * 무너져도 최댓값이 안 움직여** 그냥 통과한다(실화면에서 「기준 미달 1곳 → 2곳」이 그대로 * 지나갔다). 자리마다 따로 견준다. */ -export function curveShortfalls(nodes: ReadonlyArray, limitRadiusM: number): number[] { +export function curveShortfalls( + nodes: ReadonlyArray, + limitRadiusM: number, + limitArcM = 0, +): number[] { return nodes.map((node) => { - if (node.radius_m === null || limitRadiusM <= 0) return 0; - return Math.max(0, limitRadiusM - node.radius_m); + if (node.radius_m === null) return 0; + const floor = radiusFloorM(node.inner_angle_deg, limitRadiusM, limitArcM); + if (floor <= 0) return 0; + return Math.max(0, floor - node.radius_m); }); } diff --git a/B05_Profile/B05_Profile_UI_RouteEdit_Label.ts b/B05_Profile/B05_Profile_UI_RouteEdit_Label.ts index 1736f758..c71990e8 100644 --- a/B05_Profile/B05_Profile_UI_RouteEdit_Label.ts +++ b/B05_Profile/B05_Profile_UI_RouteEdit_Label.ts @@ -20,13 +20,11 @@ * 다른 꺾임점을 고르면 자동 자리로 돌아간다. * ========================================================================== */ -import type { CurveLock } from "./B05_Profile_UI_RouteEdit_Edits"; +import { CURVE_OPTIONAL_INNER_ANGLE_DEG, type CurveLock } from "./B05_Profile_UI_RouteEdit_Edits"; -/** 그 꺾임점의 **교각 Δ**(라디안) — 내각의 나머지. 곡선 길이 L = R·Δ 에 쓴다. */ -export function deflectionRad(innerAngleDeg: number | null | undefined): number { - if (innerAngleDeg === null || innerAngleDeg === undefined) return 0; - return ((180 - innerAngleDeg) * Math.PI) / 180; -} +// `deflectionRad` 는 화면을 안 만지는 셈이라 `_Edits.ts` 로 옮겼다(2026-09-12) — 순수 +// 함수가 DOM 파일에 얹혀 있으면 시험이 화면째 들여와야 한다. 재수출로 부르던 자리를 지킨다. +export { deflectionRad } from "./B05_Profile_UI_RouteEdit_Edits"; /** 곡선 중심이 있는 **화면 방향**(단위벡터) — 패널을 그 반대쪽에 붙이는 데 쓴다. * @@ -72,6 +70,8 @@ export interface CurveLabelState { lock: CurveLock; /** 교각점(이 꺾임점) 자리를 못 박았나 — 켜면 끌어서 못 옮긴다(2026-09-12 사용자 지시 ①). */ apexLocked: boolean; + /** 내각 155° 이상이라 **곡선을 안 둬도 되는** 자리인가(별표2 Ⅰ.2.다.(1)). */ + curveOptional: boolean; innerAngleDeg: number | null; /** **못 넘는** 반지름·곡선 길이 하한(m). 0이면 제한 없음(계획서 0-9 ④). */ limitRadiusM?: number; @@ -296,9 +296,14 @@ export function createCurveLabel(handlers: CurveLabelHandlers): CurveLabel { const inner = state.innerAngleDeg; // 하단에는 **내각만** 남긴다(2026-09-12 사용자 지시 ㉗) — 고정 여부는 단추 색으로, // 하한은 칸이 이미 막으므로 글로 또 적을 까닭이 없다. + // 내각 155° 이상은 법이 곡선을 안 둬도 된다고 한 자리다 — L 하한을 안 거는 까닭이 + // 여기서 보여야 한다(2026-09-12 사용자 확정). info.textContent = state.curveOn ? inner - ? `내각 ${Math.round(inner)}°` + ? `내각 ${Math.round(inner)}°` + + (state.curveOptional + ? ` · ${CURVE_OPTIONAL_INNER_ANGLE_DEG}° 이상 — 곡선 생략 가능` + : "") : "" : "곡선 없음 — 직선이 그대로 꺾입니다"; place(state); diff --git a/resources/tester/helper_b05_curve_radius_floor.cjs b/resources/tester/helper_b05_curve_radius_floor.cjs new file mode 100644 index 00000000..056a8630 --- /dev/null +++ b/resources/tester/helper_b05_curve_radius_floor.cjs @@ -0,0 +1,95 @@ +/* 계획노선 곡선 **하한(R·L)** 단위검증 헬퍼 — `B05_Profile_UI_RouteEdit_Edits.ts` 를 + * 그 자리에서 트랜스파일해 Node 로 돌린다. 2026-09-12 + * + * ⚠ 확장자가 `.cjs` 인 까닭은 `helper_b05_cut_merged_loop.cjs` 머리에 적힌 것과 같다 — + * 루트 `package.json` 의 `"type": "module"` 때문에 `.js` 는 환경에 따라 ESM 으로 읽힌다. + */ +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(); + +/** TS 한 장을 CommonJS 로 옮겨 실행한다. 상대 import 는 같은 길로 다시 들어온다. */ +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) => + request.startsWith(".") + ? loadTs(path.join(path.dirname(full), `${request}.ts`)) + : require(request); + new Function("exports", "module", "require", js)(box.exports, box, localRequire); + cache.set(full, box.exports); + return box.exports; +} + +const edits = loadTs(path.join(ROOT, "B05_Profile", "B05_Profile_UI_RouteEdit_Edits.ts")); +const { applyCurveLimits, curveShortfalls, radiusFloorM } = edits; + +const LIMIT_R = 12; +const LIMIT_L = 5; + +/** 내각(도)을 이루는 세 점 — 가운데가 꺾임점이고 앞뒤 팔 길이는 넉넉히 200m 다. */ +function cornerAt(innerDeg) { + const half = ((180 - innerDeg) / 2) * (Math.PI / 180); + const arm = 200; + return [ + [-arm * Math.cos(half), arm * Math.sin(half)], + [0, 0], + [arm * Math.cos(half), arm * Math.sin(half)], + ]; +} + +const floors = { + // 내각 140° (교각 40°) — L 5m 은 R 7.16m 이면 차므로 R 하한 12m 이 이긴다. + bend140: radiusFloorM(140, LIMIT_R, LIMIT_L), + // 내각 150° 에 L 하한을 20m 로 키우면 L 쪽이 이긴다(20 / 0.5236 = 38.2m). + bend150LongArc: radiusFloorM(150, LIMIT_R, 20), + // 내각 170° — 별표2 상 곡선 생략 가능 자리라 L 하한을 안 건다(안 걸면 28.6m 로 부푼다). + bend170: radiusFloorM(170, LIMIT_R, LIMIT_L), + bend170NoExempt: LIMIT_L / ((180 - 170) * (Math.PI / 180)), + // 경계값 — 155° 는 「이상」이라 생략 가능 쪽이다. + bend155: radiusFloorM(155, LIMIT_R, LIMIT_L), + bend154: radiusFloorM(154, LIMIT_R, 20), + // 내각을 모르면 R 하한만 본다. + unknown: radiusFloorM(null, LIMIT_R, LIMIT_L), +}; + +// 지정값 끌어올리기 — 내각 150°(L 하한 20m) 자리는 하한까지 오르고, 비워 둔 자리는 그대로. +const planned = cornerAt(150); +const radiusSpecified = [null, 12, null]; +applyCurveLimits(planned, [true, true, true], radiusSpecified, LIMIT_R, 20); +const radiusAuto = [null, null, null]; +applyCurveLimits(planned, [true, true, true], radiusAuto, LIMIT_R, 20); +// 곡선을 지운 자리는 안 건드린다. +const radiusCurveOff = [null, 12, null]; +applyCurveLimits(planned, [true, false, true], radiusCurveOff, LIMIT_R, 20); + +// 모자란 양 — 내각 150° 는 L 하한(20m)까지 재고, 170° 는 R 하한만 잰다. +const shortfalls = curveShortfalls( + [ + { inner_angle_deg: 150, radius_m: 12, tangent_m: null, violations: [] }, + { inner_angle_deg: 170, radius_m: 12, tangent_m: null, violations: [] }, + { inner_angle_deg: 150, radius_m: 40, tangent_m: null, violations: [] }, + ], + LIMIT_R, + 20, +); + +process.stdout.write( + JSON.stringify({ + floors, + applied: { + specified: radiusSpecified[1], + auto: radiusAuto[1], + curveOff: radiusCurveOff[1], + }, + shortfalls, + }), +); diff --git a/resources/tester/test_b05_curve_radius_floor.py b/resources/tester/test_b05_curve_radius_floor.py new file mode 100644 index 00000000..4587a77d --- /dev/null +++ b/resources/tester/test_b05_curve_radius_floor.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +"""계획노선 편집의 **곡선 하한(R·L)** 회귀검증 — 2026-09-12. + +사용자 확정: 「반경과 길이가 트레이드오프기는 하지만 **둘 다 지켜야** 한다」. +L = R·Δ 라 한 자리의 하한은 반지름 하나로 모이고, 그 값을 `radiusFloorM` 이 낸다. + +⚠ 예외 하나 — **내각 155° 이상은 곡선을 설치하지 않을 수 있다**(별표2 Ⅰ.2.다.(1)). +거기서 L 을 채우라고 하면 교각이 0 에 가까워 R 이 수십 배로 부풀고, 아무것도 안 고쳤는데 +노선이 휜다(실측: 내각 174.8° 자리가 R 12m → 55m). 그래서 그 자리는 R 하한만 본다. + +Node 헬퍼(`helper_b05_curve_radius_floor.cjs`)가 TS 를 그 자리에서 트랜스파일해 돌리고, +여기서 값을 판정한다. +""" + +import json +import os +import subprocess + +import pytest + +HERE = os.path.dirname(os.path.abspath(__file__)) + + +@pytest.fixture(scope="module") +def results(): + proc = subprocess.run( + ["node", os.path.join(HERE, "helper_b05_curve_radius_floor.cjs")], + capture_output=True, + text=True, + timeout=60, + ) + assert proc.returncode == 0, proc.stderr + return json.loads(proc.stdout) + + +def test_R_하한이_이기는_자리는_R_하한_그대로(results): + """내각 140° 면 R 12m 만 지켜도 L 이 8.4m 라 L 하한(5m)이 안 건다.""" + assert results["floors"]["bend140"] == pytest.approx(12.0) + + +def test_L_하한이_이기면_R_을_끌어올린다(results): + """내각 150°(교각 30°)에 L 하한 20m 면 R 은 38.2m 이어야 한다 — 여기가 「둘 다」의 핵심.""" + assert results["floors"]["bend150LongArc"] == pytest.approx(20 / (30 * 3.141592653589793 / 180)) + assert results["floors"]["bend150LongArc"] > 12.0 + + +def test_내각_155도_이상은_L_하한을_안_건다(results): + """곡선 생략이 되는 자리다 — 걸었다면 R 이 28.6m 로 부풀어 노선이 조용히 휜다.""" + assert results["floors"]["bend170"] == pytest.approx(12.0) + assert results["floors"]["bend170NoExempt"] > 28.0 # 예외가 없을 때의 값(참고) + assert results["floors"]["bend155"] == pytest.approx(12.0) + + +def test_155도_바로_아래는_L_하한을_건다(results): + """경계는 「155° 이상」이라 154° 는 지켜야 하는 쪽이다.""" + assert results["floors"]["bend154"] > 12.0 + + +def test_내각을_모르면_R_하한만_본다(results): + assert results["floors"]["unknown"] == pytest.approx(12.0) + + +def test_지정한_반지름만_끌어올린다(results): + """비워 둔(자동) 자리는 안 건드린다 — 건드리면 안 고쳤는데 「R 지정」이 늘어난다.""" + applied = results["applied"] + assert applied["specified"] == pytest.approx(20 / (30 * 3.141592653589793 / 180)) + assert applied["auto"] is None + assert applied["curveOff"] == 12 # 곡선을 지운 자리는 그대로 + + +def test_모자란_양도_R과_L을_함께_잰다(results): + """내각 150°(하한 38.2m)에서 R 12m 는 26.2m 모자라고, 170° 는 곡선 생략 자리라 0 이다.""" + short = results["shortfalls"] + assert short[0] == pytest.approx(20 / (30 * 3.141592653589793 / 180) - 12) + assert short[1] == 0 + assert short[2] == 0 # R 40m 는 하한을 넘겼다