Asset Progress
This commit is contained in:
@ -12,110 +12,111 @@
|
||||
|
||||
namespace Dawn {
|
||||
class Math final {
|
||||
/**
|
||||
* Returns the largest of the two provided int32 numbers.
|
||||
*
|
||||
* @param left Left number to get the largest of.
|
||||
* @param right Right number to get the largest of.
|
||||
* @return The larger of the two numbers
|
||||
*/
|
||||
template<typename T>
|
||||
static T max(T left, T right) {
|
||||
return left < right ? right : left;
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* Returns the largest of the two provided int32 numbers.
|
||||
*
|
||||
* @param left Left number to get the largest of.
|
||||
* @param right Right number to get the largest of.
|
||||
* @return The larger of the two numbers
|
||||
*/
|
||||
template<typename T>
|
||||
static T max(T left, T right) {
|
||||
return left < right ? right : left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest of two provided int32 numbers.
|
||||
*
|
||||
* @param left Left number to get the smallest of.
|
||||
* @param right Right number to get the smallest of.
|
||||
* @return Smaller of the two numbers.
|
||||
*/
|
||||
template<typename T>
|
||||
static T min(T left, T right) {
|
||||
return left < right ? left : right;
|
||||
}
|
||||
/**
|
||||
* Returns the smallest of two provided int32 numbers.
|
||||
*
|
||||
* @param left Left number to get the smallest of.
|
||||
* @param right Right number to get the smallest of.
|
||||
* @return Smaller of the two numbers.
|
||||
*/
|
||||
template<typename T>
|
||||
static T min(T left, T right) {
|
||||
return left < right ? left : right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the input value, constrained between the min and max values, so that
|
||||
* the value cannot underceed the min, and cannot exceed the max.
|
||||
*
|
||||
* @param val Value to get the clamp for.
|
||||
* @param min Minimum clamping value.
|
||||
* @param max Maximum clamping value.
|
||||
* @return The value, or the closest clamped value.
|
||||
*/
|
||||
template<typename T>
|
||||
static T clamp(T val, T min, T max) {
|
||||
return mathMin<T>(mathMax<T>(val, min), max);
|
||||
}
|
||||
/**
|
||||
* Returns the input value, constrained between the min and max values, so that
|
||||
* the value cannot underceed the min, and cannot exceed the max.
|
||||
*
|
||||
* @param val Value to get the clamp for.
|
||||
* @param min Minimum clamping value.
|
||||
* @param max Maximum clamping value.
|
||||
* @return The value, or the closest clamped value.
|
||||
*/
|
||||
template<typename T>
|
||||
static T clamp(T val, T min, T max) {
|
||||
return mathMin<T>(mathMax<T>(val, min), max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute value (the non-negative representation of) for the given
|
||||
* int32 number.Abs values will be -value if value < 0.
|
||||
*
|
||||
* @param value Value to get the absolute value for.
|
||||
* @return The absolute value (-value if value < 0)
|
||||
*/
|
||||
template<typename T>
|
||||
static T abs(T value) {
|
||||
return value < 0 ? -value : value;
|
||||
}
|
||||
/**
|
||||
* Returns the absolute value (the non-negative representation of) for the given
|
||||
* int32 number.Abs values will be -value if value < 0.
|
||||
*
|
||||
* @param value Value to get the absolute value for.
|
||||
* @return The absolute value (-value if value < 0)
|
||||
*/
|
||||
template<typename T>
|
||||
static T abs(T value) {
|
||||
return value < 0 ? -value : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the modulous a result for b. Works for floating point numbers.
|
||||
*
|
||||
* @param a Number to modulo against. (a % b)
|
||||
* @param b Number to modulo with. (a % b)
|
||||
* @returns The modulo result.
|
||||
*/
|
||||
template<typename T>
|
||||
static inline T mod(T value, T modulo) {
|
||||
return ((value % modulo) + modulo) % modulo;
|
||||
}
|
||||
/**
|
||||
* Returns the modulous a result for b. Works for floating point numbers.
|
||||
*
|
||||
* @param a Number to modulo against. (a % b)
|
||||
* @param b Number to modulo with. (a % b)
|
||||
* @returns The modulo result.
|
||||
*/
|
||||
template<typename T>
|
||||
static inline T mod(T value, T modulo) {
|
||||
return ((value % modulo) + modulo) % modulo;
|
||||
}
|
||||
|
||||
static inline float_t fmod(float_t value, float_t modulo) {
|
||||
float_t n = fmod(value, modulo);
|
||||
return n;
|
||||
}
|
||||
static inline float_t fmod(float_t value, float_t modulo) {
|
||||
float_t n = fmod(value, modulo);
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert degrees to radians.
|
||||
*
|
||||
* @param n Degrees to convert.
|
||||
* @returns The number in radians.
|
||||
*/
|
||||
static float_t deg2rad(float_t degrees) {
|
||||
return degrees * (MATH_PI / 180.0f);
|
||||
}
|
||||
/**
|
||||
* Convert degrees to radians.
|
||||
*
|
||||
* @param n Degrees to convert.
|
||||
* @returns The number in radians.
|
||||
*/
|
||||
static float_t deg2rad(float_t degrees) {
|
||||
return degrees * (MATH_PI / 180.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert radians to degrees.
|
||||
* @param n Radians to convert.
|
||||
* @returns The number in degrees.
|
||||
*/
|
||||
static float_t rad2deg(float_t n) {
|
||||
return (n * 180.0f) / MATH_PI;
|
||||
}
|
||||
/**
|
||||
* Convert radians to degrees.
|
||||
* @param n Radians to convert.
|
||||
* @returns The number in degrees.
|
||||
*/
|
||||
static float_t rad2deg(float_t n) {
|
||||
return (n * 180.0f) / MATH_PI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Round a number to the nearest whole number.
|
||||
* @param n Number to round.
|
||||
* @return Rounded number.
|
||||
*/
|
||||
template<typename T>
|
||||
static T round(float_t n) {
|
||||
return (T)roundf(n);
|
||||
}
|
||||
/**
|
||||
* Round a number to the nearest whole number.
|
||||
* @param n Number to round.
|
||||
* @return Rounded number.
|
||||
*/
|
||||
template<typename T>
|
||||
static T round(float_t n) {
|
||||
return (T)roundf(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds the number down to the nearest whole number.
|
||||
* @param n Number to round down.
|
||||
* @return Rounded number.
|
||||
*/
|
||||
template<typename T>
|
||||
static T floor(float_t n) {
|
||||
return (T)floorf(n);
|
||||
}
|
||||
/**
|
||||
* Rounds the number down to the nearest whole number.
|
||||
* @param n Number to round down.
|
||||
* @return Rounded number.
|
||||
*/
|
||||
template<typename T>
|
||||
static T floor(float_t n) {
|
||||
return (T)floorf(n);
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user