Struct TriCornerCoord
Immutable coordinate for a corner vertex in a triangular grid, expressed in three-axis lane coordinates on the dual vertex sublattice.
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public readonly struct TriCornerCoord : IEquatable<TriCornerCoord>
Remarks
In a triangular tiling each geometric vertex is shared by six triangles - three downward and three upward. The dual sublattice represents vertices using the same three-axis coordinate scheme as TriCoord, but the valid sum values differ:
- Type I (A + B + C = 0): the vertex is adjacent to three downward triangles. Check with IsTypeI.
- Type II (A + B + C = 1): the vertex is adjacent to three upward triangles. Check with IsTypeII.
Because a single geometric vertex is reachable from both sublattice representations, callers that need the full six-triangle neighbourhood around a vertex must query both the Type I and Type II coordinates for that geometric point.
Use GetTrianglesNonAlloc(TriCornerCoord, Span<TriCoord>) to find the three triangles adjacent to a given corner, and GetCornersOfCellNonAlloc(TriCoord, Span<TriCornerCoord>) to find all three corners of a triangle cell. Per-corner data can be stored in a TriCornerMap<TData>.
Constructors
TriCornerCoord(int, int, int)
Creates a new triangle corner coordinate with the specified dual-sublattice lane values.
Declaration
public TriCornerCoord(int a, int b, int c)
Parameters
| Type | Name | Description |
|---|---|---|
| int | a | The A lane value for the new corner coordinate. |
| int | b | The B lane value for the new corner coordinate. |
| int | c | The C lane value for the new corner coordinate. For a valid vertex,
|
Fields
A
The A lane value on the vertex dual sublattice.
Declaration
public readonly int A
Field Value
| Type | Description |
|---|---|
| int |
B
The B lane value on the vertex dual sublattice.
Declaration
public readonly int B
Field Value
| Type | Description |
|---|---|
| int |
C
The C lane value on the vertex dual sublattice.
For a valid corner, A + B + C equals 0 (Type I) or 1 (Type II).
Declaration
public readonly int C
Field Value
| Type | Description |
|---|---|
| int |
Properties
IsTypeI
Gets a value indicating whether this is a Type I corner (A + B + C = 0), which is adjacent to three downward triangles.
Declaration
public bool IsTypeI { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
IsTypeII
Gets a value indicating whether this is a Type II corner (A + B + C = 1), which is adjacent to three upward triangles.
Declaration
public bool IsTypeII { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
IsValid
Gets a value indicating whether this corner coordinate has a valid lane sum, meaning it represents a real vertex in the triangular tiling.
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
Equals(TriCornerCoord)
Determines whether this corner coordinate equals another corner coordinate.
Declaration
public bool Equals(TriCornerCoord other)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCornerCoord | other | The corner coordinate to compare with. |
Returns
| Type | Description |
|---|---|
| bool | True if all three lane values 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 TriCornerCoord with equal values. |
Overrides
GetCornersOfCellNonAlloc(TriCoord, Span<TriCornerCoord>)
Writes the three corner vertices of a triangle cell into the provided buffer without allocating.
Declaration
public static int GetCornersOfCellNonAlloc(TriCoord cell, Span<TriCornerCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCoord | cell | The triangle coordinate whose corners are requested. |
| Span<TriCornerCoord> | buffer | A span of at least 3 elements to receive the three TriCornerCoord values. |
Returns
| Type | Description |
|---|---|
| int | The number of corners written - 3 when |
Remarks
The formula is the same regardless of triangle orientation: the three corners
are (a-1, b, c), (a, b-1, c), and (a, b, c-1).
- For a downward triangle (A + B + C = 1), each decremented coordinate yields sum 0, so all three corners are Type I.
- For an upward triangle (A + B + C = 2), each decremented coordinate yields sum 1, so all three corners are Type II.
Returns 0 if cell has an invalid sum (neither 1 nor 2).
GetHashCode()
Returns a hash code for this corner coordinate.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code based on A, B, and C. |
Overrides
GetTrianglesNonAlloc(TriCornerCoord, Span<TriCoord>)
Writes the three triangle cells directly adjacent to the specified corner vertex into the provided buffer without allocating.
Declaration
public static int GetTrianglesNonAlloc(TriCornerCoord corner, Span<TriCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCornerCoord | corner | The corner coordinate whose adjacent triangles are requested. |
| Span<TriCoord> | buffer | A span of at least 3 elements to receive the three adjacent TriCoord values. |
Returns
| Type | Description |
|---|---|
| int | The number of triangles written - 3 when |
Remarks
The formula for the adjacent triangles is the same for both corner types:
(a+1, b, c), (a, b+1, c), (a, b, c+1).
- Type I (A + B + C = 0): the three adjacent triangles are all downward (each incremented coordinate gives sum 1).
- Type II (A + B + C = 1): the three adjacent triangles are all upward (each incremented coordinate gives sum 2).
For the full six-triangle ring around a geometric vertex, call this method on both the Type I and Type II forms of the same vertex.
Returns 0 if corner has an invalid sum (neither 0 nor 1).
ToString()
Returns a human-readable string representation of this corner coordinate.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string in the format |
Overrides
Operators
operator ==(TriCornerCoord, TriCornerCoord)
Returns true when left and right
have identical A, B, and C lane values.
Declaration
public static bool operator ==(TriCornerCoord left, TriCornerCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCornerCoord | left | The left operand. |
| TriCornerCoord | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(TriCornerCoord, TriCornerCoord)
Returns true when left and right
differ in at least one lane value.
Declaration
public static bool operator !=(TriCornerCoord left, TriCornerCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| TriCornerCoord | left | The left operand. |
| TriCornerCoord | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|