From 53664714b9a693391054d1c0c601b285f2b1a577 Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Thu, 28 May 2026 18:49:05 -0500 Subject: init --- lib/vectorlib.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/vectorlib.c (limited to 'lib/vectorlib.c') 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 +#include + +#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 -- cgit v1.3