Constructor
new Pathfinder($heuristic)
- Description:
- Creates a new pathfinder.
- Source:
Example
// minimal
const pathfinder = new Pathfinder();
const path = pathfinder.find({
$grid: grid,
$start: new Vector2(-2, 0),
$finish: new Vector2(2, 0),
$access: accessor
});
// full
const pathfinder = new Pathfinder(heuristic);
const path = pathfinder.find({
$grid: grid,
$start: new Vector2(-2, 0),
$finish: new Vector2(2, 0),
$access: accessor
});
Parameters:
| Name | Type | Description |
|---|---|---|
$heuristic |
TypeHeuristic | The heuristic function to use. |
Methods
find($parameters) → {Array.<Vector2>}
- Description:
- Gets the shortest path between the positions of the two given cells of the given weighted grid.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$parameters |
object | The given parameters. |
$parameters.$grid |
Grid.<TypeGeneric> | The weighted grid. |
$parameters.$start |
Vector2 | The position of the 'start' cell. |
$parameters.$finish |
Vector2 | The position of the 'finish' cell. |
$parameters.$access |
TypeAccessor.<TypeGeneric> | The accessor to the cost of a cell. |
Returns:
- Type
- Array.<Vector2>
Type Definitions
(protected) TypeAccessor($item) → {number}
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$item |
TypeGeneric | The item. |
Returns:
- Type
- number
(protected) TypeHeuristic($a, $b) → {number}
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$a |
Vector2 | The position of the first cell to compare. |
$b |
Vector2 | The position of the second cell to compare. |
Returns:
- Type
- number
TypeNode
- Description:
- A pathfinder node.
- Source:
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
$cost |
number | The current cost. | |
$heuristic |
number | The heuristic cost. | |
$parent |
TypeNode |
<optional> |
The parent node. |
$position |
Vector2 | The position. |
A pathfinder node.
Type:
- object