diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-14 17:16:50 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-14 17:16:50 +0300 |
commit | 3102bf28890c06b03cf7455604ec00fd1e27e89c (patch) | |
tree | 47e0d1c09f146a51fc19e855c1fa2600db369787 /source/blender/blenlib | |
parent | 618bc6c67954f80b3c0c0332f44648b3187c23ca (diff) | |
parent | f6107af4cf4d907495e2e9c18e5866fd1d420650 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_hash.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 20 |
3 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_hash.h b/source/blender/blenlib/BLI_hash.h index e849e5f8f61..8b797820722 100644 --- a/source/blender/blenlib/BLI_hash.h +++ b/source/blender/blenlib/BLI_hash.h @@ -63,4 +63,9 @@ BLI_INLINE unsigned int BLI_hash_int(unsigned int k) return BLI_hash_int_2d(k, 0); } +BLI_INLINE float BLI_hash_int_01(unsigned int k) +{ + return (float)BLI_hash_int(k) * (1.0f/(float)0xFFFFFFFF); +} + #endif // __BLI_HASH_H__ diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 377b9325717..3b24cae018d 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -132,6 +132,10 @@ MINLINE int max_iiii(int a, int b, int c, int d); MINLINE size_t min_zz(size_t a, size_t b); MINLINE size_t max_zz(size_t a, size_t b); +MINLINE int clamp_i(int value, int min, int max); +MINLINE float clamp_f(float value, float min, float max); +MINLINE size_t clamp_z(size_t value, size_t min, size_t max); + MINLINE int compare_ff(float a, float b, const float max_diff); MINLINE int compare_ff_relative(float a, float b, const float max_diff, const int max_ulps); diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 2f5b0f420b1..144198f2c06 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -324,6 +324,26 @@ MINLINE size_t max_zz(size_t a, size_t b) return (b < a) ? a : b; } +MINLINE int clamp_i(int value, int min, int max) +{ + return min_ii(max_ii(value, min), max); +} + +MINLINE float clamp_f(float value, float min, float max) +{ + if (value > max) { + return max; + } else if (value < min) { + return min; + } + return value; +} + +MINLINE size_t clamp_z(size_t value, size_t min, size_t max) +{ + return min_zz(max_zz(value, min), max); +} + /** * Almost-equal for IEEE floats, using absolute difference method. * |