Package breadboards

Class GRectangle


  • public class GRectangle
    extends java.lang.Object
    Class whose objects are rectangle whose width, height, and location coordinates are all stored as doubles
    Author:
    paul oser
    • Field Summary

      Fields 
      Modifier and Type Field Description
      double EMPTY_THRESHOLD  
    • Constructor Summary

      Constructors 
      Constructor Description
      GRectangle()
      constructs an empty rectangle (dimensions and coordinates are zero)
      GRectangle​(double width, double height)  
      GRectangle​(double x, double y, double width, double height)
      constructs a rectangle with the specified dimensions at the specified location
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(double x, double y)
      returns true when point specified (i.e., (x,y)) is on or inside the GRectangle
      boolean contains​(GPoint p)
      returns true when point specified is on or inside the GRectangle
      double getHeight()
      returns the height of the GRectangle
      GPoint getLocation()
      returns the location of this GRectangle
      GDimension getSize()
      returns the dimensions of this GRectangle
      double getWidth()
      returns the width of the GRectangle
      double getX()
      returns the x-coordinate of the upper left corner of this rectangle
      double getY()
      returns the y-coordinate of the upper left corner of this rectangle
      void grow​(double dx, double dy)
      grows the dimensions of the rectangle (width by dx, height by dy)
      boolean intersects​(GRectangle otherRectangle)  
      boolean isEmpty()
      returns whether or not the width and height are essentially zero (i.e., sufficiently small)
      void setLocation​(double x, double y)
      sets the location of the upper left corner of the rectangle to the specified coordinates
      void setSize​(double width, double height)
      sets the dimensions of the rectangle to those specified
      void setSize​(GDimension size)
      sets the dimensions of the rectangle to the specified dimensions
      java.lang.String toString()  
      void translate​(double dx, double dy)
      translates the rectangle, adding dx to the x-coordinate and dy to the y-coordinate of its upper left corner
      GRectangle union​(GRectangle r2)
      returns the GRectangle that bounds both this GRectangle and another specified GRectangle
      • Methods inherited from class java.lang.Object

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

      • GRectangle

        public GRectangle()
        constructs an empty rectangle (dimensions and coordinates are zero)
      • GRectangle

        public GRectangle​(double width,
                          double height)
      • GRectangle

        public GRectangle​(double x,
                          double y,
                          double width,
                          double height)
        constructs a rectangle with the specified dimensions at the specified location
        Parameters:
        x - x-coordinate of specified location
        y - y-coordinate of specified location
        width - specified width
        height - specified height
    • Method Detail

      • contains

        public boolean contains​(double x,
                                double y)
        returns true when point specified (i.e., (x,y)) is on or inside the GRectangle
        Parameters:
        x - x-coordinate of the point specified
        y - y-coordinate of the point specified
        Returns:
        true when (x,y) is on or inside the GRectangle, false otherwise
      • contains

        public boolean contains​(GPoint p)
        returns true when point specified is on or inside the GRectangle
        Parameters:
        p - the point specified
        Returns:
        true when point specified is on or inside the GRectangle, false otherwise
      • intersects

        public boolean intersects​(GRectangle otherRectangle)
      • getWidth

        public double getWidth()
        returns the width of the GRectangle
        Returns:
        the width of the GRectangle
      • getHeight

        public double getHeight()
        returns the height of the GRectangle
        Returns:
        the height of the GRectangle
      • getLocation

        public GPoint getLocation()
        returns the location of this GRectangle
        Returns:
        the location of this GRectangle
      • getSize

        public GDimension getSize()
        returns the dimensions of this GRectangle
        Returns:
        the dimensions of this GRectangle
      • getX

        public double getX()
        returns the x-coordinate of the upper left corner of this rectangle
        Returns:
        the x-coordinate of the upper left corner of this rectangle
      • getY

        public double getY()
        returns the y-coordinate of the upper left corner of this rectangle
        Returns:
        the y-coordinate of the upper left corner of this rectangle
      • isEmpty

        public boolean isEmpty()
        returns whether or not the width and height are essentially zero (i.e., sufficiently small)
        Returns:
        true if both width and height are less than GRectangle.EMPTY_THRESHOLD, false otherwise
      • setLocation

        public void setLocation​(double x,
                                double y)
        sets the location of the upper left corner of the rectangle to the specified coordinates
        Parameters:
        x - x-coordinate specified
        y - y-coordinate specified
      • setSize

        public void setSize​(double width,
                            double height)
        sets the dimensions of the rectangle to those specified
        Parameters:
        width - the specified width
        height - the specified height
      • setSize

        public void setSize​(GDimension size)
        sets the dimensions of the rectangle to the specified dimensions
        Parameters:
        size - the specified dimensions
      • grow

        public void grow​(double dx,
                         double dy)
        grows the dimensions of the rectangle (width by dx, height by dy)
        Parameters:
        dx - amount to add to the width of the rectangle
        dy - amount to add to the height of the rectangle
      • translate

        public void translate​(double dx,
                              double dy)
        translates the rectangle, adding dx to the x-coordinate and dy to the y-coordinate of its upper left corner
        Parameters:
        dx - amount to add to the x-coordinate of its upper left corner
        dy - amount to add to the y-coordinate of its upper left corner
      • union

        public GRectangle union​(GRectangle r2)
        returns the GRectangle that bounds both this GRectangle and another specified GRectangle
        Parameters:
        r2 - the GRectangle specified
        Returns:
        the GRectangle that bounds both this GRectangle and r2
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object