- java.lang.Object
-
- be.yildizgames.common.geometry.Rectangle
-
public final class Rectangle extends Object
Represent a 2D rectangle and contains the 4 extremities data.- Author:
- Gregory Van den Borre
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontain(float x, float y)Check if a point is contained in this rectangle.booleancontain(Point2D point)Check if a point is contained in this rectangle.booleanequals(Object o)intgetBottom()intgetHeight()intgetLeft()intgetRight()intgetTop()intgetWidth()inthashCode()voidmove(int x, int y)Update the rectangle coordinates by adding values to it, this behave the same as if the rectangle was moving.voidnormalize()Check that x1 is smaller than x2 and that y1 is smaller than y2.voidreset()Set all values to 0.voidsetBottom(int bottom)voidsetLeft(int left)voidsetRight(int right)voidsetTop(int top)voidsetValues(int leftValue, int topValue, int rightValue, int bottomValue)Update the Rectangle values.StringtoString()
-
-
-
Method Detail
-
contain
public boolean contain(float x, float y)Check if a point is contained in this rectangle. i.e. a point with coordinates(5,3) would be contained in a rectangle (x1=0, x2=10, y1=2, y2=4).- Parameters:
x- X coordinate for the point to check.y- Y coordinate for the point to check.- Returns:
- true if the point is within this rectangle.
-
contain
public boolean contain(Point2D point)
Check if a point is contained in this rectangle. i.e. a point with coordinates(5,3) would be contained in a rectangle (x1=0, x2=10, y1=2, y2=4).- Parameters:
point- Point to check.- Returns:
- true if the point is within this rectangle.
-
getHeight
public int getHeight()
- Returns:
- The rectangle height size.
-
getWidth
public int getWidth()
- Returns:
- The rectangle width size.
-
move
public void move(int x, int y)Update the rectangle coordinates by adding values to it, this behave the same as if the rectangle was moving.- Parameters:
x- Value to add to left and right.y- Value to add to top and bottom.
-
normalize
public void normalize()
Check that x1 is smaller than x2 and that y1 is smaller than y2. If not values are swapped.
-
reset
public void reset()
Set all values to 0.
-
setValues
public void setValues(int leftValue, int topValue, int rightValue, int bottomValue)Update the Rectangle values.- Parameters:
leftValue- New value for left.topValue- New value for top.rightValue- New value for right.bottomValue- New value for bottom.
-
getLeft
public int getLeft()
-
getTop
public int getTop()
-
getRight
public int getRight()
-
getBottom
public int getBottom()
-
setLeft
public void setLeft(int left)
-
setTop
public void setTop(int top)
-
setRight
public void setRight(int right)
-
setBottom
public void setBottom(int bottom)
-
-