SG 1 год назад
Родитель
Сommit
7876baf1ce
2 измененных файлов с 57 добавлено и 0 удалено
  1. 33 0
      vector.c
  2. 24 0
      vector.h

+ 33 - 0
vector.c

@@ -0,0 +1,33 @@
+#include "vector.h"
+
+Vector vector_add(Vector a, Vector b) {
+    return (Vector){.x = a.x + b.x, .y = a.y + b.y};
+}
+
+Vector vector_sub(Vector a, Vector b) {
+    return (Vector){.x = a.x - b.x, .y = a.y - b.y};
+}
+
+Vector vector_mul(Vector a, Vector b) {
+    return (Vector){.x = a.x * b.x, .y = a.y * b.y};
+}
+
+Vector vector_div(Vector a, Vector b) {
+    return (Vector){.x = a.x / b.x, .y = a.y / b.y};
+}
+
+Vector vector_addf(Vector a, float b) {
+    return (Vector){.x = a.x + b, .y = a.y + b};
+}
+
+Vector vector_subf(Vector a, float b) {
+    return (Vector){.x = a.x - b, .y = a.y - b};
+}
+
+Vector vector_mulf(Vector a, float b) {
+    return (Vector){.x = a.x * b, .y = a.y * b};
+}
+
+Vector vector_divf(Vector a, float b) {
+    return (Vector){.x = a.x / b, .y = a.y / b};
+}

+ 24 - 0
vector.h

@@ -0,0 +1,24 @@
+#pragma once
+
+typedef struct {
+    float x;
+    float y;
+} Vector;
+
+#define VECTOR_ZERO ((Vector){0, 0})
+
+Vector vector_add(Vector a, Vector b);
+
+Vector vector_sub(Vector a, Vector b);
+
+Vector vector_mul(Vector a, Vector b);
+
+Vector vector_div(Vector a, Vector b);
+
+Vector vector_addf(Vector a, float b);
+
+Vector vector_subf(Vector a, float b);
+
+Vector vector_mulf(Vector a, float b);
+
+Vector vector_divf(Vector a, float b);