类 RectHV


  • public final class RectHV
    extends java.lang.Object
    The RectHV class 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].
    • 方法概要

      修饰符和类型 方法 说明
      boolean contains​(Point2D p)
      Returns true if this rectangle contain the point.
      double distanceSquaredTo​(Point2D p)
      Returns the square of the Euclidean distance between this rectangle and the point p.
      double distanceTo​(Point2D p)
      Returns the Euclidean distance between this rectangle and the point p.
      void draw()
      Draws this rectangle to standard draw.
      boolean equals​(java.lang.Object other)
      Compares this rectangle to the specified rectangle.
      int hashCode()
      Returns an integer hash code for this rectangle.
      double height()
      Returns the height of this rectangle.
      boolean intersects​(RectHV that)
      Returns true if the two rectangles intersect.
      java.lang.String toString()
      Returns a string representation of this rectangle.
      double width()
      Returns the width of this rectangle.
      double xmax()
      Returns the maximum x-coordinate of any point in this rectangle.
      double xmin()
      Returns the minimum x-coordinate of any point in this rectangle.
      double ymax()
      Returns the maximum y-coordinate of any point in this rectangle.
      double ymin()
      Returns the minimum y-coordinate of any point in this rectangle.
      • 从类继承的方法 java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 构造器详细资料

      • 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 endpoint
        xmax - the x-coordinate of the upper-right endpoint
        ymin - the y-coordinate of the lower-left endpoint
        ymax - the y-coordinate of the upper-right endpoint
        抛出:
        java.lang.IllegalArgumentException - if any of xmin, xmax, ymin, or ymax is Double.NaN.
        java.lang.IllegalArgumentException - if xmax < xmin or ymax < 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
        返回:
        true if 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
        返回:
        true if this rectangle contain the point p, possibly at the boundary; false otherwise
      • distanceTo

        public double distanceTo​(Point2D p)
        Returns the Euclidean distance between this rectangle and the point p.
        参数:
        p - the point
        返回:
        the Euclidean distance between the point p and 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 point p.
        参数:
        p - the point
        返回:
        the square of the Euclidean distance between the point p and 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
        返回:
        true if this rectangle equals other; false otherwise
      • 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.