Struct HexCornerCoord
Represents a canonical corner vertex in a hexagonal grid, identified by the anchor hex coordinate and the corner position (N or S).
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public readonly struct HexCornerCoord : IEquatable<HexCornerCoord>
Remarks
Every interior corner vertex of a hex grid is shared by exactly three hexes. The canonical form avoids duplication by always expressing the corner as the N or S vertex of a specific anchor cell. The remaining four corner positions of any given hex are the N or S corners of its neighbors. See HexCornerPosition for the exact neighbor sharing relationships.
Use GetCellsNonAlloc(HexCornerCoord, Span<HexCoord>) to retrieve the three hexes that meet at this corner, GetEdgesNonAlloc(HexCornerCoord, Span<HexEdgeCoord>) to retrieve the three edges that radiate from this corner, and GetCornersOfCellNonAlloc(HexCoord, Span<HexCornerCoord>) to enumerate all six corners of a given cell.
HexCornerCoord is a value type safe for use as a dictionary key. Use HexCornerMap<TData> for per-corner data storage.
Constructors
HexCornerCoord(int, int, HexCornerPosition)
Creates a new hex corner coordinate from an anchor hex and a canonical corner position.
Declaration
public HexCornerCoord(int q, int r, HexCornerPosition position)
Parameters
| Type | Name | Description |
|---|---|---|
| int | q | The Q axis value of the anchor hex. |
| int | r | The R axis value of the anchor hex. |
| HexCornerPosition | position | The corner position relative to the anchor hex. Should be N or S to form a canonical corner coordinate. |
Fields
Position
The corner position relative to the anchor hex (N = north/top, S = south/bottom). Always either N or S.
Declaration
public readonly HexCornerPosition Position
Field Value
| Type | Description |
|---|---|
| HexCornerPosition |
Q
The Q axis value of the anchor hex that owns this corner in the canonical representation.
Declaration
public readonly int Q
Field Value
| Type | Description |
|---|---|
| int |
R
The R axis value of the anchor hex that owns this corner in the canonical representation.
Declaration
public readonly int R
Field Value
| Type | Description |
|---|---|
| int |
Methods
Equals(HexCornerCoord)
Determines whether this corner coordinate equals another corner coordinate.
Declaration
public bool Equals(HexCornerCoord other)
Parameters
| Type | Name | Description |
|---|---|---|
| HexCornerCoord | other | The corner coordinate to compare with. |
Returns
| Type | Description |
|---|---|
| bool | True if all fields are equal. |
Equals(object)
Determines whether this corner coordinate equals another object.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with. |
Returns
| Type | Description |
|---|---|
| bool | True if the object is a HexCornerCoord with equal values. |
Overrides
GetCellsNonAlloc(HexCornerCoord, Span<HexCoord>)
Writes the three hex cells that share this corner vertex into the provided buffer.
Declaration
public static int GetCellsNonAlloc(HexCornerCoord corner, Span<HexCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| HexCornerCoord | corner | The canonical corner coordinate. |
| Span<HexCoord> | buffer | A span of at least 3 elements to receive the cell coordinates.
|
Returns
| Type | Description |
|---|---|
| int | The number of cells written: 3 if the buffer is large enough, 0 otherwise. |
Remarks
The three cells for each position are:
- N corner of (q, r): cells (q, r), (q+1, r-1), (q, r-1).
- S corner of (q, r): cells (q, r), (q-1, r+1), (q, r+1).
If buffer has fewer than 3 elements, no data is written.
GetCornersOfCellNonAlloc(HexCoord, Span<HexCornerCoord>)
Writes the six canonical HexCornerCoord values for all corners of the given hex cell into the provided buffer. Each corner is expressed in its canonical form (anchor hex with an N or S position).
Declaration
public static int GetCornersOfCellNonAlloc(HexCoord cell, Span<HexCornerCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| HexCoord | cell | The hex cell whose corners to enumerate. |
| Span<HexCornerCoord> | buffer | A span of at least 6 elements to receive the corner coordinates. |
Returns
| Type | Description |
|---|---|
| int | The number of corners written: 6 if the buffer is large enough, 0 otherwise. |
Remarks
The six canonical corners of cell (q, r) in buffer order are:
- (q, r, N) - own north corner.
- (q+1, r-1, S) - NE neighbor south corner.
- (q, r+1, N) - SE neighbor north corner.
- (q, r, S) - own south corner.
- (q-1, r+1, N) - SW neighbor north corner.
- (q, r-1, S) - NW neighbor south corner.
If buffer has fewer than 6 elements, no data is written.
GetEdgesNonAlloc(HexCornerCoord, Span<HexEdgeCoord>)
Writes the three HexEdgeCoord values for the edges that meet at this corner into the provided buffer.
Declaration
public static int GetEdgesNonAlloc(HexCornerCoord corner, Span<HexEdgeCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| HexCornerCoord | corner | The canonical corner coordinate. |
| Span<HexEdgeCoord> | buffer | A span of at least 3 elements to receive the edge coordinates. |
Returns
| Type | Description |
|---|---|
| int | The number of edges written: 3 if the buffer is large enough, 0 otherwise. |
Remarks
The three edges for each position are:
- N corner of (q, r): edges (q, r, NE), (q, r, NW), (q, r-1, E).
- S corner of (q, r): edges (q-1, r+1, NE), (q, r+1, NW), (q-1, r+1, E).
If buffer has fewer than 3 elements, no data is written.
GetHashCode()
Returns a hash code for this corner coordinate.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code based on Q, R, and position. |
Overrides
ToString()
Returns a string representation of this corner coordinate.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string in the format "(Q, R, Position)". |
Overrides
Operators
operator ==(HexCornerCoord, HexCornerCoord)
Returns true if left and right
have equal Q, R, and Position values.
Declaration
public static bool operator ==(HexCornerCoord left, HexCornerCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| HexCornerCoord | left | The left operand. |
| HexCornerCoord | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(HexCornerCoord, HexCornerCoord)
Returns true if left and right
differ in Q, R, or Position.
Declaration
public static bool operator !=(HexCornerCoord left, HexCornerCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| HexCornerCoord | left | The left operand. |
| HexCornerCoord | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |