Documentation of 'edu.princeton.cs.algs4.Interval2D' Java class
Interval2D
edu.princeton.cs.algs4

Class 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.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      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.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Interval2D

        public Interval2D(Interval1D x,
                          Interval1D y)
        Initializes a two-dimensional interval.
        Parameters:
        x - the one-dimensional interval of x-coordinates
        y - the one-dimensional interval of y-coordinates
    • Method Detail

      • intersects

        public boolean intersects(Interval2D that)
        Does this two-dimensional interval intersect that two-dimensional interval?
        Parameters:
        that - the other two-dimensional interval
        Returns:
        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?
        Parameters:
        p - the two-dimensional point
        Returns:
        true if this two-dimensional interval contains the point p; false otherwise
      • area

        public double area()
        Returns the area of this two-dimensional interval.
        Returns:
        the area of this two-dimensional interval
      • toString

        public java.lang.String toString()
        Returns a string representation of this two-dimensional interval.
        Overrides:
        toString in class java.lang.Object
        Returns:
        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?
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - the other interval
        Returns:
        true if this interval equals the other interval; false otherwise
      • hashCode

        public int hashCode()
        Returns an integer hash code for this interval.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        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.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.