Manage our branches explicitly in clamp.
This provides saner behavior when clamping to "nonsense" ranges like [5, 3].
This commit is contained in:
@@ -50,7 +50,9 @@ public class MathUtil
|
|||||||
* Clamps a value to the range [lower, upper].
|
* Clamps a value to the range [lower, upper].
|
||||||
*/
|
*/
|
||||||
public static double clamp (double v, double lower, double 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ public class MathUtil
|
|||||||
* Clamps a value to the range [lower, upper].
|
* Clamps a value to the range [lower, upper].
|
||||||
*/
|
*/
|
||||||
public static float clamp (float v, float lower, float 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user