Browse Source

Math: added Constants::tau().

Or two pi, 6.28.
pull/77/head
Vladimír Vondruš 12 years ago
parent
commit
9bb5171365
  1. 12
      src/Magnum/Math/Constants.h
  2. 14
      src/Magnum/Math/Test/ConstantsTest.cpp

12
src/Magnum/Math/Constants.h

@ -46,10 +46,18 @@ template<class T> 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<Double> {
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<Float> {
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; }
};

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

@ -48,14 +48,20 @@ void ConstantsTest::constantsFloat() {
constexpr Float b = Constants<Float>::sqrt3();
CORRADE_COMPARE(Math::pow<2>(a), 2.0f);
CORRADE_COMPARE(Math::pow<2>(b), 3.0f);
constexpr Float c = Constants<Float>::pi();
CORRADE_COMPARE(2.0f*c, Constants<Float>::tau());
}
void ConstantsTest::constantsDouble() {
#ifndef MAGNUM_TARGET_GLES
constexpr Double c = Constants<Double>::sqrt2();
constexpr Double d = Constants<Double>::sqrt3();
CORRADE_COMPARE(Math::pow<2>(c), 2.0);
CORRADE_COMPARE(Math::pow<2>(d), 3.0);
constexpr Double a = Constants<Double>::sqrt2();
constexpr Double b = Constants<Double>::sqrt3();
CORRADE_COMPARE(Math::pow<2>(a), 2.0);
CORRADE_COMPARE(Math::pow<2>(b), 3.0);
constexpr Double c = Constants<Double>::pi();
CORRADE_COMPARE(2.0*c, Constants<Double>::tau());
#else
CORRADE_SKIP("Double precision is not supported when targeting OpenGL ES.");
#endif

Loading…
Cancel
Save