Struct HexPoint
Represents a cubic coordinate in three dimensions (Q, R, and S) used to identify a location in a grid of hexagons.
Inherited Members
Namespace: Rebus
Assembly: Rebus.dll
Syntax
[MessagePackObject(false)]
public readonly struct HexPoint : IComparable, IComparable<HexPoint>, IEquatable<HexPoint>
Remarks
The implementation of this struct was inspired by and based on this article by Amit Patel.
Constructors
HexPoint(Int32, Int32)
Initializes a new instance of the HexPoint struct.
Declaration
public HexPoint(int q, int r)
Parameters
Type | Name | Description |
---|---|---|
Int32 | q | The Q coordinate. |
Int32 | r | The R coordinate. |
Fields
Empty
Specifies the coordinate whose three axes are zero.
Declaration
public static readonly HexPoint Empty
Field Value
Type | Description |
---|---|
HexPoint | The coordinate (0, 0, 0). |
Properties
Q
Gets the Q coordinate.
Declaration
[Key(0)]
public readonly int Q { get; }
Property Value
Type | Description |
---|---|
Int32 | The Q coordinate. The default is 0. |
R
Gets the R coordinate.
Declaration
[Key(1)]
public readonly int R { get; }
Property Value
Type | Description |
---|---|
Int32 | The R coordinate. The default is 0. |
S
Gets the S coordinate.
Declaration
[IgnoreMember]
public readonly int S { get; }
Property Value
Type | Description |
---|---|
Int32 | The S coordinate. The default is 0. |
Methods
Add(HexPoint)
Declaration
public readonly HexPoint Add(HexPoint other)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | other | A positive or negative hexagonal coordinate. |
Returns
Type | Description |
---|---|
HexPoint | An object whose value is the sum of the hexagonal coordinates represented by this instance and the |
CompareTo(HexPoint)
Declaration
public readonly int CompareTo(HexPoint other)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | other |
Returns
Type | Description |
---|---|
Int32 |
CompareTo(Object)
Declaration
public readonly int CompareTo(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Int32 |
Distance(HexPoint, HexPoint)
Gets the distance between two hexagonal coordinates.
Declaration
public static int Distance(HexPoint value1, HexPoint value2)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | value1 | The first value. |
HexPoint | value2 | The second value. |
Returns
Type | Description |
---|---|
Int32 | The distance between |
Equals(HexPoint)
Declaration
public readonly bool Equals(HexPoint other)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | other |
Returns
Type | Description |
---|---|
Boolean |
Equals(Object)
Declaration
public override readonly bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Boolean |
Overrides
GetHashCode()
Declaration
public override readonly int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
Overrides
Multiply(Int32)
Returns the value that results from multiplying the specified factor by the value of this instance.
Declaration
public readonly HexPoint Multiply(int factor)
Parameters
Type | Name | Description |
---|---|---|
Int32 | factor | The factor to multiply. |
Returns
Type | Description |
---|---|
HexPoint | A hexagonal coordinate that is equal to this instance times the |
Neighbors()
Gets the six coordinates adjacent to this instance.
Declaration
public readonly IEnumerable<HexPoint> Neighbors()
Returns
Type | Description |
---|---|
IEnumerable<HexPoint> | The neighboring coordinates. |
Range(Int32)
Gets the coordinates within a hexagonal range.
Declaration
public readonly IEnumerable<HexPoint> Range(int radius)
Parameters
Type | Name | Description |
---|---|---|
Int32 | radius | The radius of the range. |
Returns
Type | Description |
---|---|
IEnumerable<HexPoint> | The coordinates within the range defined by the given |
Ring(Int32)
Gets the coordinates within a hexagonal ring.
Declaration
public readonly IEnumerable<HexPoint> Ring(int radius)
Parameters
Type | Name | Description |
---|---|---|
Int32 | radius | The radius of the ring. |
Returns
Type | Description |
---|---|
IEnumerable<HexPoint> | The coordinates within the ring defined by the given |
Spiral(Int32)
Gets the coordinates within a hexagonal spiral.
Declaration
public readonly IEnumerable<HexPoint> Spiral(int radius)
Parameters
Type | Name | Description |
---|---|---|
Int32 | radius | The radius of the spiral. |
Returns
Type | Description |
---|---|
IEnumerable<HexPoint> | The coordinates within the spiral defined by the given |
Subtract(HexPoint)
Returns the value that results from subtracting the specified hexagonal coordinate from the value of this instance.
Declaration
public readonly HexPoint Subtract(HexPoint other)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | other | The hexagonal coordinate to subtract. |
Returns
Type | Description |
---|---|
HexPoint | A hexagonal coordinate that is equal to this instance minus the |
ToString()
Declaration
public override readonly string ToString()
Returns
Type | Description |
---|---|
String |
Overrides
Operators
Addition(HexPoint, HexPoint)
Adds a specified coordinate to another specified coordinate.
Declaration
public static HexPoint operator +(HexPoint left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The first coordinate to add. |
HexPoint | right | The second coordinate to add. |
Returns
Type | Description |
---|---|
HexPoint | The sum of |
Equality(HexPoint, HexPoint)
Returns a value that indicates whether two coordinates are equal.
Declaration
public static bool operator ==(HexPoint left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The first coordinate to compare. |
HexPoint | right | The second coordinate to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
GreaterThan(HexPoint, HexPoint)
Returns a value that indicates whether a specified value is greater than another specified value.
Declaration
public static bool operator>(HexPoint left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The first value to compare. |
HexPoint | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
GreaterThanOrEqual(HexPoint, HexPoint)
Returns a value that indicates whether a specified value is greater than or equal to another specified value.
Declaration
public static bool operator >=(HexPoint left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The first value to compare. |
HexPoint | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
Inequality(HexPoint, HexPoint)
Returns a value that indicates whether two coordinates are not equal.
Declaration
public static bool operator !=(HexPoint left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The first coordinate to compare. |
HexPoint | right | The second coordinate to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
LessThan(HexPoint, HexPoint)
Returns a value that indicates whether a specified value is less than another specified value.
Declaration
public static bool operator <(HexPoint left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The first value to compare. |
HexPoint | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
LessThanOrEqual(HexPoint, HexPoint)
Returns a value that indicates whether a specified value is less than or equal to another specified value.
Declaration
public static bool operator <=(HexPoint left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The first value to compare. |
HexPoint | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
Multiply(HexPoint, Int32)
Multiplies a specified coordinate by a number.
Declaration
public static HexPoint operator *(HexPoint left, int right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The coordinate to multiply. |
Int32 | right | The number to multiply. |
Returns
Type | Description |
---|---|
HexPoint | The product of |
Multiply(Int32, HexPoint)
Multiplies a number by a specified coordinate.
Declaration
public static HexPoint operator *(int left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
Int32 | left | The number to multiply. |
HexPoint | right | The coordinate to multiply. |
Returns
Type | Description |
---|---|
HexPoint | The product of |
Subtraction(HexPoint, HexPoint)
Subtracts a specified coordinate from another specified coordinate.
Declaration
public static HexPoint operator -(HexPoint left, HexPoint right)
Parameters
Type | Name | Description |
---|---|---|
HexPoint | left | The value to subtract from (the minuend). |
HexPoint | right | The value to subtract (the subtrahend). |
Returns
Type | Description |
---|---|
HexPoint | The result of subtracting |