1.1.1 • Published 10 years ago

create-paths v1.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

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.

1.1.1

10 years ago

1.1.0

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago