BSP: add Binary Space Partitioning for procedural dungeon generation
Implements #202, #203, #204, #205; partially implements #206: - BSP class: core tree structure with bounds, split_once, split_recursive, clear - BSPNode class: lightweight node reference with bounds, level, is_leaf, split_horizontal, split_position; navigation via left/right/parent/sibling; contains() and center() methods - Traversal enum: PRE_ORDER, IN_ORDER, POST_ORDER, LEVEL_ORDER, INVERTED_LEVEL_ORDER - BSP iteration: leaves() for leaf nodes only, traverse(order) for all nodes - BSP query: find(pos) returns deepest node containing position - BSP.to_heightmap(): converts BSP to HeightMap with select, shrink, value options Note: #206's BSPMap subclass deferred - to_heightmap returns plain HeightMap. The HeightMap already has all necessary operations (inverse, threshold, etc.) for procedural generation workflows. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a4b1ab7d68
commit
8699bba9e6
5 changed files with 1703 additions and 0 deletions
28
tests/unit/bsp_simple_test.py
Normal file
28
tests/unit/bsp_simple_test.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
"""Simple BSP test to identify crash."""
|
||||
import sys
|
||||
import mcrfpy
|
||||
|
||||
print("Step 1: Import complete")
|
||||
|
||||
print("Step 2: Creating BSP...")
|
||||
bsp = mcrfpy.BSP(bounds=((0, 0), (100, 80)))
|
||||
print("Step 2: BSP created:", bsp)
|
||||
|
||||
print("Step 3: Getting bounds...")
|
||||
bounds = bsp.bounds
|
||||
print("Step 3: Bounds:", bounds)
|
||||
|
||||
print("Step 4: Getting root...")
|
||||
root = bsp.root
|
||||
print("Step 4: Root:", root)
|
||||
|
||||
print("Step 5: Split once...")
|
||||
bsp.split_once(horizontal=True, position=40)
|
||||
print("Step 5: Split complete")
|
||||
|
||||
print("Step 6: Get leaves...")
|
||||
leaves = list(bsp.leaves())
|
||||
print("Step 6: Leaves count:", len(leaves))
|
||||
|
||||
print("PASS")
|
||||
sys.exit(0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue