public static TilesHandler Create(NeighborhoodEnumerator master)
                {
                    var created = new TilesHandler(master);

                    created._searchDim = -1;
                    return(created);
                }
                private double[] GetSearchExtent(int dim)
                {
                    TilesHandler t = this;

                    while (t != null)
                    {
                        if (t._searchDim == dim)
                        {
                            return(t._searchExtent);
                        }

                        t = t._parent;
                    }

                    Box b = _master._common;

                    return(new[] { b.Min[dim], b.Max[dim] });
                }
            public bool MoveNext()
            {
                while (true)
                {
                    if (_tileNeighborhoods != null && _tileNeighborhoods.MoveNext())
                    {
                        SetCurrent(_tileNeighborhoods.Current);
                        return(true);
                    }

                    _tilesHandler = _tilesHandler.GetNext();
                    if (_tilesHandler == null)
                    {
                        return(false);
                    }

                    _tileNeighborhoods = GetTileNeighborhoods().GetEnumerator();
                }
            }
 public void Reset()
 {
     _tileNeighborhoods = null;
     _tilesHandler      = TilesHandler.Create(this);
 }
                public TilesHandler GetNext()
                {
                    var next = new TilesHandler(_master);

                    if (_searchingTile == null)
                    {
                        IBox search = GetSearchBox(_master._searchingTree.UnitBox,
                                                   _master._searchDistance,
                                                   _master._common);
                        if (search == null || !search.Intersects(_master._neighbourTree.UnitBox))
                        {
                            return(null);
                        }

                        BoxTile searchingTile  = _master._searchingTree.MainTile;
                        BoxTile neighbourTile  = _master._neighbourTree.MainTile;
                        var     neighbourTiles = new LinkedList <BoxTile>();
                        neighbourTiles.AddFirst(neighbourTile);

                        next._searchingTile = searchingTile;
                        next._parent        = this;
                        next.Init(neighbourTiles);
                    }
                    else
                    {
                        BoxTile      nextSearchTile;
                        TilesHandler nextParent = this;

                        if (!nextParent.HasNeighbourTiles() ||
                            nextParent._searchingTile.Child0 == null)
                        {
                            // MoveUp;
                            while (nextParent != null && nextParent._parent != null &&
                                   nextParent._parent._searchingTile != null &&
                                   nextParent._parent._searchingTile.Child1 ==
                                   nextParent._searchingTile)
                            {
                                nextParent = nextParent._parent;
                            }

                            if (nextParent == null || nextParent._parent == null ||
                                nextParent._parent._searchingTile == null)
                            {
                                return(null);
                            }

                            nextParent     = nextParent._parent;
                            nextSearchTile = nextParent._searchingTile.Child1;
                        }
                        else
                        {
                            nextSearchTile = nextParent._searchingTile.Child0;
                        }

                        next._searchingTile = nextSearchTile;
                        next._parent        = nextParent;
                        next.Init(nextParent._neighbourTiles);
                    }

                    return(next);
                }