This package has been deprecated

Author message:

Deprecated as there are better implementations

create-paths

1.1.1 • Public • Published

create-paths

experimental

Create a graph like structure with nodes and edges and calculate the duration between positions along the graph.

Example

var createPaths = require('create-paths');
 
var traverse = createPaths( [
    ['a', 'b', 1],
    ['a', 'c', 0.5],
    ['c', 'b', 0.25]
]);
 
// { duration: 0.75, path: [ 'a', 'c', 'b' ] }
console.log(traverse('a', 'b')); 
 
// { duration: 0.85, path: [ 'a', 'c', 'b' ] }
console.log(traverse({ from: 'a', to: 'b', location: 0.1 }, 'b')); 

Usage

NPM

var traverse = require('create-paths')(map);

When this module is passed a map it will return a function which can be used to traverse the network of underlying nodes to find the path from one location to another.

map should be an a two dimensional array. Each element of that array should describe a segment of a path.

So in the example:

[
    ['a', 'b', 1],
    ['a', 'c', 0.5],
    ['c', 'b', 0.25]
]

['a', 'b', 1] describes that you can go from 'a' to 'b' in 1.

var info = traverse(from, to);

The returned traverse function can be used to find the path and duration between two locations.

from can be a simple string which correlates to the original map passed in. Or i can describe a location between two locations using the following notations:

{ from: 'a', to: b: 'b', location: 0.1 }

Which states we're between 'a' and 'b' at 0.1.

to must always be a string.

info will be null if a path cannot be found between two locations. If path can be found it will be in the form:

{
    duration: 0.5,
    path: [ 'a', 'b', 'c' ]
}

Where duration is how the total distance/duration defined by the original map passed in. path is the name of the nodes that will be visited.

License

MIT, see LICENSE.md for details.

Dependents (1)

Package Sidebar

Install

npm i create-paths

Weekly Downloads

6

Version

1.1.1

License

MIT

Last publish

Collaborators

  • mikkoh