17#ifndef _FGE_C_MATRIX_HPP_INCLUDED
18#define _FGE_C_MATRIX_HPP_INCLUDED
20#include "FastEngine/C_vector.hpp"
21#include "FastEngine/fge_except.hpp"
23#include <initializer_list>
25#define FGE_MATRIX_GET(dataType_, data_, sizeY_, px_, py_) \
26 (reinterpret_cast<dataType_*>(data_) + (py_) + ((px_) * (sizeY_)))
43 using const_iterator = T
const*;
57 Matrix(std::initializer_list<std::initializer_list<T>> data);
66 explicit Matrix(fge::Vector2<Tvec>
const& msize);
73 Matrix(std::size_t sizex, std::size_t sizey);
83 Matrix(fge::Vector2<Tvec>
const& msize, T
const& defaultValue);
91 Matrix(std::size_t sizex, std::size_t sizey, T
const& defaultValue);
113 inline T
const*
operator[](std::size_t x)
const;
122 inline T
const&
get(std::size_t x, std::size_t y)
const;
131 inline T
const&
get(fge::Vector2<Tvec>
const& coord)
const;
132 inline T&
get(std::size_t x, std::size_t y);
134 inline T&
get(fge::Vector2<Tvec>
const& coord);
144 bool get(std::size_t x, std::size_t y, T& buff)
const;
154 bool get(fge::Vector2<Tvec>
const& coord, T& buff)
const;
163 T*
getPtr(std::size_t x, std::size_t y);
172 T*
getPtr(fge::Vector2<Tvec>
const& coord);
173 T
const*
getPtr(std::size_t x, std::size_t y)
const;
175 T
const*
getPtr(fge::Vector2<Tvec>
const& coord)
const;
184 void set(std::size_t x, std::size_t y, T&& value);
193 void set(fge::Vector2<Tvec>
const& coord, T&& value);
201 void set(std::size_t x, std::size_t y, T
const& value);
210 void set(fge::Vector2<Tvec>
const& coord, T
const& value);
219 void set(std::initializer_list<std::initializer_list<T>> data);
232 [[nodiscard]]
inline fge::Vector2<std::size_t>
const&
getSize()
const;
238 [[nodiscard]]
inline std::size_t
getSizeX()
const;
244 [[nodiscard]]
inline std::size_t
getSizeY()
const;
251 [[nodiscard]]
inline T
const*
get()
const;
252 [[nodiscard]]
inline T*
get();
254 [[nodiscard]] fge::Matrix<T>::iterator begin();
255 [[nodiscard]] fge::Matrix<T>::iterator end();
256 [[nodiscard]] fge::Matrix<T>::const_iterator begin()
const;
257 [[nodiscard]] fge::Matrix<T>::const_iterator end()
const;
266 void setSize(fge::Vector2<Tvec>
const& msize);
273 void setSize(std::size_t sizex, std::size_t sizey);
280 void fill(T
const& value);
316 void toVector(std::vector<T>& buff)
const;
319 std::unique_ptr<T[]> g_mdata;
320 fge::Vector2<std::size_t> g_msize;
344#include <FastEngine/C_matrix.inl>
A container to store a 2D matrix of any type.
Definition C_matrix.hpp:40
void rotateCounterClockwise()
Rotate the matrix by 90 degrees counter-clockwise.
Definition C_matrix.inl:360
void clear()
Clear the matrix and set the size to 0,0.
Definition C_matrix.inl:78
void set(std::size_t x, std::size_t y, T &&value)
Set the specified value by moving it.
Definition C_matrix.inl:195
void fill(T const &value)
Fill the matrix by copying a value.
Definition C_matrix.inl:332
void setSize(fge::Vector2< Tvec > const &msize)
Set the size of the matrix.
Definition C_matrix.inl:309
T * operator[](std::size_t x)
Get the specified row.
Definition C_matrix.inl:106
std::size_t getTotalSize() const
Get the total number of elements in the matrix.
Definition C_matrix.inl:255
Matrix()
Construct a empty matrix.
Definition C_matrix.inl:21
void flipVertically()
Flip the matrix vertically.
Definition C_matrix.inl:415
fge::Vector2< std::size_t > const & getSize() const
Get the size of the matrix as a vector2.
Definition C_matrix.inl:260
std::size_t getSizeY() const
Get the y size of the matrix.
Definition C_matrix.inl:270
void rotateClockwise()
Rotate the matrix by 90 degrees clockwise.
Definition C_matrix.inl:344
T const & get(fge::Vector2< Tvec > const &coord) const
Get the specified value.
void toVector(std::vector< T > &buff) const
Insert all elements of the matrix in a 1D vector.
Definition C_matrix.inl:432
void flipHorizontally()
Flip the matrix horizontally.
Definition C_matrix.inl:398
std::size_t getSizeX() const
Get the x size of the matrix.
Definition C_matrix.inl:265
T const * get() const
Get the 2D array of the matrix.
Definition C_matrix.inl:276
T * getPtr(std::size_t x, std::size_t y)
Get the specified value as a pointer.
Definition C_matrix.inl:162