FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::Matrix< T > Class Template Reference

A container to store a 2D matrix of any type. More...

#include <C_matrix.hpp>

Public Types

using iterator = T*
 
using const_iterator = T const*
 

Public Member Functions

 Matrix ()
 Construct a empty matrix.
 
 Matrix (std::initializer_list< std::initializer_list< T > > data)
 Construct a matrix with a initializer list.
 
template<class Tvec >
 Matrix (fge::Vector2< Tvec > const &msize)
 Construct a matrix with a certain size.
 
 Matrix (std::size_t sizex, std::size_t sizey)
 Construct a matrix with a certain size.
 
template<class Tvec >
 Matrix (fge::Vector2< Tvec > const &msize, T const &defaultValue)
 Construct a matrix with a certain size and a default value.
 
 Matrix (std::size_t sizex, std::size_t sizey, T const &defaultValue)
 Construct a matrix with a certain size and a default value.
 
 Matrix (fge::Matrix< T > const &m)
 
 Matrix (fge::Matrix< T > &&m) noexcept
 
void clear ()
 Clear the matrix and set the size to 0,0.
 
fge::Matrix< T > & operator= (fge::Matrix< T > const &m)
 
fge::Matrix< T > & operator= (fge::Matrix< T > &&m) noexcept
 
T * operator[] (std::size_t x)
 Get the specified row.
 
T const * operator[] (std::size_t x) const
 
T const & get (std::size_t x, std::size_t y) const
 Get the specified value.
 
template<class Tvec >
T const & get (fge::Vector2< Tvec > const &coord) const
 Get the specified value.
 
T & get (std::size_t x, std::size_t y)
 
template<class Tvec >
T & get (fge::Vector2< Tvec > const &coord)
 
bool get (std::size_t x, std::size_t y, T &buff) const
 Get the specified value without throwing an exception.
 
template<class Tvec >
bool get (fge::Vector2< Tvec > const &coord, T &buff) const
 Get the specified value without throwing an exception.
 
T * getPtr (std::size_t x, std::size_t y)
 Get the specified value as a pointer.
 
template<class Tvec >
T * getPtr (fge::Vector2< Tvec > const &coord)
 Get the specified value as a pointer.
 
T const * getPtr (std::size_t x, std::size_t y) const
 
template<class Tvec >
T const * getPtr (fge::Vector2< Tvec > const &coord) const
 
void set (std::size_t x, std::size_t y, T &&value)
 Set the specified value by moving it.
 
template<class Tvec >
void set (fge::Vector2< Tvec > const &coord, T &&value)
 Set the specified value by moving it.
 
void set (std::size_t x, std::size_t y, T const &value)
 Set the specified value by copying it.
 
template<class Tvec >
void set (fge::Vector2< Tvec > const &coord, T const &value)
 Set the specified value by copying it.
 
void set (std::initializer_list< std::initializer_list< T > > data)
 Set values with a initializer list.
 
std::size_t getTotalSize () const
 Get the total number of elements in the matrix.
 
fge::Vector2< std::size_t > const & getSize () const
 Get the size of the matrix as a vector2.
 
std::size_t getSizeX () const
 Get the x size of the matrix.
 
std::size_t getSizeY () const
 Get the y size of the matrix.
 
T const * get () const
 Get the 2D array of the matrix.
 
T * get ()
 
fge::Matrix< T >::iterator begin ()
 
fge::Matrix< T >::iterator end ()
 
fge::Matrix< T >::const_iterator begin () const
 
fge::Matrix< T >::const_iterator end () const
 
template<class Tvec >
void setSize (fge::Vector2< Tvec > const &msize)
 Set the size of the matrix.
 
void setSize (std::size_t sizex, std::size_t sizey)
 Set the size of the matrix.
 
void fill (T const &value)
 Fill the matrix by copying a value.
 
void rotateClockwise ()
 Rotate the matrix by 90 degrees clockwise.
 
void rotateCounterClockwise ()
 Rotate the matrix by 90 degrees counter-clockwise.
 
void rotateClockwise (unsigned int n)
 Rotate the matrix by 90 degrees clockwise and n times.
 
void rotateCounterClockwise (unsigned int n)
 Rotate the matrix by 90 degrees counter-clockwise and n times.
 
void flipHorizontally ()
 Flip the matrix horizontally.
 
void flipVertically ()
 Flip the matrix vertically.
 
void toVector (std::vector< T > &buff) const
 Insert all elements of the matrix in a 1D vector.
 
template<class Tvec >
T const & get (fge::Vector2< Tvec > const &coord) const
 
template<class Tvec >
T const * getPtr (fge::Vector2< Tvec > const &coord) const
 

Detailed Description

template<class T>
class fge::Matrix< T >

A container to store a 2D matrix of any type.

Template Parameters
TThe type of the matrix

Constructor & Destructor Documentation

◆ Matrix() [1/6]

template<class T >
fge::Matrix< T >::Matrix ( )

Construct a empty matrix.

◆ Matrix() [2/6]

template<class T >
fge::Matrix< T >::Matrix ( std::initializer_list< std::initializer_list< T > > data)

Construct a matrix with a initializer list.

Make sure that the number of elements in a row is the same to all other rows.

Parameters
dataThe initializer list

◆ Matrix() [3/6]

template<class T >
template<class Tvec >
fge::Matrix< T >::Matrix ( fge::Vector2< Tvec > const & msize)
explicit

Construct a matrix with a certain size.

Template Parameters
TvecThe type of the vector
Parameters
msizeThe size of the matrix

◆ Matrix() [4/6]

template<class T >
fge::Matrix< T >::Matrix ( std::size_t sizex,
std::size_t sizey )

Construct a matrix with a certain size.

Parameters
sizexThe size of the matrix on the x axis
sizeyThe size of the matrix on the y axis

◆ Matrix() [5/6]

template<class T >
template<class Tvec >
fge::Matrix< T >::Matrix ( fge::Vector2< Tvec > const & msize,
T const & defaultValue )

Construct a matrix with a certain size and a default value.

Template Parameters
TvecThe type of the vector
Parameters
msizeThe size of the matrix
defaultValueThe value to fill the matrix with

◆ Matrix() [6/6]

template<class T >
fge::Matrix< T >::Matrix ( std::size_t sizex,
std::size_t sizey,
T const & defaultValue )

Construct a matrix with a certain size and a default value.

Parameters
sizexThe size of the matrix on the x axis
sizeyThe size of the matrix on the y axis
defaultValueThe value to fill the matrix with

Member Function Documentation

◆ clear()

template<class T >
void fge::Matrix< T >::clear ( )

Clear the matrix and set the size to 0,0.

◆ fill()

template<class T >
void fge::Matrix< T >::fill ( T const & value)

Fill the matrix by copying a value.

Parameters
valueThe value to copy

◆ flipHorizontally()

template<class T >
void fge::Matrix< T >::flipHorizontally ( )

Flip the matrix horizontally.

◆ flipVertically()

template<class T >
void fge::Matrix< T >::flipVertically ( )

Flip the matrix vertically.

◆ get() [1/5]

template<class T >
T const * fge::Matrix< T >::get ( ) const
inlinenodiscard

Get the 2D array of the matrix.

Returns
The 2D array as a pointer of the first element

◆ get() [2/5]

template<class T >
template<class Tvec >
T const & fge::Matrix< T >::get ( fge::Vector2< Tvec > const & coord) const
inline

Get the specified value.

Template Parameters
TvecThe type of the vector
Parameters
coordThe coordinates of the value
Returns
A reference to the value

◆ get() [3/5]

template<class T >
template<class Tvec >
bool fge::Matrix< T >::get ( fge::Vector2< Tvec > const & coord,
T & buff ) const

Get the specified value without throwing an exception.

Template Parameters
TvecThe type of the vector
Parameters
coordThe coordinates of the value
buffThe value to store the result in
Returns
true if the value was found, false otherwise

◆ get() [4/5]

template<class T >
T const & fge::Matrix< T >::get ( std::size_t x,
std::size_t y ) const
inline

Get the specified value.

Parameters
xThe x index of the value
yThe y index of the value
Returns
A reference to the value

◆ get() [5/5]

template<class T >
bool fge::Matrix< T >::get ( std::size_t x,
std::size_t y,
T & buff ) const

Get the specified value without throwing an exception.

Parameters
xThe x index of the value
yThe y index of the value
buffThe value to store the result in
Returns
true if the value was found, false otherwise

◆ getPtr() [1/2]

template<class T >
template<class Tvec >
T * fge::Matrix< T >::getPtr ( fge::Vector2< Tvec > const & coord)

Get the specified value as a pointer.

Template Parameters
TvecThe type of the vector
Parameters
coordThe coordinates of the value
Returns
A pointer to the value or nullptr if the value was not found

◆ getPtr() [2/2]

template<class T >
T * fge::Matrix< T >::getPtr ( std::size_t x,
std::size_t y )

Get the specified value as a pointer.

Parameters
xThe x index of the value
yThe y index of the value
Returns
A pointer to the value or nullptr if the value was not found

◆ getSize()

template<class T >
fge::Vector2< std::size_t > const & fge::Matrix< T >::getSize ( ) const
inlinenodiscard

Get the size of the matrix as a vector2.

Returns
The size of the matrix as a vector2

◆ getSizeX()

template<class T >
std::size_t fge::Matrix< T >::getSizeX ( ) const
inlinenodiscard

Get the x size of the matrix.

Returns
The x size of the matrix

◆ getSizeY()

template<class T >
std::size_t fge::Matrix< T >::getSizeY ( ) const
inlinenodiscard

Get the y size of the matrix.

Returns
The y size of the matrix

◆ getTotalSize()

template<class T >
std::size_t fge::Matrix< T >::getTotalSize ( ) const
inlinenodiscard

Get the total number of elements in the matrix.

Returns
The total number of elements

◆ operator[]()

template<class T >
T * fge::Matrix< T >::operator[] ( std::size_t x)
inline

Get the specified row.

Parameters
xThe index of the row
Returns
The row as a vector

◆ rotateClockwise() [1/2]

template<class T >
void fge::Matrix< T >::rotateClockwise ( )

Rotate the matrix by 90 degrees clockwise.

◆ rotateClockwise() [2/2]

template<class T >
void fge::Matrix< T >::rotateClockwise ( unsigned int n)

Rotate the matrix by 90 degrees clockwise and n times.

Parameters
nThe number of times to rotate

◆ rotateCounterClockwise() [1/2]

template<class T >
void fge::Matrix< T >::rotateCounterClockwise ( )

Rotate the matrix by 90 degrees counter-clockwise.

◆ rotateCounterClockwise() [2/2]

template<class T >
void fge::Matrix< T >::rotateCounterClockwise ( unsigned int n)

Rotate the matrix by 90 degrees counter-clockwise and n times.

Parameters
nThe number of times to rotate

◆ set() [1/5]

template<class T >
template<class Tvec >
void fge::Matrix< T >::set ( fge::Vector2< Tvec > const & coord,
T && value )

Set the specified value by moving it.

Template Parameters
TvecThe type of the vector
Parameters
coordThe coordinates of the value
valueThe value to move

◆ set() [2/5]

template<class T >
template<class Tvec >
void fge::Matrix< T >::set ( fge::Vector2< Tvec > const & coord,
T const & value )

Set the specified value by copying it.

Template Parameters
TvecThe type of the vector
Parameters
coordThe coordinates of the value
valueThe value to copy

◆ set() [3/5]

template<class T >
void fge::Matrix< T >::set ( std::initializer_list< std::initializer_list< T > > data)

Set values with a initializer list.

The size of the matrix will be set to the size of the provided list.

Parameters
dataThe initializer list

◆ set() [4/5]

template<class T >
void fge::Matrix< T >::set ( std::size_t x,
std::size_t y,
T && value )

Set the specified value by moving it.

Parameters
xThe x index of the value
yThe y index of the value
valueThe value to move

◆ set() [5/5]

template<class T >
void fge::Matrix< T >::set ( std::size_t x,
std::size_t y,
T const & value )

Set the specified value by copying it.

Parameters
xThe x index of the value
yThe y index of the value
valueThe value to copy

◆ setSize() [1/2]

template<class T >
template<class Tvec >
void fge::Matrix< T >::setSize ( fge::Vector2< Tvec > const & msize)

Set the size of the matrix.

Template Parameters
TvecThe type of the vector
Parameters
msizeThe size of the matrix

◆ setSize() [2/2]

template<class T >
void fge::Matrix< T >::setSize ( std::size_t sizex,
std::size_t sizey )

Set the size of the matrix.

Parameters
sizexThe x size of the matrix
sizeyThe y size of the matrix

◆ toVector()

template<class T >
void fge::Matrix< T >::toVector ( std::vector< T > & buff) const

Insert all elements of the matrix in a 1D vector.

Parameters
buffThe vector to insert the elements in

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