Class GRectangle

All Implemented Interfaces:
Cloneable

public class GRectangle extends GFillableE
Author:
Federico Vera <[email protected]>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    protected int
     
    protected int
     
    protected int
     
    protected int
     
    protected int
     

    Fields inherited from class com.dkt.graphics.elements.GraphicE

    STROKE
  • 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
    Copy constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Calculates the area of this rectangle
     
    boolean
    contains(int xx, int yy)
    Tells whether a point is contained on this rectangle
    boolean
    Tells whether a line is contained on this rectangle
    boolean
    Tells whether a point is contained on this rectangle
    boolean
    Tells whether a rectangle is contained on this rectangle
    void
    Draws the component on the given graphics
    boolean
     
    int
    Retrieves the X coordinate of the center of this rectangle
    int
    Retrieves the Y coordinate of the center of this rectangle
    int
    Retrieves the height of this rectangle
    int
    Retrieves x coordinate of the left limit of this rectangle
    int
    Retrieves y coordinate of the lower limit of this rectangle
    int
    Retrieves x coordinate of the right limit of this rectangle
    This method should return a Area that represents the GFillableE.
    int
    Retrieves y coordinate of the upper limit of this rectangle
    int
    Retrieves the width of this rectangle
    int
     
    boolean
    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
    Calculated the perimeter of this rectangle
    void
    traslate(int x, int y)
    Traslates this element on X and Y

    Methods inherited from class com.dkt.graphics.elements.GFillableE

    fill, getFillPaint, setFill, setFillPaint

    Methods inherited from class com.dkt.graphics.elements.GraphicE

    getPaint, getStroke, setPaint, setStroke

    Methods inherited from class java.lang.Object

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

    • x

      protected int x
    • y

      protected int y
    • w

      protected int w
    • h

      protected int h
    • cx

      protected int cx
    • cy

      protected int cy
  • Constructor Details

    • GRectangle

      public GRectangle(GRectangle e)
      Copy constructor
      Parameters:
      e - GRectangle to copy
      Throws:
      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 Details

    • 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:
      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:
      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:
      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:
      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(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
    • clone

      public GRectangle clone()
      Specified by:
      clone in class GFillableE
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GFillableE
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class GFillableE
    • getShape

      public 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