Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/core/src/agent-operations/add-column.test.ts
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)
})
4 changes: 4 additions & 0 deletions packages/core/src/agent-operations/add-column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export const addColumn: AgentOperation<AddColumnInput> = (nodes, input, context)
y,
z,
rotation,
tiltX,
tiltZ,
...fields
} = input
const node = ColumnNode.parse({
Expand All @@ -90,6 +92,8 @@ export const addColumn: AgentOperation<AddColumnInput> = (nodes, input, context)
z ?? previous?.position[2] ?? 0,
],
rotation: rotation === undefined ? previous?.rotation : (rotation * Math.PI) / 180,
...(tiltX === undefined ? {} : { tiltX: (tiltX * Math.PI) / 180 }),
...(tiltZ === undefined ? {} : { tiltZ: (tiltZ * Math.PI) / 180 }),
...(previous?.source && !compiled ? { source: withSourceMeta(previous.source, input) } : {}),
...(compiled && dimensions
? {
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/agent-operations/scene-view.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { refuse } from '../agent-tools/refusal'
import type { VIEW_SIDES } from '../agent-tools/view-scene'
import { columnPlanLeanOffset } from '../lib/column-geometry'
import type {
AnyNode,
AnyNodeId,
Expand Down Expand Up @@ -230,7 +231,11 @@ function siteBox(node: AnyNode, baseY: number): SceneViewBox | null {
const half =
column.crossSection === 'round' ? column.radius : Math.max(column.width, column.depth) / 2
const [x, , z] = column.position
return { min: [x - half, baseY, z - half], max: [x + half, baseY + column.height, z + half] }
const [dx, dz] = columnPlanLeanOffset(column, column.height)
return {
min: [Math.min(x, x + dx) - half, baseY, Math.min(z, z + dz) - half],
max: [Math.max(x, x + dx) + half, baseY + column.height, Math.max(z, z + dz) + half],
}
}
if (node.type === 'fence') {
const fence = node as FenceNode
Expand Down
22 changes: 18 additions & 4 deletions packages/core/src/agent-tools/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,40 @@ export const addColumnTool = {
}).optional(),
width: measurement('length', 'm', {
positive: true,
description: 'Width when crossSection is "square" / "rectangular" (default: 0.44).',
description:
'Width when crossSection is "square" / "rectangular" / "i-beam" (default: 0.44).',
}).optional(),
depth: measurement('length', 'm', {
positive: true,
description: 'Depth when crossSection is "square" / "rectangular" (default: 0.44).',
description:
'Depth when crossSection is "square" / "rectangular" / "i-beam" (default: 0.44).',
}).optional(),
rotation: measurement('angle', 'deg', {
description: 'Y-axis rotation (default: 0).',
}).optional(),
tiltX: measurement('angle', 'deg', {
min: -45,
max: 45,
description:
'Lean about the column X axis, tipping the top toward its +Z (default: 0). The base stays planted and the top stays level.',
}).optional(),
tiltZ: measurement('angle', 'deg', {
min: -45,
max: 45,
description:
'Lean about the column Z axis, tipping the top toward its -X (default: 0). The base stays planted and the top stays level.',
}).optional(),
style: z
.enum(['plain', 'faceted', 'fluted', 'lathe-turned', 'dravidian-carved', 'cluster'])
.optional()
.describe(
"Visual style: 'plain' (default smooth pillar), 'faceted' (sharp prism faces), 'fluted' (vertical channels — classical), 'lathe-turned' (turned bands — porch / interior), 'dravidian-carved' (heavy carving — temple), 'cluster' (bundled colonnette — gothic).",
),
crossSection: z
.enum(['round', 'square', 'rectangular', 'octagonal', 'sixteen-sided'])
.enum(['round', 'square', 'rectangular', 'octagonal', 'sixteen-sided', 'i-beam'])
.optional()
.describe(
"Plan shape: 'round' (default), 'square' (equal width/depth), 'rectangular' (independent width/depth), 'octagonal', 'sixteen-sided'.",
"Plan shape: 'round' (default), 'square' (equal width/depth), 'rectangular' (independent width/depth), 'octagonal', 'sixteen-sided', 'i-beam' (steel H/I section: flanges span width, web runs along depth).",
),
Comment thread
cursor[bot] marked this conversation as resolved.
level: z
.string()
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ export {
computeCeilingSurfaceCells,
parseCeilingRegionRole,
} from './lib/ceiling-surface'
export {
columnIBeamOutline,
columnIBeamSection,
columnLean,
columnPlanLeanOffset,
sweptPlanFootprint,
} from './lib/column-geometry'
export { isCutterName, resolveCutterHost } from './lib/cutter-host'
export {
clampDoorOperationState,
Expand Down
66 changes: 66 additions & 0 deletions packages/core/src/lib/column-geometry.test.ts
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)
})
77 changes: 77 additions & 0 deletions packages/core/src/lib/column-geometry.ts
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]
}
1 change: 1 addition & 0 deletions packages/core/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export {
export { CeilingNode } from './nodes/ceiling'
export { ChimneyMaterialRole, ChimneyNode } from './nodes/chimney'
export {
COLUMN_MAX_TILT,
COLUMN_PRESETS,
ColumnBaseStyle,
ColumnCapitalStyle,
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/schema/nodes/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { BaseNode, nodeType, objectId } from '../base'
import { GeometryScriptSource } from '../geometry-source'
import { MaterialSchema } from '../material'

/** Steepest lean a column takes about either plan axis (45°). */
export const COLUMN_MAX_TILT = Math.PI / 4

export const ColumnStyle = z.enum([
'plain',
'faceted',
Expand All @@ -19,6 +22,7 @@ export const ColumnCrossSection = z.enum([
'rectangular',
'octagonal',
'sixteen-sided',
'i-beam',
])

export const ColumnShaftProfile = z.enum(['straight', 'tapered', 'bulged', 'baluster', 'hourglass'])
Expand Down Expand Up @@ -88,6 +92,9 @@ export const ColumnNode = BaseNode.extend({
children: z.array(z.string()).default([]),
position: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
rotation: z.number().default(0),
// Lean from vertical in radians, about the column's local X and Z axes. Absent = upright.
tiltX: z.number().min(-COLUMN_MAX_TILT).max(COLUMN_MAX_TILT).optional(),
tiltZ: z.number().min(-COLUMN_MAX_TILT).max(COLUMN_MAX_TILT).optional(),
// Persisted slab-support host — see ItemNode.supportSlabId for the rules.
supportSlabId: z.string().optional(),
source: GeometryScriptSource.optional().describe(
Expand Down Expand Up @@ -172,8 +179,10 @@ export const ColumnNode = BaseNode.extend({
}).describe(dedent`
Column node - used to represent structural or decorative pillars/columns.
- style: visual approach such as plain, lathe-turned, carved, or cluster
- crossSection: plan shape used by the procedural renderer
- crossSection: plan shape used by the procedural renderer; 'i-beam' is a steel H/I section whose flanges span the width at the front and back faces
- height/radius/width/depth: primary dimensions in meters
- tiltX/tiltZ: lean in radians (±π/4) — tiltX tips the top toward local +Z, tiltZ toward local −X;
the column shears, so its base stays planted and its top stays level
- edgeSoftness: bevel radius for square/plinth/block edges
- shaftProfile/shaftDetail: profile and surface treatment of the shaft
- shaftTwistStep: per-segment shaft rotation in degrees
Expand Down
25 changes: 23 additions & 2 deletions packages/editor/src/components/editor/floorplan-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
CeilingNode as CeilingNodeSchema,
type ColumnNode,
calculateLevelMiters,
columnIBeamOutline,
columnPlanLeanOffset,
createSizedStairFlight,
DEFAULT_ANGLE_STEP,
type DoorNode,
Expand Down Expand Up @@ -45,6 +47,7 @@ import {
sceneRegistry,
snapPointAlongAngleRay,
spatialGridManager,
sweptPlanFootprint,
terrainSupportLift,
useInteractive,
useLiveNodeOverrides,
Expand Down Expand Up @@ -2023,6 +2026,17 @@ function getColumnPlanFootprint(column: ColumnNode): Point2D[] {
return getRotatedRectanglePolygon(center, width, depth, column.rotation)
}

if (
column.crossSection === 'i-beam' &&
column.baseStyle === 'none' &&
column.capitalStyle === 'none'
) {
return columnIBeamOutline(column.width, column.depth).map(([localX, localY]) => {
const [offsetX, offsetY] = rotatePlanVector(localX, localY, column.rotation)
return { x: center.x + offsetX, y: center.y + offsetY }
})
}

const shaftWidth =
column.crossSection === 'round' ||
column.crossSection === 'octagonal' ||
Expand All @@ -2046,7 +2060,11 @@ function getColumnPlanFootprint(column: ColumnNode): Point2D[] {
column.depth * column.capitalDepthScale,
)

if (column.crossSection === 'square' || column.crossSection === 'rectangular') {
if (
column.crossSection === 'square' ||
column.crossSection === 'rectangular' ||
column.crossSection === 'i-beam'
) {
return getRotatedRectanglePolygon(center, width, depth, column.rotation)
}

Expand Down Expand Up @@ -5621,7 +5639,10 @@ export function FloorplanPanel({
})

const columnEntries = referenceColumns.flatMap((column) => {
const polygon = getColumnPlanFootprint(column)
const polygon = sweptPlanFootprint(
getColumnPlanFootprint(column).map(({ x, y }): [number, number] => [x, y]),
columnPlanLeanOffset(column, column.height),
).map(([x, y]) => ({ x, y }))
if (polygon.length < 3) {
return []
}
Expand Down
Loading