diff --git a/maths.c b/maths.c index 37567eb..65ad19c 100644 --- a/maths.c +++ b/maths.c @@ -2,11 +2,21 @@ #include +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 }; diff --git a/maths.h b/maths.h index 5b720b0..34452c7 100644 --- a/maths.h +++ b/maths.h @@ -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);