diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-12-08 23:31:53 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-12-08 23:31:53 +0300 |
commit | b09c2c7d0091dad71b8059c20cf4be255c4d7f27 (patch) | |
tree | 64efc7f22e60574fedc1ca050df066c06a607b76 /source/blender/blenlib/intern/math_base_inline.c | |
parent | a382054837bb352543c962358b548825424f2fce (diff) | |
parent | 761111efb8e40fa030cb48761df8c066d0e43ae5 (diff) |
Merge branch 'master' into functions
Diffstat (limited to 'source/blender/blenlib/intern/math_base_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index bcb223046ab..f62edda683d 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -369,6 +369,18 @@ MINLINE int mod_i(int i, int n) return (i % n + n) % n; } +MINLINE float fractf(float a) +{ + return a - floorf(a); +} + +/* Adapted from godotengine math_funcs.h. */ +MINLINE float wrapf(float value, float max, float min) +{ + float range = max - min; + return (range != 0.0f) ? value - (range * floorf((value - min) / range)) : min; +} + MINLINE float min_ff(float a, float b) { return (a < b) ? a : b; @@ -377,6 +389,17 @@ MINLINE float max_ff(float a, float b) { return (a > b) ? a : b; } +/* See: https://www.iquilezles.org/www/articles/smin/smin.htm. */ +MINLINE float smoothminf(float a, float b, float c) +{ + if (c != 0.0f) { + float h = max_ff(c - fabsf(a - b), 0.0f) / c; + return min_ff(a, b) - h * h * h * c * (1.0f / 6.0f); + } + else { + return min_ff(a, b); + } +} MINLINE double min_dd(double a, double b) { @@ -510,6 +533,19 @@ MINLINE float signf(float f) return (f < 0.f) ? -1.f : 1.f; } +MINLINE float compatible_signf(float f) +{ + if (f > 0.0f) { + return 1.0f; + } + if (f < 0.0f) { + return -1.0f; + } + else { + return 0.0f; + } +} + MINLINE int signum_i_ex(float a, float eps) { if (a > eps) { |