-
12 #ifndef YAGE_MATH_MATRIX_H
-
13 #define YAGE_MATH_MATRIX_H
-
-
-
-
-
-
-
-
-
-
-
-
25 template <
int Rows,
int Cols,
class Type>
-
-
-
-
-
-
46 template <
int Rows,
int Cols,
class Type>
-
-
-
-
-
-
-
-
-
55 : parent_(parent), index_(index)
-
-
-
-
-
-
-
62 return parent_->data_[index_ * Cols + col];
-
-
-
-
-
67 return parent_->data_[index_ * Cols + col];
-
-
-
-
-
-
75 template <
int Rows = 4,
int Cols = 4,
class Type =
double>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
104 for (
int i = 0; i < Cols; ++i) {
-
105 rowMatrix[0][i] =
data_[row][i];
-
-
-
-
-
-
-
-
118 for (
int i = 0; i < Rows; ++i) {
-
119 colMatrix[i][0] =
data_[i][col];
-
-
-
-
-
128 typename std::vector<Type>::iterator
begin() {
return data_.begin(); }
-
-
134 typename std::vector<Type>::iterator
end() {
return data_.end(); }
-
-
-
-
144 std::stringstream ss;
-
-
146 for (
int i = 0; i < Rows - 1; ++i) {
-
-
148 for (
int j = 0; j < Cols - 1; ++j) {
-
149 ss <<
data_[i * Cols + j] <<
' ';
-
-
151 ss <<
data_[(Rows - 1) * Cols + Cols - 1] <<
"],";
-
-
-
154 for (
int j = 0; j < Cols - 1; ++j) {
-
155 ss <<
data_[(Rows - 1) * Cols + j] <<
' ';
-
-
157 ss <<
data_[(Rows - 1) * Cols + Cols - 1] <<
"]]";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
174 std::vector<Type> out;
-
175 out.reserve(
data_.size());
-
176 std::transform(
data_.begin(),
data_.end(), rhs.data_.begin(),
-
177 std::back_inserter(out),
-
178 [](Type a, Type b) {
return a + b; });
-
179 data_ = std::move(out);
-
-
-
-
-
-
185 std::vector<Type> out;
-
186 out.reserve(
data_.size());
-
187 std::transform(
data_.begin(),
data_.end(), rhs.begin(),
-
188 std::back_inserter(out),
-
189 [](Type a, Type b) {
return a - b; });
-
190 data_ = std::move(out);
-
-
-
-
-
195 template <
int M,
int N,
class T>
-
-
-
-
-
-
-
202 template <
int M,
int N,
class T>
-
-
-
-
-
-
-
209 template <
int M,
int N,
class T>
-
-
-
212 for (
auto &data : lhs) {
-
-
-
-
-
-
218 template <
int M,
int N,
class T>
-
-
-
221 for (
auto &data : rhs) {
-
-
-
-
-
-
227 template <
int M,
int N,
class T>
-
-
-
230 for (
auto &data : lhs) {
-
-
-
-
-
-
236 template <
int M,
int N,
class T>
-
-
-
239 for (
auto &data : rhs) {
-
-
-
-
-
-
245 template <
int M,
int N,
class T>
-
-
-
248 for (
auto &data : lhs) {
-
-
-
-
-
-
254 template <
int M,
int N,
class T>
-
-
-
257 for (
auto &data : rhs) {
-
-
-
-
-
-
263 template <
int M,
int N,
class T>
-
-
-
266 for (
auto &data : lhs) {
-
-
-
-
-
-
272 template <
int M,
int N,
class T>
-
-
-
275 for (
int i = 0; i <
M; ++i) {
-
276 for (
int j = 0; j <
N; ++j) {
-
277 if (lhs[i][j] != rhs[i][j]) {
-
-
-
-
-
-
-
-
285 template <
int M,
int N,
class T>
-
286 std::ostream &operator<<(std::ostream &os, const Matrix<M, N, T> &mat)
-
-
288 return os << mat.toString();
-
-
-
291 template <
int Rows = 2,
class Type =
double>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
312 std::stringstream ss;
-
-
314 for (std::size_t i = 0; i < this->
data_.size() - 1; ++i) {
-
315 ss << this->
data_[i] <<
" ";
-
-
317 ss << this->
data_[this->
data_.size() - 1] <<
"]";
-
-
-
-
-
326 template <
typename Type =
double>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
342 const Type &
x()
const {
return this->
data_[0]; }
-
-
-
345 const Type &
y()
const {
return this->
data_[1]; }
-
-
-
352 template <
typename Type =
double>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
375 template <
typename Type =
double>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
426 template <
int M,
int N,
class T>
-
-
-
-
430 for (
int i = 0; i <
M; ++i) {
-
431 for (
int j = 0; j <
N; ++j) {
-
432 trans[j][i] = m[i][j];
-
-
-
-
-
-
442 template <
int R,
class T>
-
-
-
-
446 for (
int i = 0; i <
R; ++i) {
-
447 sum += m1[i][0] * m2[i][0];
-
-
-
-
-
458 template <
int M,
int N,
int P,
int Q,
class T>
-
-
-
-
463 throw std::runtime_error(
-
464 "Matrices don't have the right dimensions for multiplication");
-
-
-
-
-
471 for (
int i = 0; i <
M; ++i) {
-
472 for (
int j = 0; j <
Q; ++j) {
-
-
-
-
-
-
-
-
-
-
-
-
-
Matrix< M, N, T > operator/(Matrix< M, N, T > lhs, const T &rhs)
Definition: matrix.h:264
-
Matrix< 1, Cols, Type > getRow(int row) const
Return the row specified row as a Matrix with only one row.
Definition: matrix.h:101
-
Type & z
Definition: matrix.h:379
-
-
Matrix< M, N, T > operator*(Matrix< M, N, T > lhs, const T &rhs)
Definition: matrix.h:246
+
+
+
+
+
+
+
+
+
+
+
+
+
24 template <
int Rows,
int Cols,
class Type>
+
+
+
+
+
+
45 template <
int Rows,
int Cols,
class Type>
+
+
+
+
+
+
+
+
+
54 : parent_(parent), index_(index)
+
+
+
+
+
+
+
61 return parent_->data_[index_ * Cols + col];
+
+
+
+
+
66 return parent_->data_[index_ * Cols + col];
+
+
+
+
+
+
74 template <
int Rows = 4,
int Cols = 4,
class Type =
double>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
103 for (
int i = 0; i < Cols; ++i) {
+
104 rowMatrix[0][i] =
data_[row][i];
+
+
+
+
+
+
+
+
117 for (
int i = 0; i < Rows; ++i) {
+
118 colMatrix[i][0] =
data_[i][col];
+
+
+
+
+
127 typename std::vector<Type>::iterator
begin() {
return data_.begin(); }
+
+
133 typename std::vector<Type>::iterator
end() {
return data_.end(); }
+
+
+
+
143 std::stringstream ss;
+
+
145 for (
int i = 0; i < Rows - 1; ++i) {
+
+
147 for (
int j = 0; j < Cols - 1; ++j) {
+
148 ss <<
data_[i * Cols + j] <<
' ';
+
+
150 ss <<
data_[(Rows - 1) * Cols + Cols - 1] <<
"],";
+
+
+
153 for (
int j = 0; j < Cols - 1; ++j) {
+
154 ss <<
data_[(Rows - 1) * Cols + j] <<
' ';
+
+
156 ss <<
data_[(Rows - 1) * Cols + Cols - 1] <<
"]]";
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
173 std::vector<Type> out;
+
174 out.reserve(
data_.size());
+
175 std::transform(
data_.begin(),
data_.end(), rhs.data_.begin(),
+
176 std::back_inserter(out),
+
177 [](Type a, Type b) {
return a + b; });
+
178 data_ = std::move(out);
+
+
+
+
+
+
184 std::vector<Type> out;
+
185 out.reserve(
data_.size());
+
186 std::transform(
data_.begin(),
data_.end(), rhs.begin(),
+
187 std::back_inserter(out),
+
188 [](Type a, Type b) {
return a - b; });
+
189 data_ = std::move(out);
+
+
+
+
+
194 template <
int M,
int N,
class T>
+
+
+
+
+
+
+
201 template <
int M,
int N,
class T>
+
+
+
+
+
+
+
208 template <
int M,
int N,
class T>
+
+
+
211 for (
auto &data : lhs) {
+
+
+
+
+
+
217 template <
int M,
int N,
class T>
+
+
+
220 for (
auto &data : rhs) {
+
+
+
+
+
+
226 template <
int M,
int N,
class T>
+
+
+
229 for (
auto &data : lhs) {
+
+
+
+
+
+
235 template <
int M,
int N,
class T>
+
+
+
238 for (
auto &data : rhs) {
+
+
+
+
+
+
244 template <
int M,
int N,
class T>
+
+
+
247 for (
auto &data : lhs) {
+
+
+
+
+
+
253 template <
int M,
int N,
class T>
+
+
+
256 for (
auto &data : rhs) {
+
+
+
+
+
+
262 template <
int M,
int N,
class T>
+
+
+
265 for (
auto &data : lhs) {
+
+
+
+
+
+
271 template <
int M,
int N,
class T>
+
+
+
274 for (
int i = 0; i <
M; ++i) {
+
275 for (
int j = 0; j <
N; ++j) {
+
276 if (lhs[i][j] != rhs[i][j]) {
+
+
+
+
+
+
+
+
284 template <
int M,
int N,
class T>
+
285 std::ostream &operator<<(std::ostream &os, const Matrix<M, N, T> &mat)
+
+
287 return os << mat.toString();
+
+
+
290 template <
int Rows = 2,
class Type =
double>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
311 std::stringstream ss;
+
+
313 for (std::size_t i = 0; i < this->
data_.size() - 1; ++i) {
+
314 ss << this->
data_[i] <<
" ";
+
+
316 ss << this->
data_[this->
data_.size() - 1] <<
"]";
+
+
+
+
+
325 template <
typename Type =
double>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
341 const Type &
x()
const {
return this->
data_[0]; }
+
+
+
344 const Type &
y()
const {
return this->
data_[1]; }
+
+
+
351 template <
typename Type =
double>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
374 template <
typename Type =
double>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
425 template <
int M,
int N,
class T>
+
+
+
+
429 for (
int i = 0; i <
M; ++i) {
+
430 for (
int j = 0; j <
N; ++j) {
+
431 trans[j][i] = m[i][j];
+
+
+
+
+
+
441 template <
int R,
class T>
+
+
+
+
445 for (
int i = 0; i <
R; ++i) {
+
446 sum += m1[i][0] * m2[i][0];
+
+
+
+
+
457 template <
int M,
int N,
int P,
int Q,
class T>
+
+
+
+
462 throw std::runtime_error(
+
463 "Matrices don't have the right dimensions for multiplication");
+
+
+
+
+
470 for (
int i = 0; i <
M; ++i) {
+
471 for (
int j = 0; j <
Q; ++j) {
+
+
+
+
+
+
+
+
+
+
+
Matrix< M, N, T > operator/(Matrix< M, N, T > lhs, const T &rhs)
Definition: matrix.h:263
+
Matrix< 1, Cols, Type > getRow(int row) const
Return the row specified row as a Matrix with only one row.
Definition: matrix.h:100
+
Type & z
Definition: matrix.h:378
+
+
Matrix< M, N, T > operator*(Matrix< M, N, T > lhs, const T &rhs)
Definition: matrix.h:245
-
int rowSize() const
Returns the row size of the Matrix.
Definition: matrix.h:91
-
z(this->data_[2])
Definition: matrix.h:368
-
2D Vector class.
Definition: matrix.h:327
-
bool operator==(const Matrix< M, N, T > &lhs, const Matrix< M, N, T > &rhs)
Definition: matrix.h:273
-
Type & y
Definition: matrix.h:356
-
std::vector< Type >::iterator end()
Iterator support for the end.
Definition: matrix.h:134
-
Type & x
Definition: matrix.h:356
-
Type & operator[](int col)
Definition: matrix.h:306
+
int rowSize() const
Returns the row size of the Matrix.
Definition: matrix.h:90
+
z(this->data_[2])
Definition: matrix.h:367
+
2D Vector class.
Definition: matrix.h:326
+
bool operator==(const Matrix< M, N, T > &lhs, const Matrix< M, N, T > &rhs)
Definition: matrix.h:272
+
Type & y
Definition: matrix.h:355
+
std::vector< Type >::iterator end()
Iterator support for the end.
Definition: matrix.h:133
+
Type & x
Definition: matrix.h:355
+
Type & operator[](int col)
Definition: matrix.h:305
-
Type & y
Definition: matrix.h:379
-
std::vector< Type > data_
Vector containing the data of the matrix.
Definition: matrix.h:83
-
Matrix< M, Q, T > multiply(const Matrix< M, N, T > &m1, const Matrix< P, Q, T > &m2)
Multiplies two matrices together.
Definition: matrix.h:459
-
Type & y()
Definition: matrix.h:344
+
Type & y
Definition: matrix.h:378
+
std::vector< Type > data_
Vector containing the data of the matrix.
Definition: matrix.h:82
+
Matrix< M, Q, T > multiply(const Matrix< M, N, T > &m1, const Matrix< P, Q, T > &m2)
Multiplies two matrices together.
Definition: matrix.h:458
+
Type & y()
Definition: matrix.h:343
-
Type & operator[](int col)
Definition: matrix.h:59
-
Matrix< Rows, 1, Type > getCol(int col) const
Get a specific column in a column vector.
Definition: matrix.h:115
-
const Type & operator[](int col) const
Definition: matrix.h:65
-
w(this->data_[3])
Definition: matrix.h:391
-
const Type & x() const
Definition: matrix.h:342
-
Type & x
Definition: matrix.h:379
-
Matrix< N, M, T > transpose(const Matrix< M, N, T > &m)
Transposes a matrix and returns the result.
Definition: matrix.h:427
+
Type & operator[](int col)
Definition: matrix.h:58
+
Matrix< Rows, 1, Type > getCol(int col) const
Get a specific column in a column vector.
Definition: matrix.h:114
+
const Type & operator[](int col) const
Definition: matrix.h:64
+
w(this->data_[3])
Definition: matrix.h:390
+
const Type & x() const
Definition: matrix.h:341
+
Type & x
Definition: matrix.h:378
+
Matrix< N, M, T > transpose(const Matrix< M, N, T > &m)
Transposes a matrix and returns the result.
Definition: matrix.h:426
-
int colSize() const
Returns the column size of the Matrix.
Definition: matrix.h:94
-
const Type & operator[](int col) const
Definition: matrix.h:308
-
Matrix< Rows, Cols, Type > & operator-=(const Matrix< Rows, Cols, Type > &rhs)
Definition: matrix.h:183
-
3D Vector class.
Definition: matrix.h:353
-
Type & x()
Definition: matrix.h:341
-
details::Row< Rows, Cols, Type > operator[](int row) const
Definition: matrix.h:166
-
details::Row< Rows, Cols, Type > operator[](int row)
Definition: matrix.h:161
+
int colSize() const
Returns the column size of the Matrix.
Definition: matrix.h:93
+
const Type & operator[](int col) const
Definition: matrix.h:307
+
Matrix< Rows, Cols, Type > & operator-=(const Matrix< Rows, Cols, Type > &rhs)
Definition: matrix.h:182
+
3D Vector class.
Definition: matrix.h:352
+
Type & x()
Definition: matrix.h:340
+
details::Row< Rows, Cols, Type > operator[](int row) const
Definition: matrix.h:165
+
details::Row< Rows, Cols, Type > operator[](int row)
Definition: matrix.h:160
-
Matrix< M, N, T > operator+(Matrix< M, N, T > lhs, const Matrix< M, N, T > &rhs)
Definition: matrix.h:196
-
-
Matrix< M, N, T > operator-(Matrix< M, N, T > lhs, const Matrix< M, N, T > &rhs)
Definition: matrix.h:203
-
virtual std::string toString() const
Prints out the matrix, but can also be implemented by other classes to print data differently...
Definition: matrix.h:142
-
Matrix< Rows, Cols, Type > & operator+=(const Matrix< Rows, Cols, Type > &rhs)
Definition: matrix.h:172
-
Base Matrix class used by other similar classes.
Definition: matrix.h:26
-
T dot(const Matrix< R, 1, T > &m1, const Matrix< R, 1, T > &m2)
Returns the dot product between two vectors.
Definition: matrix.h:443
-
Type & w
Definition: matrix.h:379
-
const Type & y() const
Definition: matrix.h:345
-
std::string toString() const override
Prints out the matrix, but can also be implemented by other classes to print data differently...
Definition: matrix.h:310
-
4D Vector class
Definition: matrix.h:376
-
std::vector< Type >::iterator begin()
Iterator support for the start.
Definition: matrix.h:128
-
Type & z
Definition: matrix.h:356
+
Matrix< M, N, T > operator+(Matrix< M, N, T > lhs, const Matrix< M, N, T > &rhs)
Definition: matrix.h:195
+
+
Matrix< M, N, T > operator-(Matrix< M, N, T > lhs, const Matrix< M, N, T > &rhs)
Definition: matrix.h:202
+
virtual std::string toString() const
Prints out the matrix, but can also be implemented by other classes to print data differently...
Definition: matrix.h:141
+
Matrix< Rows, Cols, Type > & operator+=(const Matrix< Rows, Cols, Type > &rhs)
Definition: matrix.h:171
+
Base Matrix class used by other similar classes.
Definition: matrix.h:25
+
T dot(const Matrix< R, 1, T > &m1, const Matrix< R, 1, T > &m2)
Returns the dot product between two vectors.
Definition: matrix.h:442
+
Type & w
Definition: matrix.h:378
+
const Type & y() const
Definition: matrix.h:344
+
std::string toString() const override
Prints out the matrix, but can also be implemented by other classes to print data differently...
Definition: matrix.h:309
+
4D Vector class
Definition: matrix.h:375
+
std::vector< Type >::iterator begin()
Iterator support for the start.
Definition: matrix.h:127
+
Type & z
Definition: matrix.h:355