Class QuadTreeFloat

  • All Implemented Interfaces:
    Pool.Poolable

    public class QuadTreeFloat
    extends java.lang.Object
    implements Pool.Poolable
    A quad tree that stores a float for each point.
    • Constructor Detail

      • QuadTreeFloat

        public QuadTreeFloat()
        Creates a quad tree with 16 for maxValues and 8 for maxDepth.
      • QuadTreeFloat

        public QuadTreeFloat​(int maxValues,
                             int maxDepth)
        Parameters:
        maxValues - 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 - 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

      • setBounds

        public void setBounds​(float x,
                              float y,
                              float width,
                              float height)
      • add

        public void add​(float value,
                        float valueX,
                        float valueY)
      • growValues

        protected int growValues()
        Returns a new length for values when it is not enough to hold all the entries after maxDepth has been reached.
      • query

        public void query​(float centerX,
                          float centerY,
                          float radius,
                          FloatArray results)
        Parameters:
        results - 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.
      • query

        public void query​(Rectangle rect,
                          FloatArray results)
        Parameters:
        results - 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.
      • nearest

        public boolean nearest​(float x,
                               float y,
                               FloatArray result)
        Parameters:
        result - 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:
        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.
      • reset

        public void reset()
        Description copied from interface: Pool.Poolable
        Resets the object for reuse. Object references should be nulled and fields may be set to default values.
        Specified by:
        reset in interface Pool.Poolable