Skip to content
FutureBlitz

    Install

    Import std.collections.spatial

    SpatialHash

    std.collections.spatial

    class

    @DebugElements Public Class SpatialHash<T> Implements Iterable<T>, Cloneable

    Values at 2D points, kept in square cells of a size, for things spread over a world of any size.

    Examples

    Local places = SpatialHash<String>(10)
    places.Add("near", 3, 4)
    places.Add("far", 100, 100)
    Expect(places.Near(0, 0, 5) == ["near"])
    Expect(places.Query(90, 90, 110, 110) == ["far"])

    std/collections/spatial.fb, line 116

    • @PanicsAtCaller Public New(size: Float) constructor #

      An empty SpatialHash whose cells are size across, which has to be above 0 and finite.

    • Public Property Count: Int property #

      How many values it holds.

    • @PanicsAtCaller Public Method Add(value: T, x: Float, y: Float) method #

      Adds the value at (x, y).

    • @PanicsAtCaller Public Method Remove(value: T, x: Float, y: Float): Bool method #

      Removes the first value equal to value at (x, y), and tells whether there was one.

    • @PanicsAtCaller Public Method Contains(value: T, x: Float, y: Float): Bool method #

      Whether a value equal to value is at (x, y).

    • @PanicsAtCaller Public Method Move(value: T, x: Float, y: Float, toX: Float, toY: Float): Bool method #

      Moves the first value equal to value at (x, y) to (toX, toY), and tells whether there was one.

    • Public Method Clear() method #

      Takes every value out.

    • @PanicsAtCaller Public Method Query(minX: Float, minY: Float, maxX: Float, maxY: Float): T[] method #

      The values in the box from (minX, minY) to (maxX, maxY), in a new array.

    • @PanicsAtCaller Public Method Near(x: Float, y: Float, radius: Float): T[] method #

      The values no more than radius from (x, y), in a new array.

    • Public Method ToArray(): T[] method #

      Every value, in a new array.

    • Public Method Clone(): SpatialHash<T> method #

      A new SpatialHash with the same cells and values at the same points.

    • Public Method Iterate(): SpatialIterator<T> method #

      Every value. Adding or removing one while going over them panics.

    Report an issue with this page or with FutureBlitz on GitHub.