Add more vector operations

This commit is contained in:
Camden Dixie O'Brien
2025-10-14 16:04:14 +01:00
parent c3552ae872
commit 1291ec191f
2 changed files with 12 additions and 0 deletions

10
maths.c
View File

@@ -2,11 +2,21 @@
#include <math.h>
float vec2_len(vec2_t v)
{
return sqrtf(v.x * v.x + v.y * v.y);
}
vec2_t vec2_add(vec2_t v1, vec2_t v2)
{
return (vec2_t) { v1.x + v2.x, v1.y + v2.y };
}
vec2_t vec2_sub(vec2_t v1, vec2_t v2)
{
return (vec2_t) { v1.x - v2.x, v1.y - v2.y };
}
vec2_t vec2_scale(vec2_t v, float s)
{
return (vec2_t) { s * v.x, s * v.y };

View File

@@ -19,7 +19,9 @@ typedef struct {
vec3_t x, y, z;
} mat3_t;
float vec2_len(vec2_t v);
vec2_t vec2_add(vec2_t v1, vec2_t v2);
vec2_t vec2_sub(vec2_t v1, vec2_t v2);
vec2_t vec2_scale(vec2_t v, float s);
vec3_t vec2_extend(vec2_t v);