All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::GridT< T, Base > Class Template Reference

Access to the grid elements. More...

#include <Radiant/Grid.hpp>

Inheritance diagram for Radiant::GridT< T, Base >:

Public Types

typedef const T * const_iterator
 Const iterator for the grid.
 
typedef T * iterator
 Iterator for the grid.
 
typedef T value_type
 Type of grid data.
 

Public Member Functions

template<typename S >
void copyFast (const S &that)
 Copies data from that to this using memcpy. More...
 
T * data ()
 Returns a pointer to the data area. More...
 
const T * data () const
 Returns a const pointer to the data area. More...
 
void fill (const T &val, int xlow, int ylow, int width, int height)
 Fills the grid with the given value. More...
 
void fillCircle (const T &val, Nimble::Vector2 center, float radius)
 Fills a circle in the grid with the given value. More...
 
Nimble::Vector2i geometry () const
 Returns the dimensions of the grid. More...
 
T & get (unsigned x, unsigned y)
 Gets an element from the grid. More...
 
const T & get (unsigned x, unsigned y) const
 Gets an element from the grid. More...
 
T & get (const Nimble::Vector2i &v)
 Gets an element from the grid. More...
 
const T & get (const Nimble::Vector2i &v) const
 Gets an element from the grid. More...
 
T & get (const Nimble::Vector2f &v)
 Gets an element from the grid. More...
 
T & get (const Nimble::Vector2f &v) const
 Gets an element from the grid. More...
 
T & getCyclic (int x, int y)
 Gets an element from the grid. More...
 
template<typename U >
getInterpolated (const Nimble::Vector2f &v) const
 Interpolates an element from the grid values. More...
 
getInterpolated (const Nimble::Vector2f &v) const
 Interpolates an element from the grid values. More...
 
template<typename U >
getInterpolatedSafe (const Nimble::Vector2f &v) const
 Interpolates an element from the grid values. More...
 
getInterpolatedSafe (const Nimble::Vector2f &v) const
 Interpolates an element from the grid values. More...
 
T & getNearest (const Nimble::Vector2f &v)
 Returns a reference to the grid element that is closest to the argument vector. More...
 
getSafe (const Nimble::Vector2i &v) const
 Safe getter for grid data. More...
 
getSafe (int x, int y) const
 Safe getter for grid data. More...
 
 GridT ()
 Constructor.
 
template<class S >
 GridT (S &that)
 Constructs a copy. More...
 
 GridT (T *data, unsigned w, unsigned h)
 Constructor that takes the elements from the data pointer, with given width and height. More...
 
template<typename S >
bool hasIdenticalDimensions (const S &that)
 Checks if the width and height of this and that are identical. More...
 
unsigned height () const
 Returns the height (number of rows) of this object. More...
 
bool isInside (unsigned x, unsigned y) const
 Checks if the given point is inside the grid. More...
 
bool isInside (const Nimble::Vector2i &v) const
 Checks if the given point is inside the grid. More...
 
bool isInside (const Nimble::Vector2f &v) const
 Checks if the given point is inside the grid. More...
 
T * line (int y)
 Get line of the grid. More...
 
const T * line (int y) const
 Get line of the grid. More...
 
void setAll (const T &val)
 Sets all grid elements to the given value. More...
 
unsigned size () const
 Number of elements. More...
 
unsigned sizeBytes () const
 Number of bytes used. More...
 
template<typename S >
void swap (S &that)
 Swaps the contents between this grid, and the other grid. More...
 
unsigned width () const
 Returns the width (number of columns) of this object. More...
 
void zero ()
 Writes zeroes over the memory buffer (using memset)
 

Detailed Description

template<typename T, class Base>
class Radiant::GridT< T, Base >

Access to the grid elements.

Template Parameters
TType of objects to store
BaseBase class of this object

Constructor & Destructor Documentation

template<typename T , class Base >
template<class S >
Radiant::GridT< T, Base >::GridT ( S &  that)
inline

Constructs a copy.

Parameters
thatObject to copy
Template Parameters
SType of object to copy
template<typename T , class Base >
Radiant::GridT< T, Base >::GridT ( T *  data,
unsigned  w,
unsigned  h 
)
inline

Constructor that takes the elements from the data pointer, with given width and height.

Parameters
dataGrid data
wWidth of the grid
hHeight of the grid

Member Function Documentation

template<typename T , class Base >
template<typename S >
void Radiant::GridT< T, Base >::copyFast ( const S &  that)
inline

Copies data from that to this using memcpy.

Parameters
thatGrid to copy from
Template Parameters
SType of object to copy
template<typename T , class Base >
T* Radiant::GridT< T, Base >::data ( )
inline

Returns a pointer to the data area.

Returns
Pointer to the beginning of data
template<typename T , class Base >
const T* Radiant::GridT< T, Base >::data ( ) const
inline

Returns a const pointer to the data area.

Returns
Pointer to the beginning of data
template<typename T , class Base >
void Radiant::GridT< T, Base >::fill ( const T &  val,
int  xlow,
int  ylow,
int  width,
int  height 
)
inline

Fills the grid with the given value.

Parameters
valValue to fill with
xlowStart x-coordinate of area to fill
ylowStart y-coordinate of area to fill
widthWidth of area to fill
heightHeight of area to fill
template<typename T , class Base >
void Radiant::GridT< T, Base >::fillCircle ( const T &  val,
Nimble::Vector2  center,
float  radius 
)
inline

Fills a circle in the grid with the given value.

Parameters
valValue to fill with
centerThe center point of the circle
radiusThe radius of the circle
template<typename T , class Base >
Nimble::Vector2i Radiant::GridT< T, Base >::geometry ( ) const
inline

Returns the dimensions of the grid.

Returns
Integer vector storing width and height.
template<typename T , class Base >
T& Radiant::GridT< T, Base >::get ( unsigned  x,
unsigned  y 
)
inline

Gets an element from the grid.

If the arguments are outside the grid area, then result is undefined. In certain debug builds, the program stops with an assertion, while on typical release builds the function will simply return invalid data.

Parameters
xX-coordinate of element
yY-coordinate of element
Returns
Reference to the element at (x,y)
template<typename T , class Base >
const T& Radiant::GridT< T, Base >::get ( unsigned  x,
unsigned  y 
) const
inline

Gets an element from the grid.

If the arguments are outside the grid area, then result is undefined. In certain debug builds, the program stops with an assertion, while on typical release builds the function will simply return invalid data.

Parameters
xX-coordinate of element
yY-coordinate of element
Returns
Reference to the element at (x,y)
template<typename T , class Base >
T& Radiant::GridT< T, Base >::get ( const Nimble::Vector2i v)
inline

Gets an element from the grid.

Parameters
vCoordinate of element
Returns
Reference to the element at (v.x,v.y)
template<typename T , class Base >
const T& Radiant::GridT< T, Base >::get ( const Nimble::Vector2i v) const
inline

Gets an element from the grid.

Parameters
vCoordinate of element
Returns
Reference to the element at (v.x,v.y)
template<typename T , class Base >
T& Radiant::GridT< T, Base >::get ( const Nimble::Vector2f v)
inline

Gets an element from the grid.

Parameters
vCoordinate of element
Returns
Reference to the element at (v.x,v.y)
template<typename T , class Base >
T& Radiant::GridT< T, Base >::get ( const Nimble::Vector2f v) const
inline

Gets an element from the grid.

Parameters
vCoordinate of element
Returns
Reference to the element at (v.x,v.y)
template<typename T , class Base >
T& Radiant::GridT< T, Base >::getCyclic ( int  x,
int  y 
)
inline

Gets an element from the grid.

Parameters
xX-coordinate of element
yY-coordinate of element
Returns
the element at (x,y), wrapped with modulo logic.
template<typename T , class Base >
template<typename U >
U Radiant::GridT< T, Base >::getInterpolated ( const Nimble::Vector2f v) const
inline

Interpolates an element from the grid values.

This function requires that the grid template type can be multiplied from the right with a floating point number.

Parameters
vCoordinate of element
Returns
Interpolated element
Template Parameters
UType of the result
template<typename T , class Base >
T Radiant::GridT< T, Base >::getInterpolated ( const Nimble::Vector2f v) const
inline

Interpolates an element from the grid values.

Parameters
vCoordinate of element
Returns
Interpolated element
template<typename T , class Base >
template<typename U >
U Radiant::GridT< T, Base >::getInterpolatedSafe ( const Nimble::Vector2f v) const
inline

Interpolates an element from the grid values.

This function requires that the grid template type can be multiplied from the right with a floating point number. Ensures that the values read are inside grid.

Parameters
vCoordinate of element
Returns
The interpolated value from given coordinates
Template Parameters
UType of returned objest
template<typename T , class Base >
T Radiant::GridT< T, Base >::getInterpolatedSafe ( const Nimble::Vector2f v) const
inline

Interpolates an element from the grid values.

Parameters
vCoordinate of element
Returns
The interpolated value from given coordinates
template<typename T , class Base >
T& Radiant::GridT< T, Base >::getNearest ( const Nimble::Vector2f v)
inline

Returns a reference to the grid element that is closest to the argument vector.

Parameters
vCoordinate of element
Returns
a reference to the gridpoint nearest the given coordinate
template<typename T , class Base >
T Radiant::GridT< T, Base >::getSafe ( const Nimble::Vector2i v) const
inline

Safe getter for grid data.

If coordinates are invalid, this will return null element of T.

Parameters
vCoordinate of element
Returns
The requested element from the grid or zero if the coordinate is outside of the grid
template<typename T , class Base >
T Radiant::GridT< T, Base >::getSafe ( int  x,
int  y 
) const
inline

Safe getter for grid data.

If coordinates are invalid, this will return null element of T.

Parameters
xX-coordinate of element
yY-coordinate of element
Returns
The requested element from the grid or zero if the coordinate is outside of the grid
template<typename T , class Base >
template<typename S >
bool Radiant::GridT< T, Base >::hasIdenticalDimensions ( const S &  that)
inline

Checks if the width and height of this and that are identical.

Parameters
thatGrid to compare with
Returns
true if this and that have the same dimensions
Template Parameters
SType of object to compare
template<typename T , class Base >
unsigned Radiant::GridT< T, Base >::height ( ) const
inline

Returns the height (number of rows) of this object.

Returns
Number of rows of this grid
template<typename T , class Base >
bool Radiant::GridT< T, Base >::isInside ( unsigned  x,
unsigned  y 
) const
inline

Checks if the given point is inside the grid.

Parameters
xX-coordinate of point
yY-coordinate of point
Returns
true if the given coordinates are inside the grid
template<typename T , class Base >
bool Radiant::GridT< T, Base >::isInside ( const Nimble::Vector2i v) const
inline

Checks if the given point is inside the grid.

Parameters
vPoint coordinate
Returns
true if the given coordinates are inside the grid
template<typename T , class Base >
bool Radiant::GridT< T, Base >::isInside ( const Nimble::Vector2f v) const
inline

Checks if the given point is inside the grid.

Parameters
vPoint coordinate
Returns
true if the given coordinates are inside the grid
template<typename T , class Base >
T* Radiant::GridT< T, Base >::line ( int  y)
inline

Get line of the grid.

Returns
a pointer to one line (aka row)
Parameters
yLine number
template<typename T , class Base >
const T* Radiant::GridT< T, Base >::line ( int  y) const
inline

Get line of the grid.

Returns
a const pointer to one line (aka row)
Parameters
yLine number
template<typename T , class Base >
void Radiant::GridT< T, Base >::setAll ( const T &  val)
inline

Sets all grid elements to the given value.

Parameters
valValue to fill with
template<typename T , class Base >
unsigned Radiant::GridT< T, Base >::size ( ) const
inline

Number of elements.

Returns
Number of elements inside the grid
template<typename T , class Base >
unsigned Radiant::GridT< T, Base >::sizeBytes ( ) const
inline

Number of bytes used.

Returns
size multiplied with size of stored element.
template<typename T , class Base >
template<typename S >
void Radiant::GridT< T, Base >::swap ( S &  that)
inline

Swaps the contents between this grid, and the other grid.

Parameters
thatGrid to swap with
Template Parameters
SType of object to copy
template<typename T , class Base >
unsigned Radiant::GridT< T, Base >::width ( ) const
inline

Returns the width (number of columns) of this object.

Returns
Number of columns of this grid