Package org.spongepowered.api.util
Enum Direction
- java.lang.Object
-
- java.lang.Enum<Direction>
-
- org.spongepowered.api.util.Direction
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Direction.Division
The compass division supported by this direction implementation.
-
Enum Constant Summary
Enum Constants Enum Constant Description DOWN
EAST
EAST_NORTHEAST
EAST_SOUTHEAST
NONE
NORTH
NORTH_NORTHEAST
NORTH_NORTHWEST
NORTHEAST
NORTHWEST
SOUTH
SOUTH_SOUTHEAST
SOUTH_SOUTHWEST
SOUTHEAST
SOUTHWEST
UP
WEST
WEST_NORTHWEST
WEST_SOUTHWEST
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector3i
asBlockOffset()
Returns the direction as a block offset vector.Vector3d
asOffset()
Returns the direction as a unit offset vector.static Direction
closest(Vector3d vector)
Gets the closest direction from the given vector.static Direction
closest(Vector3d vector, Direction.Division smallestDivision)
Gets the closest direction from the given vector.static Direction
closestHorizontal(Vector3d vector)
Gets the closest horizontal direction from the given vector.static Direction
closestHorizontal(Vector3d vector, Direction.Division smallestDivision)
Gets the closest horizontal direction from the given vector.static Direction
fromAxis(Axis axis)
Gets the direction associated with the given axis.static Direction
fromAxis(Axis axis, AxisDirection direction)
Gets the direction of the axis along the givenAxisDirection
.boolean
isCardinal()
Return true if the direction is of a cardinal direction (north, west east, and south).boolean
isOpposite(Direction d)
Returns whether the given direction is opposite this.boolean
isOrdinal()
Return true if the direction is of an ordinal direction (northwest, southwest, southeast, northeast).boolean
isSecondaryOrdinal()
Return true if the direction is of a secondary ordinal direction (north-northwest, north-northeast, south-southwest, etc.).boolean
isUpright()
Return whether Y component is non-zero.Direction
opposite()
Gets the opposite direction i.e.static Direction
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static Direction[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
NORTH
public static final Direction NORTH
-
NORTH_NORTHEAST
public static final Direction NORTH_NORTHEAST
-
NORTHEAST
public static final Direction NORTHEAST
-
EAST_NORTHEAST
public static final Direction EAST_NORTHEAST
-
EAST
public static final Direction EAST
-
EAST_SOUTHEAST
public static final Direction EAST_SOUTHEAST
-
SOUTHEAST
public static final Direction SOUTHEAST
-
SOUTH_SOUTHEAST
public static final Direction SOUTH_SOUTHEAST
-
SOUTH
public static final Direction SOUTH
-
SOUTH_SOUTHWEST
public static final Direction SOUTH_SOUTHWEST
-
SOUTHWEST
public static final Direction SOUTHWEST
-
WEST_SOUTHWEST
public static final Direction WEST_SOUTHWEST
-
WEST
public static final Direction WEST
-
WEST_NORTHWEST
public static final Direction WEST_NORTHWEST
-
NORTHWEST
public static final Direction NORTHWEST
-
NORTH_NORTHWEST
public static final Direction NORTH_NORTHWEST
-
UP
public static final Direction UP
-
DOWN
public static final Direction DOWN
-
NONE
public static final Direction NONE
-
-
Method Detail
-
values
public static Direction[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Direction c : Direction.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Direction valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
closest
public static Direction closest(Vector3d vector)
Gets the closest direction from the given vector. If the vector is the 0-Vector, this method returnsNONE
. If the vector has the same horizontal and vertical length, a horizontal direction will be returned. If the vector is halfway between two directions the clockwise next will be selected.- Parameters:
vector
- The vector to convert to a direction- Returns:
- The closest horizontal direction.
-
closest
public static Direction closest(Vector3d vector, Direction.Division smallestDivision)
Gets the closest direction from the given vector. If the vector is the 0-Vector, this method returnsNONE
. If the vector has the same horizontal and vertical length, a horizontal direction will be returned. If the vector is halfway between two directions the clockwise next will be selected.- Parameters:
vector
- The vector to convert to a directionsmallestDivision
- The smallest compass division that can be returned- Returns:
- The closest horizontal direction.
-
closestHorizontal
public static Direction closestHorizontal(Vector3d vector)
Gets the closest horizontal direction from the given vector. If the vector is the 0-Vector (ignoring y), this method returnsNONE
. If the vector is halfway between two directions the clockwise next will be selected.- Parameters:
vector
- The vector to convert to a direction- Returns:
- The closest horizontal direction.
-
closestHorizontal
public static Direction closestHorizontal(Vector3d vector, Direction.Division smallestDivision)
Gets the closest horizontal direction from the given vector. If the vector is the 0-Vector (ignoring y), this method returnsNONE
. If the vector is halfway between two directions the clockwise next will be selected.- Parameters:
vector
- The vector to convert to a directionsmallestDivision
- The smallest compass division that can be returned- Returns:
- The closest horizontal direction.
-
fromAxis
public static Direction fromAxis(Axis axis)
Gets the direction associated with the given axis.- Parameters:
axis
- The axis- Returns:
- The direction
-
fromAxis
public static Direction fromAxis(Axis axis, AxisDirection direction)
Gets the direction of the axis along the givenAxisDirection
.- Parameters:
axis
- The axisdirection
- The direction along the axis- Returns:
- The direction
-
opposite
public Direction opposite()
Gets the opposite direction i.e. 180 degrees from this direction.- Returns:
- The opposite direction
-
isOpposite
public boolean isOpposite(Direction d)
Returns whether the given direction is opposite this.- Parameters:
d
- Direction to test- Returns:
- True if it is opposite
-
isCardinal
public boolean isCardinal()
Return true if the direction is of a cardinal direction (north, west east, and south).This evaluates as false for directions that have a non-zero Y-component.
- Returns:
- True if cardinal
-
isOrdinal
public boolean isOrdinal()
Return true if the direction is of an ordinal direction (northwest, southwest, southeast, northeast).- Returns:
- True if ordinal
-
isSecondaryOrdinal
public boolean isSecondaryOrdinal()
Return true if the direction is of a secondary ordinal direction (north-northwest, north-northeast, south-southwest, etc.).- Returns:
- True if secondary ordinal
-
isUpright
public boolean isUpright()
Return whether Y component is non-zero.- Returns:
- True if the Y component is non-zero
-
asOffset
public Vector3d asOffset()
Returns the direction as a unit offset vector. This vector is also suitable as a unit direction vector.- Returns:
- The direction as an offset
-
asBlockOffset
public Vector3i asBlockOffset()
Returns the direction as a block offset vector. For secondary ordinals the results are approximated to the nearest block.The difference between this offset and
asOffset()
is that a block offset has unit components instead of unit length.- Returns:
- The direction as a block offset
-
-