Browse Source

Math: added sin(), cos() and tan() accepting either Rad or Deg.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
c0a5e5dadd
  1. 16
      src/Math/Functions.h
  2. 17
      src/Math/Test/FunctionsTest.cpp

16
src/Math/Functions.h

@ -71,6 +71,22 @@ std::uint32_t MAGNUM_EXPORT log2(std::uint32_t number);
*/
std::uint32_t MAGNUM_EXPORT log(std::uint32_t base, std::uint32_t number);
/** @brief Sine */
template<class T> inline T sin(Rad<T> angle) { return std::sin(T(angle)); }
/** @brief Cosine */
template<class T> inline T cos(Rad<T> angle) { return std::cos(T(angle)); }
/** @brief Tangent */
template<class T> inline T tan(Rad<T> angle) { return std::tan(T(angle)); }
/** @todo Can't trigonometric functions be done with only one overload? */
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> inline T sin(Deg<T> angle) { return sin(Rad<T>(angle)); }
template<class T> inline T cos(Deg<T> angle) { return cos(Rad<T>(angle)); }
template<class T> inline T tan(Deg<T> angle) { return tan(Rad<T>(angle)); }
#endif
/**
@{ @name Scalar/vector functions

17
src/Math/Test/FunctionsTest.cpp

@ -40,8 +40,12 @@ class FunctionsTest: public Corrade::TestSuite::Tester {
void pow();
void log();
void log2();
void trigonometric();
};
typedef Math::Constants<float> Constants;
typedef Math::Deg<float> Deg;
typedef Math::Rad<float> Rad;
typedef Math::Vector3<float> Vector3;
typedef Math::Vector3<std::uint8_t> Vector3ub;
typedef Math::Vector3<std::int8_t> Vector3b;
@ -60,9 +64,11 @@ FunctionsTest::FunctionsTest() {
&FunctionsTest::denormalizeSigned,
&FunctionsTest::renormalizeUnsinged,
&FunctionsTest::renormalizeSinged,
&FunctionsTest::pow,
&FunctionsTest::log,
&FunctionsTest::log2);
&FunctionsTest::log2,
&FunctionsTest::trigonometric);
}
void FunctionsTest::min() {
@ -242,6 +248,15 @@ void FunctionsTest::log2() {
CORRADE_COMPARE(Math::log2(2153), 11);
}
void FunctionsTest::trigonometric() {
CORRADE_COMPARE(Math::sin(Deg(30.0f)), 0.5f);
CORRADE_COMPARE(Math::sin(Rad(Constants::pi()/6)), 0.5f);
CORRADE_COMPARE(Math::cos(Deg(60.0f)), 0.5f);
CORRADE_COMPARE(Math::cos(Rad(Constants::pi()/3)), 0.5f);
CORRADE_COMPARE(Math::tan(Deg(45.0f)), 1.0f);
CORRADE_COMPARE(Math::tan(Rad(Constants::pi()/4)), 1.0f);
}
}}}
CORRADE_TEST_MAIN(Magnum::Math::Test::FunctionsTest)

Loading…
Cancel
Save