public class Interval1D extends Object
Interval1D includes methods for checking whether
an interval contains a point and determining whether two intervals intersect.
For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Modifier and Type | Field and Description |
|---|---|
static Comparator<Interval1D> |
LEFT_ENDPOINT_ORDER
Compares two intervals by left endpoint.
|
static Comparator<Interval1D> |
LENGTH_ORDER
Compares two intervals by length.
|
static Comparator<Interval1D> |
RIGHT_ENDPOINT_ORDER
Compares two intervals by right endpoint.
|
| Constructor and Description |
|---|
Interval1D(double left,
double right)
Initializes an interval [left, right].
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(double x)
Does this interval contain the value x?
|
boolean |
intersects(Interval1D that)
Does this interval intersect that interval?
|
double |
left()
Returns the left endpoint.
|
double |
length()
Returns the length of this interval.
|
static void |
main(String[] args)
Unit tests the Interval1D data type.
|
double |
right()
Returns the right endpoint.
|
String |
toString()
Returns a string representation of this interval.
|
public static final Comparator<Interval1D> LEFT_ENDPOINT_ORDER
public static final Comparator<Interval1D> RIGHT_ENDPOINT_ORDER
public static final Comparator<Interval1D> LENGTH_ORDER
public Interval1D(double left,
double right)
left - the left endpointright - the right endpointIllegalArgumentException - if the left endpoint is greater than the right endpointIllegalArgumentException - if either left or right
is Double.NaN, Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITYpublic double left()
public double right()
public boolean intersects(Interval1D that)
that - the other intervalpublic boolean contains(double x)
x - the valuepublic double length()
public String toString()
public static void main(String[] args)
Copyright © 2014. All Rights Reserved.