/// <summary> /// /// </summary> /// <param name="itemInterval"></param> /// <returns></returns> public static Node CreateNode(Interval itemInterval) { Key key = new Key(itemInterval); Node node = new Node(key.Interval, key.Level); return node; }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <param name="addInterval"></param> /// <returns></returns> public static Node CreateExpanded(Node node, Interval addInterval) { Interval expandInt = new Interval(addInterval); if (node != null) expandInt.ExpandToInclude(node.interval); Node largerNode = CreateNode(expandInt); if (node != null) largerNode.Insert(node); return largerNode; }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <returns></returns> private Node CreateSubnode(int index) { // create a new subnode in the appropriate interval double min = 0.0; double max = 0.0; switch (index) { case 0: min = interval.Min; max = centre; break; case 1: min = centre; max = interval.Max; break; default: break; } Interval subInt = new Interval(min, max); Node node = new Node(subInt, level - 1); return node; }
/// <summary> /// /// </summary> /// <param name="node"></param> public void Insert(Node node) { Assert.IsTrue(interval == null || interval.Contains(node.Interval)); int index = GetSubnodeIndex(node.interval, centre); if (node.level == level - 1) subnode[index] = node; else { // the node is not a direct child, so make a new child node to contain it // and recursively insert the node Node childNode = CreateSubnode(index); childNode.Insert(node); subnode[index] = childNode; } }