Skip to content

@graphty/algorithms / index / pathfindingUtils

Variable: pathfindingUtils ​

const pathfindingUtils: object

Defined in: pathfinding/utils.ts:5

Utility functions for pathfinding algorithms

Type Declaration ​

createGridGraph() ​

createGridGraph(width, height, obstacles): Map<string, Map<string, number>>

Creates a grid graph for testing pathfinding algorithms

Parameters ​

width ​

number

The width of the grid

height ​

number

The height of the grid

obstacles ​

Set<string> = ...

Set of obstacle coordinates as "x,y" strings

Returns ​

Map<string, Map<string, number>>

A grid graph with 4-directional movement

parseGridCoordinate() ​

parseGridCoordinate(coord): [number, number]

Parses a grid coordinate string

Parameters ​

coord ​

string

The coordinate string in "x,y" format

Returns ​

[number, number]

A tuple of [x, y] coordinates

reconstructPath() ​

reconstructPath<T>(cameFrom, goal): T[]

Reconstructs a path from start to goal using the cameFrom map

Type Parameters ​

T ​

T

Parameters ​

cameFrom ​

Map<T, T>

Map of each node to its predecessor on the path

goal ​

T

The goal node to reconstruct the path to

Returns ​

T[]

An array of nodes representing the path from start to goal