npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wave-pathfinder

v2.1.1

Published

Wave pathfinding (The Lee algorithm)

Downloads

9

Readme

Wave Pathfinder

Pathfinding for 2-dimensional matrix (rows, cols) using Lee algorithm, also known as wave pathfinding.

Code Climate Test Coverage

Advantages of wave algorithm:

  • Very simple, easy to understand and implement
  • Ability to quickly get matrix of all reachable cells with number of steps required
  • Once steps matrix has been calculated for start cell, it's very fast to find path to any reachable cell

Changelog:

2.1.0

Better tests and docs reflect changes since v1.

2.0.0

Breaking change!

Returns path as an array of points in matrix notation: [ [y1, x1], [y2, x2], ... ]

1.0.1

Breaking change!

Uses obstaclesMatrix instead of passabilityMatrix.

0.1.0

Working version

Installation:

$ npm install wave-pathfinder

Quick example:

var WavePathfinder = require('wave-pathfinder');

// use "truthy" values for obstacles 
// use "falsy" values for passable cells 
var obstaclesMatrix = [
  [ 0, 0, 0 ],
  [ 1, 1, 0 ],
  [ 0, 1, 0 ]
];

var startY = 0;
var startX = 0;

var finishY = 2;
var finishX = 2;

var path = WavePathfinder.findPath(obstaclesMatrix, startY, startX, finishY, finishX);
console.log(path); 

/* [ 
  [0, 0],
  [0, 1],
  [0, 2],
  [1, 2],
  [2, 2] 
] */

Advanced usage:

If you want to get access to the steps matrix and/or find multiple paths from one starting point, it's useful to instantiate pathfinder object and work with it.

  1. Create pathfinder object using passability matrix:
var WavePathfinder = require('wave-pathfinder');

// use "truthy" values for obstacles 
// use "falsy" values for passable cells 
var obstaclesMatrix = [
  [ 0, 0, 0 ],
  [ 1, 1, 0 ],
  [ 0, 1, 0 ]
];

var pathfinder = new WavePathfinder(obstaclesMatrix);
  1. Call "expandWave" to calculate possible steps matrix for given start cell. There's no need to call expandWave again after that, if start cell remains the same.
var startY = 0;
var startX = 0;

var stepsMatrix = pathfinder.expandWave(startY, startX);
console.log(stepsMatrix); 
console.log(pathfinder.stepsMatrix); // same as above 

/* 0: start cell 
   n: minimum number of steps
  -1: unreachable cell

[ 
  [  0,  1, 2 ], 
  [ -1, -1, 3 ], 
  [ -1, -1, 4 ] 
] */
  1. Call "backtracePath" to get path from start (which was setup during previous expandWave call) to given finish.
var finishY1 = 2;
var finishX1 = 2;

var path1 = pathfinder.backtracePath(finishY1, finishX1);
console.log(path1); 

/* [ 
  [0, 0],
  [0, 1],
  [0, 2],
  [1, 2],
  [2, 2] 
] */

var finishY2 = 1;
var finishX2 = 1;

var path2 = pathfinder.backtracePath(finishY2, finishX2);
console.log(path2);
 
/* [ 
  [0, 0],
  [0, 1],
  [0, 2]
] */
  1. Or, call shorthand "findPath" which will call expandWave and backtracePath under the hood.
var startY = 0;
var startX = 0;

var finishY = 1;
var finishX = 1;

var path = pathfinder.findPath(startY, startX, finishY, finishX);
console.log(path);

/* [ 
  [0, 0],
  [0, 1],
  [0, 2]
] */

var stepsMatrix = pathfinder.stepsMatrix;
console.log(stepsMatrix); 

/* 0: start cell 
   n: minimum number of steps
  -1: unreachable cell

[ 
  [  0,  1, 2 ], 
  [ -1, -1, 3 ], 
  [ -1, -1, 4 ] 
] */