2023-06-17 17:00:55 +00:00
|
|
|
/* date = April 29th 2023 3:06 pm */
|
|
|
|
|
|
|
|
#ifndef VN_MATH_H
|
|
|
|
#define VN_MATH_H
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
|
2023-06-17 21:06:25 +00:00
|
|
|
inline r32 Round(r32 Value)
|
|
|
|
{
|
|
|
|
r32 Result = roundf(Value);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
2023-06-17 17:00:55 +00:00
|
|
|
inline r32 Floor(r32 Value)
|
|
|
|
{
|
|
|
|
r32 Result = floorf(Value);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
2023-06-17 21:06:25 +00:00
|
|
|
inline r32 Ceil(r32 Value)
|
|
|
|
{
|
|
|
|
r32 Result = ceilf(Value);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:12:26 +00:00
|
|
|
inline r32 Log(r32 Value)
|
|
|
|
{
|
|
|
|
r32 Result = logf(Value);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
2023-06-17 17:00:55 +00:00
|
|
|
inline r32 Pow(r32 Base, r32 Exponent)
|
|
|
|
{
|
|
|
|
r32 Result = powf(Base, Exponent);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline r32 AbsoluteValue(r32 Value)
|
|
|
|
{
|
|
|
|
r32 Result = fabsf(Value);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline b32 AreAlmostEqual(r32 A, r32 B)
|
|
|
|
{
|
|
|
|
b32 Result = false;
|
|
|
|
|
|
|
|
r32 Epsilon = 0.001;
|
|
|
|
if(AbsoluteValue(A - B) < Epsilon)
|
|
|
|
{
|
|
|
|
Result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:12:26 +00:00
|
|
|
inline s64 Min(s64 A, s64 B)
|
|
|
|
{
|
|
|
|
s64 Result = Minimum(A, B);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 Max(s64 A, s64 B)
|
|
|
|
{
|
|
|
|
s64 Result = Maximum(A, B);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
2023-06-17 17:00:55 +00:00
|
|
|
inline v2s operator+(v2s A, v2s B)
|
|
|
|
{
|
|
|
|
v2s Result = {A.x + B.x, A.y + B.y};
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v2s operator-(v2s A, v2s B)
|
|
|
|
{
|
|
|
|
v2s Result = {A.x - B.x, A.y - B.y};
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v2s operator+=(v2s &A, v2s B) { return A = A + B; }
|
|
|
|
inline v2s operator-=(v2s &A, v2s B) { return A = A - B; }
|
|
|
|
|
|
|
|
inline v2 operator+(v2 A, v2 B)
|
|
|
|
{
|
|
|
|
v2 Result = {A.x + B.x, A.y + B.y};
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v2 operator-(v2 A, v2 B)
|
|
|
|
{
|
|
|
|
v2 Result = {A.x - B.x, A.y - B.y};
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v2 operator*(v2 A, r32 B)
|
|
|
|
{
|
|
|
|
v2 Result = {A.x*B, A.y*B};
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v2 operator+=(v2 &A, v2 B) { return A = A + B; }
|
|
|
|
inline v2 operator-=(v2 &A, v2 B) { return A = A - B; }
|
|
|
|
|
|
|
|
inline v2 Min(v2 A, v2 B)
|
|
|
|
{
|
|
|
|
v2 Result = V2(Minimum(A.x, B.x), Minimum(A.y, B.y));
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v2 Max(v2 A, v2 B)
|
|
|
|
{
|
|
|
|
v2 Result = V2(Maximum(A.x, B.x), Maximum(A.y, B.y));
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v4 operator+(v4 A, v4 B)
|
|
|
|
{
|
|
|
|
v4 Result = {A.x + B.x, A.y + B.y, A.z + B.z, A.w + B.w};
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v4 operator-(v4 A, v4 B)
|
|
|
|
{
|
|
|
|
v4 Result = {A.x - B.x, A.y - B.y, A.z - B.z, A.w - B.w};
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v4 operator*(v4 A, r32 B)
|
|
|
|
{
|
|
|
|
v4 Result = {A.x*B, A.y*B, A.z*B, A.w*B};
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline v4 operator+=(v4 &A, v4 B) { return A = A + B; }
|
|
|
|
inline v4 operator-=(v4 &A, v4 B) { return A = A - B; }
|
|
|
|
|
|
|
|
inline v4 LinearBlend(v4 A, v4 B, r32 C)
|
|
|
|
{
|
|
|
|
v4 Result = A + (B - A) * C;
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //VN_MATH_H
|