diff --git a/doc/changelog.dox b/doc/changelog.dox index 734563366..a3cf253a9 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -106,7 +106,7 @@ See also: integral centered ranges - @ref Math::Range is now constructible from a @ref std::pair of values, making it usable in combination with @ref Math::minmax(), for example -- Added @ref Math::Constants::piQuarter() +- Added @ref Math::Constants::piQuarter(), @ref Math::Constants::sqrtHalf() - Added a convenience function @ref Math::select() as a constant interpolation counterpart to @ref Math::lerp() - Added a convenience function @ref Math::planeEquation() to aid with passing diff --git a/src/Magnum/Math/Constants.h b/src/Magnum/Math/Constants.h index 9d1dbd940..7c96a4f59 100644 --- a/src/Magnum/Math/Constants.h +++ b/src/Magnum/Math/Constants.h @@ -71,7 +71,8 @@ template struct Constants { * @f[ * \frac{\pi}{4} = 45 \degree * @f] - * @see @ref pi(), @ref piHalf(), @ref tau(), @ref Deg, @ref Rad + * @see @ref pi(), @ref piHalf(), @ref sqrtHalf(), @ref tau(), @ref Deg, + * @ref Rad */ static constexpr T piQuarter(); @@ -117,6 +118,16 @@ template struct Constants { */ static constexpr T sqrt3(); + /** + * @brief Square root of @f$ \frac{1}{2} @f$ + * + * @f[ + * \frac{\sqrt{2}}{2} = \frac{1}{\sqrt{2}} = \sin(45 \degree) = \cos(45 \degree) + * @f] + * @see @ref sqrt2(), @ref sqrt3(), @ref piQuarter() + */ + static constexpr T sqrtHalf(); + /** * @brief Quiet NaN * @@ -144,6 +155,7 @@ template<> struct Constants { static constexpr Double e() { return 2.718281828459045; } static constexpr Double sqrt2() { return 1.414213562373095; } static constexpr Double sqrt3() { return 1.732050807568877; } + static constexpr Double sqrtHalf() { return 0.707106781186547; } static constexpr Double nan() { return Double(NAN); } static constexpr Double inf() { return HUGE_VAL; } @@ -158,6 +170,7 @@ template<> struct Constants { static constexpr Float e() { return 2.718281828f; } static constexpr Float sqrt2() { return 1.414213562f; } static constexpr Float sqrt3() { return 1.732050808f; } + static constexpr Float sqrtHalf() { return 0.707106781f; } static constexpr Float nan() { return NAN; } static constexpr Float inf() { return HUGE_VALF; } diff --git a/src/Magnum/Math/Test/ConstantsTest.cpp b/src/Magnum/Math/Test/ConstantsTest.cpp index b2205dbe9..298f1bd60 100644 --- a/src/Magnum/Math/Test/ConstantsTest.cpp +++ b/src/Magnum/Math/Test/ConstantsTest.cpp @@ -51,8 +51,10 @@ template void ConstantsTest::constants() { { constexpr T a = Constants::sqrt2(); constexpr T b = Constants::sqrt3(); + constexpr T c = Constants::sqrtHalf(); CORRADE_COMPARE(Math::pow<2>(a), T(2)); CORRADE_COMPARE(Math::pow<2>(b), T(3)); + CORRADE_COMPARE(Math::pow<2>(c), T(0.5)); } { constexpr T a = Constants::pi(); constexpr T b = Constants::piHalf();