Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -614,23 +614,6 @@ export const ADD_LEVEL_CASES: AgentToolCase[] = [
mentions: ['below grade', 'cast concrete', 'Europe'],
},
},
{
name: 'set_ground_level on a site in Paris seats the building 0.15 m over grade, as cast concrete foundations do',
tool: 'set_ground_level',
scene: () =>
onSite(storeysScene(), SiteNode.parse({ id: 'site_paris', dossier: dossierAt('Paris, France') })),
input: { levelId: 'level_ground' },
expect: {
result: {
ok: true,
floorElevation: 0.15,
aboveGrade: 0.15,
foundation: { region: 'europe', construction: 'cast-concrete' },
},
mentions: ['cast concrete', 'Europe'],
after: { building_house: { position: [0, 0.15, 0], groundLevelId: 'level_ground' } },
},
},
{
name: 'above the highest level of the viewed building, at the default storey height',
tool: 'add_level',
Expand Down Expand Up @@ -703,7 +686,7 @@ export const ADD_LEVEL_CASES: AgentToolCase[] = [
scene: storeysScene,
input: { levelId: 'level_upper' },
expect: {
result: { ok: true, renumbered: true, floorElevation: 0.203 },
result: { ok: true, renumbered: true, floorElevation: 0 },
after: {
level_upper: { level: 0 },
level_ground: { level: -1 },
Expand Down
17 changes: 3 additions & 14 deletions packages/core/src/agent-operations/set-ground-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type SetGroundLevelInput = { levelId: string }

/**
* `set_ground_level`: the level asked for becomes the building's ground floor — named on the
* building, its floor the top of the foundation over grade (as the building's region and style seat it), index 0 — the same change the level panel's "Set as ground floor"
* building, its floor on grade, index 0 — the same change the level panel's "Set as ground floor"
* writes (`buildGroundLevelChanges`).
*/
export const setGroundLevel: AgentOperation<SetGroundLevelInput> = (nodes, input) => {
Expand All @@ -32,13 +32,6 @@ export const setGroundLevel: AgentOperation<SetGroundLevelInput> = (nodes, input
const { seat, moveBy } = built
const floorElevation = Math.round((seat.floorElevation + moveBy) * 1e6) / 1e6
const name = level.name ?? level.id
const { aboveGrade, foundation } = seat
const construction = {
region: foundation.region,
construction: foundation.construction.id,
basis: foundation.basis,
}
const inches = Math.round(aboveGrade / 0.0254)
if (built.unchanged)
return {
result: {
Expand All @@ -47,9 +40,7 @@ export const setGroundLevel: AgentOperation<SetGroundLevelInput> = (nodes, input
levelId: level.id,
buildingId: built.buildingId,
floorElevation: seat.floorElevation,
aboveGrade,
foundation: construction,
message: `${name} is already the ground floor, its floor ${aboveGrade} m (${inches} in) over grade (${foundation.construction.label} foundation; ${foundation.basis}).`,
message: `${name} is already the ground floor, its floor on grade.`,
},
}
return {
Expand All @@ -59,11 +50,9 @@ export const setGroundLevel: AgentOperation<SetGroundLevelInput> = (nodes, input
buildingId: built.buildingId,
floorElevation,
gradeElevation: seat.gradeElevation,
aboveGrade,
foundation: construction,
movedBuildingBy: moveBy,
renumbered: built.renumbered,
message: `${name} is the ground floor: its floor, the top of the foundation where the wood framing starts, stands ${aboveGrade} m (${inches} in) over grade (${floorElevation.toFixed(2)} m over grade ${seat.gradeElevation.toFixed(2)} m), as a ${foundation.construction.label} foundation seats it: ${foundation.construction.seatBasis}; ${foundation.basis}. The levels with a lower index are below grade${moveBy === 0 ? '' : `; the building moved ${moveBy.toFixed(2)} m in height, its plan where it was`}.`,
message: `${name} is the ground floor: its floor stands on grade (${floorElevation.toFixed(2)} m). The levels with a lower index are below grade${moveBy === 0 ? '' : `; the building moved ${moveBy.toFixed(2)} m in height, its plan where it was`}.`,
},
changes: { update: built.update },
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent-operations/verify-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export const verifyScene: AgentOperation<VerifySceneInput | undefined> = (
if (seat?.levelId === level.levelId && seat.explicit && !seat.seated)
report(
'ground_level_unseated',
`${levelName} is the ground floor, but its floor datum stands ${seat.offset.toFixed(2)} m ${seat.offset > 0 ? 'over' : 'under'} grade (${seat.gradeElevation.toFixed(2)} m); a seated ground floor stands between grade and ${seat.aboveGrade} m (the top of the ${seat.foundation.construction.label} foundation) over it. set_ground_level on it seats the building.`,
`${levelName} is the ground floor, but its floor datum stands ${seat.offset.toFixed(2)} m ${seat.offset > 0 ? 'over' : 'under'} grade (${seat.gradeElevation.toFixed(2)} m); a seated ground floor stands on it. set_ground_level on it seats the building.`,
true,
)
if (content.walls > 0 && content.zones === 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent-tools/levels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const setGroundLevelTool = {
name: 'set_ground_level',
title: 'Set ground level',
description:
"Make a level the building's ground floor: the one standing at grade, its floor 8 in over the ground (about 6 in on cast concrete foundations, 12 in on stone: the building's foundation construction seats it; the result names it). A building's levels stack on a ground line; the levels with a lower floor index are below grade (basements), the ones at or over it are not, and list_levels reads it as groundLevels (levelId, floorElevation, floorOverGrade, seated) and each level's gradeStanding (at-grade, partly-below-grade, below-grade) and isGroundLevel. This names the level on the building, seats the building so that level's floor datum, the top of the foundation where the wood framing starts, stands 0.203 m (8 in) over grade on a block foundation, 0.15 m on cast concrete (Europe), 0.3 m on stone (a historic style) (flat site: world Y 0.203; sculpted terrain: 0.203 m over the mean ground height under its floor), moving the building in height only — the plan stays where it is and every level keeps its place relative to the others — and renumbers the floor indices so it is 0 and the ones under it are -1, -2…. A level added below (add_level position below) stacks under the lowest level without moving the ground floor. A roof level or a support level cannot be the ground floor (not_a_storey). One undo step. Refusals: level_not_found, not_a_level, no_building, not_a_storey. Answering unchanged: true when the level is already the named ground floor, at that seat, at index 0.",
"Make a level the building's ground floor: the one standing at grade, its floor on the ground. A building's levels stack on a ground line; the levels with a lower floor index are below grade (basements), the ones at or over it are not, and list_levels reads it as groundLevels (levelId, floorElevation, floorOverGrade, seated) and each level's gradeStanding (at-grade, partly-below-grade, below-grade) and isGroundLevel. This names the level on the building, seats the building so that level's floor datum stands on grade (flat site: world Y 0; sculpted terrain: the mean ground height under its floor), moving the building in height only — the plan stays where it is and every level keeps its place relative to the others — and renumbers the floor indices so it is 0 and the ones under it are -1, -2…. A level added below (add_level position below) stacks under the lowest level without moving the ground floor. A roof level or a support level cannot be the ground floor (not_a_storey). One undo step. Refusals: level_not_found, not_a_level, no_building, not_a_storey. Answering unchanged: true when the level is already the named ground floor, on grade, at index 0.",
input: {
levelId: NodeId.describe('The level to stand at grade, by an id list_levels returned.'),
},
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/building/ground-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { getLevelElevations } from '../services/storey'
/**
* Making `levelId` the building's ground floor, as the level panel's "Set as ground floor" and the
* agent's `set_ground_level` do: the building names it (`groundLevelId`), is seated so that level's
* floor datum, the top of the foundation, stands over grade as the building's foundation
* construction seats it (`GroundSeat.aboveGrade`: 0.203 m on block, by region and style); its
* position moves in height, the plan stays where it is, and the
* floor datum stands on grade; its position moves in height, the plan stays where it is, and the
* floor indices are renumbered so it is index 0 and the ones under it are the basements. Every
* floor keeps its place relative to the others. One change set, one undo step. `null` for an id
* that is no level of a building.
Expand Down Expand Up @@ -36,7 +34,7 @@ export function buildGroundLevelChanges({

const [x, y, z] = (building as BuildingNode).position
// Micrometres: the seat is measured through sums of storey heights, and a stored height keeps no noise.
const moveBy = seat.atFoundationTop ? 0 : Math.round((seat.aboveGrade - seat.offset) * 1e6) / 1e6
const moveBy = seat.seated ? 0 : Math.round(-seat.offset * 1e6) / 1e6
const shift = level.level
const renumbered = Object.values(nodes).filter(
(node): node is LevelNode =>
Expand All @@ -45,7 +43,7 @@ export function buildGroundLevelChanges({
getLevelElevations(nodes).get(node.id)?.buildingId === building.id,
)
const unchanged =
before?.explicit === true && before.levelId === level.id && seat.atFoundationTop && shift === 0
before?.explicit === true && before.levelId === level.id && seat.seated && shift === 0
return {
buildingId: building.id,
seat,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export {
GROUND_PIT_FLOOR_DROP,
GROUND_PIT_PLATE_CLEARANCE,
groundPitFloorY,
terrainOverFloors,
} from './lib/below-grade-footprints'
export {
CEILING_BUILD_UP_PRESETS,
Expand Down Expand Up @@ -363,7 +364,6 @@ export {
framingPostTopAt,
isFramingPost,
} from './lib/framing-post'
export { type FoundationMember, genericFoundation } from './lib/generic-foundation'
export {
ceilingSeatY,
isScriptedNode,
Expand All @@ -390,7 +390,6 @@ export {
export { type LevelGradeStanding, levelGradeStanding } from './lib/grade-standing'
export { type GroundLevel, groundLevelOf, levelUnderNamedGround } from './lib/ground-level'
export {
GROUND_FLOOR_ABOVE_GRADE,
GROUND_SEAT_TOLERANCE,
type GroundSeat,
gradeUnderLevel,
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/lib/below-grade-footprints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
coveredBelowGradeFootprints,
GROUND_PIT_PLATE_CLEARANCE,
groundPitFloorY,
terrainOverFloors,
} from './below-grade-footprints'
import { levelGradeStanding } from './grade-standing'
import { levelGroundBox, levelStackGroundBox, terrainBetweenEyeAndBox } from './ground-window'
Expand Down Expand Up @@ -337,6 +338,31 @@ test('a walk-out whose buried part is wider than the cellar opens it, the edge f
expect(belowGradeFootprints(nodes, 'level_walkout')).toHaveLength(1)
})

test('the terrain is cut wherever it stands over a floor inside its plate, the tolerance band included', () => {
// The ground climbs 0.4 m: over the walk-out's 0.2 m floor, under the 0.5 m below-grade bar.
const nodes = houseOnHillside({ walkoutEast: 9, riseCm: 40 })
expect(belowGradeFootprints(nodes, 'level_walkout')).toEqual([])
// Over the floor from x = -0.5 (0.2 m reached on the 0.4 m climb between -1 and 0) to the east
// edge; the cellar, under the ground everywhere, whole: one outline.
const [outline, ...more] = terrainOverFloors(nodes)
expect(more).toEqual([])
const { x, z } = extent(outline ?? [])
expect(x[0]).toBeCloseTo(-2, 3)
expect(x[1]).toBe(9)
expect(z).toEqual([-4, 4])
const walkoutOnly = {
...nodes,
slab_cellar: { ...nodes.slab_cellar, visible: false },
} as typeof nodes
const [walkout] = terrainOverFloors(walkoutOnly)
expect(extent(walkout ?? []).x[0]).toBeCloseTo(-0.5 + 0.005 / 0.4, 3)
})

test('a floor the terrain stays under cuts nothing: on flat ground only the cellar under it is cut', () => {
const cut = terrainOverFloors(houseOnHillside({ riseCm: 0 }))
expect(cut.map(extent)).toEqual([{ x: [-2, 5], z: [-4, 4] }])
})

test('a level under the ground line that the ground leaves out of the ground opens nothing', () => {
// A flat site at 0 m, the walk-out's floor at 0.2 m: the main floor over it is the ground line,
// so the walk-out reads partly below grade, and nothing stands over it.
Expand Down
49 changes: 44 additions & 5 deletions packages/core/src/lib/below-grade-footprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ function levelPlates(nodes: Record<AnyNodeId, AnyNode>): LevelPlates[] {
* Where the ground meets the levels below grade, in the site's plan: each such level's floor slabs
* placed where its building stands and joined into outlines, the levels' together as one set (a
* deeper level wider than the one over it, or under part of it, gives one outline, not overlapping
* ones). The 3D view cuts its hole in the ground and draws its grade ring along them while the
* ground is veiled. An automatic floor follows the walls' centrelines, so an outline runs half a
* ones). The 3D view cuts its hole in the ground over them while the ground is veiled. An automatic floor follows the walls' centrelines, so an outline runs half a
* wall inside the outer faces. A level only partly below grade (a walk-out on a hillside) gives
* the part of its floor the ground stands over by more than {@link BELOW_GRADE_TOLERANCE}, the
* edge following the slope; fully buried levels give their whole floor.
Expand Down Expand Up @@ -165,6 +164,47 @@ export function coveredBelowGradeFootprints(nodes: Record<AnyNodeId, AnyNode>):
return rings
}

/** Ground this little over a floor counts as level with it, not over it: the terrain's centimetre steps. */
const OVER_FLOOR_EPSILON = 0.005
const overFloorsMemo = new WeakMap<object, Point2D[][]>()

/**
* The part of every floor plate the rendered terrain stands over, in the site's plan: each visible
* level's floor slabs (not a recessed pit, not site flatwork), cut where the ground (the triangle
* plane the terrain draws) is higher than that slab's own top. Inside a storey's floor the ground
* is never seen over it: the terrain is cut open there, whatever the level's grade standing. Unlike
* the below-grade outlines this takes no {@link BELOW_GRADE_TOLERANCE}: a slope interpolated a few
* centimetres to 0.3 m over a walk-out's floor near where the ground rises is cut too. Rings only,
* as the cover: an outline with an inner outline is left out. Empty on a site with no terrain.
*/
export function terrainOverFloors(nodes: Record<AnyNodeId, AnyNode>): Point2D[][] {
const hit = overFloorsMemo.get(nodes)
if (hit) return hit
const elevations = getLevelElevations(nodes)
const pieces: Point2D[][] = []
for (const level of Object.values(nodes)) {
if (level.type !== 'level' || level.visible === false) continue
const field = terrainFieldOverLevel(nodes, level)
const plane = field ? levelPlaneWorldY(nodes, level.id) : null
if (!field || plane === null) continue
const buildingId = elevations.get(level.id)?.buildingId
const building = buildingId ? nodes[buildingId as AnyNodeId] : undefined
const placed = building?.type === 'building' ? building : null
for (const childId of level.children) {
const slab = nodes[childId as AnyNodeId]
if (slab?.type !== 'slab' || slab.recessed === true || isSiteFlatwork(slab)) continue
if (slab.visible === false) continue
const plate = slab.polygon.map(([x, z]) => levelLocalToWorldXZ(placed, x, z))
pieces.push(...groundOverPart(plate, field, plane + slab.elevation + OVER_FLOOR_EPSILON))
}
}
const rings = union(pieces)
.filter((polygon) => polygon.holes.length === 0)
.map((polygon) => polygon.outer)
overFloorsMemo.set(nodes, rings)
return rings
}

/**
* How deep the pit under the hole goes: the world Y of the top of the lowest floor of the level
* shown (the sunken room of a split level, not its raised part), the deepest of the levels the hole
Expand All @@ -182,9 +222,8 @@ export function belowGradeFloorY(
/** How far under the top of the floor plate the pit hangs its own floor: the default plate's thickness. */
export const GROUND_PIT_FLOOR_DROP = 0.05
/**
* How far the pit's floor keeps from the plane of the plate's underside. The foundation under the
* level tops out on that plane (`genericFoundation`), and seen through the hole it has to stand
* on the pit's floor, not share its plane: two faces on one plane flicker. 2 cm is what a 24-bit
* How far the pit's floor keeps from the plane of the plate's underside: two faces on one plane
* flicker. 2 cm is what a 24-bit
* depth buffer with the viewer's 0.3 m near plane tells apart out to about 300 m, further than
* the hole is ever looked into from.
*/
Expand Down
28 changes: 7 additions & 21 deletions packages/core/src/lib/deepest-drawn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
WallNode,
} from '../schema'
import { deepestDrawnY, lowestGroundY } from './deepest-drawn'
import { FOUNDATION_STANDARD } from './foundation-standard'
import { FLAT_GROUND_Y } from './site-ground-height'
import { encodeTerrainField } from './terrain-codec'
import { createTerrainField } from './terrain-field'
Expand Down Expand Up @@ -83,16 +82,13 @@ test('over no floor the scene draws nothing deep', () => {
expect(deepestDrawnY(keyed([site()]))).toBeNull()
})

test('a house at grade is deepest at a footing under its floor', () => {
expect(deepestDrawnY(house(null))).toBeCloseTo(
0.05 - 0.05 - FOUNDATION_STANDARD.footingThickness,
9,
)
test('a house at grade is deepest at the underside of its floor', () => {
expect(deepestDrawnY(house(null))).toBeCloseTo(0.05 - 0.05, 9)
})

test('a basement is deepest at the footing under its floor', () => {
test('a basement is deepest at the underside of its floor', () => {
// The floor top is at -3.63 + 0.05 on a 0.05 m slab.
expect(deepestDrawnY(house(-3.63))).toBeCloseTo(-3.63 - FOUNDATION_STANDARD.footingThickness, 9)
expect(deepestDrawnY(house(-3.63))).toBeCloseTo(-3.63, 9)
})

/** A basement (-1, plane at -3.63) whose floor has two slabs on different elevations. */
Expand Down Expand Up @@ -127,10 +123,10 @@ test('a split-level floor is deepest at its lowest slab underside, not the highe
{ elevation: 0.05, thickness: 0.05 },
{ elevation: -1.2, thickness: 0.2 },
])
expect(deepestDrawnY(nodes)).toBeCloseTo(-3.63 - 1.4 - FOUNDATION_STANDARD.footingThickness, 9)
expect(deepestDrawnY(nodes)).toBeCloseTo(-3.63 - 1.4, 9)
})

test('a recessed slab counts where it is drawn: by its own underside, with no footing under it', () => {
test('a recessed slab counts where it is drawn: by its own underside', () => {
// A pool basin: floor at -1.5, 0.3 thick, under a 0.05 m standing slab.
const nodes = splitBasement([
{ elevation: 0.05, thickness: 0.05 },
Expand All @@ -139,21 +135,11 @@ test('a recessed slab counts where it is drawn: by its own underside, with no fo
expect(deepestDrawnY(nodes)).toBeCloseTo(-3.63 - 1.8, 9)
})

test('a thick recessed slab that stays shallow does not deepen the standing plate’s footing', () => {
// A raised recessed plate (top 0.45, 0.5 thick: underside -0.05) beside a thin standing plate:
// the footing under the standing plate is the deeper thing, not a thickest-slab guess.
const nodes = splitBasement([
{ elevation: 0.05, thickness: 0.05 },
{ elevation: 0.45, thickness: 0.5, recessed: true },
])
expect(deepestDrawnY(nodes)).toBeCloseTo(-3.63 - FOUNDATION_STANDARD.footingThickness, 9)
})

test('site flatwork is not a floor: a driveway laid deeper than the house’s slab does not take the dive depth down', () => {
// The house on its 0.05 m plate; a driveway on the same level, top -0.3, 0.3 thick (underside -0.6).
const nodes = splitBasement([
{ elevation: 0.05, thickness: 0.05 },
{ elevation: -0.3, thickness: 0.3, metadata: { flatwork: 'driveway' } },
])
expect(deepestDrawnY(nodes)).toBeCloseTo(-3.63 - FOUNDATION_STANDARD.footingThickness, 9)
expect(deepestDrawnY(nodes)).toBeCloseTo(-3.63, 9)
})
Loading
Loading