Package xyz.gmitch215.socketmc.util
Class ElementBounds
java.lang.Object
xyz.gmitch215.socketmc.util.ElementBounds
- All Implemented Interfaces:
Serializable
Utility class for 2D sizeable and placeable objects.
- See Also:
-
Constructor Summary
ConstructorDescriptionElementBounds
(int width, int height) Constructs new bounds at (0, 0).ElementBounds
(int x, int y, int width, int height) Constructs new bounds. -
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(int x, int y) Checks if the object contains the given point.boolean
int
Gets the x-coordinate of the center of the bounds.int
Gets the y-coordinate of the center of the bounds.int
Gets the height of the bounds.int
getWidth()
Gets the width of the bounds.int
getX()
Gets the x-coordinate of the bounds.int
getY()
Gets the y-coordinate of the bounds.int
hashCode()
void
scale
(double factor) Scales the object by the given factor.void
scale
(int factor) Scales the object by the given factor.void
setHeight
(int height) Sets the height of the bounds.void
setWidth
(int width) Sets the width of the bounds.void
setX
(int x) Sets the x-coordinate of the bounds.void
setY
(int y) Sets the y-coordinate of the bounds.toString()
void
translate
(int x, int y) Translates the object by the given amount.
-
Constructor Details
-
ElementBounds
public ElementBounds(int width, int height) Constructs new bounds at (0, 0).- Parameters:
width
- the widthheight
- the height
-
ElementBounds
Constructs new bounds.- Parameters:
x
- the x-coordinatey
- the y-coordinatewidth
- the widthheight
- the height- Throws:
IllegalArgumentException
- if coordinates or dimensions are negative
-
-
Method Details
-
getX
public int getX()Gets the x-coordinate of the bounds.- Returns:
- the x-coordinate
-
setX
public void setX(int x) Sets the x-coordinate of the bounds.- Parameters:
x
- the x-coordinate
-
getY
public int getY()Gets the y-coordinate of the bounds.- Returns:
- the y-coordinate
-
setY
public void setY(int y) Sets the y-coordinate of the bounds.- Parameters:
y
- the y-coordinate
-
translate
public void translate(int x, int y) Translates the object by the given amount.- Parameters:
x
- the x-translationy
- the y-translation
-
getWidth
public int getWidth()Gets the width of the bounds.- Returns:
- the width
-
setWidth
public void setWidth(int width) Sets the width of the bounds.- Parameters:
width
- the width
-
getHeight
public int getHeight()Gets the height of the bounds.- Returns:
- the height
-
setHeight
public void setHeight(int height) Sets the height of the bounds.- Parameters:
height
- the height
-
scale
public void scale(double factor) Scales the object by the given factor.- Parameters:
factor
- the scaling factor
-
scale
public void scale(int factor) Scales the object by the given factor.- Parameters:
factor
- the scaling factor
-
contains
public boolean contains(int x, int y) Checks if the object contains the given point.- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- true if the point is contained, false otherwise
-
getCenterX
public int getCenterX()Gets the x-coordinate of the center of the bounds.- Returns:
- the x-coordinate of the center
-
getCenterY
public int getCenterY()Gets the y-coordinate of the center of the bounds.- Returns:
- the y-coordinate of the center
-
equals
-
hashCode
public int hashCode() -
toString
-