Enum Class CompassDirection

java.lang.Object
java.lang.Enum<CompassDirection>
com.thecsdev.common.util.enumerations.CompassDirection
All Implemented Interfaces:
Serializable, Comparable<CompassDirection>, Constable

public enum CompassDirection extends Enum<CompassDirection>
Represents one of the 9 compass-like positions in a 3x3 grid: the eight cardinal/intercardinal directions plus the CENTER.

Useful for things like UI grids and spatial layouts where both axis and directional grouping queries are needed.

  • Enum Constant Details

  • Method Details

    • values

      public static CompassDirection[] 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 CompassDirection 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
    • isLeft

      public boolean isLeft()
      Returns:
      true if this direction is on the left column
    • isCenterX

      public boolean isCenterX()
      Returns:
      true if this direction is on the middle column
    • isRight

      public boolean isRight()
      Returns:
      true if this direction is on the right column
    • isTop

      public boolean isTop()
      Returns:
      true if this direction is on the top row
    • isCenterY

      public boolean isCenterY()
      Returns:
      true if this direction is on the middle row
    • isBottom

      public boolean isBottom()
      Returns:
      true if this direction is on the bottom row
    • of01

      public static final CompassDirection of01(int x, int y)
      Returns the CompassDirection that corresponds to a given XY coordinate that ranges from [-1, -1] to [1, 1], where [0, 0] is the CENTER.

      Negative X corresponds to western directions, whereas negative Y corresponds to northern directions.