public static RectInt32 Intersect(RectInt32 a, RectInt32 b) { // MS.NET returns a non-empty rectangle if the two rectangles // touch each other if (!a.IntersectsWithInclusive(b)) { return(new RectInt32(0, 0, 0, 0)); } // return(RectInt32.FromLTRB( Math.Max(a.Left, b.Left), Math.Max(a.Top, b.Top), Math.Min(a.Right, b.Right), Math.Min(a.Bottom, b.Bottom))); }
private bool IntersectsWithInclusive(RectInt32 r) { return(!((Left > r.Right) || (Right < r.Left) || (Top > r.Bottom) || (Bottom < r.Top))); }
/// <summary> /// Intersect Method /// </summary> /// /// <remarks> /// Replaces the Rectangle with the intersection of itself /// and another Rectangle. /// </remarks> public void Intersect(RectInt32 rect) { this = RectInt32.Intersect(this, rect); }