Skip to content
FutureBlitz

    Install

    Import std.collections.spatial

    std.collections.spatial

    SpatialHash<T>, QuadTree<T>, and Octree<T>: values at points, found by where they are, the ones in a box or near a point, without going over the others. A SpatialHash keeps the points in square cells of a size, for things spread over a world of any size; a QuadTree splits its bounds in four where points crowd, and an Octree, in 3D, in eight. A box holds the points on its edges, a point near another is no more than the radius from it, so a negative or NaN radius finds nothing and an infinite one finds everything, and what's found comes in no order to count on. A coordinate that's NaN panics. Distances and boxes are worked out in Doubles, so no Float overflows on the way.

    std/collections/spatial.fb

    Types

    SpatialHash 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.

    std/collections/spatial.fb, line 104

    • @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.

    SpatialIterator struct

    Public Struct SpatialIterator<T> Implements Iterator<T>

    The values of a SpatialHash, a QuadTree, or an Octree, from a copy made when the loop began, with what the collection has changed by, which a change that panics is the only one to reach.

    std/collections/spatial.fb, line 281

    QuadTree class

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

    Values at 2D points, in bounds it splits in four where points crowd.

    std/collections/spatial.fb, line 533

    • @PanicsAtCaller Public New(minX: Float, minY: Float, maxX: Float, maxY: Float) constructor #

      An empty QuadTree for the points in the box from (minX, minY) to (maxX, maxY), which has to be finite. A box whose max is below its min along an axis panics.

    • 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). A point outside the QuadTree's box panics.

    • @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. A point outside the QuadTree's box panics.

    • 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(): QuadTree<T> method #

      A new QuadTree with the same box and values at the same points.

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

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

    Octree class

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

    Values at 3D points, in bounds it splits in eight where points crowd.

    std/collections/spatial.fb, line 612

    • @PanicsAtCaller Public New(minX: Float, minY: Float, minZ: Float, maxX: Float, maxY: Float, maxZ: Float) constructor #

      An empty Octree for the points in the box from (minX, minY, minZ) to (maxX, maxY, maxZ), which has to be finite. A box whose max is below its min along an axis panics.

    • Public Property Count: Int property #

      How many values it holds.

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

      Adds the value at (x, y, z). A point outside the Octree's box panics.

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

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

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

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

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

      Moves the first value equal to value at (x, y, z) to (toX, toY, toZ), and tells whether there was one. A point outside the Octree's box panics.

    • Public Method Clear() method #

      Takes every value out.

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

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

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

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

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

      Every value, in a new array.

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

      A new Octree with the same box 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.