feat: Build optimizations
This commit is contained in:
106
src/dxd_math.cpp
Normal file
106
src/dxd_math.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "dxd_math.hpp"
|
||||
|
||||
vec2 operator+(vec2 const &v)
|
||||
{
|
||||
return { .x = v.x, .y = v.y };
|
||||
}
|
||||
|
||||
vec2 operator-(vec2 const &v)
|
||||
{
|
||||
return { .x = -v.x, .y = -v.y };
|
||||
}
|
||||
|
||||
vec2 operator+(vec2 const &a, vec2 const &b)
|
||||
{
|
||||
return { .x = a.x + b.x, .y = a.y + b.y };
|
||||
}
|
||||
|
||||
vec2 operator-(vec2 const &a, vec2 const &b)
|
||||
{
|
||||
return { .x = a.x - b.x, .y = a.y - b.y };
|
||||
}
|
||||
|
||||
vec2 operator*(vec2 const &a, float const &b)
|
||||
{
|
||||
return { .x = a.x * b, .y = a.y * b };
|
||||
}
|
||||
|
||||
vec2 operator/(vec2 const &a, float const &b)
|
||||
{
|
||||
return { .x = a.x / b, .y = a.y / b };
|
||||
}
|
||||
|
||||
bool operator<(vec2 const &a, vec2 const &b)
|
||||
{
|
||||
return a.x < b.x && a.y < b.y;
|
||||
}
|
||||
|
||||
bool operator>(vec2 const &a, vec2 const &b)
|
||||
{
|
||||
return a.x > b.x && a.y > b.y;
|
||||
}
|
||||
|
||||
float dot(vec2 const &a, vec2 const &b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y;
|
||||
}
|
||||
|
||||
float norm2(vec2 const &v)
|
||||
{
|
||||
return v.x * v.x + v.y * v.y;
|
||||
}
|
||||
|
||||
float norm(vec2 const &v)
|
||||
{
|
||||
return std::sqrtf(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
vec2 normalize(vec2 const &v)
|
||||
{
|
||||
return v / std::sqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
vec2 min2(vec2 const &a, vec2 const &b)
|
||||
{
|
||||
return {
|
||||
.x = a.x < b.x ? a.x : b.x,
|
||||
.y = a.y < b.y ? a.y : b.y,
|
||||
};
|
||||
}
|
||||
|
||||
vec2 max2(vec2 const &a, vec2 const &b)
|
||||
{
|
||||
return {
|
||||
.x = a.x > b.x ? a.x : b.x,
|
||||
.y = a.y > b.y ? a.y : b.y,
|
||||
};
|
||||
}
|
||||
|
||||
vec2 polar_to_vec2(const float angle, const float len)
|
||||
{
|
||||
return {
|
||||
.x = len * sinf(angle),
|
||||
.y = len * cosf(angle)
|
||||
};
|
||||
}
|
||||
|
||||
float vec2_angle(const vec2 v)
|
||||
{
|
||||
return atan2f(v.x, v.y);
|
||||
}
|
||||
|
||||
float normalize_angle(const float angle)
|
||||
{
|
||||
float a = angle;
|
||||
while (a > 2*M_PIf) a -= 2*M_PIf;
|
||||
while (a < 0) a += 2*M_PIf;
|
||||
return a;
|
||||
}
|
||||
|
||||
float normalize_angle_diff(const float diff)
|
||||
{
|
||||
float d = diff;
|
||||
while (d > M_PIf) d -= 2*M_PIf;
|
||||
while (d < -M_PIf) d += 2*M_PIf;
|
||||
return d;
|
||||
}
|
||||
Reference in New Issue
Block a user