类 Interval2D


  • public class Interval2D
    extends java.lang.Object
    The Interval2D class represents a closed two-dimensional interval, which represents all points (x, y) with both xmin <= x <= xmax and ymin <= y <= ymax. Two-dimensional intervals are immutable: their values cannot be changed after they are created. The class Interval2D 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.

    • 方法概要

      修饰符和类型 方法 说明
      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 the Interval2D data type.
      java.lang.String toString()
      Returns a string representation of this two-dimensional interval.
      • 从类继承的方法 java.lang.Object

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

      • Interval2D

        public Interval2D​(Interval1D x,
                          Interval1D y)
        Initializes a two-dimensional interval.
        参数:
        x - the one-dimensional interval of x-coordinates
        y - 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 the Interval2D data type.
        参数:
        args - the command-line arguments