类 Interval2D
- java.lang.Object
-
- edu.princeton.cs.algs4.Interval2D
-
public class Interval2D extends java.lang.Object
TheInterval2D
class represents a closed two-dimensional interval, which represents all points (x, y) with bothxmin <= x <= xmax
andymin <= y <= ymax
. Two-dimensional intervals are immutable: their values cannot be changed after they are created. The classInterval2D
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.
-
-
构造器概要
构造器 构造器 说明 Interval2D(Interval1D x, Interval1D y)
Initializes a two-dimensional interval.
-
方法概要
修饰符和类型 方法 说明 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(java.lang.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(java.lang.String[] args)
Unit tests theInterval2D
data type.java.lang.String
toString()
Returns a string representation of this two-dimensional interval.
-
-
-
构造器详细资料
-
Interval2D
public Interval2D(Interval1D x, Interval1D y)
Initializes a two-dimensional interval.- 参数:
x
- the one-dimensional interval of x-coordinatesy
- the one-dimensional interval of y-coordinates
-
-
方法详细资料
-
intersects
public boolean intersects(Interval2D that)
Does this two-dimensional interval intersect that two-dimensional interval?- 参数:
that
- the other two-dimensional interval- 返回:
- true if this two-dimensional interval intersects that two-dimensional interval; false otherwise
-
contains
public boolean contains(Point2D p)
Does this two-dimensional interval contain the point p?- 参数:
p
- the two-dimensional point- 返回:
- true if this two-dimensional interval contains the point p; false otherwise
-
area
public double area()
Returns the area of this two-dimensional interval.- 返回:
- the area of this two-dimensional interval
-
toString
public java.lang.String toString()
Returns a string representation of this two-dimensional interval.- 覆盖:
toString
在类中java.lang.Object
- 返回:
- a string representation of this two-dimensional interval in the form [xmin, xmax] x [ymin, ymax]
-
equals
public boolean equals(java.lang.Object other)
Does this interval equal the other interval?- 覆盖:
equals
在类中java.lang.Object
- 参数:
other
- the other interval- 返回:
- true if this interval equals the other interval; false otherwise
-
hashCode
public int hashCode()
Returns an integer hash code for this interval.- 覆盖:
hashCode
在类中java.lang.Object
- 返回:
- an integer hash code for this interval
-
draw
public void draw()
Draws this two-dimensional interval to standard draw.
-
main
public static void main(java.lang.String[] args)
Unit tests theInterval2D
data type.- 参数:
args
- the command-line arguments
-
-