Given a binary ndarray encoding a grid, calling l1-path-finder constructs a data structure for shortest path queries.
You can then query the planner by calling .search(), which computes the shortest path between a pair of points. That's it!
var ndarray = require('ndarray') var createPlanner = require('l1-path-finder') //Create a maze as an ndarray var maze = ndarray([ 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, ], [8, 7]) //Create path planner var planner = createPlanner(maze) //Find path var path = [] var dist = planner.search(0,0, 7,6, path) //Log output console.log('path length=', dist) console.log('path = ', path)
l1-path-finder is also extremely fast in practice.
On the grid path planning challenge [4] data set, it outperforms all other JavaScript path planning libraries by orders of magnitude:
The JavaScript implementation of l1-path-finder is even competitive with state of the art native C++ codes.
The following chart is a comparison to the Dan Harabor's implementation of jump point search [5]: