From 26ba13532a59a6d450113eabe66fafa39c9df6ea Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Wed, 1 Apr 2020 11:59:42 +0200 Subject: [PATCH] Adding helper functions for maths with vectors --- include/utility.h | 2 +- include/vector2.h | 3 ++- src/utility/vector2.c | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/utility.h b/include/utility.h index c179617..80684a8 100644 --- a/include/utility.h +++ b/include/utility.h @@ -33,7 +33,7 @@ void *my_realloc(void *oldptr, size_t oldsize, size_t newsize); #define NCLAMP(x, y) (((x) < (y)) ? ((x) = (y)) : (x)) #define ABSCLAMP(x, y) (((x) > 0) ? CLAMP((x), (y)) : NCLAMP((x), -(y))) -#define GETSIGN(x) (((x) < 0) ? (-1) : (1)) +#define SIGN(x) (((x) < 0) ? (-1) : ((x == 0 ? 0 : 1))) #define SET_SIGN(x, s) (x = (x) * (s) > 0 ? (x) : ((x) * (-1))) #define ABS(x) ((x) > 0 ? (x) : -(x)) \ No newline at end of file diff --git a/include/vector2.h b/include/vector2.h index 16b5fc7..8cfc4ac 100644 --- a/include/vector2.h +++ b/include/vector2.h @@ -35,4 +35,5 @@ float gcvector_magnitude(gc_vector2 vec); gc_vector2 gcvector2_normilize(gc_vector2 vec); gc_vector2 gc_vector2_from_sf(sfVector2f sf_vector); -gc_vector2 gc_vector2_add(gc_vector2 first, gc_vector2 second); \ No newline at end of file +gc_vector2 gc_vector2_add(gc_vector2 first, gc_vector2 second); +gc_vector2i gc_vector2i_add(gc_vector2i first, gc_vector2i second); \ No newline at end of file diff --git a/src/utility/vector2.c b/src/utility/vector2.c index e37d108..8d146a6 100644 --- a/src/utility/vector2.c +++ b/src/utility/vector2.c @@ -29,6 +29,11 @@ gc_vector2 gc_vector2_add(gc_vector2 first, gc_vector2 second) return ((gc_vector2){first.x + second.x, first.y + second.y}); } +gc_vector2i gc_vector2i_add(gc_vector2i first, gc_vector2i second) +{ + return ((gc_vector2i){first.x + second.x, first.y + second.y}); +} + gc_vector2 gc_vector2_from_sf(sfVector2f sf_vector) { return (gc_vector2){sf_vector.x, sf_vector.y};