Repository navigation
feat(nodes): steel i-beam profile and slanted columns support #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ovurrsl
wants to merge
2
commits into
pascalorg:main
Choose a base branch
from
ovurrsl:feat/column-enhancements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { expect, test } from 'bun:test' | ||
| import { z } from 'zod' | ||
| import { addColumnTool } from '../agent-tools/columns' | ||
| import { type ColumnNode, LevelNode } from '../schema' | ||
| import { addColumn } from './add-column' | ||
|
|
||
| const level = LevelNode.parse({ id: 'level_columns' }) | ||
| const nodes = { [level.id]: level } | ||
| const context = { activeLevelId: level.id } | ||
| const input = z.object(addColumnTool.input) | ||
|
|
||
| function created(outcome: ReturnType<typeof addColumn>) { | ||
| return outcome.changes?.create?.[0]?.node as ColumnNode | ||
| } | ||
|
|
||
| test('add_column creates an i-beam column', () => { | ||
| const column = created( | ||
| addColumn( | ||
| nodes, | ||
| input.parse({ x: 1, z: 2, crossSection: 'i-beam', width: 0.3, depth: 0.4 }), | ||
| context, | ||
| ), | ||
| ) | ||
| expect(column.crossSection).toBe('i-beam') | ||
| expect(column.width).toBe(0.3) | ||
| expect(column.depth).toBe(0.4) | ||
| expect(column.position).toEqual([1, 0, 2]) | ||
| }) | ||
|
|
||
| test('add_column takes tilt in degrees and stores radians', () => { | ||
| const column = created( | ||
| addColumn(nodes, input.parse({ x: 0, z: 0, tiltX: 10, tiltZ: '-5°' }), context), | ||
| ) | ||
| expect(column.tiltX).toBeCloseTo((10 * Math.PI) / 180, 12) | ||
| expect(column.tiltZ).toBeCloseTo((-5 * Math.PI) / 180, 12) | ||
| expect(() => input.parse({ x: 0, z: 0, tiltX: 50 })).toThrow() | ||
|
|
||
| const upright = created(addColumn(nodes, input.parse({ x: 0, z: 0 }), context)) | ||
| expect('tiltX' in upright || 'tiltZ' in upright).toBe(false) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { expect, test } from 'bun:test' | ||
| import { | ||
| columnIBeamOutline, | ||
| columnIBeamSection, | ||
| columnLean, | ||
| columnPlanLeanOffset, | ||
| sweptPlanFootprint, | ||
| } from './column-geometry' | ||
|
|
||
| test('i-beam plates scale with the section and keep a minimum thickness', () => { | ||
| expect(columnIBeamSection(0.3, 0.4)).toEqual({ | ||
| flangeThickness: expect.closeTo(0.04, 9), | ||
| webThickness: expect.closeTo(0.03, 9), | ||
| }) | ||
| expect(columnIBeamSection(0.05, 0.05)).toEqual({ flangeThickness: 0.01, webThickness: 0.01 }) | ||
| }) | ||
|
|
||
| test('i-beam outline spans the section with a web narrower than the flanges', () => { | ||
| const outline = columnIBeamOutline(0.3, 0.4) | ||
| expect(outline).toHaveLength(12) | ||
| const xs = outline.map(([x]) => x) | ||
| const zs = outline.map(([, z]) => z) | ||
| expect(Math.min(...xs)).toBeCloseTo(-0.15) | ||
| expect(Math.max(...xs)).toBeCloseTo(0.15) | ||
| expect(Math.min(...zs)).toBeCloseTo(-0.2) | ||
| expect(Math.max(...zs)).toBeCloseTo(0.2) | ||
| // The web edge sits half a web thickness off the axis. | ||
| expect(outline[3]).toEqual([expect.closeTo(0.015, 9), expect.closeTo(-0.16, 9)]) | ||
| // Shoelace area: two flanges plus the web. | ||
| const area = | ||
| Math.abs( | ||
| outline.reduce((sum, [x, z], i) => { | ||
| const [nx, nz] = outline[(i + 1) % outline.length]! | ||
| return sum + x * nz - nx * z | ||
| }, 0), | ||
| ) / 2 | ||
| expect(area).toBeCloseTo(2 * 0.3 * 0.04 + 0.03 * 0.32, 9) | ||
| }) | ||
|
|
||
| test('a leaning column shears its section by height, in the yawed plan frame', () => { | ||
| const tilt = Math.PI / 8 | ||
| expect(columnLean({ tiltX: tilt })).toEqual([0, expect.closeTo(Math.tan(tilt), 12)]) | ||
| expect(columnLean({ tiltZ: tilt })).toEqual([expect.closeTo(-Math.tan(tilt), 12), 0]) | ||
| expect(columnPlanLeanOffset({ tiltX: tilt, rotation: 0 }, 0)).toEqual([0, 0]) | ||
| const [x, z] = columnPlanLeanOffset({ tiltX: tilt, rotation: Math.PI / 2 }, 2) | ||
| // Local +Z turns to plan +X under a quarter turn of yaw. | ||
| expect(x).toBeCloseTo(2 * Math.tan(tilt), 12) | ||
| expect(z).toBeCloseTo(0, 12) | ||
| }) | ||
|
|
||
| test('a swept footprint covers the base, the top and the band between', () => { | ||
| const square: [number, number][] = [ | ||
| [-0.5, -0.5], | ||
| [0.5, -0.5], | ||
| [0.5, 0.5], | ||
| [-0.5, 0.5], | ||
| ] | ||
| expect(sweptPlanFootprint(square, [0, 0])).toEqual(square) | ||
| const swept = sweptPlanFootprint(square, [2, 0]) | ||
| const xs = swept.map(([px]) => px) | ||
| expect(Math.min(...xs)).toBeCloseTo(-0.5) | ||
| expect(Math.max(...xs)).toBeCloseTo(2.5) | ||
| const diagonal = sweptPlanFootprint(square, [1, 1]) | ||
| // A square swept along its diagonal is a hexagon. | ||
| expect(diagonal).toHaveLength(6) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import type { ColumnNode } from '../schema/nodes/column' | ||
| import { union } from './polygon-boolean' | ||
|
|
||
| /** | ||
| * Plate thicknesses of an i-beam column. The flanges span the width (local X) | ||
| * at the front and back faces; the web joins them along the depth (local Z). | ||
| */ | ||
| export function columnIBeamSection( | ||
| width: number, | ||
| depth: number, | ||
| ): { flangeThickness: number; webThickness: number } { | ||
| return { | ||
| flangeThickness: Math.max(0.01, depth * 0.1), | ||
| webThickness: Math.max(0.01, width * 0.1), | ||
| } | ||
| } | ||
|
|
||
| /** Plan outline of an i-beam section centred on the column axis, in local XZ. */ | ||
| export function columnIBeamOutline(width: number, depth: number): [number, number][] { | ||
| const { flangeThickness, webThickness } = columnIBeamSection(width, depth) | ||
| const x = width / 2 | ||
| const z = depth / 2 | ||
| const webX = webThickness / 2 | ||
| const innerZ = Math.max(0, z - flangeThickness) | ||
| return [ | ||
| [-x, -z], | ||
| [x, -z], | ||
| [x, -innerZ], | ||
| [webX, -innerZ], | ||
| [webX, innerZ], | ||
| [x, innerZ], | ||
| [x, z], | ||
| [-x, z], | ||
| [-x, innerZ], | ||
| [-webX, innerZ], | ||
| [-webX, -innerZ], | ||
| [-x, -innerZ], | ||
| ] | ||
| } | ||
|
|
||
| /** | ||
| * How far a leaning column's section moves per metre of height, in its local | ||
| * XZ. A column leans by shearing, not rotating: tiltX tips the top toward +Z | ||
| * and tiltZ toward −X (the senses of right-handed rotations about those axes), | ||
| * while the base stays planted and every horizontal section stays level. | ||
| */ | ||
| export function columnLean(column: Pick<ColumnNode, 'tiltX' | 'tiltZ'>): [number, number] { | ||
| return [-Math.tan(column.tiltZ ?? 0) || 0, Math.tan(column.tiltX ?? 0)] | ||
| } | ||
|
|
||
| /** Level-plan offset of a leaning column's section at height `y`, after its yaw. */ | ||
| export function columnPlanLeanOffset( | ||
| column: Pick<ColumnNode, 'tiltX' | 'tiltZ' | 'rotation'>, | ||
| y: number, | ||
| ): [number, number] { | ||
| const [x, z] = columnLean(column) | ||
| const cos = Math.cos(column.rotation) | ||
| const sin = Math.sin(column.rotation) | ||
| return [(x * cos + z * sin) * y, (-x * sin + z * cos) * y] | ||
| } | ||
|
|
||
| /** | ||
| * Plan area a footprint covers while sliding by `offset`: the footprint, its | ||
| * shifted copy and the band each edge sweeps. Returned unchanged when nothing moves. | ||
| */ | ||
| export function sweptPlanFootprint( | ||
| points: readonly [number, number][], | ||
| [dx, dz]: readonly [number, number], | ||
| ): [number, number][] { | ||
| if (Math.hypot(dx, dz) < 1e-9 || points.length < 3) return [...points] | ||
| const shifted = points.map(([x, z]): [number, number] => [x + dx, z + dz]) | ||
| const bands = points.map((point, i): [number, number][] => { | ||
| const next = (i + 1) % points.length | ||
| return [point, points[next]!, shifted[next]!, shifted[i]!] | ||
| }) | ||
| return union([[...points], shifted, ...bands])[0]?.outer ?? [...points] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.