From 988b3d718835c1474353ff3aa04fce5e17ed2f2e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 4 Nov 2014 16:31:42 +0500 Subject: Add utility macros to clamp all elements of 2,3,4 component vectors --- source/blender/blenlib/BLI_utildefines.h | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'source/blender') diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 736578361b3..f318ae0e39f 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -335,6 +335,60 @@ if ((a) < (b)) (a) = (b); \ } (void)0 +#define CLAMP2(vec, b, c) { \ + CLAMP((vec)[0], b, c); \ + CLAMP((vec)[1], b, c); \ +} (void)0 + +#define CLAMP2_MIN(vec, b) { \ + CLAMP_MIN((vec)[0], b); \ + CLAMP_MIN((vec)[1], b); \ +} (void)0 + +#define CLAMP2_MAX(vec, b) { \ + CLAMP_MAX((vec)[0], b); \ + CLAMP_MAX((vec)[1], b); \ +} (void)0 + +#define CLAMP3(vec, b, c) { \ + CLAMP((vec)[0], b, c); \ + CLAMP((vec)[1], b, c); \ + CLAMP((vec)[2], b, c); \ +} (void)0 + +#define CLAMP3_MIN(vec, b) { \ + CLAMP_MIN((vec)[0], b); \ + CLAMP_MIN((vec)[1], b); \ + CLAMP_MIN((vec)[2], b); \ +} (void)0 + +#define CLAMP3_MAX(vec, b) { \ + CLAMP_MAX((vec)[0], b); \ + CLAMP_MAX((vec)[1], b); \ + CLAMP_MAX((vec)[2], b); \ +} (void)0 + +#define CLAMP4(vec, b, c) { \ + CLAMP((vec)[0], b, c); \ + CLAMP((vec)[1], b, c); \ + CLAMP((vec)[2], b, c); \ + CLAMP((vec)[3], b, c); \ +} (void)0 + +#define CLAMP4_MIN(vec, b) { \ + CLAMP_MIN((vec)[0], b); \ + CLAMP_MIN((vec)[1], b); \ + CLAMP_MIN((vec)[2], b); \ + CLAMP_MIN((vec)[3], b); \ +} (void)0 + +#define CLAMP4_MAX(vec, b) { \ + CLAMP_MAX((vec)[0], b); \ + CLAMP_MAX((vec)[1], b); \ + CLAMP_MAX((vec)[2], b); \ + CLAMP_MAX((vec)[3], b); \ +} (void)0 + #define IS_EQ(a, b) ( \ CHECK_TYPE_INLINE(a, double), CHECK_TYPE_INLINE(b, double), \ ((fabs((double)((a) - (b))) >= (double) FLT_EPSILON) ? false : true)) -- cgit v1.2.3