54 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * @brief Defines and implements functions to get mathematical helper functions
 | |
|  * @file helper/Math.h
 | |
|  * @author Sven Czarnian <devel@svcz.de>
 | |
|  * @copyright Copyright 2020-2021 Sven Czarnian
 | |
|  * @license This project is published under the GNU General Public License v3 (GPLv3)
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #define _USE_MATH_DEFINES
 | |
| #include <math.h>
 | |
| 
 | |
| namespace aman {
 | |
|     /**
 | |
|      * @brief Contains helper functions to get numerical stability in the functions
 | |
|      * @ingroup helper
 | |
|      */
 | |
|     class Math {
 | |
|     public:
 | |
|         Math(const Math& other) = delete;
 | |
|         Math(Math&& other) = delete;
 | |
|         Math& operator=(const Math& other) = delete;
 | |
|         Math& operator=(Math&& other) = delete;
 | |
| 
 | |
|         /**
 | |
|          * @brief Compares two floating point numbers if they are almost equal
 | |
|          * @param[in] value0 The first floating point number
 | |
|          * @param[in] value1 The second floating point number
 | |
|          * @param[in] threshold The threshold which defines both numbers as almost equal
 | |
|          * @return True if the difference between value0 and value1 is smaller than the threshold, else false
 | |
|          */
 | |
|         static __inline bool almostEqual(float value0, float value1, float threshold = 1e-4) noexcept {
 | |
|             return std::abs(value0 - value1) <= threshold;
 | |
|         }
 | |
|         /**
 | |
|          * @brief Converts a degree value into a radian value
 | |
|          * @param[in] degree The degree value
 | |
|          * @return The radian value
 | |
|          */
 | |
|         static constexpr __inline float deg2rad(float degree) noexcept {
 | |
|             return degree * static_cast<float>(M_PI) / 180.0f;
 | |
|         }
 | |
|         /**
 | |
|          * @brief Converts a radian value into a degree value
 | |
|          * @param[in] radian The degree value
 | |
|          * @return The degree value
 | |
|          */
 | |
|         static constexpr __inline float rad2deg(float radian) noexcept {
 | |
|             return radian * 180.0f / static_cast<float>(M_PI);
 | |
|         }
 | |
|     };
 | |
| }
 |