Class Cuboid
java.lang.Object
nl.pim16aap2.animatedarchitecture.core.util.Cuboid
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDetermines how to deal with double values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(int x, int y, int z) Adds (or subtracts) x/y/z values to the current minimum and maximum values.Returns aRectanglethat describes the area of this cuboid when you disregard the vertical (y) dimension.booleanGets the center point of the cuboid.Gets the center block of the cuboid.Returns all 8 corners of this cuboid.Gets the dimensions of this structure.intGets the distance of a position to the cuboid.getMax()Gets the upper bound position.getMin()Gets the lower bound position.intGets the total number of blocks in this cuboid.grow(int x, int y, int z) Changes the dimensions of thisCuboid.inthashCode()booleanisInRange(int x, int y, int z, int range) Checks if a position is within a certain range of the outer edge of the cuboid.booleanbooleanbooleanChecks if a position is inside this cuboid.move(int x, int y, int z) Moves thisCuboid.static CuboidCreates a new cuboid that describes the combined area of two other cuboids.static Cuboidof(Vector3Dd a, Vector3Dd b, Cuboid.RoundingMode roundingMode) Constructs a new cuboid from doubles.@NonNull StringtoString()updatePositions(UnaryOperator<Vector3Di> updateFunction) Applies an update function to bothminandmax.
-
Constructor Details
-
Cuboid
-
-
Method Details
-
of
@CheckReturnValue @Contract(pure=true) public static Cuboid of(Vector3Dd a, Vector3Dd b, Cuboid.RoundingMode roundingMode) Constructs a new cuboid 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 cuboid.
-
of
-
isPosInsideCuboid
Checks if a position is inside this cuboid. This includes the edges.- Parameters:
pos- The position to check.- Returns:
- True if the position lies inside this cuboid (including the edges).
-
isInRange
@CheckReturnValue @Contract(pure=true) public boolean isInRange(int x, int y, int z, int range) Checks if a position is within a certain range of the outer edge of the cuboid.Any point inside the cuboid will always be within range.
For example, a range of 1 would include the cuboid itself as well as a 1 deep layer of blocks around it (including corners).
- Parameters:
x- The x-coordinate to check.y- The y-coordinate to check.z- The z-coordinate to check.range- The range the position might be in. A range of 0 gives the same result asisPosInsideCuboid(Vector3Di).- Returns:
- True if the provided position lies within the range of this cuboid.
- Throws:
IllegalArgumentException- If the range is smaller than 0.
-
isInRange
-
isInRange
-
getDistanceToPoint
Gets the distance of a position to the cuboid.This the largest distance of the position along the x, y, or z axis to the cuboid.
The distance is -1 if the position is inside the cuboid.
This works similarly to
isInRange(int, int, int, int), but it returns the distance value.- Parameters:
pos- The position to check.- Returns:
- The distance of the position to the cuboid or -1 if the position is inside the cuboid.
-
getCenter
Gets the center point of the cuboid.- Returns:
- The center point of the cuboid.
-
getCenterBlock
Gets the center block of the cuboid. The results are cast to ints, basically taking the floor.- Returns:
- The center block of the cuboid.
-
updatePositions
@CheckReturnValue @Contract(pure=true) public Cuboid updatePositions(UnaryOperator<Vector3Di> updateFunction) Applies an update function to bothminandmax.- Parameters:
updateFunction- The update function used to update bothVector3Dis.- Returns:
- A new Cuboid.
-
move
-
grow
Changes the dimensions of thisCuboid. 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).To only add values to either the minimum or the maximum, use
add(int, int, int)instead.- Parameters:
x- The number of blocks to change in the x-axis.y- The number of blocks to change in the y-axis.z- The number of blocks to change in the z-axis.- Returns:
- A new
Cuboid.
-
add
Adds (or subtracts) x/y/z values to the current minimum and maximum values.Each non-zero value is added to either the minimum or the maximum, never to both. If that is desired, use
grow(int, int, int)instead.- Parameters:
x- The number of blocks to add in the x-axis.y- The number of blocks to add in the y-axis.z- The number of blocks to add in the z-axis.- Returns:
- The new Cuboid.
-
getCorners
Returns all 8 corners of this cuboid.- Returns:
- All 8 corners of this cuboid.
-
asFlatRectangle
-
toString
-
equals
-
hashCode
-
getMin
Gets the lower bound position. -
getMax
Gets the upper bound position. -
getVolume
public int getVolume()Gets the total number of blocks in this cuboid. It is inclusive of lower and upper bound. E.g. the volume of [(1,1,1)(2,2,2)] = 8. -
getDimensions
Gets the dimensions of this structure.
-