Class NumberRange
java.lang.Object
etithespirit.orimod.api.util.valuetypes.NumberRange
- Direct Known Subclasses:
MutableNumberRange
A value representing a range between two numbers [min, max]
- Author:
- Eti
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double
The maximum possible value this will return.protected double
The minimum possible value this will return.protected final Random
A randomizer used forrandom()
static final NumberRange
A NumberRange whose min and max are both zero. -
Constructor Summary
ConstructorsConstructorDescriptionNumberRange
(double min, double max) Creates a new range between min and max, as well as a new randomizer for use in therandom()
method.NumberRange
(double min, double max, Random rng) Creates a new range between min and max, using the given randomizer for therandom()
method. -
Method Summary
-
Field Details
-
ZERO
A NumberRange whose min and max are both zero. This can be used as a lazy default. -
rng
A randomizer used forrandom()
-
min
protected double minThe minimum possible value this will return. -
max
protected double maxThe maximum possible value this will return.
-
-
Constructor Details
-
NumberRange
Creates a new range between min and max, as well as a new randomizer for use in therandom()
method. If min is greater than max, anIllegalArgumentException
is thrown.- Parameters:
min
- The minimum possible value to contain.max
- The maximum possible value to contain.- Throws:
IllegalArgumentException
- If min is greater than max.
-
NumberRange
Creates a new range between min and max, using the given randomizer for therandom()
method. If min is greater than max, anIllegalArgumentException
is thrown.- Parameters:
min
- The minimum possible value to contain.max
- The maximum possible value to contain.rng
- The randomizer to use in therandom()
method.- Throws:
IllegalArgumentException
- If min is greater than max.
-
-
Method Details
-
getMin
public double getMin()- Returns:
- The minimum possible value that this can return.
-
getMax
public double getMax()- Returns:
- The maximum possible value that this can return.
-
isSingular
public boolean isSingular()- Returns:
- Whether or not this has a range of zero, or, min is equal to max.
-
lerp
public double lerp(double alpha) Returns the value of this range interpolated to the given percentage. This is unclamped and accepts alpha values outside of the range of 0-1.- Parameters:
alpha
- The percentage to go from min to max.- Returns:
- A value linearly interpolated from min to max by alpha percent.
-
random
public double random()- Returns:
- A random value in the range [min, max), unless min and max are equal, from which that value will be returned verbatim.
-
isMutable
public boolean isMutable()- Returns:
- Whether or not this
NumberRange
is able to have its minimum and maximum edited.
-
immutableCopy
- Returns:
- A copy of this
NumberRange
as an immutable instance.
-
mutableCopy
- Returns:
- A copy of this
NumberRange
as a mutable instance.
-
equals
-