Class for managing a grid with objects on overlapping areas. More...
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_t * | GetBounds (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. | |
Entry * | FindData (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. | |
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.
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.
pBounds | Pointer to the bounds rectangle |
uXCells | Width of the grid in cells |
uYCells | Height of the grid in cells |
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.
pBounds | Pointer to the bounds rectangle |
uItemCountEstimate | Number of total elements in the grid |
fGridScale | Scale value to increase precision on the grid for the bounds rect |
Burger::GridIndexBox::~GridIndexBox | ( | ) |
Dispose of all allocated memory.
Standard destructor
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.
pBounds | Pointer to the area of the grid to insert uValue |
uValue | Data to place in the area in the grid. |
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.
|
inline |
Create an iterator for all of the data in the grid.
Set up an iterator that will traverse all of the data.
|
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.
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.
pBounds | Pointer to the area in the grid to start searching. |
uValue | Value to match. |
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.
pPoint | Pointer to the point in the grid to search. |
uValue | Value to match. |
|
inline |
Get the bounds rectangle.
|
inline |
Get the entry at a location in the grid.
Retrieve the root entry, if any, at the requested location in the grid
uX | X coordinate in the grid |
uY | Y coordinate in the grid |
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
pOutput | Pointer to store the adjusted location. |
pInput | Pointer to the high resolution location |
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.
pOutput | Pointer to store the adjusted rectangle. |
pInput | Pointer to the high resolution rectangle |
|
inline |
Get the number of times begin(const Vector4D_t *) has been called.
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.
pEntry | Pointer to the Entry to dispose of. |
|
private |
Bounds rectangle for the grid.
|
private |
Number of cells wide as a float.
|
private |
Number of cells high as a float.
|
private |
Array of pointers to arrays in the grid.
|
private |
Token for iterating over the grid.
|
private |
Number of cells wide.
|
private |
Number of cells high.