Example #1
0
        public List <TezQtEntry> retrieve(TezQtEntry obj)
        {
            List <TezQtEntry> result = new List <TezQtEntry>();

            var shape = obj.shape;

            if (!bounds.intersects(shape))
            {
                return(result);
            }

            if (m_Objects.Count > 0)
            {
                result.AddRange(m_Objects);
            }

            if (m_IsSubdivided)
            {
                m_Nodes[Quadrant_1].retrieve(shape, ref result);
                m_Nodes[Quadrant_2].retrieve(shape, ref result);
                m_Nodes[Quadrant_3].retrieve(shape, ref result);
                m_Nodes[Quadrant_4].retrieve(shape, ref result);
            }

            return(result);
        }
Example #2
0
        public bool insert(TezQtEntry obj)
        {
            ///形状没有被完美包含在范围内
            if (!bounds.contains(obj.shape))
            {
                return(false);
            }

            if (!m_IsSubdivided && m_Objects.Count < this.maxObject)
            {
                m_Objects.Add(obj);
                return(true);
            }

            if (!m_IsSubdivided)
            {
                if (m_Level + 1 == this.maxLevel)
                {
                    Debug.Log("超过最大分裂值,留在当前");
                    m_Objects.Add(obj);
                    return(true);
                }

                m_IsSubdivided = true;

                this.subdivide();

                for (int oi = m_Objects.Count - 1; oi >= 0; oi--)
                {
                    var old = m_Objects[oi];
#if OptimizeSearch
                    if (m_Nodes[this.calculateQuadrant(obj.shape)].insert(obj))
                    {
                        m_Objects.RemoveAt(oi);
                    }
#else
                    if (m_Nodes[Quadrant_1].insert(old))
                    {
                        m_Objects.RemoveAt(oi);
                        continue;
                    }

                    if (m_Nodes[Quadrant_2].insert(old))
                    {
                        m_Objects.RemoveAt(oi);
                        continue;
                    }

                    if (m_Nodes[Quadrant_3].insert(old))
                    {
                        m_Objects.RemoveAt(oi);
                        continue;
                    }

                    if (m_Nodes[Quadrant_4].insert(old))
                    {
                        m_Objects.RemoveAt(oi);
                        continue;
                    }
#endif
                }
            }

#if OptimizeSearch
            var quadrant = this.calculateQuadrant(obj.shape);
            if (m_Nodes[quadrant].insert(obj))
            {
                return(true);
            }
#else
            if (m_Nodes[Quadrant_1].insert(obj))
            {
                return(true);
            }

            if (m_Nodes[Quadrant_2].insert(obj))
            {
                return(true);
            }

            if (m_Nodes[Quadrant_3].insert(obj))
            {
                return(true);
            }

            if (m_Nodes[Quadrant_4].insert(obj))
            {
                return(true);
            }
#endif

            Debug.Log("插入失败,超出数量,留在父节点");
//            m_Objects.Add(obj);
            return(false);
        }