ScrollingShooter.GameObjectManager.QueryRegion C# (CSharp) Method

QueryRegion() public method

Queries a rectangular region and retuns game object ids for all game objects within that region
public QueryRegion ( Rectangle bounds ) : uint[]
bounds Microsoft.Xna.Framework.Rectangle A bounding rectangle for the region of interest
return uint[]
        public uint[] QueryRegion(Rectangle bounds)
        {
            HashSet<uint> matches = new HashSet<uint>();

            // Find the maximal index for the bounding region in the vertical
            // axis list
            Bound top = new Bound(null, bounds.Top, BoundType.Min);
            int minVerticalIndex = verticalAxis.BinarySearch(top);
            if (minVerticalIndex < 0) minVerticalIndex = ~minVerticalIndex;

            // Find the minimal index for the bounding region in the vertical
            // axis list
            Bound bottom = new Bound(null, bounds.Bottom, BoundType.Max);
            int maxVerticalIndex = verticalAxis.BinarySearch(bottom);
            if (maxVerticalIndex < 0) maxVerticalIndex = ~maxVerticalIndex;

            // Collect all game object ids between the minimal and maximal
            // indices
            for (int i = minVerticalIndex; i < maxVerticalIndex; i++)
            {
                matches.Add(verticalAxis[i].Box.GameObjectID);
            }

            return matches.ToArray();
        }