summaryrefslogtreecommitdiff
path: root/frontend/shared_cpp/mathlib.h
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-04-01 17:02:44 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-04-01 17:02:44 -0400
commitdbd32f11e2a3df38162c70f946b5bfa9a8dedbfa (patch)
treedf3c1baf5818a641f7c15acbc59d90abcf0360c5 /frontend/shared_cpp/mathlib.h
parentb17c518155fae64083eb5b56b78b9eec57603ac0 (diff)
Lots of work in progress on pill intersections, but will have to read more up on it
Diffstat (limited to 'frontend/shared_cpp/mathlib.h')
-rw-r--r--frontend/shared_cpp/mathlib.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/frontend/shared_cpp/mathlib.h b/frontend/shared_cpp/mathlib.h
index 7595045..2784f6a 100644
--- a/frontend/shared_cpp/mathlib.h
+++ b/frontend/shared_cpp/mathlib.h
@@ -2,6 +2,11 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <cmath>
+
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+#define ABS(x) (x < 0 ? -x : x)
struct Vector2 {
float x = 0;
@@ -11,6 +16,12 @@ struct Vector2 {
return { x + other.x, y + other.y };
}
+ Vector2& operator+=(Vector2 other) {
+ x += other.x;
+ y += other.y;
+ return *this;
+ }
+
Vector2 operator-(Vector2 other) {
return { x - other.x, y - other.y };
}
@@ -19,6 +30,10 @@ struct Vector2 {
return { x * s, y * s };
}
+ Vector2 operator/(float s) {
+ return { x / s, y / s };
+ }
+
float dot(Vector2 other) {
return x * other.x + y * other.y;
}
@@ -45,6 +60,20 @@ struct Vector2 {
void printDebug(const char* name) {
printf("%s=Vector2(%f, %f)\n", name, x, y);
}
+
+ float determinant(Vector2 other) {
+ //
+ // [ a b ]
+ // [ c d ]
+ //
+ // [ x other.x ]
+ // [ y other.y ]
+ //
+ // det = a * d - b * c
+ // det = x * other.y - other.x * y
+ //
+ return x * other.y - other.x * y;
+ }
};
struct Vector3 {