Show / Hide Table of Contents

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
System.Object
Direction
Implements
System.IEquatable<Direction>
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
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 Source

DeltaX

Change in x-value represented by this direction.

Declaration
public readonly int DeltaX
Field Value
Type Description
System.Int32
| Improve this Doc View Source

DeltaY

Change in y-value represented by this direction.

Declaration
public readonly int DeltaY
Field Value
Type Description
System.Int32
| Improve this Doc View Source

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 Source

DOWN

Down direction.

Declaration
public static Direction DOWN { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

DOWN_LEFT

Down-left direction.

Declaration
public static Direction DOWN_LEFT { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

DOWN_RIGHT

Down-right direction.

Declaration
public static Direction DOWN_RIGHT { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

LEFT

Left direction.

Declaration
public static Direction LEFT { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

NONE

No direction.

Declaration
public static Direction NONE { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

RIGHT

Right direction.

Declaration
public static Direction RIGHT { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

UP

Up direction.

Declaration
public static Direction UP { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

UP_LEFT

Up-left direction.

Declaration
public static Direction UP_LEFT { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

UP_RIGHT

Up-right direction.

Declaration
public static Direction UP_RIGHT { get; }
Property Value
Type Description
Direction
| Improve this Doc View Source

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 Source

Equals(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.

| Improve this Doc View Source

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
System.Object.Equals(System.Object)
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

GetHashCode()

Returns a hash-value for this object.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32
Overrides
System.Object.GetHashCode()
| Improve this Doc View Source

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.

| Improve this Doc View Source

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
System.Object.ToString()

Operators

| Improve this Doc View Source

Addition(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 i times.

| Improve this Doc View Source

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).

| Improve this Doc View Source

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).

| Improve this Doc View Source

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).

| Improve this Doc View Source

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 d.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 d.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 i times.

Implements

System.IEquatable<T>

Extension Methods

Utility.Yield<T>(T)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX