Enum Class CardinalDirection

java.lang.Object
java.lang.Enum<CardinalDirection>
net.buildtheearth.terracore.geo.CardinalDirection
All Implemented Interfaces:
Serializable, Comparable<CardinalDirection>, Constable

public enum CardinalDirection extends Enum<CardinalDirection>
Represents one of the eight main cardinal and intercardinal directions.

Each direction covers a 45° half-open azimuth sector [min, max), measured clockwise from North (0° = NORTH, 90° = EAST, 180° = SOUTH, 270° = WEST). In clockwise order:

  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    East, centered on 90°: azimuths in [67.5°, 112.5°).
    North, centered on 0°: azimuths in [337.5°, 360°) and [0°, 22.5°).
    Northeast, centered on 45°: azimuths in [22.5°, 67.5°).
    Northwest, centered on 315°: azimuths in [292.5°, 337.5°).
    South, centered on 180°: azimuths in [157.5°, 202.5°).
    Southeast, centered on 135°: azimuths in [112.5°, 157.5°).
    Southwest, centered on 225°: azimuths in [202.5°, 247.5°).
    West, centered on 270°: azimuths in [247.5°, 292.5°).
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    matches(float azimuth, @NonNull AngleUnit unit)
    Checks whether the given azimuth faces this cardinal direction.
    double
    The end of this direction's azimuth sector in degrees, exclusive.
    double
    The start of this direction's azimuth sector in degrees, inclusive.
    ofAzimuth(float angle, @NonNull AngleUnit unit)
    Returns the cardinal direction closest to the given azimuth.
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • NORTH

      public static final CardinalDirection NORTH
      North, centered on 0°: azimuths in [337.5°, 360°) and [0°, 22.5°).
    • NORTHEAST

      public static final CardinalDirection NORTHEAST
      Northeast, centered on 45°: azimuths in [22.5°, 67.5°).
    • EAST

      public static final CardinalDirection EAST
      East, centered on 90°: azimuths in [67.5°, 112.5°).
    • SOUTHEAST

      public static final CardinalDirection SOUTHEAST
      Southeast, centered on 135°: azimuths in [112.5°, 157.5°).
    • SOUTH

      public static final CardinalDirection SOUTH
      South, centered on 180°: azimuths in [157.5°, 202.5°).
    • SOUTHWEST

      public static final CardinalDirection SOUTHWEST
      Southwest, centered on 225°: azimuths in [202.5°, 247.5°).
    • WEST

      public static final CardinalDirection WEST
      West, centered on 270°: azimuths in [247.5°, 292.5°).
    • NORTHWEST

      public static final CardinalDirection NORTHWEST
      Northwest, centered on 315°: azimuths in [292.5°, 337.5°).
  • Method Details

    • values

      public static CardinalDirection[] 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 CardinalDirection 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
    • ofAzimuth

      public static CardinalDirection ofAzimuth(float angle, @NonNull @NonNull AngleUnit unit)
      Returns the cardinal direction closest to the given azimuth.
      Parameters:
      angle - an azimuth, measured clockwise from north, expressed in the given unit
      unit - the unit angle is expressed in
      Returns:
      the CardinalDirection the given azimuth is the closest to
      Throws:
      IllegalArgumentException - if the given azimuth is not a finite number
      NullPointerException - if the given unit is null
    • matches

      public boolean matches(float azimuth, @NonNull @NonNull AngleUnit unit)
      Checks whether the given azimuth faces this cardinal direction.
      Parameters:
      azimuth - an azimuth measured clockwise from north; any finite value is accepted
      unit - the unit azimuth is expressed in
      Returns:
      true if the given azimuth faces this cardinal direction
      Throws:
      IllegalArgumentException - if the given azimuth is not a finite number
      NullPointerException - if the given unit is null
    • minDegrees

      public double minDegrees()
      The start of this direction's azimuth sector in degrees, inclusive. For NORTH the sector wraps around 360°/0°, so this is 337.5 while maxDegrees is 22.5.
    • maxDegrees

      public double maxDegrees()
      The end of this direction's azimuth sector in degrees, exclusive. For NORTH the sector wraps around 360°/0°, so this is 22.5 while minDegrees is 337.5.