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
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected intprotected intprotected intprotected int -
Constructor Summary
ConstructorsConstructorDescriptionGRectangle(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 TypeMethodDescriptiondoublearea()Calculates the area of this rectangleclone()booleancontains(int xx, int yy) Tells whether a point is contained on this rectanglebooleanTells whether a line is contained on this rectanglebooleanTells whether a point is contained on this rectanglebooleanTells whether a rectangle is contained on this rectanglevoiddraw(Graphics2D g) Draws the component on the given graphicsbooleanintgetCX()Retrieves the X coordinate of the center of this rectangleintgetCY()Retrieves the Y coordinate of the center of this rectangleintRetrieves the height of this rectangleintgetLeftL()Retrieves x coordinate of the left limit of this rectangleintRetrieves y coordinate of the lower limit of this rectangleintRetrieves x coordinate of the right limit of this rectanglegetShape()This method should return aAreathat represents theGFillableE.intRetrieves y coordinate of the upper limit of this rectangleintgetWidth()Retrieves the width of this rectangleinthashCode()booleanTells whether a rectangle is intersecting this rectanglevoidmove(int x, int y) Moves the center of this rectangle to the given coordinatesdoubleCalculated the perimeter of this rectanglevoidtraslate(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-GRectangleto copy- Throws:
IllegalArgumentException- ifeisnull
-
GRectangle
public GRectangle(int s) Creates a new rectangle (square) on with center in(0, 0)- Parameters:
s- side of the square- Throws:
InvalidArgumentException- ifsis 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- ifsis 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 eitherworhare less or equal than 0
-
-
Method Details
-
intersects
Tells whether a rectangle is intersecting this rectangle- Parameters:
r-GRectangleto check- Returns:
trueif the rectangles intersect andfalseotherwise- Throws:
IllegalArgumentException- ifrisnull
-
contains
Tells whether a rectangle is contained on this rectangle- Parameters:
r-GRectangleto check- Returns:
trueif the rectangle is contained andfalseotherwise- Throws:
IllegalArgumentException- ifrisnull
-
contains
Tells whether a line is contained on this rectangle- Parameters:
l-GLineto check- Returns:
trueif the line is contained andfalseotherwise- Throws:
IllegalArgumentException- iflisnull
-
contains
Tells whether a point is contained on this rectangle- Parameters:
p-GPointto check- Returns:
trueif the point is contained andfalseotherwise- Throws:
IllegalArgumentException- ifpisnull
-
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:
trueif the point is contained andfalseotherwise
-
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:GraphicETraslates 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:GraphicEDraws the component on the given graphics -
clone
- Specified by:
clonein classGFillableE
-
hashCode
public int hashCode()- Overrides:
hashCodein classGFillableE
-
equals
- Overrides:
equalsin classGFillableE
-
getShape
Description copied from class:GFillableEThis method should return aAreathat represents theGFillableE. Since this is not always possible, and the implementation ofAreaisn't always easy, it should returnnullotherwise.
InjDrawingLibs implementation we use the default shapes for this. Note that this method is only called to create clips forGraphicobjects- Specified by:
getShapein classGFillableE- Returns:
- Shape
-