// This puts a thing in the blockmap public void AddThing(Thing t) { Point p = GetBlockCoordinates(t.Position); VisualBlockEntry block = GetBlock(p); block.Things.Add(t); }
// This returns the block with the given coordinates // Creates the block if it doesn't exist yet public VisualBlockEntry GetBlock(Point p) { ulong k = GetBlockKey(p); if (blockmap.ContainsKey(k)) { return(blockmap[k]); } else { return(blockmap[k] = new VisualBlockEntry()); } }
// This puts a sector in the blockmap public void AddSector(Sector s) { Point p1 = GetBlockCoordinates(new Vector2D(s.BBox.Left, s.BBox.Top)); Point p2 = GetBlockCoordinates(new Vector2D(s.BBox.Right, s.BBox.Bottom)); for (int x = p1.X; x <= p2.X; x++) { for (int y = p1.Y; y <= p2.Y; y++) { VisualBlockEntry block = GetBlock(new Point(x, y)); block.Sectors.Add(s); } } }
// This puts a thing in the blockmap public void AddThing(Thing t) { //mxd Point p1 = GetBlockCoordinates(new Vector2D(t.Position.x - t.Size, t.Position.y - t.Size)); Point p2 = GetBlockCoordinates(new Vector2D(t.Position.x + t.Size, t.Position.y + t.Size)); for (int x = p1.X; x <= p2.X; x++) { for (int y = p1.Y; y <= p2.Y; y++) { VisualBlockEntry block = GetBlock(new Point(x, y)); block.Things.Add(t); } } }
public VisualBlockEntry GetEntry(Rectangle box, int level = 0) { if (level == MaxLevels) { if (visualBlock == null) { visualBlock = new VisualBlockEntry(); } return(visualBlock); } if (topLeft == null) { CreateChildren(); } if (topLeft.bbox.Contains(box)) { return(topLeft.GetEntry(box, level + 1)); } if (topRight.bbox.Contains(box)) { return(topRight.GetEntry(box, level + 1)); } if (bottomLeft.bbox.Contains(box)) { return(bottomLeft.GetEntry(box, level + 1)); } if (bottomRight.bbox.Contains(box)) { return(bottomRight.GetEntry(box, level + 1)); } if (visualBlock == null) { visualBlock = new VisualBlockEntry(); } return(visualBlock); }