/// <summary> /// Checks rectangles for intersection /// </summary> /// <param name="rect1">First rectangle</param> /// <param name="rect2">Second rectangle</param> /// <param name="result">Area of intersection</param> public static void Intersect(ref RectangleFloat rect1, ref RectangleFloat rect2, out RectangleFloat result) { if (rect1.Contains(rect2)) { result = new RectangleFloat(rect2); } else if (rect2.Contains(rect1)) { result = new RectangleFloat(rect1); } else if (!rect1.Intersects(rect2)) { result = new RectangleFloat(); } else { result = new RectangleFloat( Math.Max(rect1.X, rect2.X), Math.Max(rect1.Y, rect2.Y), Math.Min(rect1.Right, rect2.Right) - Math.Max(rect1.Left, rect2.Left), Math.Min(rect1.Bottom, rect2.Bottom) - Math.Max(rect1.Top, rect2.Top)); } }
/// <summary> /// Checks rectangles for intersection /// </summary> /// <param name="rect1">First rectangle</param> /// <param name="rect2">Second rectangle</param> /// <returns>Area of intersection</returns> public static RectangleFloat Intersect(RectangleFloat rect1, RectangleFloat rect2) { RectangleFloat result; if (rect1.Contains(rect2)) { result = new RectangleFloat(rect2); } else if (rect2.Contains(rect1)) { result = new RectangleFloat(rect1); } else if (!rect1.Intersects(rect2)) { result = new RectangleFloat(); } else { result = new RectangleFloat( Math.Max(rect1.X, rect2.X), Math.Max(rect1.Y, rect2.Y), Math.Min(rect1.Right, rect2.Right) - Math.Max(rect1.Left, rect2.Left), Math.Min(rect1.Bottom, rect2.Bottom) - Math.Max(rect1.Top, rect2.Top)); } return result; }