Struct SquareEdgeCoord
Represents a unique, canonical edge in a square grid, identified by the anchor cell coordinate and the edge direction (N or W).
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public readonly struct SquareEdgeCoord : IEquatable<SquareEdgeCoord>
Remarks
Each interior edge in a square grid is physically shared by two adjacent cells. To guarantee a single canonical address per edge the encoding stores only the N (top) and W (left) edges of each cell:
- N edge of (c, r) - the horizontal edge at the top of cell (c, r), also the south edge of cell (c, r-1).
- W edge of (c, r) - the vertical edge at the left of cell (c, r), also the east edge of cell (c-1, r).
To address the south edge of cell (c, r), use the N edge of (c, r+1). To address the east edge of cell (c, r), use the W edge of (c+1, r).
The static topology helpers (GetCellsNonAlloc(SquareEdgeCoord, Span<SquareCoord>), GetCornersNonAlloc(SquareEdgeCoord, Span<SquareCornerCoord>), GetEdgesOfCellNonAlloc(SquareCoord, Span<SquareEdgeCoord>)) all write into caller-supplied Span<T> buffers to remain allocation-free.
Constructors
SquareEdgeCoord(int, int, SquareEdgeDirection)
Creates a new square edge coordinate from an anchor cell and a direction.
Declaration
public SquareEdgeCoord(int col, int row, SquareEdgeDirection direction)
Parameters
| Type | Name | Description |
|---|---|---|
| int | col | The column of the anchor cell. |
| int | row | The row of the anchor cell. |
| SquareEdgeDirection | direction | The canonical edge direction: N for the top horizontal edge, or W for the left vertical edge. |
Fields
Col
The column of the anchor cell that owns this edge.
Declaration
public readonly int Col
Field Value
| Type | Description |
|---|---|
| int |
Direction
The direction of this edge relative to the anchor cell. N is the top horizontal edge; W is the left vertical edge.
Declaration
public readonly SquareEdgeDirection Direction
Field Value
| Type | Description |
|---|---|
| SquareEdgeDirection |
Row
The row of the anchor cell that owns this edge.
Declaration
public readonly int Row
Field Value
| Type | Description |
|---|---|
| int |
Methods
Equals(SquareEdgeCoord)
Determines whether this edge coordinate equals other.
Declaration
public bool Equals(SquareEdgeCoord other)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | other | The edge coordinate to compare with. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Determines whether this edge coordinate equals an arbitrary object.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with. May be |
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
GetCellsNonAlloc(SquareEdgeCoord, Span<SquareCoord>)
Writes the two cells that share edge into buffer.
Declaration
public static int GetCellsNonAlloc(SquareEdgeCoord edge, Span<SquareCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | edge | The edge whose sharing cells are requested. |
| Span<SquareCoord> | buffer | A Span<T> of at least 2 elements to receive the two cell coordinates. If the span is smaller than 2, the method writes nothing and returns 0. |
Returns
| Type | Description |
|---|---|
| int | The number of cell coordinates written into |
Remarks
The two sharing cells are determined by the edge direction:
-
N edge of (c, r) - cells
(c, r)and(c, r-1). -
W edge of (c, r) - cells
(c, r)and(c-1, r).
The returned coordinates are not bounds-checked against any particular grid; callers should validate them with IsInBounds(int, int) or IsInBounds(int, int) as needed.
GetCornersNonAlloc(SquareEdgeCoord, Span<SquareCornerCoord>)
Writes the two corner endpoints of edge into buffer.
Declaration
public static int GetCornersNonAlloc(SquareEdgeCoord edge, Span<SquareCornerCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | edge | The edge whose corner endpoints are requested. |
| Span<SquareCornerCoord> | buffer | A Span<T> of at least 2 elements to receive the two corner coordinates. If the span is smaller than 2, the method writes nothing and returns 0. |
Returns
| Type | Description |
|---|---|
| int | The number of corner coordinates written into |
Remarks
The corner endpoints are determined by the edge direction:
-
N edge of (c, r) - corners
(c, r)(northwest) and(c+1, r)(northeast). -
W edge of (c, r) - corners
(c, r)(northwest) and(c, r+1)(southwest).
Corner coordinates follow the convention described in SquareCornerCoord: corner (c, r) is the northwest vertex of cell (c, r).
GetEdgesOfCellNonAlloc(SquareCoord, Span<SquareEdgeCoord>)
Writes the four canonical edges that bound cell into
buffer.
Declaration
public static int GetEdgesOfCellNonAlloc(SquareCoord cell, Span<SquareEdgeCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCoord | cell | The cell whose four bounding edges are requested. |
| Span<SquareEdgeCoord> | buffer | A Span<T> of at least 4 elements to receive the edge coordinates. If the span is smaller than 4, the method writes nothing and returns 0. |
Returns
| Type | Description |
|---|---|
| int | The number of edge coordinates written into |
Remarks
Every square cell is surrounded by four edges. Using the canonical N/W encoding, the four edges of cell (c, r) are:
- North:
(c, r, N) - West:
(c, r, W) - East:
(c+1, r, W) - South:
(c, r+1, N)
The edges are written in the order North, West, East, South (indices 0-3).
GetHashCode()
Returns a hash code for this edge coordinate based on its column, row, and direction.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code suitable for use in hash-based collections such as Dictionary<TKey, TValue>. |
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 ==(SquareEdgeCoord, SquareEdgeCoord)
Returns true if left and right refer
to the same canonical edge (equal column, row, and direction).
Declaration
public static bool operator ==(SquareEdgeCoord left, SquareEdgeCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | left | |
| SquareEdgeCoord | right |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(SquareEdgeCoord, SquareEdgeCoord)
Returns true if left and right refer
to different edges.
Declaration
public static bool operator !=(SquareEdgeCoord left, SquareEdgeCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | left | |
| SquareEdgeCoord | right |
Returns
| Type | Description |
|---|---|
| bool |