]> git.lizzy.rs Git - nothing.git/blobdiff - src/math/point.c
Merge pull request #924 from RIscRIpt/manual_sdl2
[nothing.git] / src / math / point.c
index 0139d09b0296f709d958d2e403ac670cb6be9c5c..dbdfc54537c8a0d28e08e6025333f941a25ff441 100644 (file)
@@ -1,4 +1,4 @@
-#include <assert.h>
+#include "system/stacktrace.h"
 #include <math.h>
 
 #include "point.h"
@@ -47,6 +47,15 @@ Vec vec_sum(Vec v1, Vec v2)
     return result;
 }
 
+Vec vec_sub(Vec v1, Vec v2)
+{
+    Vec result = {
+        .x = v1.x - v2.x,
+        .y = v1.y - v2.y
+    };
+    return result;
+}
+
 Vec vec_neg(Vec v)
 {
     Vec result = {
@@ -125,6 +134,9 @@ Point point_mat3x3_product(Point p, mat3x3 m)
 
 Vec vec_norm(Vec v)
 {
+    // TODO(#657): math/point/vec_norm: using vec_length is too expensive
+    //   It involves multiplication and sqrt. We can just check if its components are close to 0.0f.
+
     const float l = vec_length(v);
 
     if (l < 1e-6) {
@@ -133,3 +145,8 @@ Vec vec_norm(Vec v)
 
     return vec(v.x / l, v.y / l);
 }
+
+float vec_sqr_norm(Vec v)
+{
+    return v.x * v.x + v.y * v.y;
+}