diff --git a/src/Math/Algorithms/Svd.h b/src/Math/Algorithms/Svd.h index 9c4200515..51ef991ae 100644 --- a/src/Math/Algorithms/Svd.h +++ b/src/Math/Algorithms/Svd.h @@ -51,7 +51,9 @@ template T pythagoras(T a, T b) { template T smallestDelta(); template<> inline constexpr Float smallestDelta() { return 1.0e-32; } +#ifndef MAGNUM_TARGET_GLES template<> inline constexpr Double smallestDelta() { return 1.0e-64; } +#endif } #endif diff --git a/src/Math/Algorithms/Test/SvdTest.cpp b/src/Math/Algorithms/Test/SvdTest.cpp index ca1a1219b..3397f92f3 100644 --- a/src/Math/Algorithms/Test/SvdTest.cpp +++ b/src/Math/Algorithms/Test/SvdTest.cpp @@ -36,11 +36,13 @@ class SvdTest: public Corrade::TestSuite::Tester { void testFloat(); }; +#ifndef MAGNUM_TARGET_GLES typedef RectangularMatrix<5, 8, Double> Matrix5x8d; typedef Matrix<8, Double> Matrix8d; typedef Matrix<5, Double> Matrix5d; typedef Vector<8, Double> Vector8d; typedef Vector<5, Double> Vector5d; +#endif typedef RectangularMatrix<5, 8, Float> Matrix5x8f; typedef Matrix<8, Float> Matrix8f; @@ -48,15 +50,25 @@ typedef Matrix<5, Float> Matrix5f; typedef Vector<8, Float> Vector8f; typedef Vector<5, Float> Vector5f; -constexpr static Matrix5x8d a( +#ifndef MAGNUM_TARGET_GLES +constexpr static Matrix5x8d ad( Vector8d(22.0, 14.0, -1.0, -3.0, 9.0, 9.0, 2.0, 4.0), Vector8d(10.0, 7.0, 13.0, -2.0, 8.0, 1.0, -6.0, 5.0), Vector8d( 2.0, 10.0, -1.0, 13.0, 1.0, -7.0, 6.0, 0.0), Vector8d( 3.0, 0.0, -11.0, -2.0, -2.0, 5.0, 5.0, -2.0), Vector8d( 7.0, 8.0, 3.0, 4.0, 4.0, -1.0, 1.0, 2.0) ); - -static const Vector5d expected(std::sqrt(1248.0), 0.0, 20.0, std::sqrt(384.0), 0.0); +static const Vector5d expectedd(std::sqrt(1248.0), 0.0, 20.0, std::sqrt(384.0), 0.0); +#endif + +constexpr static Matrix5x8f af( + Vector8f(22.0f, 14.0f, -1.0f, -3.0f, 9.0f, 9.0f, 2.0f, 4.0f), + Vector8f(10.0f, 7.0f, 13.0f, -2.0f, 8.0f, 1.0f, -6.0f, 5.0f), + Vector8f( 2.0f, 10.0f, -1.0f, 13.0f, 1.0f, -7.0f, 6.0f, 0.0f), + Vector8f( 3.0f, 0.0f, -11.0f, -2.0f, -2.0f, 5.0f, 5.0f, -2.0f), + Vector8f( 7.0f, 8.0f, 3.0f, 4.0f, 4.0f, -1.0f, 1.0f, 2.0f) +); +static const Vector5f expectedf(std::sqrt(1248.0f), 0.0f, 20.0f, std::sqrt(384.0f), 0.0f); SvdTest::SvdTest() { addTests({&SvdTest::testDouble, @@ -64,41 +76,45 @@ SvdTest::SvdTest() { } void SvdTest::testDouble() { + #ifndef MAGNUM_TARGET_GLES Matrix5x8d u; Vector5d w; Matrix5d v; - std::tie(u, w, v) = Algorithms::svd(a); + std::tie(u, w, v) = Algorithms::svd(ad); /* Test composition */ Matrix8d u2(u[0], u[1], u[2], u[3], u[4], Vector8d(), Vector8d(), Vector8d()); Matrix5x8d w2 = Matrix5x8d::fromDiagonal(w); - CORRADE_COMPARE(u2*w2*v.transposed(), a); + CORRADE_COMPARE(u2*w2*v.transposed(), ad); /* Test that V is unitary */ CORRADE_COMPARE(v*v.transposed(), Matrix5d(Matrix5d::Identity)); CORRADE_COMPARE(v.transposed()*v, Matrix5d(Matrix5d::Identity)); /* Test W */ - CORRADE_COMPARE(w, expected); + CORRADE_COMPARE(w, expectedd); + #else + CORRADE_SKIP("Double precision is not supported when targeting OpenGL ES."); + #endif } void SvdTest::testFloat() { Matrix5x8f u; Vector5f w; Matrix5f v; - std::tie(u, w, v) = Algorithms::svd(Matrix5x8f(a)); + std::tie(u, w, v) = Algorithms::svd(af); /* Test composition (single precision is not enough, test for similarity) */ Matrix8f u2(u[0], u[1], u[2], u[3], u[4], Vector8f(), Vector8f(), Vector8f()); Matrix5x8f w2 = Matrix5x8f::fromDiagonal(w); - CORRADE_VERIFY((u2*w2*v.transposed()-Matrix5x8f(a)).maxAbs() < 1.0e-5f); + CORRADE_VERIFY((u2*w2*v.transposed()-af).maxAbs() < 1.0e-5f); /* Test that V is unitary */ CORRADE_COMPARE(v*v.transposed(), Matrix5f(Matrix5f::Identity)); CORRADE_COMPARE(v.transposed()*v, Matrix5f(Matrix5f::Identity)); /* Test W (single precision is not enough, test for similarity) */ - CORRADE_VERIFY((w-Vector5f(expected)).maxAbs() < 1.0e-5f); + CORRADE_VERIFY((w-expectedf).maxAbs() < 1.0e-5f); } }}}} diff --git a/src/Math/Constants.h b/src/Math/Constants.h index 9f7402da6..d4c232677 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -55,6 +55,7 @@ template struct Constants { }; #ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef MAGNUM_TARGET_GLES template<> struct Constants { Constants() = delete; @@ -62,6 +63,7 @@ template<> struct Constants { static inline constexpr Double sqrt2() { return 1.414213562373095; } static inline constexpr Double sqrt3() { return 1.732050807568877; } }; +#endif template<> struct Constants { Constants() = delete; diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index eef26316f..9242453b7 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -33,23 +33,31 @@ class ConstantsTest: public Corrade::TestSuite::Tester { public: ConstantsTest(); - void constants(); + void constantsFloat(); + void constantsDouble(); }; ConstantsTest::ConstantsTest() { - addTests({&ConstantsTest::constants}); + addTests({&ConstantsTest::constantsFloat, + &ConstantsTest::constantsDouble}); } -void ConstantsTest::constants() { +void ConstantsTest::constantsFloat() { constexpr Float a = Constants::sqrt2(); constexpr Float b = Constants::sqrt3(); CORRADE_COMPARE(Math::pow<2>(a), 2.0f); CORRADE_COMPARE(Math::pow<2>(b), 3.0f); +} +void ConstantsTest::constantsDouble() { + #ifndef MAGNUM_TARGET_GLES constexpr Double c = Constants::sqrt2(); constexpr Double d = Constants::sqrt3(); CORRADE_COMPARE(Math::pow<2>(c), 2.0); CORRADE_COMPARE(Math::pow<2>(d), 3.0); + #else + CORRADE_SKIP("Double precision is not supported when targeting OpenGL ES."); + #endif } }}}