2.3 KiB
2.3 KiB
Task 7: BspPartition Pass
Depends on: Task 6
Context Files
.dev/2026-05-28-procgen-map-core/spec/design.md— §4.7 (Partitioner role), §5 (data flow)..dev/2026-05-28-procgen-map-core/README.md— inter-pass data contract (this pass is the first row).reikhelm-core/src/pass.rs—Pass,GenContext(Task 6).reikhelm-core/src/geometry.rs—Rect(Task 2).reikhelm-core/src/passes/mod.rs— append the module declaration here.
Files
- Create:
reikhelm-core/src/passes/bsp.rs—BspConfig,BspPartition. - Modify:
reikhelm-core/src/passes/mod.rs— appendpub mod bsp;and re-exportBspPartition,BspConfig.
What to Build
A binary-space-partition partitioner (spec §4.7). Recursively splits the map rectangle into leaves, randomly choosing split axis and position within configured limits, stopping when a leaf can't be split without violating the minimum leaf size or when max depth is reached. For each final leaf it adds a placeholder Room region (kind: Room, bounds: <leaf rect>, cells: []) to ctx.regions via ctx.add_region. It does not carve tiles — the grid stays all Wall. All randomness comes from the passed rng.
Interface Dependencies
- Consumes:
Pass,GenContext,Rng(Task 6);Rect(Task 2). - Produces:
struct BspConfig { min_leaf: i32, max_depth: u32 }(+Default).struct BspPartition { /* holds BspConfig */ }—new(cfg: BspConfig) -> Self;impl Passwithname() == "bsp_partition".- Writes to context: one placeholder Room region per leaf in
ctx.regions.
Tests
- After running on an empty
GenContext(grid allWall),ctx.regionsis non-empty and every region iskind: Room. - Every leaf's
boundslies fully within the map and respectsmin_leaf(no dimension below the minimum). - Leaves do not overlap and stay within map bounds.
- Determinism: same seed/sub-stream → identical leaf set (compare region bounds).
max_depth: 0yields a single leaf (the whole map).
Success Criteria
BspPartitionimplementsPassand populatesctx.regionswith non-overlapping in-bounds Room placeholders respectingmin_leaf/max_depth.- Carves no tiles.
pub mod bsp;appended topasses/mod.rs.- Tests pass:
cargo test -p reikhelm-core bsp
Commit
"feat(core): BspPartition pass"