@ -86,39 +86,24 @@ template<class T, size_t size> class Matrix {
* @ return One - dimensional array of ` size * size ` length in column - major
* order .
*/
inline constexpr const T * data ( ) const { return _data ; }
/** @brief Value at given position */
inline constexpr T at ( size_t row , size_t col ) const {
return _data [ col * size + row ] ;
}
inline T * data ( ) { return _data ; }
inline constexpr const T * data ( ) const { return _data ; } /**< @copydoc data() */
/** @brief %Matrix column */
inline constexpr Vector < T , size > at ( size_t col ) const {
inline Vector < T , size > & operator [ ] ( size_t col ) {
return Vector < T , size > : : from ( _data + col * size ) ;
}
/** @brief Set value at given position */
inline void set ( size_t row , size_t col , T value ) {
_data [ col * size + row ] = value ;
}
/** @brief Set matrix column */
inline void set ( size_t col , const Vector < T , size > & value ) {
Vector < T , size > : : from ( _data + col * size ) = value ;
}
/** @brief Add value to given position */
inline void add ( size_t row , size_t col , T value ) {
_data [ col * size + row ] + = value ;
/** @copydoc operator[]() */
inline constexpr const Vector < T , size > & operator [ ] ( size_t col ) const {
return Vector < T , size > : : from ( _data + col * size ) ;
}
/** @brief Equality operator */
inline bool operator = = ( const Matrix < T , size > & other ) const {
for ( size_t row = 0 ; row ! = size ; + + row ) {
for ( size_t row = 0 ; row ! = size ; + + row )
for ( size_t col = 0 ; col ! = size ; + + col )
if ( ! TypeTraits < T > : : equals ( at ( row , col ) , other . at ( row , col ) ) ) return false ;
}
if ( ! TypeTraits < T > : : equals ( ( * this ) [ col ] [ row ] , other [ col ] [ row ] ) ) return false ;
return true ;
}
@ -132,12 +117,10 @@ template<class T, size_t size> class Matrix {
Matrix < T , size > operator * ( const Matrix < T , size > & other ) const {
Matrix < T , size > out ( false ) ;
for ( size_t row = 0 ; row ! = size ; + + row ) {
for ( size_t col = 0 ; col ! = size ; + + col ) {
for ( size_t row = 0 ; row ! = size ; + + row )
for ( size_t col = 0 ; col ! = size ; + + col )
for ( size_t pos = 0 ; pos ! = size ; + + pos )
out . add ( row , col , at ( row , pos ) * other . at ( pos , col ) ) ;
}
}
out [ col ] [ row ] + = ( * this ) [ pos ] [ row ] * other [ col ] [ pos ] ;
return out ;
}
@ -151,10 +134,9 @@ template<class T, size_t size> class Matrix {
Vector < T , size > operator * ( const Vector < T , size > & other ) const {
Vector < T , size > out ;
for ( size_t row = 0 ; row ! = size ; + + row ) {
for ( size_t row = 0 ; row ! = size ; + + row )
for ( size_t pos = 0 ; pos ! = size ; + + pos )
out . add ( row , at ( row , pos ) * other . at ( pos ) ) ;
}
out [ row ] + = ( * this ) [ pos ] [ row ] * other [ pos ] ;
return out ;
}
@ -163,23 +145,21 @@ template<class T, size_t size> class Matrix {
Matrix < T , size > transposed ( ) const {
Matrix < T , size > out ( false ) ;
for ( size_t row = 0 ; row ! = size ; + + row ) {
for ( size_t row = 0 ; row ! = size ; + + row )
for ( size_t col = 0 ; col ! = size ; + + col )
out . set ( col , row , at ( row , col ) ) ;
}
out [ row ] [ col ] = ( * this ) [ col ] [ row ] ;
return out ;
}
/** @brief %Matrix without given row and column */
Matrix < T , size - 1 > ij ( size_t skipRow , size_t skipCol ) const {
/** @brief %Matrix without given column and row */
Matrix < T , size - 1 > ij ( size_t skipCol , size_t skipRow ) const {
Matrix < T , size - 1 > out ( false ) ;
for ( size_t row = 0 ; row ! = size - 1 ; + + row ) {
for ( size_t row = 0 ; row ! = size - 1 ; + + row )
for ( size_t col = 0 ; col ! = size - 1 ; + + col )
out . set ( row , col , at ( row + ( row > = skipRow ) ,
col + ( col > = skipCol ) ) ) ;
}
out [ col ] [ row ] = ( * this ) [ col + ( col > = skipCol ) ]
[ row + ( row > = skipRow ) ] ;
return out ;
}
@ -201,10 +181,9 @@ template<class T, size_t size> class Matrix {
T _determinant = determinant ( ) ;
for ( size_t row = 0 ; row ! = size ; + + row ) {
for ( size_t row = 0 ; row ! = size ; + + row )
for ( size_t col = 0 ; col ! = size ; + + col )
out . set ( row , col , ( ( ( row + col ) & 1 ) ? - 1 : 1 ) * ij ( col , row ) . determinant ( ) / _determinant ) ;
}
out [ col ] [ row ] = ( ( ( row + col ) & 1 ) ? - 1 : 1 ) * ij ( row , col ) . determinant ( ) / _determinant ;
return out ;
}
@ -223,7 +202,7 @@ template<class T, size_t size> class MatrixDeterminant {
T out ( 0 ) ;
for ( size_t col = 0 ; col ! = size ; + + col )
out + = ( ( col & 1 ) ? - 1 : 1 ) * m . at ( 0 , col ) * m . ij ( 0 , col ) . determinant ( ) ;
out + = ( ( col & 1 ) ? - 1 : 1 ) * m [ col ] [ 0 ] * m . ij ( col , 0 ) . determinant ( ) ;
return out ;
}
@ -234,7 +213,7 @@ template<class T> class MatrixDeterminant<T, 2> {
public :
/** @brief Functor */
inline constexpr T operator ( ) ( const Matrix < T , 2 > & m ) {
return m . at ( 0 , 0 ) * m . at ( 1 , 1 ) - m . at ( 0 , 1 ) * m . at ( 1 , 0 ) ;
return m [ 0 ] [ 0 ] * m [ 1 ] [ 1 ] - m [ 1 ] [ 0 ] * m [ 0 ] [ 1 ] ;
}
} ;
@ -243,7 +222,7 @@ template<class T> class MatrixDeterminant<T, 1> {
public :
/** @brief Functor */
inline constexpr T operator ( ) ( const Matrix < T , 1 > & m ) {
return m . at ( 0 , 0 ) ;
return m [ 0 ] [ 0 ] ;
}
} ;
@ -257,7 +236,7 @@ template<class T, size_t size> Corrade::Utility::Debug operator<<(Corrade::Utili
if ( row ! = 0 ) debug < < " , \n " ;
for ( size_t col = 0 ; col ! = size ; + + col ) {
if ( col ! = 0 ) debug < < " , " ;
debug < < value . at ( row , col ) ;
debug < < value [ col ] [ row ] ;
}
}
debug < < ' ) ' ;