Struct TriEdgeCoord
Immutable canonical representation of a shared edge between two adjacent triangles in a triangular grid.
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public readonly struct TriEdgeCoord : IEquatable<TriEdgeCoord>
Remarks
Every internal edge is shared by exactly one downward triangle and one upward
triangle. The TriEdgeCoord uses a canonical form: the anchor is
always the downward triangle (A + B + C = 1), identified by its
(A, B, C) lane coordinate, and the
Direction specifies which of its three sides this edge belongs to.
The three edge directions map to upward neighbors as follows:
-
A: edge between downward
(a,b,c)and upward(a+1,b,c). -
B: edge between downward
(a,b,c)and upward(a,b+1,c). -
C: edge between downward
(a,b,c)and upward(a,b,c+1).
Use GetCellsNonAlloc(TriEdgeCoord, Span<TriCoord>) to retrieve the two triangles sharing this edge, GetCornersNonAlloc(TriEdgeCoord, Span<TriCornerCoord>) for the two corner vertices, and GetEdgesOfCellNonAlloc(TriCoord, Span<TriEdgeCoord>) to enumerate all edges of a given triangle. Per-edge data can be stored in a TriEdgeMap<TData>.
Constructors
TriEdgeCoord(int, int, int, TriEdgeDirection)
Creates a new triangle edge coordinate from the downward anchor triangle's lane values and the edge direction.
Declaration
public TriEdgeCoord(int a, int b, int c, TriEdgeDirection direction)
Parameters
| Type | Name | Description |
|---|---|---|
| int | a | The A lane value of the downward anchor triangle. |
| int | b | The B lane value of the downward anchor triangle. |
| int | c | The C lane value of the downward anchor triangle. For a valid edge coordinate,
|
| TriEdgeDirection | direction | The TriEdgeDirection indicating which of the three sides of the anchor triangle this edge occupies. |
Fields
A
The A lane value of the downward anchor triangle.
Declaration
public readonly int A
Field Value
| Type | Description |
|---|---|
| int |
B
The B lane value of the downward anchor triangle.
Declaration
public readonly int B
Field Value
| Type | Description |
|---|---|
| int |
C
The C lane value of the downward anchor triangle.
For a valid edge, A + B + C must equal 1 (downward triangle sum).
Declaration
public readonly int C
Field Value
| Type | Description |
|---|---|
| int |
Direction
The direction of this edge relative to the anchor downward triangle, indicating which lane axis the shared boundary lies along.
Declaration
public readonly TriEdgeDirection Direction
Field Value
| Type | Description |
|---|---|
| TriEdgeDirection |
See Also
Properties
IsValid
Gets a value indicating whether the anchor triangle portion of this coordinate is valid - that is, whether A + B + C = 1 (a downward triangle).
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
Equals(TriEdgeCoord)
Determines whether this edge coordinate equals another edge coordinate.
Declaration
public bool Equals(TriEdgeCoord other)
Parameters
| Type | Name | Description |
|---|---|---|
| TriEdgeCoord | other | The edge coordinate to compare with. |
Returns
| Type | Description |
|---|---|
| bool | True if all fields are equal. |
Equals(object)
Determines whether this edge 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 TriEdgeCoord with equal values. |
Overrides
GetCellsNonAlloc(TriEdgeCoord, Span<TriCoord>)
Writes the two triangle cells that share this edge into the provided buffer without allocating.
Declaration
public static int GetCellsNonAlloc(TriEdgeCoord edge, Span<TriCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| TriEdgeCoord | edge | The canonical edge coordinate whose adjacent cells are needed. |
| Span<TriCoord> | buffer | A span of at least 2 elements to receive the two adjacent TriCoord values. |
Returns
| Type | Description |
|---|---|
| int | The number of cells written - always 2 when |
Remarks
The first element written is always the downward anchor triangle
(edge.A, edge.B, edge.C). The second element is the upward neighbor:
GetCornersNonAlloc(TriEdgeCoord, Span<TriCornerCoord>)
Writes the two corner vertices that are the endpoints of this edge into the provided buffer without allocating.
Declaration
public static int GetCornersNonAlloc(TriEdgeCoord edge, Span<TriCornerCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| TriEdgeCoord | edge | The canonical edge coordinate whose corner endpoints are needed. |
| Span<TriCornerCoord> | buffer | A span of at least 2 elements to receive the two TriCornerCoord endpoints. |
Returns
| Type | Description |
|---|---|
| int | The number of corners written - always 2 when |
Remarks
Every edge endpoint is a Type I corner (A + B + C = 0 on the TriCornerCoord sublattice), meaning it is adjacent to three downward triangles. The endpoint pairs by direction are:
GetEdgesOfCellNonAlloc(TriCoord, Span<TriEdgeCoord>)
Writes the three canonical edge coordinates of a triangle cell into the provided buffer without allocating.
Declaration
public static int GetEdgesOfCellNonAlloc(TriCoord cell, Span<TriEdgeCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | cell | The triangle coordinate whose edges are requested. |
| Span<TriEdgeCoord> | buffer | A span of at least 3 elements to receive the three TriEdgeCoord values. |
Returns
| Type | Description |
|---|---|
| int | The number of edges written - 3 when |
Remarks
Each triangle has exactly three edges. Because the canonical form always uses a
downward triangle as the anchor, the edges are expressed differently depending on
the orientation of cell:
-
Downward (A + B + C = 1): the cell is the anchor for all
three edges -
(a,b,c,A),(a,b,c,B),(a,b,c,C). -
Upward (A + B + C = 2): the neighboring downward triangles are the
anchors -
(a-1,b,c,A),(a,b-1,c,B),(a,b,c-1,C).
If cell has a lane sum other than 1 or 2 the coordinate is
not a valid triangle and 0 is returned.
GetHashCode()
Returns a hash code for this edge coordinate.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code based on A, B, C, and direction. |
Overrides
ToString()
Returns a human-readable string representation of this edge coordinate.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string in the format |
Overrides
Operators
operator ==(TriEdgeCoord, TriEdgeCoord)
Returns true when left and right
have identical anchor lane values and direction.
Declaration
public static bool operator ==(TriEdgeCoord left, TriEdgeCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| TriEdgeCoord | left | The left operand. |
| TriEdgeCoord | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(TriEdgeCoord, TriEdgeCoord)
Returns true when left and right
differ in at least one field.
Declaration
public static bool operator !=(TriEdgeCoord left, TriEdgeCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| TriEdgeCoord | left | The left operand. |
| TriEdgeCoord | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|