Pathfinding.PointKDTree.Rebuild C# (CSharp) Method

Rebuild() public method

Rebuild the tree starting with all nodes in the array between index start (inclusive) and end (exclusive)
public Rebuild ( Array nodes, int start, int end ) : void
nodes Array
start int
end int
return void
		public void Rebuild (GraphNode[] nodes, int start, int end) {
			if (start < 0 || end < start || end > nodes.Length)
				throw new System.ArgumentException();

			for (int i = 0; i < tree.Length; i++) {
				var data = tree[i].data;
				if (data != null) {
					for (int j = 0; j < LeafArraySize; j++) data[j] = null;
					arrayCache.Push(data);
					tree[i].data = null;
				}
			}

			numNodes = end - start;
			Build(1, new List<GraphNode>(nodes), start, end);
		}

Usage Example

 /// <summary>
 /// Rebuilds the lookup structure for nodes.
 ///
 /// This is used when <see cref="optimizeForSparseGraph"/> is enabled.
 ///
 /// You should call this method every time you move a node in the graph manually and
 /// you are using <see cref="optimizeForSparseGraph"/>, otherwise pathfinding might not work correctly.
 ///
 /// You may also call this after you have added many nodes using the
 /// <see cref="AddNode"/> method. When adding nodes using the <see cref="AddNode"/> method they
 /// will be added to the lookup structure. The lookup structure will
 /// rebalance itself when it gets too unbalanced however if you are
 /// sure you won't be adding any more nodes in the short term, you can
 /// make sure it is perfectly balanced and thus squeeze out the last
 /// bit of performance by calling this method. This can improve the
 /// performance of the <see cref="GetNearest"/> method slightly. The improvements
 /// are on the order of 10-20%.
 /// </summary>
 public void RebuildNodeLookup()
 {
     if (!optimizeForSparseGraph || nodes == null)
     {
         lookupTree = new PointKDTree();
     }
     else
     {
         lookupTree.Rebuild(nodes, 0, nodeCount);
     }
 }
All Usage Examples Of Pathfinding.PointKDTree::Rebuild