matrix: add begin/end family of methods

This commit is contained in:
Danny Robson 2016-08-15 17:33:53 +10:00
parent b809925396
commit 43b59c6801
2 changed files with 63 additions and 19 deletions

View File

@ -30,9 +30,19 @@ namespace util {
static const size_t rows = S; static const size_t rows = S;
static const size_t cols = S; static const size_t cols = S;
// 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); T* operator[] (size_t);
const T* operator[] (size_t) const; const T* operator[] (size_t) const;
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;
matrix& transpose (void); matrix& transpose (void);
matrix transposed (void) const; matrix transposed (void) const;

View File

@ -39,25 +39,59 @@ util::matrix<S,T>::operator[] (size_t idx) const
return this->values[idx]; return this->values[idx];
} }
///////////////////////////////////////////////////////////////////////////////
//template <size_t S, typename T> //-----------------------------------------------------------------------------
//vector<3,T> template <size_t S, typename T>
//matrix<S,T>::operator* (vector<3,T> v) const const T*
//{ util::matrix<S,T>::begin (void) const
// return ( {
// *this * v.template homog<S> () return &(*this)[0][0];
// ).template redim<3> (); }
//}
//
// //-----------------------------------------------------------------------------
////----------------------------------------------------------------------------- template <size_t S, typename T>
//template <size_t S, typename T> const T*
//point<3,T> util::matrix<S,T>::end (void) const
//matrix<S,T>::operator* (point<3,T> p) const {
//{ return &(*this)[S][0];
// return (*this * p.template homog<S> ()).template redim<3> (); }
//}
//
//-----------------------------------------------------------------------------
template <size_t S, typename T>
const T*
util::matrix<S,T>::cbegin (void) const
{
return begin ();
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
const T*
util::matrix<S,T>::cend (void) const
{
return end ();
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
T*
util::matrix<S,T>::begin (void)
{
return &(*this)[0][0];
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
T*
util::matrix<S,T>::end (void)
{
return &(*this)[S][0];
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////