diff --git a/src/core/bearing-pair.ts b/src/core/bearing-pair.ts new file mode 100644 index 0000000..fc692f6 --- /dev/null +++ b/src/core/bearing-pair.ts @@ -0,0 +1,115 @@ +/** + * 거더 짝 받침 · 종단경사 S · 솔플레이트 열 두께 (결정 2026-11-06, RAG/받침방위각_솔플레이트검토.md §3, Q-SH1·4·8·9). + * Pure. Not wired into the model yet: the height rule (Q-SH7, 블럭 상면 = z − (T − T_ref)) conflicts with the 2026-11-03 + * C안 already in use (받침높이 H 고정, h3 = H − T, src/core/solplate-rule.ts), so only the parts both rules need live here. + * + * Frame: (E, N) in m as in the model (x = E, y = N). Azimuth: the model's 진북 방위각 (deg, clockwise from north), i.e. the + * workbook CAD angle θ_CAD converted by 90 − θ_CAD. A girder at azimuth θ runs along (sin θ, cos θ). + */ + +export interface PairBearing { + no: number; + x: number; + y: number; + /** z (EL m). Q-SH5: both ends on the 받침블럭 상면 basis; the pier z definition is still spec Q16. */ + z: number; + azimuthDeg: number; +} + +export interface PairStructure { + name: string; + bearings: PairBearing[]; +} + +/** Q-SH1 tolerances and the Q-SH4 azimuth check. */ +export const PAIR_AZIMUTH_TOL_DEG = 0.1; +export const PAIR_OFFSET_TOL_M = 0.1; +export const AZIMUTH_CHECK_SEC = 10; + +export type PairWarning = 'WS01' | 'WS04'; + +export interface BearingPair { + /** The bearing on structure k and its partner on structure k + 1 (structure order A1, P1 … Pn, A2). */ + from: { structure: string; no: number }; + to: { structure: string; no: number }; + /** Horizontal distance (m), distance off the girder line of `from` (m), azimuth difference |θ_to − θ_from| (deg). */ + distanceM: number; + offsetM: number; + azimuthDiffDeg: number; + /** Direction from → to as an azimuth (deg), and its difference from each input azimuth (arc seconds). */ + directionDeg: number; + fromCheckSec: number; + toCheckSec: number; + /** S = (z_to − z_from) / distance × 100 (%), sign along the structure order (− = lower towards the later structure). */ + slopePct: number; + /** The structure on the higher end: the 오르막 쪽 where T1 sits for both bearings. */ + uphill: string; + warnings: PairWarning[]; +} + +const DEG = Math.PI / 180; +const angleDiffDeg = (a: number, b: number) => Math.abs(((a - b + 540) % 360) - 180); + +/** + * Girder pairs between neighbouring structures (Q-SH1, Q-SH4). For each bearing b on structure k the candidates on k + 1 lie + * ahead along b's azimuth, within 0.1° of its azimuth and 0.1 m of its girder line; the closest to the line is the pair + * (WS04 when there were two or more). WS01 when either input azimuth is more than 10″ from the pair direction. + */ +export function girderPairs(structures: PairStructure[]): BearingPair[] { + const pairs: BearingPair[] = []; + for (let k = 0; k + 1 < structures.length; k++) { + const here = structures[k], next = structures[k + 1]; + for (const b of here.bearings) { + const u = { e: Math.sin(b.azimuthDeg * DEG), n: Math.cos(b.azimuthDeg * DEG) }; + const candidates = next.bearings.map((c) => { + const d = { e: c.x - b.x, n: c.y - b.y }; + return { c, along: d.e * u.e + d.n * u.n, offset: Math.abs(d.e * u.n - d.n * u.e), dAz: angleDiffDeg(c.azimuthDeg, b.azimuthDeg), d }; + }).filter((t) => t.along > 0 && t.dAz <= PAIR_AZIMUTH_TOL_DEG && t.offset <= PAIR_OFFSET_TOL_M) + .sort((p, q) => p.offset - q.offset); + if (!candidates.length) continue; + const best = candidates[0]; + const distanceM = Math.hypot(best.d.e, best.d.n); + const directionDeg = (Math.atan2(best.d.e, best.d.n) / DEG + 360) % 360; + const fromCheckSec = angleDiffDeg(directionDeg, b.azimuthDeg) * 3600; + const toCheckSec = angleDiffDeg(directionDeg, best.c.azimuthDeg) * 3600; + const slopePct = ((best.c.z - b.z) / distanceM) * 100; + const warnings: PairWarning[] = []; + if (fromCheckSec > AZIMUTH_CHECK_SEC || toCheckSec > AZIMUTH_CHECK_SEC) warnings.push('WS01'); + if (candidates.length > 1) warnings.push('WS04'); + pairs.push({ + from: { structure: here.name, no: b.no }, to: { structure: next.name, no: best.c.no }, + distanceM, offsetM: best.offset, azimuthDiffDeg: best.dAz, directionDeg, fromCheckSec, toCheckSec, + slopePct, uphill: best.c.z > b.z ? next.name : here.name, warnings, + }); + } + } + return pairs; +} + +/** The pair a bearing belongs to, on either end; undefined when it has none (then WS03 with a fallback S, not done here). */ +export function pairOf(pairs: BearingPair[], structure: string, no: number): BearingPair | undefined { + return pairs.find((p) => (p.from.structure === structure && p.from.no === no) || (p.to.structure === structure && p.to.no === no)); +} + +/** Smallest allowed thin-end thickness T_min (mm, Q-SH3). */ +export const SOLE_T_MIN_MM = 22; + +/** Thickness one bearing needs: T_req = T_min + L·|S|/2 (L mm, S %). */ +export function soleRequiredT(lengthMm: number, slopePct: number, tMinMm: number = SOLE_T_MIN_MM): number { + return tMinMm + (lengthMm * Math.abs(slopePct)) / 200; +} + +/** + * Row thickness and end thicknesses (Q-SH8·9): T_row = max(T_min, ⌈max T_req⌉) over the row; per bearing + * T1 = round(T_row + L·|S|/2) on the 오르막 쪽 and T2 = round(T_row − L·|S|/2) (≥ T_min by construction). + */ +export function soleRowThickness(items: { lengthMm: number; slopePct: number }[], tMinMm: number = SOLE_T_MIN_MM) { + const T = Math.max(tMinMm, Math.ceil(Math.max(...items.map((i) => soleRequiredT(i.lengthMm, i.slopePct, tMinMm))) - 1e-9)); + return { + T, + ends: items.map((i) => { + const half = (i.lengthMm * Math.abs(i.slopePct)) / 200; + return { T1: Math.round(T + half), T2: Math.round(T - half) }; + }), + }; +} diff --git a/tests/bearing-pair.test.ts b/tests/bearing-pair.test.ts new file mode 100644 index 0000000..c400b0c --- /dev/null +++ b/tests/bearing-pair.test.ts @@ -0,0 +1,71 @@ +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import * as XLSX from 'xlsx'; +import { describe, expect, it } from 'vitest'; +import { parseAbutments } from '../src/core/abut/parse'; +import { girderPairs, pairOf, type PairStructure, soleRowThickness } from '../src/core/bearing-pair'; +import { loadP1 } from './helpers'; + +// RAG/받침방위각_솔플레이트검토.md §2 · §6 (Q-SH1·4·8·9). A1 from the RAG workbook's Abut sheet, P1 from the same input. +const RAG = fileURLToPath(new URL('../../../RAG/운곡교P1입력.xlsx', import.meta.url)); +const a1 = parseAbutments(XLSX.read(readFileSync(RAG), { type: 'buffer' })).abutments[0]; +const A1: PairStructure = { name: 'A1', bearings: a1.bearings.map((b) => ({ no: b.no, x: b.pos.e, y: b.pos.n, z: b.z, azimuthDeg: b.azimuthDeg! })) }; +const p1 = loadP1(); +const P1: PairStructure = { name: 'P1', bearings: p1.bearings.map((b) => ({ no: b.no, x: b.x, y: b.y, z: b.z, azimuthDeg: b.azimuthDeg })) }; + +describe('거더 짝 받침 · 종단경사 S (Q-SH1·4·5)', () => { + const pairs = girderPairs([A1, P1]); + + it('pairs A1 ①–⑤ with P1 ①–⑤ on the girder line (offset 0.000 m, azimuth difference ≤ 0.1″)', () => { + expect(pairs.map((p) => [p.from.no, p.to.no])).toEqual([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]); + for (const p of pairs) { + expect(p.offsetM).toBeLessThan(0.0005); + expect(p.fromCheckSec).toBeLessThanOrEqual(0.5); + expect(p.distanceM).toBeCloseTo(48.791, 3); + expect(p.warnings).toEqual([]); + } + }); + + it('S = −1.908 / −1.906 / −1.904 / −1.904 / −1.902 % (상세도 −1.910 … −1.901, ≤ 0.002 %), A1 is the 오르막 쪽', () => { + expect(pairs.map((p) => p.slopePct.toFixed(3))).toEqual(['-1.908', '-1.906', '-1.904', '-1.904', '-1.902']); + const drawing = [-1.910, -1.907, -1.905, -1.903, -1.901]; + pairs.forEach((p, i) => expect(Math.abs(p.slopePct - drawing[i])).toBeLessThanOrEqual(0.0025)); + expect(pairs.every((p) => p.uphill === 'A1')).toBe(true); + }); + + it('P1 back row ⑥–⑩ (next span, P2 not in the workbook) has no pair', () => { + for (const no of [6, 7, 8, 9, 10]) expect(pairOf(pairs, 'P1', no)).toBeUndefined(); + expect(pairOf(pairs, 'P1', 3)!.from).toEqual({ structure: 'A1', no: 3 }); + }); + + it('WS01: P1 ③ azimuth typed as 75°59′ (CAD) is kept but flagged', () => { + const typo: PairStructure = { ...P1, bearings: P1.bearings.map((b) => (b.no === 3 ? { ...b, azimuthDeg: 90 - (75 + 59 / 60) } : b)) }; + const p = girderPairs([A1, typo]).find((q) => q.to.no === 3)!; + expect(p.warnings).toContain('WS01'); + expect(p.toCheckSec).toBeGreaterThan(10); + expect(girderPairs([A1, typo]).filter((q) => q.to.no !== 3).every((q) => !q.warnings.includes('WS01'))).toBe(true); + }); + + it('WS04: two candidates within tolerance → the closest to the girder line is used', () => { + const b1 = P1.bearings[0]; + const extra = { ...b1, no: 99, x: b1.x + 0.05 * Math.cos(b1.azimuthDeg * Math.PI / 180), y: b1.y - 0.05 * Math.sin(b1.azimuthDeg * Math.PI / 180) }; + const p = girderPairs([A1, { ...P1, bearings: [...P1.bearings, extra] }]).find((q) => q.from.no === 1)!; + expect(p.warnings).toContain('WS04'); + expect(p.to.no).toBe(1); + }); +}); + +describe('솔플레이트 열 두께 (Q-SH3·8·9, L 800)', () => { + it('S 1.908 % → T 30, T1 38 / T2 22 (P1 상세도)', () => { + expect(soleRowThickness([{ lengthMm: 800, slopePct: -1.908 }])).toEqual({ T: 30, ends: [{ T1: 38, T2: 22 }] }); + }); + it('S 3 % → T 34, T1 46 / T2 22; S 0 → T 22', () => { + expect(soleRowThickness([{ lengthMm: 800, slopePct: 3 }])).toEqual({ T: 34, ends: [{ T1: 46, T2: 22 }] }); + expect(soleRowThickness([{ lengthMm: 800, slopePct: 0 }]).T).toBe(22); + }); + it('one T per row: the largest requirement wins, the flatter bearing gets a thicker T2', () => { + const row = soleRowThickness([{ lengthMm: 800, slopePct: 3 }, { lengthMm: 800, slopePct: 1 }]); + expect(row.T).toBe(34); + expect(row.ends[1]).toEqual({ T1: 38, T2: 30 }); + }); +});