private void BuidTree() { foreach (GameObject o in list_object) { root.Insert(o); } }
public void Insert(Objects _obj) { Rectangle r = new Rectangle(_obj.Point, _obj.Size); if (LeftBot == null) { CreateSubNodes(); } if (LeftTop != null && LeftTop.rec.Contains(r)) { LeftTop.Insert(_obj); return; } if (RightTop != null && RightTop.rec.Contains(r)) { RightTop.Insert(_obj); return; } if (LeftBot != null && LeftBot.rec.Contains(r)) { LeftBot.Insert(_obj); return; } if (RightBot != null && RightBot.rec.Contains(r)) { RightBot.Insert(_obj); return; } this.listObjects.Add(_obj); }
private void btSave_Click(object sender, EventArgs e) { if (this.worldmap != null) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "map files (*.txt)|*.txt"; dlg.Title = "Save map"; dlg.CheckPathExists = true; dlg.CheckPathExists = true; dlg.ShowDialog(); if (dlg.FileName != "") { Rectangle rrr = new Rectangle(new Point(0, y_Axis - pb_background.Height + 1), pb_background.Size); root_node = new Node("0", rrr); List <Objects> tmplst = new List <Objects>(worldmap.ListObject); worldmap.ListObject.Clear(); foreach (Objects o in tmplst) { if (o.Type < 10 || o.Type == 20) { worldmap.ListObject.Add(o); } } foreach (Objects o in tmplst) { if (o.Type < 10 || o.Type == 20) { continue; } worldmap.ListObject.Add(o); } foreach (Objects o in worldmap.ListObject) { o.Id = worldmap.ListObject.IndexOf(o); root_node.Insert(o); } worldmap.saveMap(dlg.FileName, root_node); Rectangle re = new Rectangle(new Point(5665, 32), new Size(7200, 352)); List <Objects> l = root_node.Query(re); } } }
public bool Insert(GameObject go) { //Kiểm tra nếu diện tích giao nhau giữa khung bao đối tượng //và khung bao của node quá nhỏ thì xem như không có Rectangle inter_rect = Rectangle.Intersect(go.BOUNDS, this.bounds); if (inter_rect.Width < 3 || inter_rect.Height < 3) { return(false); } //Nếu node mẹ không thể chia node con nữa thì đưa đối tượng //vào node mẹ và kết thúc if (bounds.Width <= Global.MIN_WIDTH * 2) { list_object.Add(go); return(true); } //Khởi tạo các nút lá nếu chưa có if (top_left == null) { int node_width = bounds.Width / 2; top_left = new Node(id, Location.TopLeft, new Rectangle(bounds.X, bounds.Y, node_width, node_width)); top_right = new Node(id, Location.TopRight, new Rectangle(bounds.X + node_width, bounds.Y, node_width, node_width)); bot_left = new Node(id, Location.BotLeft, new Rectangle(bounds.X, bounds.Y + node_width, node_width, node_width)); bot_right = new Node(id, Location.BotRight, new Rectangle(bounds.X + node_width, bounds.Y + node_width, node_width, node_width)); } top_left.Insert(go); top_right.Insert(go); bot_left.Insert(go); bot_right.Insert(go); return(true); }