• Articles
  • Api Documentation
Show / Hide Table of Contents
  • AnyPath
    • Graphs
      • Extra
        • Line2D
        • Line3D
        • Triangle
      • HexGrid
        • HexGrid
        • HexGrid.Enumerator
        • HexGridCell
        • HexGridHeuristicProvider
        • HexGridType
      • Line
        • ClosestLineLocationPredicate
        • LineGraph
        • LineGraph.Edge
        • LineGraph.Enumerator
        • LineGraphBuilder
        • LineGraphBuilder.ProtoEdge
        • LineGraphDrawer
        • LineGraphHeuristic
        • LineGraphLocation
        • LineGraphPopulator
        • LineGraphProcessor
        • LineGraphWelder
        • SceneGraph
          • LineGraphNode
          • LineSceneGraph
          • LineSceneGraphEdge
          • SceneGraphNodeEditor
      • NavMesh
        • ClosestNavMeshLocationPredicate
        • CornerAndNormal
        • IUnrolledNavMeshGraphPortal
        • NavMeshGraph
        • NavMeshGraph.EnterCostAndFlags
        • NavMeshGraph.Enumerator
        • NavMeshGraphCorners
        • NavMeshGraphCorners3D
        • NavMeshGraphHeuristic
        • NavMeshGraphLocation
        • NavMeshGraphUnroller
        • NavMeshLineBitmaskMod
        • NavMeshLineMod
        • NavMeshPlaneBitmaskMod
        • NavMeshPlaneMod
        • NavMeshPopulator
        • NavMeshWelder
        • SSFA
        • UnrolledNavMeshGraphPortal
      • Node
        • NodeGraph
        • NodeGraphNode
      • PlatformerGraph
        • ClosestPlatformerGraphLocationPredicate
        • PlatformerGraph
        • PlatformerGraph.Enumerator
        • PlatformerGraphBuilder
        • PlatformerGraphBuilder.ProtoEdge
        • PlatformerGraphDrawer
        • PlatformerGraphHeuristic
        • PlatformerGraphLocation
        • PlatformerGraphPopulator
        • PlatformerGraphProcessor
        • PlatformerGraphWelder
        • SceneGraph
          • PlatformerSceneGraph
          • PlatformerSceneGraphEdge
          • PlatformerSceneGraphNode
          • SceneGraphNodeEditor
      • SquareGrid
        • SquareGrid
        • SquareGrid.Enumerator
        • SquareGridCell
        • SquareGridHeuristicProvider
        • SquareGridHeuristicProviderEightDirectional
        • SquareGridHeuristicProviderManhattanDistance
        • SquareGridType
      • VoxelGrid
        • VoxelGrid
        • VoxelGrid.DirCost
        • VoxelGrid.Enumerator
        • VoxelGridCell
        • VoxelGridDirectionFlags
        • VoxelGridDirectionMod
        • VoxelGridHeuristicProvider
        • VoxelGridHeuristicProviderManhattanDistance
    • Managed
      • ClearFinderFlags
      • FinderExtensions
      • IFinder
      • IOptionReserver<TOption>
      • IOptionValidator<TOption>
      • ImmutableFinderException
      • ManagedDisposeExtensions
      • Results
        • DijkstraResult<TNode>
        • Eval
        • Eval<TOption>
        • MultiEvalResult
        • MultiPathResult<TSeg>
        • Path<TSeg>
        • Path<TOption, TSeg>
    • Native
      • AStarCheapestOption
      • AStarEvalOptionResult
      • AStarEvalResult
      • AStarFindOptionResult
      • AStarFindPathResult
      • AStarOption
      • AStarStops
      • AStar<TNode>
      • ComposedGraph<TGraph, TNode>
      • Edge<TNode>
      • FlagBitmask<TNode>
      • IEdgeMod<TNode>
      • IGraph<TNode>
      • IHeuristicProvider<TNode>
      • INodeFlags
      • IPathProcessor<TNode, TSeg>
      • NativeListWrapper<TSeg>
      • NoEdgeMod<TNode>
      • NoProcessing<TNode>
      • OffsetInfo
      • ReversedGraph<TNode>
      • EdgeMods
        • AdditionalAndExcludeEdges<TNode>
        • AdditionalEdges<TNode>
        • ExcludeEdges<TNode>
        • ExcludeLocations<TNode>
      • Heuristics
        • ALTCompute<TGraph, TNode>
        • ALTSerialization
        • ALT<TNode>
        • LandmarkSelection<TGraph, TNode, TEnumerator>
      • Util
        • IRefComparer<T>
        • NativeMinHeap<T, TComp>
        • NativeRefMinHeap<T, TComp>

Struct SquareGrid

A 2D-grid where each cell is defined as an int2 Travelling one cell along the map has a cost of 1 + destination cell cost. Travelling diagonally has a cost of sqrt(2) + destination cell cost. Unset cells have a default cost of zero. To make a cell unwalkable, assign it a cost of infinity. This means that every location is walkable by default.

Implements
IGraph<SquareGridCell>
IDisposable
Namespace: AnyPath.Graphs.SquareGrid
Assembly: AnyPath.dll
Syntax
public struct SquareGrid : IGraph<SquareGridCell>, IDisposable

Constructors

SquareGrid(int2, int2, SquareGridType, IReadOnlyList<SquareGridCell>, Allocator)

Constructs a new grid

Declaration
public SquareGrid(int2 min, int2 max, SquareGridType neighbourMode, IReadOnlyList<SquareGridCell> cells, Allocator allocator)
Parameters
Type Name Description
int2 min

Boundary min

int2 max

Boundary max

SquareGridType neighbourMode

Should cells have four or eight neighbours?

IReadOnlyList<SquareGridCell> cells

Array containing the cells to set initially

Allocator allocator

Allocator to use

SquareGrid(int2, int2, SquareGridType, int, Allocator)

Constructs a new grid

Declaration
public SquareGrid(int2 min, int2 max, SquareGridType neighbourMode, int capacity, Allocator allocator)
Parameters
Type Name Description
int2 min

Boundary min

int2 max

Boundary max

SquareGridType neighbourMode

Should cells have four or eight neighbours?

int capacity

Initial capacity of the internal hashmap

Allocator allocator

Allocator to use

Fields

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

neighbourMode

Type of grid, 4 our 8 neighbours

Declaration
public readonly SquareGridType neighbourMode
Field Value
Type Description
SquareGridType

Methods

Collect(SquareGridCell, ref NativeList<Edge<SquareGridCell>>)

Collects all neighbouring cells from a given location

Declaration
public void Collect(SquareGridCell node, ref NativeList<Edge<SquareGridCell>> edgeBuffer)
Parameters
Type Name Description
SquareGridCell node

The location to find the neighbours for

NativeList<Edge<SquareGridCell>> edgeBuffer

GetCell(int2)

Returns the cell at a given position.

Declaration
public SquareGridCell GetCell(int2 position)
Parameters
Type Name Description
int2 position
Returns
Type Description
SquareGridCell

GetCost(int2)

Returns the enter cost of a given position. Note that unset cells are considered open and have an entering cost of zero.

Declaration
public float GetCost(int2 position)
Parameters
Type Name Description
int2 position
Returns
Type Description
float

GetEnumerator()

Enumerates all of the cells in the grid, including unset ones. This can be used for constructing ALT heuristics.

Declaration
public SquareGrid.Enumerator GetEnumerator()
Returns
Type Description
SquareGrid.Enumerator

GetSetCells(Allocator)

Allocates an array containing all of the cells that are set on this grid.

Declaration
public NativeArray<SquareGridCell> GetSetCells(Allocator allocator)
Parameters
Type Name Description
Allocator allocator
Returns
Type Description
NativeArray<SquareGridCell>

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

Implements

IGraph<TNode>
IDisposable

Extension Methods

FinderExtensions.AddOption<T, TNode, TOption>(T, TOption, TNode, TNode)
FinderExtensions.AddOptions<T, TNode, TOption>(T, IEnumerable<TOption>, TNode, Func<TOption, TNode>)
FinderExtensions.AddRange<T, TNode, TOption>(T, IEnumerable<TOption>, TNode, Func<TOption, TNode>)
FinderExtensions.AddRequest<T, TNode>(T, TNode, TNode)
FinderExtensions.AddRequests<T, TNode>(T, IEnumerable<TNode>)
FinderExtensions.AddStop<T, TNode>(T, TNode)
FinderExtensions.AddStops<T, TNode>(T, IEnumerable<TNode>)
FinderExtensions.SetComparer<T, TOption>(T, IComparer<TOption>)
FinderExtensions.SetEdgeMod<T, TMod>(T, TMod)
FinderExtensions.SetGraph<T, TGraph>(T, TGraph)
FinderExtensions.SetHeuristicProvider<T, TH>(T, TH)
FinderExtensions.SetPathProcessor<T, TProc>(T, TProc)
FinderExtensions.SetReserver<T, TOption>(T, IOptionReserver<TOption>)
FinderExtensions.SetStartAndGoal<T, TNode>(T, TNode, TNode)
FinderExtensions.SetValidator<T, TOption>(T, IOptionValidator<TOption>)
ManagedDisposeExtensions.DisposeGraph<TGraph>(TGraph)
In This Article
Back to top Generated by DocFX