Struct HexGrid
A simple hexagonal grid structure that can be used for pathfinding queries. Each cell can have an additional cost and flags associated with it.
Namespace: AnyPath.Graphs.HexGrid
Assembly: AnyPath.dll
Syntax
public struct HexGrid : IGraph<HexGridCell>, IDisposable
Remarks
The cells are stored in a hash map, which is more memory efficient for sparse grids. For raw performance, this grid can be easily modified to using an array instead.
Constructors
HexGrid(int2, int2, IReadOnlyList<HexGridCell>, Allocator, HexGridType)
Constructs a new hexagonal grid.
Declaration
public HexGrid(int2 min, int2 max, IReadOnlyList<HexGridCell> cells, Allocator allocator, HexGridType type = HexGridType.OddR)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | min | Boundary min |
| int2 | max | Boundary max |
| IReadOnlyList<HexGridCell> | cells | A list containing all cells that need to be set and the cost associated with them. Use a cost of PositiveInfinity to make a cell unwalkable. Locations that are ommitted in the array will be considered as open. |
| Allocator | allocator | |
| HexGridType | type | Type of hexgrid |
HexGrid(int2, int2, Allocator, HexGridType)
Constructs a new hexagonal grid.
Declaration
public HexGrid(int2 min, int2 max, Allocator allocator, HexGridType type = HexGridType.OddR)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | min | Boundary min |
| int2 | max | Boundary max |
| Allocator | allocator | |
| HexGridType | type | Type of hexgrid |
Fields
gridType
Type of hexgrid
Declaration
public readonly HexGridType gridType
Field Value
| Type | Description |
|---|---|
| HexGridType |
max
The boundary -max- position
Declaration
public readonly int2 max
Field Value
| Type | Description |
|---|---|
| int2 |
min
The boundary -min- position
Declaration
public readonly int2 min
Field Value
| Type | Description |
|---|---|
| int2 |
Methods
Collect(HexGridCell, ref NativeList<Edge<HexGridCell>>)
Collects all neighbouring cells from a given location
Declaration
public void Collect(HexGridCell node, ref NativeList<Edge<HexGridCell>> edgeBuffer)
Parameters
| Type | Name | Description |
|---|---|---|
| HexGridCell | node | The location to find the neighbours for |
| NativeList<Edge<HexGridCell>> | edgeBuffer |
GetCell(int2)
Returns the cell at a given position.
Declaration
public HexGridCell GetCell(int2 position)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | position |
Returns
| Type | Description |
|---|---|
| HexGridCell |
GetEnumerator()
Enumerates all of the cells in the grid, including unset ones. This can be used for constructing ALT heuristics.
Declaration
public HexGrid.Enumerator GetEnumerator()
Returns
| Type | Description |
|---|---|
| HexGrid.Enumerator |
GetSetCells(Allocator)
Allocates an array containing all of the cells that are set on this grid.
Declaration
public NativeArray<HexGridCell> GetSetCells(Allocator allocator)
Parameters
| Type | Name | Description |
|---|---|---|
| Allocator | allocator |
Returns
| Type | Description |
|---|---|
| NativeArray<HexGridCell> |
InBounds(int2)
Returns wether a certain position is within the bounds of the grid
Declaration
public bool InBounds(int2 position)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | position |
Returns
| Type | Description |
|---|---|
| bool |
IsOpen(int2)
Returns wether a cell at a position is open/walkable.
Declaration
public bool IsOpen(int2 position)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | position |
Returns
| Type | Description |
|---|---|
| bool |
SetCell(int2, float, int)
Sets the cost for a cell.
Declaration
public void SetCell(int2 position, float enterCost, int flags = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | position | Position to set |
| float | enterCost | Additional cost for walking this cell. Use float.PositiveInfinity to make this cell unwalkable |
| int | flags | Flags for this cell, this can be used in conjunction with FlagBitmask<TNode> to exclude certain areas. |
Remarks
No bounds checking is done on the position