public void SubDivide(T NewValue = default(T)) { if (BB.Width > 1.0 && BB.Height > 1.0) { for (int i = 0; i < Siblings.Length; i++) { Siblings[i] = new QuadLeaf <T>(); Rect C = BB; C.Width /= 2; C.Height /= 2; C.X = C.X + i % 2 * C.Width; C.Y = C.Y + i / 2 * C.Height; Siblings[i].BB = C; if (!EqualityComparer <T> .Default.Equals(NewValue, default(T))) { Siblings[i].NodeValue = NewValue; } else { Siblings[i].NodeValue = NodeValue; } } } else { IsLast = true; } }
public List <QuadLeaf <T> > getLeafs() { List <QuadLeaf <T> > retval = new List <QuadLeaf <T> >(); List <QuadLeaf <T> > Pack = new List <QuadLeaf <T> >(); Pack.Add(Root); QuadLeaf <T> Curleaf = Pack[0]; while (Pack.Count > 0) { Curleaf = Pack[0]; foreach (var q in Curleaf.Siblings) { if (q != null) { Pack.Add(q); } else { retval.Add(Curleaf); break; } } Pack.RemoveAt(0); } return(retval); }
public void CollapseLeafs() { List <QuadLeaf <T> > Pack = new List <QuadLeaf <T> >(); Pack.Add(Root); QuadLeaf <T> Curleaf = Pack[0]; while (Pack.Count > 0) { Curleaf = Pack[0]; T Nv = Curleaf.Siblings[0].NodeValue; bool isEqualPack = true; foreach (var q in Curleaf.Siblings) { if (q != null) { Pack.Add(q); if (!q.NodeValue.Equals(Nv)) { isEqualPack = false; } } else { break; } } if (isEqualPack) { Curleaf.Siblings = null; Pack.Clear(); Pack.Add(Root); } Pack.RemoveAt(0); } }
public QuadTree() { Root = new QuadLeaf <T>(); }