Class DirectionHelpers
Defines extension methods and helpers for the Direction enum.
Inheritance
Namespace: AS2
Assembly: .dll
Syntax
public static class DirectionHelpers
Methods
| Edit this page View SourceAddTo(Direction, Direction, bool)
Adds this direction value to the given direction. The current direction is interpreted as an amount of rotation relative to the E direction that is to be added to the given other direction. This can be used to convert local directions to global directions.
Declaration
public static Direction AddTo(this Direction d, Direction other, bool clockwise = false)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The current direction to be interpreted as an amount of rotation. |
Direction | other | The offset direction to which the first direction should be added. |
bool | clockwise | If |
Returns
Type | Description |
---|---|
Direction |
Cardinal(int)
Returns the cardinal direction corresponding to the given integer.
The cardinal directions are numbered 0,...,5
, with 0
being E and values increasing counter-
clockwise.
Declaration
public static Direction Cardinal(int d)
Parameters
Type | Name | Description |
---|---|---|
int | d | The integer representing a cardinal direction. If negative, the result will be NONE. |
Returns
Type | Description |
---|---|
Direction | The cardinal direction identified by the integer |
DistanceTo(Direction, Direction, bool)
Returns the number of 30 degree rotations needed to make
direction d
match direction target
.
Declaration
public static int DistanceTo(this Direction d, Direction target, bool clockwise = false)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The direction to be rotated. |
Direction | target | The target direction to be matched. |
bool | clockwise | If |
Returns
Type | Description |
---|---|
int | The number of counter-clockwise or clockwise 30 degree rotations
necessary to align |
FromInitDir(Compass)
Translates the Initialization.Compass enum into the Direction enum.
Declaration
public static Direction FromInitDir(Initialization.Compass initDir)
Parameters
Type | Name | Description |
---|---|---|
Initialization.Compass | initDir | A compass direction specified in the Initialization.Compass enum. |
Returns
Type | Description |
---|---|
Direction | The Direction corresponding
to |
IsCardinal(Direction)
Checks if this is a cardinal direction.
See also IsSecondary(Direction).
Declaration
public static bool IsCardinal(this Direction d)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The direction to check. |
Returns
Type | Description |
---|---|
bool |
|
IsSecondary(Direction)
Checks if this is a secondary direction.
See also IsCardinal(Direction).
Declaration
public static bool IsSecondary(this Direction d)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The direction to check. |
Returns
Type | Description |
---|---|
bool |
|
Iterate30(Direction, int, bool)
Creates an array of consecutive cardinal and secondary directions.
Declaration
public static Direction[] Iterate30(Direction start, int number, bool clockwise = false)
Parameters
Type | Name | Description |
---|---|---|
Direction | start | The first element of the array. If the value is NONE, all directions in the array will be NONE. |
int | number | The number of elements in the array. The array will have length 0 for any value less than or equal to 0. If the value is greater than 12, the directions will start repeating. |
bool | clockwise | If |
Returns
Type | Description |
---|---|
Direction[] | An array containing |
Iterate60(Direction, int, bool)
Creates an array of consecutive cardinal or secondary directions.
Declaration
public static Direction[] Iterate60(Direction start, int number, bool clockwise = false)
Parameters
Type | Name | Description |
---|---|---|
Direction | start | The first element of the array. If this is a cardinal/secondary direction, all directions in the array will be cardinal/secondary. If the value is NONE, all directions will be NONE. |
int | number | The number of elements in the array. The array will have length 0 for any value less than or equal to 0. If the value is greater than 6, the directions will start repeating. |
bool | clockwise | If |
Returns
Type | Description |
---|---|
Direction[] | An array containing |
Opposite(Direction)
Returns the direction directly opposite to this direction.
If d
is (not) a cardinal direction, then
the result will also (not) be a cardinal direction.
Declaration
public static Direction Opposite(this Direction d)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The current direction. |
Returns
Type | Description |
---|---|
Direction | The direction directly opposite of |
Rotate30(Direction, int)
Returns the given direction rotated by 30 degrees times the given amount in counter-clockwise direction. Negative values rotate in clockwise direction.
If d
is (not) a cardinal direction, then
the result will also (not) be a cardinal direction if and
only if the given amount
is even. If
amount
is odd, one of d
and the result will be a cardinal direction and the other
one will not be a cardinal direction.
Declaration
public static Direction Rotate30(this Direction d, int amount)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The current direction. |
int | amount | The number of times to rotate by 30 degrees in clockwise direction. |
Returns
Type | Description |
---|---|
Direction | Direction |
Rotate60(Direction, int)
Returns the given direction rotated by 60 degrees times the given amount in counter-clockwise direction. Negative values rotate in clockwise direction.
If d
is (not) a cardinal direction, then
the result will also (not) be a cardinal direction.
Declaration
public static Direction Rotate60(this Direction d, int amount)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The current direction. |
int | amount | The number of times to rotate by 60 degrees in clockwise direction. |
Returns
Type | Description |
---|---|
Direction | Direction |
Secondary(int)
Returns the secondary direction corresponding to the given integer.
The secondary direction for integer i
is obtained by rotating
the cardinal direction with index i
counter-clockwise by 30
degrees.
Declaration
public static Direction Secondary(int d)
Parameters
Type | Name | Description |
---|---|---|
int | d | The integer representing a cardinal direction. If negative, the result will be NONE. |
Returns
Type | Description |
---|---|
Direction | The secondary direction corresponding to the cardinal
direction that is identified by the integer |
Subtract(Direction, Direction, bool)
Subtracts the given direction from this global direction. The current
direction is interpreted as the result of adding a rotation x
to
the given other direction, where x
can be clockwise or counter-
clockwise rotation. This method finds and returns x
. It can be
used to convert global directions to local directions.
Declaration
public static Direction Subtract(this Direction d, Direction other, bool clockwise = false)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The current global direction. |
Direction | other | The global direction used as offset. |
bool | clockwise | If |
Returns
Type | Description |
---|---|
Direction | A direction indicating the amoutn of rotation that must be added
to |
ToInt(Direction)
Maps this direction to its integer representation. Every cardinal
direction is mapped to the same value as the secondary direction
obtained by a 30 degree counter-clockwise rotation. Thus, there
are 6 pairs of directions, which are mapped to the integers
0,...,5
. The integer values increase with counter-
clockwise rotation. The special direction NONE
is represented by -1
.
Declaration
public static int ToInt(this Direction d)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | The direction to be mapped to an integer. |
Returns
Type | Description |
---|---|
int | The integer representing the given cardinal or secondary direction. |