public class Interval2D extends Object
Interval2D
class represents a closed two-dimensional interval,
which represents all points (x, y) with both xmin <= x <= xmax
and
ymin <= y <= ymax
.
Two-dimensional intervals are immutable: their values cannot be changed
after they are created.
The class Interval2D
includes methods for checking whether
a two-dimensional interval contains a point and determining whether
two two-dimensional intervals intersect.
For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Constructor and Description |
---|
Interval2D(Interval1D x,
Interval1D y)
Initializes a two-dimensional interval.
|
Modifier and Type | Method and Description |
---|---|
double |
area()
Returns the area of this two-dimensional interval.
|
boolean |
contains(Point2D p)
Does this two-dimensional interval contain the point p?
|
void |
draw()
Draws this two-dimensional interval to standard draw.
|
boolean |
equals(Object other)
Does this interval equal the other interval?
|
int |
hashCode()
Returns an integer hash code for this interval.
|
boolean |
intersects(Interval2D that)
Does this two-dimensional interval intersect that two-dimensional interval?
|
static void |
main(String[] args)
Unit tests the
Interval2D data type. |
String |
toString()
Returns a string representation of this two-dimensional interval.
|
public Interval2D(Interval1D x, Interval1D y)
x
- the one-dimensional interval of x-coordinatesy
- the one-dimensional interval of y-coordinatespublic boolean intersects(Interval2D that)
that
- the other two-dimensional intervalpublic boolean contains(Point2D p)
p
- the two-dimensional pointpublic double area()
public String toString()
public boolean equals(Object other)
public int hashCode()
public void draw()
public static void main(String[] args)
Interval2D
data type.args
- the command-line arguments