]> git.lizzy.rs Git - nothing.git/commitdiff
Get rid of point.c
authorrexim <reximkut@gmail.com>
Sat, 28 Sep 2019 20:22:25 +0000 (03:22 +0700)
committerrexim <reximkut@gmail.com>
Sat, 28 Sep 2019 20:22:25 +0000 (03:22 +0700)
CMakeLists.txt
src/math/point.c [deleted file]
src/math/point.h

index 4c1182cf9498717350b1c3587f679af154f6413d..1d1b8961a5f31e22c1e8beb3cd259b6d42b07f57 100644 (file)
@@ -132,7 +132,6 @@ add_executable(nothing
   src/math/extrema.h
   src/math/mat3x3.h
   src/math/pi.h
-  src/math/point.c
   src/math/point.h
   src/math/rand.c
   src/math/rand.h
diff --git a/src/math/point.c b/src/math/point.c
deleted file mode 100644 (file)
index e63d5a4..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-#include "system/stacktrace.h"
-#include <math.h>
-
-#include "point.h"
-
-Vec vec(float x, float y)
-{
-    Vec result = {
-        .x = x,
-        .y = y
-    };
-    return result;
-}
-
-Vec vec_from_polar(float arg, float mag)
-{
-    return vec_scala_mult(
-        vec(cosf(arg), sinf(arg)),
-        mag);
-}
-
-Vec vec_from_ps(Point p1, Point p2)
-{
-    Vec result = {
-        .x = p2.x - p1.x,
-        .y = p2.y - p1.y
-    };
-    return result;
-}
-
-float vec_arg(Vec v)
-{
-    return atan2f(v.y, v.x);
-}
-
-float vec_mag(Vec v)
-{
-    return sqrtf(v.x * v.x + v.y * v.y);
-}
-
-Vec vec_sum(Vec v1, Vec v2)
-{
-    Vec result = {
-        .x = v1.x + v2.x,
-        .y = v1.y + v2.y
-    };
-    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 = {
-        .x = -v.x,
-        .y = -v.y
-    };
-
-    return result;
-}
-
-float vec_length(Vec v)
-{
-    return sqrtf(v.x * v.x + v.y * v.y);
-}
-
-void vec_add(Vec *v1, Vec v2)
-{
-    v1->x += v2.x;
-    v1->y += v2.y;
-}
-
-Vec vec_scala_mult(Vec v, float scalar)
-{
-    Vec result = {
-        .x = v.x * scalar,
-        .y = v.y * scalar
-    };
-    return result;
-}
-
-Vec vec_entry_mult(Vec v1, Vec v2)
-{
-    Vec result = {
-        .x = v1.x * v2.x,
-        .y = v1.y * v2.y
-    };
-
-    return result;
-}
-
-Vec vec_entry_div(Vec v1, Vec v2)
-{
-    Vec result = {
-        .x = v1.x / v2.x,
-        .y = v1.y / v2.y
-    };
-
-    return result;
-}
-
-float rad_to_deg(float a)
-{
-    return 180 / PI * a;
-}
-
-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) {
-        return vec(0.0f, 0.0f);
-    }
-
-    return vec(v.x / l, v.y / l);
-}
-
-float vec_sqr_norm(Vec v)
-{
-    return v.x * v.x + v.y * v.y;
-}
index fc055be39dabceaf7f275bddb92edc241dc28201..6543eb0d0994cf469ed087125d37ae16fb1747b7 100644 (file)
@@ -9,27 +9,149 @@ typedef struct Point {
 
 typedef Point Vec;
 
-Vec vec(float x, float y);
-Vec vec_from_polar(float arg, float mag);
-Vec vec_from_ps(Point p1, Point p2);
-
-float vec_arg(Vec v);
-float vec_mag(Vec v);
-
-float rad_to_deg(float a);
-
-Vec vec_sum(Vec v1, Vec v2);
-Vec vec_sub(Vec v1, Vec v2);
-Vec vec_neg(Vec v);
-void vec_add(Vec *v1, Vec v2);
-float vec_length(Vec v);
-float vec_sqr_norm(Vec v);
-Vec vec_scala_mult(Vec v, float scalar);
-#define vec_scale vec_scala_mult
-Vec vec_entry_mult(Vec v1, Vec v2);
-Vec vec_entry_div(Vec v1, Vec v2);
-Vec vec_norm(Vec v);
+static inline
+Vec vec(float x, float y)
+{
+    Vec result = {
+        .x = x,
+        .y = y
+    };
+    return result;
+}
+
+static inline
+Vec vec_scala_mult(Vec v, float scalar)
+{
+    Vec result = {
+        .x = v.x * scalar,
+        .y = v.y * scalar
+    };
+    return result;
+}
+
+static inline
+Vec vec_from_polar(float arg, float mag)
+{
+    return vec_scala_mult(
+        vec(cosf(arg), sinf(arg)),
+        mag);
+}
+
+static inline
+Vec vec_from_ps(Point p1, Point p2)
+{
+    Vec result = {
+        .x = p2.x - p1.x,
+        .y = p2.y - p1.y
+    };
+    return result;
+}
+
+static inline
+float vec_arg(Vec v)
+{
+    return atan2f(v.y, v.x);
+}
+
+static inline
+float vec_mag(Vec v)
+{
+    return sqrtf(v.x * v.x + v.y * v.y);
+}
+
+static inline
+Vec vec_sum(Vec v1, Vec v2)
+{
+    Vec result = {
+        .x = v1.x + v2.x,
+        .y = v1.y + v2.y
+    };
+    return result;
+}
+
+static inline
+Vec vec_sub(Vec v1, Vec v2)
+{
+    Vec result = {
+        .x = v1.x - v2.x,
+        .y = v1.y - v2.y
+    };
+    return result;
+}
+
+static inline
+Vec vec_neg(Vec v)
+{
+    Vec result = {
+        .x = -v.x,
+        .y = -v.y
+    };
+
+    return result;
+}
+
+static inline
+float vec_length(Vec v)
+{
+    return sqrtf(v.x * v.x + v.y * v.y);
+}
 
+static inline
+void vec_add(Vec *v1, Vec v2)
+{
+    v1->x += v2.x;
+    v1->y += v2.y;
+}
 
+static inline
+Vec vec_entry_mult(Vec v1, Vec v2)
+{
+    Vec result = {
+        .x = v1.x * v2.x,
+        .y = v1.y * v2.y
+    };
+
+    return result;
+}
+
+static inline
+Vec vec_entry_div(Vec v1, Vec v2)
+{
+    Vec result = {
+        .x = v1.x / v2.x,
+        .y = v1.y / v2.y
+    };
+
+    return result;
+}
+
+static inline
+float rad_to_deg(float a)
+{
+    return 180 / PI * a;
+}
+
+static inline
+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) {
+        return vec(0.0f, 0.0f);
+    }
+
+    return vec(v.x / l, v.y / l);
+}
+
+static inline
+float vec_sqr_norm(Vec v)
+{
+    return v.x * v.x + v.y * v.y;
+}
+
+#define vec_scale vec_scala_mult
 
 #endif  // POINT_H_