clean up magic numbers, enable arbitrary gridding, add cache invalidatino

This commit is contained in:
Jan Petykiewicz 2026-03-26 20:22:17 -07:00
commit 519dd48131

View file

@ -119,9 +119,16 @@ class DangerMap:
Returns:
Pre-computed cost, or 1e15 if out of bounds.
"""
# Clamp to grid range to handle upper boundary exactly
ix = int((x - self.minx) / self.resolution)
iy = int((y - self.miny) / self.resolution)
# Handle exact upper boundary
if ix == self.width_cells and abs(x - self.maxx) < 1e-9:
ix = self.width_cells - 1
if iy == self.height_cells and abs(y - self.maxy) < 1e-9:
iy = self.height_cells - 1
if 0 <= ix < self.width_cells and 0 <= iy < self.height_cells:
return float(self.grid[ix, iy])
return 1e15 # Outside bounds is impossible
return 1e15 # Outside bounds