类 Interval2D
- java.lang.Object
-
- edu.princeton.cs.algs4.Interval2D
-
public class Interval2D extends java.lang.ObjectTheInterval2Dclass 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.
-
-
构造器概要
构造器 构造器 说明 Interval2D(Interval1D x, Interval1D y)Initializes a two-dimensional interval.
-
方法概要
修饰符和类型 方法 说明 doublearea()Returns the area of this 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(java.lang.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(java.lang.String[] args)Unit tests theInterval2Ddata type.java.lang.StringtoString()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 theInterval2Ddata type.- 参数:
args- the command-line arguments
-
-