本文整理汇总了C#中GraphNode.getPosition方法的典型用法代码示例。如果您正苦于以下问题:C# GraphNode.getPosition方法的具体用法?C# GraphNode.getPosition怎么用?C# GraphNode.getPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphNode
的用法示例。
在下文中一共展示了GraphNode.getPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: connectNodeNeighbourhood
/*
* Connects a single node to the graph using the neighbourhood method. If the arrays passed are null,
* the method will create them. If the arrays have already been allocated, they should be passed in in
* order to reduce the time spent on creating and destroying objects.
*/
private void connectNodeNeighbourhood(GraphNode<StateConfig> node, Tuple<int,float>[] distances, List<GraphNode<StateConfig>> neighbourhoodNodes)
{
if (distances == null){
distances = new Tuple<int, float>[graph.nodes.Count];
}
if (neighbourhoodNodes == null){
neighbourhoodNodes = new List<GraphNode<StateConfig>>(graph.nodes.Count);
}
GraphNode<StateConfig> comp;
// initialise tuples in the distances array
for (int i = 0; i < distances.Length; i++) {
distances[i] = new Tuple<int, float>();
}
// Compute distances from the node we are currently looking at to
// all other nodes in the graph
for (int otherIndex = 0; otherIndex < graph.nodes.Count; otherIndex++) {
distances[otherIndex].first = otherIndex;
distances[otherIndex].second = node.content.computeDistanceEuclidean(graph.nodes[otherIndex].content);
}
// Sort the distances in ascending order so the closest nodes
// are at the front of the array
Array.Sort(distances, ((x,y)=> x.second.CompareTo(y.second)));
// clear the neighbourhod nodes from the previous node.
neighbourhoodNodes.Clear();
// add nodes to the neighbourhood list until the nodes are no longer
// in the neighbourhood
for (int i = 0; i < distances.Length; i++) {
if (distances[i].second > radius){
break;
}
neighbourhoodNodes.Add(graph.nodes[distances[i].first]);
}
// Connect the node to its closest N neighbours, to which it is not already
// connected via nodes in its neighbourhood.
int connected = 0;
for (int j = 0; connected < neighbours && j < distances.Length; j++) {
comp = graph.nodes[distances[j].first];
if (!neighbourConnected(node, comp, neighbourhoodNodes, radius)
&& occupancy.obstacleFreeStraightPath(node.getPosition(), comp.getPosition())){
node.addNeighbour(ref comp);
comp.addNeighbour(ref node);
connected++;
}
}
}