Class FloatRange
java.lang.Object
org.jjazz.utilities.api.FloatRange
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FloatRangeThe special shared instance for the empty range.floatDon't use negative value.static final FloatRangeThe biggest FloatRange possible.floatDon't use negative value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatclamp(float value, float upperBoundDelta) Clamps the value to fit in this range.clone()booleancontains(float x, boolean excludeUpperBound) Check if value is within the range.booleancontains(FloatRange fr, boolean excludeUpperBound) Check if specified range is within this float range.booleanfloatThe center of the range.floatgetPercentage(float value) Get the value expressed as a percentage of the range.getTransformed(float offset) Get a new range with bounds modified by adding offset.getTransformed(float fromOffset, float toOffset) Get a new range with bounds modified.Get a new range made from the lowest and highest bounds from this object and r.inthashCode()booleanintersects(FloatRange rg) Check if specified range intersects with this range.booleanisEmpty()setFrom(float newFrom) Return a copy of this FloatRange with a new "from" value.setTo(float newTo) Return a copy of this FloatRange with a new "to" value.floatsize()Get the size of the range.toString()
-
Field Details
-
from
public float fromDon't use negative value. -
to
public float toDon't use negative value. -
EMPTY_FLOAT_RANGE
The special shared instance for the empty range.EMPTY_FLOAT_RANGE.size() returns 0.
-
MAX_FLOAT_RANGE
The biggest FloatRange possible.
-
-
Constructor Details
-
FloatRange
public FloatRange(float from, float to) A range representing [from; to].Use the EMPTY_FLOAT_RANGE instance for empty range.
- Parameters:
from- Must be >= 0to- Must be > from- Throws:
IllegalArgumentException- If from and to are not valid
-
-
Method Details
-
clone
-
isEmpty
public boolean isEmpty() -
size
public float size()Get the size of the range.- Returns:
- (to - from), or 0 for the EMPTY_RANGE.
-
getCenter
public float getCenter()The center of the range.- Returns:
- (to-from)/2 + from
- Throws:
IllegalStateException- If range is empty
-
getPercentage
public float getPercentage(float value) Get the value expressed as a percentage of the range.- Parameters:
value-- Returns:
- 0 for a value <= from, 0.5 for getCenter(), 1 for a value >= to.
- Throws:
IllegalStateException- If range is empty- See Also:
-
contains
public boolean contains(float x, boolean excludeUpperBound) Check if value is within the range.- Parameters:
x-excludeUpperBound- If true, return false if x == this.to.- Returns:
-
contains
Check if specified range is within this float range.- Parameters:
fr-excludeUpperBound- If true, fr.to must be < this.to to be considered as contained.- Returns:
-
getIntersectRange
- Parameters:
rg-- Returns:
- Can return the EMPTY_RANGE if no intersection.
-
intersects
Check if specified range intersects with this range.Note: [2;4] and [4;7] does NOT intersect.
- Parameters:
rg-- Returns:
-
clamp
public float clamp(float value, float upperBoundDelta) Clamps the value to fit in this range.If value is >= upper bound, return value is (upper bound - upperBoundDelta).
- Parameters:
value-upperBoundDelta- Use 0 to clamp at the upper bound. If non zero, upperBoundDelta should be consistent with value and float precision (7 digits).- Returns:
-
getTransformed
Get a new range with bounds modified.Modifying the empty range returns the empty range.
- Parameters:
fromOffset-toOffset-- Returns:
- Throws:
IllegalArgumentException- If adding fromOffset and toOffset result in non-valid range values.
-
getTransformed
Get a new range with bounds modified by adding offset.Modifying the empty range returns the empty range.
- Parameters:
offset-- Returns:
- Throws:
IllegalArgumentException- If adding soffset result in non-valid range values.
-
setFrom
Return a copy of this FloatRange with a new "from" value.- Parameters:
newFrom- Must be stricly less thatn the "to" bound of this object.- Returns:
-
setTo
Return a copy of this FloatRange with a new "to" value.- Parameters:
newTo- Must be stricly greater thatn the "from" bound of this object.- Returns:
-
getUnion
Get a new range made from the lowest and highest bounds from this object and r.If one of the range is empty, return the empty range.
- Parameters:
r-- Returns:
-
toString
-
equals
-
hashCode
-