QuadTree
QuadTree
QuadTree for efficient 2D spatial indexing and querying. More…
#include <QuadTree.hpp>
Public Functions
| Name | |
|---|---|
| QuadTree(BoundingBox const & bounds, int depth =0) | |
| ~QuadTree() =default | |
| QuadTree(QuadTree && other) | |
| QuadTree & | operator=(QuadTree && other) |
| QuadTree(QuadTree const & ) =delete | |
| QuadTree & | operator=(QuadTree const & ) =delete |
| bool | insert(float x, float y, T data) Insert a point with associated data into the quadtree. |
| void | query(BoundingBox const & query_bounds, std::vector< QuadTreePoint< T > > & results) const Query points within a bounding box. |
| void | queryPointers(BoundingBox const & query_bounds, std::vector< QuadTreePoint< T > const * > & results) const Query points within a bounding box, returning pointers to stored points. |
| QuadTreePoint< T > const * | findNearest(float x, float y, float max_distance) const Find the nearest point to the given coordinates within a maximum distance. |
| void | clear() Clear all points from the quadtree. |
| size_t | size() const Get the total number of points in the quadtree. |
| BoundingBox const & | getBounds() const Get the bounding box of this node. |
Public Attributes
| Name | |
|---|---|
| int | MAX_DEPTH |
| int | MAX_POINTS_PER_NODE |
Detailed Description
template <typename T >
class QuadTree;QuadTree for efficient 2D spatial indexing and querying.
This implementation supports inserting points with associated data and efficiently querying points within a bounding box or near a specific location.
Public Functions Documentation
function QuadTree
explicit QuadTree(
BoundingBox const & bounds,
int depth =0
)function ~QuadTree
~QuadTree() =defaultfunction QuadTree
QuadTree(
QuadTree && other
)function operator=
QuadTree & operator=(
QuadTree && other
)function QuadTree
QuadTree(
QuadTree const &
) =deletefunction operator=
QuadTree & operator=(
QuadTree const &
) =deletefunction insert
bool insert(
float x,
float y,
T data
)Insert a point with associated data into the quadtree.
Parameters:
- x X coordinate
- y Y coordinate
- data Associated data
Return: True if successfully inserted
Precondition: Point (x, y) must be within the quadtree bounds. Inserting out-of-bounds points is a logic error and will trigger an assertion failure.
function query
void query(
BoundingBox const & query_bounds,
std::vector< QuadTreePoint< T > > & results
) constQuery points within a bounding box.
Parameters:
- query_bounds The bounding box to search within
- results Vector to store found points
function queryPointers
void queryPointers(
BoundingBox const & query_bounds,
std::vector< QuadTreePoint< T > const * > & results
) constQuery points within a bounding box, returning pointers to stored points.
Parameters:
- query_bounds The bounding box to search within
- results Vector to store pointers to found points
function findNearest
QuadTreePoint< T > const * findNearest(
float x,
float y,
float max_distance
) constFind the nearest point to the given coordinates within a maximum distance.
Parameters:
- x X coordinate to search near
- y Y coordinate to search near
- max_distance Maximum distance to search
Return: Pointer to the nearest point, or nullptr if none found
function clear
void clear()Clear all points from the quadtree.
function size
size_t size() constGet the total number of points in the quadtree.
Return: Total point count
function getBounds
inline BoundingBox const & getBounds() constGet the bounding box of this node.
Return: The bounding box
Public Attributes Documentation
variable MAX_DEPTH
static int MAX_DEPTH = 8;variable MAX_POINTS_PER_NODE
static int MAX_POINTS_PER_NODE = 16;Updated on 2026-11-13 at 20:25:40 +0000