findPath

(require("findPath"))(start, end, nonRoutable, punishedButRoutable) → {Array}

Heavily modified implementation of the A* algorithm

Parameters:
Name Type Description
start Object

object containing numeric attributes x and y that represent the first endpoint of the wire in grid pixels

end Object

object containing numeric attributes x and y that represent the second endpoint of the wire in grid pixels

nonRoutable Set

set of non routable nodes

punishedButRoutable Set

set of nodes that are not optimal for routing

Returns:
Array -

array of objects containing numeric attributes x and y

Methods

inner movePoint(point, direction) → {Object}

Helper that moves the passed point in the specified direction. It simply adds or subtracts 1 from one of the coordinates depending on the direction attribute.

Parameters:
Name Type Description
point Object

object containing numeric attributes x and y

direction number

directions: - 0: up - 1: right - 2: down - 3: left

Returns:
Object -

object containing numeric attributes x and y

inner reconstructPath(cameFrom, currentNode) → {Array}

helper backtracking function used by the aStar algorithm to construct the final path

Parameters:
Name Type Description
cameFrom Object

object containing numeric attributes x and y

currentNode Object

object containing numeric attributes x and y

Returns:
Array -

array of objects containing numeric attributes x and y

inner setHasThisPoint(set, point)

returns true if the specified set of points contains the specified point (and returns false otherwise)

Parameters:
Name Type Description
set Set

set of points

point Object

object containing numeric attributes x and y