Class Distance
Class representing methods of calculating distance on a grid. You cannot create instances of this class using a constructor -- instead this class contains static instances representing the various distance calculations.
Inheritance
Implements
Inherited Members
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
[Serializable]
public class Distance : IEquatable<Distance>
Remarks
Provides functions that calculate the distance between two points according to the distance measurement being used. Instances of Distance are also implicitly convertible to AdjacencyRule types (since an adjacency method is implied by a distance calculation), and they may also be explicitly casted to the appropriate 2D Radius types.
Fields
| Improve this Doc View SourceCHEBYSHEV
Represents chebyshev distance (equivalent to 8-way movement with no extra cost for diagonals).
Declaration
[NonSerialized]
public static Distance CHEBYSHEV
Field Value
Type | Description |
---|---|
Distance |
EUCLIDEAN
Represents euclidean distance (equivalent to 8-way movement with ~1.41 movement cost for diagonals).
Declaration
[NonSerialized]
public static Distance EUCLIDEAN
Field Value
Type | Description |
---|---|
Distance |
MANHATTAN
Represents manhattan distance (equivalent to 4-way, cardinal-only movement).
Declaration
[NonSerialized]
public static Distance MANHATTAN
Field Value
Type | Description |
---|---|
Distance |
Type
Enum value representing the method of calcuating distance -- useful for using Distance types in switch statements.
Declaration
public readonly Distance.Types Type
Field Value
Type | Description |
---|---|
Distance.Types |
Methods
| Improve this Doc View SourceCalculate(Coord)
Returns the distance between two locations, given the change in X and change in Y value (specified by the X and Y values of the given vector).
Declaration
public double Calculate(Coord deltaChange)
Parameters
Type | Name | Description |
---|---|---|
Coord | deltaChange | The delta-x and delta-y between the two locations. |
Returns
Type | Description |
---|---|
System.Double | The distance between two locations withe the given delta-change values. |
Calculate(Coord, Coord)
Returns the distance between the two (2D) points specified.
Declaration
public double Calculate(Coord start, Coord end)
Parameters
Type | Name | Description |
---|---|---|
Coord | start | Starting point. |
Coord | end | Ending point. |
Returns
Type | Description |
---|---|
System.Double | The distance between the two points. |
Calculate(Double, Double)
Returns the distance between two locations, given the change in X and change in Y value.
Declaration
public double Calculate(double dx, double dy)
Parameters
Type | Name | Description |
---|---|---|
System.Double | dx | The delta-x between the two locations. |
System.Double | dy | The delta-y between the two locations. |
Returns
Type | Description |
---|---|
System.Double | The distance between two locations with the given delta-change values. |
Calculate(Double, Double, Double)
Returns the distance between two locations, given the change in X, Y, and Z value.
Declaration
public double Calculate(double dx, double dy, double dz)
Parameters
Type | Name | Description |
---|---|---|
System.Double | dx | The delta-x between the two locations. |
System.Double | dy | The delta-y between the two locations. |
System.Double | dz | The delta-z between the two locations. |
Returns
Type | Description |
---|---|
System.Double | The distance between two locations with the given delta-change values. |
Calculate(Double, Double, Double, Double)
Returns the distance between the two (2D) points specified.
Declaration
public double Calculate(double startX, double startY, double endX, double endY)
Parameters
Type | Name | Description |
---|---|---|
System.Double | startX | X-Coordinate of the starting point. |
System.Double | startY | Y-Coordinate of the starting point. |
System.Double | endX | X-Coordinate of the ending point. |
System.Double | endY | Y-Coordinate of the ending point. |
Returns
Type | Description |
---|---|
System.Double | The distance between the two points. |
Calculate(Double, Double, Double, Double, Double, Double)
Returns the distance between the two (3D) points specified.
Declaration
public double Calculate(double startX, double startY, double startZ, double endX, double endY, double endZ)
Parameters
Type | Name | Description |
---|---|---|
System.Double | startX | X-Coordinate of the starting point. |
System.Double | startY | Y-Coordinate of the starting point. |
System.Double | startZ | Z-Coordinate of the starting point. |
System.Double | endX | X-Coordinate of the ending point. |
System.Double | endY | Y-Coordinate of the ending point. |
System.Double | endZ | Z-Coordinate of the ending point. |
Returns
Type | Description |
---|---|
System.Double | The distance between the two points. |
Calculate(Int32, Int32)
Returns the distance between two locations, given the change in X and change in Y value.
Declaration
public double Calculate(int dx, int dy)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dx | The delta-x between the two locations. |
System.Int32 | dy | The delta-y between the two locations. |
Returns
Type | Description |
---|---|
System.Double | The distance between two locations with the given delta-change values. |
Calculate(Int32, Int32, Int32)
Returns the distance between two locations, given the change in X, Y, and Z value.
Declaration
public double Calculate(int dx, int dy, int dz)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dx | The delta-x between the two locations. |
System.Int32 | dy | The delta-y between the two locations. |
System.Int32 | dz | The delta-z between the two locations. |
Returns
Type | Description |
---|---|
System.Double | The distance between the locations with the given delta-change values. |
Calculate(Int32, Int32, Int32, Int32)
Returns the distance between the two (2D) points specified.
Declaration
public double Calculate(int startX, int startY, int endX, int endY)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startX | X-Coordinate of the starting point. |
System.Int32 | startY | Y-Coordinate of the starting point. |
System.Int32 | endX | X-Coordinate of the ending point. |
System.Int32 | endY | Y-Coordinate of the ending point. |
Returns
Type | Description |
---|---|
System.Double | The distance between the two points. |
Calculate(Int32, Int32, Int32, Int32, Int32, Int32)
Returns the distance between the two (3D) points specified.
Declaration
public double Calculate(int startX, int startY, int startZ, int endX, int endY, int endZ)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startX | X-Coordinate of the starting point. |
System.Int32 | startY | Y-Coordinate of the starting point. |
System.Int32 | startZ | Z-Coordinate of the starting point. |
System.Int32 | endX | X-Coordinate of the ending point. |
System.Int32 | endY | Y-Coordinate of the ending point. |
System.Int32 | endZ | Z-Coordinate of the ending point. |
Returns
Type | Description |
---|---|
System.Double | The distance between the two points. |
Equals(Distance)
Compares the current Distance to the one given.
Declaration
public bool Equals(Distance other)
Parameters
Type | Name | Description |
---|---|---|
Distance | other |
Returns
Type | Description |
---|---|
System.Boolean | True if the given Distance has the same Type, false otherwise. |
Equals(Object)
Compares the current Distance 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 Distance with the same Type, false otherwise. |
Overrides
GetHashCode()
Returns a hash-value for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
ToDistance(Distance.Types)
Gets the Distance class instance representing the distance type specified.
Declaration
public static Distance ToDistance(Distance.Types distanceType)
Parameters
Type | Name | Description |
---|---|---|
Distance.Types | distanceType | The enum value for the distance calculation method. |
Returns
Type | Description |
---|---|
Distance | The Distance class representing the given distance calculation. |
ToString()
Returns a string representation of the distance calculation method represented.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of the distance method represented. |
Overrides
Operators
| Improve this Doc View SourceEquality(Distance, Distance)
Compares the two Distance instances.
Declaration
public static bool operator ==(Distance lhs, Distance rhs)
Parameters
Type | Name | Description |
---|---|---|
Distance | lhs | |
Distance | rhs |
Returns
Type | Description |
---|---|
System.Boolean | True if the two given Distance instances have the same Type, false otherwise. |
Explicit(Distance to Radius)
Allows explicit casting to Radius type.
Declaration
public static explicit operator Radius(Distance distance)
Parameters
Type | Name | Description |
---|---|---|
Distance | distance |
Returns
Type | Description |
---|---|
Radius |
Remarks
The 2D radius shape corresponding to the definition of a radius according to the distance calculation casted will be returned.
Implicit(Distance to AdjacencyRule)
Allows implicit casting to the AdjacencyRule type.
Declaration
public static implicit operator AdjacencyRule(Distance distance)
Parameters
Type | Name | Description |
---|---|---|
Distance | distance |
Returns
Type | Description |
---|---|
AdjacencyRule |
Remarks
The adjacency rule corresponding to the definition of a adjacency according to the distance calculation casted will be returned.
Inequality(Distance, Distance)
Compares the two Distance instances.
Declaration
public static bool operator !=(Distance lhs, Distance rhs)
Parameters
Type | Name | Description |
---|---|---|
Distance | lhs | |
Distance | rhs |
Returns
Type | Description |
---|---|
System.Boolean | True if the two given Distance instances do NOT have the same Type, false otherwise. |