Skip to content
FutureBlitz

    Install

    Import std.collections.spatial

    QuadTree

    std.collections.spatial

    class

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

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

    Examples

    Local tree = QuadTree<Int>(0, 0, 100, 100)
    tree.Add(1, 10, 10)
    tree.Add(2, 20, 20)
    tree.Add(3, 60, 60)
    Expect(tree.Query(0, 0, 25, 25).Count == 2)
    Expect(tree.Move(1, 10, 10, 90, 5))
    Expect(tree.Query(0, 0, 25, 25) == [2])

    std/collections/spatial.fb, line 561

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

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