Class Rectangle

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.util.Rectangle

public final class Rectangle extends Object
Represents a rectangle as described by 2 Vector2Dis.
  • Constructor Details

  • Method Details

    • of

      @CheckReturnValue @Contract(pure=true) public static Rectangle of(Vector2Dd a, Vector2Dd b, Rectangle.RoundingMode roundingMode)
      Constructs a new rectangle from doubles.
      Parameters:
      a - The first position.
      b - The second position.
      roundingMode - The rounding mode to use when rounding doubles into integer values.
      Returns:
      The new rectangle.
    • isPosInsideRectangle

      @CheckReturnValue @Contract(pure=true) public boolean isPosInsideRectangle(Vector2Di pos)
      Checks if a position is inside this rectangle. This includes the edges.
      Parameters:
      pos - The position to check.
      Returns:
      True if the position lies inside this rectangle (including the edges).
    • getCenter

      @CheckReturnValue @Contract(pure=true) public Vector2Dd getCenter()
      Returns the center point of the rectangle.
      Returns:
      The center point of the rectangle.
    • getCenterBlock

      @CheckReturnValue @Contract(pure=true) public Vector2Di getCenterBlock()
      Gets the center block of the rectangle. The results are cast to ints, basically taking the floor.
      Returns:
      The center block of the rectangle.
    • updatePositions

      @CheckReturnValue @Contract(pure=true) public Rectangle updatePositions(UnaryOperator<Vector2Di> updateFunction)
      Applies an update function to both min and max.
      Parameters:
      updateFunction - The update function used to update both Vector2Dis.
      Returns:
      A new Rectangle.
    • move

      @CheckReturnValue @Contract(pure=true) public Rectangle move(int x, int y)
      Moves this Rectangle.
      Parameters:
      x - The number of blocks to move in the x-axis.
      y - The number of blocks to move in the y-axis.
      Returns:
      A new Rectangle.
    • grow

      @CheckReturnValue @Contract(pure=true) public Rectangle grow(int x, int y)
      Changes the dimensions of this Rectangle. The changes are applied symmetrically. So a change of 1 in the x-axis, means that the length of the x-axis is increased by 2 (1 subtracted from min and 1 added to max).
      Parameters:
      x - The number of blocks to change in the x-axis.
      y - The number of blocks to change in the y-axis.
      Returns:
      A new Rectangle.
    • toString

      public @NonNull String toString()
      Overrides:
      toString in class Object
    • equals

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

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

      public Vector2Di getMin()
      Gets the lower bound position.
    • getMax

      public Vector2Di getMax()
      Gets the upper bound position.
    • getSurface

      public int getSurface()
      Gets the total number of blocks in this rectangle.
    • getDimensions

      public Vector2Di getDimensions()
      Gets the dimensions of this rectangle.