feat: Build optimizations

This commit is contained in:
2026-04-23 21:37:44 +01:00
parent 6cab255d92
commit 153fb762af
11 changed files with 157 additions and 139 deletions

106
src/dxd_math.cpp Normal file
View 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;
}