Neighbors¶
- Plugin name:
"neighbors" - Plugin namespace:
"neighbors"
Loading the plugin¶
Warning
This plugin requires special metadata to compute the neighbors, so it will not work with all maps, only those with that additional information.
If this plugin is loaded, the module will have the following additional features:
Methods¶
getAdjacentNeighbors()¶
Asynchronous method that returns a group of quantity adjacent nodes that achieve the following requirements:
- The introduced node has to be
availableorselected. - There must be enough contiguous nodes that are
availableorselected.
If also filter_single_nodes flag is set to true, the following conditions need also to be achieved:
-
the returned node set cannot leave a node with state
availableorselectedwithout at least one adjacent node with stateavailableorselected. -
In case of achieving the above conditions, an array with the same quantity of nodes requested will be given (including the introduced node).
- In case of not achieving the above conditions, the returning array will be empty.
The difference with the original getNeighbors method is that this one allows circular rows,
and it's not dependant of the row parameter, and that it's asynchronous.
Warning
This method is asynchronous.
Input:
node(string | MapViewerNode): base node from which adjacent nodes will be searched.quantity(number): Quantity of nodes to be obtained.options(Object) [optional]: Object with additional options:filter_single_nodes(boolean) [optional]: Iftrue, returned groups will apply the stranded single nodes filtering logic. Default esfalse.subset((string | MapViewerNode)[]) [optional]: Optional subset of nodes to do the computations, instead of the full map.
Output:
node_array(MapViewerNode[]):MapViewerNodearray with the nodes that meet the requirements.
Example:
getNeighbors()¶
Asynchronous method that returns a group of quantity nearby nodes that achieve the following requirements:
- The introduced node has to be
availableorselected. - There must be enough nearby nodes that are
availableorselected.
If also filter_single_nodes flag is set to true, the following conditions need also to be achieved:
-
the returned node set cannot leave a node with state
availableorselectedwithout at least one adjacent node with stateavailableorselected. -
In case of achieving the above conditions, an array with the same quantity of nodes requested will be given (including the introduced node).
- In case of not achieving the above conditions, the returning array will be empty, unless the flag
return_always, in which case it will return the maximum group achieved.
The difference with the original getNeighbors method is that this one allows circular rows,
it's not dependant of the row parameter, and it allows to give groups with other rows.
Warning
This method is asynchronous.
Input:
node(string | MapViewerNode): base node from which adjacent nodes will be searched.quantity(number): Quantity of nodes to be obtained.options(Object) [optional]: Object with additional options:filter_single_nodes(boolean) [optional]: Iftrue, returned groups will apply the stranded single nodes filtering logic. Default esfalse.subset((string | MapViewerNode)[]) [optional]: Optional subset of nodes to do the computations, instead of the full map.return_always(boolean) [optional]: Returns the maximum achievable group if not enough nodes are found. Default isfalse.
Output:
node_array(MapViewerNode[]):MapViewerNodearray with the nodes that meet the requirements.
Example:
validateNeighbors()¶
Asynchronous method that checks if the input can be considered a group of neighbors, meaning that, starting from an arbitrary node in the list and following the neighbors graph, you can reach all the other nodes in the list.
Warning
This method is asynchronous.
Input:
nodes((string | MapViewerNode)[]): List of nodes to check if they are neighbors of each other.
Output:
result(boolean):trueif the all nodes of the input are considered neighbors of each other,falseotherwise.