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

public final class Cuboid extends Object
Represents a cuboid as described by 2 Vector3Dis.
  • Constructor Details

  • 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

      public static Cuboid of(Cuboid a, Cuboid b)
      Creates a new cuboid that describes the combined area of two other cuboids.
      Parameters:
      a - One of the two cuboids.
      b - The other cuboid.
      Returns:
      The new cuboid that is the result of joining
    • isPosInsideCuboid

      @CheckReturnValue @Contract(pure=true) public boolean isPosInsideCuboid(Vector3Di pos)
      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 as isPosInsideCuboid(Vector3Di).
      Returns:
      True if the provided position lies within the range of this cuboid.
      Throws:
      IllegalArgumentException - If the range is smaller than 0.
    • isInRange

      @CheckReturnValue @Contract(pure=true) public boolean isInRange(Vector3Di pos, int range)
    • isInRange

      @CheckReturnValue @Contract(pure=true) public boolean isInRange(ILocation loc, int range)
    • getDistanceToPoint

      @CheckReturnValue @Contract(pure=true) public int getDistanceToPoint(Vector3Di pos)
      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

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

      @CheckReturnValue @Contract(pure=true) public Vector3Di 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 both min and max.
      Parameters:
      updateFunction - The update function used to update both Vector3Dis.
      Returns:
      A new Cuboid.
    • move

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

      @CheckReturnValue @Contract(pure=true) public Cuboid grow(int x, int y, int z)
      Changes the dimensions of this Cuboid. 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

      @CheckReturnValue @Contract(pure=true) public Cuboid add(int x, int y, int z)
      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

      @CheckReturnValue @Contract(pure=true) public Vector3Di[] getCorners()
      Returns:
      All 8 corners of this cuboid.
    • asFlatRectangle

      public Rectangle asFlatRectangle()
      Returns:
      The area described by this cuboid when you disregard the vertical (y) dimension.
    • toString

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

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

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

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

      public Vector3Di 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

      public Vector3Di getDimensions()
      Gets the dimensions of this structure.