/// <summary>
 /// Determines if this rectangle intersets with rect.
 /// </summary>
 /// <param name="rect"></param>
 /// <returns></returns>
 public bool CollidesWith(AARectangle rect)
 {
     return((rect.X < this.X + this.Width) &&
            (this.X < (rect.X + rect.Width)) &&
            (rect.Y < this.Y + this.Height) &&
            (this.Y < rect.Y + rect.Height));
 }
 /// <summary>
 /// Determines if the given rect is entirely contained within this rectangle.
 /// </summary>
 /// <param name="rect"></param>
 /// <returns></returns>
 public bool Contains(AARectangle rect)
 {
     return((this.X <= rect.X) &&
            ((rect.X + rect.Width) <= (this.X + this.Width)) &&
            (this.Y <= rect.Y) &&
            ((rect.Y + rect.Height) <= (this.Y + this.Height)));
 }
        /// <summary>
        /// Creates a rectangle that represents the union between a and b.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static AARectangle Union(AARectangle a, AARectangle b)
        {
            double x1 = Math.Min(a.X, b.X);
            double x2 = Math.Max(a.X + a.Width, b.X + b.Width);
            double y1 = Math.Min(a.Y, b.Y);
            double y2 = Math.Max(a.Y + a.Height, b.Y + b.Height);

            return(new AARectangle(x1, y1, x2 - x1, y2 - y1));
        }
        /// <summary>
        /// Creates a rectangle that represents the union between a and b.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static AARectangle Union(AARectangle a, AARectangle b)
        {
            double x1 = Math.Min(a.X, b.X);
            double x2 = Math.Max(a.X + a.Width, b.X + b.Width);
            double y1 = Math.Min(a.Y, b.Y);
            double y2 = Math.Max(a.Y + a.Height, b.Y + b.Height);

            return new AARectangle(x1, y1, x2 - x1, y2 - y1);
        }
        /// <summary>
        /// Creates a rectangle that represents the intersetion between a and
        ///    b. If there is no intersection, null is returned.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static AARectangle Intersect(AARectangle a, AARectangle b)
        {
            double x1 = Math.Max(a.X, b.X);
            double x2 = Math.Min(a.X + a.Width, b.X + b.Width);
            double y1 = Math.Max(a.Y, b.Y);
            double y2 = Math.Min(a.Y + a.Height, b.Y + b.Height);

            if (x2 >= x1 &&
                y2 >= y1)
            {
                return(new AARectangle(x1, y1, x2 - x1, y2 - y1));
            }
            return(Empty);
        }
        /// <summary>
        /// Creates a rectangle that represents the intersetion between a and
        ///    b. If there is no intersection, null is returned.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static AARectangle Intersect(AARectangle a, AARectangle b)
        {
            double x1 = Math.Max(a.X, b.X);
            double x2 = Math.Min(a.X + a.Width, b.X + b.Width);
            double y1 = Math.Max(a.Y, b.Y);
            double y2 = Math.Min(a.Y + a.Height, b.Y + b.Height);

            if (x2 >= x1
                && y2 >= y1)
            {

                return new AARectangle(x1, y1, x2 - x1, y2 - y1);
            }
            return Empty;
        }
 /// <summary>
 ///  Creates a rectangle
 ///       that is inflated by the specified amount.
 /// </summary>
 /// <param name="rect"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public static AARectangle Inflate(AARectangle rect, float x, float y)
 {
     return(new AARectangle(rect.X - x, rect.Y - y, rect.Width + 2 * x, rect.Height + 2 * y));
 }
 public bool Equals(AARectangle other)
 {
     return(_x.Equals(other._x) && _y.Equals(other._y) && _width.Equals(other._width) && _height.Equals(other._height));
 }
 /// <summary>
 ///  Creates a rectangle
 ///       that is inflated by the specified amount.
 /// </summary>
 /// <param name="rect"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public static AARectangle Inflate(AARectangle rect, float x, float y)
 {
     return new AARectangle(rect.X - x, rect.Y - y, rect.Width + 2 * x, rect.Height + 2 * y);
 }
 public bool Equals(AARectangle other)
 {
     return _x.Equals(other._x) && _y.Equals(other._y) && _width.Equals(other._width) && _height.Equals(other._height);
 }
 /// <summary>
 /// Determines if this rectangle intersets with rect.
 /// </summary>
 /// <param name="rect"></param>
 /// <returns></returns>
 public bool CollidesWith(AARectangle rect)
 {
     return (rect.X < this.X + this.Width) &&
            (this.X < (rect.X + rect.Width)) &&
            (rect.Y < this.Y + this.Height) &&
            (this.Y < rect.Y + rect.Height);
 }
 /// <summary>
 /// Determines if the given rect is entirely contained within this rectangle.
 /// </summary>
 /// <param name="rect"></param>
 /// <returns></returns>
 public bool Contains(AARectangle rect)
 {
     return (this.X <= rect.X) &&
            ((rect.X + rect.Width) <= (this.X + this.Width)) &&
            (this.Y <= rect.Y) &&
            ((rect.Y + rect.Height) <= (this.Y + this.Height));
 }