From 625fc2c61b6a3631e5bae2c891de725caa84f1cd Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Sat, 2 Mar 2013 11:25:40 +1030 Subject: [PATCH] common: add VecStr convenience function Signed-off-by: Kevin Shanahan --- common/mathlib.c | 17 +++++++++++++++++ include/common/mathlib.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/common/mathlib.c b/common/mathlib.c index a9c25cd4..a4de4d86 100644 --- a/common/mathlib.c +++ b/common/mathlib.c @@ -75,3 +75,20 @@ VectorNormalize(vec3_t v) return (vec_t)length; } + +/* + * VecStr - handy shortcut for printf, not thread safe, obviously + */ +const char * +VecStr(const vec3_t vec) +{ + static char buffers[4][20]; + static int current = 0; + char *buf; + + buf = buffers[current++ & 3]; + snprintf(buf, sizeof(buffers[0]), "%i %i %i", + (int)vec[0], (int)vec[1], (int)vec[2]); + + return buf; +} diff --git a/include/common/mathlib.h b/include/common/mathlib.h index 79c80ee6..f22b53ea 100644 --- a/include/common/mathlib.h +++ b/include/common/mathlib.h @@ -107,4 +107,7 @@ void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross); vec_t VectorNormalize(vec3_t v); double VectorLength(const vec3_t v); +/* Shortcut for output of warnings/errors */ +const char *VecStr(const vec3_t vec); + #endif /* __COMMON_MATHLIB_H__ */