Class Direction2Helper
A set of helper and extension methods for dealing with Direction2
public static class Direction2Helper
- Inheritance
-
Direction2Helper
- Inherited Members
Fields
Adjacent
public static readonly Direction2[] Adjacent
Field Value
All
All Direction2 enum values
public static readonly Direction2[] All
Field Value
AllExceptNone
All directions except None
public static readonly Direction2[] AllExceptNone
Field Value
Diagonals
public static readonly Direction2[] Diagonals
Field Value
Methods
Angle(Direction2)
Returns the angle of the direction in radians, where Right has an angle of 0.
public static float Angle(this Direction2 dir)
Parameters
dir
Direction2The direction whose angle to get
Returns
- float
The direction's angle
IsAdjacent(Direction2)
Returns if the given direction is considered an "adjacent" direction. An adjacent direction is one that is not a diagonal.
public static bool IsAdjacent(this Direction2 dir)
Parameters
dir
Direction2The direction to query
Returns
- bool
Whether the direction is adjacent
IsDiagonal(Direction2)
Returns if the given direction is considered a diagonal direction.
public static bool IsDiagonal(this Direction2 dir)
Parameters
dir
Direction2The direction to query
Returns
- bool
Whether the direction is diagonal
Offset(Direction2)
Returns the directional offset of a given direction. The offset direction will be exactly one unit in each axis that the direction represents.
public static Point Offset(this Direction2 dir)
Parameters
dir
Direction2The direction whose offset to query
Returns
- Point
The direction's offset
Offsets(IEnumerable<Direction2>)
Maps each direction in the given enumerable of directions to its Offset(Direction2).
public static IEnumerable<Point> Offsets(this IEnumerable<Direction2> directions)
Parameters
directions
IEnumerable<Direction2>The direction enumerable
Returns
- IEnumerable<Point>
The directions' offsets, in the same order as the input directions.
Opposite(Direction2)
Returns the opposite of the given direction. For "adjacent" directions, this is the direction that points into the same axis, but the opposite sign. For diagonal directions, this is the direction that points into the opposite of both the x and y axis.
public static Direction2 Opposite(this Direction2 dir)
Parameters
dir
Direction2The direction whose opposite to get
Returns
- Direction2
The opposite of the direction
RotateBy(Direction2, Direction2, Direction2)
Rotates the given direction by a given reference direction
public static Direction2 RotateBy(this Direction2 dir, Direction2 reference, Direction2 start = Direction2.Up)
Parameters
dir
Direction2The direction to rotate
reference
Direction2The direction to rotate by
start
Direction2The direction to use as the default direction
Returns
- Direction2
The direction, rotated by the reference direction
RotateCcw(Direction2, bool)
Rotates the given direction counter-clockwise and returns the resulting direction.
public static Direction2 RotateCcw(this Direction2 dir, bool fortyFiveDegrees = false)
Parameters
dir
Direction2The direction to rotate counter-clockwise
fortyFiveDegrees
boolWhether to rotate by 45 degrees. If this is false, the rotation is 90 degrees instead.
Returns
- Direction2
The rotated direction
RotateCw(Direction2, bool)
Rotates the given direction clockwise and returns the resulting direction.
public static Direction2 RotateCw(this Direction2 dir, bool fortyFiveDegrees = false)
Parameters
dir
Direction2The direction to rotate
fortyFiveDegrees
boolWhether to rotate by 45 degrees. If this is false, the rotation is 90 degrees instead.
Returns
- Direction2
The rotated direction
To90Direction(Vector2)
Returns the Direction2 that is closest to the given position's facing direction, only taking Adjacent directions into account. Diagonal directions will be rounded to the nearest vertical direction.
public static Direction2 To90Direction(this Vector2 offset)
Parameters
offset
Vector2The vector whose corresponding direction to get
Returns
- Direction2
The vector's direction
ToDirection(Vector2)
Returns the Direction2 that is closest to the given position's facing direction.
public static Direction2 ToDirection(this Vector2 offset)
Parameters
offset
Vector2The vector whose corresponding direction to get
Returns
- Direction2
The vector's direction