diff options
Diffstat (limited to 'src/la.h')
| -rw-r--r-- | src/la.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/la.h b/src/la.h new file mode 100644 index 0000000..af8a293 --- /dev/null +++ b/src/la.h @@ -0,0 +1,45 @@ +#ifndef LA_H +#define LA_H + +#include <math.h> + +typedef struct { + float x, y; +} Vec2f; + +Vec2f vec2(float x, float y); +Vec2f vec2_add(Vec2f a, Vec2f b); +Vec2f vec2_sub(Vec2f a, Vec2f b); +Vec2f vec2_mul(Vec2f a, float s); +Vec2f vec2_div(Vec2f a, float s); +float vec2_length(Vec2f a); + +#ifdef LA_IMPL + +Vec2f vec2(float x, float y) { + return (Vec2f){x, y}; +} + +Vec2f vec2_add(Vec2f a, Vec2f b) { + return vec2(a.x + b.x, a.y + b.y); +} + +Vec2f vec2_sub(Vec2f a, Vec2f b) { + return vec2(a.x - b.x, a.y - b.y); +} + +Vec2f vec2_mul(Vec2f a, float s) { + return vec2(a.x * s, a.y * s); +} + +Vec2f vec2_div(Vec2f a, float s) { + return vec2(a.x / s, a.y / s); +} + +float vec2_length(Vec2f a) { + return sqrtf(a.x * a.x + a.y * a.y); +} + +#endif // LA_IMPL + +#endif // LA_H |
