Class GRectangle

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class GRectangle
    extends GFillableE
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int cx
      X Coordinate of the center
      protected int cy
      Y Coordinate of the center
      protected int h
      Height of the rectangle
      protected int w
      Width of the rectangle
      protected int x
      X Coordinate of the upper left corner
      protected int y
      Y Coordinate of the upper left corner
    • Constructor Summary

      Constructors 
      Constructor Description
      GRectangle​(int s)
      Creates a new rectangle (square) on with center in (0, 0)
      GRectangle​(int x, int y, int s)
      Creates a new rectangle (square) given the coordinates of the center, and the size of it's side
      GRectangle​(int x, int y, int w, int h)
      Creates a new rectangle given the coordinates of the center, it's width and height
      GRectangle​(GRectangle e)
      Copy constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double area()
      Calculates the area of this rectangle
      GRectangle clone()  
      boolean contains​(int xx, int yy)
      Tells whether a point is contained on this rectangle
      boolean contains​(GLine l)
      Tells whether a line is contained on this rectangle
      boolean contains​(GPoint p)
      Tells whether a point is contained on this rectangle
      boolean contains​(GRectangle r)
      Tells whether a rectangle is contained on this rectangle
      void draw​(java.awt.Graphics2D g)
      Draws the component on the given graphics
      boolean equals​(java.lang.Object obj)  
      int getCX()
      Retrieves the X coordinate of the center of this rectangle
      int getCY()
      Retrieves the Y coordinate of the center of this rectangle
      int getHeight()
      Retrieves the height of this rectangle
      int getLeftL()
      Retrieves x coordinate of the left limit of this rectangle
      int getLowerL()
      Retrieves y coordinate of the lower limit of this rectangle
      int getRightL()
      Retrieves x coordinate of the right limit of this rectangle
      java.awt.geom.Area getShape()
      This method should return a Area that represents the GFillableE.
      int getUpperL()
      Retrieves y coordinate of the upper limit of this rectangle
      int getWidth()
      Retrieves the width of this rectangle
      int hashCode()  
      boolean intersects​(GRectangle r)
      Tells whether a rectangle is intersecting this rectangle
      void move​(int x, int y)
      Moves the center of this rectangle to the given coordinates
      double perimeter()
      Calculated the perimeter of this rectangle
      void traslate​(int x, int y)
      Traslates this element on X and Y
      • Methods inherited from class java.lang.Object

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

      • x

        protected int x
        X Coordinate of the upper left corner
      • y

        protected int y
        Y Coordinate of the upper left corner
      • w

        protected int w
        Width of the rectangle
      • h

        protected int h
        Height of the rectangle
      • cx

        protected int cx
        X Coordinate of the center
      • cy

        protected int cy
        Y Coordinate of the center
    • Constructor Detail

      • GRectangle

        public GRectangle​(GRectangle e)
        Copy constructor
        Parameters:
        e - GRectangle to copy
        Throws:
        java.lang.IllegalArgumentException - if e is null
      • GRectangle

        public GRectangle​(int s)
        Creates a new rectangle (square) on with center in (0, 0)
        Parameters:
        s - side of the square
        Throws:
        InvalidArgumentException - if s is less or equal than 0
      • GRectangle

        public GRectangle​(int x,
                          int y,
                          int s)
        Creates a new rectangle (square) given the coordinates of the center, and the size of it's side
        Parameters:
        x - x coordinate of the center of the rectangle
        y - y coordinate of the center of the rectangle
        s - side of the square
        Throws:
        InvalidArgumentException - if s is less or equal than 0
      • GRectangle

        public GRectangle​(int x,
                          int y,
                          int w,
                          int h)
        Creates a new rectangle given the coordinates of the center, it's width and height
        Parameters:
        x - x coordinate of the center of the rectangle
        y - y coordinate of the center of the rectangle
        w - width of the rectangle
        h - height of the rectangle
        Throws:
        InvalidArgumentException - if either w or h are less or equal than 0
    • Method Detail

      • intersects

        public boolean intersects​(GRectangle r)
        Tells whether a rectangle is intersecting this rectangle
        Parameters:
        r - GRectangle to check
        Returns:
        true if the rectangles intersect and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if r is null
      • contains

        public boolean contains​(GRectangle r)
        Tells whether a rectangle is contained on this rectangle
        Parameters:
        r - GRectangle to check
        Returns:
        true if the rectangle is contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if r is null
      • contains

        public boolean contains​(GLine l)
        Tells whether a line is contained on this rectangle
        Parameters:
        l - GLine to check
        Returns:
        true if the line is contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if l is null
      • contains

        public boolean contains​(GPoint p)
        Tells whether a point is contained on this rectangle
        Parameters:
        p - GPoint to check
        Returns:
        true if the point is contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if p is null
      • contains

        public boolean contains​(int xx,
                                int yy)
        Tells whether a point is contained on this rectangle
        Parameters:
        xx - x coordinate of the point
        yy - y coordinate of the point
        Returns:
        true if the point is contained and false otherwise
      • getCX

        public int getCX()
        Retrieves the X coordinate of the center of this rectangle
        Returns:
        x coordinate
      • getCY

        public int getCY()
        Retrieves the Y coordinate of the center of this rectangle
        Returns:
        y coordinate
      • getRightL

        public int getRightL()
        Retrieves x coordinate of the right limit of this rectangle
        Returns:
        x coordinate of the right limit
      • getLeftL

        public int getLeftL()
        Retrieves x coordinate of the left limit of this rectangle
        Returns:
        x coordinate of the left limit
      • getLowerL

        public int getLowerL()
        Retrieves y coordinate of the lower limit of this rectangle
        Returns:
        y coordinate of the lower limit
      • getUpperL

        public int getUpperL()
        Retrieves y coordinate of the upper limit of this rectangle
        Returns:
        y coordinate of the upper limit
      • area

        public double area()
        Calculates the area of this rectangle
        Returns:
        area
      • perimeter

        public double perimeter()
        Calculated the perimeter of this rectangle
        Returns:
        perimeter
      • getHeight

        public int getHeight()
        Retrieves the height of this rectangle
        Returns:
        height
      • getWidth

        public int getWidth()
        Retrieves the width of this rectangle
        Returns:
        width
      • traslate

        public void traslate​(int x,
                             int y)
        Description copied from class: GraphicE
        Traslates this element on X and Y
        Specified by:
        traslate in class GraphicE
        Parameters:
        x - size in px of the horizontal translation
        y - size in px of the vertical translation
      • move

        public void move​(int x,
                         int y)
        Moves the center of this rectangle to the given coordinates
        Parameters:
        x - new x coordinate
        y - new y coordinate
      • draw

        public void draw​(java.awt.Graphics2D g)
        Description copied from class: GraphicE
        Draws the component on the given graphics
        Specified by:
        draw in class GraphicE
        Parameters:
        g - where to draw
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class GFillableE
      • getShape

        public java.awt.geom.Area getShape()
        Description copied from class: GFillableE
        This method should return a Area that represents the GFillableE. Since this is not always possible, and the implementation of Area isn't always easy, it should return null otherwise.
        In jDrawingLibs implementation we use the default shapes for this. Note that this method is only called to create clips for Graphic objects
        Specified by:
        getShape in class GFillableE
        Returns:
        Shape