APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.utils

public Class QuadTreeFloat

extends Object
implements Poolable
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.utils.Pool.Poolable
Imports
java.util.Arrays, com.badlogic.gdx.math.Rectangle, com.badlogic.gdx.utils.Pool.Poolable

A quad tree that stores a float for each point.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
public int
count

The number of elements stored in values (3 values per quad tree entry).

public int
public static final int
public float
public final int
public final int
public QuadTreeFloat
public QuadTreeFloat
private static final Pool<QuadTreeFloat>
public QuadTreeFloat
public QuadTreeFloat
public static final int
public float[]
values

For each entry, stores the value, x, and y.

public float
public static final int
X

public float
x

public static final int
Y

public float
y

Constructor Summary

AccessConstructor and Description
public
QuadTreeFloat()

Creates a quad tree with 16 for maxValues and 8 for maxDepth.

public
QuadTreeFloat(int
The maximum number of values stored in each quad tree node. When exceeded, the node is split into 4 child nodes. If the maxDepth has been reached, more than maxValues may be stored.
maxValues
,
int
The maximum depth of the tree nodes. Nodes at the maxDepth will not be split and may store more than maxValues number of entries.
maxDepth
)

Method Summary

Modifier and TypeMethod and Description
public void
add(float value, float valueX, float valueY)

private void
addToChild(float value, float valueX, float valueY)

private void
findNearestInternal(float x, float y, FloatArray result)

protected int
growValues()

Returns a new length for values when it is not enough to hold all the entries after maxDepth has been reached.

public boolean
nearest(float x, float y, FloatArray
For the entry nearest to the specified point, the value, x, y, and square of the distance to the value are added to this array after it is cleared. See VALUE, X, Y, and DISTSQR.
result
)

Returns: false if no entry was found because the quad tree was empty or the specified point is farther than the larger of the quad tree's width or height from an entry.

private QuadTreeFloat
obtainChild(float x, float y, float width, float height, int depth)

public void
query(float centerX, float centerY, float radius, FloatArray
For each entry found within the radius, if any, the value, x, y, and square of the distance to the entry are added to this array. See VALUE, X, Y, and DISTSQR.
results
)

private void
query(float centerX, float centerY, float radiusSqr, float rectX, float rectY, float rectSize, FloatArray results)

public void
query(Rectangle rect, FloatArray
For each entry found within the rectangle, if any, the value, x, and y of the entry are added to this array. See VALUE, X, and Y.
results
)

public void
reset()

Implements com.badlogic.gdx.utils.Pool.Poolable.reset.

Resets the object for reuse.

public void
setBounds(float x, float y, float width, float height)

private void
split(float value, float valueX, float valueY)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
public int count

The number of elements stored in values (3 values per quad tree entry).

depthback to summary
public int depth
DISTSQRback to summary
public static final int DISTSQR
heightback to summary
public float height
maxDepthback to summary
public final int maxDepth
maxValuesback to summary
public final int maxValues
neback to summary
public QuadTreeFloat ne
Annotations
@Null
nwback to summary
public QuadTreeFloat nw
Annotations
@Null
poolback to summary
private static final Pool<QuadTreeFloat> pool
seback to summary
public QuadTreeFloat se
Annotations
@Null
swback to summary
public QuadTreeFloat sw
Annotations
@Null
VALUEback to summary
public static final int VALUE
valuesback to summary
public float[] values

For each entry, stores the value, x, and y.

widthback to summary
public float width
Xback to summary
public static final int X
xback to summary
public float x
Yback to summary
public static final int Y
yback to summary
public float y

Constructor Detail

QuadTreeFloatback to summary
public QuadTreeFloat()

Creates a quad tree with 16 for maxValues and 8 for maxDepth.

QuadTreeFloatback to summary
public QuadTreeFloat(int maxValues, int maxDepth)
Parameters
maxValues:int

The maximum number of values stored in each quad tree node. When exceeded, the node is split into 4 child nodes. If the maxDepth has been reached, more than maxValues may be stored.

maxDepth:int

The maximum depth of the tree nodes. Nodes at the maxDepth will not be split and may store more than maxValues number of entries.

Method Detail

addback to summary
public void add(float value, float valueX, float valueY)
addToChildback to summary
private void addToChild(float value, float valueX, float valueY)
findNearestInternalback to summary
private void findNearestInternal(float x, float y, FloatArray result)
growValuesback to summary
protected int growValues()

Returns a new length for values when it is not enough to hold all the entries after maxDepth has been reached.

nearestback to summary
public boolean nearest(float x, float y, FloatArray result)
Parameters
result:FloatArray

For the entry nearest to the specified point, the value, x, y, and square of the distance to the value are added to this array after it is cleared. See VALUE, X, Y, and DISTSQR.

Returns:boolean

false if no entry was found because the quad tree was empty or the specified point is farther than the larger of the quad tree's width or height from an entry. If false is returned the result array is empty.

obtainChildback to summary
private QuadTreeFloat obtainChild(float x, float y, float width, float height, int depth)
queryback to summary
public void query(float centerX, float centerY, float radius, FloatArray results)
Parameters
results:FloatArray

For each entry found within the radius, if any, the value, x, y, and square of the distance to the entry are added to this array. See VALUE, X, Y, and DISTSQR.

queryback to summary
private void query(float centerX, float centerY, float radiusSqr, float rectX, float rectY, float rectSize, FloatArray results)
queryback to summary
public void query(Rectangle rect, FloatArray results)
Parameters
results:FloatArray

For each entry found within the rectangle, if any, the value, x, and y of the entry are added to this array. See VALUE, X, and Y.

resetback to summary
public void reset()

Implements com.badlogic.gdx.utils.Pool.Poolable.reset.

Doc from com.badlogic.gdx.utils.Pool.Poolable.reset.

Resets the object for reuse. Object references should be nulled and fields may be set to default values.

setBoundsback to summary
public void setBounds(float x, float y, float width, float height)
splitback to summary
private void split(float value, float valueX, float valueY)