@ -63,6 +63,8 @@ struct FunctionsTest: TestSuite::Tester {
void sqrt ( ) ;
void sqrt ( ) ;
void sqrtInverted ( ) ;
void sqrtInverted ( ) ;
void lerp ( ) ;
void lerp ( ) ;
void lerpLimits ( ) ;
void lerpInfinity ( ) ;
void lerpBool ( ) ;
void lerpBool ( ) ;
void lerpInverted ( ) ;
void lerpInverted ( ) ;
void select ( ) ;
void select ( ) ;
@ -128,6 +130,8 @@ FunctionsTest::FunctionsTest() {
& FunctionsTest : : sqrt ,
& FunctionsTest : : sqrt ,
& FunctionsTest : : sqrtInverted ,
& FunctionsTest : : sqrtInverted ,
& FunctionsTest : : lerp ,
& FunctionsTest : : lerp ,
& FunctionsTest : : lerpLimits ,
& FunctionsTest : : lerpInfinity ,
& FunctionsTest : : lerpBool ,
& FunctionsTest : : lerpBool ,
& FunctionsTest : : lerpInverted ,
& FunctionsTest : : lerpInverted ,
& FunctionsTest : : select ,
& FunctionsTest : : select ,
@ -403,6 +407,44 @@ void FunctionsTest::lerp() {
CORRADE_COMPARE ( Math : : lerp ( 2.0 _usec , 5.0 _usec , 0.5f ) , 3.5 _usec ) ;
CORRADE_COMPARE ( Math : : lerp ( 2.0 _usec , 5.0 _usec , 0.5f ) , 3.5 _usec ) ;
}
}
template < class T , class U > T lerpOptimized ( const T & a , const T & b , U t ) {
/* One multiplication and two additions, while `T((U(1) - t)*a + t*b)` is
two multiplications , addition and subtraction . Doesn ' t correctly
preserve boundary values . */
return t * ( b - a ) + a ;
}
void FunctionsTest : : lerpLimits ( ) {
CORRADE_COMPARE ( Math : : lerp ( 1.0e10 f , 1.0e-5 f , 0.0f ) , 1.0e10 f ) ;
CORRADE_COMPARE ( Math : : lerp ( 1.0e10 f , 1.0e-5 f , 1.0f ) , 1.0e-5 f ) ;
CORRADE_COMPARE ( Math : : lerp ( 1.0e-5 f , 1.0e10 f , 0.0f ) , 1.0e-5 f ) ;
CORRADE_COMPARE ( Math : : lerp ( 1.0e-5 f , 1.0e10 f , 1.0f ) , 1.0e10 f ) ;
CORRADE_COMPARE ( lerpOptimized ( 1.0e10 f , 1.0e-5 f , 0.0f ) , 1.0e10 f ) ;
{
CORRADE_EXPECT_FAIL ( " \" Optimized \" version of a lerp doesn't correctly preserve boundary values with wildly different magnitudes. " ) ;
CORRADE_COMPARE ( lerpOptimized ( 1.0e10 f , 1.0e-5 f , 1.0f ) , 1.0e-5 f ) ;
}
}
void FunctionsTest : : lerpInfinity ( ) {
CORRADE_COMPARE ( Math : : lerp ( Constants : : inf ( ) , 0.0f , 0.0f ) , Constants : : inf ( ) ) ;
CORRADE_COMPARE ( Math : : lerp ( 0.0f , Constants : : inf ( ) , 1.0f ) , Constants : : inf ( ) ) ;
{
CORRADE_EXPECT_FAIL ( " Lerp with infinity doesn't correctly preserve the other boundary value. " ) ;
CORRADE_COMPARE ( Math : : lerp ( Constants : : inf ( ) , 0.0f , 1.0f ) , 0.0f ) ;
CORRADE_COMPARE ( Math : : lerp ( 0.0f , Constants : : inf ( ) , 0.0f ) , 0.0f ) ;
}
CORRADE_COMPARE ( lerpOptimized ( 0.0f , Constants : : inf ( ) , 1.0f ) , Constants : : inf ( ) ) ;
{
CORRADE_EXPECT_FAIL ( " \" Optimized \" version of a lerp doesn't correctly preserve boundary values if an infinity is present. " ) ;
CORRADE_COMPARE ( lerpOptimized ( Constants : : inf ( ) , 0.0f , 0.0f ) , Constants : : inf ( ) ) ;
CORRADE_COMPARE ( lerpOptimized ( Constants : : inf ( ) , 0.0f , 1.0f ) , 0.0f ) ;
CORRADE_COMPARE ( lerpOptimized ( 0.0f , Constants : : inf ( ) , 0.0f ) , 0.0f ) ;
}
}
void FunctionsTest : : lerpBool ( ) {
void FunctionsTest : : lerpBool ( ) {
/* Scalar interpolation phase */
/* Scalar interpolation phase */
CORRADE_COMPARE ( Math : : lerp ( Vector3i { 1 , 2 , 3 } , Vector3i { 5 , 6 , 7 } , true ) , ( Vector3i { 5 , 6 , 7 } ) ) ;
CORRADE_COMPARE ( Math : : lerp ( Vector3i { 1 , 2 , 3 } , Vector3i { 5 , 6 , 7 } , true ) , ( Vector3i { 5 , 6 , 7 } ) ) ;