diff options
author | Tiago Chaves <laurelkeys> | 2020-03-04 02:24:21 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-03-04 02:25:44 +0300 |
commit | 14c9f64def7439aa4b6b74d57ba9bc2b82177dd6 (patch) | |
tree | b96f188350ad886c61cd3ea6bfa4a0ba5161c387 /source/blender/blenlib/intern/math_vector.c | |
parent | 31aefdeec5a6e098acabee80517aa6ca03933808 (diff) |
BLI_math: add clamp_v# and clamp_v#_v#v# utility functions
Diffstat (limited to 'source/blender/blenlib/intern/math_vector.c')
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 5919b7e1dd6..d1b36884038 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -1051,6 +1051,48 @@ void axis_sort_v3(const float axis_values[3], int r_axis_order[3]) #undef SWAP_AXIS } +void clamp_v2(float vec[2], const float min, const float max) +{ + CLAMP(vec[0], min, max); + CLAMP(vec[1], min, max); +} + +void clamp_v3(float vec[3], const float min, const float max) +{ + CLAMP(vec[0], min, max); + CLAMP(vec[1], min, max); + CLAMP(vec[2], min, max); +} + +void clamp_v4(float vec[4], const float min, const float max) +{ + CLAMP(vec[0], min, max); + CLAMP(vec[1], min, max); + CLAMP(vec[2], min, max); + CLAMP(vec[3], min, max); +} + +void clamp_v2_v2v2(float vec[2], const float min[2], const float max[2]) +{ + CLAMP(vec[0], min[0], max[0]); + CLAMP(vec[1], min[1], max[1]); +} + +void clamp_v3_v3v3(float vec[3], const float min[3], const float max[3]) +{ + CLAMP(vec[0], min[0], max[0]); + CLAMP(vec[1], min[1], max[1]); + CLAMP(vec[2], min[2], max[2]); +} + +void clamp_v4_v4v4(float vec[4], const float min[4], const float max[4]) +{ + CLAMP(vec[0], min[0], max[0]); + CLAMP(vec[1], min[1], max[1]); + CLAMP(vec[2], min[2], max[2]); + CLAMP(vec[3], min[3], max[3]); +} + /***************************** Array Functions *******************************/ MINLINE double sqr_db(double f) |