From 9bb5171365d35b1b3e4d88dc7dc508653d23a139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 18 Oct 2014 14:41:58 +0200 Subject: [PATCH] Math: added Constants::tau(). Or two pi, 6.28. --- src/Magnum/Math/Constants.h | 12 +++++++++++- src/Magnum/Math/Test/ConstantsTest.cpp | 14 ++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Magnum/Math/Constants.h b/src/Magnum/Math/Constants.h index fc14397f6..0b2803fe4 100644 --- a/src/Magnum/Math/Constants.h +++ b/src/Magnum/Math/Constants.h @@ -46,10 +46,18 @@ template struct Constants { /** * @brief Pi * - * @see @ref Deg, @ref Rad + * @see @ref tau(), @ref Deg, @ref Rad */ static constexpr T pi(); + /** + * @brief Tau + * + * Or two pi. + * @see @ref pi(), @ref Deg, @ref Rad + */ + static constexpr T tau(); + static constexpr T sqrt2(); /**< @brief Square root of 2 */ static constexpr T sqrt3(); /**< @brief Square root of 3 */ #endif @@ -61,6 +69,7 @@ template<> struct Constants { Constants() = delete; static constexpr Double pi() { return 3.141592653589793; } + static constexpr Double tau() { return 6.283185307179586; } static constexpr Double sqrt2() { return 1.414213562373095; } static constexpr Double sqrt3() { return 1.732050807568877; } }; @@ -69,6 +78,7 @@ template<> struct Constants { Constants() = delete; static constexpr Float pi() { return 3.141592654f; } + static constexpr Float tau() { return 6.283185307f; } static constexpr Float sqrt2() { return 1.414213562f; } static constexpr Float sqrt3() { return 1.732050808f; } }; diff --git a/src/Magnum/Math/Test/ConstantsTest.cpp b/src/Magnum/Math/Test/ConstantsTest.cpp index 5a33881a0..5ad0cae87 100644 --- a/src/Magnum/Math/Test/ConstantsTest.cpp +++ b/src/Magnum/Math/Test/ConstantsTest.cpp @@ -48,14 +48,20 @@ void ConstantsTest::constantsFloat() { constexpr Float b = Constants::sqrt3(); CORRADE_COMPARE(Math::pow<2>(a), 2.0f); CORRADE_COMPARE(Math::pow<2>(b), 3.0f); + + constexpr Float c = Constants::pi(); + CORRADE_COMPARE(2.0f*c, Constants::tau()); } 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); + constexpr Double a = Constants::sqrt2(); + constexpr Double b = Constants::sqrt3(); + CORRADE_COMPARE(Math::pow<2>(a), 2.0); + CORRADE_COMPARE(Math::pow<2>(b), 3.0); + + constexpr Double c = Constants::pi(); + CORRADE_COMPARE(2.0*c, Constants::tau()); #else CORRADE_SKIP("Double precision is not supported when targeting OpenGL ES."); #endif