Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0254b82
feat(wall): add endHeightOffset for sloped walls
Aug 17, 2026
e93a231
fix(wall): address review feedback for sloped wall end-height
vducasse Aug 29, 2026
40a1800
fix(wall): address review feedback on snapping, formatting, slider li…
vducasse Sep 1, 2026
f12f6c1
fix(editor): emit unsupported diagnostic for sloped walls in print co…
vducasse Sep 1, 2026
e2dd5d3
Merge branch 'main' into feat/wall-end-height
cursoragent Nov 9, 2026
5a5f9db
fix(core): default getWallEffectiveHeightForNodes to the lower end of…
cursoragent Nov 9, 2026
cdfad81
test(nodes): expect fits from the curtain door and window clamps
cursoragent Nov 9, 2026
089aecf
i18n: extract the wall end height offset label
cursoragent Nov 9, 2026
54cf353
fix(core): keep resolveWallTop's authored storey height in fourth place
cursoragent Nov 9, 2026
fa6f401
fix(wall): read a curved wall's sloped top at the chord position of e…
cursoragent Nov 9, 2026
25ff6d3
fix(wall): gate door and window placement on fit only under a sloped top
cursoragent Nov 9, 2026
cd1b22f
fix(wall): split a sloped wall into pieces whose tops continue the line
cursoragent Nov 9, 2026
402ca19
fix(wall): merge and heal sloped walls only when their tops continue …
cursoragent Nov 9, 2026
6a482e9
fix(ifc): export a sloped wall top as a clipped body
cursoragent Nov 9, 2026
0fa47c5
fix(wall): drop the static max on the end height offset field
cursoragent Nov 9, 2026
4a951be
test(viewer): pin the sloped wall's top at both ends
cursoragent Nov 9, 2026
bcace73
fix(agents): refuse an opening that fits nowhere under a sloped wall'…
cursoragent Nov 9, 2026
fefd5ca
Merge origin/main into the wall endHeightOffset branch
cursoragent Nov 9, 2026
449d83e
fix(viewer): keep mitered sloped-wall top vertices above the base
cursoragent Nov 9, 2026
bc3b712
fix(agents): clamp a sloped-wall door before refusing it as too tall
cursoragent Nov 9, 2026
509b34f
fix(usage-field): mark a sloped wall's full-height prism approximate
cursoragent Nov 9, 2026
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
10 changes: 7 additions & 3 deletions packages/core/src/agent-operations/author-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
WINDOW_STYLES,
type WindowStyle,
} from '../building/opening-style-presets'
import { doorFacing, resolveWallOpeningCeiling } from '../building/wall-openings'
import { doorFacing, wallOpeningCeilingOver } from '../building/wall-openings'
import {
NEW_WINDOW_FRAME_THICKNESS,
windowTakesStyle,
Expand Down Expand Up @@ -1079,8 +1079,12 @@ export function authorScene(
}
if (o.kind === 'door') {
const wallHeight =
resolveWallOpeningCeiling(node, draft) -
(node.wallType === 'curtain' ? getCurtainWallConfig(node).perimeterWidth : 0)
wallOpeningCeilingOver(
node,
draft,
o.along - size.width / 2,
o.along + size.width / 2,
) - (node.wallType === 'curtain' ? getCurtainWallConfig(node).perimeterWidth : 0)
if (o.sill + size.height > wallHeight + 1e-6) {
defect(
id,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent-operations/level-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function wallResolvedHeight(nodes: SceneNodes, wall: WallNode): number {
nodes as Record<AnyNodeId, AnyNode>,
)
return (
getWallTop(wall, levelId, nodes as Record<AnyNodeId, AnyNode>, support.elevation) -
getWallTop(wall, levelId, nodes as Record<AnyNodeId, AnyNode>, support.elevation, 0) -
support.elevation
)
}
Expand Down
42 changes: 28 additions & 14 deletions packages/core/src/agent-operations/move-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
clampDoorToWall,
clampWindowToWall,
findWallChildOverlap,
resolveWallOpeningCeiling,
refuseOpeningAboveSlope,
wallOpeningCeilingOver,
} from '../building/wall-openings'
import { getDoorOpeningSize } from '../lib/door-opening'
import { openingHostFacing } from '../lib/opening-casing'
Expand Down Expand Up @@ -231,27 +232,23 @@ function planOpeningMove(
`Wall ${wall.id} is ${length.toFixed(2)} m long, too short for this ${cutout.width.toFixed(2)} m ${node.type}.`,
{ id: node.id, wallId: wall.id, wallLength: length, width: cutout.width },
)
if (node.type === 'door') {
const wallHeight =
resolveWallOpeningCeiling(wall, nodes as Record<AnyNodeId, AnyNode>) -
(wall.wallType === 'curtain' ? getCurtainWallConfig(wall).perimeterWidth : 0)
if (cutout.height > wallHeight + 1e-6)
refuse(
'wall_too_low',
`Wall ${wall.id} is ${wallHeight.toFixed(2)} m high, too low for this ${cutout.height.toFixed(2)} m door.`,
{ id: node.id, wallId: wall.id, wallHeight, height: cutout.height },
)
}
const rawX = desiredLocalX(wall, node, target)
const rawY =
node.type === 'door'
? node.height / 2
: target.y === undefined
? node.position[1]
: target.y + node.height / 2
const { clampedX, clampedY } =
const { clampedX, clampedY, fits } =
node.type === 'door'
? clampDoorToWall(wall, rawX, node.width, node.height, node)
? clampDoorToWall(
wall,
rawX,
node.width,
node.height,
node,
nodes as Record<AnyNodeId, AnyNode>,
)
: clampWindowToWall(
wall,
rawX,
Expand All @@ -260,6 +257,23 @@ function planOpeningMove(
node.height,
nodes as Record<AnyNodeId, AnyNode>,
)
if (!fits) refuseOpeningAboveSlope(wall, nodes, node.type, node.width, node.height)
// Checked where the clamp put the door: under a sloped top it may have slid to the high end.
if (node.type === 'door') {
const wallHeight =
wallOpeningCeilingOver(
wall,
nodes as Record<AnyNodeId, AnyNode>,
clampedX - cutoutOffsetX - cutout.width / 2,
clampedX - cutoutOffsetX + cutout.width / 2,
) - (wall.wallType === 'curtain' ? getCurtainWallConfig(wall).perimeterWidth : 0)
if (cutout.height > wallHeight + 1e-6)
refuse(
'wall_too_low',
`Wall ${wall.id} is ${wallHeight.toFixed(2)} m high, too low for this ${cutout.height.toFixed(2)} m door.`,
{ id: node.id, wallId: wall.id, wallHeight, height: cutout.height },
)
}
overlapRefusal(
nodes,
wall,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/agent-operations/verify-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,10 @@ export const verifyScene: AgentOperation<VerifySceneInput | undefined> = (
for (const level of levels) {
for (const wall of ofType(onLevel(level.levelId), 'wall')) {
const base = wallSupportForNodes(wall, nodes).elevation
const wallTop = getWallTop(wall, level.levelId, nodes, base)
const wallTop = Math.max(
getWallTop(wall, level.levelId, nodes, base, 0),
getWallTop(wall, level.levelId, nodes, base, 1),
)
for (const { slab, top: slabTop, underside: slabUnderside } of getWallCoveringSlabs(
wall,
level.levelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ function wallSolid(
nodes: Readonly<Record<string, AnyNode>>,
): MultiPolygon | undefined {
const support = wallSupportForNodes(wall, nodes).elevation
const height = getWallTop(wall, wall.parentId!, nodes, support) - support
const height =
Math.max(
getWallTop(wall, wall.parentId!, nodes, support, 0),
getWallTop(wall, wall.parentId!, nodes, support, 1),
) - support
const length = Math.hypot(wall.end[0] - wall.start[0], wall.end[1] - wall.start[1])
if (
![height, length, support, wall.thickness ?? 0.1].every(Number.isFinite) ||
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/agent-tools/wall-openings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const addDoorTool = {
name: 'add_door',
title: 'Add door',
description:
'Add a door to an existing straight wall at t (0..1 along it), or a passage with no leaf (openingKind opening: a cased opening, an arch). The door slides to stay on the wall and reports clamped. On a railing (wallType railing) it is a gap in the guard as tall as the railing, with no leaf, casing or threshold. Refused with a code, as in the editor: curved walls, walls shorter than the door, and overlapping another door, window or wall item unless force is set. Match the reference with the outline (rectangle, rounded, arch), doorType and style; what they cannot express (glass strips, a pattern of lites, carved panels) is written as a script in code, never left as not possible. Not available in run_batch: the host opening executor prepares scripted creation and rebuilds, which a batch does not prepare.',
'Add a door to an existing straight wall at t (0..1 along it), or a passage with no leaf (openingKind opening: a cased opening, an arch). The door slides to stay on the wall and reports clamped. On a railing (wallType railing) it is a gap in the guard as tall as the railing, with no leaf, casing or threshold. Refused with a code, as in the editor: curved walls, walls shorter than the door, a door taller than the wall top where it stands or anywhere along a sloped wall (wall_too_low), and overlapping another door, window or wall item unless force is set. Match the reference with the outline (rectangle, rounded, arch), doorType and style; what they cannot express (glass strips, a pattern of lites, carved panels) is written as a script in code, never left as not possible. Not available in run_batch: the host opening executor prepares scripted creation and rebuilds, which a batch does not prepare.',
input: {
wallId: NodeId.optional().describe('The wall to add the door to.'),
nodeId: NodeId.optional().describe(
Expand Down Expand Up @@ -243,7 +243,7 @@ export const addWindowTool = {
name: 'add_window',
title: 'Add window',
description:
"Add a window to an existing straight wall at t (0..1 along it), centred vertically on the wall, or on sillHeight above the floor when given. It slides to stay on the wall and under the wall's ceiling, and reports clamped. Refused with a code, as in the editor: curved walls, railings (railing_window: a railing takes a door, a gap in its guard), walls shorter than the window, overlapping another door, window or wall item unless force is set, and a style on a window that is not Fixed (style_needs_fixed_window). Match the reference with the outline (rectangle, rounded, arch), windowType and panes (columns × rows, or a style); what they cannot express (glass strips, leaded lites, a feature frame) is written as a script in code, never left as not possible. Not available in run_batch: the host opening executor prepares scripted creation and rebuilds, which a batch does not prepare.",
"Add a window to an existing straight wall at t (0..1 along it), centred vertically on the wall, or on sillHeight above the floor when given. It slides to stay on the wall and under the wall's ceiling, and reports clamped. Refused with a code, as in the editor: curved walls, railings (railing_window: a railing takes a door, a gap in its guard), walls shorter than the window, a window that fits nowhere under a sloped wall's top (wall_too_low), overlapping another door, window or wall item unless force is set, and a style on a window that is not Fixed (style_needs_fixed_window). Match the reference with the outline (rectangle, rounded, arch), windowType and panes (columns × rows, or a style); what they cannot express (glass strips, leaded lites, a feature frame) is written as a script in code, never left as not possible. Not available in run_batch: the host opening executor prepares scripted creation and rebuilds, which a batch does not prepare.",
input: {
wallId: NodeId.optional().describe('The wall to add the window to.'),
nodeId: NodeId.optional().describe(
Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/building/merge-windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
windowEndGap,
} from '../lib/corner-pair'
import type { AnyNode, AnyNodeId, WallNode, WindowNode } from '../schema'
import { findWallChildOverlap, resolveWallOpeningCeiling } from './wall-openings'
import { findWallChildOverlap, wallOpeningCeilingOver } from './wall-openings'

/**
* Two windows that exist become one: the one operation behind the editor's Merge windows button,
Expand Down Expand Up @@ -232,7 +232,15 @@ function mergeAtCorner(nodes: Nodes, first: Side, second: Side): WindowMerge {
)
}

const ceiling = resolveWallOpeningCeiling(second.wall, nodes as Record<AnyNodeId, AnyNode>)
const centreAt = (window: WindowNode, wall: WallNode, end: WallEnd) =>
end === 'start' ? window.width / 2 : wallLengthOf(wall) - window.width / 2
const secondCentre = centreAt(b, second.wall, joint.endB)
const ceiling = wallOpeningCeilingOver(
second.wall,
nodes as Record<AnyNodeId, AnyNode>,
secondCentre - b.width / 2,
secondCentre + b.width / 2,
)
if (headOf(a) > ceiling + 1e-6)
refuse(
'height_exceeds_wall',
Expand All @@ -242,8 +250,6 @@ function mergeAtCorner(nodes: Nodes, first: Side, second: Side): WindowMerge {

// Each side slides to the corner, keeping its width, if no other opening is in the way.
const post = fusesAtCorner(a) ? 'none' : 'post'
const centreAt = (window: WindowNode, wall: WallNode, end: WallEnd) =>
end === 'start' ? window.width / 2 : wallLengthOf(wall) - window.width / 2
const placed = sides.map(({ window, wall, end }, index) => {
const x = centreAt(window, wall, end)
const y = a.position[1]
Expand Down
168 changes: 168 additions & 0 deletions packages/core/src/building/wall-openings-slope.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { describe, expect, test } from 'bun:test'
import { moveNode } from '../agent-operations/move-node'
import { isAgentRefusal } from '../agent-tools/refusal'
import { type AnyNode, DoorNode, LevelNode, WallNode, WindowNode } from '../schema'
import { getWallTopOver } from '../services/storey'
import {
getWallChordFractionAt,
getWallCurveLength,
getWallStationAtChordFraction,
} from '../systems/wall/wall-curve'
import { clampDoorToWall, clampWindowToWall, planWallOpening } from './wall-openings'

function scene(wall: Partial<WallNode>) {
const node = WallNode.parse({
id: 'wall_slope',
parentId: 'level_slope',
start: [0, 0],
end: [4, 0],
height: 2.5,
...wall,
})
const level = LevelNode.parse({ id: 'level_slope', children: [node.id] })
return { wall: node, nodes: { [level.id]: level, [node.id]: node } as Record<string, AnyNode> }
}

// A semicircle on a 4 m chord: radius 2, so station s sits at angle s / 2 and projects onto the
// chord at (1 - cos(s / 2)) / 2, far from s / 4.
const semicircle = { curveOffset: 2 }

describe('a sloped top on a curved wall runs along the chord', () => {
test('arc-length stations map to the chord fraction the viewer slopes by, and back', () => {
const { wall } = scene(semicircle)
const length = getWallCurveLength(wall)
expect(getWallChordFractionAt(wall, length / 2)).toBeCloseTo(0.5, 6)
expect(getWallChordFractionAt(wall, length / 4)).toBeCloseTo((1 - Math.cos(Math.PI / 4)) / 2, 3)
expect(getWallStationAtChordFraction(wall, 0.25)).toBeCloseTo(
(length / Math.PI) * (Math.PI / 3),
4,
)
expect(getWallChordFractionAt(wall, getWallStationAtChordFraction(wall, 0.8))).toBeCloseTo(
0.8,
6,
)
})

test('the top over a span reads the chord position of its ends', () => {
const { wall, nodes } = scene({ ...semicircle, endHeightOffset: -1.5 })
const length = getWallCurveLength(wall)
// The arc midpoint is the chord midpoint: halfway down the slope, though s / chord would say 0.79.
expect(getWallTopOver(wall, 'level_slope', nodes, 0, 0, length / 2)).toBeCloseTo(1.75, 3)
})

test('a window slides to where the curved, sloped top still clears it', () => {
const { wall, nodes } = scene({ ...semicircle, endHeightOffset: -1.5 })
// 2.5 m falling to 1 m: 1.5 m of clearance ends at chord fraction 2/3, angle acos(-1/3).
const limit = (getWallCurveLength(wall) / Math.PI) * Math.acos(-1 / 3)
const placed = clampWindowToWall(wall, 100, 0.75, 1, 1.5, nodes)
expect(placed.fits).toBe(true)
expect(placed.clampedX).toBeCloseTo(limit - 0.5, 4)
})
})

describe('a flat wall places openings as it did before tops could slope', () => {
test('an opening taller than a 1 m wall still fits and clamps', () => {
const { wall, nodes } = scene({ height: 1 })
expect(clampWindowToWall(wall, 2, 0.5, 1, 1.2, nodes)).toEqual({
clampedX: 2,
clampedY: 0.6,
fits: true,
})
expect(clampDoorToWall(wall, 2, 0.9, 2.1, undefined, nodes)).toEqual({
clampedX: 2,
clampedY: 1.05,
fits: true,
})
})

test('an opening wider than the wall still fits, pinned to the start', () => {
const { wall, nodes } = scene({})
expect(clampWindowToWall(wall, 3, 1, 5, 1, nodes)).toMatchObject({ clampedX: 2.5, fits: true })
})

test('a sloped wall too low everywhere does not fit', () => {
const { wall, nodes } = scene({ height: 1, endHeightOffset: 0.1 })
expect(clampWindowToWall(wall, 2, 0.5, 1, 1.2, nodes).fits).toBe(false)
expect(clampDoorToWall(wall, 2, 0.9, 2.1, undefined, nodes).fits).toBe(false)
})
})

describe('agents refuse an opening no stretch of a sloped wall can take', () => {
// 2.5 m at the start falling to 1 m at the end; a flat 2.5 m wall is the control.
const sloped = { endHeightOffset: -1.5 }
const refusal = (run: () => unknown) => {
try {
run()
} catch (error) {
if (isAgentRefusal(error)) return error.code
throw error
}
return null
}
const withOpening = (wall: Partial<WallNode>, opening: DoorNode | WindowNode) => {
const { nodes } = scene({ ...wall, children: [opening.id] })
return { ...nodes, [opening.id]: opening } as Record<string, AnyNode>
}
const window = (height: number) =>
WindowNode.parse({
id: 'window_slope',
parentId: 'wall_slope',
wallId: 'wall_slope',
position: [1, 1.2, 0],
width: 1.2,
height,
})
const door = DoorNode.parse({
id: 'door_slope',
parentId: 'wall_slope',
wallId: 'wall_slope',
position: [0.6, 1.2, 0],
width: 0.9,
height: 2.4,
})
const move = (nodes: Record<string, AnyNode>, id: string) =>
moveNode(nodes as never, { id, by: [0.1, 0] } as never, { activeLevelId: null })

test('placing a window', () => {
const tall = { kind: 'window', wallId: 'wall_slope', t: 0.2, width: 1.2, height: 2.4 } as const
expect(refusal(() => planWallOpening(scene(sloped).nodes as never, tall))).toBe('wall_too_low')
expect(refusal(() => planWallOpening(scene({}).nodes as never, tall))).toBeNull()
// One that fits only near the high end slides there instead.
const planned = planWallOpening(scene(sloped).nodes as never, { ...tall, t: 0.9, height: 1.5 })
expect(planned.clamped).toBe(true)
})

test('placing a door', () => {
const tall = { kind: 'door', wallId: 'wall_slope', t: 0.15, width: 0.9, height: 2.4 } as const
expect(refusal(() => planWallOpening(scene(sloped).nodes as never, tall))).toBe('wall_too_low')
expect(refusal(() => planWallOpening(scene({}).nodes as never, tall))).toBeNull()
})

test('a door asked for at the low end of a rising wall slides to where it fits', () => {
// 1 m at the start rising to 3 m: a 2.1 m door clears from 2.2 m on, centre 2.65 m.
const rising = { height: 1, endHeightOffset: 2 }
const request = { kind: 'door', wallId: 'wall_slope', t: 0.1, width: 0.9, height: 2.1 } as const
const planned = planWallOpening(scene(rising).nodes as never, request)
expect(planned.clamped).toBe(true)
expect(planned.localX).toBeCloseTo(2.65, 4)
expect(
refusal(() => planWallOpening(scene(rising).nodes as never, { ...request, height: 3.2 })),
).toBe('wall_too_low')
expect(refusal(() => planWallOpening(scene({ height: 2 }).nodes as never, request))).toBe(
'wall_too_low',
)

const low = DoorNode.parse({ ...door, position: [0.6, 1.05, 0], height: 2.1 })
expect(refusal(() => move(withOpening(rising, low), 'door_slope'))).toBeNull()
expect(refusal(() => move(withOpening({ height: 2 }, low), 'door_slope'))).toBe('wall_too_low')
})

test('moving a window or a door', () => {
expect(refusal(() => move(withOpening(sloped, window(2.4)), 'window_slope'))).toBe(
'wall_too_low',
)
expect(refusal(() => move(withOpening({}, window(2.4)), 'window_slope'))).toBeNull()
expect(refusal(() => move(withOpening(sloped, door), 'door_slope'))).toBe('wall_too_low')
expect(refusal(() => move(withOpening({}, door), 'door_slope'))).toBeNull()
})
})
Loading
Loading