Show / Hide Table of Contents

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.

Namespace: Sylves
Assembly: Sylves.dll
Syntax
public interface IGrid

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
int IndexCount { get; }
Property Value
Type Description
System.Int32

Is2d

True if this grid uses 2d cell types

Declaration
bool Is2d { get; }
Property Value
Type Description
System.Boolean

Is3d

True if this grid uses 3d cell types

Declaration
bool Is3d { get; }
Property Value
Type Description
System.Boolean

IsFinite

True if there is a finite amout of cells in the grid.

Declaration
bool IsFinite { get; }
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
bool IsPlanar { get; }
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
IGrid Unbounded { get; }
Property Value
Type Description
IGrid

Unwrapped

Returns the grid with most grid modifiers removed.

Declaration
IGrid Unwrapped { get; }
Property Value
Type Description
IGrid

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
Type Description
IGrid

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
Type Name Description
Matrix4x4 matrix
Cell cell
CellRotation rotation
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
Type Name Description
Vector3 position
Cell cell
Returns
Type Description
System.Boolean

FindGridSymmetry(ISet<Cell>, ISet<Cell>, Cell, CellRotation)

Finds a GridSymmetry that:

  1. Maps from the cells of src into dest (in any order / rotation), and
  2. 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
Type Description
GridSymmetry

GetBound()

Returns the bound currently applied to the grid.

Declaration
IBound GetBound()
Returns
Type Description
IBound

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
Type Description
IBound

GetCellByIndex(Int32)

Finds the cell associated with a given index.

Declaration
Cell GetCellByIndex(int index)
Parameters
Type Name Description
System.Int32 index
Returns
Type Description
Cell

GetCellCenter(Cell)

Returns the center of the cell in local space

Declaration
Vector3 GetCellCenter(Cell cell)
Parameters
Type Name Description
Cell cell
Returns
Type Description
Vector3

GetCellCorner(Cell, CellCorner)

Returns the position of a corner.

Declaration
Vector3 GetCellCorner(Cell cell, CellCorner corner)
Parameters
Type Name Description
Cell cell
CellCorner corner
Returns
Type Description
Vector3

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
Type Name Description
Vector3 min
Vector3 max
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
Type Description
ICellType

GetCellTypes()

Returns the full list of cell types that can be returned by GetCellType(Cell)

Declaration
IEnumerable<ICellType> GetCellTypes()
Returns
Type Description
System.Collections.Generic.IEnumerable<ICellType>

GetDeformation(Cell)

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
Type Description
Deformation

GetDual()

Declaration
IDualMapping GetDual()
Returns
Type Description
IDualMapping

GetIndex(Cell)

Finds the index associated with a given cell.

Declaration
int GetIndex(Cell cell)
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
Type Name Description
Cell cell
MeshData meshData
Matrix4x4 transform

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
Type Description
System.Collections.Generic.IEnumerable<System.ValueTuple<Vector3, Vector3, Vector3, CellDir>>

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
TRS GetTRS(Cell cell)
Parameters
Type Name Description
Cell cell
Returns
Type Description
TRS

IntersectBounds(IBound, IBound)

Returns a bound that contains cells included in both arguments.

Declaration
IBound IntersectBounds(IBound bound, IBound other)
Parameters
Type Name Description
IBound bound
IBound other
Returns
Type Description
IBound

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
Type Name Description
Cell cell
IBound bound
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
Type Name Description
IGrid aGrid
Cell aSrcCell
Cell aDestCell
Cell srcCell
CellRotation startRotation
Cell destCell
CellRotation destRotation
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
Type Name Description
GridSymmetry s
Cell src
Cell dest
CellRotation r
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
Type Name Description
GridSymmetry s
IBound srcBound
IBound destBound
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
Type Name Description
Cell startCell
Vector3Int startOffset
Vector3Int destOffset
CellRotation startRotation
Cell destCell
CellRotation destRotation
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
Type Name Description
IBound bound
IBound other
Returns
Type Description
IBound

Extension Methods

GridExtensions.Move(IGrid, Cell, CellDir)
GridExtensions.GetNeighbours(IGrid, Cell)
GridExtensions.FindCell(IGrid, Vector3)
GridExtensions.Transformed(IGrid, Matrix4x4)
GridExtensions.Masked(IGrid, ISet<Cell>)
GridExtensions.Masked(IGrid, Func<Cell, Boolean>, IEnumerable<Cell>)
GridExtensions.ToMeshData(IGrid, IEnumerable<Cell>)
GridExtensions.GetPolygon(IGrid, Cell)
GridExtensions.GetMeshData(IGrid, Cell)
In This Article
Back to top Generated by DocFX