Enum Class Measurement

java.lang.Object
java.lang.Enum<Measurement>
com.github.yellowstonegames.grid.Measurement
All Implemented Interfaces:
Serializable, Comparable<Measurement>, Constable

public enum Measurement extends Enum<Measurement>
A way of measuring what cells are adjacent and how much further any adjacent cells are from other adjacent cells. In practice, this is used for pathfinding first and foremost, with some other code using this to fill nearby cells in some way. You will usually want to use either MANHATTAN through an entire codebase when only moves in cardinal directions are allowed, EUCLIDEAN when you want some things to look circular instead of always diamond-shaped as with MANHATTAN (this allows diagonal movement for pathfinders only if it is the best option), or maybe CHEBYSHEV if you consider using EUCLIDEAN for pathfinding (CHEBYSHEV allows cardinal and diagonal movement with equal cost, but this permits pathfinders to make very strange choices).
  • Enum Constant Details

    • MANHATTAN

      public static final Measurement MANHATTAN
      The distance it takes when only the four primary directions can be moved in. The default.
    • CHEBYSHEV

      public static final Measurement CHEBYSHEV
      The distance it takes when diagonal movement costs the same as cardinal movement.
    • EUCLIDEAN

      public static final Measurement EUCLIDEAN
      The distance it takes as the crow flies. This will NOT affect movement cost when calculating a path, only the preferred squares to travel to (resulting in drastically more reasonable-looking paths).
  • Field Details

    • ALL

      public static final Measurement[] ALL
      The cached result of values(), so you can avoid repeatedly allocating Measurement[] objects. DO NOT MODIFY THIS ARRAY.
  • Method Details

    • values

      public static Measurement[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Measurement valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • heuristic

      public float heuristic(Direction target)
    • directionCount

      public int directionCount()
    • matchingMeasurement

      public static Measurement matchingMeasurement(Radius radius)
      Gets the appropriate Measurement that matches a Radius enum. Matches SQUARE to CHEBYSHEV, DIAMOND to MANHATTAN, and CIRCLE to EUCLIDEAN.
      Parameters:
      radius - the Radius to find the corresponding Measurement for
      Returns:
      a Measurement that matches radius; SQUARE to CHEBYSHEV, DIAMOND to MANHATTAN, etc.
    • matchingRadius

      public Radius matchingRadius()
      Gets the appropriate Radius corresponding to a Measurement. Matches CHEBYSHEV to SQUARE, MANHATTAN to DIAMOND, and EUCLIDEAN to CIRCLE.
      Returns:
      a Radius enum that matches this Measurement; CHEBYSHEV to SQUARE, MANHATTAN to DIAMOND, etc.