diff --git a/src/Color.h b/src/Color.h index c3554e1ae..74b634d84 100644 --- a/src/Color.h +++ b/src/Color.h @@ -158,7 +158,7 @@ template class Color3: public Math::Vector3 { public: /** @brief Corresponding floating-point type for HSV computation */ - typedef typename Math::MathTypeTraits::FloatingPointType FloatingPointType; + typedef typename Math::TypeTraits::FloatingPointType FloatingPointType; /** * @brief Type for storing HSV values diff --git a/src/DebugTools/Implementation/ForceRendererTransformation.h b/src/DebugTools/Implementation/ForceRendererTransformation.h index 75c3896fc..067df4960 100644 --- a/src/DebugTools/Implementation/ForceRendererTransformation.h +++ b/src/DebugTools/Implementation/ForceRendererTransformation.h @@ -42,17 +42,17 @@ template<> inline Matrix4 forceRendererTransformation<3>(const Vector3& forcePos const Float forceLength = force.length(); /* Zero length, zero scaling */ - if(forceLength < Math::MathTypeTraits::epsilon()) + if(forceLength < Math::TypeTraits::epsilon()) return translation*Matrix4::scaling(Vector3(0.0f)); const Float dot = Vector3::dot(force/forceLength, Vector3::xAxis()); /* Force is parallel to X axis, just scaling */ - if(dot > 1.0f - Math::MathTypeTraits::epsilon()) + if(dot > 1.0f - Math::TypeTraits::epsilon()) return translation*Matrix4::scaling(Vector3(forceLength)); /* Force is antiparallel to X axis, scaling inverted on X */ - if(-dot > 1.0f - Math::MathTypeTraits::epsilon()) + if(-dot > 1.0f - Math::TypeTraits::epsilon()) return translation*Matrix4::scaling({-forceLength, forceLength, forceLength}); /* Normal of plane going through force vector and X axis vector */ diff --git a/src/Math/Algorithms/GaussJordan.h b/src/Math/Algorithms/GaussJordan.h index 1bdbef2b8..37bacfe51 100644 --- a/src/Math/Algorithms/GaussJordan.h +++ b/src/Math/Algorithms/GaussJordan.h @@ -64,7 +64,7 @@ template bool gaussJordanInPlaceTra std::swap(t[row], t[rowMax]); /* Singular */ - if(MathTypeTraits::equals(a[row][row], T(0))) + if(TypeTraits::equals(a[row][row], T(0))) return false; /* Eliminate column */ diff --git a/src/Math/Algorithms/Svd.h b/src/Math/Algorithms/Svd.h index fdf22703a..9c4200515 100644 --- a/src/Math/Algorithms/Svd.h +++ b/src/Math/Algorithms/Svd.h @@ -96,8 +96,8 @@ decomposition and least squares solutions"*. /* The matrix is passed by value because it is changed inside */ template std::tuple, Vector, Matrix> svd(RectangularMatrix m) { static_assert(rows >= cols, "Unsupported matrix aspect ratio"); - static_assert(T(1)+MathTypeTraits::epsilon() > T(1), "Epsilon too small"); - constexpr T tol = Implementation::smallestDelta()/MathTypeTraits::epsilon(); + static_assert(T(1)+TypeTraits::epsilon() > T(1), "Epsilon too small"); + constexpr T tol = Implementation::smallestDelta()/TypeTraits::epsilon(); static_assert(tol > T(0), "Tol too small"); constexpr std::size_t maxIterations = 50; @@ -212,7 +212,7 @@ template std::tuple::epsilon()*epsilonX; + const T epsilon = TypeTraits::epsilon()*epsilonX; for(std::size_t k2 = cols; k2 != 0; --k2) { const std::size_t k = k2 - 1; diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 5455c492a..9552fd85c 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -32,7 +32,7 @@ set(MagnumMath_HEADERS DualQuaternion.h Functions.h Math.h - MathTypeTraits.h + TypeTraits.h Matrix.h Matrix3.h Matrix4.h diff --git a/src/Math/Complex.h b/src/Math/Complex.h index cd3ed3cb5..7f7d741bb 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -69,7 +69,7 @@ template class Complex { * @see Quaternion::angle(), Vector::angle() */ inline static Rad angle(const Complex& normalizedA, const Complex& normalizedB) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Complex::angle(): complex numbers must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(std::acos(normalizedA._real*normalizedB._real + normalizedA._imaginary*normalizedB._imaginary)); } @@ -117,8 +117,8 @@ template class Complex { /** @brief Equality comparison */ inline bool operator==(const Complex& other) const { - return MathTypeTraits::equals(_real, other._real) && - MathTypeTraits::equals(_imaginary, other._imaginary); + return TypeTraits::equals(_real, other._real) && + TypeTraits::equals(_imaginary, other._imaginary); } /** @brief Non-equality comparison */ @@ -345,7 +345,7 @@ template class Complex { * @see inverted() */ inline Complex invertedNormalized() const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Complex::invertedNormalized(): complex number must be normalized", Complex(std::numeric_limits::quiet_NaN(), {})); return conjugated(); diff --git a/src/Math/Constants.h b/src/Math/Constants.h index 358a246da..9f7402da6 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -40,7 +40,7 @@ namespace Magnum { namespace Math { template struct Constants { Constants() = delete; - /* See MathTypeTraits for answer why these are functions and not constants. */ + /* See TypeTraits for answer why these are functions and not constants. */ #ifdef DOXYGEN_GENERATING_OUTPUT /** * @brief Pi diff --git a/src/Math/Dual.h b/src/Math/Dual.h index 4f6135f30..630a6f736 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -31,7 +31,7 @@ #include #include -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" namespace Magnum { namespace Math { @@ -63,8 +63,8 @@ template class Dual { /** @brief Equality comparison */ inline bool operator==(const Dual& other) const { - return MathTypeTraits::equals(_real, other._real) && - MathTypeTraits::equals(_dual, other._dual); + return TypeTraits::equals(_real, other._real) && + TypeTraits::equals(_dual, other._dual); } /** @brief Non-equality comparison */ diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index b8b6c1913..c680c53f7 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -96,7 +96,7 @@ template class Matrix3: public Matrix<3, T> { * @see Matrix4::reflection() */ static Matrix3 reflection(const Vector2& normal) { - CORRADE_ASSERT(MathTypeTraits::equals(normal.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normal.dot(), T(1)), "Math::Matrix3::reflection(): normal must be normalized", {}); return from(Matrix<2, T>() - T(2)*normal*RectangularMatrix<1, 2, T>(normal).transposed(), {}); } diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 13a96d7bb..3676f5ecc 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -91,7 +91,7 @@ template class Matrix4: public Matrix<4, T> { * Vector3::zAxis() */ static Matrix4 rotation(Rad angle, const Vector3& normalizedAxis) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedAxis.dot(), T(1)), "Math::Matrix4::rotation(): axis must be normalized", {}); T sine = std::sin(T(angle)); @@ -184,7 +184,7 @@ template class Matrix4: public Matrix<4, T> { * @see Matrix3::reflection() */ static Matrix4 reflection(const Vector3& normal) { - CORRADE_ASSERT(MathTypeTraits::equals(normal.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normal.dot(), T(1)), "Math::Matrix4::reflection(): normal must be normalized", {}); return from(Matrix<3, T>() - T(2)*normal*RectangularMatrix<1, 3, T>(normal).transposed(), {}); } diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index e57bc0023..5103de897 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -32,7 +32,7 @@ #include #include -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" #include "Math/Matrix.h" #include "Math/Vector3.h" @@ -71,7 +71,7 @@ template class Quaternion { * @see Complex::angle(), Vector::angle() */ inline static Rad angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Quaternion::angle(): quaternions must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(angleInternal(normalizedA, normalizedB)); } @@ -88,7 +88,7 @@ template class Quaternion { * @see slerp(), Math::lerp() */ inline static Quaternion lerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Quaternion::lerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); return ((T(1) - t)*normalizedA + t*normalizedB).normalized(); @@ -108,7 +108,7 @@ template class Quaternion { * @see lerp() */ inline static Quaternion slerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Quaternion::slerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); T a = angleInternal(normalizedA, normalizedB); @@ -128,7 +128,7 @@ template class Quaternion { * Vector3::yAxis(), Vector3::zAxis() */ inline static Quaternion rotation(Rad angle, const Vector3& normalizedAxis) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedAxis.dot(), T(1)), "Math::Quaternion::rotation(): axis must be normalized", {}); return {normalizedAxis*std::sin(T(angle)/2), std::cos(T(angle)/2)}; @@ -164,7 +164,7 @@ template class Quaternion { /** @brief Equality comparison */ inline bool operator==(const Quaternion& other) const { - return _vector == other._vector && MathTypeTraits::equals(_scalar, other._scalar); + return _vector == other._vector && TypeTraits::equals(_scalar, other._scalar); } /** @brief Non-equality comparison */ @@ -187,7 +187,7 @@ template class Quaternion { * @see rotationAxis(), rotation(), DualQuaternion::rotationAngle() */ inline Rad rotationAngle() const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Quaternion::rotationAngle(): quaternion must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(T(2)*std::acos(_scalar)); @@ -204,7 +204,7 @@ template class Quaternion { * @see rotationAngle(), rotation() */ inline Vector3 rotationAxis() const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Quaternion::rotationAxis(): quaternion must be normalized", {}); return _vector/std::sqrt(1-pow2(_scalar)); @@ -404,7 +404,7 @@ template class Quaternion { * @see inverted() */ inline Quaternion invertedNormalized() const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Quaternion::invertedNormalized(): quaternion must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); return conjugated(); @@ -435,7 +435,7 @@ template class Quaternion { * DualQuaternion::transformPointNormalized(), Complex::transformVector() */ inline Vector3 transformVectorNormalized(const Vector3& vector) const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Quaternion::transformVectorNormalized(): quaternion must be normalized", Vector3(std::numeric_limits::quiet_NaN())); return ((*this)*Quaternion(vector)*conjugated()).vector(); diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 4e2a1a990..e071c9da9 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -25,7 +25,7 @@ corrade_add_test(MathBoolVectorTest BoolVectorTest.cpp) corrade_add_test(MathConstantsTest ConstantsTest.cpp) corrade_add_test(MathFunctionsTest FunctionsTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) +corrade_add_test(MathTypeTraitsTest TypeTraitsTest.cpp) corrade_add_test(MathVectorTest VectorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathVector2Test Vector2Test.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index d35efe979..1cbc1d8af 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -120,10 +120,10 @@ void ComplexTest::constructFromVector() { } void ComplexTest::compare() { - CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()/2) == Complex(3.7f, -1.0f)); - CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()*2) != Complex(3.7f, -1.0f)); - CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()/2, 3.7f) == Complex(1.0f, 3.7f)); - CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()*2, 3.7f) != Complex(1.0f, 3.7f)); + CORRADE_VERIFY(Complex(3.7f, -1.0f+TypeTraits::epsilon()/2) == Complex(3.7f, -1.0f)); + CORRADE_VERIFY(Complex(3.7f, -1.0f+TypeTraits::epsilon()*2) != Complex(3.7f, -1.0f)); + CORRADE_VERIFY(Complex(1.0f+TypeTraits::epsilon()/2, 3.7f) == Complex(1.0f, 3.7f)); + CORRADE_VERIFY(Complex(1.0f+TypeTraits::epsilon()*2, 3.7f) != Complex(1.0f, 3.7f)); } void ComplexTest::constExpressions() { diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp index 3bc8057d1..dd6338f0c 100644 --- a/src/Math/Test/DualTest.cpp +++ b/src/Math/Test/DualTest.cpp @@ -83,10 +83,10 @@ void DualTest::constructDefault() { } void DualTest::compare() { - CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()/2) == Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()*2) != Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()/2, 1.0f) == Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()*2, 1.0f) != Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f, 1.0f+TypeTraits::epsilon()/2) == Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f, 1.0f+TypeTraits::epsilon()*2) != Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f+TypeTraits::epsilon()/2, 1.0f) == Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f+TypeTraits::epsilon()*2, 1.0f) != Dual(1.0f, 1.0f)); /* Compare to real part only */ CORRADE_VERIFY(Dual(1.0f, 0.0f) == 1.0f); diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 75d4ddf46..6577ea5ab 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -123,10 +123,10 @@ void QuaternionTest::constructFromVector() { } void QuaternionTest::compare() { - CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()/2, 2.0f, 3.0f}, -4.0f) == Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); - CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()*2, 2.0f, 3.0f}, -4.0f) != Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); - CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()/2) == Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); - CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); + CORRADE_VERIFY(Quaternion({1.0f+TypeTraits::epsilon()/2, 2.0f, 3.0f}, -4.0f) == Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_VERIFY(Quaternion({1.0f+TypeTraits::epsilon()*2, 2.0f, 3.0f}, -4.0f) != Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+TypeTraits::epsilon()/2) == Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); + CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+TypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); } void QuaternionTest::constExpressions() { diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 7c2c22289..d311231c3 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -214,9 +214,9 @@ void RectangularMatrixTest::row() { void RectangularMatrixTest::compare() { Matrix2 a(Vector2(1.0f, -3.0f), Vector2(5.0f, -10.0f)); - Matrix2 b(Vector2(1.0f + MathTypeTraits::epsilon()/2, -3.0f), + Matrix2 b(Vector2(1.0f + TypeTraits::epsilon()/2, -3.0f), Vector2(5.0f, -10.0f)); - Matrix2 c(Vector2(1.0f, -1.0f + MathTypeTraits::epsilon()*2), + Matrix2 c(Vector2(1.0f, -1.0f + TypeTraits::epsilon()*2), Vector2(5.0f, -10.0f)); CORRADE_VERIFY(a == b); CORRADE_VERIFY(a != c); diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/TypeTraitsTest.cpp similarity index 67% rename from src/Math/Test/MathTypeTraitsTest.cpp rename to src/Math/Test/TypeTraitsTest.cpp index f1239ce50..63a6fbace 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/TypeTraitsTest.cpp @@ -25,13 +25,13 @@ #include #include -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" namespace Magnum { namespace Math { namespace Test { -class MathTypeTraitsTest: public Corrade::TestSuite::Tester { +class TypeTraitsTest: public Corrade::TestSuite::Tester { public: - MathTypeTraitsTest(); + TypeTraitsTest(); void equalsFloatingPoint(); void equalsIntegral(); @@ -41,12 +41,12 @@ class MathTypeTraitsTest: public Corrade::TestSuite::Tester { template void _equalsIntegral(); }; -MathTypeTraitsTest::MathTypeTraitsTest() { - addTests({&MathTypeTraitsTest::equalsIntegral, - &MathTypeTraitsTest::equalsFloatingPoint}); +TypeTraitsTest::TypeTraitsTest() { + addTests({&TypeTraitsTest::equalsIntegral, + &TypeTraitsTest::equalsFloatingPoint}); } -void MathTypeTraitsTest::equalsIntegral() { +void TypeTraitsTest::equalsIntegral() { _equalsIntegral(); _equalsIntegral(); _equalsIntegral(); @@ -57,29 +57,29 @@ void MathTypeTraitsTest::equalsIntegral() { _equalsIntegral(); } -void MathTypeTraitsTest::equalsFloatingPoint() { +void TypeTraitsTest::equalsFloatingPoint() { _equalsFloatingPoint(); _equalsFloatingPoint(); } -template void MathTypeTraitsTest::_equalsIntegral() { - CORRADE_VERIFY(!MathTypeTraits::equals(1, 1+MathTypeTraits::epsilon())); +template void TypeTraitsTest::_equalsIntegral() { + CORRADE_VERIFY(!TypeTraits::equals(1, 1+TypeTraits::epsilon())); } -template void MathTypeTraitsTest::_equalsFloatingPoint() { - CORRADE_VERIFY(MathTypeTraits::equals(T(1)+MathTypeTraits::epsilon()/T(2), T(1))); - CORRADE_VERIFY(!MathTypeTraits::equals(T(1)+MathTypeTraits::epsilon()*T(2), T(1))); +template void TypeTraitsTest::_equalsFloatingPoint() { + CORRADE_VERIFY(TypeTraits::equals(T(1)+TypeTraits::epsilon()/T(2), T(1))); + CORRADE_VERIFY(!TypeTraits::equals(T(1)+TypeTraits::epsilon()*T(2), T(1))); { CORRADE_EXPECT_FAIL("Comparing to infinity is broken"); - CORRADE_VERIFY(MathTypeTraits::equals(std::numeric_limits::infinity(), + CORRADE_VERIFY(TypeTraits::equals(std::numeric_limits::infinity(), std::numeric_limits::infinity())); } - CORRADE_VERIFY(!MathTypeTraits::equals(std::numeric_limits::quiet_NaN(), + CORRADE_VERIFY(!TypeTraits::equals(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); } }}} -CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest) +CORRADE_TEST_MAIN(Magnum::Math::Test::TypeTraitsTest) diff --git a/src/Math/Test/UnitTest.cpp b/src/Math/Test/UnitTest.cpp index 18dc1179d..d1d687a9a 100644 --- a/src/Math/Test/UnitTest.cpp +++ b/src/Math/Test/UnitTest.cpp @@ -78,8 +78,8 @@ void UnitTest::constructConversion() { } void UnitTest::compare() { - CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()/2) == Sec(25.0f)); - CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()*2) != Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + TypeTraits::epsilon()/2) == Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + TypeTraits::epsilon()*2) != Sec(25.0f)); constexpr bool c = Sec(3.0f) < Sec(3.0f); constexpr bool d = Sec(3.0f) <= Sec(3.0f); diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 8cc307a5b..7c301cd7e 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -215,8 +215,8 @@ void VectorTest::data() { } void VectorTest::compare() { - CORRADE_VERIFY(Vector4(1.0f, -3.5f, 5.0f, -10.0f) == Vector4(1.0f + MathTypeTraits::epsilon()/2, -3.5f, 5.0f, -10.0f)); - CORRADE_VERIFY(Vector4(1.0f, -1.0f, 5.0f, -10.0f) != Vector4(1.0f, -1.0f + MathTypeTraits::epsilon()*2, 5.0f, -10.0f)); + CORRADE_VERIFY(Vector4(1.0f, -3.5f, 5.0f, -10.0f) == Vector4(1.0f + TypeTraits::epsilon()/2, -3.5f, 5.0f, -10.0f)); + CORRADE_VERIFY(Vector4(1.0f, -1.0f, 5.0f, -10.0f) != Vector4(1.0f, -1.0f + TypeTraits::epsilon()*2, 5.0f, -10.0f)); CORRADE_VERIFY(Vector4i(1, -3, 5, -10) == Vector4i(1, -3, 5, -10)); CORRADE_VERIFY(Vector4i(1, -3, 5, -10) != Vector4i(1, -2, 5, -10)); diff --git a/src/Math/MathTypeTraits.h b/src/Math/TypeTraits.h similarity index 73% rename from src/Math/MathTypeTraits.h rename to src/Math/TypeTraits.h index 7a8dbe0e8..8897f33c3 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/TypeTraits.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Math_MathTypeTraits_h -#define Magnum_Math_MathTypeTraits_h +#ifndef Magnum_Math_TypeTraits_h +#define Magnum_Math_TypeTraits_h /* This file is part of Magnum. @@ -25,7 +25,7 @@ */ /** @file - * @brief Class Magnum::Math::MathTypeTraits + * @brief Class Magnum::Math::TypeTraits */ #include @@ -54,8 +54,8 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct MathTypeTraitsDefault { - MathTypeTraitsDefault() = delete; + template struct TypeTraitsDefault { + TypeTraitsDefault() = delete; inline constexpr static bool equals(T a, T b) { return a == b; @@ -71,7 +71,7 @@ Traits classes are usable for detecting type features at compile time without the need for repeated code such as method overloading or template specialization for given types. */ -template struct MathTypeTraits: Implementation::MathTypeTraitsDefault { +template struct TypeTraits: Implementation::TypeTraitsDefault { /* * The following values are implemented as inline functions, not as * static const variables, because the compiler will inline the return @@ -118,58 +118,58 @@ template struct MathTypeTraits: Implementation::MathTypeTraitsDefault struct MathTypeTraitsIntegral: MathTypeTraitsDefault { + template struct TypeTraitsIntegral: TypeTraitsDefault { inline constexpr static T epsilon() { return T(1); } }; } -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef long double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef long double FloatingPointType; }; /* Floating-point scalar types */ namespace Implementation { - template struct MathTypeTraitsFloatingPoint { - MathTypeTraitsFloatingPoint() = delete; + template struct TypeTraitsFloatingPoint { + TypeTraitsFloatingPoint() = delete; inline static bool equals(T a, T b) { - return std::abs(a - b) < MathTypeTraits::epsilon(); + return std::abs(a - b) < TypeTraits::epsilon(); } }; } -template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { +template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint { typedef Float FloatingPointType; inline constexpr static Float epsilon() { return FLOAT_EQUALITY_PRECISION; } }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { +template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint { typedef Double FloatingPointType; inline constexpr static Double epsilon() { return DOUBLE_EQUALITY_PRECISION; } }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { +template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint { typedef long double FloatingPointType; inline constexpr static long double epsilon() { return LONG_DOUBLE_EQUALITY_PRECISION; } diff --git a/src/Math/Unit.h b/src/Math/Unit.h index 4b9c5aad3..7a586ec6e 100644 --- a/src/Math/Unit.h +++ b/src/Math/Unit.h @@ -28,7 +28,7 @@ * @brief Class Magnum::Math::Unit */ -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" namespace Magnum { namespace Math { @@ -58,7 +58,7 @@ template class Derived, class T> class Unit { /** @brief Equality comparison */ inline constexpr bool operator==(Unit other) const { - return MathTypeTraits::equals(value, other.value); + return TypeTraits::equals(value, other.value); } /** @brief Non-equality comparison */ diff --git a/src/Math/Vector.h b/src/Math/Vector.h index df51b6a7f..767c79ce0 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -36,7 +36,7 @@ #include "Math/Angle.h" #include "Math/BoolVector.h" -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" #include "magnumVisibility.h" @@ -102,7 +102,7 @@ template class Vector { * @see Quaternion::angle(), Complex::angle() */ inline static Rad angle(const Vector& normalizedA, const Vector& normalizedB) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Vector::angle(): vectors must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(std::acos(dot(normalizedA, normalizedB))); } @@ -195,7 +195,7 @@ template class Vector { /** @brief Equality comparison */ inline bool operator==(const Vector& other) const { for(std::size_t i = 0; i != size; ++i) - if(!MathTypeTraits::equals(_data[i], other._data[i])) return false; + if(!TypeTraits::equals(_data[i], other._data[i])) return false; return true; } @@ -468,7 +468,7 @@ template class Vector { * @f] */ inline Vector projectedOntoNormalized(const Vector& line) const { - CORRADE_ASSERT(MathTypeTraits::equals(line.dot(), T(1)), "Math::Vector::projectedOntoNormalized(): line must be normalized", (Vector(std::numeric_limits::quiet_NaN()))); + CORRADE_ASSERT(TypeTraits::equals(line.dot(), T(1)), "Math::Vector::projectedOntoNormalized(): line must be normalized", (Vector(std::numeric_limits::quiet_NaN()))); return line*dot(*this, line); } diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 288fc5992..369fbc680 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -43,7 +43,7 @@ template class Clean { public: inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} - void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { + void operator()(typename Vertex::Type epsilon = Math::TypeTraits::epsilon()) { if(indices.empty()) return; /* Get mesh bounds */ @@ -145,7 +145,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::TypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); }