]> git.lizzy.rs Git - nothing.git/commitdiff
point.h -> vec.h
authorrexim <reximkut@gmail.com>
Sat, 28 Sep 2019 20:24:30 +0000 (03:24 +0700)
committerrexim <reximkut@gmail.com>
Sat, 28 Sep 2019 20:24:30 +0000 (03:24 +0700)
21 files changed:
CMakeLists.txt
src/game/camera.h
src/game/level/labels.h
src/game/level/level_editor/label_layer.c
src/game/level/level_editor/label_layer.h
src/game/level/level_editor/point_layer.h
src/game/level/player.c
src/game/sound_samples.h
src/game/sprite_font.h
src/main.c
src/math/mat3x3.h
src/math/point.h [deleted file]
src/math/rect.h
src/math/triangle.h
src/math/vec.h [new file with mode: 0644]
src/sdl/renderer.h
src/ui/console_log.c
src/ui/console_log.h
src/ui/edit_field.h
src/ui/list_selector.c
src/ui/wiggly_text.c

index 1d1b8961a5f31e22c1e8beb3cd259b6d42b07f57..0fa31b18a7ad7d8d557ff8011051a4001144a6b7 100644 (file)
@@ -132,7 +132,7 @@ add_executable(nothing
   src/math/extrema.h
   src/math/mat3x3.h
   src/math/pi.h
-  src/math/point.h
+  src/math/vec.h
   src/math/rand.c
   src/math/rand.h
   src/math/rect.c
index 208c0903b5205344f0b99d8d1c0d95c0d06fbaef..20e053731059d8c65896348273a70895f3afe4d5 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "color.h"
 #include "game/sprite_font.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "math/rect.h"
 #include "math/triangle.h"
 
index edef35b1ccbe5da218d6f0ae40ade74ce1185a40..b547b89d41fa57571523a54179ee80dc9ae568d5 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef LABELS_H_
 #define LABELS_H_
 
-#include "math/point.h"
+#include "math/vec.h"
 #include "color.h"
 #include "ebisp/expr.h"
 
index ade14530e4cad8cfc916cd8c1a4c21585dc9e0f5..3915544e8d90477542a5bd39499205d5d2a9070d 100644 (file)
@@ -8,7 +8,7 @@
 #include "system/lt.h"
 #include "system/str.h"
 #include "system/log.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "label_layer.h"
 #include "dynarray.h"
 #include "color.h"
index cbb798557af142211f4511454f779b205db32329..62ddd5c371b4f916c77c3a82a3c92ef0a98958e7 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "layer.h"
 #include "color.h"
-#include "math/point.h"
+#include "math/vec.h"
 
 #define LABELS_SIZE vec(2.0f, 2.0f)
 #define LABEL_LAYER_ID_MAX_SIZE 36
index 7c86092ef1aa9e5edaa015e0fb56af50fd084c1c..0369e8bc9a208edc3a162863d86c3ba08d49a99b 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef POINT_LAYER_H_
 #define POINT_LAYER_H_
 
-#include "math/point.h"
+#include "math/vec.h"
 #include "color.h"
 #include "layer.h"
 
index 7aac4052c9bb661e90bd9d6430e76a51a909ed32..6775230d0f2bece3ccabb55c3b79fd13303f86bd 100644 (file)
@@ -7,7 +7,7 @@
 #include "game/level/script.h"
 #include "game/level/rigid_bodies.h"
 #include "goals.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "platforms.h"
 #include "player.h"
 #include "system/line_stream.h"
index b02e6a851e0c30d73cfec7a8126abc5e09c7660b..b46747cc42445c21fc3d54f89fa779d14bcd8dd1 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef SOUND_SAMPLES_H_
 #define SOUND_SAMPLES_H_
 
-#include "math/point.h"
+#include "math/vec.h"
 
 typedef struct Sound_samples Sound_samples;
 
index 468db39ec8dc06d24290499f575ebe63ec6af650..baed3083c03c9acd633794d5adfd9976e084c387 100644 (file)
@@ -2,7 +2,7 @@
 #define SPRITE_FONT_H_
 
 #include "color.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "math/rect.h"
 
 #define FONT_CHAR_WIDTH 7
index 71354bf26657ac0e7fd95069367c818a27e869dd..2a3b0e040260274d49506f0b902b87ba3390e85c 100644 (file)
@@ -12,7 +12,7 @@
 #include "game/sound_samples.h"
 #include "game/sprite_font.h"
 #include "math/extrema.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "sdl/renderer.h"
 #include "system/log.h"
 #include "system/lt.h"
index b1550276489a9a72e27e5cc11c773c4b28be0044..50f99e54fd719a4831d1d7fb65e03d61dbd59035 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MAT3X3_H_
 #define MAT3X3_H_
 
-#include "point.h"
+#include "vec.h"
 
 typedef struct mat3x3 {
     float M[3][3];
diff --git a/src/math/point.h b/src/math/point.h
deleted file mode 100644 (file)
index 6543eb0..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-#ifndef POINT_H_
-#define POINT_H_
-
-#include "math/pi.h"
-
-typedef struct Point {
-    float x, y;
-} Point;
-
-typedef Point Vec;
-
-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_
index fc4cd98cc9b1f5996de8bd6acc8c61a81dc6ae47..e8a8353807daffaf7c85923efa2dc17cb539e62f 100644 (file)
@@ -4,7 +4,7 @@
 #include <SDL.h>
 #include <math.h>
 
-#include "math/point.h"
+#include "math/vec.h"
 
 typedef enum Rect_side {
     RECT_SIDE_LEFT = 0,
index a035432a7b0aa81d56d5b59fcef61ca2afa47907..cdd0340290d327556d23c636470f44af087cb0fe 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef TRIANGLE_H_
 #define TRIANGLE_H_
 
-#include "math/point.h"
+#include "math/vec.h"
 #include "math/rect.h"
 
 typedef struct Triangle {
diff --git a/src/math/vec.h b/src/math/vec.h
new file mode 100644 (file)
index 0000000..6543eb0
--- /dev/null
@@ -0,0 +1,157 @@
+#ifndef POINT_H_
+#define POINT_H_
+
+#include "math/pi.h"
+
+typedef struct Point {
+    float x, y;
+} Point;
+
+typedef Point Vec;
+
+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_
index 6d4a0ee261772a5d16324555dd88657bcfa42bbe..ebd471f7989f3a6b9ec4c2224d2e023243b0fad3 100644 (file)
@@ -4,7 +4,7 @@
 #include <SDL.h>
 
 #include "color.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "math/triangle.h"
 
 // TODO(#474): there are no logging SDL wrappers (similar to system/nth_alloc)
index 6038919fc5232b09c5d28b77709e860306bc7db9..94fff202dd28ae56ddbd5fb55a11ef26a19f4830 100644 (file)
@@ -5,7 +5,7 @@
 #include "color.h"
 #include "game/sprite_font.h"
 #include "console_log.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "system/str.h"
 #include "system/lt.h"
 #include "system/nth_alloc.h"
index e733a0b056c002aff0055358e642b9bd8ea2fc43..a47c3187fb8ed7c0b963f92b25b903a91cd9a015 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef CONSOLE_LOG_H_
 #define CONSOLE_LOG_H_
 
-#include "math/point.h"
+#include "math/vec.h"
 #include "game/camera.h"
 
 typedef struct Console_Log Console_Log;
index ed7398c4d22b7e7e91541502d540d8501ac9c56a..9feffee626bb1c9eab15ce3664d130580d5002f0 100644 (file)
@@ -4,7 +4,7 @@
 #include <SDL.h>
 
 #include "color.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "game/camera.h"
 
 typedef struct Edit_field Edit_field;
index 97cb30b16bb88bf774ac96731175eaa9bcaef03a..75065b560a0d6bf32c8c72db373883e068cb6a48 100644 (file)
@@ -6,7 +6,7 @@
 #include "system/lt.h"
 #include "system/nth_alloc.h"
 #include "system/str.h"
-#include "math/point.h"
+#include "math/vec.h"
 #include "game/sprite_font.h"
 #include "system/log.h"
 
index 39d2d407d7f15dc39baa251fb9a0d0d4cf0f4cb9..fcffe6842dca15c4cd338c033bdca91f1dcf8127 100644 (file)
@@ -1,6 +1,6 @@
 #include <SDL.h>
 
-#include "math/point.h"
+#include "math/vec.h"
 
 #include "./wiggly_text.h"
 #include "system/lt.h"