Skip to content

Commit

Permalink
mathlib Limits move radians/degrees to header (#9102)
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed Mar 19, 2018
1 parent cd25083 commit e63f9d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 84 deletions.
1 change: 0 additions & 1 deletion src/lib/mathlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ px4_add_module(
COMPILE_FLAGS
SRCS
math/test/test.cpp
math/Limits.cpp
math/matrix_alg.cpp
math/filter/LowPassFilter2p.cpp
)
74 changes: 0 additions & 74 deletions src/lib/mathlib/math/Limits.cpp

This file was deleted.

22 changes: 13 additions & 9 deletions src/lib/mathlib/math/Limits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,33 @@ namespace math
{

template<typename _Tp>
inline constexpr const _Tp &min(const _Tp &a, const _Tp &b)
constexpr const _Tp &min(const _Tp &a, const _Tp &b)
{
return (a < b) ? a : b;
}

template<typename _Tp>
inline constexpr const _Tp &max(const _Tp &a, const _Tp &b)
constexpr const _Tp &max(const _Tp &a, const _Tp &b)
{
return (a > b) ? a : b;
}

template<typename _Tp>
inline constexpr const _Tp &constrain(const _Tp &val, const _Tp &min_val, const _Tp &max_val)
constexpr const _Tp &constrain(const _Tp &val, const _Tp &min_val, const _Tp &max_val)
{
return (val < min_val) ? min_val : ((val > max_val) ? max_val : val);
}

float __EXPORT radians(float degrees);

double __EXPORT radians(double degrees);

float __EXPORT degrees(float radians);
template<typename T>
constexpr T radians(const T degrees)
{
return degrees * (static_cast<T>(M_PI) / static_cast<T>(180));
}

double __EXPORT degrees(double radians);
template<typename T>
constexpr T degrees(const T radians)
{
return radians * (static_cast<T>(180) / static_cast<T>(M_PI));
}

}

0 comments on commit e63f9d9

Please sign in to comment.