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
60 changes: 58 additions & 2 deletions packages/editor/src/lib/paint-scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ describe('paintScopeLabel', () => {
function item(id: string, assetId: string): ItemNode {
return { id, type: 'item', asset: { id: assetId } } as unknown as ItemNode
}
function slab(id: string, polygon: Array<[number, number]>): SlabNode {
return { id, type: 'slab', polygon } as unknown as SlabNode
function slab(id: string, polygon: Array<[number, number]>, levelId = 'l1'): SlabNode {
return { id, type: 'slab', polygon, parentId: levelId } as unknown as SlabNode
}
function wall(
id: string,
Expand Down Expand Up @@ -451,4 +451,60 @@ describe('resolvePaintScopeTargets', () => {
})
expect(keys(result).sort()).toEqual(['inA:surface', 'inB:surface'])
})

it('slab room stops at the level boundary', () => {
// Stacked storeys share a footprint, so the upper slab's centroid sits inside
// the ground floor's space polygon. Painting downstairs must not reach it.
const ground = slab(
'ground',
[
[1, 1],
[3, 1],
[3, 3],
[1, 3],
],
'l1',
)
const upstairs = slab(
'upstairs',
[
[1, 1],
[3, 1],
[3, 3],
[1, 3],
],
'l2',
)
const footprint: Array<[number, number]> = [
[0, 0],
[10, 0],
[10, 10],
[0, 10],
]
const result = resolve({
node: ground,
role: 'surface',
scope: 'room',
nodes: [ground, upstairs],
spaces: [
{
id: 's1',
levelId: 'l1',
polygon: footprint,
wallIds: [],
boundaryFaces: [],
isExterior: false,
},
{
id: 's2',
levelId: 'l2',
polygon: footprint,
wallIds: [],
boundaryFaces: [],
isExterior: false,
},
],
})
expect(keys(result)).toEqual(['ground:surface'])
})
})
10 changes: 8 additions & 2 deletions packages/editor/src/lib/paint-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,19 @@ export function resolvePaintScopeTargets(args: {
if (node.type === 'slab' && scope === 'room') {
const centroid = polygonCentroid((node as SlabNode).polygon)
if (!centroid) return single
const space = Object.values(spaces).find((candidate) =>
pointInPolygon2D(centroid, candidate.polygon),
// Space polygons are per-level footprints, and stacked storeys share a
// footprint — so the level has to gate both the space lookup and the fan-out
// or one click paints the floor above too.
const levelId = node.parentId ?? resolveLevelId(node, nodes)
if (!levelId) return single
const space = Object.values(spaces).find(
(candidate) => candidate.levelId === levelId && pointInPolygon2D(centroid, candidate.polygon),
)
if (!space) return single
return Object.values(nodes)
.filter((other) => {
if (other.type !== 'slab') return false
if ((other.parentId ?? resolveLevelId(other, nodes)) !== levelId) return false
const otherCentroid = polygonCentroid((other as SlabNode).polygon)
return otherCentroid != null && pointInPolygon2D(otherCentroid, space.polygon)
})
Expand Down
Loading