16 #ifndef YAGE_MATH_MATRIX_HPP 17 #define YAGE_MATH_MATRIX_HPP 29 template<
int Rows,
int Cols,
class Type>
class Matrix;
39 template<
int Rows,
int Cols,
class Type>
class Row 47 parent_(parent), index_(index)
50 Type& operator[](
int col)
53 return parent_->data_[index_*Cols+col];
56 const Type& operator[](
int col)
const 58 return parent_->data_[index_*Cols+col];
68 template<
int Rows=4,
int Cols=4,
class Type=
double>
class Matrix 73 std::vector<Type> data_;
92 for(
int i=0; i<Cols; ++i)
94 rowMatrix[0][i]=data_[row][i];
103 for(
int i=0; i<Rows; ++i)
105 colMatrix[i][0]=data_[i][col];
111 typename std::vector<Type>::iterator begin()
113 return data_.begin();
117 typename std::vector<Type>::iterator end()
124 virtual std::string toString()
const 126 std::stringstream ss;
128 for(
int i=0; i<Rows-1; ++i)
131 for(
int j=0; j<Cols-1; ++j)
133 ss<<data_[i*Cols+j]<<
' ';
135 ss<<data_[(Rows-1)*Cols+Cols-1]<<
"],";
138 for(
int j=0; j<Cols-1; ++j)
140 ss<<data_[(Rows-1)*Cols+j]<<
' ';
142 ss<<data_[(Rows-1)*Cols+Cols-1]<<
"]]";
168 std::vector<Type> out;
169 out.reserve(data_.size());
170 std::transform(data_.begin(), data_.end(), rhs.data_.begin(), std::back_inserter(out),
171 [] (Type a, Type b) {
174 data_=std::move(out);
180 std::vector<Type> out;
181 out.reserve(data_.size());
182 std::transform(data_.begin(), data_.end(), rhs.begin(), std::back_inserter(out),
183 [] (Type a, Type b) {
186 data_=std::move(out);
191 template<
int M,
int N,
class T>
198 template<
int M,
int N,
class T>
205 template<
int M,
int N,
class T>
208 for(
auto &data : lhs)
215 template<
int M,
int N,
class T>
218 for(
auto &data : rhs)
225 template<
int M,
int N,
class T>
228 for(
auto &data : lhs)
235 template<
int M,
int N,
class T>
238 for(
auto &data : rhs)
245 template<
int M,
int N,
class T>
248 for(
auto &data : lhs)
255 template<
int M,
int N,
class T>
258 for(
auto &data : rhs)
265 template<
int M,
int N,
class T>
268 for(
auto &data : lhs)
275 template<
int M,
int N,
class T>
278 for(
int i=0; i<M; ++i)
279 for(
int j=0; j<N; ++j)
280 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>
class Vector :
public Matrix<Rows, 1, Type>
297 Type& operator[](
int col)
299 return this->data_[col];
302 const Type& operator[](
int col)
const 304 return this->data_[col];
307 virtual std::string toString()
const 309 std::stringstream ss;
311 for(std::size_t i=0; i<this->data_.size()-1; ++i)
313 ss<<this->data_[i]<<
" ";
315 ss<<this->data_[this->data_.size()-1]<<
"]";
335 return this->data_[0];
338 const Type& x()
const 340 return this->data_[0];
345 return this->data_[1];
348 const Type& y()
const 350 return this->data_[1];
362 for(
int i=0; i<M; ++i)
364 for(
int j=0; j<N; ++j)
375 for(
int i=0; i<R; ++i)
377 sum += m1[i][0]*m2[i][0];
382 template<
int M,
int N,
int P,
int Q,
class T>
387 throw std::runtime_error(
"Matrices don't have the right dimensions for multiplication");
392 for(
int i=0; i<M; ++i)
394 for(
int j=0; j<Q; ++j)
396 res[i][j] = dot(transpose(m1.getRow(i)), m2.getCol(j));
Definition: matrix.hpp:320
Definition: matrix.hpp:39
Definition: matrix.hpp:291
Definition: matrix.hpp:29
Definition: camera2d.hpp:17