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
15 changes: 15 additions & 0 deletions packages/core/src/systems/wall/wall-mitering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ describe('wall miter boundary sides', () => {
})
})

describe('deterministic junction ordering', () => {
test('same wall set produces the same miter data regardless of input order', () => {
const thickWall = (id: string, thickness: number, end: [number, number]) =>
({ ...wall(id, [0, 0], end), thickness }) as WallNode
const wide = thickWall('wide', 0.6, [4, 0])
const narrow = thickWall('narrow', 0.2, [4, 0])
const branch = thickWall('branch', 0.4, [0, 4])

const forward = calculateLevelMiters([wide, narrow, branch]).junctionData.get('0,0')
const reversed = calculateLevelMiters([narrow, wide, branch]).junctionData.get('0,0')

expect(forward).toEqual(reversed)
})
})

describe('junction grid prefilter', () => {
function thickWall(
id: string,
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/systems/wall/wall-mitering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,13 @@ function calculateJunctionIntersections(
}
}

// Sort by outgoing angle
processedWalls.sort((a, b) => a.angle - b.angle)
// Sort by outgoing angle, then by wall ID so equal-angle walls produce the
// same pairing regardless of scene iteration order.
processedWalls.sort((a, b) => {
const angleOrder = a.angle - b.angle
if (angleOrder !== 0) return angleOrder
return a.wallId < b.wallId ? -1 : a.wallId > b.wallId ? 1 : 0
})

const wallIntersections = new Map<string, { left?: Point2D; right?: Point2D }>()
const n = processedWalls.length
Expand Down
Loading