tile2d
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Grid< T, Int > Class Template Reference

Used for spatial indexing. More...

#include <spatial.hpp>

Classes

struct  GridElement
 
struct  ParentCell
 

Public Types

using GridMap = boost::unordered_flat_map<ivec2, ParentCell>
 

Public Member Functions

 Grid (Float cellSize=(Float) tcW)
 Constructs a new Grid.
 
uint16_t insert (const AABB< Float > &aabb, const T &data)
 Inserts a new element into the grid.
 
void relocate (uint16_t idx, const AABB< Float > &newAABB)
 Relocates an already existing element within the grid.
 
void erase (uint16_t idx)
 Erases an element.
 
template<typename Callback >
void queryIntersects (const AABB< Float > &area, Callback &&clbk) const
 
void cleanup ()
 Removes empty cells, if any.
 
GridMap & gridMap ()
 Returns the map of all cells.
 

Protected Member Functions

ivec2 getCellCoords (const vec2 &coords) const
 
bool contains (const Int &min, const Int &max, const Int &point)
 
bool contains (const ivec2 &min, const ivec2 &max, const ivec2 &point)
 

Protected Attributes

Float m_invCellSize
 
Float m_cellSize
 
FreeList< GridElement, uint16_t > m_elementList
 
GridMap m_cells
 
std::vector< ivec2 > m_possiblyEmptyCells
 

Detailed Description

template<class T, typename Int = int32_t>
class Grid< T, Int >

Used for spatial indexing.

Constructor & Destructor Documentation

◆ Grid()

template<class T , typename Int = int32_t>
Grid< T, Int >::Grid ( Float cellSize = (Float)tcW)
inline

Constructs a new Grid.

@parram cellSize the side length of a cell within this grid

Member Function Documentation

◆ erase()

template<class T , typename Int = int32_t>
void Grid< T, Int >::erase ( uint16_t idx)
inline

Erases an element.

Parameters
idxThe id of the element to remove

◆ gridMap()

template<class T , typename Int = int32_t>
GridMap & Grid< T, Int >::gridMap ( )
inline

Returns the map of all cells.

Returns
the map of all cells

◆ insert()

template<class T , typename Int = int32_t>
uint16_t Grid< T, Int >::insert ( const AABB< Float > & aabb,
const T & data )
inline

Inserts a new element into the grid.

Parameters
aabbThe AABB of the element
dataThe user data of the element
Returns
The id of the element

◆ relocate()

template<class T , typename Int = int32_t>
void Grid< T, Int >::relocate ( uint16_t idx,
const AABB< Float > & newAABB )
inline

Relocates an already existing element within the grid.

Parameters
idxThe id of the element
newAABBThe new AABB of the element

The documentation for this class was generated from the following file: