/// <summary> /// Adds a point data range to the data structure. /// </summary> /// <param name="data">The data to add</param> /// <param name="pt">The botom left corner for the point to add</param> /// <param name="range">The optimal size of the box</param> /// <returns>True if a new point was added, false if it was a replacement or failure to add.</returns> public bool Add(QTPoint pt, N range, D data) { if (RootNode == null) { RootNode = new QTNode <N, D>(); return(RootNode.Add(pt, range, data)); } // If the point to add is in the current bounds, then add it. if (RootNode.Contains(pt)) // TODO: do i need to check if it overlaps as well or something? { return(RootNode.Add(pt, range, data)); } else { // The point is out of the current bounds, we need to move the root down a level. // Get the range and the point for the new root node QTPoint NewRootPt = new QTPoint(); dynamic NewRootRange = 0; QTPoint.Capture(RootNode.Point, RootNode.Range, pt, range, ref NewRootPt, ref NewRootRange); // Add the current root to the new node QTNode <N, D> NewRoot = new QTNode <N, D>(); if (!NewRoot.Add(pt, range, data)) { throw new Exception("How did we get here? I thought we were adding to an empty node?"); } bool worked = NewRoot.Append(RootNode); // Update out root node // TODO: can optimize some lines out once we pass testing if (worked) { RootNode = NewRoot; return(true); } else { throw new Exception("Why did that not work?"); } } }