Package edu.princeton.cs.algs4
Class Interval2D
- Object
-
- edu.princeton.cs.algs4.Interval2D
-
public class Interval2D extends Object
TheInterval2Dclass represents a closed two-dimensional interval, which represents all points (x, y) with bothxmin <= x <= xmaxandymin <= y <= ymax. Two-dimensional intervals are immutable: their values cannot be changed after they are created. The classInterval2Dincludes 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.
- Author:
- Robert Sedgewick, Kevin Wayne
-
-
Constructor Summary
Constructors Constructor Description Interval2D(Interval1D x, Interval1D y)Initializes a two-dimensional interval.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublearea()Returns the area of this two-dimensional interval.booleancontains(Interval2D that)Does this two-dimensional interval contain that two-dimensional interval?booleancontains(Point2D p)Does this two-dimensional interval contain the point p?voiddraw()Draws this two-dimensional interval to standard draw.booleanequals(Object other)Does this interval equal the other interval?inthashCode()Returns an integer hash code for this interval.booleanintersects(Interval2D that)Does this two-dimensional interval intersect that two-dimensional interval?static voidmain(String[] args)Unit tests theInterval2Ddata type.StringtoString()Returns a string representation of this two-dimensional interval.
-
-
-
Constructor Detail
-
Interval2D
public Interval2D(Interval1D x, Interval1D y)
Initializes a two-dimensional interval.- Parameters:
x- the one-dimensional interval of x-coordinatesy- the one-dimensional interval of y-coordinates
-
-
Method Detail
-
intersects
public boolean intersects(Interval2D that)
Does this two-dimensional interval intersect that two-dimensional interval?- Parameters:
that- the other two-dimensional interval- Returns:
- true if this two-dimensional interval intersects that two-dimensional interval; false otherwise
-
contains
public boolean contains(Interval2D that)
Does this two-dimensional interval contain that two-dimensional interval?- Parameters:
that- the other two-dimensional interval- Returns:
- true if this two-dimensional interval contains that two-dimensional interval; false otherwise
-
contains
public boolean contains(Point2D p)
Does this two-dimensional interval contain the point p?- Parameters:
p- the two-dimensional point- Returns:
- true if this two-dimensional interval contains the point p; false otherwise
-
area
public double area()
Returns the area of this two-dimensional interval.- Returns:
- the area of this two-dimensional interval
-
toString
public String toString()
Returns a string representation of this two-dimensional interval.
-
equals
public boolean equals(Object other)
Does this interval equal the other interval?
-
hashCode
public int hashCode()
Returns an integer hash code for this interval.
-
draw
public void draw()
Draws this two-dimensional interval to standard draw.
-
main
public static void main(String[] args)
Unit tests theInterval2Ddata type.- Parameters:
args- the command-line arguments
-
-