类 RectHV
- java.lang.Object
-
- edu.princeton.cs.algs4.RectHV
-
public final class RectHV extends java.lang.ObjectTheRectHVclass is an immutable data type to encapsulate a two-dimensional axis-aligned rectagle with real-value coordinates. The rectangle is closed—it includes the points on the boundary.For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
构造器概要
构造器 构造器 说明 RectHV(double xmin, double ymin, double xmax, double ymax)Initializes a new rectangle [xmin, xmax] x [ymin, ymax].
-
方法概要
修饰符和类型 方法 说明 booleancontains(Point2D p)Returns true if this rectangle contain the point.doubledistanceSquaredTo(Point2D p)Returns the square of the Euclidean distance between this rectangle and the pointp.doubledistanceTo(Point2D p)Returns the Euclidean distance between this rectangle and the pointp.voiddraw()Draws this rectangle to standard draw.booleanequals(java.lang.Object other)Compares this rectangle to the specified rectangle.inthashCode()Returns an integer hash code for this rectangle.doubleheight()Returns the height of this rectangle.booleanintersects(RectHV that)Returns true if the two rectangles intersect.java.lang.StringtoString()Returns a string representation of this rectangle.doublewidth()Returns the width of this rectangle.doublexmax()Returns the maximum x-coordinate of any point in this rectangle.doublexmin()Returns the minimum x-coordinate of any point in this rectangle.doubleymax()Returns the maximum y-coordinate of any point in this rectangle.doubleymin()Returns the minimum y-coordinate of any point in this rectangle.
-
-
-
构造器详细资料
-
RectHV
public RectHV(double xmin, double ymin, double xmax, double ymax)Initializes a new rectangle [xmin, xmax] x [ymin, ymax].- 参数:
xmin- the x-coordinate of the lower-left endpointxmax- the x-coordinate of the upper-right endpointymin- the y-coordinate of the lower-left endpointymax- the y-coordinate of the upper-right endpoint- 抛出:
java.lang.IllegalArgumentException- if any ofxmin,xmax,ymin, orymaxisDouble.NaN.java.lang.IllegalArgumentException- ifxmax < xminorymax < ymin.
-
-
方法详细资料
-
xmin
public double xmin()
Returns the minimum x-coordinate of any point in this rectangle.- 返回:
- the minimum x-coordinate of any point in this rectangle
-
xmax
public double xmax()
Returns the maximum x-coordinate of any point in this rectangle.- 返回:
- the maximum x-coordinate of any point in this rectangle
-
ymin
public double ymin()
Returns the minimum y-coordinate of any point in this rectangle.- 返回:
- the minimum y-coordinate of any point in this rectangle
-
ymax
public double ymax()
Returns the maximum y-coordinate of any point in this rectangle.- 返回:
- the maximum y-coordinate of any point in this rectangle
-
width
public double width()
Returns the width of this rectangle.- 返回:
- the width of this rectangle
xmax - xmin
-
height
public double height()
Returns the height of this rectangle.- 返回:
- the height of this rectangle
ymax - ymin
-
intersects
public boolean intersects(RectHV that)
Returns true if the two rectangles intersect. This includes improper intersections (at points on the boundary of each rectangle) and nested intersctions (when one rectangle is contained inside the other)- 参数:
that- the other rectangle- 返回:
trueif this rectangle intersect the argument rectangle at one or more points
-
contains
public boolean contains(Point2D p)
Returns true if this rectangle contain the point.- 参数:
p- the point- 返回:
trueif this rectangle contain the pointp, possibly at the boundary;falseotherwise
-
distanceTo
public double distanceTo(Point2D p)
Returns the Euclidean distance between this rectangle and the pointp.- 参数:
p- the point- 返回:
- the Euclidean distance between the point
pand the closest point on this rectangle; 0 if the point is contained in this rectangle
-
distanceSquaredTo
public double distanceSquaredTo(Point2D p)
Returns the square of the Euclidean distance between this rectangle and the pointp.- 参数:
p- the point- 返回:
- the square of the Euclidean distance between the point
pand the closest point on this rectangle; 0 if the point is contained in this rectangle
-
equals
public boolean equals(java.lang.Object other)
Compares this rectangle to the specified rectangle.- 覆盖:
equals在类中java.lang.Object- 参数:
other- the other rectangle- 返回:
trueif this rectangle equalsother;falseotherwise
-
hashCode
public int hashCode()
Returns an integer hash code for this rectangle.- 覆盖:
hashCode在类中java.lang.Object- 返回:
- an integer hash code for this rectangle
-
toString
public java.lang.String toString()
Returns a string representation of this rectangle.- 覆盖:
toString在类中java.lang.Object- 返回:
- a string representation of this rectangle, using the format
[xmin, xmax] x [ymin, ymax]
-
draw
public void draw()
Draws this rectangle to standard draw.
-
-