From 608a93f403009f25d3ef9deffbf48253808dbcc2 Mon Sep 17 00:00:00 2001 From: kj_sh604 Date: Fri, 5 Jun 2026 16:07:29 -0400 Subject: refactor: src/la.h --- src/la.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/la.h 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 + +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 -- cgit v1.2.3