From 7f27d3bf881ca3c257ab346c4ef5b6b0d177cdaa Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 22 Jun 2017 17:47:51 +0100 Subject: Documenting --- include/YAGE/Math/matrix.hpp | 26 +++++++++++++++++++++++++- test/matrix_test.cpp | 37 ++++++++----------------------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 5a753616..d4566c98 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -1,3 +1,11 @@ +/* + * created 22-06-17 by Yann Herklotz + * + * Matrix class that contains definitions for matrices, vectors and operations + * on vectors and matrices. + * + */ + #ifndef YAGE_MATH_MATRIX_HPP #define YAGE_MATH_MATRIX_HPP @@ -12,11 +20,15 @@ namespace yage { template class Matrix; -template class Vector; +// includes implementation details that should not be accessible to the user namespace detail { +// Row class +// +// Used to implement the double square bracket operator and be able +// to return the value by reference of the array. template class Row { private: @@ -30,6 +42,7 @@ public: Type& operator[](int col) { + // the index is the y-position of the element in the matrix return parent_->data_[index_*Cols+col]; } @@ -41,8 +54,13 @@ public: } // detail +// Matrix class +// +// Implements the base Matrix class that is inherited by other classes to make them more +// specific. template class Matrix { + // friended with the row class so that it can access protected member data friend class detail::Row; protected: std::vector data_; @@ -60,6 +78,7 @@ public: return Cols; } + // returns the row in a row matrix Matrix<1, Cols, Type> getRow(int row) const { Matrix<1, Cols, Type> rowMatrix; @@ -70,6 +89,7 @@ public: return rowMatrix; } + // returns the column in a column matrix Matrix getCol(int col) const { Matrix colMatrix; @@ -80,16 +100,20 @@ public: return colMatrix; } + // iterator support for begin typename std::vector::iterator begin() { return data_.begin(); } + // iterator support for end typename std::vector::iterator end() { return data_.end(); } + // prints out the matrix, but can also be implemented by other classes to print data + // differently virtual std::string toString() const { std::stringstream ss; diff --git a/test/matrix_test.cpp b/test/matrix_test.cpp index aa8bb71d..16548164 100644 --- a/test/matrix_test.cpp +++ b/test/matrix_test.cpp @@ -1,35 +1,14 @@ -#include "Math/math.hpp" +/* + * created 22-06-17 by Yann Herklotz + * + * Tests the math class using different tests to see if matrix operations work + * correctly. + * + */ -#include +#include "Math/math.hpp" int main() { - yage::Matrix<4, 4, int> m1, m2; - - yage::Vector<2, int> v1, v2; - - yage::Vector2d v3; - - m1[0][1]=1; - m2[1][1]=2; - - v1[0]=2; - v1[1]=3; - v2[0]=5; - v2[1]=2; - - v2 += v1+v1; - - v3.x() = 2; - v3.y() = 1; - - auto m3=yage::matrix::transpose(v3); - auto vec4=yage::Vector<2, double>(yage::matrix::transpose(m3)); - - std::cout<