/**************************************************************************************** * \file SHMathHelpers.h * \author Diren D Bharwani, diren.dbharwani, 390002520 * \brief Interface for various mathematical helper functions. * * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or * disclosure of this file or its contents without the prior written consent * of DigiPen Institute of Technology is prohibited. ****************************************************************************************/ #pragma once #include #include #include #include namespace SHADE { /*-----------------------------------------------------------------------------------*/ /* Concepts */ /*-----------------------------------------------------------------------------------*/ template concept IsArithmetic = std::is_arithmetic_v; template concept IsIntegral = std::is_integral_v; template concept IsFloatingPoint = std::is_floating_point_v; /*-----------------------------------------------------------------------------------*/ /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ class SHMath { public: /*---------------------------------------------------------------------------------*/ /* Static Data Members */ /*---------------------------------------------------------------------------------*/ /** Standard Epsilon value for comparing Single-Precision Floating-Point values. */ static constexpr float EPSILON = 0.001f; /** Single-Precision Floating-Point value of infinity */ static constexpr float INF = std::numeric_limits::infinity(); static constexpr float PI = std::numbers::pi_v; static constexpr float HALF_PI = PI * 0.5f; static constexpr float TWO_PI = 2.0f * PI; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ /*---------------------------------------------------------------------------------*/ static void Initialise (); template [[nodiscard]] static constexpr T DegreesToRadians (T angleInDeg); template [[nodiscard]] static constexpr T RadiansToDegrees (T angleInRad); template [[nodiscard]] static T Lerp (T a, T b, T alpha); template [[nodiscard]] static T ClampedLerp (T a, T b, T alpha, T alphaMin, T alphaMax); template [[nodiscard]] static T Wrap (T value, T min, T max); template [[nodiscard]] static T GenerateRandomNumber (T lowerBound = 0, T upperBound = 1); /** * @brief Compares two floating-point values for equality within given tolerances. * @tparam T A floating-point type * @param lhs A floating-point value. * @param rhs A floating-point value. * @param absTolerance The absolute tolerance to compare the values for equality. * @param relTolerance The relative tolerance for comparing large values for equality. * @returns True if the values are equal within the specified tolerances. */ template [[nodiscard]] static bool CompareFloat (T lhs, T rhs, T absTolerance = EPSILON, T relTolerance = EPSILON); private: /*---------------------------------------------------------------------------------*/ /* Static Data Members */ /*---------------------------------------------------------------------------------*/ static std::default_random_engine rng; }; } // namespace SHADE #include "SHMathHelpers.hpp"