35 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
36 this->setSize(
static_cast<std::size_t
>(msize.x),
static_cast<std::size_t
>(msize.y));
41 this->setSize(sizex, sizey);
48 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
49 this->setSize(
static_cast<std::size_t
>(msize.x),
static_cast<std::size_t
>(msize.y));
50 this->fill(defaultValue);
55 this->setSize(sizex, sizey);
56 this->fill(defaultValue);
62 this->setSize(m.g_msize);
65 this->g_mdata[i] = m.g_mdata[i];
71 g_mdata(std::move(m.g_mdata))
80 this->g_mdata.reset();
88 this->setSize(m.g_msize);
91 this->g_mdata[i] = m.g_mdata[i];
98 this->g_msize = m.g_msize;
101 this->g_mdata = std::move(m.g_mdata);
108 return FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, 0);
113 return FGE_MATRIX_GET(T
const, this->g_mdata.get(), this->g_msize.y, x, 0);
119 return *FGE_MATRIX_GET(T
const, this->g_mdata.get(), this->g_msize.y, x, y);
125 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
126 return *FGE_MATRIX_GET(T
const, this->g_mdata.get(), this->g_msize.y,
static_cast<std::size_t
>(coord.x),
127 static_cast<std::size_t
>(coord.y));
132 return *FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, y);
138 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
139 return *FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y,
static_cast<std::size_t
>(coord.x),
140 static_cast<std::size_t
>(coord.y));
146 if ((x < this->g_msize.x) && (y < this->g_msize.y))
148 buff = *FGE_MATRIX_GET(T
const, this->g_mdata.get(), this->g_msize.y, x, y);
157 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
158 return this->get(
static_cast<std::size_t
>(coord.x),
static_cast<std::size_t
>(coord.y), buff);
164 if ((x < this->g_msize.x) && (y < this->g_msize.y))
166 return FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, y);
174 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
175 return this->getPtr(
static_cast<std::size_t
>(coord.x),
static_cast<std::size_t
>(coord.y));
180 if ((x < this->g_msize.x) && (y < this->g_msize.y))
182 return FGE_MATRIX_GET(T
const, this->g_mdata.get(), this->g_msize.y, x, y);
190 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
191 return this->getPtr(
static_cast<std::size_t
>(coord.x),
static_cast<std::size_t
>(coord.y));
197 *FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, y) = std::move(value);
203 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
204 *FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y,
static_cast<std::size_t
>(coord.x),
205 static_cast<std::size_t
>(coord.y)) = std::move(value);
210 *FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, y) = value;
216 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
217 *FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y,
static_cast<std::size_t
>(coord.x),
218 static_cast<std::size_t
>(coord.y)) = value;
224 std::size_t
const sizey = data.size();
225 std::size_t sizex = 0;
228 auto it = data.begin();
230 for (++it; it != data.end(); ++it)
232 if (it->size() != sizex)
234 throw fge::Exception(
"Matrix : size must be constant between rows");
239 this->setSize(sizex, sizey);
241 std::size_t ycount = 0;
242 for (
auto datay: data)
244 std::size_t xcount = 0;
245 for (
auto datax: datay)
247 *FGE_MATRIX_GET(T, this->g_mdata.get(), sizey, xcount, ycount) = std::move(datax);
257 return this->g_msize.x * this->g_msize.y;
262 return this->g_msize;
267 return this->g_msize.x;
272 return this->g_msize.y;
278 return this->g_mdata;
283 return this->g_mdata;
289 return this->g_mdata.
get();
294 return this->g_mdata.
get() + this->getTotalSize();
299 return this->g_mdata.
get();
304 return this->g_mdata.
get() + this->getTotalSize();
311 static_assert(std::is_integral<Tvec>::value,
"Tvec must be an integral type");
312 this->setSize(
static_cast<std::size_t
>(msize.x),
static_cast<std::size_t
>(msize.y));
317 if (sizex == this->g_msize.x && sizey == this->g_msize.y)
321 if (sizex == 0 || sizey == 0)
326 this->g_mdata.reset(
new T[sizex * sizey]);
327 this->g_msize.x = sizex;
328 this->g_msize.y = sizey;
334 for (std::size_t x = 0; x < this->g_msize.x; ++x)
336 for (std::size_t y = 0; y < this->g_msize.y; ++y)
338 *FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, y) = value;
346 Matrix<T> newMatrix(this->g_msize.y, this->g_msize.x);
348 for (std::size_t y = 0; y < this->g_msize.y; ++y)
350 for (std::size_t x = 0; x < this->g_msize.x; ++x)
352 newMatrix[newMatrix.g_msize.x - y - 1][x] =
353 std::move(*FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, y));
356 this->g_mdata = std::move(newMatrix.g_mdata);
357 this->g_msize = newMatrix.g_msize;
362 Matrix<T> newMatrix(this->g_msize.y, this->g_msize.x);
364 for (std::size_t y = 0; y < this->g_msize.y; ++y)
366 for (std::size_t x = 0; x < this->g_msize.x; ++x)
368 newMatrix[y][newMatrix.g_msize.y - x - 1] =
369 std::move(*FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, y));
372 this->g_mdata = std::move(newMatrix.g_mdata);
373 this->g_msize = newMatrix.g_msize;
382 this->rotateClockwise();
392 this->rotateCounterClockwise();
400 Matrix<T> newMatrix(this->g_msize.x, this->g_msize.y);
402 for (std::size_t x = 0; x < this->g_msize.x; ++x)
404 for (std::size_t y = 0; y < this->g_msize.y; ++y)
407 std::move(*FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, this->g_msize.x - 1 - x, y));
410 this->g_mdata = std::move(newMatrix.g_mdata);
411 this->g_msize = newMatrix.g_msize;
417 Matrix<T> newMatrix(this->g_msize.x, this->g_msize.y);
419 for (std::size_t x = 0; x < this->g_msize.x; ++x)
421 for (std::size_t y = 0; y < this->g_msize.y; ++y)
424 std::move(*FGE_MATRIX_GET(T, this->g_mdata.get(), this->g_msize.y, x, this->g_msize.y - 1 - y));
427 this->g_mdata = std::move(newMatrix.g_mdata);
428 this->g_msize = newMatrix.g_msize;
434 buff.assign(this->g_mdata.get(), this->g_mdata.get() + this->g_msize.x * this->g_msize.y);
442 nlohmann::json& datay = data[
"data"];
443 datay = nlohmann::json::array();
445 for (std::size_t y = 0; y < r.
getSizeY(); ++y)
447 nlohmann::json datax = nlohmann::json::array();
448 for (std::size_t x = 0; x < r.
getSizeX(); ++x)
462 j.at(
"sizeX").get_to(sizex);
463 j.at(
"sizeY").get_to(sizey);
465 nlohmann::json
const& datay = j.at(
"data");
467 if (!datay.is_array())
471 if (datay.size() != sizey)
479 for (nlohmann::json::const_iterator ity = datay.begin(); ity != datay.end(); ++ity)
481 if (!(*ity).is_array())
485 if ((*ity).size() != sizex)
491 for (nlohmann::json::const_iterator itx = (*ity).begin(); itx != (*ity).end(); ++itx)
493 (*itx).get_to(r[x][y]);
Definition fge_except.hpp:28
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
T const & get(std::size_t x, std::size_t y) const
Get the specified value.
Definition C_matrix.inl:117
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
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