public void FillBucket(GameObject gameObject)
        {
            CollisionBucket bucket = FetchBucket(gameObject);

            if (bucket == null)
            {
                return;
            }
            bucket.AddElement(gameObject);
        }
        public Boolean RemoveFromBucketIfExists(GameObject gameObject)
        {
            var             t      = gameObject;
            CollisionBucket bucket = FetchBucket(gameObject);

            if (bucket == null)
            {
                return(false);
            }

            return(bucket.RemoveElement(gameObject));
        }
        private CollisionBucket FetchBucket(GameObject gameObject)
        {
            Vector2 coordinates = GetCoordinates(gameObject.Position);

            if (!IsValidBucketCoordinates((int)coordinates.X, (int)coordinates.Y))
            {
                return(null);
            }

            CollisionBucket bucket = collisionBuckets[(int)coordinates.X][(int)coordinates.Y];

            return(bucket);
        }
        private CollisionBucket FetchBucket(GameObject gameObject, int xOffset, int yOffset)
        {
            Vector2 coordinates = GetCoordinates(gameObject.Position);

            /* If the coordinates are out of bounds, we return null. */
            if (!IsValidBucketCoordinates((int)coordinates.X + xOffset, (int)coordinates.Y + yOffset))
            {
                return(null);
            }

            CollisionBucket bucket = collisionBuckets[(int)coordinates.X + xOffset][(int)coordinates.Y + yOffset];

            return(bucket);
        }
        public HashSet <GameObject> GetObjectsCollided(GameObject gameObject, Type type) /* Optional filter parameter */
        {
            HashSet <GameObject> ret = new HashSet <GameObject>();
            double radius            = gameObject.HitBoxRadius;

            /* Directions */
            int[,] dirs = new int[, ] {
                { 1, 1 }, { 0, 1 }, { -1, 1 },
                { 1, 0 }, { 0, 0 }, { -1, 0 },
                { 1, -1 }, { 0, -1 }, { -1, -1 }
            };

            /* Check all neighboring cells */
            for (int i = 0; i < 9; ++i)
            {
                int xOffset = dirs[i, 0];
                int yOffset = dirs[i, 1];

                CollisionBucket cb = FetchBucket(gameObject, xOffset, yOffset);
                /* null indicates that the coordinates were invalid */
                if (cb != null)
                {
                    /* For all game objects in the bucket, if within the collision region add to return set */
                    foreach (GameObject go in cb.GetObjects())
                    {
                        if (!go.GetType().IsSubclassOf(type) && !go.GetType().Equals(type))
                        {
                            continue;
                        }
                        if (gameObject.BoundsContains(go.Position) ||
                            go.BoundsContains(gameObject.Position))
                        {
                            ret.Add(go);
                        }
                    }
                }
            }
            return(ret);
        }