Struct SquareCornerCoord
Represents a corner vertex in a square grid.
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public readonly struct SquareCornerCoord : IEquatable<SquareCornerCoord>
Remarks
A square grid of W columns and H rows has (W+1) * (H+1) corner vertices,
one at each lattice point. The coordinate (c, r) identifies the northwest (top-left)
vertex of the cell at position (c, r). Equivalently:
- Corner (0, 0) is the top-left vertex of cell (0, 0).
- Corner (W, H) is the bottom-right vertex of the last cell (W-1, H-1).
Every interior corner is shared by up to four cells. The four cells that share corner (c, r) are
(c, r), (c-1, r), (c-1, r-1), and (c, r-1). Use
GetCellsNonAlloc(SquareCornerCoord, Span<SquareCoord>) to retrieve them without allocation.
The static topology helpers (GetCellsNonAlloc(SquareCornerCoord, Span<SquareCoord>), GetEdgesNonAlloc(SquareCornerCoord, Span<SquareEdgeCoord>), GetCornersOfCellNonAlloc(SquareCoord, Span<SquareCornerCoord>)) write into caller-supplied Span<T> buffers to remain allocation-free.
Constructors
SquareCornerCoord(int, int)
Creates a new square corner coordinate at the specified lattice point.
Declaration
public SquareCornerCoord(int col, int row)
Parameters
| Type | Name | Description |
|---|---|---|
| int | col | The column index of the lattice point. Valid range for a grid of width |
| int | row | The row index of the lattice point. Valid range for a grid of height |
Fields
Col
The column index of the lattice point. Corresponds to the left boundary of column Col in cell coordinates.
Declaration
public readonly int Col
Field Value
| Type | Description |
|---|---|
| int |
Row
The row index of the lattice point. Corresponds to the top boundary of row Row in cell coordinates.
Declaration
public readonly int Row
Field Value
| Type | Description |
|---|---|
| int |
Methods
Equals(SquareCornerCoord)
Determines whether this corner coordinate equals other.
Declaration
public bool Equals(SquareCornerCoord other)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | other | The corner coordinate to compare with. |
Returns
| Type | Description |
|---|---|
| bool |
Equals(object)
Determines whether this corner 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(SquareCornerCoord, Span<SquareCoord>)
Writes the (up to) four cells that share corner into
buffer.
Declaration
public static int GetCellsNonAlloc(SquareCornerCoord corner, Span<SquareCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | corner | The corner whose adjacent cells are requested. |
| Span<SquareCoord> | buffer | A Span<T> of at least 4 elements to receive the cell coordinates. If the span is smaller than 4, the method writes nothing and returns 0. |
Returns
| Type | Description |
|---|---|
| int | The number of cell coordinates written: always 4 when the buffer is large enough, or 0 when the buffer has fewer than 4 elements. |
Remarks
Corner (c, r) is the northwest vertex of cell (c, r). The four cells that share this vertex are written in the following order:
- Index 0:
(c, r)- southeast cell (below-right) - Index 1:
(c-1, r)- southwest cell (below-left) - Index 2:
(c-1, r-1)- northwest cell (above-left) - Index 3:
(c, r-1)- northeast cell (above-right)
The returned coordinates are not bounds-checked; callers should validate them against the grid before use.
GetCornersOfCellNonAlloc(SquareCoord, Span<SquareCornerCoord>)
Writes the four corner vertices of cell into buffer.
Declaration
public static int GetCornersOfCellNonAlloc(SquareCoord cell, Span<SquareCornerCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCoord | cell | The cell whose four corner vertices are requested. |
| Span<SquareCornerCoord> | buffer | A Span<T> of at least 4 elements to receive the corner coordinates. If the span is smaller than 4, the method writes nothing and returns 0. |
Returns
| Type | Description |
|---|---|
| int | The number of corner coordinates written: always 4 when the buffer is large enough, or 0 when the buffer has fewer than 4 elements. |
Remarks
The four corners of cell (c, r) are written in clockwise order starting from the northwest (top-left) vertex:
- Index 0:
(c, r)- northwest - Index 1:
(c+1, r)- northeast - Index 2:
(c+1, r+1)- southeast - Index 3:
(c, r+1)- southwest
These corner coordinates can be converted to world-space positions using GridToWorld(SquareCoord), taking into account that each corner is offset from the cell center by half a cell width/height.
GetEdgesNonAlloc(SquareCornerCoord, Span<SquareEdgeCoord>)
Writes the four canonical edges that meet at corner into
buffer.
Declaration
public static int GetEdgesNonAlloc(SquareCornerCoord corner, Span<SquareEdgeCoord> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | corner | The corner whose incident 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: always 4 when the buffer is large enough, or 0 when the buffer has fewer than 4 elements. |
Remarks
Using the canonical N/W encoding (see SquareEdgeDirection), the four edges that terminate at corner (c, r) are:
- Index 0:
(c, r, N)- N edge of the cell to the south-east - Index 1:
(c, r, W)- W edge of the cell to the south-east - Index 2:
(c-1, r, N)- N edge of the cell to the south-west - Index 3:
(c, r-1, W)- W edge of the cell to the north-east
GetHashCode()
Returns a hash code for this corner coordinate based on its column and row values.
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 corner coordinate.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string in the format |
Overrides
Operators
operator +(SquareCornerCoord, SquareCornerCoord)
Adds two corner coordinates component-wise, computing a new lattice point offset
from a by b.
Declaration
public static SquareCornerCoord operator +(SquareCornerCoord a, SquareCornerCoord b)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | a | |
| SquareCornerCoord | b |
Returns
| Type | Description |
|---|---|
| SquareCornerCoord |
operator ==(SquareCornerCoord, SquareCornerCoord)
Returns true if left and right refer
to the same lattice point (equal column and row).
Declaration
public static bool operator ==(SquareCornerCoord left, SquareCornerCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | left | |
| SquareCornerCoord | right |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(SquareCornerCoord, SquareCornerCoord)
Returns true if left and right refer
to different lattice points.
Declaration
public static bool operator !=(SquareCornerCoord left, SquareCornerCoord right)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | left | |
| SquareCornerCoord | right |
Returns
| Type | Description |
|---|---|
| bool |
operator *(SquareCornerCoord, int)
Scales both components of coord by scalar.
Declaration
public static SquareCornerCoord operator *(SquareCornerCoord coord, int scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | coord | |
| int | scalar |
Returns
| Type | Description |
|---|---|
| SquareCornerCoord |
operator *(int, SquareCornerCoord)
Scales both components of coord by scalar.
Commutative overload of coord * scalar.
Declaration
public static SquareCornerCoord operator *(int scalar, SquareCornerCoord coord)
Parameters
| Type | Name | Description |
|---|---|---|
| int | scalar | |
| SquareCornerCoord | coord |
Returns
| Type | Description |
|---|---|
| SquareCornerCoord |
operator -(SquareCornerCoord, SquareCornerCoord)
Subtracts b from a component-wise, returning
the displacement vector between the two lattice points.
Declaration
public static SquareCornerCoord operator -(SquareCornerCoord a, SquareCornerCoord b)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | a | |
| SquareCornerCoord | b |
Returns
| Type | Description |
|---|---|
| SquareCornerCoord |
operator -(SquareCornerCoord)
Returns a new corner coordinate with both components negated, mirroring
coord through the origin.
Declaration
public static SquareCornerCoord operator -(SquareCornerCoord coord)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCornerCoord | coord |
Returns
| Type | Description |
|---|---|
| SquareCornerCoord |