Beispiel #1
0
        //Chen doi tuong vao trong Nodes
        public void Insert(TreeObject myobject)
        {
            if (m_nodes != null) //if nodes khong phai la nodes la thi khoi tao cac nodes con va goi ham insert cho nodes
            {
                for (int i = 0; i < 4; i++)
                {
                    if (m_nodes[i].isBelongNode(myobject.getRect()))
                    {
                        m_nodes[i].Insert(myobject);
                    }
                }
            }
            else //Neu la nodes la thi kiem tra doi tuong co thuoc nodes khong neu co thi them vao nodes
            {
                if (this.isBelongNode(myobject.getRect()))
                {
                    this.m_listObject.Add(myobject);
                }



                if (this.m_rect.Width / 2 >= MIN_SIZE && this.m_listObject.Count >= MAX_OBJECT)
                {
                    CreateNode();
                    TreeObject temp = new TreeObject();

                    while (m_listObject.Count > 0)
                    {
                        temp = m_listObject.First();
                        m_listObject.Remove(temp);

                        for (int i = 0; i < 4; i++)
                        {
                            if (m_nodes[i].isBelongNode(myobject.getRect()))
                            {
                                m_nodes[i].m_listObject.Add(temp);
                            }
                        }
                    }
                    m_listObject.Clear();
                    //m_listObject = null;
                }
            }
        }