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:
java.lang.Cloneable
public class GRectangle extends GFillableE
-
-
Field Summary
Fields Modifier and Type Field Description protected int
cx
X Coordinate of the centerprotected int
cy
Y Coordinate of the centerprotected int
h
Height of the rectangleprotected int
w
Width of the rectangleprotected int
x
X Coordinate of the upper left cornerprotected 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 sideGRectangle(int x, int y, int w, int h)
Creates a new rectangle given the coordinates of the center, it's width and heightGRectangle(GRectangle e)
Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
area()
Calculates the area of this rectangleGRectangle
clone()
boolean
contains(int xx, int yy)
Tells whether a point is contained on this rectangleboolean
contains(GLine l)
Tells whether a line is contained on this rectangleboolean
contains(GPoint p)
Tells whether a point is contained on this rectangleboolean
contains(GRectangle r)
Tells whether a rectangle is contained on this rectanglevoid
draw(java.awt.Graphics2D g)
Draws the component on the given graphicsboolean
equals(java.lang.Object obj)
int
getCX()
Retrieves the X coordinate of the center of this rectangleint
getCY()
Retrieves the Y coordinate of the center of this rectangleint
getHeight()
Retrieves the height of this rectangleint
getLeftL()
Retrieves x coordinate of the left limit of this rectangleint
getLowerL()
Retrieves y coordinate of the lower limit of this rectangleint
getRightL()
Retrieves x coordinate of the right limit of this rectanglejava.awt.geom.Area
getShape()
This method should return aArea
that represents theGFillableE
.int
getUpperL()
Retrieves y coordinate of the upper limit of this rectangleint
getWidth()
Retrieves the width of this rectangleint
hashCode()
boolean
intersects(GRectangle r)
Tells whether a rectangle is intersecting this rectanglevoid
move(int x, int y)
Moves the center of this rectangle to the given coordinatesdouble
perimeter()
Calculated the perimeter of this rectanglevoid
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
-
-
-
-
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
- 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 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 andfalse
otherwise- Throws:
java.lang.IllegalArgumentException
- ifr
isnull
-
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 andfalse
otherwise- Throws:
java.lang.IllegalArgumentException
- ifr
isnull
-
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 andfalse
otherwise- Throws:
java.lang.IllegalArgumentException
- ifl
isnull
-
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 andfalse
otherwise- Throws:
java.lang.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
public void draw(java.awt.Graphics2D g)
Description copied from class:GraphicE
Draws the component on the given graphics
-
clone
public GRectangle clone()
- Specified by:
clone
in classGFillableE
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classGFillableE
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classGFillableE
-
getShape
public java.awt.geom.Area 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
-
-