@ -86,6 +86,10 @@ struct ComplexTest: Corrade::TestSuite::Tester {
void angle ( ) ;
void rotation ( ) ;
void matrix ( ) ;
void lerp ( ) ;
void lerpNotNormalized ( ) ;
void slerp ( ) ;
void slerpNotNormalized ( ) ;
void transformVector ( ) ;
void debug ( ) ;
@ -128,6 +132,10 @@ ComplexTest::ComplexTest() {
& ComplexTest : : angle ,
& ComplexTest : : rotation ,
& ComplexTest : : matrix ,
& ComplexTest : : lerp ,
& ComplexTest : : lerpNotNormalized ,
& ComplexTest : : slerp ,
& ComplexTest : : slerpNotNormalized ,
& ComplexTest : : transformVector ,
& ComplexTest : : debug ,
@ -141,6 +149,8 @@ typedef Math::Vector2<Float> Vector2;
typedef Math : : Matrix3 < Float > Matrix3 ;
typedef Math : : Matrix2x2 < Float > Matrix2x2 ;
using namespace Math : : Literals ;
void ComplexTest : : construct ( ) {
constexpr Complex a = { 0.5f , - 3.7f } ;
CORRADE_COMPARE ( a , Complex ( 0.5f , - 3.7f ) ) ;
@ -411,6 +421,57 @@ void ComplexTest::matrix() {
CORRADE_COMPARE ( b , a ) ;
}
void ComplexTest : : lerp ( ) {
/* Results should be consistent with QuaternionTest::lerp2D() (but not
equivalent , probably because quaternions double cover and complex
numbers not ) */
Complex a = Complex : : rotation ( 15.0 _degf ) ;
Complex b = Complex : : rotation ( 57.0 _degf ) ;
Complex lerp = Math : : lerp ( a , b , 0.35f ) ;
CORRADE_VERIFY ( lerp . isNormalized ( ) ) ;
CORRADE_COMPARE ( lerp . angle ( ) , 29.4308 _degf ) ; /* almost but not quite 29.7 */
CORRADE_COMPARE ( lerp , ( Complex { 0.87095f , 0.491372f } ) ) ;
}
void ComplexTest : : lerpNotNormalized ( ) {
std : : ostringstream out ;
Error redirectError { & out } ;
Complex a ;
Math : : lerp ( a * 3.0f , a , 0.35f ) ;
Math : : lerp ( a , a * - 3.0f , 0.35f ) ;
CORRADE_COMPARE ( out . str ( ) ,
" Math::lerp(): complex numbers must be normalized \n "
" Math::lerp(): complex numbers must be normalized \n " ) ;
}
void ComplexTest : : slerp ( ) {
/* Result angle should be equivalent to QuaternionTest::slerp2D() */
Complex a = Complex : : rotation ( 15.0 _degf ) ;
Complex b = Complex : : rotation ( 57.0 _degf ) ;
Complex slerp = Math : : slerp ( a , b , 0.35f ) ;
CORRADE_VERIFY ( slerp . isNormalized ( ) ) ;
CORRADE_COMPARE ( slerp . angle ( ) , 29.7 _degf ) ; /* 15 + (57-15)*0.35 */
CORRADE_COMPARE ( slerp , ( Complex { 0.868632f , 0.495459f } ) ) ;
/* Avoid division by zero */
CORRADE_COMPARE ( Math : : slerp ( a , a , 0.25f ) , a ) ;
}
void ComplexTest : : slerpNotNormalized ( ) {
std : : ostringstream out ;
Error redirectError { & out } ;
Complex a ;
Math : : slerp ( a * 3.0f , a , 0.35f ) ;
Math : : slerp ( a , a * - 3.0f , 0.35f ) ;
CORRADE_COMPARE ( out . str ( ) ,
" Math::slerp(): complex numbers must be normalized \n "
" Math::slerp(): complex numbers must be normalized \n " ) ;
}
void ComplexTest : : transformVector ( ) {
Complex a = Complex : : rotation ( Deg ( 23.0f ) ) ;
Matrix3 m = Matrix3 : : rotation ( Deg ( 23.0f ) ) ;