From 33408e5e46a3694d438057229d1f40479f102e93 Mon Sep 17 00:00:00 2001 From: hasufell Date: Tue, 13 May 2014 20:09:32 +0200 Subject: [PATCH] Add is_null_vector() function --- src/vector.c | 21 +++++++++++++++++++++ src/vector.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/vector.c b/src/vector.c index f33f2c8..ba8151a 100644 --- a/src/vector.c +++ b/src/vector.c @@ -184,3 +184,24 @@ bool set_null_vector(vector *a) return true; } + +/** + * Check if vector a is a null vector, + * so all coordinates are 0. + * + * @param a vector + * @return true if vector is a null vector, false + * otherwise, -1 on failure + */ +int is_null_vector(vector *a) +{ + if (!a) + return -1; + + if (a->x == 0 && + a->y == 0 && + a->z == 0) + return true; + else + return false; +} diff --git a/src/vector.h b/src/vector.h index 8ce955c..0fe21bb 100644 --- a/src/vector.h +++ b/src/vector.h @@ -123,6 +123,7 @@ bool sub_vectors(vector *a, vector *b, vector *c); bool normalize_vector(vector *a, vector *b); bool copy_vector(vector *a, vector *b); bool set_null_vector(vector *a); +int is_null_vector(vector *a); #endif /* _DROW_ENGINE_VEC_MATH_H */