Class Rectangle
java.lang.Object
nl.pim16aap2.animatedarchitecture.core.util.Rectangle
Represents a rectangle as described by 2
Vector2Dis.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDetermines how to deal with double values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the center block of the rectangle.Gets the dimensions of this rectangle.getMax()Gets the upper bound position.getMin()Gets the lower bound position.intGets the total number of blocks in this rectangle.grow(int x, int y) Changes the dimensions of thisRectangle.inthashCode()booleanChecks if a position is inside this rectangle.move(int x, int y) Moves thisRectangle.static Rectangleof(Vector2Dd a, Vector2Dd b, Rectangle.RoundingMode roundingMode) Constructs a new rectangle from doubles.toString()updatePositions(UnaryOperator<Vector2Di> updateFunction) Applies an update function to bothminandmax.
-
Constructor Details
-
Rectangle
-
-
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
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
- Returns:
- The center point of the rectangle.
-
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 bothminandmax. -
move
Moves thisRectangle.- 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
Changes the dimensions of thisRectangle. 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
-
equals
-
hashCode
public int hashCode() -
getMin
Gets the lower bound position. -
getMax
Gets the upper bound position. -
getSurface
public int getSurface()Gets the total number of blocks in this rectangle. -
getDimensions
Gets the dimensions of this rectangle.
-