Constructor
new AStar(getNeighbours, diagonal)
Parameters:
Name | Type | Description |
---|---|---|
getNeighbours |
function | |
diagonal |
Boolean | also allow moving diagonal |
Methods
(static) fromGrid(grid, walkable_cb, diagonal) → {AStar}
- Source:
Create an AStar instance from a grid
Example
let astar = AStar.fromGrid(grid, (node) => {
return node === 0;
});
let path = astar.calc({ x: 0, y: 0 }, { x: 4, y: 4 });
Parameters:
Name | Type | Default | Description |
---|---|---|---|
grid |
Grid | ||
walkable_cb |
function | callback that should return true/false if the node is walkable |
|
diagonal |
Boolean |
false
|
Returns:
- Type
- AStar
calc(start, end) → {Array}
- Source:
Calculate a path from start to end
Parameters:
Name | Type | Description |
---|---|---|
start |
Vector | Object | start position |
end |
Vector | Object | end position |
Returns:
the path as array of points [{x: start.x, y: start.y}, ..., {x: end.x, y: end.y}]
- Type
- Array