Microsoft.Xna.Framework.Rectangle.Union C# (CSharp) Method

Union() public static method

public static Union ( Rectangle r1, Rectangle r2 ) : Rectangle
r1 Rectangle
r2 Rectangle
return Rectangle
		public static Rectangle Union (Rectangle r1, Rectangle r2)
		{
			int num = r1.X + r1.Width;
			int num2 = r2.X + r2.Width;
			int num3 = r1.Y + r1.Height;
			int num4 = r2.Y + r2.Height;
			int num5 = (r1.X < r2.X) ? r1.X : r2.X;
			int num6 = (r1.Y < r2.Y) ? r1.Y : r2.Y;
			int num7 = (num > num2) ? num : num2;
			int num8 = (num3 > num4) ? num3 : num4;
			Rectangle result;
			result.X = num5;
			result.Y = num6;
			result.Width = num7 - num5;
			result.Height = num8 - num6;
			return result;
		}

Usage Example

            public static void Postfix(Farmer __instance, xTile.Dimensions.Rectangle viewport, GameLocation currentLocation, ref Vector2 __state)
            {
                if (!IsModEnabled())
                {
                    return;
                }

                if (backwardsFarmer)
                {
                    Vector2   dest          = __state - (__instance.Position - __state);
                    int       width         = __instance.GetSpriteWidthForPositioning() * 4 * 3 / 4;
                    Rectangle destRectFloor = new Rectangle((int)Math.Floor(dest.X) - 8, (int)Math.Floor(dest.Y) - 16, width, 32);
                    Rectangle destRectCeil  = new Rectangle((int)Math.Ceiling(dest.X) + 8, (int)Math.Ceiling(dest.Y) + 16, width, 32);
                    Rectangle destRect      = Rectangle.Union(destRectCeil, destRectFloor);
                    if (!currentLocation.isCollidingPosition(destRect, viewport, true, -1, false, __instance))
                    {
                        __instance.Position = dest;
                    }
                }
            }