From d9936c40fd9be160a0b9eddebd469b2051ebca2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 May 2018 16:02:31 +0200 Subject: [PATCH] Math: added Constants::piQuarter(). --- doc/changelog.dox | 6 ++++++ src/Magnum/Math/Constants.h | 17 +++++++++++---- src/Magnum/Math/Test/ConstantsTest.cpp | 30 +++++++++++++++----------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 06b366683..a4eb32ae2 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -38,6 +38,12 @@ See also: @section changelog-latest Changes since 2018.04 +@subsection changelog-latest-new New features + +@subsubsection changelog-lates-new-math Math library + +- Added @ref Math::piQuarter() + @subsection changelog-latest-changes Changes and improvements - @ref Platform::GlfwApplication now behaves the same as diff --git a/src/Magnum/Math/Constants.h b/src/Magnum/Math/Constants.h index df2739363..ea13c8dd8 100644 --- a/src/Magnum/Math/Constants.h +++ b/src/Magnum/Math/Constants.h @@ -48,22 +48,29 @@ template struct Constants { /** * @brief Pi * - * @see @ref piHalf(), @ref tau(), @ref Deg, @ref Rad + * @see @ref piHalf(), @ref piQuarter(), @ref tau(), @ref Deg, @ref Rad */ static constexpr T pi(); /** - * @brief Half pi + * @brief Half of a pi * - * @see @ref pi(), @ref tau(), @ref Deg, @ref Rad + * @see @ref pi(), @ref piQuarter(), @ref tau(), @ref Deg, @ref Rad */ static constexpr T piHalf(); + /** + * @brief Quarter of a pi + * + * @see @ref pi(), @ref piHalf(), @ref tau(), @ref Deg, @ref Rad + */ + static constexpr T piQuarter(); + /** * @brief Tau * * Or two pi. See the [Tau manifesto](https://www.tauday.com/tau-manifesto). - * @see @ref pi(), @ref piHalf(), @ref Deg, @ref Rad + * @see @ref pi(), @ref piHalf(), @ref piQuarter(), @ref Deg, @ref Rad */ static constexpr T tau(); @@ -93,6 +100,7 @@ template<> struct Constants { static constexpr Double pi() { return 3.141592653589793; } static constexpr Double piHalf() { return 1.570796326794897; } + static constexpr Double piQuarter() { return 0.785398163397448; } static constexpr Double tau() { return 6.283185307179586; } static constexpr Double e() { return 2.718281828459045; } static constexpr Double sqrt2() { return 1.414213562373095; } @@ -106,6 +114,7 @@ template<> struct Constants { static constexpr Float pi() { return 3.141592654f; } static constexpr Float piHalf() { return 1.570796327f; } + static constexpr Float piQuarter() { return 0.785398163f; } static constexpr Float tau() { return 6.283185307f; } static constexpr Float e() { return 2.718281828f; } static constexpr Float sqrt2() { return 1.414213562f; } diff --git a/src/Magnum/Math/Test/ConstantsTest.cpp b/src/Magnum/Math/Test/ConstantsTest.cpp index b3cea52a6..b2205dbe9 100644 --- a/src/Magnum/Math/Test/ConstantsTest.cpp +++ b/src/Magnum/Math/Test/ConstantsTest.cpp @@ -48,19 +48,23 @@ ConstantsTest::ConstantsTest() { template void ConstantsTest::constants() { setTestCaseName(std::is_same::value ? "constants" : "constants"); - constexpr T a = Constants::sqrt2(); - constexpr T b = Constants::sqrt3(); - CORRADE_COMPARE(Math::pow<2>(a), T(2)); - CORRADE_COMPARE(Math::pow<2>(b), T(3)); - - constexpr T c = Constants::pi(); - constexpr T d = Constants::piHalf(); - constexpr T e = Constants::tau(); - CORRADE_COMPARE(T(0.5)*c, d); - CORRADE_COMPARE(T(2.0)*c, e); - - constexpr T f = Constants::e(); - CORRADE_COMPARE(std::log(f), T(1)); + { + constexpr T a = Constants::sqrt2(); + constexpr T b = Constants::sqrt3(); + CORRADE_COMPARE(Math::pow<2>(a), T(2)); + CORRADE_COMPARE(Math::pow<2>(b), T(3)); + } { + constexpr T a = Constants::pi(); + constexpr T b = Constants::piHalf(); + constexpr T c = Constants::piQuarter(); + constexpr T d = Constants::tau(); + CORRADE_COMPARE(T(0.50)*a, b); + CORRADE_COMPARE(T(0.25)*a, c); + CORRADE_COMPARE(T(2.00)*a, d); + } { + constexpr T e = Constants::e(); + CORRADE_COMPARE(std::log(e), T(1)); + } } template void ConstantsTest::specials() {