diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-11-04 14:31:42 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-11-04 14:31:42 +0300 |
commit | 988b3d718835c1474353ff3aa04fce5e17ed2f2e (patch) | |
tree | 6cca2c57f52879d6c2aa2d33a72bcfb3ccf6132b | |
parent | 1179ce6f11a6fe4a4b6a32b6ddad50c94cd54a59 (diff) |
Add utility macros to clamp all elements of 2,3,4 component vectors
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 54 |
1 files changed, 54 insertions, 0 deletions
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)) |