diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index c862290b262..028ca31a059 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -117,6 +117,9 @@ MINLINE float sasqrt(float fac); MINLINE float interpf(float a, float b, float t); MINLINE double interpd(double a, double b, double t); +MINLINE float ratiof(float min, float max, float pos); +MINLINE double ratiod(double min, double max, double pos); + /* NOTE: Compilers will upcast all types smaller than int to int when performing arithmetic * operation. */ MINLINE int square_s(short a); diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 39945960e68..6481fac5a14 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -180,6 +180,18 @@ MINLINE double interpd(double target, double origin, double fac) return (fac * target) + (1.0f - fac) * origin; } +MINLINE float ratiof(float min, float max, float pos) +{ + float range = max - min; + return range == 0 ? 0 : ((pos - min) / range); +} + +MINLINE double ratiod(double min, double max, double pos) +{ + double range = max - min; + return range == 0 ? 0 : ((pos - min) / range); +} + /* used for zoom values*/ MINLINE float power_of_2(float val) { |