Class BijectModifier
Remaps the cells of the grid by changing their co-ordinates,
without touching the position, shape or topology.
Inheritance
BijectModifier
Assembly: Sylves.dll
Syntax
public class BijectModifier : BaseModifier, IGrid
Constructors
BijectModifier(IGrid, Func<Cell, Cell>, Func<Cell, Cell>, int)
Declaration
public BijectModifier(IGrid underlying, Func<Cell, Cell> toUnderlying, Func<Cell, Cell> fromUnderlying, int coordinateDimension = 3)
Parameters
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
public override int CoordinateDimension { get; }
Property Value
Overrides
Methods
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
public override IEnumerable<(Cell, CellDir)> FindBasicPath(Cell startCell, Cell destCell)
Parameters
| Type |
Name |
Description |
| Cell |
startCell |
|
| Cell |
destCell |
|
Returns
Overrides
FindCell(Matrix4x4, out Cell, out CellRotation)
Returns the cell and rotation corresponding to a given transform matrix.
Declaration
public override bool FindCell(Matrix4x4 matrix, out Cell cell, out CellRotation rotation)
Parameters
Returns
Overrides
FindCell(Vector3, out Cell)
Finds the cell containg the give position
Declaration
public override bool FindCell(Vector3 position, out Cell cell)
Parameters
Returns
Overrides
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
public override GridSymmetry FindGridSymmetry(ISet<Cell> src, ISet<Cell> dest, Cell srcCell, CellRotation cellRotation)
Parameters
Returns
Overrides
GetBound(IEnumerable<Cell>)
Returns a bound that contains all the listed cells.
Declaration
public override IBound GetBound(IEnumerable<Cell> cells)
Parameters
Returns
Overrides
GetCellByIndex(int)
Finds the cell associated with a given index.
Declaration
public override Cell GetCellByIndex(int index)
Parameters
| Type |
Name |
Description |
| int |
index |
|
Returns
Overrides
GetCellCenter(Cell)
Returns the center of the cell in local space
Declaration
public override Vector3 GetCellCenter(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
GetCellCorner(Cell, CellCorner)
Returns the position of a corner.
Declaration
public override Vector3 GetCellCorner(Cell cell, CellCorner corner)
Parameters
Returns
Overrides
GetCellDirs(Cell)
Returns directions we might expect TryMove to work for.
This usually just forwards to GetCellDirs()
Declaration
public override IEnumerable<CellDir> GetCellDirs(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
GetCellType(Cell)
Returns the cell type associated with a given cell
Declaration
public override ICellType GetCellType(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
GetCells()
Gets a full list of cells in bounds.
Declaration
public override IEnumerable<Cell> GetCells()
Returns
Overrides
GetCellsIntersectsApprox(Vector3, Vector3)
Gets the set of cells that potentially overlap bounds.
Declaration
public override IEnumerable<Cell> GetCellsIntersectsApprox(Vector3 min, Vector3 max)
Parameters
Returns
Overrides
GetCompactGrid()
For a grid that has CoordinateDimension == 3,
returns a grid that is the same as the current, but uses at most 2 dimensions.
Otherwise, returns the current grid.
(see RavelModifier if you want to reduce to 1 dimension).
Declaration
public override IGrid GetCompactGrid()
Returns
Overrides
Returns a deformation mapping from the cell's co-ordinates
to something that fits in the grids co-ordinates.
Declaration
public override Deformation GetDeformation(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
GetDual()
Returns a second grid which has one cell for every vertex of this grid,
and also methods for mapping corners of one grid to the other.
Declaration
public override IDualMapping GetDual()
Returns
Overrides
GetIndex(Cell)
Finds the index associated with a given cell.
Declaration
public override int GetIndex(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
GetMeshData(Cell, out MeshData, out Matrix4x4)
For 3d cells, returns the mesh of a given cell.
Declaration
public override void GetMeshData(Cell cell, out MeshData meshData, out Matrix4x4 transform)
Parameters
Overrides
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
public override 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.
|
Overrides
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
public override TRS GetTRS(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
GetTriangleMesh(Cell)
For 3d cells, returns triangles on the boundary of a given cell, and which direction they correspond to.
Declaration
public override IEnumerable<(Vector3, Vector3, Vector3, CellDir)> GetTriangleMesh(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
IsCellInBound(Cell, IBound)
Tests if a given cell is in bound.
i.e. returns true if the cell is listed in GetCellsInBounds.
Declaration
public override bool IsCellInBound(Cell cell, IBound bound)
Parameters
Returns
Overrides
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
public override bool IsCellInGrid(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
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
public override bool ParallelTransport(IGrid aGrid, Cell aSrcCell, Cell aDestCell, Cell srcCell, CellRotation startRotation, out Cell destCell, out CellRotation destRotation)
Parameters
Returns
Overrides
Raycast(Vector3, Vector3, float)
Returns the cells intersecting a ray starting at origin, of length direction.magnitude * maxDistance, in order.
Declaration
public override IEnumerable<RaycastInfo> Raycast(Vector3 origin, Vector3 direction, float maxDistance = Infinity)
Parameters
Returns
Overrides
Rebind(IGrid)
Creates a new grid applying the current wrapper to a new underlying.
Declaration
protected override IGrid Rebind(IGrid underlying)
Parameters
| Type |
Name |
Description |
| IGrid |
underlying |
|
Returns
Overrides
Recenter(Cell)
Translates the grid so that the given cell is at the origin,
trying to minimize floating point error for nearby cells.
Declaration
public override IGrid Recenter(Cell cell)
Parameters
| Type |
Name |
Description |
| Cell |
cell |
|
Returns
Overrides
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
public override bool TryApplySymmetry(GridSymmetry s, Cell src, out Cell dest, out CellRotation r)
Parameters
Returns
Overrides
TryApplySymmetry(GridSymmetry, IBound, out IBound)
Finds a bound that would contain all the cells of srcBound after applying the grid symmetry to them.
Declaration
public override bool TryApplySymmetry(GridSymmetry s, IBound srcBound, out IBound destBound)
Parameters
Returns
Overrides
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
public override 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
Overrides
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
public override bool TryMoveByOffset(Cell startCell, Vector3Int startOffset, Vector3Int destOffset, CellRotation startRotation, out Cell destCell, out CellRotation destRotation)
Parameters
Returns
Overrides
Implements
Extension Methods