Пример #1
0
        /// <summary>
        /// 查询初始化
        /// </summary>
        /// <param name="node">初始节点</param>
        /// <param name="x0"></param>
        /// <param name="y0"></param>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <returns></returns>
        QuadtreeVisit quad(QuadtreeNode node, double x0, double y0, double x1, double y1)
        {
            double        x00 = x0, y00 = y0, x10 = x1, y10 = y1;
            QuadtreeVisit visit = new QuadtreeVisit
            {
                node = node,
                x0   = x0,
                x1   = x1,
                y0   = y0,
                y1   = y1
            };

            return(visit);
        }
Пример #2
0
        public void visitAfter(CallBackHandler5 callback)
        {
            var           quads = new Stack <QuadtreeVisit>();
            var           next  = new Stack <QuadtreeVisit>();
            QuadtreeVisit q     = null;

            if (this._root != null)
            {
                quads.Push(quad(this._root, this._x0, this._y0, this._x1, this._y1));
            }
            while (quads.Count > 0)
            {
                q = quads.Pop();
                var node = q.node;
                //判断是否已经到了底层叶结点
                if (node.children != null)
                {
                    double x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
                    if (node.children[0] != null)
                    {
                        quads.Push(quad(node.children[0], x0, y0, xm, ym));
                    }
                    if (node.children[1] != null)
                    {
                        quads.Push(quad(node.children[1], xm, y0, x1, ym));
                    }
                    if (node.children[2] != null)
                    {
                        quads.Push(quad(node.children[2], x0, ym, xm, y1));
                    }
                    if (node.children[3] != null)
                    {
                        quads.Push(quad(node.children[3], xm, ym, x1, y1));
                    }
                }
                next.Push(q);
            }
            while (next.Count > 0)
            {
                q = next.Pop();
                callback(q.node, q.x0, q.y0, q.x1, q.y1);
            }
        }