From 8b78aeb666e1e8d2ddb61abc3c0436c41d496527 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 22 Dec 2011 09:21:54 +0900 Subject: [PATCH] Add component-wise vector and quaternion comparison macros. Also, re-implement VectorCompare and QuatCompare using the new macros. VectorCompCompare and QuatCompCompare take a parameter specifying the comparison operator to use. All component-wise comparisons must be true for the whole comparison to be true. --- include/QF/mathlib.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/QF/mathlib.h b/include/QF/mathlib.h index 676bd4d31..9604da15a 100644 --- a/include/QF/mathlib.h +++ b/include/QF/mathlib.h @@ -101,8 +101,9 @@ extern const vec_t * const quat_origin; (c)[1] = (a)[1] * (b)[1]; \ (c)[2] = (a)[2] * (b)[2]; \ } while (0) -#define VectorCompare(x, y) \ - (((x)[0] == (y)[0]) && ((x)[1] == (y)[1]) && ((x)[2] == (y)[2])) +#define VectorCompCompare(x, op, y) \ + (((x)[0] op (y)[0]) && ((x)[1] op (y)[1]) && ((x)[2] op (y)[2])) +#define VectorCompare(x, y) VectorCompCompare (x, ==, y) #define VectorIsZero(a) (!(a)[0] && !(a)[1] && !(a)[2]) #define VectorZero(a) ((a)[2] = (a)[1] = (a)[0] = 0); @@ -183,9 +184,10 @@ extern const vec_t * const quat_origin; (c)[2] = (a)[2] * (b); \ (c)[3] = (a)[3] * (3); \ } while (0) -#define QuatCompare(x, y) \ - (((x)[0] == (y)[0]) && ((x)[1] == (y)[1]) \ - && ((x)[2] == (y)[2]) && ((x)[3] == (y)[3])) +#define QuatCompCompare(x, op, y) \ + (((x)[0] op (y)[0]) && ((x)[1] op (y)[1]) \ + && ((x)[2] op (y)[2]) && ((x)[3] op (y)[3])) +#define QuatCompare(x, y) QuatCompCompare (x, ==, y) #define QuatIsZero(a) (!(a)[0] && !(a)[1] && !(a)[2] && !(a)[3]) #define QuatZero(a) ((a)[3] = (a)[2] = (a)[1] = (a)[0] = 0);