Class AbstractUniformGrid<TCell, TPoint>
This is the base class for grids that are not spliced; in other words, grids that have identical cells, with identical orientation, and in which grid points behave as (integer) vectors.
[Version(1, 0, 0)]
[Serializable]
public abstract class AbstractUniformGrid<TCell, TPoint> : IVectorGrid<TCell, TPoint, TPoint>, IGrid<TCell, TPoint>, IGrid<TPoint>, IGridSpace<TPoint>, IEnumerable<TPoint>, IEnumerable where TPoint : IGridPoint<TPoint>, IVectorPoint<TPoint>
Type Parameters
TCellTPoint
- Inheritance
-
AbstractUniformGrid<TCell, TPoint>
- Implements
-
IVectorGrid<TCell, TPoint, TPoint>IGrid<TCell, TPoint>IGrid<TPoint>IGridSpace<TPoint>IEnumerable<TPoint>
- Derived
- Inherited Members
- Extension Methods
Constructors
AbstractUniformGrid(int, int, Func<TPoint, bool>, Func<TPoint, TPoint>, Func<TPoint, TPoint>, IEnumerable<TPoint>)
Constructs a new hex grid with a shape determined by the IsInsider shape.
protected AbstractUniformGrid(int width, int height, Func<TPoint, bool> isInsideTest, Func<TPoint, TPoint> gridPointTransform, Func<TPoint, TPoint> inverseGridPointTransform, IEnumerable<TPoint> neighborDirections)
Parameters
widthintThe with of the hex rectangle that will contain the grid.
heightintThe height of the hex rectangle that will contain the grid.
isInsideTestFunc<TPoint, bool>A function that tests whether a given point is inside the grid.This function should not rely on the points given to it to be limited in any way by the specified with and height.
gridPointTransformFunc<TPoint, TPoint>Points returned by tis grid are transformed first with this delagate.
inverseGridPointTransformFunc<TPoint, TPoint>This must be the inverse of the gridPointTransform function. Together, these functions make it possible to do things such as flip axes.
neighborDirectionsIEnumerable<TPoint>Possible direction of the neighbor
Fields
contains
[NonSerialized]
protected Func<TPoint, bool> contains
Field Value
height
protected int height
Field Value
width
protected int width
Field Value
Properties
GridOrigin
Gives the Zero point as transform by this grids transforms.
protected abstract TPoint GridOrigin { get; }
Property Value
- TPoint
InversePointTransform
protected Func<TPoint, TPoint> InversePointTransform { get; }
Property Value
- Func<TPoint, TPoint>
this[TPoint]
Gets the cell at the specified point.
public TCell this[TPoint point] { get; set; }
Parameters
pointTPoint
Property Value
- TCell
NeighborDirections
public IEnumerable<TPoint> NeighborDirections { get; set; }
Property Value
- IEnumerable<TPoint>
PointTransform
protected Func<TPoint, TPoint> PointTransform { get; }
Property Value
- Func<TPoint, TPoint>
Values
A enumerable containing all the values of this grid.
public IEnumerable<TCell> Values { get; }
Property Value
- IEnumerable<TCell>
Examples
For example, the following two pieces of code do the same:
foreach(var point in grid)
{
Debug.Log(grid[point]);
}
foreach(var value in grid.Values)
{
Debug.Log(value);
}
Methods
ArrayPointFromPoint(int, int)
protected abstract ArrayPoint ArrayPointFromPoint(int hX, int hY)
Parameters
Returns
ArrayPointFromPoint(TPoint)
protected abstract ArrayPoint ArrayPointFromPoint(TPoint point)
Parameters
pointTPoint
Returns
CloneStructure<TNewCell>()
Returns a grid with exactly the same structure, but potentially holding elements of a different type.
public abstract IGrid<TNewCell, TPoint> CloneStructure<TNewCell>()
Returns
- IGrid<TNewCell, TPoint>
Type Parameters
TNewCell
Contains(TPoint)
Checks whether the given point is inside the grid, or not.
This function must be consistent with the enumerator that is returned with GetEnumerator(all points returned by the enumerator must be Inside, and all points that are inside must be returned by the enumerator).
public bool Contains(TPoint point)
Parameters
pointTPoint
Returns
GetAllNeighbors(TPoint)
Returns the neighbors of this point, regardless of whether they are in the grid or not.
public IEnumerable<TPoint> GetAllNeighbors(TPoint point)
Parameters
pointTPoint
Returns
- IEnumerable<TPoint>
GetEnumerator()
public IEnumerator<TPoint> GetEnumerator()
Returns
- IEnumerator<TPoint>
GetLargeSet(int)
This functions returns a large number of points around the origin.
This is useful(when used with big enough n) to determine whether a grid that is missing points is doing so becuase of an incorrect test function, or an incorrect storage rectangle.
Use for debugging.
[Version(1, 1, 0)]
public IEnumerable<TPoint> GetLargeSet(int n)
Parameters
nint
Returns
- IEnumerable<TPoint>
GetNeighborDirections(int)
The only legal cellIndex to pass to this methid is 0
public IEnumerable<TPoint> GetNeighborDirections(int cellIndex)
Parameters
cellIndexint
Returns
- IEnumerable<TPoint>
GetStoragePoints()
This method returns all points that can be contined by the storage rectangle for this grid.
This is useful for debuggong shape functions.
[Version(1, 1, 0)]
public IEnumerable<TPoint> GetStoragePoints()
Returns
- IEnumerable<TPoint>
PointFromArrayPoint(int, int)
protected abstract TPoint PointFromArrayPoint(int aX, int aY)
Parameters
Returns
- TPoint
SetGridPointTransforms(Func<TPoint, TPoint>, Func<TPoint, TPoint>)
Set the GridPointTransform and InverseGridPointTransform.
public void SetGridPointTransforms(Func<TPoint, TPoint> gridPointTransform, Func<TPoint, TPoint> inverseGridPointTransform)