Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::GridIndexBox Class Reference

Class for managing a grid with objects on overlapping areas. More...

Collaboration diagram for Burger::GridIndexBox:

Classes

struct  Entry
 Data chunk for GridIndexBox. More...
 
struct  iterator
 STL compatible iterator. More...
 

Public Member Functions

SimpleArray< Entry * > * GetCell (uint_t uX, uint_t uY) const
 Get the entry at a location in the grid.
 
void GetContainingCellClamped (Vector2D_t *pOutput, const Vector2D_t *pInput) const
 Get the high precision location that contains a specific point.
 
void GetContainingCellsClamped (Vector4D_t *pOutput, const Vector4D_t *pInput) const
 Get the high precision location that contains a specific rectangle of cells.
 
 GridIndexBox (const Vector4D_t *pBounds, uint_t uXCells, uint_t uYCells)
 Construct a grid of a specific size.
 
 GridIndexBox (const Vector4D_t *pBounds, uintptr_t uItemCountEstimate, float fGridScale=0.707f)
 Construct a grid of an optimum size.
 
 ~GridIndexBox ()
 Dispose of all allocated memory.
 
const Vector4D_tGetBounds (void) const
 Get the bounds rectangle.
 
uint_t GetQueryCount (void) const
 Get the number of times begin(const Vector4D_t *) has been called.
 
iterator begin (const Vector4D_t *pBounds)
 Create an iterator for a sub-rectangle of the grid.
 
iterator begin_all (void)
 Create an iterator for all of the data in the grid.
 
iterator end (void) const
 Create an iterator with no data.
 
void add (const Vector4D_t *pBounds, uint_t uValue)
 Insert data into the grid.
 
void remove (Entry *pEntry)
 Remove an entry from the grid.
 
iterator find (const Vector4D_t *pBounds, uint_t uValue)
 Find an entry on the grid.
 
EntryFindData (const Vector2D_t *pPoint, uint_t uValue) const
 Find a single entry on the grid.
 

Private Attributes

Vector4D_t m_BoundsRect
 Bounds rectangle for the grid.
 
SimpleArray< Entry * > * m_pGrid
 Array of pointers to arrays in the grid.
 
uint_t m_uXCells
 Number of cells wide.
 
uint_t m_uYCells
 Number of cells high.
 
float m_fXCells
 Number of cells wide as a float.
 
float m_fYCells
 Number of cells high as a float.
 
uint_t m_uQueryCount
 Token for iterating over the grid.
 

Detailed Description

Class for managing a grid with objects on overlapping areas.


For some algorithms, it may be needed to insert data into overlapping regions onto a grid so when a location on a grid is queried, all objects that are in that location on the grid can be found.

See also
GridIndexPoints

Constructor & Destructor Documentation

◆ GridIndexBox() [1/2]

Burger::GridIndexBox::GridIndexBox ( const Vector4D_t * pBounds,
uint_t uXCells,
uint_t uYCells )

Construct a grid of a specific size.


Given a grid size and a bounds rect that encompasses it, allocate memory for the grid and initialize it to empty arrays.

Parameters
pBoundsPointer to the bounds rectangle
uXCellsWidth of the grid in cells
uYCellsHeight of the grid in cells
See also
GridIndexBox(const Vector4D_t *,uintptr_t,float)

◆ GridIndexBox() [2/2]

Burger::GridIndexBox::GridIndexBox ( const Vector4D_t * pBounds,
uintptr_t uItemCountEstimate,
float fGridScale = 0.707f )

Construct a grid of an optimum size.


Given a grid size in elements and a bounds rect that encompasses it, allocate memory for the grid and initialize it to NULL entries.

The actual size will be generated to be as close to square that will hold as many elements as uItemCountEstimate requests.

Parameters
pBoundsPointer to the bounds rectangle
uItemCountEstimateNumber of total elements in the grid
fGridScaleScale value to increase precision on the grid for the bounds rect
See also
GridIndexBox(const Vector4D_t *,uint_t,uint_t)

◆ ~GridIndexBox()

Burger::GridIndexBox::~GridIndexBox ( )

Dispose of all allocated memory.


Standard destructor

Member Function Documentation

◆ add()

void BURGER_API Burger::GridIndexBox::add ( const Vector4D_t * pBounds,
uint_t uValue )

Insert data into the grid.


In the area indicated by pBounds, create an entry with the data and insert it into the grid.

Parameters
pBoundsPointer to the area of the grid to insert uValue
uValueData to place in the area in the grid.
See also
remove(Entry *)

◆ begin()

Burger::GridIndexBox::iterator Burger::GridIndexBox::begin ( const Vector4D_t * pBounds)

Create an iterator for a sub-rectangle of the grid.


Clip a high resolution rectangle from the grid and set up an iterator that will traverse only the requested data.

Returns
An iterator set up to the requested data.
See also
end(void) const or begin_all(void)

◆ begin_all()

iterator Burger::GridIndexBox::begin_all ( void )
inline

Create an iterator for all of the data in the grid.


Set up an iterator that will traverse all of the data.

Returns
An iterator set up to traverse the entire grid.
See also
end(void) const or begin(const Vector4D_t *)

◆ end()

iterator Burger::GridIndexBox::end ( void ) const
inline

Create an iterator with no data.


This iterator is used for comparisons to determine if the iterator returned by begin() or begin_all() has reached the end of the data.

Returns
Iterator that is pointing past the end of the data.
See also
begin(const Vector4D_t *) or begin_all(void)

◆ find()

Burger::GridIndexBox::iterator Burger::GridIndexBox::find ( const Vector4D_t * pBounds,
uint_t uValue )

Find an entry on the grid.


Scan the grid if an entry if present, if so, return an iterator pointing to the requested entry. Otherwise, the iterator is set to point to the end of the data.

Parameters
pBoundsPointer to the area in the grid to start searching.
uValueValue to match.
See also
FindData(const Vector2D_t *,uint_t) const

◆ FindData()

Burger::GridIndexBox::Entry *BURGER_API Burger::GridIndexBox::FindData ( const Vector2D_t * pPoint,
uint_t uValue ) const

Find a single entry on the grid.


Scan the grid if an entry if present, if so, return the pointer to the requested entry. Otherwise, return NULL.

Parameters
pPointPointer to the point in the grid to search.
uValueValue to match.
See also
find(const Vector4D_t *,uint_t)

◆ GetBounds()

const Vector4D_t * Burger::GridIndexBox::GetBounds ( void ) const
inline

Get the bounds rectangle.


Returns
Pointer to the bounds rectangle

◆ GetCell()

SimpleArray< Entry * > * Burger::GridIndexBox::GetCell ( uint_t uX,
uint_t uY ) const
inline

Get the entry at a location in the grid.


Retrieve the root entry, if any, at the requested location in the grid

Parameters
uXX coordinate in the grid
uYY coordinate in the grid
Returns
Pointer to a data entry or NULL if no data is present in the location.
See also
GetContainingCellClamped(Vector2D_t *,const Vector2D_t *) const or GridIndexBox::Entry

◆ GetContainingCellClamped()

void BURGER_API Burger::GridIndexBox::GetContainingCellClamped ( Vector2D_t * pOutput,
const Vector2D_t * pInput ) const

Get the high precision location that contains a specific point.


Given a high precision location in the grid, clamp it onto the grid

Parameters
pOutputPointer to store the adjusted location.
pInputPointer to the high resolution location
See also
GetCell(uint_t,uint_t) const or GetContainingCellsClamped(Vector4D_t *,const Vector4D_t *) const

◆ GetContainingCellsClamped()

void BURGER_API Burger::GridIndexBox::GetContainingCellsClamped ( Vector4D_t * pOutput,
const Vector4D_t * pInput ) const

Get the high precision location that contains a specific rectangle of cells.


Given a high precision area in the grid, clamp it onto the grid and return in cells.

Parameters
pOutputPointer to store the adjusted rectangle.
pInputPointer to the high resolution rectangle
See also
GetCell(uint_t,uint_t) const or GetContainingCellClamped(Vector2D_t *,const Vector2D_t *) const

◆ GetQueryCount()

uint_t Burger::GridIndexBox::GetQueryCount ( void ) const
inline

Get the number of times begin(const Vector4D_t *) has been called.


Returns
Counter that has the number of times a search was performed.

◆ remove()

void BURGER_API Burger::GridIndexBox::remove ( Entry * pEntry)

Remove an entry from the grid.


Check if the entry is in the grid, and if so, removes it and then deletes the memory for the entry.

Parameters
pEntryPointer to the Entry to dispose of.
See also
add(const Vector4D_t *,uint_t)

Member Data Documentation

◆ m_BoundsRect

Vector4D_t Burger::GridIndexBox::m_BoundsRect
private

Bounds rectangle for the grid.

◆ m_fXCells

float Burger::GridIndexBox::m_fXCells
private

Number of cells wide as a float.

◆ m_fYCells

float Burger::GridIndexBox::m_fYCells
private

Number of cells high as a float.

◆ m_pGrid

SimpleArray<Entry* >* Burger::GridIndexBox::m_pGrid
private

Array of pointers to arrays in the grid.

◆ m_uQueryCount

uint_t Burger::GridIndexBox::m_uQueryCount
private

Token for iterating over the grid.

◆ m_uXCells

uint_t Burger::GridIndexBox::m_uXCells
private

Number of cells wide.

◆ m_uYCells

uint_t Burger::GridIndexBox::m_uYCells
private

Number of cells high.