public class Interval extends Object
Constructor and Description |
---|
Interval(double bound1,
double bound2)
Creates a new
Interval between the given bounds. |
Modifier and Type | Method and Description |
---|---|
static Interval |
calculateBridge(Interval i1,
Interval i2)
|
static Interval |
calculateIntersection(Interval i1,
Interval i2)
Returns the intersection of the given
intervals . |
static YRectangle |
calculateSpanningRectangle(Interval horizontal,
Interval vertical)
Returns the spanning rectangle between the given
intervals . |
static Interval |
calculateUnion(Interval interval,
double value)
Returns the union of the given
intervals and the given value. |
static Interval |
calculateUnion(Interval i1,
Interval i2)
Returns the union of the given
intervals . |
boolean |
contains(double value)
Checks whether or not the given value lies within the interval.
|
boolean |
coveredBy(Interval other)
|
boolean |
coveredBy(Interval other,
double eps)
|
double |
distanceTo(double value)
Returns the distance between the value and this
interval . |
double |
distanceTo(Interval other)
|
boolean |
equals(Object other)
|
double |
getCenter()
Gets the midpoint of the interval.
|
double |
getClosest(double value)
Returns the
interval bound that is closest to the given value. |
double |
getMax()
Gets the upper bound of the interval.
|
double |
getMin()
Gets the lower bound of the interval.
|
double |
getSize()
Gets the size of the interval, i.e., the difference between the
upper bound and the
lower bound . |
int |
hashCode()
Returns the hash code for this
interval . |
boolean |
hasSameRange(Interval other)
|
boolean |
hasSameRange(Interval other,
double eps)
|
boolean |
intersects(Interval other)
|
boolean |
intersects(Interval other,
double minIntersection)
|
boolean |
isGreaterThan(Interval other)
Checks whether or not the lower bound of this
interval is greater than the upper bound of the given
interval. |
boolean |
isLessThan(Interval other)
Checks whether or not the upper bound of this
interval is smaller than the lower bound of the given
interval. |
String |
toString()
Returns a string representation of this
Interval object. |
public Interval(double bound1, double bound2)
Interval
between the given bounds.
The upper and lower bound of the two given values are determined automatically, i.e., the smaller one will be treated as the lower bound and the larger one as the upper bound.
bound1
- the first interval boundbound2
- the second interval boundpublic static final Interval calculateBridge(Interval i1, Interval i2)
interval
between the given intervals
.
The bridging interval is null
if the given intervals intersect each other. Otherwise, the bridging interval is
[minimum of upper bounds, maximum of lower bounds]
.
i1
- the first intervali2
- the second intervalnull
if the intervals intersectpublic static final Interval calculateIntersection(Interval i1, Interval i2)
intervals
.
The intersection is null
if the given intervals do not intersect each other. Otherwise, the intersection is
[maximum of lower bounds, minimum of upper bounds]
.
i1
- the first intervali2
- the second intervalnull
if the intervals do not intersectpublic static final YRectangle calculateSpanningRectangle(Interval horizontal, Interval vertical)
intervals
.
The first interval spans the rectangle in horizontal dimension, the second interval in vertical dimension.
horizontal
- the interval that defines the location and length of the rectangle in horizontal dimensionvertical
- the interval that defines the location and length of the rectangle in vertical dimensionpublic static final Interval calculateUnion(Interval interval, double value)
intervals
and the given value.
The union is between the minimum of the lower bound of the given interval and the given value and the maximum of the upper bound of the given interval and the given value.
interval
- the interval to be extendedvalue
- the value to be in the unionpublic static final Interval calculateUnion(Interval i1, Interval i2)
intervals
.
The union is [minimum of lower bounds, maximum of upper bounds]
.
i1
- the first intervali2
- the second intervalpublic boolean contains(double value)
value
- the value to checktrue
if the value lies within the interval, false
otherwisepublic final boolean coveredBy(Interval other)
interval
fully covers this interval
given a small
epsilon value.
The given interval covers this interval, if other lower bound - epsilon <= this lower bound
and
this upper bound <= other upper bound + epsilon
.
other
- the other intervaltrue
if this interval is fully covered by the other interval, false
otherwisepublic boolean coveredBy(Interval other, double eps)
interval
fully covers this interval
given a small
epsilon value.
The given interval covers this interval, if other lower bound - epsilon <= this lower bound
and
this upper bound <= other upper bound + epsilon
.
other
- the other intervaleps
- the epsilon value that determines the extended range of the other intervaltrue
if this interval is fully covered by the other interval, false
otherwisepublic double distanceTo(double value)
interval
.
If this interval contains the specified value, the distance is 0
. Otherwise, it is the minimum of dist(value, lower bound)
and dist(value, upper bound)
.
value
- the value to which the distance is calculatedpublic double distanceTo(Interval other)
interval
and the given interval
.
If the intervals intersect
, the distance is 0
. Otherwise, it is equal to
dist(minimum of upper bounds, maximum of lower bounds)
.
other
- the other interval to which the distance is calculatedpublic boolean equals(Object other)
public double getCenter()
public double getClosest(double value)
interval
bound that is closest to the given value.value
- the value for which the closest interval bound will be returnedvalue
, if the given value lies within the interval, orpublic double getMax()
public double getMin()
public double getSize()
upper bound
and the
lower bound
.public int hashCode()
interval
.public final boolean hasSameRange(Interval other)
interval
and the given interval
cover the same range.
The intervals are considered to cover the same range, if their minimum values as well as their maximum values differ only in the given epsilon value.
other
- the other intervaltrue
if the intervals cover the same range, false
otherwisepublic boolean hasSameRange(Interval other, double eps)
interval
and the given interval
cover the same range.
The intervals are considered to cover the same range, if their minimum values as well as their maximum values differ only in the given epsilon value.
other
- the other intervaleps
- the maximum distance between the two minimum and the two maximum valuestrue
if the intervals cover the same range, false
otherwisepublic final boolean intersects(Interval other)
interval
intersects with the given
interval
, considering the given minimum intersection length.other
- the other interval to checktrue
if the intervals intersect at least by the given minimum length, false
otherwisepublic boolean intersects(Interval other, double minIntersection)
interval
intersects with the given
interval
, considering the given minimum intersection length.other
- the other interval to checkminIntersection
- the minimum length of the intersection of the intervalstrue
if the intervals intersect at least by the given minimum length, false
otherwisepublic boolean isGreaterThan(Interval other)
interval
is greater than the upper bound of the given
interval.other
- the interval to comparetrue
if the current interval is on the right of the given one, false
otherwisepublic boolean isLessThan(Interval other)
interval
is smaller than the lower bound of the given
interval.other
- the interval to comparetrue
if the current interval is on the left of the given one, false
otherwise