Interface IGridView<T>
Interface designed to act as a standardized input/output format that defines minimal required data for algorithms that operate on a grid of some sort. For a concrete implementation to subclass for custom implementations, see GridViewBase<T>.
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public interface IGridView<out T>
Type Parameters
Name | Description |
---|---|
T | The type of value being returned by the indexer functions. |
Remarks
Many algorithms that operate on a grid need only some very basic information about each location in the grid to function. For example, a basic grid-based pathfinding algorithm might only need to know whether each location can be traversed or not, which can be represented by a single boolean value per location. A renderer might want to know simple rendering information for each location, which might be wrapped in a class or structure.
One option for creating these algorithms would be to take as input arrays of the type they need. For example, the pathing algorithm might take an array of boolean values as input. However, this can be quite inflexible. The values that algorithms need to function might be determined based on a much more complex structure than a simple array of the precise type it needs, depending on use case. Taking an array as input in these cases forces a user to either adapt their data structure to the one that the algorithm uses, or maintain multiple "copies" of their data in the format that the algorithms need.
IGridView<T> is designed to act as a much more flexible input/output format for algorithms like this that operate on a grid. The interface simply defines properties for width and height, and some basic abstract indexers that allow accessing the "object" at each location. In the examples from above, the basic pathfinding algorithm might take as input an IGridView<bool>, whereas the renderer might take IGridView<RenderingInfo>. This allows the algorithms to operate on the minimal data that they need to function, but allows a user to define where that data comes from. For common cases, concrete implementations are provided that make the interface easier to use; for example, ArrayView<T> defines the interface such that the data comes from an array, and LambdaGridView<T> defines the interface such that an arbitrary callback is used to retrieve the data.
Properties
Count
Declaration
int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Height
The height of the grid being represented.
Declaration
int Height { get; }
Property Value
Type | Description |
---|---|
Int32 |
Item[Point]
Given a position, returns the "value" associated with that location.
Declaration
T this[Point pos] { get; }
Parameters
Type | Name | Description |
---|---|---|
Point | pos | Location to retrieve the value for. |
Property Value
Type | Description |
---|---|
T | The "value" associated with the provided location. |
Item[Int32]
Given an 1-dimensional index, returns the value associated with the corresponding position in the map view.
Declaration
T this[int index1D] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index1D | 1D index of location to retrieve the "value" for. |
Property Value
Type | Description |
---|---|
T | The "value" associated with the given location. |
Remarks
Typically, this may be implemented in terms of Item[Point] by using FromIndex(Int32, Int32) to calculate the 2D position represented by that 1D index, and passing that position to the Item[Point] indexer to determine the value associated with the position.
Item[Int32, Int32]
Given an X and Y value, returns the "value" associated with that location.
Declaration
T this[int x, int y] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | X-value of location. |
Int32 | y | Y-value of location. |
Property Value
Type | Description |
---|---|
T | The "value" associated with that location. |
Remarks
Typically, this can be implemented via Item[Point].
Width
The width of the grid being represented.
Declaration
int Width { get; }
Property Value
Type | Description |
---|---|
Int32 |