Interface IScyllaGrid<TCoord, TCell>
Base interface for all spatially-addressed Scylla grid collections. Extends IScyllaCollection with coordinate-keyed cell access and a topology-neutral contract that works identically for square, hexagonal, and triangular grid layouts.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public interface IScyllaGrid<TCoord, TCell> : IScyllaCollection where TCoord : struct, IEquatable<TCoord>
Type Parameters
| Name | Description |
|---|---|
| TCoord | The coordinate type used to address cells. Must be a value type that implements IEquatable<T> so that equality comparisons and dictionary lookups are allocation-free. Concrete coordinate types are SquareCoord, HexCoord, and TriCoord. |
| TCell | The type of data stored in each grid cell. May be any type, including value types,
reference types, or Unity structs such as |
Remarks
This interface abstracts over two storage strategies used by concrete implementations:
-
Dense grids (ScyllaSquareGrid<TCell>,
ScyllaHexGrid<TCell>, ScyllaTriGrid<TCell>):
All cells are pre-allocated in a flat array at construction time.
Count equals the total number of allocated cells
and never changes. CellCount likewise equals the total cell count.
IsEmpty always returns
false. - Sparse grids (ScyllaSparseSquareGrid<TCell>, ScyllaSparseHexGrid<TCell>, ScyllaSparseTriGrid<TCell>): Cells are stored only when explicitly written via TrySet(TCoord, TCell). Count and CellCount reflect the current number of populated cells and grow or shrink dynamically. Sparse grids may be optionally bounded or unbounded.
Use this interface when writing code that must work with any grid topology or storage strategy. Prefer the concrete types for performance-critical paths that require direct indexer access or topology-specific operations such as neighbor queries, world-space conversions, or ring/range enumeration.
Properties
CellCount
Gets the number of populated (logically active) cells in the grid.
Declaration
int CellCount { get; }
Property Value
| Type | Description |
|---|---|
| int | For dense grids, this always equals Count - every cell slot is pre-allocated and considered populated regardless of its stored value. The value is fixed at construction and never changes. For sparse grids, this equals the number of cells that have been explicitly written via TrySet(TCoord, TCell) and not yet removed. The value may be zero on a freshly created or cleared sparse grid. |
See Also
Methods
Contains(TCoord)
Determines whether the specified coordinate is addressable and populated in this grid.
Declaration
bool Contains(TCoord coord)
Parameters
| Type | Name | Description |
|---|---|---|
| TCoord | coord | The coordinate to test. |
Returns
| Type | Description |
|---|---|
| bool |
For dense grids, returns
For sparse grids, returns |
Remarks
This method is equivalent to checking whether TryGet(TCoord, out TCell) would return
true for the same coordinate. Use it when you only need the existence check
and do not need the value.
See Also
TryGet(TCoord, out TCell)
Attempts to retrieve the value stored at the specified coordinate without throwing on failure.
Declaration
bool TryGet(TCoord coord, out TCell value)
Parameters
| Type | Name | Description |
|---|---|---|
| TCoord | coord | The grid coordinate to look up. |
| TCell | value | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Prefer this method over direct indexer access when the coordinate's validity is not guaranteed, as it avoids the cost of exception handling on out-of-bounds access. For dense grids, "within bounds" means the coordinate maps to a valid flat-array index. For sparse grids, "within bounds" additionally requires that the cell has been set.
See Also
TrySet(TCoord, TCell)
Attempts to store a value at the specified coordinate without throwing on failure.
Declaration
bool TrySet(TCoord coord, TCell value)
Parameters
| Type | Name | Description |
|---|---|---|
| TCoord | coord | The grid coordinate to write to. |
| TCell | value | The value to store at |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
For dense grids, this writes to the pre-allocated cell at
coord and returns false if the coordinate falls outside
the grid's dimensions.
For sparse grids, this inserts or updates the entry at
coord and returns false only when the grid is bounded
and coord falls outside the defined bounds. On unbounded sparse
grids this method always returns true.
A successful call increments CellCount on sparse grids when
coord is newly written for the first time.