aboutsummaryrefslogtreecommitdiff
path: root/lib/vectorlib.c
diff options
context:
space:
mode:
authoriceyrazor <iceyrazor@mailfence.com>2026-05-28 18:49:05 -0500
committericeyrazor <iceyrazor@mailfence.com>2026-05-28 18:49:05 -0500
commit53664714b9a693391054d1c0c601b285f2b1a577 (patch)
tree0a9f9e6d6dcf61f9f8d13f1e8c45e8ab6b361a9c /lib/vectorlib.c
init
Diffstat (limited to 'lib/vectorlib.c')
-rw-r--r--lib/vectorlib.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/vectorlib.c b/lib/vectorlib.c
new file mode 100644
index 0000000..c059742
--- /dev/null
+++ b/lib/vectorlib.c
@@ -0,0 +1,72 @@
+#ifndef vector_lib
+#define vector_lib
+
+#include <math.h>
+#include <stdlib.h>
+
+#define flaot float
+
+typedef struct {
+ float x;
+ float y;
+} Point;
+
+void point_add(Point *A, Point *B){
+ A->x = A->x + B->x;
+ A->y = A->y + B->y;
+}
+
+void point_sub(Point *A, Point *B){
+ A->x = A->x - B->x;
+ A->y = A->y - B->y;
+}
+
+void point_mul(Point *A, Point *B){
+ A->x = A->x * B->x;
+ A->y = A->y * B->y;
+}
+
+void point_div(Point *A, Point *B){
+ A->x = A->x / B->x;
+ A->y = A->y / B->y;
+}
+
+float magnitude(flaot x, flaot y) {
+ return sqrt((pow(x,2) + pow(y,2)));
+}
+
+void point_set_mag(Point *point, float mag){
+ flaot getmag = magnitude(point->x, point->y);
+ flaot rx = (point->x / getmag) * mag;
+ flaot ry = (point->y / getmag) * mag;
+
+ point->x = rx;
+ point->y = ry;
+}
+
+void point_limit(Point *point, float mag){
+ flaot getmag = magnitude(point->x, point->y);
+ flaot rx, ry;
+ if (getmag > mag){
+ rx = (point->x / getmag) * mag;
+ ry = (point->y / getmag) * mag;
+ } else {
+ rx = point->x;
+ ry = point->y;
+ }
+
+ point->x = rx;
+ point->y = ry;
+}
+
+float RandomFloat(float min, float max){
+ return ((max - min) * ((float)rand() / (double)RAND_MAX)) + min;
+}
+
+float constrain(float val, float min, float max){
+ if(val > max) val=max;
+ else if(val < min) val=min;
+ return val;
+}
+
+#endif \ No newline at end of file