@ -82,9 +82,9 @@ class MatrixTest: public Corrade::TestSuite::Tester {
void configuration ( ) ;
} ;
typedef Matrix < 4 , Float > Matrix4 ;
typedef Matrix < 4 , Int > Matrix4i ;
typedef Matrix < 3 , Float > Matrix3 ;
typedef Matrix < 4 , Float > Matrix4x4 ;
typedef Matrix < 4 , Int > Matrix4x4 i ;
typedef Matrix < 3 , Float > Matrix3x3 ;
typedef Vector < 4 , Float > Vector4 ;
typedef Vector < 4 , Int > Vector4i ;
typedef Vector < 3 , Float > Vector3 ;
@ -115,30 +115,30 @@ MatrixTest::MatrixTest() {
}
void MatrixTest : : construct ( ) {
constexpr Matrix4 a = { Vector4 ( 3.0f , 5.0f , 8.0f , - 3.0f ) ,
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) } ;
CORRADE_COMPARE ( a , Matrix4 ( Vector4 ( 3.0f , 5.0f , 8.0f , - 3.0f ) ,
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) ) ) ;
constexpr Matrix4x4 a = { Vector4 ( 3.0f , 5.0f , 8.0f , - 3.0f ) ,
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) } ;
CORRADE_COMPARE ( a , Matrix4x4 ( Vector4 ( 3.0f , 5.0f , 8.0f , - 3.0f ) ,
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) ) ) ;
}
void MatrixTest : : constructIdentity ( ) {
Matrix4 identity ;
Matrix4 identity2 ( Matrix4 : : Identity ) ;
Matrix4 identity3 ( Matrix4 : : Identity , 4.0f ) ;
Matrix4x4 identity ;
Matrix4x4 identity2 ( Matrix4 x4 : : Identity ) ;
Matrix4x4 identity3 ( Matrix4 x4 : : Identity , 4.0f ) ;
Matrix4 identityExpected ( Vector4 ( 1.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 1.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 1.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ;
Matrix4x4 identityExpected ( Vector4 ( 1.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 1.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 1.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ;
Matrix4 identity3Expected ( Vector4 ( 4.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 4.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 4.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 4.0f ) ) ;
Matrix4x4 identity3Expected ( Vector4 ( 4.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 4.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 4.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 4.0f ) ) ;
CORRADE_COMPARE ( identity , identityExpected ) ;
CORRADE_COMPARE ( identity2 , identityExpected ) ;
@ -146,30 +146,30 @@ void MatrixTest::constructIdentity() {
}
void MatrixTest : : constructZero ( ) {
constexpr Matrix4 a ( Matrix4 : : Zero ) ;
CORRADE_COMPARE ( a , Matrix4 ( Vector4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ) ;
constexpr Matrix4x4 a ( Matrix4 x4 : : Zero ) ;
CORRADE_COMPARE ( a , Matrix4x4 ( Vector4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ,
Vector4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ) ;
}
void MatrixTest : : constructConversion ( ) {
constexpr Matrix4 a ( Vector4 ( 3.0f , 5.0f , 8.0f , - 3.0f ) ,
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) ) ;
constexpr Matrix4x4 a ( Vector4 ( 3.0f , 5.0f , 8.0f , - 3.0f ) ,
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) ) ;
# ifndef CORRADE_GCC46_COMPATIBILITY
constexpr Matrix4i b ( a ) ;
constexpr Matrix4x4 i b ( a ) ;
# else
Matrix4i b ( a ) ; /* Not constexpr under GCC < 4.7 */
# endif
CORRADE_COMPARE ( b , Matrix4i ( Vector4i ( 3 , 5 , 8 , - 3 ) ,
Vector4i ( 4 , 4 , 7 , 2 ) ,
Vector4i ( 1 , 2 , 3 , - 1 ) ,
Vector4i ( 7 , - 1 , 8 , - 1 ) ) ) ;
CORRADE_COMPARE ( b , Matrix4x4 i ( Vector4i ( 3 , 5 , 8 , - 3 ) ,
Vector4i ( 4 , 4 , 7 , 2 ) ,
Vector4i ( 1 , 2 , 3 , - 1 ) ,
Vector4i ( 7 , - 1 , 8 , - 1 ) ) ) ;
/* Implicit conversion is not allowed */
CORRADE_VERIFY ( ! ( std : : is_convertible < Matrix4 , Matrix4i > : : value ) ) ;
CORRADE_VERIFY ( ! ( std : : is_convertible < Matrix4x4 , Matrix4 x4i > : : value ) ) ;
}
void MatrixTest : : constructCopy ( ) {
@ -177,22 +177,22 @@ void MatrixTest::constructCopy() {
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) ) ;
constexpr Matrix4 b ( a ) ;
CORRADE_COMPARE ( b , Matrix4 ( Vector4 ( 3.0f , 5.0f , 8.0f , - 3.0f ) ,
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) ) ) ;
constexpr Matrix4x4 b ( a ) ;
CORRADE_COMPARE ( b , Matrix4x4 ( Vector4 ( 3.0f , 5.0f , 8.0f , - 3.0f ) ,
Vector4 ( 4.5f , 4.0f , 7.0f , 2.0f ) ,
Vector4 ( 1.0f , 2.0f , 3.0f , - 1.0f ) ,
Vector4 ( 7.9f , - 1.0f , 8.0f , - 1.5f ) ) ) ;
}
void MatrixTest : : convert ( ) {
constexpr Mat3 a { { 1.5f , 2.0f , - 3.5f ,
2.0f , - 3.1f , 0.4f ,
9.5f , - 1.5f , 0.1f } } ;
constexpr Matrix3 b ( Vector3 ( 1.5f , 2.0f , - 3.5f ) ,
Vector3 ( 2.0f , - 3.1f , 0.4f ) ,
Vector3 ( 9.5f , - 1.5f , 0.1f ) ) ;
constexpr Matrix3x3 b ( Vector3 ( 1.5f , 2.0f , - 3.5f ) ,
Vector3 ( 2.0f , - 3.1f , 0.4f ) ,
Vector3 ( 9.5f , - 1.5f , 0.1f ) ) ;
constexpr Matrix3 c ( b ) ;
constexpr Matrix3x3 c ( b ) ;
CORRADE_COMPARE ( c , b ) ;
# ifndef CORRADE_GCC46_COMPATIBILITY
@ -203,20 +203,20 @@ void MatrixTest::convert() {
CORRADE_COMPARE ( d . a [ i ] , a . a [ i ] ) ;
/* Implicit conversion is not allowed */
CORRADE_VERIFY ( ! ( std : : is_convertible < Mat3 , Matrix3 > : : value ) ) ;
CORRADE_VERIFY ( ! ( std : : is_convertible < Matrix3 , Mat3 > : : value ) ) ;
CORRADE_VERIFY ( ! ( std : : is_convertible < Mat3 , Matrix3x3 > : : value ) ) ;
CORRADE_VERIFY ( ! ( std : : is_convertible < Matrix3x3 , Mat3 > : : value ) ) ;
}
void MatrixTest : : isOrthogonal ( ) {
CORRADE_VERIFY ( ! Matrix3 ( Vector3 ( 1.0f , 0.0f , 0.0f ) ,
Vector3 ( 0.0f , 1.0f , 0.0f ) ,
Vector3 ( 0.0f , 0.1f , 1.0f ) ) . isOrthogonal ( ) ) ;
CORRADE_VERIFY ( ! Matrix3 ( Vector3 ( 1.0f , 0.0f , 0.0f ) ,
Vector3 ( 0.0f , 1.0f , 0.0f ) ,
Vector3 ( 0.0f , 1.0f , 0.0f ) ) . isOrthogonal ( ) ) ;
CORRADE_VERIFY ( Matrix3 ( Vector3 ( 1.0f , 0.0f , 0.0f ) ,
Vector3 ( 0.0f , 1.0f , 0.0f ) ,
Vector3 ( 0.0f , 0.0f , 1.0f ) ) . isOrthogonal ( ) ) ;
CORRADE_VERIFY ( ! Matrix3x3 ( Vector3 ( 1.0f , 0.0f , 0.0f ) ,
Vector3 ( 0.0f , 1.0f , 0.0f ) ,
Vector3 ( 0.0f , 0.1f , 1.0f ) ) . isOrthogonal ( ) ) ;
CORRADE_VERIFY ( ! Matrix3x3 ( Vector3 ( 1.0f , 0.0f , 0.0f ) ,
Vector3 ( 0.0f , 1.0f , 0.0f ) ,
Vector3 ( 0.0f , 1.0f , 0.0f ) ) . isOrthogonal ( ) ) ;
CORRADE_VERIFY ( Matrix3x3 ( Vector3 ( 1.0f , 0.0f , 0.0f ) ,
Vector3 ( 0.0f , 1.0f , 0.0f ) ,
Vector3 ( 0.0f , 0.0f , 1.0f ) ) . isOrthogonal ( ) ) ;
}
void MatrixTest : : trace ( ) {
@ -232,14 +232,14 @@ void MatrixTest::trace() {
}
void MatrixTest : : ij ( ) {
Matrix4 original ( Vector4 ( 0.0f , 1.0f , 2.0f , 3.0f ) ,
Vector4 ( 4.0f , 5.0f , 6.0f , 7.0f ) ,
Vector4 ( 8.0f , 9.0f , 10.0f , 11.0f ) ,
Vector4 ( 12.0f , 13.0f , 14.0f , 15.0f ) ) ;
Matrix4x4 original ( Vector4 ( 0.0f , 1.0f , 2.0f , 3.0f ) ,
Vector4 ( 4.0f , 5.0f , 6.0f , 7.0f ) ,
Vector4 ( 8.0f , 9.0f , 10.0f , 11.0f ) ,
Vector4 ( 12.0f , 13.0f , 14.0f , 15.0f ) ) ;
Matrix3 skipped ( Vector3 ( 0.0f , 1.0f , 3.0f ) ,
Vector3 ( 8.0f , 9.0f , 11.0f ) ,
Vector3 ( 12.0f , 13.0f , 15.0f ) ) ;
Matrix3x3 skipped ( Vector3 ( 0.0f , 1.0f , 3.0f ) ,
Vector3 ( 8.0f , 9.0f , 11.0f ) ,
Vector3 ( 12.0f , 13.0f , 15.0f ) ) ;
CORRADE_COMPARE ( original . ij ( 1 , 2 ) , skipped ) ;
}
@ -257,33 +257,33 @@ void MatrixTest::determinant() {
}
void MatrixTest : : inverted ( ) {
Matrix4 m ( Vector4 ( 3.0f , 5.0f , 8.0f , 4.0f ) ,
Vector4 ( 4.0f , 4.0f , 7.0f , 3.0f ) ,
Vector4 ( 7.0f , - 1.0f , 8.0f , 0.0f ) ,
Vector4 ( 9.0f , 4.0f , 5.0f , 9.0f ) ) ;
Matrix4x4 m ( Vector4 ( 3.0f , 5.0f , 8.0f , 4.0f ) ,
Vector4 ( 4.0f , 4.0f , 7.0f , 3.0f ) ,
Vector4 ( 7.0f , - 1.0f , 8.0f , 0.0f ) ,
Vector4 ( 9.0f , 4.0f , 5.0f , 9.0f ) ) ;
Matrix4 inverse ( Vector4 ( - 60 / 103.0f , 71 / 103.0f , - 4 / 103.0f , 3 / 103.0f ) ,
Vector4 ( - 66 / 103.0f , 109 / 103.0f , - 25 / 103.0f , - 7 / 103.0f ) ,
Vector4 ( 177 / 412.0f , - 97 / 206.0f , 53 / 412.0f , - 7 / 206.0f ) ,
Vector4 ( 259 / 412.0f , - 185 / 206.0f , 31 / 412.0f , 27 / 206.0f ) ) ;
Matrix4x4 inverse ( Vector4 ( - 60 / 103.0f , 71 / 103.0f , - 4 / 103.0f , 3 / 103.0f ) ,
Vector4 ( - 66 / 103.0f , 109 / 103.0f , - 25 / 103.0f , - 7 / 103.0f ) ,
Vector4 ( 177 / 412.0f , - 97 / 206.0f , 53 / 412.0f , - 7 / 206.0f ) ,
Vector4 ( 259 / 412.0f , - 185 / 206.0f , 31 / 412.0f , 27 / 206.0f ) ) ;
Matrix4 _inverse = m . inverted ( ) ;
Matrix4x4 _inverse = m . inverted ( ) ;
CORRADE_COMPARE ( _inverse , inverse ) ;
CORRADE_COMPARE ( _inverse * m , Matrix4 ( ) ) ;
CORRADE_COMPARE ( _inverse * m , Matrix4x4 ( ) ) ;
}
void MatrixTest : : invertedOrthogonal ( ) {
std : : ostringstream o ;
Error : : setOutput ( & o ) ;
Matrix3 a ( Vector3 ( Constants : : sqrt3 ( ) / 2.0f , 0.5f , 0.0f ) ,
Vector3 ( - 0.5f , Constants : : sqrt3 ( ) / 2.0f , 0.0f ) ,
Vector3 ( 0.0f , 0.0f , 1.0f ) ) ;
Matrix3x3 a ( Vector3 ( Constants : : sqrt3 ( ) / 2.0f , 0.5f , 0.0f ) ,
Vector3 ( - 0.5f , Constants : : sqrt3 ( ) / 2.0f , 0.0f ) ,
Vector3 ( 0.0f , 0.0f , 1.0f ) ) ;
( a * 2 ) . invertedOrthogonal ( ) ;
CORRADE_COMPARE ( o . str ( ) , " Math::Matrix::invertedOrthogonal(): the matrix is not orthogonal \n " ) ;
CORRADE_COMPARE ( a . invertedOrthogonal ( ) * a , Matrix3 ( ) ) ;
CORRADE_COMPARE ( a . invertedOrthogonal ( ) * a , Matrix3x3 ( ) ) ;
CORRADE_COMPARE ( a . invertedOrthogonal ( ) , a . inverted ( ) ) ;
}
@ -344,10 +344,10 @@ void MatrixTest::subclass() {
}
void MatrixTest : : debug ( ) {
Matrix4 m ( Vector4 ( 3.0f , 5.0f , 8.0f , 4.0f ) ,
Vector4 ( 4.0f , 4.0f , 7.0f , 3.0f ) ,
Vector4 ( 7.0f , - 1.0f , 8.0f , 0.0f ) ,
Vector4 ( 9.0f , 4.0f , 5.0f , 9.0f ) ) ;
Matrix4x4 m ( Vector4 ( 3.0f , 5.0f , 8.0f , 4.0f ) ,
Vector4 ( 4.0f , 4.0f , 7.0f , 3.0f ) ,
Vector4 ( 7.0f , - 1.0f , 8.0f , 0.0f ) ,
Vector4 ( 9.0f , 4.0f , 5.0f , 9.0f ) ) ;
std : : ostringstream o ;
Debug ( & o ) < < m ;
@ -357,7 +357,7 @@ void MatrixTest::debug() {
" 4, 3, 0, 9) \n " ) ;
o . str ( { } ) ;
Debug ( & o ) < < " a " < < Matrix4 ( ) < < " b " < < Matrix4 ( ) ;
Debug ( & o ) < < " a " < < Matrix4x4 ( ) < < " b " < < Matrix4 x4 ( ) ;
CORRADE_COMPARE ( o . str ( ) , " a Matrix(1, 0, 0, 0, \n "
" 0, 1, 0, 0, \n "
" 0, 0, 1, 0, \n "
@ -370,15 +370,15 @@ void MatrixTest::debug() {
void MatrixTest : : configuration ( ) {
Corrade : : Utility : : Configuration c ;
Matrix4 m ( Vector4 ( 3.0f , 5.0f , 8.0f , 4.0f ) ,
Vector4 ( 4.0f , 4.0f , 7.0f , 3.125f ) ,
Vector4 ( 7.0f , - 1.0f , 8.0f , 0.0f ) ,
Vector4 ( 9.0f , 4.0f , 5.0f , 9.55f ) ) ;
Matrix4x4 m ( Vector4 ( 3.0f , 5.0f , 8.0f , 4.0f ) ,
Vector4 ( 4.0f , 4.0f , 7.0f , 3.125f ) ,
Vector4 ( 7.0f , - 1.0f , 8.0f , 0.0f ) ,
Vector4 ( 9.0f , 4.0f , 5.0f , 9.55f ) ) ;
std : : string value ( " 3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55 " ) ;
c . setValue ( " matrix " , m ) ;
CORRADE_COMPARE ( c . value ( " matrix " ) , value ) ;
CORRADE_COMPARE ( c . value < Matrix4 > ( " matrix " ) , m ) ;
CORRADE_COMPARE ( c . value < Matrix4x4 > ( " matrix " ) , m ) ;
}
} } }