T - The type of object this quad tree should contain. An object only requires some way of getting rough bounds.public class QuadTree<T extends QuadTree.QuadTreeObject>
extends java.lang.Object
This class represents any node, but you will likely only interact with the root node.
| Modifier and Type | Class and Description |
|---|---|
static interface |
QuadTree.QuadTreeObject
Represents an object in a QuadTree.
|
| Constructor and Description |
|---|
QuadTree(int maxObjectsPerNode,
com.badlogic.gdx.math.Rectangle bounds)
Constructs a new quad tree.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all objects.
|
void |
getAllChildren(com.badlogic.gdx.utils.Array<T> out)
Fills the out array with all objects in this node and all child nodes, recursively.
|
QuadTree<T> |
getBottomLeftChild()
Returns the bottom left child node, or null if this node is a leaf node.
|
QuadTree<T> |
getBottomRightChild()
Returns the bottom right child node, or null if this node is a leaf node.
|
com.badlogic.gdx.math.Rectangle |
getBounds()
Returns the entire bounds of this node.
|
void |
getMaybeIntersecting(com.badlogic.gdx.utils.Array<T> out,
com.badlogic.gdx.math.Rectangle toCheck)
Fills the out parameter with any objects that may intersect the given rectangle.
|
QuadTree<T> |
getNodeAt(float x,
float y)
Returns the leaf node directly at the given coordinates, or null if the coordinates are outside this node's bounds.
|
com.badlogic.gdx.utils.Array<T> |
getObjects()
Returns the objects in this node only.
|
QuadTree<T> |
getTopLeftChild()
Returns the top left child node, or null if this node is a leaf node.
|
QuadTree<T> |
getTopRightChild()
Returns the top right child node, or null if this node is a leaf node.
|
int |
getTotalObjectCount()
Returns the total number of objects in this node and all child nodes, recursively
|
void |
insert(T obj)
Inserts an object into this node or its child nodes.
|
boolean |
isLeaf()
Returns whether this node is a leaf node (has no child nodes)
|
void |
remove(T obj)
Removes an object from this node or its child nodes.
|
public QuadTree(int maxObjectsPerNode,
com.badlogic.gdx.math.Rectangle bounds)
maxObjectsPerNode - How many objects may be in a node before it will split.
Should be around 3-5 for optimal results, depending on your use case.bounds - The total bounds of this root nodepublic void insert(T obj)
public void remove(T obj)
public void clear()
public QuadTree<T> getNodeAt(float x, float y)
public void getMaybeIntersecting(com.badlogic.gdx.utils.Array<T> out, com.badlogic.gdx.math.Rectangle toCheck)
This will result in false positives, but never a false negative.
public boolean isLeaf()
public QuadTree<T> getBottomLeftChild()
public QuadTree<T> getBottomRightChild()
public QuadTree<T> getTopLeftChild()
public QuadTree<T> getTopRightChild()
public com.badlogic.gdx.math.Rectangle getBounds()
public com.badlogic.gdx.utils.Array<T> getObjects()
If this node isn't a leaf node, it will only return the objects that don't fit perfectly into a specific child node (lie on a border).
public int getTotalObjectCount()
public void getAllChildren(com.badlogic.gdx.utils.Array<T> out)