diff options
author | Uwe Klotz <uwe_klotz@web.de> | 2014-11-17 11:05:32 +0100 |
---|---|---|
committer | Uwe Klotz <uwe_klotz@web.de> | 2014-11-17 21:35:50 +0100 |
commit | 749374af3851dfd7bbc3ee958e39bba54e9f497e (patch) | |
tree | d658ef218b988fdb3dcb7c581e78312ea26070a3 /src/util/math.h | |
parent | 7b1a419abcb851c0b6ab7a50264242f17003a2ce (diff) |
Improve math_clamp_safe() by not changing the value on invalid bounds
..and reorder parameters in the warning message to reflect their order
in the function definition.
Diffstat (limited to 'src/util/math.h')
-rw-r--r-- | src/util/math.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/util/math.h b/src/util/math.h index d3392dff2e..08846aa854 100644 --- a/src/util/math.h +++ b/src/util/math.h @@ -26,11 +26,16 @@ template <typename T> inline T math_clamp_safe(T value, T min, T max) { // XXX: If max < min, behavior is undefined, and has been causing problems. // if debugging is on, assert when this happens. - if (max < min) { - qWarning() << "PROGRAMMING ERROR: math_clamp called with max < min! " - << max << " " << min; + if (min <= max) { + // valid bounds + return math_clamp_unsafe(value, min, max); + } else { + // invalid bounds + qWarning() << "PROGRAMMING ERROR: math_clamp_safe() called with min > max!" + << min << ">" << max; + // simply return the value unchanged + return value; } - return math_clamp_unsafe(value, min, max); } template <typename T> |