[Proc Gen] Grid - apply_threshold and apply_ranges for walkable/transparent #199

Closed
opened 2026-01-12 00:08:46 +00:00 by john · 0 comments
Owner

Parent Issue: #192
Depends On: #193 (HeightMap core)

Overview

Add methods to Grid for applying HeightMap data to walkability and transparency properties.

Specification

def apply_threshold(self,
                    source: HeightMap,
                    range: tuple[float, float],
                    walkable: bool = None,
                    transparent: bool = None) -> Grid

Set walkable/transparent properties where source value is in range. None means don't change that property.

def apply_ranges(self,
                 source: HeightMap,
                 ranges: list[tuple]) -> Grid

Apply multiple thresholds in a single pass.

Example

grid.apply_threshold(terrain, range=(0.3, 1.0), walkable=True, transparent=True)

grid.apply_ranges(terrain, [
    ((0.0, 0.3), {"walkable": False, "transparent": True}),   # Water
    ((0.3, 0.8), {"walkable": True, "transparent": True}),    # Land
    ((0.8, 1.0), {"walkable": False, "transparent": False}),  # Mountains
])

Implementation Notes

  • HeightMap size must match Grid's grid_size
  • Raise ValueError on size mismatch
  • apply_ranges processes all ranges in a single pass over the data
  • Cells not matching any range are left unchanged (important for composability)
  • Return self for chaining

Acceptance Criteria

  • apply_threshold sets walkable/transparent correctly
  • apply_ranges handles multiple ranges efficiently
  • Size mismatch raises ValueError
  • Unaffected cells remain unchanged
  • Unit tests verify grid properties after application
**Parent Issue:** #192 **Depends On:** #193 (HeightMap core) ## Overview Add methods to Grid for applying HeightMap data to walkability and transparency properties. ## Specification ```python def apply_threshold(self, source: HeightMap, range: tuple[float, float], walkable: bool = None, transparent: bool = None) -> Grid ``` Set walkable/transparent properties where source value is in range. `None` means don't change that property. ```python def apply_ranges(self, source: HeightMap, ranges: list[tuple]) -> Grid ``` Apply multiple thresholds in a single pass. ### Example ```python grid.apply_threshold(terrain, range=(0.3, 1.0), walkable=True, transparent=True) grid.apply_ranges(terrain, [ ((0.0, 0.3), {"walkable": False, "transparent": True}), # Water ((0.3, 0.8), {"walkable": True, "transparent": True}), # Land ((0.8, 1.0), {"walkable": False, "transparent": False}), # Mountains ]) ``` ## Implementation Notes - HeightMap size must match Grid's `grid_size` - Raise `ValueError` on size mismatch - `apply_ranges` processes all ranges in a single pass over the data - Cells not matching any range are left unchanged (important for composability) - Return `self` for chaining ## Acceptance Criteria - [ ] `apply_threshold` sets walkable/transparent correctly - [ ] `apply_ranges` handles multiple ranges efficiently - [ ] Size mismatch raises `ValueError` - [ ] Unaffected cells remain unchanged - [ ] Unit tests verify grid properties after application
john closed this issue 2026-01-12 01:42:56 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
john/McRogueFace#199
No description provided.