reikhelm/.dev/2026-05-28-procgen-map-core/tasks/07-bsp-partition.md
Parley Hatch 08e99e38a3 chore: scaffold reikhelm cargo workspace (core + viz crates)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-28 20:56:24 -06:00

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.rsPass, GenContext (Task 6).
  • reikhelm-core/src/geometry.rsRect (Task 2).
  • reikhelm-core/src/passes/mod.rs — append the module declaration here.

Files

  • Create: reikhelm-core/src/passes/bsp.rsBspConfig, BspPartition.
  • Modify: reikhelm-core/src/passes/mod.rs — append pub mod bsp; and re-export BspPartition, 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 Pass with name() == "bsp_partition".
    • Writes to context: one placeholder Room region per leaf in ctx.regions.

Tests

  • After running on an empty GenContext (grid all Wall), ctx.regions is non-empty and every region is kind: Room.
  • Every leaf's bounds lies fully within the map and respects min_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: 0 yields a single leaf (the whole map).

Success Criteria

  • BspPartition implements Pass and populates ctx.regions with non-overlapping in-bounds Room placeholders respecting min_leaf/max_depth.
  • Carves no tiles.
  • pub mod bsp; appended to passes/mod.rs.
  • Tests pass: cargo test -p reikhelm-core bsp

Commit

"feat(core): BspPartition pass"