public static bool RectanglesOverlap(Int2 topLeft0, Int2 size0, Int2 topLeft1, Int2 size1) { DebugEx.Assert(size0.X >= 0 && size0.Y >= 0); DebugEx.Assert(size1.X >= 0 && size1.Y >= 0); var topRight0 = topLeft0 + new Int2(Math.Max(size0.X - 1, 0), 0); var bottomRight0 = topLeft0 + Int2.ComponentMax(new Int2(), size0 - new Int2(1, 1)); var topRight1 = topLeft1 + new Int2(Math.Max(size1.X - 1, 0), 0); var bottomRight1 = topLeft1 + Int2.ComponentMax(new Int2(), size1 - new Int2(1, 1)); return(PointInRectangle(topLeft0, size0, topLeft1) || PointInRectangle(topLeft0, size0, topRight1) || PointInRectangle(topLeft0, size0, bottomRight1) || PointInRectangle(topLeft1, size1, topLeft0) || PointInRectangle(topLeft1, size1, topRight0) || PointInRectangle(topLeft1, size1, bottomRight0)); }