A class that represents a graph. Serves as a container for a group of nodes.
0.2.0
.Constructor
new(?parent:Object, defaultAutoConnect:Bool = false, trackNetworks:Bool = false)
Creates an nb.Graph
instance.
Parameters:
parent | The instance's parent object. |
---|---|
defaultAutoConnect | Whether this instance should use assign a default function to |
trackNetworks | Whether this instance should track networks. (See |
Variables
read onlydebugG:Graphics = new Graphics()
The nb.Graphics
instance to draw this instance's debug visuals.
debugInteractives:Array<Interactive> = []
The nb.Graphics
instance to draw this instance's interactives debug visuals.
networks:Array<Array<Node>> = [[]]
Contains all networks of this instance. A network is an array of nb.Node
instances
that are all connected. A connection betweens two nodes in a network means that there
exists a path that connects the two.
A network has an associated ID number starting from 1. Doing networks[5]
accesses
the array of nodes pertaining to a network with 5
as the id.
skippedNetworksIds:Array<Int> = []
Contains network ids that were never used. Those ids are always lower than the highest used netword id.
read onlytrackNetworks:Bool
Whether this instance should track networks. Networks are nodes all connected to each other, directly or indirectly.
Methods
addNode(p:Point, autoConnect:Bool = false):Node
Adds a node to this graph.
Parameters:
p | An |
---|---|
autoConnect | If |
Returns:
The nb.Graph.Node
instance representing the node.
dynamicautoConnect(allNodes:Array<Node>, newNode:Node):Void
A saved connection logic.
Parameters:
allNodes | All nodes in this instance. |
---|---|
newNode | The node that was just added to this instance. |
connect(node:Node, toNodes:Array<Node>):Void
Connects a node to other nodes.
Parameters:
node | The node that will be connected. |
---|---|
toNodes | The nodes |
convertNetwork(from:Int, to:Int):Void
Moves all the nodes of a network to another network.
All the nodes belonging to the network with id from
now belongs to the network with id to
.
Nothing happens to the nodes that are already in the destination network.
Parameters:
from | The ID of the network to move from. |
---|---|
to | The ID of the network to move to. |
debugDraw(pointRadius:Float = 2, withInteractive:Bool = false):Void
Draws a visualization of this instance.
POINT:
Green: Connected, in path
| Grey: Connected, not in path
| Red: No connection
SEGMENT:
Darker green: In path
| Grey: Anything else
Parameters:
pointRadius | The radius of the circle drawn for each node. |
---|---|
withInteractive | Whether the nodes will have their interactives enabled, making them movable. |
disconnect(node:Node, fromNodes:Array<Node>):Void
Disconnects a node from other nodes.
Parameters:
node | The node that will be disconnected. |
---|---|
fromNodes | The nodes |
getLastPathInfo():{start:Node, newCalcNodes:Array<Node>, lastPath:Array<Node>, end:Node, currentNode:Node, checkedNodes:Array<Node>, calculatedNodes:Array<Node>}
getNodeAtPoint(p:Point):Null<Node>
Returns the node with the coordinates of p
. (There's a tiny tolerance value.)
dynamiconJustCalculated(node:Node):Void
Called in pathfinding, when a node's pathfinder values was just assigned.
dynamiconWasCalculated(node:Node):Void
Called in pathfinding, at the start of the loop, when a node had its pathfinder values assigned in the previous loop.
path(start:Node, end:Node, ?maxStep:Int, skipEvents:Bool = false, updateVars:Bool = true):Null<Array<Node>>
Returns a path between a node and another node.
Parameters:
start | The node to start the path from. |
---|---|
end | The node to end the path to. |
maxStep | The maximum number of steps/loop count. |
skipEvents | Whether pathfinder events should be called. |
setLastPath | Whether |
Returns:
An array of nb.Graph.Node
instances representing a path.