Package net.rotgruengelb.nixienaut.math
Class ClampedNum<T extends Comparable<T>>
java.lang.Object
net.rotgruengelb.nixienaut.math.ClampedNum<T>
- Type Parameters:
T- The type of the number.
A number that is clamped between a minimum and a maximum value.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the value and clamps it if it is out of range.static floatclamp(float value, float minValue, float maxValue) Clamps a float value between a minimum and a maximum value.static intclamp(int value, int minValue, int maxValue) Clamps an integer value between a minimum and a maximum value.get()Gets the minimum value.Gets the maximum value.Gets the minimum value.voidSets the value.
-
Constructor Details
-
ClampedNum
Creates a new ClampedNum object.- Parameters:
minValue- The minimum value.maxValue- The maximum value.- See Also:
-
-
Method Details
-
clamp
public static int clamp(int value, int minValue, int maxValue) Clamps an integer value between a minimum and a maximum value.- Parameters:
value- The value to clamp.minValue- The minimum value.maxValue- The maximum value.- Returns:
- The clamped value.
-
clamp
public static float clamp(float value, float minValue, float maxValue) Clamps a float value between a minimum and a maximum value.- Parameters:
value- The value to clamp.minValue- The minimum value.maxValue- The maximum value.- Returns:
- The clamped value.
-
get
Gets the minimum value.- Returns:
- The minimum value.
-
set
Sets the value.- Parameters:
value- The value to set.- Throws:
IllegalArgumentException- If the value is out of range.- See Also:
-
adjustSet
Sets the value and clamps it if it is out of range. -
getMinValue
Gets the minimum value.- Returns:
- The minimum value.
- See Also:
-
getMaxValue
Gets the maximum value.- Returns:
- The maximum value.
- See Also:
-