-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathMathUtils.java
More file actions
34 lines (31 loc) · 1.1 KB
/
MathUtils.java
File metadata and controls
34 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package nodebox.util;
public class MathUtils {
/**
* Clamps the value so the result is between 0.0 and 1.0.
* <p/>
* This means that if the value is smaller than 0.0, this method will return 0.0.
* If the value is larger than 1.0, this method will return 1.0.
* Values within the range are returned unchanged.
*
* @param v the value to clamp
* @return a value between 0.0 and 1.0.
*/
public static float clamp(float v) {
return 0 > v ? 0 : 1 < v ? 1 : v;
}
/**
* Clamps the value so the result is between the given minimum and maximum value.
* <p/>
* This means that if the value is smaller than min, this method will return min.
* If the value is larger than max, this method will return max.
* Values within the range are returned unchanged.
*
* @param v the value to clamp
* @param min the minimum value
* @param max the maximum value
* @return a value between min and max.
*/
public static float clamp(float v, float min, float max) {
return min > v ? min : max < v ? max : v;
}
}