diff options
Diffstat (limited to 'boost/geometry/util/math.hpp')
-rw-r--r-- | boost/geometry/util/math.hpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/boost/geometry/util/math.hpp b/boost/geometry/util/math.hpp index c193c8f3f1..234cfa1ed0 100644 --- a/boost/geometry/util/math.hpp +++ b/boost/geometry/util/math.hpp @@ -32,6 +32,8 @@ #include <boost/type_traits/is_fundamental.hpp> #include <boost/type_traits/is_integral.hpp> +#include <boost/geometry/core/cs.hpp> + #include <boost/geometry/util/select_most_precise.hpp> namespace boost { namespace geometry @@ -601,6 +603,65 @@ inline T r2d() } +#ifndef DOXYGEN_NO_DETAIL +namespace detail { + +template <typename DegreeOrRadian> +struct as_radian +{ + template <typename T> + static inline T apply(T const& value) + { + return value; + } +}; + +template <> +struct as_radian<degree> +{ + template <typename T> + static inline T apply(T const& value) + { + return value * d2r<T>(); + } +}; + +template <typename DegreeOrRadian> +struct from_radian +{ + template <typename T> + static inline T apply(T const& value) + { + return value; + } +}; + +template <> +struct from_radian<degree> +{ + template <typename T> + static inline T apply(T const& value) + { + return value * r2d<T>(); + } +}; + +} // namespace detail +#endif + +template <typename DegreeOrRadian, typename T> +inline T as_radian(T const& value) +{ + return detail::as_radian<DegreeOrRadian>::apply(value); +} + +template <typename DegreeOrRadian, typename T> +inline T from_radian(T const& value) +{ + return detail::from_radian<DegreeOrRadian>::apply(value); +} + + /*! \brief Calculates the haversine of an angle \ingroup utility |