Exemplo n.º 1
0
 public T RemoveNode(OctreeLeaf <T> leaf)
 {
     if (Branch == null)
     {
         // This must be the node that has it...
         for (int i = 0; i < Items.Count; i++)
         {
             var qtl = (OctreeLeaf <T>)Items[i];
             if (!leaf.LeafObject.Equals(qtl.LeafObject))
             {
                 continue;
             }
             Items.RemoveAt(i);
             return(qtl.LeafObject);
         }
     }
     else
     {
         OctreeNode <T> node = GetChild(leaf.X, leaf.Y, leaf.Z);
         if (node != null)
         {
             return(node.RemoveNode(leaf));
         }
     }
     return(default(T));
 }
Exemplo n.º 2
0
        public bool AddNode(OctreeLeaf <T> leaf)
        {
            if (Branch == null)
            {
                Items.Add(leaf);
                if (Items.Count == 1)
                {
                    AllTheSamePoint = true;
                    FirstX          = leaf.X;
                    FirstY          = leaf.Y;
                    FirstZ          = leaf.Z;
                }
                else
                {
                    if (FirstX != leaf.X || FirstY != leaf.Y || FirstZ != leaf.Z)
                    {
                        AllTheSamePoint = false;
                    }
                }
                if (Items.Count > MaxItems && !AllTheSamePoint)
                {
                    Split();
                }
                return(true);
            }
            OctreeNode <T> node = GetChild(leaf.X, leaf.Y, leaf.Z);

            return(node != null && node.AddNode(leaf));
        }