Class Direction
Represents the concept of a "direction" on a grid, and "defines" the coordinate plane GoRogue uses via the YIncreasesUpward flag. Interacts with Coord and other supported library's equivalent types to allow easy translation of positions in a direction, and contains numerous helper functions for retrieving directions in various orders, getting direction closest to a line, etc.
Inheritance
Implements
Inherited Members
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
[Serializable]
public class Direction : IEquatable<Direction>
Remarks
The static YIncreasesUpward flag defines the way that many GoRogue algorithms interpret the coordinate plane. By default, this flag is false, meaning that the y-value of positions is assumed to DECREASE as you proceed in the direction defined by UP, and increase as you go downward. If the coordinate plane is displayed on the screen, the origin would be the top left corner. This default setting matches the typical console/computer graphic definition of the coordinate plane. Setting the flag to true inverts this, so that the y-value of positions INCREASES as you proceed in the direction defined by UP. This places the origin in the bottom left corner, and matches a typical mathmatical definition of a euclidean coordinate plane, as well as the scene coordinate plane defined by Unity and other game engines.
Fields
| Improve this Doc View SourceDeltaX
Change in x-value represented by this direction.
Declaration
public readonly int DeltaX
Field Value
Type | Description |
---|---|
System.Int32 |
DeltaY
Change in y-value represented by this direction.
Declaration
public readonly int DeltaY
Field Value
Type | Description |
---|---|
System.Int32 |
Type
Enum type corresponding to direction being represented.
Declaration
public readonly Direction.Types Type
Field Value
Type | Description |
---|---|
Direction.Types |
Properties
| Improve this Doc View SourceDOWN
Down direction.
Declaration
public static Direction DOWN { get; }
Property Value
Type | Description |
---|---|
Direction |
DOWN_LEFT
Down-left direction.
Declaration
public static Direction DOWN_LEFT { get; }
Property Value
Type | Description |
---|---|
Direction |
DOWN_RIGHT
Down-right direction.
Declaration
public static Direction DOWN_RIGHT { get; }
Property Value
Type | Description |
---|---|
Direction |
LEFT
Left direction.
Declaration
public static Direction LEFT { get; }
Property Value
Type | Description |
---|---|
Direction |
NONE
No direction.
Declaration
public static Direction NONE { get; }
Property Value
Type | Description |
---|---|
Direction |
RIGHT
Right direction.
Declaration
public static Direction RIGHT { get; }
Property Value
Type | Description |
---|---|
Direction |
UP
Up direction.
Declaration
public static Direction UP { get; }
Property Value
Type | Description |
---|---|
Direction |
UP_LEFT
Up-left direction.
Declaration
public static Direction UP_LEFT { get; }
Property Value
Type | Description |
---|---|
Direction |
UP_RIGHT
Up-right direction.
Declaration
public static Direction UP_RIGHT { get; }
Property Value
Type | Description |
---|---|
Direction |
YIncreasesUpward
Whether or not a positive y-value indicates an upward change. If true, Directions with an upwards component represent a positive change in y-value, and ones with downward components represent a negative change in y-value. Setting this to false (which is the default) inverts this.
Declaration
public static bool YIncreasesUpward { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceEquals(Direction)
Compares the current Direction to the one given.
Declaration
public bool Equals(Direction other)
Parameters
Type | Name | Description |
---|---|---|
Direction | other |
Returns
Type | Description |
---|---|
System.Boolean | True if the given Direction has the same type and delta-y/delta-x values, false otherwise. |
Equals(Object)
Compares the current Direction to the object given.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj |
Returns
Type | Description |
---|---|
System.Boolean | True if the given object is a Direction with the same Type/dx/dy values, false otherwise. |
Overrides
GetCardinalDirection(Coord)
Returns the cardinal direction that most closely matches the degree heading of a line with the given delta-change values. Rounds clockwise if exactly on a diagonal. Similar to GetDirection(Coord), except this function returns only cardinal directions.
Declaration
public static Direction GetCardinalDirection(Coord deltaChange)
Parameters
Type | Name | Description |
---|---|---|
Coord | deltaChange | Vector representing the change in x and change in y across the line (deltaChange.X is the change in x, deltaChange.Y is the change in y). |
Returns
Type | Description |
---|---|
Direction | The cardinal direction that most closely matches the degree heading of the given line. |
GetCardinalDirection(Coord, Coord)
Returns the cardinal direction that most closely matches the degree heading of the given line. Rounds clockwise if the heading is exactly on a diagonal direction. Similar to GetDirection(Coord, Coord), except this function returns only cardinal directions.
Declaration
public static Direction GetCardinalDirection(Coord start, Coord end)
Parameters
Type | Name | Description |
---|---|---|
Coord | start | Starting coordinate of the line. |
Coord | end | Ending coordinate of the line. |
Returns
Type | Description |
---|---|
Direction | The cardinal direction that most closely matches the heading indicated by the given line. |
GetCardinalDirection(Int32, Int32)
Returns the cardinal direction that most closely matches the degree heading of a line with the given dx and dy values. Rounds clockwise if exactly on a diagonal direction. Similar to GetDirection(Int32, Int32), except this function returns only cardinal directions.
Declaration
public static Direction GetCardinalDirection(int dx, int dy)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dx | The change in x-values across the line. |
System.Int32 | dy | The change in x-values across the line. |
Returns
Type | Description |
---|---|
Direction | The cardinal direction that most closely matches the degree heading of the given line. |
GetCardinalDirection(Int32, Int32, Int32, Int32)
Returns the cardinal direction that most closely matches the degree heading of the given line. Rounds clockwise if the heading is exactly on a diagonal direction. Similar to GetDirection(Int32, Int32, Int32, Int32), except this function returns only cardinal directions.
Declaration
public static Direction GetCardinalDirection(int startX, int startY, int endX, int endY)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startX | X-coordinate of the starting position of the line. |
System.Int32 | startY | Y-coordinate of the starting position of the line. |
System.Int32 | endX | X-coordinate of the ending position of the line. |
System.Int32 | endY | Y-coordinate of the ending position of the line. |
Returns
Type | Description |
---|---|
Direction | The cardinal direction that most closely matches the heading indicated by the given line. |
GetDirection(Coord)
Returns the direction that most closely matches the degree heading of a line with the given delta-change values. Rounds clockwise if the heading is exactly between two directions.
Declaration
public static Direction GetDirection(Coord deltaChange)
Parameters
Type | Name | Description |
---|---|---|
Coord | deltaChange | Vector representing the change in x and change in y across the line (deltaChange.X is the change in x, deltaChange.Y is the change in y). |
Returns
Type | Description |
---|---|
Direction | The direction that most closely matches the heading indicated by the given input. |
GetDirection(Coord, Coord)
Returns the direction that most closely matches the degree heading of the given line. Rounds clockwise if the heading is exactly between two directions.
Declaration
public static Direction GetDirection(Coord start, Coord end)
Parameters
Type | Name | Description |
---|---|---|
Coord | start | Starting coordinate of the line. |
Coord | end | Ending coordinate of the line. |
Returns
Type | Description |
---|---|
Direction | The direction that most closely matches the heading indicated by the given line. |
GetDirection(Int32, Int32)
Returns the direction that most closely matches the degree heading of a line with the given dx and dy values. Rounds clockwise if the heading is exactly between two directions.
Declaration
public static Direction GetDirection(int dx, int dy)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dx | The change in x-values across the line. |
System.Int32 | dy | The change in y-values across the line. |
Returns
Type | Description |
---|---|
Direction | The direction that most closely matches the heading indicated by the given input. |
GetDirection(Int32, Int32, Int32, Int32)
Returns the direction that most closely matches the degree heading of the given line. Rounds clockwise if the heading is exactly between two directions.
Declaration
public static Direction GetDirection(int startX, int startY, int endX, int endY)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startX | X-coordinate of the starting position of the line. |
System.Int32 | startY | Y-coordinate of the starting position of the line. |
System.Int32 | endX | X-coordinate of the ending position of the line. |
System.Int32 | endY | Y-coordinate of the ending position of the line. |
Returns
Type | Description |
---|---|
Direction | The direction that most closely matches the heading indicated by the given line. |
GetHashCode()
Returns a hash-value for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
ToDirection(Direction.Types)
Gets the Direction class instance representing the direction type specified.
Declaration
public static Direction ToDirection(Direction.Types directionType)
Parameters
Type | Name | Description |
---|---|---|
Direction.Types | directionType | The enum value for the direction. |
Returns
Type | Description |
---|---|
Direction | The direction class representing the given direction. |
ToString()
Writes the string (eg. "UP", "UP_RIGHT", etc.) for the direction.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | String representation of the direction. |
Overrides
Operators
| Improve this Doc View SourceAddition(Direction, Int32)
Moves the direction clockwise i
times.
Declaration
public static Direction operator +(Direction d, int i)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | |
System.Int32 | i |
Returns
Type | Description |
---|---|
Direction | The given direction moved clockwise |
Addition(Point, Direction)
Translates the given position by one unit in the given direction.
Declaration
public static Point operator +(Point p, Direction d)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Xna.Framework.Point | p | |
Direction | d |
Returns
Type | Description |
---|---|
Microsoft.Xna.Framework.Point | Position (p.X + d.DeltaX, p.Y + d.DeltaY). |
Addition(Point, Direction)
Translates the given position by one unit in the given direction.
Declaration
public static Point operator +(Point p, Direction d)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Point | p | |
Direction | d |
Returns
Type | Description |
---|---|
System.Drawing.Point | Position (p.X + d.DeltaX, p.Y + d.DeltaY). |
Addition((Int32 x, Int32 y), Direction)
Translates the given position by one unit in the given direction.
Declaration
public static (int x, int y) operator +((int x, int y) tuple, Direction d)
Parameters
Type | Name | Description |
---|---|---|
System.ValueTuple<System.Int32, System.Int32> | tuple | |
Direction | d |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Int32, System.Int32> | Tuple (tuple.y + d.DeltaX, tuple.y + d.DeltaY). |
Decrement(Direction)
Moves the direction counter-clockwise by one.
Declaration
public static Direction operator --(Direction d)
Parameters
Type | Name | Description |
---|---|---|
Direction | d |
Returns
Type | Description |
---|---|
Direction | The direction one unit counterclockwise of |
Equality(Direction, Direction)
Compares the two Direction instances.
Declaration
public static bool operator ==(Direction lhs, Direction rhs)
Parameters
Type | Name | Description |
---|---|---|
Direction | lhs | |
Direction | rhs |
Returns
Type | Description |
---|---|
System.Boolean | True if the two given Direction instances have the same Type and delta values, false otherwise. |
Increment(Direction)
Moves the direction clockwise by one.
Declaration
public static Direction operator ++(Direction d)
Parameters
Type | Name | Description |
---|---|---|
Direction | d |
Returns
Type | Description |
---|---|
Direction | The direction one unit clockwise of |
Inequality(Direction, Direction)
Compares the two BoundedRectangle instances.
Declaration
public static bool operator !=(Direction lhs, Direction rhs)
Parameters
Type | Name | Description |
---|---|---|
Direction | lhs | |
Direction | rhs |
Returns
Type | Description |
---|---|
System.Boolean | True if the two given Direction instances do NOT have the same Type and delta values, false otherwise. |
Subtraction(Direction, Int32)
Moves the direction counter-clockwise i
times.
Declaration
public static Direction operator -(Direction d, int i)
Parameters
Type | Name | Description |
---|---|---|
Direction | d | |
System.Int32 | i |
Returns
Type | Description |
---|---|
Direction | The given direction moved counter-clockwise |