Class ElementBounds

java.lang.Object
xyz.gmitch215.socketmc.util.ElementBounds
All Implemented Interfaces:
Serializable

public final class ElementBounds extends Object implements Serializable
Utility class for 2D sizeable and placeable objects.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    ElementBounds(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 Type
    Method
    Description
    boolean
    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
    Gets the width of the bounds.
    int
    Gets the x-coordinate of the bounds.
    int
    Gets the y-coordinate of the bounds.
    int
     
    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.
     
    void
    translate(int x, int y)
    Translates the object by the given amount.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ElementBounds

      public ElementBounds(int width, int height)
      Constructs new bounds at (0, 0).
      Parameters:
      width - the width
      height - the height
    • ElementBounds

      public ElementBounds(int x, int y, int width, int height) throws IllegalArgumentException
      Constructs new bounds.
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      width - the width
      height - 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-translation
      y - 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-coordinate
      y - 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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object