/// <summary> /// grows a tree of n-tiers from current node /// </summary> /// <param name="node">node to grow from</param> /// <param name="tiers">number of tiers to grow</param> private void growTree(QuadNode <E> node, int tiers) { if (tiers == 0) { return; } else { node.Q1.subdivide(); growTree(node.Q1, tiers - 1); node.Q2.subdivide(); growTree(node.Q2, tiers - 1); node.Q3.subdivide(); growTree(node.Q3, tiers - 1); node.Q4.subdivide(); growTree(node.Q4, tiers - 1); } }
/// <summary> /// sets the content at the leaf node descendant from the given node /// </summary> /// <param name="node">given node</param> /// <param name="val">content to be set</param> /// <param name="point">location of the content</param> /// <returns>the leaf node set or null if set failed or content already exists</returns> private QuadNode <E> setContentAtLocation(QuadNode <E> node, E val, Vector2 point) { if (node.Q1 == null || node.Q2 == null || node.Q3 == null || node.Q4 == null) { if (node.contains(point)) { if (!node.Contents.Contains(val)) { node.Contents.Add(val); } return(node); } else { return(null); } } else { if (node.Q1.contains(point)) { return(setContentAtLocation(node.Q1, val, point)); } if (node.Q2.contains(point)) { return(setContentAtLocation(node.Q2, val, point)); } if (node.Q3.contains(point)) { return(setContentAtLocation(node.Q3, val, point)); } if (node.Q4.contains(point)) { return(setContentAtLocation(node.Q4, val, point)); } return(null); } }
public QuadTree(Vector2 ul, Vector2 lr) { q_RootNode = new QuadNode <E>(ul, lr); q_RootNode.Parent = null; }
/// <summary> /// remove specific contents of a node /// </summary> /// <param name="node">node contents to remove</param> /// <param name="val">content to be removed</param> private void remove(QuadNode <E> node, E val) { node.Contents.Remove(val); }