Class RectangleInt32

  • All Implemented Interfaces:
    java.lang.Cloneable, Shape

    public class RectangleInt32
    extends Rectangle2D
    A rectangle with integer coordinates.
    Author:
    Lawrie Griffiths
    • Field Detail

      • height

        public int height
        The height of the rectangle
      • width

        public int width
        The width of the rectangle
      • x

        public int x
        The x coordinate of the top left of the rectangle
      • y

        public int y
        The y coordinate of the top right of the rectangle
    • Constructor Detail

      • RectangleInt32

        public RectangleInt32​(int x,
                              int y,
                              int width,
                              int height)
        Creates a rectangle with top left corner at (x,y) and with specified width and height.
        Parameters:
        x - the x coordinate of the top left corner
        y - the y coordinate of the top left corner
        width - the width of the rectangle
        height - the height of the rectangle
      • RectangleInt32

        public RectangleInt32​(int width,
                              int height)
        Creates a rectangle with top left corner at (0,0) and with specified width and height.
        Parameters:
        width - the width of the rectangle
        height - the height of the rectangle
      • RectangleInt32

        public RectangleInt32()
        Creates an empty rectangle at (0,0).
      • RectangleInt32

        public RectangleInt32​(Point p)
        Create an empty rectangle at the given point
        Parameters:
        p - trhe point
    • Method Detail

      • getX

        public double getX()
        Get the x coordinate as a double
        Specified by:
        getX in class RectangularShape
        Returns:
        the x coordinate
      • getY

        public double getY()
        Get the y coordinate as a double
        Specified by:
        getY in class RectangularShape
        Returns:
        the y coordinate
      • getWidth

        public double getWidth()
        Get the width as a double
        Specified by:
        getWidth in class RectangularShape
        Returns:
        the width
      • getHeight

        public double getHeight()
        Get the height as a double
        Specified by:
        getHeight in class RectangularShape
        Returns:
        the height
      • setLocation

        public void setLocation​(int x,
                                int y)
        Move the rectangle to (x,y)
        Parameters:
        x - the new x coordinate
        y - the new y coordinate
      • setLocation

        public void setLocation​(Point p)
        Set the location of this point to the location of a given point
        Parameters:
        p - the given point
      • isEmpty

        public boolean isEmpty()
        Test if the rectangle is empty
        Specified by:
        isEmpty in class RectangularShape
        Returns:
        true iff the rectangle is empty
      • contains

        public boolean contains​(int x,
                                int y)
        Test if a point given by (x,y) coordinates is within the rectangle
        Parameters:
        x - the x coordinate
        y - the y coordinate
        Returns:
        true iff the point is within the rectangle
      • contains

        public boolean contains​(Point p)
        Test if a point is within the rectangle
        Parameters:
        p - the point
        Returns:
        true iff the point is within the rectangle
      • contains

        public boolean contains​(RectangleInt32 r)
        Test if this rectangle contains a specified rectangle
        Parameters:
        r - the specified rectangle
        Returns:
        true iff the specified rectangle is contained within this rectangle
      • intersects

        public boolean intersects​(RectangleInt32 r)
        Test if this rectangle intersects a specified rectangle
        Parameters:
        r - the given rectangle
        Returns:
        true iff this rectangle intersects the given rectangle
      • getBounds2D

        public Rectangle2D getBounds2D()
        Description copied from interface: Shape
        Get the bounding Rectangle2D for the shape
        Returns:
        the bounding Rectangle2D
      • setBounds

        public void setBounds​(int x,
                              int y,
                              int width,
                              int height)
        Set the bounds of this rectangle
        Parameters:
        x - the new x coordinate
        y - the new y coordinate
        width - the new width
        height - the new height
      • setBounds

        public void setBounds​(RectangleInt32 r)
        Set the bounds of this rectangle to the given rectangle
        Parameters:
        r - the new rectangle
      • setRect

        public void setRect​(double x,
                            double y,
                            double width,
                            double height)
        Description copied from class: Rectangle2D
        Set this rectangle to a rectangle defined by double coordinates
        Specified by:
        setRect in class Rectangle2D
        Parameters:
        x - the x coordinate of the top left corner
        y - the y coordinate of the top right corner
        width - the width of the rectangle
        height - the height of the rectangle
      • reshape

        @Deprecated
        public void reshape​(int x,
                            int y,
                            int width,
                            int height)
        Deprecated.
        Use setBounds.
      • equals

        public boolean equals​(java.lang.Object obj)
        Test if the Rectangle is equal to a given object
        Overrides:
        equals in class Rectangle2D
        Parameters:
        obj - the object
      • getLocation

        public Point getLocation()
        Get the location of the rectangle
        Returns:
        the (x,y) coordinate of the top left corner
      • setSize

        public void setSize​(int width,
                            int height)
        Set the size of the rectangle
        Parameters:
        width - the new width
        height - the new height
      • resize

        @Deprecated
        public void resize​(int width,
                           int height)
        Deprecated.
        Use setSize
      • toString

        public java.lang.String toString()
        Returns a String representing this rectangle.
        Overrides:
        toString in class java.lang.Object
      • outcode

        public int outcode​(double x,
                           double y)
        Description copied from class: Rectangle2D
        Returns a mask value that specifies where a point lies with respect to this rectangle.
        Specified by:
        outcode in class Rectangle2D
        Parameters:
        x - the x coordinate of the given point
        y - the y coordinate of the given point
        Returns:
        the mask value
      • inside

        @Deprecated
        public boolean inside​(int x,
                              int y)
        Deprecated.