Manage our branches explicitly in clamp.

This provides saner behavior when clamping to "nonsense" ranges like [5, 3].
This commit is contained in:
Michael Bayne
2012-04-03 15:30:18 -07:00
parent 45b11b6f7c
commit cb8de43027
2 changed files with 6 additions and 2 deletions
+3 -1
View File
@@ -50,7 +50,9 @@ public class MathUtil
* Clamps a value to the range [lower, upper].
*/
public static double clamp (double v, double lower, double upper) {
return Math.min(Math.max(v, lower), upper);
if (v < lower) return lower;
else if (v > upper) return upper;
else return v;
}
/**
+3 -1
View File
@@ -50,7 +50,9 @@ public class MathUtil
* Clamps a value to the range [lower, upper].
*/
public static float clamp (float v, float lower, float upper) {
return Math.min(Math.max(v, lower), upper);
if (v < lower) return lower;
else if (v > upper) return upper;
else return v;
}
/**