Class Rect


  • public class Rect
    extends java.lang.Object
    Rect represents a rectangle.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int height
      rectangle height
      int width
      rectangle width
      int x
      x position
      int y
      y position
    • Constructor Summary

      Constructors 
      Constructor Description
      Rect()
      Constructs a rectangle with x = y = width = height = 0.
      Rect​(int x, int y, int width, int height)
      Constructs a rectangle with the given x, y, width and height.
      Rect​(Coord topleft, Coord bottomright)
      Constructs a rectangle with the given coords
      Rect​(Rect r)
      Constructs a rectangle with the given rectangle coordinates.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(int xx, int yy)
      Returns true if the point xx,yy is inside this rect.
      boolean equals​(java.lang.Object other)
      Returns true if the bounds of this Rect and the given one are the same
      int hashCode()
      Returns the hashcode for this rect, ie, an integer valued 0xXXYYWWHH
      boolean intersects​(Rect r)
      Returns true if this rectangle intersects with the given one
      Rect intersectWith​(Rect r)
      Modify this Rect by doing the intersection with the given rect.
      Rect modifiedBy​(int deltaX, int deltaY, int deltaW, int deltaH)
      Returns a new rect modified by the specified parameters.
      void modify​(int deltaX, int deltaY, int deltaW, int deltaH)
      Modifies this rect by the specified parameters.
      void set​(int x, int y, int width, int height)
      Sets the properties of this rect.
      void set​(Rect r)
      Copies the properties of this rect from the given rect.
      java.lang.String toString()  
      void translate​(int deltaX, int deltaY)
      Translates this rect.
      Rect unionWith​(Rect r)
      Modify this Rect by doing an union with the given rect.
      int x2()
      Returns x+width-1
      int y2()
      Returns y+height-1
      • Methods inherited from class java.lang.Object

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

      • x

        public int x
        x position
      • y

        public int y
        y position
      • width

        public int width
        rectangle width
      • height

        public int height
        rectangle height
    • Constructor Detail

      • Rect

        public Rect()
        Constructs a rectangle with x = y = width = height = 0.
      • Rect

        public Rect​(int x,
                    int y,
                    int width,
                    int height)
        Constructs a rectangle with the given x, y, width and height.
      • Rect

        public Rect​(Rect r)
        Constructs a rectangle with the given rectangle coordinates.
      • Rect

        public Rect​(Coord topleft,
                    Coord bottomright)
        Constructs a rectangle with the given coords
    • Method Detail

      • set

        public void set​(int x,
                        int y,
                        int width,
                        int height)
        Sets the properties of this rect.
      • set

        public void set​(Rect r)
        Copies the properties of this rect from the given rect.
      • contains

        public boolean contains​(int xx,
                                int yy)
        Returns true if the point xx,yy is inside this rect.
      • toString

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

        public void translate​(int deltaX,
                              int deltaY)
        Translates this rect. The new positions will be this.x+deltaX, this.y+deltaY.
      • modifiedBy

        public Rect modifiedBy​(int deltaX,
                               int deltaY,
                               int deltaW,
                               int deltaH)
        Returns a new rect modified by the specified parameters.
      • modify

        public void modify​(int deltaX,
                           int deltaY,
                           int deltaW,
                           int deltaH)
        Modifies this rect by the specified parameters.
      • x2

        public int x2()
        Returns x+width-1
      • y2

        public int y2()
        Returns y+height-1
      • intersects

        public boolean intersects​(Rect r)
        Returns true if this rectangle intersects with the given one
      • intersectWith

        public Rect intersectWith​(Rect r)
        Modify this Rect by doing the intersection with the given rect. Returns this rect.
      • unionWith

        public Rect unionWith​(Rect r)
        Modify this Rect by doing an union with the given rect. Returns this rect.
      • equals

        public boolean equals​(java.lang.Object other)
        Returns true if the bounds of this Rect and the given one are the same
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Returns the hashcode for this rect, ie, an integer valued 0xXXYYWWHH
        Overrides:
        hashCode in class java.lang.Object