aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkj_sh6042026-06-05 16:07:29 -0400
committerkj_sh6042026-06-05 16:07:29 -0400
commit608a93f403009f25d3ef9deffbf48253808dbcc2 (patch)
tree628ea954e9b5613fd72ce443eb82670c636aa64a
parent27bf89f9e509690c671bc9c303fdeeace5674c88 (diff)
refactor: src/la.h
-rw-r--r--src/la.h45
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