MCPcopy
hub / github.com/libgdx/libgdx / QuadTreeFloat

Class QuadTreeFloat

gdx/src/com/badlogic/gdx/utils/QuadTreeFloat.java:26–275  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

24/** A quad tree that stores a float for each point.
25 * @author Nathan Sweet */
26public class QuadTreeFloat implements Poolable {
27 static public final int VALUE = 0, X = 1, Y = 2, DISTSQR = 3;
28
29 static private final Pool<QuadTreeFloat> pool = new Pool(128, 4096) {
30 protected Object newObject () {
31 return new QuadTreeFloat();
32 }
33 };
34
35 public final int maxValues, maxDepth;
36 public float x, y, width, height;
37 public int depth;
38 public @Null QuadTreeFloat nw, ne, sw, se;
39
40 /** For each entry, stores the value, x, and y. */
41 public float[] values;
42
43 /** The number of elements stored in {@link #values} (3 values per quad tree entry). */
44 public int count;
45
46 /** Creates a quad tree with 16 for maxValues and 8 for maxDepth. */
47 public QuadTreeFloat () {
48 this(16, 8);
49 }
50
51 /** @param maxValues The maximum number of values stored in each quad tree node. When exceeded, the node is split into 4 child
52 * nodes. If the maxDepth has been reached, more than maxValues may be stored.
53 * @param maxDepth The maximum depth of the tree nodes. Nodes at the maxDepth will not be split and may store more than
54 * maxValues number of entries. */
55 public QuadTreeFloat (int maxValues, int maxDepth) {
56 this.maxValues = maxValues * 3;
57 this.maxDepth = maxDepth;
58 values = new float[this.maxValues];
59 }
60
61 public void setBounds (float x, float y, float width, float height) {
62 this.x = x;
63 this.y = y;
64 this.width = width;
65 this.height = height;
66 }
67
68 public void add (float value, float valueX, float valueY) {
69 int count = this.count;
70 if (count == -1) {
71 addToChild(value, valueX, valueY);
72 return;
73 }
74 if (depth < maxDepth) {
75 if (count == maxValues) {
76 split(value, valueX, valueY);
77 return;
78 }
79 } else if (count == values.length) //
80 values = Arrays.copyOf(values, growValues());
81 values[count] = value;
82 values[count + 1] = valueX;
83 values[count + 2] = valueY;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected