summaryrefslogtreecommitdiffstats
path: root/src/util/math.h
diff options
context:
space:
mode:
authorUwe Klotz <uwe_klotz@web.de>2014-11-16 23:54:32 +0100
committerUwe Klotz <uwe_klotz@web.de>2014-11-17 21:35:50 +0100
commit2f90fe17e0fe94a9b7f22b6547969325ad0596d1 (patch)
tree29e2e703e9d33d7add75b98a26eaa47a890b6ddf /src/util/math.h
parent16c0706b06e0a6935dcba853731b903b6042ee1a (diff)
Provide both safe (default) and fast variants of math_clamp()
Diffstat (limited to 'src/util/math.h')
-rw-r--r--src/util/math.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/util/math.h b/src/util/math.h
index d7d8627021..f2c839069c 100644
--- a/src/util/math.h
+++ b/src/util/math.h
@@ -20,14 +20,24 @@ using std::fabs;
#define math_max3(a, b, c) math_max(math_max((a), (b)), (c))
template <typename T>
-inline T math_clamp(T value, T min, T max) {
+inline T math_clamp_fast(T value, T min, T max) {
+ return math_max(min, math_min(max, value));
+}
+
+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 (CmdlineArgs::Instance().getDeveloper() && max < min) {
qWarning() << "PROGRAMMING ERROR: math_clamp called with max < min! "
<< max << " " << min;
}
- return math_max(min, math_min(max, value));
+ return math_clamp_fast(value, min, max);
+}
+
+template <typename T>
+inline T math_clamp(T value, T min, T max) {
+ return math_clamp_safe(value, min, max);
}
// NOTE(rryan): It is an error to call even() on a floating point number. Do not