SHADE_Y3/SHADE_Managed/src/Math/Math.hxx

111 lines
5.4 KiB
C++

/************************************************************************************//*!
\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
{
/// <summary>
/// Contains utility Math functions.
/// </summary>
public ref class Math abstract sealed
{
public:
/*-----------------------------------------------------------------------------*/
/* Static Constants */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Degrees-to-radians conversion constant
/// </summary>
static constexpr float Deg2Rad = System::Math::PI / 180.0f;
/// <summary>
/// Radians-to-degrees conversion constant
/// </summary>
static constexpr float Rad2Deg = 180.0f / System::Math::PI;
/// <summary>
/// Small value used for single precision floating point comparisons.
/// </summary>
static constexpr float Epsilon = 0.001f;
/*-----------------------------------------------------------------------------*/
/* Utility Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Wraps a value if they get to low or too high.
/// </summary>
/// <param name="value">Value to wrap.</param>
/// <param name="min">Minimum value to wrap at.</param>
/// <param name="max">Maximum value to wrap at.</param>
/// <returns>Wrapped value.</returns>
static float Wrap(float value, float min, float max);
/// <summary>
/// Converts an angle from degree representation to radian representation.
/// </summary>
/// <param name="degrees">Degree-based angle to convert.</param>
/// <returns>The specified angle in radians.</returns>
static float DegreesToRadians(float degrees);
/// <summary>
/// Converts an angle from radian representation to degree representation.
/// </summary>
/// <param name="radians">Radian-based angle to convert.</param>
/// <returns>The specified angle in degrees.</returns>
static float RadiansToDegrees(float radians);
/// <summary>
/// Linearly interpolates between a and b by t.
/// The parameter t is clamped to the range [0, 1].
/// </summary>
/// <param name="a">The start value.</param>
/// <param name="b">The end value.</param>
/// <param name="t">The interpolation value between the two float.</param>
/// <returns>The interpolated float result between the two float values.</returns>
static float Lerp(float a, float b, float t);
/// <summary>
/// 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.
/// </summary>
/// <param name="a">The start value.</param>
/// <param name="b">The end value.</param>
/// <param name="t">The interpolation value between the two float.</param>
/// <returns>The interpolated float result between the two float values.</returns>
static float LerpUnclamped(float a, float b, float t);
/// <summary>
/// Calculates the linear parameter t that produces the interpolant value within
/// the range [a, b].
/// </summary>
/// <param name="a">Start value.</param>
/// <param name="b">End value.</param>
/// <param name="value">Value between start and end.</param>
/// <returns>Percentage of value between start and end.</returns>
static float InverseLerp(float a, float b, float value);
/// <summary>
/// Compares if two float values are close enough to be the same with a tolerance
/// of Epsilon.
/// </summary>
/// <param name="a">One of the values to compare.</param>
/// <param name="b">The other value to compare.</param>
/// <returns>True if a and b are practically the same.</returns>
static bool CompareFloat(float a, float b);
/// <summary>
/// Compares if two float values are close enough to be the same with the
/// specified tolerance value.
/// </summary>
/// <param name="a">One of the values to compare.</param>
/// <param name="b">The other value to compare.</param>
/// <param name="tolerance">Tolerance for floating point comparison.</param>
/// <returns>True if a and b are practically the same.</returns>
static bool CompareFloat(float a, float b, float tolerance);
};
}