Class Rectangle

  • All Implemented Interfaces:
    Shape
    Direct Known Subclasses:
    ImageLayoutInformation

    @API(type=EXTENDABLE,
         src=PRIVATE)
    public class Rectangle
    extends java.lang.Object
    implements Shape
    Rectangle.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int height
      The height.
      int width
      The width.
      int x
      The x.
      int y
      The y.
    • Constructor Summary

      Constructors 
      Constructor Description
      Rectangle​(int x, int y, int width, int height)
      Constructor.
      Rectangle​(Rectangle r)
      Copy constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean adjacent​(Rectangle r)  
      java.lang.Object clone()  
      boolean contains​(int x, int y)
      Checks whether or not this Rectangle contains the point at the specified location (xy).
      boolean contains​(int X, int Y, int W, int H)
      Checks whether this Rectangle entirely contains the Rectangle at the specified location ( X Y ) with the specified dimensions ( W H ).
      boolean contains​(Rectangle r)
      Checks whether or not this Rectangle entirely contains the specified Rectangle.
      boolean equals​(java.lang.Object obj)
      Checks whether two rectangles are equal.
      Rectangle getBounds()  
      int getHeight()  
      int getWidth()  
      int getX()  
      int getY()  
      int hashCode()  
      Rectangle intersection​(Rectangle r)
      Computes the intersection of this Rectangle with the specified Rectangle.
      boolean intersects​(int rX, int rY, int rW, int rH)
      Determines whether or not this Rectangle and the specified Rectangle intersect.
      boolean intersects​(Rectangle r)
      Determines whether or not this Rectangle and the specified Rectangle intersect.
      static void main​(java.lang.String[] args)
      TC main.
      java.lang.String toString()
      Returns a String representing this Rectangle and its values.
      Shape translate​(int tx, int ty)
      Translate the shape into another one.
      Rectangle union​(Rectangle r)
      Computes the union of this Rectangle with the specified Rectangle.
      • Methods inherited from class java.lang.Object

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

      • width

        public int width
        The width.
      • height

        public int height
        The height.
      • x

        public int x
        The x.
      • y

        public int y
        The y.
    • Constructor Detail

      • Rectangle

        public Rectangle​(int x,
                         int y,
                         int width,
                         int height)
        Constructor.
        Parameters:
        x - The x coordinate.
        y - The y coordinate.
        width - The width.
        height - The height.
      • Rectangle

        public Rectangle​(Rectangle r)
        Copy constructor.
        Parameters:
        r - The other rectangle to be used.
    • Method Detail

      • intersects

        public final boolean intersects​(Rectangle r)
        Determines whether or not this Rectangle and the specified Rectangle intersect. Two rectangles intersect if their intersection is nonempty.
        Parameters:
        r - the specified Rectangle
        Returns:
        true if the specified Rectangle and this Rectangle intersect; false otherwise.
      • intersects

        public final boolean intersects​(int rX,
                                        int rY,
                                        int rW,
                                        int rH)
        Determines whether or not this Rectangle and the specified Rectangle intersect. Two rectangles intersect if their intersection is nonempty.
        Parameters:
        rX - X of rect
        rY - Y of rect
        rW - Width of rect
        rH - Height of rect
        Returns:
        true if the specified Rectangle and this Rectangle intersect; false otherwise.
      • contains

        public boolean contains​(Rectangle r)
        Checks whether or not this Rectangle entirely contains the specified Rectangle.
        Parameters:
        r - the specified Rectangle
        Returns:
        true if the Rectangle is contained entirely inside this Rectangle;false otherwise.
      • contains

        public boolean contains​(int X,
                                int Y,
                                int W,
                                int H)
        Checks whether this Rectangle entirely contains the Rectangle at the specified location ( X Y ) with the specified dimensions ( W H ).
        Specified by:
        contains in interface Shape
        Parameters:
        X - the specified x coordinate
        Y - the specified y coordinate
        W - the width of the Rectangle
        H - the height of the Rectangle
        Returns:
        true if the Rectangle specified by ( X Y W H ) is entirely enclosed inside this Rectangle;false otherwise.
      • contains

        public boolean contains​(int x,
                                int y)
        Checks whether or not this Rectangle contains the point at the specified location (xy).
        Specified by:
        contains in interface Shape
        Parameters:
        x - the specified x coordinate
        y - the specified y coordinate
        Returns:
        true if the point (xy) is inside this Rectangle; false otherwise.
      • toString

        public java.lang.String toString()
        Returns a String representing this Rectangle and its values.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representing this Rectangle object's coordinate and size values.
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks whether two rectangles are equal.

        The result is true if and only if the argument is not null and is a Rectangle object that has the same top-left corner, width, and height as this Rectangle.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the Object to compare with this Rectangle
        Returns:
        true if the objects are equal; false otherwise.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • union

        public Rectangle union​(Rectangle r)
        Computes the union of this Rectangle with the specified Rectangle. Returns a new Rectangle that represents the union of the two rectangles
        Parameters:
        r - the specified Rectangle
        Returns:
        the smallest Rectangle containing both the specified Rectangle and this Rectangle.
      • getHeight

        public int getHeight()
        Returns:
        The rectangle height.
      • getWidth

        public int getWidth()
        Returns:
        The rectangle width.
      • getX

        public int getX()
        Returns:
        The rectangle x coordinate.
      • getY

        public int getY()
        Returns:
        The rectangle y coordinate.
      • adjacent

        public boolean adjacent​(Rectangle r)
        Parameters:
        r - The rectangle to check for adjacency.
        Returns:
        True if the rectangles are neighbours around one margin and they do not intersect each other.
      • intersection

        public Rectangle intersection​(Rectangle r)
        Computes the intersection of this Rectangle with the specified Rectangle. Returns a new Rectangle that represents the intersection of the two rectangles. If the two rectangles do not intersect, the result will be an empty rectangle.
        Parameters:
        r - the specified Rectangle
        Returns:
        the largest Rectangle contained in both the specified Rectangle and in this Rectangle; or if the rectangles do not intersect, an empty rectangle.
      • main

        public static void main​(java.lang.String[] args)
        TC main.
        Parameters:
        args - Main args
      • translate

        public Shape translate​(int tx,
                               int ty)
        Description copied from interface: Shape
        Translate the shape into another one.
        Specified by:
        translate in interface Shape
        Parameters:
        tx - the distance by which coordinates are translated in the X axis direction
        ty - the distance by which coordinates are translated in the Y axis direction
        Returns:
        The newly translated shape
        See Also:
        Shape.translate(int, int)
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
        See Also:
        Object.clone()