Table of Contents

Class GridExtensions

Namespace
Gamelogic.Grids
Assembly
Assembly-CSharp.dll

Defines extension methods for the IGrid interface. This is implemented as an extension so that implementers need not extend from a common base class, but provide it to their clients.

[Version(1, 0, 0)]
public static class GridExtensions
Inheritance
GridExtensions
Inherited Members

Methods

Apply<TCell, TPoint>(IGrid<TCell, TPoint>, Action<TCell>)

Applies the given action to all cells in the grid.

[Version(1, 10, 0)]
public static void Apply<TCell, TPoint>(this IGrid<TCell, TPoint> grid, Action<TCell> action) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
action Action<TCell>

Type Parameters

TCell
TPoint

Examples

grid.Apply(cell => cell.Color = Color.red);

CastValues<TNewCell, TPoint>(IGrid<TPoint>)

Returns a new grid in the same shape as the given grid, with the same contents casted to the new type.

public static IGrid<TNewCell, TPoint> CastValues<TNewCell, TPoint>(this IGrid<TPoint> grid) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TPoint>

Returns

IGrid<TNewCell, TPoint>

Type Parameters

TNewCell
TPoint

CloneStructure<TNewCell, TPoint>(IGrid<TPoint>, Func<TNewCell>)

Clones the given grid, and fills all cells of the cloned grid with the value returned by createValue.

[Version(1, 10, 0)]
public static IGrid<TNewCell, TPoint> CloneStructure<TNewCell, TPoint>(this IGrid<TPoint> grid, Func<TNewCell> createValue) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TPoint>
createValue Func<TNewCell>

Returns

IGrid<TNewCell, TPoint>

Type Parameters

TNewCell
TPoint

CloneStructure<TNewCell, TPoint>(IGrid<TPoint>, Func<TPoint, TNewCell>)

Clones the given grid, and fills the cell at each point of the cloned grid with the value returned by createValue when the point is passed as a parameter.

[Version(1, 10, 0)]
public static IGrid<TNewCell, TPoint> CloneStructure<TNewCell, TPoint>(this IGrid<TPoint> grid, Func<TPoint, TNewCell> createValue) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TPoint>
createValue Func<TPoint, TNewCell>

Returns

IGrid<TNewCell, TPoint>

Type Parameters

TNewCell
TPoint

CloneStructure<TNewCell, TPoint>(IGrid<TPoint>, TNewCell)

Clones the given grid, and fills all cells of the cloned grid with the given value.

[Version(1, 10, 0)]
public static IGrid<TNewCell, TPoint> CloneStructure<TNewCell, TPoint>(this IGrid<TPoint> grid, TNewCell value) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TPoint>
value TNewCell

Returns

IGrid<TNewCell, TPoint>

Type Parameters

TNewCell
TPoint

Clone<TCell, TPoint>(IGrid<TCell, TPoint>)

Returns a shallow copy of the given grid.

public static IGrid<TCell, TPoint> Clone<TCell, TPoint>(this IGrid<TCell, TPoint> grid) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>

Returns

IGrid<TCell, TPoint>

Type Parameters

TCell
TPoint

Fill<TCell, TPoint>(IGrid<TCell, TPoint>, Func<TCell>)

Fills all cells of a grid with the value returned by createValue.

[Version(1, 10, 0)]
public static void Fill<TCell, TPoint>(this IGrid<TCell, TPoint> grid, Func<TCell> createValue) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
createValue Func<TCell>

Type Parameters

TCell
TPoint

Fill<TCell, TPoint>(IGrid<TCell, TPoint>, Func<TPoint, TCell>)

Fills the cell of each point of a grid with the value returned by createValue when passed the point as a parameter.

[Version(1, 10, 0)]
public static void Fill<TCell, TPoint>(this IGrid<TCell, TPoint> grid, Func<TPoint, TCell> createValue) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
createValue Func<TPoint, TCell>

Type Parameters

TCell
TPoint

Fill<TCell, TPoint>(IGrid<TCell, TPoint>, TCell)

Fills all cells of a grid with the given value.

[Version(1, 10, 0)]
public static void Fill<TCell, TPoint>(this IGrid<TCell, TPoint> grid, TCell value) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
value TCell

Type Parameters

TCell
TPoint

GetAllNeighbors<TCell, TPoint>(IGrid<TCell, TPoint>, TPoint, Func<TPoint, bool>)

Returns all neighbors of this point that satisfies the condition, regardless of whether they are in the grid or not.

public static IEnumerable<TPoint> GetAllNeighbors<TCell, TPoint>(this IGrid<TCell, TPoint> grid, TPoint point, Func<TPoint, bool> includePoint) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
point TPoint
includePoint Func<TPoint, bool>

Returns

IEnumerable<TPoint>

Type Parameters

TCell
TPoint

GetCell<TCell, TPoint>(IGrid<TCell, TPoint>, TPoint)

The same as grid[point]. This method is included to make it easier to construct certain LINQ expressions, for example

grid.Select(grid.GetCell) grid.Where(p => p.GetColor4_2() == 0).Select(grid.GetCell)

[Version(1, 7, 0)]
public static TCell GetCell<TCell, TPoint>(this IGrid<TCell, TPoint> grid, TPoint point) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
point TPoint

Returns

TCell

Type Parameters

TCell
TPoint

GetNeighborHood<T>(RectGrid<T>, RectPoint, int)

Returns the points in a grid neighborhood around the given center.

[Version(1, 8, 0)]
public static IEnumerable<RectPoint> GetNeighborHood<T>(this RectGrid<T> grid, RectPoint center, int radius)

Parameters

grid RectGrid<T>
center RectPoint
radius int

Returns

IEnumerable<RectPoint>

Type Parameters

T

GetNeighbors<TCell, TPoint>(IGrid<TCell, TPoint>, TPoint)

Only return neighbors of the point that are inside the grid, as defined by Contains.

public static IEnumerable<TPoint> GetNeighbors<TCell, TPoint>(this IGrid<TCell, TPoint> grid, TPoint point) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
point TPoint

Returns

IEnumerable<TPoint>

Type Parameters

TCell
TPoint

GetNeighbors<TCell, TPoint>(IGrid<TCell, TPoint>, TPoint, Func<TCell, bool>)

Only return neighbors of the point that are inside the grid, as defined by IsInside, whose associated cells also satisfy the predicate includeCell.

It is equivalent to GetNeighbors(point).Where(p => includeCell(grid[p])

[Version(1, 7, 0)]
public static IEnumerable<TPoint> GetNeighbors<TCell, TPoint>(this IGrid<TCell, TPoint> grid, TPoint point, Func<TCell, bool> includeCell) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
point TPoint
includeCell Func<TCell, bool>

Returns

IEnumerable<TPoint>

Type Parameters

TCell
TPoint

GetNeighbors<TCell, TPoint>(IGrid<TCell, TPoint>, TPoint, Func<TPoint, bool>)

Only return neighbors of the point that are inside the grid, as defined by IsInside, that also satisfies the predicate includePoint.

It is equivalent to GetNeighbors(point).Where(includePoint).

[Version(1, 7, 0)]
public static IEnumerable<TPoint> GetNeighbors<TCell, TPoint>(this IGrid<TCell, TPoint> grid, TPoint point, Func<TPoint, bool> includePoint) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
point TPoint
includePoint Func<TPoint, bool>

Returns

IEnumerable<TPoint>

Type Parameters

TCell
TPoint

IsOutside<TCell, TPoint>(IGrid<TCell, TPoint>, TPoint)

Returns whether the point is outside the grid.

public static bool IsOutside<TCell, TPoint>(this IGrid<TCell, TPoint> grid, TPoint point) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
point TPoint

Returns

bool

Type Parameters

TCell
TPoint

Remarks

implementers This method must be consistent with IsInside, and hence is not overridable.

SelectValuesAt<TCell, TPoint>(IGrid<TCell, TPoint>, IEnumerable<TPoint>)

Returns a list of cells that correspond to the list of points.

public static IEnumerable<TCell> SelectValuesAt<TCell, TPoint>(this IGrid<TCell, TPoint> grid, IEnumerable<TPoint> pointList) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
pointList IEnumerable<TPoint>

Returns

IEnumerable<TCell>

Type Parameters

TCell
TPoint

SetCell<TCell, TPoint>(IGrid<TCell, TPoint>, TPoint, TCell)

The same as grid[point] = value. This method is provided to be consistent with GetCell.

[Version(1, 7, 0)]
public static void SetCell<TCell, TPoint>(this IGrid<TCell, TPoint> grid, TPoint point, TCell value) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
point TPoint
value TCell

Type Parameters

TCell
TPoint

Shuffle<TCell, TPoint>(IGrid<TCell, TPoint>)

Shuffles the contents of a grid.

[Version(1, 6, 0)]
public static void Shuffle<TCell, TPoint>(this IGrid<TCell, TPoint> grid) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>

Type Parameters

TCell
TPoint

TransformValues<TCell, TPoint>(IGrid<TCell, TPoint>, Func<TCell, TCell>)

Transforms all values in this grid using the given transformation.

[Version(1, 10, 0)]
public static void TransformValues<TCell, TPoint>(this IGrid<TCell, TPoint> grid, Func<TCell, TCell> transformation) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
transformation Func<TCell, TCell>

Type Parameters

TCell
TPoint

Examples

gridOfNumbers.TransformValues(x => x + 1);

WhereCell<TCell, TPoint>(IGrid<TCell, TPoint>, Func<TCell, bool>)

Returns a list of all points whose associated cells also satisfy the predicate include.

It is equivalent to GetNeighbors(point).Where(p => includeCell(grid[p])

[Version(1, 7, 0)]
public static IEnumerable<TPoint> WhereCell<TCell, TPoint>(this IGrid<TCell, TPoint> grid, Func<TCell, bool> include) where TPoint : IGridPoint<TPoint>

Parameters

grid IGrid<TCell, TPoint>
include Func<TCell, bool>

Returns

IEnumerable<TPoint>

Type Parameters

TCell
TPoint