Enum Class Direction
- All Implemented Interfaces:
Serializable, Comparable<Direction>, Constable
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Direction[]The cached result ofvalues(), so you can avoid repeatedly allocatingDirection[]objects.static final Direction[]An array which holds only the four cardinal directions.static final Direction[]An array which holds only the four cardinal directions in clockwise order.static final Direction[]An array which holds only the four cardinal directions in counter-clockwise order.static final Direction[]An array which holds all eight OUTWARDS directions in clockwise order.final Coordstatic final Direction[]An array which holds all eight OUTWARDS directions in counter-clockwise order.final intThe x coordinate difference for this direction.final intThe y coordinate difference for this direction.static final Direction[]An array which holds only the four diagonal directions.static final Direction[]An array which holds all eight OUTWARDS directions. -
Method Summary
Modifier and TypeMethodDescriptionReturns the Direction one step clockwise, including diagonals.Returns the Direction one step counterclockwise, including diagonals.static DirectiongetCardinalDirection(int x, int y) Returns the direction that most closely matches the input.static DirectiongetDirection(int x, int y) Returns the direction that most closely matches the input.static DirectiongetRoughDirection(int x, int y) Gets an estimate at the correct direction that a position lies in given the distance towards it on the x and y axes.booleanhasDown()booleanhasLeft()booleanhasRight()booleanhasUp()booleanbooleanopposite()Returns the direction directly opposite to this one.static Directionstatic DirectionReturns the enum constant of this class with the specified name.static Direction[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
UP
-
DOWN
-
LEFT
-
RIGHT
-
UP_LEFT
-
UP_RIGHT
-
DOWN_LEFT
-
DOWN_RIGHT
-
NONE
-
-
Field Details
-
CARDINALS
An array which holds only the four cardinal directions. -
CARDINALS_CLOCKWISE
An array which holds only the four cardinal directions in clockwise order. -
CARDINALS_COUNTERCLOCKWISE
An array which holds only the four cardinal directions in counter-clockwise order. -
DIAGONALS
An array which holds only the four diagonal directions. -
OUTWARDS
An array which holds all eight OUTWARDS directions. -
CLOCKWISE
An array which holds all eight OUTWARDS directions in clockwise order. -
COUNTERCLOCKWISE
An array which holds all eight OUTWARDS directions in counter-clockwise order. -
ALL
-
deltaX
public final int deltaXThe x coordinate difference for this direction. -
deltaY
public final int deltaYThe y coordinate difference for this direction. -
coord
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
getDirection
Returns the direction that most closely matches the input. This can be any direction, including cardinal and diagonal directions as well asNONEin the case that x and y are both 0.
This can be used to get the primary intercardinal direction from an origin point to an event point, such as a mouse click on a grid. If the point given is exactly on a boundary between directions then the direction clockwise is returned.- Parameters:
x- the x position relative to the origin (0,0)y- the y position relative to the origin (0,0)- Returns:
- the closest matching Direction enum, which may be
NONE
-
getRoughDirection
Gets an estimate at the correct direction that a position lies in given the distance towards it on the x and y axes. If x and y are both between -1 and 1 inclusive, this will always be accurate, and should be faster thangetDirection(int, int)by avoiding trigonometry or any other math on floats. If at least one of x or y is 0, then this will also be accurate and will produce either a cardinal direction or NONE if both are 0. If x and y are both non-zero, this will always produce a diagonal, even if a cardinal direction should be more accurate; this behavior may sometimes be desirable to detect when some position is even slightly off from a true cardinal direction.- Parameters:
x- the x position relative to the origin (0,0)y- the y position relative to the origin (0,0)- Returns:
- the Direction that x,y lies in, roughly; will always be accurate for arguments between -1 and 1 inclusive
-
getCardinalDirection
Returns the direction that most closely matches the input. This can be any of the four cardinal directions as well asNONEin the case that x and y are both 0.
This can be used to get the primary cardinal direction from an origin point to an event point, such as a mouse click on a grid. If the point given is directly diagonal then the direction clockwise is returned.- Parameters:
x- the x position relative to the origin (0,0)y- the y position relative to the origin (0,0)- Returns:
- the closest matching cardinal Direction enum, which may also be
NONE
-
toGoTo
-
clockwise
Returns the Direction one step clockwise, including diagonals. If considering only Cardinal directions, calling this twice will get the next clockwise cardinal direction.- Returns:
- the Direction one step clockwise, including diagonals
-
counterClockwise
Returns the Direction one step counterclockwise, including diagonals. If considering only Cardinal directions, calling this twice will get the next counterclockwise cardinal direction.- Returns:
- the Direction one step counterclockwise, including diagonals
-
opposite
Returns the direction directly opposite to this one.- Returns:
- the direction directly opposite to this one
-
isDiagonal
public boolean isDiagonal()- Returns:
- Whether this is a diagonal move.
-
isCardinal
public boolean isCardinal()- Returns:
- Whether this is a cardinal-direction move.
-
hasUp
public boolean hasUp()- Returns:
trueifthishas an upward component.
-
hasDown
public boolean hasDown()- Returns:
trueifthishas a downward component.
-
hasLeft
public boolean hasLeft()- Returns:
trueifthishas a left component.
-
hasRight
public boolean hasRight()- Returns:
trueifthishas a right component.
-