Package com.dkt.graphics.elements
Class GRectangle
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.GFillableE
com.dkt.graphics.elements.GRectangle
- All Implemented Interfaces:
Cloneable
- Author:
- Federico Vera <[email protected]>
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
protected int
protected int
protected int
protected int
protected int
-
Constructor Summary
ConstructorDescriptionGRectangle
(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 sideGRectangle
(int x, int y, int w, int h) Creates a new rectangle given the coordinates of the center, it's width and heightCopy constructor -
Method Summary
Modifier and TypeMethodDescriptiondouble
area()
Calculates the area of this rectangleclone()
boolean
contains
(int xx, int yy) Tells whether a point is contained on this rectangleboolean
Tells whether a line is contained on this rectangleboolean
Tells whether a point is contained on this rectangleboolean
Tells whether a rectangle is contained on this rectanglevoid
draw
(Graphics2D g) Draws the component on the given graphicsboolean
int
getCX()
Retrieves the X coordinate of the center of this rectangleint
getCY()
Retrieves the Y coordinate of the center of this rectangleint
Retrieves the height of this rectangleint
getLeftL()
Retrieves x coordinate of the left limit of this rectangleint
Retrieves y coordinate of the lower limit of this rectangleint
Retrieves x coordinate of the right limit of this rectanglegetShape()
This method should return aArea
that represents theGFillableE
.int
Retrieves y coordinate of the upper limit of this rectangleint
getWidth()
Retrieves the width of this rectangleint
hashCode()
boolean
Tells whether a rectangle is intersecting this rectanglevoid
move
(int x, int y) Moves the center of this rectangle to the given coordinatesdouble
Calculated the perimeter of this rectanglevoid
traslate
(int x, int y) Traslates this element on X and YMethods inherited from class com.dkt.graphics.elements.GFillableE
fill, getFillPaint, setFill, setFillPaint
-
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
Copy constructor- Parameters:
e
-GRectangle
to copy- Throws:
IllegalArgumentException
- ife
isnull
-
GRectangle
public GRectangle(int s) Creates a new rectangle (square) on with center in(0, 0)
- Parameters:
s
- side of the square- Throws:
InvalidArgumentException
- ifs
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 rectangley
- y coordinate of the center of the rectangles
- side of the square- Throws:
InvalidArgumentException
- ifs
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 rectangley
- y coordinate of the center of the rectanglew
- width of the rectangleh
- height of the rectangle- Throws:
InvalidArgumentException
- if eitherw
orh
are less or equal than 0
-
-
Method Details
-
intersects
Tells whether a rectangle is intersecting this rectangle- Parameters:
r
-GRectangle
to check- Returns:
true
if the rectangles intersect andfalse
otherwise- Throws:
IllegalArgumentException
- ifr
isnull
-
contains
Tells whether a rectangle is contained on this rectangle- Parameters:
r
-GRectangle
to check- Returns:
true
if the rectangle is contained andfalse
otherwise- Throws:
IllegalArgumentException
- ifr
isnull
-
contains
Tells whether a line is contained on this rectangle- Parameters:
l
-GLine
to check- Returns:
true
if the line is contained andfalse
otherwise- Throws:
IllegalArgumentException
- ifl
isnull
-
contains
Tells whether a point is contained on this rectangle- Parameters:
p
-GPoint
to check- Returns:
true
if the point is contained andfalse
otherwise- Throws:
IllegalArgumentException
- ifp
isnull
-
contains
public boolean contains(int xx, int yy) Tells whether a point is contained on this rectangle- Parameters:
xx
- x coordinate of the pointyy
- y coordinate of the point- Returns:
true
if the point is contained andfalse
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 -
move
public void move(int x, int y) Moves the center of this rectangle to the given coordinates- Parameters:
x
- new x coordinatey
- new y coordinate
-
draw
Description copied from class:GraphicE
Draws the component on the given graphics -
clone
- Specified by:
clone
in classGFillableE
-
hashCode
public int hashCode()- Overrides:
hashCode
in classGFillableE
-
equals
- Overrides:
equals
in classGFillableE
-
getShape
Description copied from class:GFillableE
This method should return aArea
that represents theGFillableE
. Since this is not always possible, and the implementation ofArea
isn't always easy, it should returnnull
otherwise.
InjDrawingLib
s implementation we use the default shapes for this. Note that this method is only called to create clips forGraphic
objects- Specified by:
getShape
in classGFillableE
- Returns:
- Shape
-