|
|
|
@ -39,6 +39,9 @@ class FunctionsTest: public Corrade::TestSuite::Tester { |
|
|
|
void max(); |
|
|
|
void max(); |
|
|
|
void maxList(); |
|
|
|
void maxList(); |
|
|
|
void minmax(); |
|
|
|
void minmax(); |
|
|
|
|
|
|
|
void clamp(); |
|
|
|
|
|
|
|
void nanPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
void sign(); |
|
|
|
void sign(); |
|
|
|
void abs(); |
|
|
|
void abs(); |
|
|
|
|
|
|
|
|
|
|
|
@ -48,7 +51,6 @@ class FunctionsTest: public Corrade::TestSuite::Tester { |
|
|
|
|
|
|
|
|
|
|
|
void sqrt(); |
|
|
|
void sqrt(); |
|
|
|
void sqrtInverted(); |
|
|
|
void sqrtInverted(); |
|
|
|
void clamp(); |
|
|
|
|
|
|
|
void lerp(); |
|
|
|
void lerp(); |
|
|
|
void lerpInverted(); |
|
|
|
void lerpInverted(); |
|
|
|
void fma(); |
|
|
|
void fma(); |
|
|
|
@ -71,6 +73,7 @@ class FunctionsTest: public Corrade::TestSuite::Tester { |
|
|
|
typedef Math::Constants<Float> Constants; |
|
|
|
typedef Math::Constants<Float> Constants; |
|
|
|
typedef Math::Deg<Float> Deg; |
|
|
|
typedef Math::Deg<Float> Deg; |
|
|
|
typedef Math::Rad<Float> Rad; |
|
|
|
typedef Math::Rad<Float> Rad; |
|
|
|
|
|
|
|
typedef Math::Vector2<Float> Vector2; |
|
|
|
typedef Math::Vector3<Float> Vector3; |
|
|
|
typedef Math::Vector3<Float> Vector3; |
|
|
|
typedef Math::Vector3<UnsignedByte> Vector3ub; |
|
|
|
typedef Math::Vector3<UnsignedByte> Vector3ub; |
|
|
|
typedef Math::Vector3<Byte> Vector3b; |
|
|
|
typedef Math::Vector3<Byte> Vector3b; |
|
|
|
@ -82,6 +85,9 @@ FunctionsTest::FunctionsTest() { |
|
|
|
&FunctionsTest::max, |
|
|
|
&FunctionsTest::max, |
|
|
|
&FunctionsTest::maxList, |
|
|
|
&FunctionsTest::maxList, |
|
|
|
&FunctionsTest::minmax, |
|
|
|
&FunctionsTest::minmax, |
|
|
|
|
|
|
|
&FunctionsTest::clamp, |
|
|
|
|
|
|
|
&FunctionsTest::nanPropagation, |
|
|
|
|
|
|
|
|
|
|
|
&FunctionsTest::sign, |
|
|
|
&FunctionsTest::sign, |
|
|
|
&FunctionsTest::abs, |
|
|
|
&FunctionsTest::abs, |
|
|
|
|
|
|
|
|
|
|
|
@ -91,7 +97,6 @@ FunctionsTest::FunctionsTest() { |
|
|
|
|
|
|
|
|
|
|
|
&FunctionsTest::sqrt, |
|
|
|
&FunctionsTest::sqrt, |
|
|
|
&FunctionsTest::sqrtInverted, |
|
|
|
&FunctionsTest::sqrtInverted, |
|
|
|
&FunctionsTest::clamp, |
|
|
|
|
|
|
|
&FunctionsTest::lerp, |
|
|
|
&FunctionsTest::lerp, |
|
|
|
&FunctionsTest::lerpInverted, |
|
|
|
&FunctionsTest::lerpInverted, |
|
|
|
&FunctionsTest::fma, |
|
|
|
&FunctionsTest::fma, |
|
|
|
@ -147,6 +152,30 @@ void FunctionsTest::minmax() { |
|
|
|
CORRADE_COMPARE_AS(Math::minmax(b, a), expectedVector, std::pair<Vector3, Vector3>); |
|
|
|
CORRADE_COMPARE_AS(Math::minmax(b, a), expectedVector, std::pair<Vector3, Vector3>); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FunctionsTest::clamp() { |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(0.5f, -1.0f, 5.0f), 0.5f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(-1.6f, -1.0f, 5.0f), -1.0f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(9.5f, -1.0f, 5.0f), 5.0f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(Vector3(0.5f, -1.6f, 9.5f), -1.0f, 5.0f), Vector3(0.5f, -1.0f, 5.0f)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FunctionsTest::nanPropagation() { |
|
|
|
|
|
|
|
constexpr const Float NaN = std::numeric_limits<float>::quiet_NaN(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::min(NaN, 5.0f), NaN); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::min(Vector2{NaN, 6.0f}, Vector2{5.0f})[0], NaN); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::min(Vector2{NaN, 6.0f}, Vector2{5.0f})[1], 5.0f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::max(NaN, 5.0f), NaN); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::max(Vector2{NaN, 4.0f}, Vector2{5.0f})[0], NaN); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::max(Vector2{NaN, 4.0f}, Vector2{5.0f})[1], 5.0f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(NaN, 2.0f, 6.0f), NaN); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(Vector2{NaN, 1.0f}, 2.0f, 6.0f)[0], NaN); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(Vector2{NaN, 1.0f}, 2.0f, 6.0f)[1], 2.0f); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FunctionsTest::sign() { |
|
|
|
void FunctionsTest::sign() { |
|
|
|
CORRADE_COMPARE(Math::sign(3516), 1); |
|
|
|
CORRADE_COMPARE(Math::sign(3516), 1); |
|
|
|
CORRADE_COMPARE(Math::sign(0.0f), 0.0f); |
|
|
|
CORRADE_COMPARE(Math::sign(0.0f), 0.0f); |
|
|
|
@ -194,14 +223,6 @@ void FunctionsTest::sqrtInverted() { |
|
|
|
CORRADE_COMPARE(Math::sqrtInverted(Vector3(1.0f, 4.0f, 16.0f)), Vector3(1.0f, 0.5f, 0.25f)); |
|
|
|
CORRADE_COMPARE(Math::sqrtInverted(Vector3(1.0f, 4.0f, 16.0f)), Vector3(1.0f, 0.5f, 0.25f)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FunctionsTest::clamp() { |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(0.5f, -1.0f, 5.0f), 0.5f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(-1.6f, -1.0f, 5.0f), -1.0f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(9.5f, -1.0f, 5.0f), 5.0f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::clamp(Vector3(0.5f, -1.6f, 9.5f), -1.0f, 5.0f), Vector3(0.5f, -1.0f, 5.0f)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FunctionsTest::lerp() { |
|
|
|
void FunctionsTest::lerp() { |
|
|
|
/* Floating-point / integral scalar */ |
|
|
|
/* Floating-point / integral scalar */ |
|
|
|
CORRADE_COMPARE(Math::lerp(2.0f, 5.0f, 0.5f), 3.5f); |
|
|
|
CORRADE_COMPARE(Math::lerp(2.0f, 5.0f, 0.5f), 3.5f); |
|
|
|
|