- Object
-
- Interval
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double
clamp(double value)
If the value is within thisInterval
, inclusive, then return the value, else return either the max or minimum value.static double
clamp(double value, double min, double max)
Returns a number clamped between two other numbers.boolean
contains(Interval interval)
double
distance(Interval interval)
Returns the distance between the twoInterval
s.void
expand(double value)
Expands thisInterval
by half the given amount in both directions.Interval
getExpanded(double value)
Returns a newInterval
of this interval expanded by half the given amount in both directions.Interval
getIntersection(Interval interval)
double
getLength()
Returns the length of this interval from its min to its max.double
getMax()
Returns the maximum value for thisInterval
.double
getMin()
Returns the minimum value for thisInterval
.double
getOverlap(Interval interval)
Interval
getUnion(Interval interval)
boolean
includesExclusive(double value)
Returns true if the given value is within thisInterval
exlcuding the maximum and minimum.boolean
includesInclusive(double value)
Returns true if the given value is within thisInterval
including the maximum and minimum.boolean
includesInclusiveMax(double value)
Returns true if the given value is within thisInterval
including the maximum and excluding the minimum.boolean
includesInclusiveMin(double value)
Returns true if the given value is within thisInterval
including the minimum and excluding the maximum.void
intersection(Interval interval)
boolean
isDegenerate()
Returns true if thisInterval
is degenerate.boolean
isDegenerate(double error)
Returns true if thisInterval
is degenerate given the allowed error.boolean
overlaps(Interval interval)
Returns true if the twoInterval
s overlap.void
setMax(double max)
Sets the maximum for this interval.void
setMin(double min)
Sets the minimum for this interval.String
toString()
void
union(Interval interval)
-
-
-
Constructor Detail
-
Interval
public Interval(double min, double max)
Full constructor.- Parameters:
min
- the minimum valuemax
- the maximum value- Throws:
IllegalArgumentException
- if min > max
-
-
Method Detail
-
getMin
public double getMin()
Returns the minimum value for thisInterval
.- Returns:
- double
-
getMax
public double getMax()
Returns the maximum value for thisInterval
.- Returns:
- double
-
setMin
public void setMin(double min)
Sets the minimum for this interval.- Parameters:
min
- the minimum value- Throws:
IllegalArgumentException
- if min > max
-
setMax
public void setMax(double max)
Sets the maximum for this interval.- Parameters:
max
- the maximum value- Throws:
IllegalArgumentException
- if max < min
-
includesInclusive
public boolean includesInclusive(double value)
Returns true if the given value is within thisInterval
including the maximum and minimum.- Parameters:
value
- the test value- Returns:
- boolean
-
includesExclusive
public boolean includesExclusive(double value)
Returns true if the given value is within thisInterval
exlcuding the maximum and minimum.- Parameters:
value
- the test value- Returns:
- boolean
-
includesInclusiveMin
public boolean includesInclusiveMin(double value)
Returns true if the given value is within thisInterval
including the minimum and excluding the maximum.- Parameters:
value
- the test value- Returns:
- boolean
-
includesInclusiveMax
public boolean includesInclusiveMax(double value)
Returns true if the given value is within thisInterval
including the maximum and excluding the minimum.- Parameters:
value
- the test value- Returns:
- boolean
-
overlaps
public boolean overlaps(Interval interval)
Returns true if the twoInterval
s overlap.- Parameters:
interval
- theInterval
- Returns:
- boolean
-
getOverlap
public double getOverlap(Interval interval)
Returns the amount of overlap between thisInterval
and the givenInterval
.This method tests to if the
Interval
s overlap first. If they do then the overlap is returned, if they do not then 0 is returned.- Parameters:
interval
- theInterval
- Returns:
- double
-
clamp
public double clamp(double value)
If the value is within thisInterval
, inclusive, then return the value, else return either the max or minimum value.- Parameters:
value
- the value to clamp- Returns:
- double
-
clamp
public static double clamp(double value, double min, double max)
Returns a number clamped between two other numbers.This method assumes that min ≤ max.
- Parameters:
value
- the value to clampmin
- the min valuemax
- the max value- Returns:
- double
-
isDegenerate
public boolean isDegenerate()
- Returns:
- boolean
-
isDegenerate
public boolean isDegenerate(double error)
Returns true if thisInterval
is degenerate given the allowed error.An
Interval
is degenerate given some error if max - min <= error.- Parameters:
error
- the allowed error- Returns:
- boolean
-
contains
public boolean contains(Interval interval)
- Parameters:
interval
- theInterval
- Returns:
- boolean
-
union
public void union(Interval interval)
Sets thisInterval
to the union of thisInterval
and the givenInterval
.If the two
Interval
s are not overlapping then this method will return oneInterval
that represents anInterval
enclosing bothInterval
s.- Parameters:
interval
- theInterval
-
getUnion
public Interval getUnion(Interval interval)
- Parameters:
interval
- theInterval
- Returns:
Interval
- See Also:
union(Interval)
-
intersection
public void intersection(Interval interval)
Sets thisInterval
to the intersection of thisInterval
and the givenInterval
.If the two
Interval
s are not overlapping then this method will make thisInterval
the a zero degenerateInterval
, [0, 0].- Parameters:
interval
- theInterval
-
getIntersection
public Interval getIntersection(Interval interval)
- Parameters:
interval
- theInterval
- Returns:
Interval
- See Also:
intersection(Interval)
-
distance
public double distance(Interval interval)
Returns the distance between the twoInterval
s.If the given interval overlaps this interval, zero is returned.
- Parameters:
interval
- theInterval
- Returns:
- double
-
expand
public void expand(double value)
Expands thisInterval
by half the given amount in both directions.The value can be negative to shrink the interval. However, if the value is greater than the current length of the interval, the interval can become invalid. In this case, the interval will become a degenerate interval at the mid point of the min and max.
- Parameters:
value
- the value
-
getExpanded
public Interval getExpanded(double value)
Returns a newInterval
of this interval expanded by half the given amount in both directions.The value can be negative to shrink the interval. However, if the value is greater than the current length of the interval, the interval will be invalid. In this case, the interval returned will be a degenerate interval at the mid point of the min and max.
- Parameters:
value
- the value- Returns:
Interval
- Since:
- 3.1.1
-
getLength
public double getLength()
Returns the length of this interval from its min to its max.- Returns:
- double
- Since:
- 3.1.1
-
-