[Proc Gen] HeightMap - kernel_transform #198

Open
opened 2026-01-12 00:07:56 +00:00 by john · 0 comments
Owner

Parent Issue: #192

Overview

Expose libtcod's kernelTransform with a Pythonic dict-based interface.

Specification

def kernel_transform(self,
                     weights: dict[tuple[int, int], float],
                     min: float = 0.0,
                     max: float = 1.0) -> HeightMap

Parameters

Parameter Type Description
weights dict Maps (dx, dy) offsets to weight values. Keys can be tuple, list, or Vector.
min float Only apply to cells with value >= min
max float Only apply to cells with value <= max

Example

# Sobel edge detection (vertical)
heightmap.kernel_transform(weights={
    (-1, -1): 1.0, (0, -1): 2.0, (1, -1): 1.0,
    (-1,  0): 0.0, (0,  0): 0.0, (1,  0): 0.0,
    (-1,  1): -1.0, (0,  1): -2.0, (1,  1): -1.0,
})

# Simple blur
heightmap.kernel_transform(weights={
    (-1, -1): 1/9, (0, -1): 1/9, (1, -1): 1/9,
    (-1,  0): 1/9, (0,  0): 1/9, (1,  0): 1/9,
    (-1,  1): 1/9, (0,  1): 1/9, (1,  1): 1/9,
})

Implementation Notes

Transform the dict into libtcod's arrays:

# From weights dict, build:
dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
weight = [1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9]
# Then call TCOD_heightmap_kernel_transform
  • Keys accept tuple, list, or mcrfpy.Vector
  • Order of iteration through dict doesn't matter (position is explicit in key)

Acceptance Criteria

  • Dict-based interface correctly transforms to libtcod arrays
  • Various kernel sizes work (3x3, 5x5, arbitrary)
  • min/max filtering works correctly
  • Edge detection kernel produces expected output
  • Blur kernel smooths terrain
**Parent Issue:** #192 ## Overview Expose libtcod's `kernelTransform` with a Pythonic dict-based interface. ## Specification ```python def kernel_transform(self, weights: dict[tuple[int, int], float], min: float = 0.0, max: float = 1.0) -> HeightMap ``` ### Parameters | Parameter | Type | Description | |-----------|------|-------------| | `weights` | `dict` | Maps `(dx, dy)` offsets to weight values. Keys can be tuple, list, or Vector. | | `min` | `float` | Only apply to cells with value >= min | | `max` | `float` | Only apply to cells with value <= max | ### Example ```python # Sobel edge detection (vertical) heightmap.kernel_transform(weights={ (-1, -1): 1.0, (0, -1): 2.0, (1, -1): 1.0, (-1, 0): 0.0, (0, 0): 0.0, (1, 0): 0.0, (-1, 1): -1.0, (0, 1): -2.0, (1, 1): -1.0, }) # Simple blur heightmap.kernel_transform(weights={ (-1, -1): 1/9, (0, -1): 1/9, (1, -1): 1/9, (-1, 0): 1/9, (0, 0): 1/9, (1, 0): 1/9, (-1, 1): 1/9, (0, 1): 1/9, (1, 1): 1/9, }) ``` ## Implementation Notes Transform the dict into libtcod's arrays: ```python # From weights dict, build: dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1] dy = [-1, -1, -1, 0, 0, 0, 1, 1, 1] weight = [1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9] # Then call TCOD_heightmap_kernel_transform ``` - Keys accept tuple, list, or `mcrfpy.Vector` - Order of iteration through dict doesn't matter (position is explicit in key) ## Acceptance Criteria - [ ] Dict-based interface correctly transforms to libtcod arrays - [ ] Various kernel sizes work (3x3, 5x5, arbitrary) - [ ] min/max filtering works correctly - [ ] Edge detection kernel produces expected output - [ ] Blur kernel smooths terrain
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#198
No description provided.