コード例 #1
0
 public void Dispose()
 {
     _child0  = null;
     _child1  = null;
     _objList = null;
 }
コード例 #2
0
        public void AddNode(BoxObjects o, Heuristic h)
        {
            /* -------------------------------------------------------------------- */
            /*      If there are subnodes, then consider whether this object        */
            /*      will fit in them.                                               */
            /* -------------------------------------------------------------------- */
            if (_child0 != null && _depth < h.maxdepth)
            {
                if (_child0.Box.Contains(o.Box.GetCentroid()))
                {
                    _child0.AddNode(o, h);
                }
                else if (_child1.Box.Contains(o.Box.GetCentroid()))
                {
                    _child1.AddNode(o, h);
                }
                return;
            }

            /* -------------------------------------------------------------------- */
            /*      Otherwise, consider creating two subnodes if could fit into     */
            /*      them, and adding to the appropriate subnode.                    */
            /* -------------------------------------------------------------------- */
            if (h.maxdepth > _depth && !IsLeaf)
            {
                BoundingBox half1, half2;
                SplitBoundingBox(Box, out half1, out half2);


                if (half1.Contains(o.Box.GetCentroid()))
                {
                    _child0 = new QuadTree(half1, _depth + 1);
                    _child1 = new QuadTree(half2, _depth + 1);
                    _child0.AddNode(o, h);
                    return;
                }
                if (half2.Contains(o.Box.GetCentroid()))
                {
                    _child0 = new QuadTree(half1, _depth + 1);
                    _child1 = new QuadTree(half2, _depth + 1);
                    _child1.AddNode(o, h);
                    return;
                }
            }

            /* -------------------------------------------------------------------- */
            /*      If none of that worked, just add it to this nodes list.         */
            /* -------------------------------------------------------------------- */

            if (_objList == null)
            {
                _objList = new List <BoxObjects>();
            }

            if (!Box.Contains(o.Box))
            {
                Box = Box.Join(o.Box);
            }

            _objList.Add(o);
        }