Browse Source

Math: added Constants::piQuarter().

pull/194/merge
Vladimír Vondruš 8 years ago
parent
commit
d9936c40fd
  1. 6
      doc/changelog.dox
  2. 17
      src/Magnum/Math/Constants.h
  3. 30
      src/Magnum/Math/Test/ConstantsTest.cpp

6
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

17
src/Magnum/Math/Constants.h

@ -48,22 +48,29 @@ template<class T> 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<Double> {
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<Float> {
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; }

30
src/Magnum/Math/Test/ConstantsTest.cpp

@ -48,19 +48,23 @@ ConstantsTest::ConstantsTest() {
template<class T> void ConstantsTest::constants() {
setTestCaseName(std::is_same<T, Double>::value ? "constants<Double>" : "constants<Float>");
constexpr T a = Constants<T>::sqrt2();
constexpr T b = Constants<T>::sqrt3();
CORRADE_COMPARE(Math::pow<2>(a), T(2));
CORRADE_COMPARE(Math::pow<2>(b), T(3));
constexpr T c = Constants<T>::pi();
constexpr T d = Constants<T>::piHalf();
constexpr T e = Constants<T>::tau();
CORRADE_COMPARE(T(0.5)*c, d);
CORRADE_COMPARE(T(2.0)*c, e);
constexpr T f = Constants<T>::e();
CORRADE_COMPARE(std::log(f), T(1));
{
constexpr T a = Constants<T>::sqrt2();
constexpr T b = Constants<T>::sqrt3();
CORRADE_COMPARE(Math::pow<2>(a), T(2));
CORRADE_COMPARE(Math::pow<2>(b), T(3));
} {
constexpr T a = Constants<T>::pi();
constexpr T b = Constants<T>::piHalf();
constexpr T c = Constants<T>::piQuarter();
constexpr T d = Constants<T>::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<T>::e();
CORRADE_COMPARE(std::log(e), T(1));
}
}
template<class T> void ConstantsTest::specials() {

Loading…
Cancel
Save