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 List <Objects> Query(Rectangle queryArea) { // create a list of the items that are found List <Objects> results = new List <Objects>(); // this quad contains items that are not entirely contained by // it's four sub-quads. Iterate through the items in this quad // to see if they intersect. foreach (Objects obj in this.listObjects) { Rectangle r = new Rectangle(obj.Point, obj.Size); if (queryArea.IntersectsWith(r)) { results.Add(obj); } } if (LeftTop != null) { if (LeftTop.rec.Contains(queryArea)) { results.AddRange(LeftTop.Query(queryArea)); } if (queryArea.Contains(LeftTop.rec)) { results.AddRange(LeftTop.SubTreeObjects); } if (LeftTop.rec.IntersectsWith(queryArea)) { results.AddRange(LeftTop.Query(queryArea)); } } if (RightTop != null) { if (RightTop.rec.Contains(queryArea)) { results.AddRange(RightTop.Query(queryArea)); } if (queryArea.Contains(RightTop.rec)) { results.AddRange(RightTop.SubTreeObjects); } if (RightTop.rec.IntersectsWith(queryArea)) { results.AddRange(RightTop.Query(queryArea)); } } if (LeftBot != null) { if (LeftBot.rec.Contains(queryArea)) { results.AddRange(LeftTop.Query(queryArea)); } if (queryArea.Contains(LeftBot.rec)) { results.AddRange(LeftBot.SubTreeObjects); } if (LeftBot.rec.IntersectsWith(queryArea)) { results.AddRange(LeftBot.Query(queryArea)); } } if (RightBot != null) { if (RightBot.rec.Contains(queryArea)) { results.AddRange(RightBot.Query(queryArea)); } if (queryArea.Contains(RightBot.rec)) { results.AddRange(RightBot.SubTreeObjects); } if (RightBot.rec.IntersectsWith(queryArea)) { results.AddRange(RightBot.Query(queryArea)); } } return(results); }