Class BlockIterator

java.lang.Object
com.hypixel.hytale.math.iterator.BlockIterator

public final class BlockIterator extends Object
This class does a full block iteration from a position by a direction until it reaches a maximum distance. The line, generated does not allow to have diagonal jumps. A block always has a direct neighbor. Once the iteration reaches maximum distance, it stop the iteration.
    O O O O O O O O X X X
    O O O O O O X X X O O
    O O O O X X X O O O O
    O O X X X O O O O O O
    X X X O O O O O O O O

This class is also ThreadSafe and can be called from multiple Threads at the same time. There is no memory allocation during the iteration process.

This class makes use of the functional interface BlockIteratorProcedure.

Since:
15.06.2016
See Also:
  • Method Details

    • iterateFromTo

      public static boolean iterateFromTo(@Nonnull org.joml.Vector3dc origin, @Nonnull org.joml.Vector3dc target, @Nonnull BlockIterator.BlockIteratorProcedure procedure)
      Iterates from a Vector3d to another Vector3d and reports found blocks to the passed procedure.
      Parameters:
      origin - Ray-origin
      target - Ray-target
      procedure - Procedure to handle found blocks
    • iterateFromTo

      public static boolean iterateFromTo(@Nonnull org.joml.Vector3ic origin, @Nonnull org.joml.Vector3ic target, @Nonnull BlockIterator.BlockIteratorProcedure procedure)
      Iterates from a Vector3d to another Vector3d and reports found blocks to the passed procedure.
      Parameters:
      origin - Ray-origin
      target - Ray-target
      procedure - Procedure to handle found blocks
    • iterateFromTo

      public static boolean iterateFromTo(double sx, double sy, double sz, double tx, double ty, double tz, @Nonnull BlockIterator.BlockIteratorProcedure procedure)
      Iterates from a Vector3d to another Vector3d and reports found blocks to the passed procedure.
      Parameters:
      sx - X-coordinate of ray-origin
      sy - Y-coordinate of ray-origin
      sz - Z-coordinate of ray-origin
      tx - X-coordinate of ray-target
      ty - Y-coordinate of ray-target
      tz - Z-coordinate of ray-target
      procedure - Procedure to handle found blocks
    • iterateFromTo

      public static <T> boolean iterateFromTo(double sx, double sy, double sz, double tx, double ty, double tz, @Nonnull BlockIterator.BlockIteratorProcedurePlus1<T> procedure, T t)
      Iterates from a Vector3d to another Vector3d and reports found blocks to the passed procedure.
      Parameters:
      sx - X-coordinate of ray-origin
      sy - Y-coordinate of ray-origin
      sz - Z-coordinate of ray-origin
      tx - X-coordinate of ray-target
      ty - Y-coordinate of ray-target
      tz - Z-coordinate of ray-target
      procedure - Procedure to handle found blocks
    • iterate

      public static boolean iterate(@Nonnull org.joml.Vector3dc origin, @Nonnull org.joml.Vector3dc direction, double maxDistance, @Nonnull BlockIterator.BlockIteratorProcedure procedure)
      Iterates from an origin vector into a given direction until it reaches the maximum distance. Reports found blocks to the passed procedure.
      Parameters:
      origin - Ray-origin
      direction - Ray-direction
      maxDistance - Maximum distance to iterate over
      procedure - Procedure to handle found blocks
    • iterate

      public static boolean iterate(double sx, double sy, double sz, double dx, double dy, double dz, double maxDistance, @Nonnull BlockIterator.BlockIteratorProcedure procedure)
      Internal method to do the actual iteration. It has O(n) runtime, where n is the maxDistance. It may abort early if the passed BlockIteratorProcedure returns false.
      Parameters:
      sx - X-coordinate of ray-origin
      sy - Y-coordinate of ray-origin
      sz - Z-coordinate of ray-origin
      dx - X-value for ray-direction
      dy - Y-value for ray-direction
      dz - Z-value for ray-direction
      maxDistance - Maximum distance to iterate over the ray
      procedure - Procedure to report blocks
    • iterate

      public static <T> boolean iterate(double sx, double sy, double sz, double dx, double dy, double dz, double maxDistance, @Nonnull BlockIterator.BlockIteratorProcedurePlus1<T> procedure, T obj1)
      Internal method to do the actual iteration. It has O(n) runtime, where n is the maxDistance. It may abort early if the passed BlockIteratorProcedure returns false.
      Parameters:
      sx - X-coordinate of ray-origin
      sy - Y-coordinate of ray-origin
      sz - Z-coordinate of ray-origin
      dx - X-value for ray-direction
      dy - Y-value for ray-direction
      dz - Z-value for ray-direction
      maxDistance - Maximum distance to iterate over the ray
      procedure - Procedure to report blocks
    • isNonValidNumber

      public static boolean isNonValidNumber(double d)
      Checks if a value is a valid double number.
      Parameters:
      d - Value
      Returns:
      TRUE if a valid number
    • isZeroDirection

      public static boolean isZeroDirection(double dx, double dy, double dz)
      Checks if the given direction is a zero-vector or close to a zero-vector. It uses the same rounding error as the BlockIterator algorithm.
      Parameters:
      dx - X-value for ray-direction
      dy - Y-value for ray-direction
      dz - Z-value for ray-direction
      Returns:
      TRUE if direction is a zero-vector