# pathfindingjs

> Install with `npm install gjuchault/pathfindingjs --save`

Latest version **1.1.2** (published 2015-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install pathfindingjs
pnpm add pathfindingjs
yarn add pathfindingjs
bun add pathfindingjs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2015-12-03 |
| First published | 2015-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Gabriel Juchault |
| Maintainers | gjuchault |

## Links

- npm: https://www.npmjs.com/package/pathfindingjs
- npm.io page: https://npm.io/package/pathfindingjs

## Dependencies (1)

- [bindings](https://npm.io/package/bindings.md) ^1.2.1

## Recent versions

- 1.1.2 (latest) — 2015-12-03
- 1.1.1 — 2015-11-05

## README

# Pathfindingjs

Install with `npm install gjuchault/pathfindingjs --save`

## Basic usage

```js
var grid = [
    [ 0, 1, 0, 0, 0 ],
    [ 0, 0, 1, 0, 0 ],
    [ 0, 0, 0, 1, 0 ],
    [ 0, 1, 1, 1, 0 ],
    [ 0, 0, 0, 0, 0 ]
];

var Pathfinding = require('pathfindingjs');

var finder = new Pathfinding(grid);
var path = finder
    .setFrom(2, 0)
    .setTo(2, 2)
    .find();
console.log(path);
```

Note : if you try to reach the origin point (from `(2, 0)` to `(2, 0)`), `find` will return true

## Walker size

The walker size is a number representing the width taken by the walker around its starting point.
That means that a basic walker has a walker size of 1 (`O` being the walker) :
```
. . . .
. O . .
. . . .
. . . .
```

And a walker with a size of two is like this (`O` and `x` being the walker) :
```
x x x .
x O x .
x x x .
. . . .
```

```
var grid = [
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 ],
    [ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 ]
];

var Pathfinding = require('.');

var finder = new Pathfinding(grid, 2);
var path = finder
    .setFrom(1, 1)
    .setTo(13, 2)
    .find();

console.log(path);
```

## Chaining

After calling find, the origin is set to the target point, and you may call `setTo` and `find` again

```js
var grid = [
    [ 0, 1, 0, 0, 0 ],
    [ 0, 0, 1, 0, 0 ],
    [ 0, 0, 0, 1, 0 ],
    [ 0, 1, 1, 1, 0 ],
    [ 0, 0, 0, 0, 0 ]
];

var Pathfinding = require('pathfindingjs');

var finder = new Pathfinding(grid);
var path = finder
    .setFrom(2, 0)
    .setTo(2, 2)
    .find();
console.log(path);

var returnPath = finder
    .setTo(2, 0)
    .find();
console.log(returnPath);

require('assert').deepEqual(path.reverse(), returnPath);
```

## Path length

If you want to compare two smoothen paths, you may want to use `Pathfinding.getFullLength(path)`.
It will return the sum of Manhattan distances between each point. This is useful only on smoothen
paths.

---
_Source: https://npm.io/package/pathfindingjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
