The goog.structs.QuadTree Class

goog.structs.QuadTree(minX, minY, maxX, maxY)

Constructs a new quad tree.

minX {number}
Minimum x-value that can be held in tree.
minY {number}
Minimum y-value that can be held in tree.
maxX {number}
Maximum x-value that can be held in tree.
maxY {number}
Maximum y-value that can be held in tree.

The goog.structs.QuadTree.Node Class

Constructs a new quad tree node. … more

The goog.structs.QuadTree.NodeType Enum

Enumeration of node types. … more

The goog.structs.QuadTree.Point Class

Creates a new point object. … more

.clear()

Removes all items from the tree.

.clone()

Clones the quad-tree and returns the new instance.

returns {goog.structs.QuadTree}
A clone of the tree.

.contains(x, y)

Returns true if the point at (x, y) exists in the tree.

x {number}
The x-coordinate.
y {number}
The y-coordinate.
returns {boolean}
Whether the tree contains a point at (x, y).

.forEach(fn, opt_obj)

Traverses the tree and calls a function on each node.

fn {function(?, goog.math.Coordinate, goog.structs.QuadTree)}
The function to call for every value. This function takes 3 arguments (the value, the coordinate, and the tree itself) and the return value is irrelevant.
opt_obj {Object=}
The object to be used as the value of 'this' within {@ code fn}.

.get(x, y, opt_default)

Gets the value of the point at (x, y) or null if the point is empty.

x {number}
The x-coordinate.
y {number}
The y-coordinate.
opt_default {*=}
The default value to return if the node doesn't exist.
returns {*}
The value of the node, the default value if the node doesn't exist, or undefined if the node doesn't exist and no default has been provided.

.getCount()

returns {number}
The number of items in the tree.

.getKeys()

Returns an array containing the coordinates of each point stored in the tree.

returns {Array.<goog.math.Coordinate?>}
Array of coordinates.

.getRootNode()

Returns a reference to the tree's root node. Callers shouldn't modify nodes, directly. This is a convenience for visualization and debugging purposes.

returns {goog.structs.QuadTree.Node}
The root node.

.getValues()

Returns an array containing all values stored within the tree.

returns {Array.<Object>}
The values stored within the tree.

.isEmpty()

returns {boolean}
Whether the tree is empty.

.remove(x, y)

Removes a point from (x, y) if it exists.

x {number}
The x-coordinate.
y {number}
The y-coordinate.
returns {*}
The value of the node that was removed, or null if the node doesn't exist.

.set(x, y, value)

Sets the value of an (x, y) point within the quad-tree.

x {number}
The x-coordinate.
y {number}
The y-coordinate.
value {*}
The value associated with the point.