Math.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * @brief Defines and implements functions to get mathematical helper functions
  3. * @file helper/Math.h
  4. * @author Sven Czarnian <devel@svcz.de>
  5. * @copyright Copyright 2020-2021 Sven Czarnian
  6. * @license This project is published under the GNU General Public License v3 (GPLv3)
  7. */
  8. #pragma once
  9. #define _USE_MATH_DEFINES
  10. #include <math.h>
  11. namespace aman {
  12. /**
  13. * @brief Contains helper functions to get numerical stability in the functions
  14. * @ingroup helper
  15. */
  16. class Math {
  17. public:
  18. Math(const Math& other) = delete;
  19. Math(Math&& other) = delete;
  20. Math& operator=(const Math& other) = delete;
  21. Math& operator=(Math&& other) = delete;
  22. /**
  23. * @brief Compares two floating point numbers if they are almost equal
  24. * @param[in] value0 The first floating point number
  25. * @param[in] value1 The second floating point number
  26. * @param[in] threshold The threshold which defines both numbers as almost equal
  27. * @return True if the difference between value0 and value1 is smaller than the threshold, else false
  28. */
  29. static __inline bool almostEqual(float value0, float value1, float threshold = 1e-4) noexcept {
  30. return std::abs(value0 - value1) <= threshold;
  31. }
  32. /**
  33. * @brief Converts a degree value into a radian value
  34. * @param[in] degree The degree value
  35. * @return The radian value
  36. */
  37. static constexpr __inline float deg2rad(float degree) noexcept {
  38. return degree * static_cast<float>(M_PI) / 180.0f;
  39. }
  40. /**
  41. * @brief Converts a radian value into a degree value
  42. * @param[in] radian The degree value
  43. * @return The degree value
  44. */
  45. static constexpr __inline float rad2deg(float radian) noexcept {
  46. return radian * 180.0f / static_cast<float>(M_PI);
  47. }
  48. };
  49. }