getPath method

List<int> getPath()

Returns the shortest path from the source to the target node as an array of node indices.

Implementation

List<int> getPath() {
	// array of node indices that comprise the shortest path from the source to the target
	final path = <int>[];

	// just return an empty path if no path to target found or if no target has been specified
	if ( found == false || target == - 1 ) return path;

	// start with the target of the path
	int currentNode = target;
	path.add( currentNode );

	// while the current node is not the source node keep processing
	while ( currentNode != source ) {
		// determine the parent of the current node
		currentNode = _route[currentNode];

		// push the new current node at the beginning of the array
		path.insert(0, currentNode );
	}

	return path;
}