feat(core): parse P1 workbook and build T-type pier shape

- parse Excel input by header strings (pier, IP, bearing tables)
- DMS azimuth parser (E03), input validation (E01, E02)
- pure geometry: axis, bearings, stepped coping, column, footing, piles, blinding
- warnings W01, W02, W05, W07, I01
- regression tests against spec.md section 12 (P1)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
ypshimandClaude Haiku 5.5 committed 2026-10-21 17:26:16 +09:00
commit d963d8ed3c
15 files changed
+2527

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
const DMS = /(\d+(?:\.\d+)?)°\s*(\d+)'\s*(\d+(?:\.\d+)?)"/;
/** Parses a degree-minute-second string such as ` 75°56'55.9"` into decimal degrees. Returns null when invalid. */
export function parseDms(text: string): number | null {
const m = DMS.exec(String(text));
if (!m) return null;
const deg = Number(m[1]);
const min = Number(m[2]);
const sec = Number(m[3]);
if (min >= 60 || sec >= 60) return null;
return deg + min / 60 + sec / 3600;
}
+335
View File
@@ -0,0 +1,335 @@
import type { PierInput, Row } from './types';
/** Dimensions in m. Sources: intent.PR sheet (P1 rules) and spec.md §3 defaults. */
export const DIM = {
columnDiameter: 2.0,
copingH1: 1.0,
copingH2: 1.5,
levelWidth: 2.1,
padThickness: 0.05,
padSize: 1.0,
blockSize: 1.2,
footingL: 10.4,
footingW: 8.15,
footingH: 2.0,
blindingMargin: 0.2,
blindingT: 0.1,
pileDiameter: 0.6,
pileEnd: 0.7,
pileSpacing: 2.25,
/** Front/back EL difference below this is treated as no lateral step (spec §4.3, Q2). */
lateralTolerance: 0.005,
} as const;
export interface Vec2 {
e: number;
n: number;
}
export interface Segment {
s0: number;
s1: number;
top: number;
}
export interface BearingLocal {
no: number;
row: Row;
s: number;
n: number;
z: number;
}
export interface BlockModel {
no: number;
row: Row;
s: number;
n: number;
bottom: number;
top: number;
padTop: number;
}
export interface ColumnModel {
s: number;
top: number;
bottom: number;
diameter: number;
}
export interface FootingModel {
s: number;
top: number;
bottom: number;
length: number;
width: number;
}
export interface BlindingModel {
s: number;
top: number;
length: number;
width: number;
thickness: number;
}
export interface PileModel {
s: number;
n: number;
top: number;
bottom: number;
diameter: number;
}
export interface PierModel {
name: string;
lengthIp: number;
azimuthDeg: number;
/** Unit vector along the pier axis (east, north). */
u: Vec2;
/** Unit vector across the axis: (u.n, -u.e). Front row is negative, back row positive. */
nrm: Vec2;
ip1: Vec2;
ip2Input: Vec2;
ip2Calc: Vec2;
dIp2: number;
bp1: Vec2;
bp2: Vec2;
/** Horizontal centre of the drawing frame: the centre of the first column. */
pivot: Vec2;
copingL: number;
copingB: number;
copingRefTop: number;
h1: number;
h2: number;
segments: Segment[];
/** Coping elevation outline as (s, EL) points, closed. */
profile: [number, number][];
levelBottom: number;
endBottom: number;
bearings: BearingLocal[];
blocks: BlockModel[];
columns: ColumnModel[];
footings: FootingModel[];
blindings: BlindingModel[];
piles: PileModel[];
groundEl: number;
derived: {
columnHeight: number;
soilCover: number;
pileCount: number;
pileTipEl: number | null;
blockHeightFront: number;
blockHeightBack: number;
frontBackDiffSpread: number;
};
}
function toLocal(p: Vec2, origin: Vec2, u: Vec2, nrm: Vec2): { s: number; n: number } {
const dx = p.e - origin.e;
const dy = p.n - origin.n;
return { s: dx * u.e + dy * u.n, n: dx * nrm.e + dy * nrm.n };
}
/**
* Builds the first-stage (shape only) model of a T-type pier from one input record.
* Pure function: same input always gives the same output. Throws for cases not implemented yet.
*/
export function buildPier(input: PierInput): PierModel {
const ip = (name: string) => {
const p = input.ips.find((q) => q.name === name);
if (!p) throw new Error(`IP 누락: ${name}`);
return p;
};
const ip1 = ip('IP1');
const ip2 = ip('IP2');
const ip3 = ip('IP3');
const ip4 = ip('IP4');
if (ip4.angleDeg !== 0) {
throw new Error('미실시: 꺾인 코핑(IP4 꺾임각 ≠ 0)은 아직 지원하지 않습니다.');
}
const dx = ip3.x - ip1.x;
const dy = ip3.y - ip1.y;
const lengthIp = Math.hypot(dx, dy);
const u: Vec2 = { e: dx / lengthIp, n: dy / lengthIp };
const nrm: Vec2 = { e: u.n, n: -u.e };
const azimuthDeg = (((Math.atan2(u.e, u.n) * 180) / Math.PI) + 360) % 360;
// IP2 is a reference point at a 1:9 division of IP1–IP3 (intent.PR, spec §2.2).
const ip2Calc: Vec2 = { e: ip1.x + 0.1 * dx, n: ip1.y + 0.1 * dy };
const ip2Input: Vec2 = { e: ip2.x, n: ip2.y };
const L = input.copingLengthMm / 1000;
const B = input.copingWidthMm / 1000;
const ip1v: Vec2 = { e: ip1.x, n: ip1.y };
const bp1: Vec2 = { e: ip1v.e + u.e * (lengthIp / 2 - L / 2), n: ip1v.n + u.n * (lengthIp / 2 - L / 2) };
const bp2: Vec2 = { e: bp1.e + u.e * L, n: bp1.n + u.n * L };
const front = input.bearings.filter((b) => b.row === '전열').sort((a, b) => a.no - b.no);
const back = input.bearings.filter((b) => b.row === '후열').sort((a, b) => a.no - b.no);
if (front.length !== back.length) throw new Error('E02: 전열·후열 받침 수가 다릅니다.');
if (front.length < 2) throw new Error('받침이 2개 미만입니다.');
// Bearing block heights (spec §4.3 h1OshoeBlock / h2, pad 50 included). Not the coping end heights (DIM.copingH1/H2).
const h1 = front[0].z - input.copingTopEl;
const h2 = h1 + (back[0].z - front[0].z);
const frontLocal = front.map((b) => ({ no: b.no, row: '전열' as Row, z: b.z, ...toLocal({ e: b.x, n: b.y }, bp1, u, nrm) }));
const backLocal = back.map((b) => ({ no: b.no, row: '후열' as Row, z: b.z, ...toLocal({ e: b.x, n: b.y }, bp1, u, nrm) }));
// Step boundaries sit midway between consecutive front bearings (spec §4.3).
const bounds = [0];
for (let k = 0; k < frontLocal.length - 1; k++) {
bounds.push((frontLocal[k].s + frontLocal[k + 1].s) / 2);
}
bounds.push(L);
const segments: Segment[] = frontLocal.map((b, k) => ({ s0: bounds[k], s1: bounds[k + 1], top: b.z - h1 }));
// Lateral step: front and back coping tops must match segment by segment (not supported yet).
frontLocal.forEach((f, k) => {
const backTop = backLocal[k].z - h2;
if (Math.abs(segments[k].top - backTop) > DIM.lateralTolerance) {
throw new Error('미실시: 횡방향 단차(전열·후열 상면 차 ≥ 5 mm)는 아직 지원하지 않습니다.');
}
});
// Columns (spec §4.5). Multi-column positions are placed; haunch and separate-footing checks are not.
const colS = columnPositions(input.type, L);
// Coping underside: ends at (top − end height h1 = 1000), Level zone at (top − h1 − h2 taper height = 1500).
const levelBottom = input.copingTopEl - DIM.copingH1 - DIM.copingH2;
const endBottom = input.copingTopEl - DIM.copingH1;
const levelStart = Math.min(...colS) - DIM.levelWidth / 2;
const levelEnd = Math.max(...colS) + DIM.levelWidth / 2;
if (levelStart < 0 || levelEnd > L) throw new Error('코핑 길이가 Level 구간보다 짧습니다.');
const profile: [number, number][] = [[0, endBottom]];
for (const seg of segments) {
profile.push([seg.s0, seg.top], [seg.s1, seg.top]);
}
profile.push([L, endBottom], [levelEnd, levelBottom], [levelStart, levelBottom], [0, endBottom]);
profile.pop(); // the last point repeats the first one
const footingTop = input.foundationType === '현장타설말뚝' ? input.footingBottomEl : input.footingBottomEl + DIM.footingH;
const columns: ColumnModel[] = colS.map((s) => ({
s,
top: levelBottom,
bottom: footingTop,
diameter: DIM.columnDiameter,
}));
const footings: FootingModel[] = [];
const blindings: BlindingModel[] = [];
const piles: PileModel[] = [];
const pileLength = input.pileLengthMm / 1000;
const pileTip = input.footingBottomEl - pileLength;
for (const s of colS) {
if (input.foundationType === '현장타설말뚝') {
piles.push({ s, n: 0, top: input.footingBottomEl, bottom: pileTip, diameter: DIM.columnDiameter });
continue;
}
footings.push({ s, top: footingTop, bottom: input.footingBottomEl, length: DIM.footingL, width: DIM.footingW });
blindings.push({
s,
top: input.footingBottomEl,
length: DIM.footingL + DIM.blindingMargin,
width: DIM.footingW + DIM.blindingMargin,
thickness: DIM.blindingT,
});
if (input.foundationType === '말뚝기초') {
piles.push(...pilesFor(s, input.footingBottomEl, pileLength));
}
}
const blocks: BlockModel[] = [];
frontLocal.forEach((b) => {
const bottom = segmentTop(segments, b.s);
blocks.push({ no: b.no, row: '전열', s: b.s, n: b.n, bottom, top: b.z - DIM.padThickness, padTop: b.z });
});
backLocal.forEach((b) => {
const bottom = b.z - h2;
blocks.push({ no: b.no, row: '후열', s: b.s, n: b.n, bottom, top: b.z - DIM.padThickness, padTop: b.z });
});
const blockHeightFront = blocks.find((b) => b.row === '전열')!.top - blocks.find((b) => b.row === '전열')!.bottom;
const blockHeightBack = blocks.find((b) => b.row === '후열')!.top - blocks.find((b) => b.row === '후열')!.bottom;
const diffs = frontLocal.map((f, k) => f.z - backLocal[k].z);
const frontBackDiffSpread = Math.max(...diffs) - Math.min(...diffs);
return {
name: input.name,
lengthIp,
azimuthDeg,
u,
nrm,
ip1: ip1v,
ip2Input,
ip2Calc,
dIp2: (ip2Calc.e - bp1.e) * u.e + (ip2Calc.n - bp1.n) * u.n,
bp1,
bp2,
pivot: { e: bp1.e + u.e * (L / 2), n: bp1.n + u.n * (L / 2) },
copingL: L,
copingB: B,
copingRefTop: input.copingTopEl,
h1,
h2,
segments,
profile,
levelBottom,
endBottom,
bearings: [...frontLocal, ...backLocal].map((b) => ({ no: b.no, row: b.row, s: b.s, n: b.n, z: b.z })),
blocks,
columns,
footings,
blindings,
piles,
groundEl: input.groundEl,
derived: {
columnHeight: levelBottom - columns[0].bottom,
soilCover: input.groundEl - (input.foundationType === '현장타설말뚝' ? input.footingBottomEl : footingTop),
pileCount: piles.length,
pileTipEl: piles.length ? pileTip : null,
blockHeightFront,
blockHeightBack,
frontBackDiffSpread,
},
};
}
export function columnPositions(type: PierInput['type'], L: number): number[] {
if (type === 'T형') return [L / 2];
if (type === '2주형') return [L / 5, L - L / 5];
return [L / 5, L / 2, L - L / 5];
}
function segmentTop(segments: Segment[], s: number): number {
const hit = segments.find((seg) => s >= seg.s0 && s < seg.s1) ?? segments[segments.length - 1];
return hit.top;
}
/**
* Piles under one footing (spec §4.6): rows across the footing width, piles along the length,
* both with an end distance of 0.7 m and an even spacing that never exceeds 2.25 m.
*/
export function pilesFor(s: number, topEl: number, length: number): PileModel[] {
const span = (size: number) => Math.floor((size - 2 * DIM.pileEnd) / DIM.pileSpacing) + 1;
const countS = span(DIM.footingL);
const countN = span(DIM.footingW);
const spacingS = (DIM.footingL - 2 * DIM.pileEnd) / (countS - 1);
const spacingN = (DIM.footingW - 2 * DIM.pileEnd) / (countN - 1);
const out: PileModel[] = [];
for (let i = 0; i < countS; i++) {
for (let j = 0; j < countN; j++) {
out.push({
s: s + (i - (countS - 1) / 2) * spacingS,
n: (j - (countN - 1) / 2) * spacingN,
top: topEl,
bottom: topEl - length,
diameter: DIM.pileDiameter,
});
}
}
return out;
}
+121
View File
@@ -0,0 +1,121 @@
import * as XLSX from 'xlsx';
import { parseDms } from './dms';
import type { Bearing, FoundationType, Issue, IpPoint, PierInput, PierType, Row } from './types';
type Cell = string | number | null | undefined;
type Grid = Cell[][];
export interface ParseResult {
piers: PierInput[];
issues: Issue[];
}
const PIER_TYPES: PierType[] = ['T형', '2주형', '3주형'];
const FOUNDATION_TYPES: FoundationType[] = ['말뚝기초', '직접기초', '현장타설말뚝'];
/** Reads every sheet and collects the pier tables found by their header strings (position-independent). */
export function parseWorkbook(wb: XLSX.WorkBook): ParseResult {
const piers: PierInput[] = [];
const issues: Issue[] = [];
for (const sheetName of wb.SheetNames) {
const ws = wb.Sheets[sheetName];
const grid = XLSX.utils.sheet_to_json<Cell[]>(ws, { header: 1, raw: true, defval: null }) as Grid;
piers.push(...parseSheet(grid, sheetName, issues));
}
return { piers, issues };
}
function parseSheet(grid: Grid, sheet: string, issues: Issue[]): PierInput[] {
const pierHeaders = findHeaders(grid, (r) => r[0] === '교각명' && r[1] === '교각형식');
const ipHeaders = findHeaders(grid, (r) => r[0] === '교각명' && r[1] === 'IP점');
const bearingHeaders = findHeaders(grid, (r) => r[0] === '교각명' && r[1] === '받침번호');
const ips = ipHeaders.flatMap((h) => readBlock(grid, h).map((r) => toIp(r)));
const bearings: { pier: string; bearing: Bearing; row: number; azimuthOk: boolean }[] = [];
for (const h of bearingHeaders) {
for (const { cells, index } of readBlock(grid, h)) {
const azimuth = parseDms(String(cells[5] ?? ''));
bearings.push({
pier: String(cells[0]),
row: index + 1,
azimuthOk: azimuth !== null,
bearing: {
no: Number(cells[1]),
x: Number(cells[2]),
y: Number(cells[3]),
z: Number(cells[4]),
azimuthDeg: azimuth ?? NaN,
row: String(cells[6]) as Row,
},
});
}
}
const piers: PierInput[] = [];
for (const h of pierHeaders) {
for (const { cells, index } of readBlock(grid, h)) {
const name = String(cells[0]);
const bad = bearings.find((b) => b.pier === name && !b.azimuthOk);
if (bad) {
issues.push({
code: 'E03',
level: 'E',
pier: name,
message: `${sheet} ${bad.row}행: 방위각 문자열을 읽을 수 없습니다. 예: 75°56'55.9"`,
});
continue;
}
const type = String(cells[1]) as PierType;
const foundation = String(cells[5]) as FoundationType;
if (!PIER_TYPES.includes(type) || !FOUNDATION_TYPES.includes(foundation)) {
issues.push({ code: 'E01', level: 'E', pier: name, message: `${sheet} ${index + 1}행: 교각형식 또는 기초 형식을 알 수 없습니다.` });
continue;
}
piers.push({
name,
type,
copingTopEl: Number(cells[2]),
footingBottomEl: Number(cells[3]),
groundEl: Number(cells[4]),
foundationType: foundation,
pileLengthMm: Number(cells[6]),
copingWidthMm: Number(cells[7]),
copingLengthMm: Number(cells[8]),
columnCount: Number(cells[9]),
ips: ips.filter((p) => p.pier === name).map((p) => p.ip),
bearings: bearings.filter((b) => b.pier === name).map((b) => b.bearing),
});
}
}
return piers;
}
function findHeaders(grid: Grid, match: (row: Cell[]) => boolean): number[] {
const out: number[] = [];
grid.forEach((row, i) => {
if (match(row)) out.push(i);
});
return out;
}
/** Reads the data rows under a header until the first blank row. Blank pier-name cells inherit the row above. */
function readBlock(grid: Grid, header: number): { cells: Cell[]; index: number }[] {
const out: { cells: Cell[]; index: number }[] = [];
let lastName: Cell = null;
for (let i = header + 1; i < grid.length; i++) {
const row = grid[i] ?? [];
if (row[1] === null || row[1] === undefined || row[1] === '') break;
const name: Cell = row[0] ?? lastName;
lastName = name;
out.push({ cells: [name, ...row.slice(1)], index: i });
}
return out;
}
function toIp(entry: { cells: Cell[]; index: number }): { pier: string; ip: IpPoint } {
const c = entry.cells;
return {
pier: String(c[0]),
ip: { name: String(c[1]), x: Number(c[2]), y: Number(c[3]), angleDeg: Number(c[4] ?? 0) },
};
}
+44
View File
@@ -0,0 +1,44 @@
export type PierType = 'T형' | '2주형' | '3주형';
export type FoundationType = '말뚝기초' | '직접기초' | '현장타설말뚝';
export type Row = '전열' | '후열';
/** Inputs are stored as the sheet gives them: coordinates in m, EL in m, lengths in mm. */
export interface IpPoint {
name: string;
x: number;
y: number;
angleDeg: number;
}
export interface Bearing {
no: number;
x: number;
y: number;
z: number;
azimuthDeg: number;
row: Row;
}
export interface PierInput {
name: string;
type: PierType;
copingTopEl: number;
footingBottomEl: number;
groundEl: number;
foundationType: FoundationType;
pileLengthMm: number;
copingWidthMm: number;
copingLengthMm: number;
columnCount: number;
ips: IpPoint[];
bearings: Bearing[];
}
export type IssueLevel = 'E' | 'W' | 'I';
export interface Issue {
code: string;
level: IssueLevel;
pier?: string;
message: string;
}
+69
View File
@@ -0,0 +1,69 @@
import { DIM, type PierModel } from './geometry';
import type { Issue, PierInput, PierType } from './types';
const EXPECTED_COLUMNS: Record<PierType, number> = { 'T형': 1, '2주형': 2, '3주형': 3 };
/** Rules from spec §10 that are not implemented in this stage. Shown to the user, never silently skipped. */
export const NOT_IMPLEMENTED_RULES = [
'E04 fck 미입력 (배근 단계, 3단계)',
'W03 받침 중심 ~ 계단 경계 < 블럭 폭/2',
'W04 블럭이 코핑 평면 밖',
'W06 속성 복사 건너뜀 (2단계)',
'W08 솔플레이트 T1−T2 검사 (2단계)',
'다주형 코핑 헌치·Level−300 (Q3), 일체기초 판정 (2·3주형)',
] as const;
/** Input-level checks (spec §10 E01, E02). Returns false when the pier must not be built. */
export function validateInput(input: PierInput, issues: Issue[]): boolean {
let ok = true;
if (input.columnCount !== EXPECTED_COLUMNS[input.type]) {
issues.push({
code: 'E01',
level: 'E',
pier: input.name,
message: `교각형식 ${input.type}과 기둥갯수 ${input.columnCount}개가 맞지 않습니다. 기둥 ${EXPECTED_COLUMNS[input.type]}개로 맞추세요.`,
});
ok = false;
}
const front = input.bearings.filter((b) => b.row === '전열').length;
const back = input.bearings.filter((b) => b.row === '후열').length;
if (front !== back) {
issues.push({ code: 'E02', level: 'E', pier: input.name, message: `전열 받침 ${front}개, 후열 받침 ${back}개로 수가 다릅니다.` });
ok = false;
}
return ok;
}
/** Geometry-level checks (spec §10 W01, W02, W05, W07, I01) on a built model. */
export function validatePier(input: PierInput, model: PierModel, issues: Issue[]): void {
const ip2Gap = Math.hypot(model.ip2Input.e - model.ip2Calc.e, model.ip2Input.n - model.ip2Calc.n);
if (ip2Gap > 0.001) {
issues.push({
code: 'W01',
level: 'W',
pier: input.name,
message: `IP2 입력과 재계산값이 ${(ip2Gap * 1000).toFixed(1)} mm 다릅니다. 재계산값을 사용합니다.`,
});
}
const minBlock = Math.min(model.derived.blockHeightFront, model.derived.blockHeightBack);
if (minBlock <= 0) {
issues.push({ code: 'W02', level: 'W', pier: input.name, message: '받침블럭 콘크리트 높이가 0 이하입니다. 블럭을 생략합니다.' });
}
if (input.foundationType !== '현장타설말뚝' && model.footings.some((f) => f.top > input.groundEl)) {
issues.push({ code: 'W05', level: 'W', pier: input.name, message: '확대기초 상면이 지반고보다 높습니다.' });
}
if (model.derived.frontBackDiffSpread > DIM.lateralTolerance) {
issues.push({ code: 'W07', level: 'I', pier: input.name, message: '전열·후열 EL 차이가 받침마다 다릅니다 (정보).' });
}
// I01: block concrete below cover + bar diameter (cover 100 mm, S1·S2 H19 from spec §6.3).
const cover = 0.1;
const barDia = 0.019;
if (minBlock < cover + barDia) {
issues.push({
code: 'I01',
level: 'I',
pier: input.name,
message: `받침블럭 높이 ${(minBlock * 1000).toFixed(0)} mm가 피복 + 철근 지름(${((cover + barDia) * 1000).toFixed(0)} mm)보다 작습니다. 블럭 철근은 코핑 안에 묻힙니다.`,
});
}
}