/************************************************************************************//*! \file Math.hxx \author Tng Kah Wei, kahwei.tng, 390009620 \par email: kahwei.tng\@digipen.edu \date Nov 11, 2021 \brief Contains the definition of the managed Math static class. Note: This file is written in C++17/CLI. Copyright (C) 2021 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 namespace SHADE { /// /// Contains utility Math functions. /// public ref class Math abstract sealed { public: /*-----------------------------------------------------------------------------*/ /* Static Constants */ /*-----------------------------------------------------------------------------*/ /// /// Degrees-to-radians conversion constant /// static constexpr float Deg2Rad = System::Math::PI / 180.0f; /// /// Radians-to-degrees conversion constant /// static constexpr float Rad2Deg = 180.0f / System::Math::PI; /// /// Small value used for single precision floating point comparisons. /// static constexpr float Epsilon = 0.001f; /*-----------------------------------------------------------------------------*/ /* Utility Functions */ /*-----------------------------------------------------------------------------*/ /// /// Wraps a value if they get to low or too high. /// /// Value to wrap. /// Minimum value to wrap at. /// Maximum value to wrap at. /// Wrapped value. static float Wrap(float value, float min, float max); /// /// Converts an angle from degree representation to radian representation. /// /// Degree-based angle to convert. /// The specified angle in radians. static float DegreesToRadians(float degrees); /// /// Converts an angle from radian representation to degree representation. /// /// Radian-based angle to convert. /// The specified angle in degrees. static float RadiansToDegrees(float radians); /// /// Linearly interpolates between a and b by t. /// The parameter t is clamped to the range [0, 1]. /// /// The start value. /// The end value. /// The interpolation value between the two float. /// The interpolated float result between the two float values. static float Lerp(float a, float b, float t); /// /// Linearly interpolates between a and b by t. /// The parameter t is not clamped and a value based on a and b is supported. /// If t is less than zero, or greater than one, then LerpUnclamped will result /// in a return value outside the range a to b. /// /// The start value. /// The end value. /// The interpolation value between the two float. /// The interpolated float result between the two float values. static float LerpUnclamped(float a, float b, float t); /// /// Calculates the linear parameter t that produces the interpolant value within /// the range [a, b]. /// /// Start value. /// End value. /// Value between start and end. /// Percentage of value between start and end. static float InverseLerp(float a, float b, float value); /// /// Compares if two float values are close enough to be the same with a tolerance /// of Epsilon. /// /// One of the values to compare. /// The other value to compare. /// True if a and b are practically the same. static bool CompareFloat(float a, float b); /// /// Compares if two float values are close enough to be the same with the /// specified tolerance value. /// /// One of the values to compare. /// The other value to compare. /// Tolerance for floating point comparison. /// True if a and b are practically the same. static bool CompareFloat(float a, float b, float tolerance); }; }