Package org.jjazz.utilities.api
Class FloatRange
java.lang.Object
org.jjazz.utilities.api.FloatRange
A range between 2 positive floats.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final FloatRange
The special shared instance for the empty range.float
float
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(float x, boolean excludeUpperBound) Check if value is within the range.boolean
contains
(FloatRange fr, boolean excludeUpperBound) Check if specified range is within this float range.boolean
float
The center 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.int
hashCode()
boolean
intersects
(FloatRange rg) Check if specified range intersects with this range.boolean
isEmpty()
float
size()
Get the size of the range.toString()
-
Field Details
-
from
public float from -
to
public float to -
EMPTY_FLOAT_RANGE
The special shared instance for the empty range.EMPTY_FLOAT_RANGE.size() returns 0.
-
-
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==to
-
-
Method Details
-
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
-
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:
-
getTransformed
Get a new range with bounds modified.Modifying the empty range returns the empty range.
- Parameters:
fromOffset
-toOffset
-- Returns:
-
getTransformed
Get a new range with bounds modified by adding offset.Modifying the empty range returns the empty range.
- Parameters:
offset
-- 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
public int hashCode()
-