|
@@ -1,4 +1,10 @@
|
|
|
#include "vector.h"
|
|
#include "vector.h"
|
|
|
|
|
+#include <math.h>
|
|
|
|
|
+
|
|
|
|
|
+#undef vector_add
|
|
|
|
|
+#undef vector_sub
|
|
|
|
|
+#undef vector_mul
|
|
|
|
|
+#undef vector_div
|
|
|
|
|
|
|
|
Vector vector_add(Vector a, Vector b) {
|
|
Vector vector_add(Vector a, Vector b) {
|
|
|
return (Vector){.x = a.x + b.x, .y = a.y + b.y};
|
|
return (Vector){.x = a.x + b.x, .y = a.y + b.y};
|
|
@@ -30,4 +36,23 @@ Vector vector_mulf(Vector a, float b) {
|
|
|
|
|
|
|
|
Vector vector_divf(Vector a, float b) {
|
|
Vector vector_divf(Vector a, float b) {
|
|
|
return (Vector){.x = a.x / b, .y = a.y / b};
|
|
return (Vector){.x = a.x / b, .y = a.y / b};
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+float vector_length(Vector v) {
|
|
|
|
|
+ return sqrtf(v.x * v.x + v.y * v.y);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Vector vector_normalize(Vector v) {
|
|
|
|
|
+ float length = vector_length(v);
|
|
|
|
|
+ return (Vector){v.x / length, v.y / length};
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+float vector_dot(Vector a, Vector b) {
|
|
|
|
|
+ return a.x * b.x + a.y * b.y;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Vector vector_rand() {
|
|
|
|
|
+ float x = (rand() % __INT_MAX__) / (float)__INT_MAX__;
|
|
|
|
|
+ float y = (rand() % __INT_MAX__) / (float)__INT_MAX__;
|
|
|
|
|
+ return (Vector){x, y};
|
|
|
}
|
|
}
|