structs.QuadTree Extends
Constructs a new quad tree.

Inheritance

Constructor

goog.structs.QuadTree(minXminYmaxXmaxY)

Parameters

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.

Instance Methods

Public Protected Private
balance_(node)
Attempts to balance a node. A node will need balancing if all its children are empty or it contains just one leaf.
Arguments:
node : goog.structs.QuadTree.Node
The node to balance.
code »
clear()
Removes all items from the tree.
code »
clone() !goog.structs.QuadTree
Clones the quad-tree and returns the new instance.
Returns: !goog.structs.QuadTree  A clone of the tree.
code »
contains(xy) boolean
Returns true if the point at (x, y) exists in the tree.
Arguments:
x : number
The x-coordinate.
y : number
The y-coordinate.
Returns: boolean  Whether the tree contains a point at (x, y).
code »
find_(nodexy) goog.structs.QuadTree.Node
Finds a leaf node with the same (x, y) coordinates as the target point, or null if no point exists.
Arguments:
node : goog.structs.QuadTree.Node
The node to search in.
x : number
The x-coordinate of the point to search for.
y : number
The y-coordinate of the point to search for.
Returns: goog.structs.QuadTree.Node  The leaf node that matches the target, or null if it doesn't exist.
code »
forEach(fnopt_obj)
Traverses the tree and calls a function on each node.
Arguments:
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.
code »
get(xyopt_default) *
Gets the value of the point at (x, y) or null if the point is empty.
Arguments:
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.
code »
getCount() number
No description.
Returns: number  The number of items in the tree.
code »
getKeys() !Array.<?goog.math.Coordinate>
Returns an array containing the coordinates of each point stored in the tree.
Returns: !Array.<?goog.math.Coordinate>  Array of coordinates.
code »
getQuadrantForPoint_(parentxy) goog.structs.QuadTree.Node
Returns the child quadrant within a node that contains the given (x, y) coordinate.
Arguments:
parent : goog.structs.QuadTree.Node
The node.
x : number
The x-coordinate to look for.
y : number
The y-coordinate to look for.
Returns: goog.structs.QuadTree.Node  The child quadrant that contains the point.
code »
getRootNode() goog.structs.QuadTree.Node
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.
code »
getValues() !Array.<Object>
Returns an array containing all values stored within the tree.
Returns: !Array.<Object>  The values stored within the tree.
code »
insert_(parentpoint) boolean
Inserts a point into the tree, updating the tree's structure if necessary.
Arguments:
parent : goog.structs.QuadTree.Node
The parent to insert the point into.
point : goog.structs.QuadTree.Point
The point to insert.
Returns: boolean  True if a new node was added to the tree; False if a node already existed with the correpsonding coordinates and had its value reset.
code »
isEmpty() boolean
No description.
Returns: boolean  Whether the tree is empty.
code »
remove(xy) *
Removes a point from (x, y) if it exists.
Arguments:
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.
code »
set(xyvalue)
Sets the value of an (x, y) point within the quad-tree.
Arguments:
x : number
The x-coordinate.
y : number
The y-coordinate.
value : *
The value associated with the point.
code »
setPointForNode_(nodepoint)
Sets the point for a node, as long as the node is a leaf or empty.
Arguments:
node : goog.structs.QuadTree.Node
The node to set the point for.
point : goog.structs.QuadTree.Point
The point to set.
code »
split_(node)
Converts a leaf node to a pointer node and reinserts the node's point into the correct child.
Arguments:
node : goog.structs.QuadTree.Node
The node to split.
code »
traverse_(nodefn)
Traverses the tree depth-first, with quadrants being traversed in clockwise order (NE, SE, SW, NW). The provided function will be called for each leaf node that is encountered.
Arguments:
node : goog.structs.QuadTree.Node
The current node.
fn : function(goog.structs.QuadTree.Node)
The function to call for each leaf node. This function takes the node as an argument, and its return value is irrelevant.
code »

Instance Properties

count_ :
Count of the number of items in the tree.
Code »
The root node for the quad tree.
Code »

Enumerations

goog.structs.QuadTree.NodeType :
Enumeration of node types.
Constants:
EMPTY
No description.
LEAF
No description.
POINTER
No description.
Code »

Package structs

Package Reference