pyLEAFS.spatialhash module
Generic spatial hash over a point set.
A SpatialHash buckets an arbitrary (n, D) set of points into the
regions of a shared Grid, then answers Moore-neighbourhood queries.
It is deliberately agnostic about what the points are — resources, foragers,
predators — so the same structure serves every layer. Unlike the resource
field’s internal buffer, this is a lightweight index rebuilt from a positions
array on demand.
- class pyLEAFS.spatialhash.SpatialHash(grid, positions=None)[source]
Bases:
objectBucket a point set into grid regions for neighbourhood queries.
- Parameters:
Examples
>>> g = Grid((5, 5), L=10.0) >>> pts = np.array([[1.0, 1.0], [12.0, 3.0], [1.5, 1.5]]) >>> sh = SpatialHash(g, pts) >>> idx = sh.query(np.array([1.2, 1.2])) >>> sorted(idx.tolist()) [0, 2]