Struct TriCoord
Immutable coordinate for a cell in a triangular grid, expressed in three-axis lane
coordinates (A, B, C).
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public readonly struct TriCoord : IEquatable<TriCoord>
Remarks
A triangular tiling can be described by three families of parallel lines - the A, B, and C lanes - each at 60-degree angles to each other. Each triangle is uniquely identified by which lane-strips it falls inside:
- Downward triangle (A + B + C = 1): the flat edge faces upward; check with IsDownward.
- Upward triangle (A + B + C = 2): the apex points upward; check with IsUpward.
The distance metric for this coordinate system is the sum of absolute component differences: |ΔA| + |ΔB| + |ΔC|. Use Distance(TriCoord, TriCoord) or DistanceTo(TriCoord) to compute it.
To retrieve the three edge-sharing neighbor cells, use GetEdgeNeighbors(TriCoord, Span<TriCoord>). For world-space conversions, use a TriGridLayout.
Constructors
TriCoord(int, int, int)
Creates a new triangle grid coordinate with the specified lane values.
Declaration
public TriCoord(int a, int b, int c)
Parameters
| Type | Name | Description |
|---|---|---|
| int | a | The A lane value for the new coordinate. |
| int | b | The B lane value for the new coordinate. |
| int | c | The C lane value for the new coordinate. For a downward triangle,
|
Fields
A
The A lane value. Represents which strip along the A-axis family of lines this triangle occupies.
Declaration
public readonly int A
Field Value
| Type | Description |
|---|---|
| int |
B
The B lane value. Represents which strip along the B-axis family of lines this triangle occupies.
Declaration
public readonly int B
Field Value
| Type | Description |
|---|---|
| int |
C
The C lane value. Represents which strip along the C-axis family of lines this triangle occupies.
Declaration
public readonly int C
Field Value
| Type | Description |
|---|---|
| int |
Properties
IsDownward
Gets a value indicating whether this triangle points downward (A + B + C = 1).
Declaration
public bool IsDownward { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
IsUpward
Gets a value indicating whether this triangle points upward (A + B + C = 2).
Declaration
public bool IsUpward { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
Distance(TriCoord, TriCoord)
Computes the triangular-grid distance between two coordinates as the sum of absolute component differences: |ΔA| + |ΔB| + |ΔC|.
Declaration
public static int Distance(TriCoord a, TriCoord b)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | a | The first triangle coordinate. |
| TriCoord | b | The second triangle coordinate. |
Returns
| Type | Description |
|---|---|
| int | A non-negative integer representing the distance between |
Remarks
This metric counts the minimum number of edge-crossing steps required to travel from one triangle to another, which equals one step per lane boundary crossed.
DistanceTo(TriCoord)
Computes the triangular-grid distance from this coordinate to another.
Declaration
public int DistanceTo(TriCoord other)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | other | The target triangle coordinate. |
Returns
| Type | Description |
|---|---|
| int | A non-negative integer equal to |
See Also
Equals(TriCoord)
Determines whether this coordinate equals another coordinate.
Declaration
public bool Equals(TriCoord other)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | other | The coordinate to compare with. |
Returns
| Type | Description |
|---|---|
| bool | True if all three lane values are equal. |
Equals(object)
Determines whether this 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 TriCoord with equal values. |
Overrides
GetEdgeNeighbors(TriCoord, Span<TriCoord>)
Writes the three edge-sharing neighbors of the specified triangle into the provided buffer without allocating.
Declaration
public static int GetEdgeNeighbors(TriCoord coord, Span<TriCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | coord | The triangle coordinate whose neighbors are requested. |
| Span<TriCoord> | buffer | A span of at least 3 elements to receive the neighbor coordinates. If the span is smaller than 3 no neighbors are written and 0 is returned. |
Returns
| Type | Description |
|---|---|
| int | The number of neighbors written into |
Remarks
Every triangle in the tiling has exactly three edge-sharing neighbors, one along each lane axis:
-
Upward triangle (A + B + C = 2): neighbors are obtained by
decrementing each component by 1 individually -
(A-1, B, C),(A, B-1, C),(A, B, C-1). -
Downward triangle (A + B + C = 1): neighbors are obtained by
incrementing each component by 1 individually -
(A+1, B, C),(A, B+1, C),(A, B, C+1).
This method does not clip to any grid bounds. Use GetNeighborsNonAlloc(TriCoord, Span<TriCoord>) or GetNeighborsNonAlloc(TriCoord, Span<TriCoord>) to filter results to in-bounds or populated cells.
GetHashCode()
Returns a hash code for this coordinate.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code based on A, B, and C. |
Overrides
ToString()
Returns a human-readable string representation of this coordinate.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string in the format |
Overrides
Operators
operator +(TriCoord, TriCoord)
Returns a new coordinate whose lane values are the component-wise sum of
a and b.
Declaration
public static TriCoord operator +(TriCoord a, TriCoord b)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | a | The first coordinate. |
| TriCoord | b | The second coordinate. |
Returns
| Type | Description |
|---|---|
| TriCoord | A new TriCoord equal to |
operator ==(TriCoord, TriCoord)
Returns true when left and right
have identical A, B, and C values.
Declaration
public static bool operator ==(TriCoord left, TriCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | left | The left operand. |
| TriCoord | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(TriCoord, TriCoord)
Returns true when left and right
differ in at least one lane value.
Declaration
public static bool operator !=(TriCoord left, TriCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | left | The left operand. |
| TriCoord | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator *(TriCoord, int)
Returns a new coordinate whose lane values are each multiplied by
scalar.
Declaration
public static TriCoord operator *(TriCoord coord, int scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | coord | The coordinate to scale. |
| int | scalar | The integer scalar. |
Returns
| Type | Description |
|---|---|
| TriCoord | A new TriCoord equal to |
operator *(int, TriCoord)
Returns a new coordinate whose lane values are each multiplied by
scalar (scalar-first overload).
Declaration
public static TriCoord operator *(int scalar, TriCoord coord)
Parameters
| Type | Name | Description |
|---|---|---|
| int | scalar | The integer scalar. |
| TriCoord | coord | The coordinate to scale. |
Returns
| Type | Description |
|---|---|
| TriCoord | A new TriCoord equal to |
operator -(TriCoord, TriCoord)
Returns a new coordinate whose lane values are the component-wise difference of
a minus b.
Declaration
public static TriCoord operator -(TriCoord a, TriCoord b)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | a | The minuend coordinate. |
| TriCoord | b | The subtrahend coordinate. |
Returns
| Type | Description |
|---|---|
| TriCoord | A new TriCoord equal to |
operator -(TriCoord)
Returns a new coordinate with all lane values negated.
Declaration
public static TriCoord operator -(TriCoord coord)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | coord | The coordinate to negate. |
Returns
| Type | Description |
|---|---|
| TriCoord | A new TriCoord equal to |