Class Rectangle2D

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Rectangle2D.Double
      A Rectangle2D with double coordinates
      static class  Rectangle2D.Float
      A Rectangle2D with float coordinates.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int OUT_BOTTOM
      The bitmask that indicates that a point lies below this rectangle.
      static int OUT_LEFT
      The bitmask that indicates that a point lies to the left of this rectangle.
      static int OUT_RIGHT
      The bitmask that indicates that a point lies to the right of this rectangle.
      static int OUT_TOP
      The bitmask that indicates that a point lies above this rectangle.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Rectangle2D()
      This is an abstract class which cannot be instantiated: use Rectangle2D.Float, Rectangle2D.Double, or Rectangle.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(double x, double y)
      Test if this Rectangle2D contains a rectangle defined by double coordinates
      boolean contains​(double x, double y, double w, double h)
      Test if the shape contains the rectangle with top left at (x,y), width w and height h.
      boolean equals​(java.lang.Object obj)
      Test if the rectangle is equal to a given object
      boolean intersects​(double x, double y, double w, double h)
      Test if this Rectangle2D intersects a rectangle defined by double coordinates
      boolean intersectsLine​(double x1, double y1, double x2, double y2)
      Test if this rectangle intersects a given line
      abstract int outcode​(double x, double y)
      Returns a mask value that specifies where a point lies with respect to this rectangle.
      int outcode​(Point2D p)
      Returns a mask value that specifies where a given point lies with respect to this rectangle.
      void setFrame​(double x, double y, double w, double h)
      Set the frame for the rectangular shape
      abstract void setRect​(double x, double y, double w, double h)
      Set this rectangle to a rectangle defined by double coordinates
      void setRect​(Rectangle2D r)
      Set this Rectangle2D to be the same as a given Rectangle2D
      • Methods inherited from class java.lang.Object

        finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • OUT_LEFT

        public static final int OUT_LEFT
        The bitmask that indicates that a point lies to the left of this rectangle.
        See Also:
        Constant Field Values
      • OUT_TOP

        public static final int OUT_TOP
        The bitmask that indicates that a point lies above this rectangle.
        See Also:
        Constant Field Values
      • OUT_RIGHT

        public static final int OUT_RIGHT
        The bitmask that indicates that a point lies to the right of this rectangle.
        See Also:
        Constant Field Values
      • OUT_BOTTOM

        public static final int OUT_BOTTOM
        The bitmask that indicates that a point lies below this rectangle.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Rectangle2D

        protected Rectangle2D()
        This is an abstract class which cannot be instantiated: use Rectangle2D.Float, Rectangle2D.Double, or Rectangle.
    • Method Detail

      • contains

        public boolean contains​(double x,
                                double y,
                                double w,
                                double h)
        Description copied from interface: Shape
        Test if the shape contains the rectangle with top left at (x,y), width w and height h.
        Parameters:
        x - the x-coordinate of the top left point of the rectangle
        y - the y-coordinate of the top left point of the rectangle
        w - the width of the rectangle
        h - the height of the rectangle
        Returns:
        true iff the shape contains the rectangle
      • setRect

        public abstract void setRect​(double x,
                                     double y,
                                     double w,
                                     double h)
        Set this rectangle to a rectangle defined by double coordinates
        Parameters:
        x - the x coordinate of the top left corner
        y - the y coordinate of the top right corner
        w - the width of the rectangle
        h - the height of the rectangle
      • setRect

        public void setRect​(Rectangle2D r)
        Set this Rectangle2D to be the same as a given Rectangle2D
        Parameters:
        r - the Rectangle2D
      • setFrame

        public void setFrame​(double x,
                             double y,
                             double w,
                             double h)
        Description copied from class: RectangularShape
        Set the frame for the rectangular shape
        Specified by:
        setFrame in class RectangularShape
        Parameters:
        x - the x coordinate of the top left corner
        y - the y coordinate iof the top left corner
        w - the width
        h - the height
      • contains

        public boolean contains​(double x,
                                double y)
        Test if this Rectangle2D contains a rectangle defined by double coordinates
        Parameters:
        x - the x co-ordinate of the point
        y - the y co-ordinate of the point
        Returns:
        true iff the shape contains the point
      • intersects

        public boolean intersects​(double x,
                                  double y,
                                  double w,
                                  double h)
        Test if this Rectangle2D intersects a rectangle defined by double coordinates
        Parameters:
        x - the x-coordinate of the top left point of the rectangle
        y - the y-coordinate of the top left point of the rectangle
        w - the width of the rectangle
        h - the height of the rectangle
        Returns:
        true iff the shape intersects the rectangle
      • intersectsLine

        public boolean intersectsLine​(double x1,
                                      double y1,
                                      double x2,
                                      double y2)
        Test if this rectangle intersects a given line
        Parameters:
        x1 - the x coordinate of the start of the given line
        y1 - the y coordinate of the start of the given line
        x2 - the x coordinate of the end of the given line
        y2 - the y coordinate of the end of the given line
        Returns:
        true iff the rectangle intersects the line
      • outcode

        public int outcode​(Point2D p)
        Returns a mask value that specifies where a given point lies with respect to this rectangle.
        Parameters:
        p - the given point
        Returns:
        the mask value
      • outcode

        public abstract int outcode​(double x,
                                    double y)
        Returns a mask value that specifies where a point lies with respect to this rectangle.
        Parameters:
        x - the x coordinate of the given point
        y - the y coordinate of the given point
        Returns:
        the mask value
      • equals

        public boolean equals​(java.lang.Object obj)
        Test if the rectangle is equal to a given object
        Overrides:
        equals in class java.lang.Object