Class WrapModifier
Turns any bounded grid into a grid which connects back on itself when you leave the grounds. This is done via a canonicalize method that is responsible for replacing cells that are outside of the bounds.
Implements
Inherited Members
Namespace: Sylves
Assembly: Sylves.dll
Syntax
public class WrapModifier : BaseModifier, IGrid
Constructors
WrapModifier(IGrid, Func<Cell, Cell?>)
Declaration
public WrapModifier(IGrid underlying, Func<Cell, Cell?> canonicalize)
Parameters
| Type | Name | Description |
|---|---|---|
| IGrid | underlying | |
| Func<Cell, Cell?> | canonicalize |
Properties
Unbounded
Returns the grid with any bounds removed.
Declaration
public override IGrid Unbounded { get; }
Property Value
| Type | Description |
|---|---|
| IGrid |
Overrides
Methods
Canonicalize(Cell)
Declaration
public Cell? Canonicalize(Cell cell)
Parameters
| Type | Name | Description |
|---|---|---|
| Cell | cell |
Returns
| Type | Description |
|---|---|
| Cell? |
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
| Type | Name | Description |
|---|---|---|
| ISet<Cell> | src | |
| ISet<Cell> | dest | |
| Cell | srcCell | |
| CellRotation | cellRotation |
Returns
| Type | Description |
|---|---|
| GridSymmetry |
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
| Type | Description |
|---|---|
| IDualMapping |
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
| Type | Name | Description |
|---|---|---|
| IGrid | aGrid | |
| Cell | aSrcCell | |
| Cell | aDestCell | |
| Cell | srcCell | |
| CellRotation | startRotation | |
| Cell | destCell | |
| CellRotation | destRotation |
Returns
| Type | Description |
|---|---|
| bool |
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
| Type | Name | Description |
|---|---|---|
| Vector3 | origin | |
| Vector3 | direction | |
| float | maxDistance |
Returns
| Type | Description |
|---|---|
| IEnumerable<RaycastInfo> |
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
| Type | Description |
|---|---|
| IGrid |
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
| Type | Name | Description |
|---|---|---|
| GridSymmetry | s | |
| Cell | src | |
| Cell | dest | |
| CellRotation | r |
Returns
| Type | Description |
|---|---|
| bool |
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
| Type | Description |
|---|---|
| bool |
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
| Type | Name | Description |
|---|---|---|
| Cell | startCell | |
| Vector3Int | startOffset | |
| Vector3Int | destOffset | |
| CellRotation | startRotation | |
| Cell | destCell | |
| CellRotation | destRotation |
Returns
| Type | Description |
|---|---|
| bool |