Interface IGrid
Contains all the methods for querying a grid.
A grid is a collection of cells, with each cell having various data associated with it
such as neighbours, position in space.
For more details see the basic concepts in the docs.
Assembly: Sylves.dll
Syntax
Properties
CoordinateDimension
Returns the number of co-ordinates needed to identify a cell.
i.e.
dim 1 means cell.y === 0 and cell.z === 0
dim 2 means cell.z === 0
dim 3 means all three co-ordinates are relevant.
Declaration
int CoordinateDimension { get; }
Property Value
Type |
Description |
System.Int32 |
|
IndexCount
Finds a number one larger than the maximum index for an in bounds cell.
Declaration
Property Value
Type |
Description |
System.Int32 |
|
Is2d
True if this grid uses 2d cell types
Declaration
Property Value
Type |
Description |
System.Boolean |
|
Is3d
True if this grid uses 3d cell types
Declaration
Property Value
Type |
Description |
System.Boolean |
|
IsFinite
True if there is a finite amout of cells in the grid.
Declaration
Property Value
Type |
Description |
System.Boolean |
|
IsOrientable
True if tile connections never set Mirror to true.
Declaration
bool IsOrientable { get; }
Property Value
Type |
Description |
System.Boolean |
|
IsPlanar
True if this grid uses 2d cell types, and all cells fit in the XY plane.
Declaration
Property Value
Type |
Description |
System.Boolean |
|
IsRepeating
True for grids that are some fixed pattern repeated over and over.
Declaration
bool IsRepeating { get; }
Property Value
Type |
Description |
System.Boolean |
|
IsSingleCellType
True if GetCellTypes always returns a single value.
Declaration
bool IsSingleCellType { get; }
Property Value
Type |
Description |
System.Boolean |
|
Unbounded
Returns the grid with any bounds removed.
Declaration
Property Value
Unwrapped
Returns the grid with most grid modifiers removed.
Declaration
Property Value
Methods
BoundBy(IBound)
Returns a new grid restricted to just the given bound.
If the grid already has a bound, the new grid will have the intersection of both.
Declaration
IGrid BoundBy(IBound bound)
Parameters
Type |
Name |
Description |
IBound |
bound |
|
Returns
FindBasicPath(Cell, Cell)
Returns a ordered series of cells and directions, starting a startCell,
such that moving in the given direction gives the next cell in the sequence,
and the final cell then moves to destCell.
Returns null if this is not possible.
This method is not indended for path finding as it lacks any customization options. It is intended
for algorithms that need to work between any two connected cells, as provides a "proof"
of connectivity.
See pathfinding in the docs for how to actually find a path.
Declaration
IEnumerable<(Cell, CellDir)> FindBasicPath(Cell startCell, Cell destCell)
Parameters
Type |
Name |
Description |
Cell |
startCell |
|
Cell |
destCell |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<System.ValueTuple<Cell, CellDir>> |
|
FindCell(Matrix4x4, out Cell, out CellRotation)
Returns the cell and rotation corresponding to a given transform matrix.
Declaration
bool FindCell(Matrix4x4 matrix, out Cell cell, out CellRotation rotation)
Parameters
Returns
Type |
Description |
System.Boolean |
|
FindCell(Vector3, out Cell)
Finds the cell containg the give position
Declaration
bool FindCell(Vector3 position, out Cell cell)
Parameters
Returns
Type |
Description |
System.Boolean |
|
FindGridSymmetry(ISet<Cell>, ISet<Cell>, Cell, CellRotation)
Finds a GridSymmetry that:
- Maps from the cells of src into dest (in any order / rotation), and
- Maps srcCell using cellRotation (to any cell in dest)
For simple, regular grids, srcCell is irrelevant, as every cell uses the same cellRotation.
Returns null if one cannot be found. Returns an arbitrary pick if there are multiple possibilities.
Declaration
GridSymmetry FindGridSymmetry(ISet<Cell> src, ISet<Cell> dest, Cell srcCell, CellRotation cellRotation)
Parameters
Type |
Name |
Description |
System.Collections.Generic.ISet<Cell> |
src |
|
System.Collections.Generic.ISet<Cell> |
dest |
|
Cell |
srcCell |
|
CellRotation |
cellRotation |
|
Returns
GetBound()
Returns the bound currently applied to the grid.
Declaration
Returns
GetBound(IEnumerable<Cell>)
Returns a bound that contains all the listed cells.
Declaration
IBound GetBound(IEnumerable<Cell> cells)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<Cell> |
cells |
|
Returns
GetCellByIndex(Int32)
Finds the cell associated with a given index.
Declaration
Cell GetCellByIndex(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
|
Returns
GetCellCenter(Cell)
Returns the center of the cell in local space
Declaration
Vector3 GetCellCenter(Cell cell)
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
GetCellCorner(Cell, CellCorner)
Returns the position of a corner.
Declaration
Vector3 GetCellCorner(Cell cell, CellCorner corner)
Parameters
Returns
GetCellCorners(Cell)
Declaration
IEnumerable<CellCorner> GetCellCorners(Cell cell)
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<CellCorner> |
|
GetCellDirs(Cell)
Returns directions we might expect TryMove to work for.
This usually just forwards to GetCellDirs()
Declaration
IEnumerable<CellDir> GetCellDirs(Cell cell)
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<CellDir> |
|
GetCells()
Gets a full list of cells in bounds.
Declaration
IEnumerable<Cell> GetCells()
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<Cell> |
|
GetCellsInBounds(IBound)
Returns the cells inside a given bound.
Declaration
IEnumerable<Cell> GetCellsInBounds(IBound bound)
Parameters
Type |
Name |
Description |
IBound |
bound |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<Cell> |
|
GetCellsIntersectsApprox(Vector3, Vector3)
Gets the set of cells that potentially overlap bounds.
Declaration
IEnumerable<Cell> GetCellsIntersectsApprox(Vector3 min, Vector3 max)
Parameters
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<Cell> |
|
GetCellType(Cell)
Returns the cell type associated with a given cell
Declaration
ICellType GetCellType(Cell cell)
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
GetCellTypes()
Declaration
IEnumerable<ICellType> GetCellTypes()
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<ICellType> |
|
Returns a deformation mapping from the cell's co-ordinates
to something that fits in the grids co-ordinates.
Declaration
Deformation GetDeformation(Cell cell)
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
GetDual()
Declaration
Returns
GetIndex(Cell)
Finds the index associated with a given cell.
Declaration
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
Type |
Description |
System.Int32 |
|
GetMeshData(Cell, out MeshData, out Matrix4x4)
For 3d cells, returns the mesh of a given cell.
Declaration
void GetMeshData(Cell cell, out MeshData meshData, out Matrix4x4 transform)
Parameters
GetPolygon(Cell, out Vector3[], out Matrix4x4)
For 2d cells, returns the polygon of the boundary of the cell.
For performance reasons, cells can share a vertices array, so you need to apply
a specific transform to get the polygon specific to a particular cell.
Declaration
void GetPolygon(Cell cell, out Vector3[] vertices, out Matrix4x4 transform)
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Vector3[] |
vertices |
The vertices of the polygon. This should not be mutated.
|
Matrix4x4 |
transform |
A transformation that needs to be applied to each vertex.
|
GetTriangleMesh(Cell)
For 3d cells, returns triangles on the boundary of a given cell, and which direction they correspond to.
Declaration
IEnumerable<(Vector3, Vector3, Vector3, CellDir)> GetTriangleMesh(Cell cell)
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
GetTRS(Cell)
Returns the appropriate transform for the cell.
The translation will always be to GetCellCenter,
rotation reflects the particular orientation of this cell
and the scale will reflect cell sizing.
GetTRS is often "best effort", there might not be an obvious
linear transformation from the canonical cell to the grid cell.
Declaration
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
IntersectBounds(IBound, IBound)
Returns a bound that contains cells included in both arguments.
Declaration
IBound IntersectBounds(IBound bound, IBound other)
Parameters
Returns
IsCellInBound(Cell, IBound)
Tests if a given cell is in bound.
i.e. returns true if the cell is listed in GetCellsInBounds.
Declaration
bool IsCellInBound(Cell cell, IBound bound)
Parameters
Returns
Type |
Description |
System.Boolean |
|
IsCellInGrid(Cell)
Returns true if the cell is in the grid (and within bounds).
This is one of the few methods that accepts any Cell object, most
other methods only work with the cells in the grid.
Declaration
bool IsCellInGrid(Cell cell)
Parameters
Type |
Name |
Description |
Cell |
cell |
|
Returns
Type |
Description |
System.Boolean |
|
ParallelTransport(IGrid, Cell, Cell, Cell, CellRotation, out Cell, out CellRotation)
Given a path in aGrid from aSrcCell to aDestCell
follows the same path in the current grid, starting at srcCell, and with the whole path rotated by startRotation.
Reports the final spot that the path ends at, and it's rotation.
Returns false if this cannot be done (typically because an equivalent pathc annot be found in the grid).
This method is useful for translating co-ordinates between different grids that are similarish, at least having the same celltypes.
For example, suppose
aGrid = new SquareGrid(1);
aSrcCell = new Cell(0, 0)
aDestCell = new Cell(5, 0)
srcCell = new Cell(100, 100)
startRotation = identity
Then the path in aGrid is a straight line moving 5 units to the right,
and this method would attempt to move 5 units in the straight line that leads right out of (100, 100).
Declaration
bool ParallelTransport(IGrid aGrid, Cell aSrcCell, Cell aDestCell, Cell srcCell, CellRotation startRotation, out Cell destCell, out CellRotation destRotation)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Raycast(Vector3, Vector3, Single)
Returns the cells intersecting a ray starting at origin, of length direction.magnitude * maxDistance, in order.
Declaration
IEnumerable<RaycastInfo> Raycast(Vector3 origin, Vector3 direction, float maxDistance = InfinityF)
Parameters
Type |
Name |
Description |
Vector3 |
origin |
|
Vector3 |
direction |
|
System.Single |
maxDistance |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<RaycastInfo> |
|
TryApplySymmetry(GridSymmetry, Cell, out Cell, out CellRotation)
Applies the mapping of s to cell, and also returns the rotation
For more details, see GridSymmetry.
For simple, regular grids, the output rotation is copied directly from Rotation.
Declaration
bool TryApplySymmetry(GridSymmetry s, Cell src, out Cell dest, out CellRotation r)
Parameters
Returns
Type |
Description |
System.Boolean |
|
TryApplySymmetry(GridSymmetry, IBound, out IBound)
Finds a bound that would contain all the cells of srcBound after applying the grid symmetry to them.
Declaration
bool TryApplySymmetry(GridSymmetry s, IBound srcBound, out IBound destBound)
Parameters
Returns
Type |
Description |
System.Boolean |
|
TryMove(Cell, CellDir, out Cell, out CellDir, out Connection)
Attempts to move from a cell in a given direction, and returns information about the move if successful.
Declaration
bool TryMove(Cell cell, CellDir dir, out Cell dest, out CellDir inverseDir, out Connection connection)
Parameters
Type |
Name |
Description |
Cell |
cell |
The cell to move from
|
CellDir |
dir |
The direction to move in
|
Cell |
dest |
The cell moved to
|
CellDir |
inverseDir |
The direction leading back from dest to cell.
|
Connection |
connection |
A descriptor of how cell-local space relates between cell and dest.
|
Returns
Type |
Description |
System.Boolean |
|
TryMoveByOffset(Cell, Vector3Int, Vector3Int, CellRotation, out Cell, out CellRotation)
Maps between cell offsets and cells in the grid.
This is normally done via FindBasicPath(Cell, Cell), but regular grids
often have a more efficient implementation.
Declaration
bool TryMoveByOffset(Cell startCell, Vector3Int startOffset, Vector3Int destOffset, CellRotation startRotation, out Cell destCell, out CellRotation destRotation)
Parameters
Returns
Type |
Description |
System.Boolean |
|
UnionBounds(IBound, IBound)
Returns a bound that contains cells included in either argument.
Declaration
IBound UnionBounds(IBound bound, IBound other)
Parameters
Returns
Extension Methods