Gamedev Framework (gf)  0.8.0
A C++14 framework for 2D games
Classes | Public Member Functions | List of all members
gf::QuadTree< T, U, Size > Class Template Reference

An implementation of quadtree. More...

#include <gf/Spatial.h>

Public Member Functions

 QuadTree (const Box< U, 2 > &bounds)
 Constructor. More...
 
bool insert (const T &value, const Box< U, 2 > &bounds)
 Insert an object in the tree. More...
 
std::size_t query (const Box< U, 2 > &bounds, SpatialQueryCallback< T > callback, SpatialQuery kind=SpatialQuery::Intersect) const
 Query objects in the tree. More...
 
void clear ()
 Remove all the objects from the tree. More...
 

Detailed Description

template<typename T, typename U = float, std::size_t Size = 16>
class gf::QuadTree< T, U, Size >

An implementation of quadtree.

See also
gf::RStarTree
Quadtree - Wikipedia

Constructor & Destructor Documentation

◆ QuadTree()

template<typename T , typename U = float, std::size_t Size = 16>
gf::QuadTree< T, U, Size >::QuadTree ( const Box< U, 2 > &  bounds)
inline

Constructor.

Parameters
boundsThe global bounds for objects in the tree

Member Function Documentation

◆ clear()

template<typename T , typename U = float, std::size_t Size = 16>
void gf::QuadTree< T, U, Size >::clear ( )
inline

Remove all the objects from the tree.

◆ insert()

template<typename T , typename U = float, std::size_t Size = 16>
bool gf::QuadTree< T, U, Size >::insert ( const T value,
const Box< U, 2 > &  bounds 
)
inline

Insert an object in the tree.

Parameters
valueThe object to insert
boundsThe bounds of the object
Returns
True if the object has been inserted

◆ query()

template<typename T , typename U = float, std::size_t Size = 16>
std::size_t gf::QuadTree< T, U, Size >::query ( const Box< U, 2 > &  bounds,
SpatialQueryCallback< T callback,
SpatialQuery  kind = SpatialQuery::Intersect 
) const
inline

Query objects in the tree.

Parameters
boundsThe bounds of the query
callbackThe callback to apply to found objects
kindThe kind of spatial query
Returns
The number of objects found