LCOV - code coverage report
Current view: top level - src/AH/Math - Degrees.hpp (source / functions) Hit Total Coverage
Test: b8a30b4b7040ae1abf162fd0a258beaa2de43626 Lines: 7 7 100.0 %
Date: 2024-12-21 21:28:55 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  * @brief   Conversions between radians and degrees.
       4             :  */
       5             : #pragma once
       6             : 
       7             : #include <AH/STL/type_traits>
       8             : #include <AH/Settings/NamespaceSettings.hpp>
       9             : 
      10             : BEGIN_AH_NAMESPACE
      11             : 
      12             : namespace detail {
      13             : constexpr long double pi_inv_l = 0.318309886183790671537767526745028724L;
      14             : constexpr long double pi_l = 3.141592653589793238462643383279502884L;
      15             : } // namespace detail
      16             : 
      17             : /// @addtogroup AH_Math
      18             : /// @{
      19             : 
      20             : /// Convert radians to degrees.
      21             : template <class T>
      22             : constexpr inline
      23             :     typename std::enable_if<std::is_floating_point<T>::value, T>::type
      24           4 :     rad2deg(T r) {
      25           4 :     return r * static_cast<T>(detail::pi_inv_l) * 180;
      26             : }
      27             : /// Convert degrees to radians.
      28             : template <class T>
      29             : constexpr inline
      30             :     typename std::enable_if<std::is_floating_point<T>::value, T>::type
      31      499718 :     deg2rad(T d) {
      32      499718 :     return d * static_cast<T>(detail::pi_l) / 180;
      33             : }
      34             : 
      35             : /// Convert degrees to radians, e.g. 10_deg.
      36           1 : constexpr long double operator"" _deg(long double deg) { return deg2rad(deg); }
      37             : /// Convert degrees to radians, e.g. 10_deg.
      38      499714 : constexpr long double operator"" _deg(unsigned long long deg) {
      39      499714 :     return deg2rad(static_cast<long double>(deg));
      40             : }
      41             : 
      42             : /// @}
      43             : 
      44             : END_AH_NAMESPACE

Generated by: LCOV version 1.15