diff --git a/matrix.hpp b/matrix.hpp index 417ecb59..270f6742 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -31,22 +31,81 @@ namespace util { T values[Rows][Cols]; + /////////////////////////////////////////////////////////////////////// // index operators return a pointer into the data array so that // multidimensional array syntax can be used transparently on this // type. - T* operator[] (size_t); - const T* operator[] (size_t) const; + constexpr T* + operator[] (size_t idx) noexcept + { + return this->values[idx]; + } - T* data (void); - const T* data (void) const; + //--------------------------------------------------------------------- + constexpr const T* + operator[] (size_t idx) const noexcept + { + return this->values[idx]; + } - const T* begin (void) const; - const T* end (void) const; - T* begin (void); - T* end (void); - const T* cbegin (void) const; - const T* cend (void) const; + //--------------------------------------------------------------------- + constexpr T* + data (void) noexcept + { + return begin (); + } + //--------------------------------------------------------------------- + constexpr const T* + data (void) const noexcept + { + return begin (); + } + + //--------------------------------------------------------------------- + constexpr const T* + begin (void) const noexcept + { + return &(*this)[0][0]; + } + + //--------------------------------------------------------------------- + constexpr const T* + end (void) const noexcept + { + return &(*this)[Rows][0]; + } + + //--------------------------------------------------------------------- + constexpr T* + begin (void) noexcept + { + return &(*this)[0][0]; + } + + //--------------------------------------------------------------------- + constexpr T* + end (void) noexcept + { + return &(*this)[Rows][0]; + } + + //--------------------------------------------------------------------- + constexpr auto + cbegin (void) const noexcept + { + return begin (); + } + + //--------------------------------------------------------------------- + constexpr auto + cend (void) const noexcept + { + return end (); + } + + + /////////////////////////////////////////////////////////////////////// T determinant (void) const; matrix inverse (void) const; @@ -58,6 +117,8 @@ namespace util { return inverse (); } + + /////////////////////////////////////////////////////////////////////// vector operator* (const vector&) const; point operator* (const point &) const; @@ -65,7 +126,12 @@ namespace util { template matrix - cast (void) const; + cast (void) const + { + util::matrix out; + std::copy (cbegin (), cend (), std::begin (out)); + return out; + } // Perspective matrices static matrix<4,4,T> ortho (T left, T right, T bottom, T top, T near, T far); diff --git a/matrix.ipp b/matrix.ipp index 1f3f53f8..7a2e0b69 100644 --- a/matrix.ipp +++ b/matrix.ipp @@ -22,108 +22,6 @@ #define __UTIL_MATRIX_IPP -/////////////////////////////////////////////////////////////////////////////// -template -T* -util::matrix::operator[] (size_t idx) -{ - return this->values[idx]; -} - - -//----------------------------------------------------------------------------- -template -const T* -util::matrix::operator[] (size_t idx) const -{ - return this->values[idx]; -} - - -//----------------------------------------------------------------------------- -template -T* -util::matrix::data (void) -{ - return begin (); -} - - -//----------------------------------------------------------------------------- -template -const T* -util::matrix::data (void) const -{ - return begin (); -} - - -//----------------------------------------------------------------------------- -template -const T* -util::matrix::begin (void) const -{ - return &(*this)[0][0]; -} - - -//----------------------------------------------------------------------------- -template -const T* -util::matrix::end (void) const -{ - return &(*this)[Rows][0]; -} - - -//----------------------------------------------------------------------------- -template -const T* -util::matrix::cbegin (void) const -{ - return begin (); -} - - -//----------------------------------------------------------------------------- -template -const T* -util::matrix::cend (void) const -{ - return end (); -} - - -//----------------------------------------------------------------------------- -template -T* -util::matrix::begin (void) -{ - return &(*this)[0][0]; -} - - -//----------------------------------------------------------------------------- -template -T* -util::matrix::end (void) -{ - return &(*this)[Rows][0]; -} - - -/////////////////////////////////////////////////////////////////////////////// -template -template -util::matrix -util::matrix::cast (void) const -{ - util::matrix out; - std::copy (cbegin (), cend (), std::begin (out)); - return out; -} - - /////////////////////////////////////////////////////////////////////////////// #define MATRIX_ELEMENT_OP(OP) \ template \