[System.Drawing] Add ifdefs to source code used by Xamarin.iOS/Mac to make it compile...
[mono.git] / mcs / class / System.Drawing / System.Drawing / Rectangle.cs
index 4a54adc76846ebe65f872746f8aa517f09684f3c..c2ffbc80e5e647b589ed5aec55c96c1fb0703439 100644 (file)
@@ -39,7 +39,9 @@ namespace System.Drawing
 {
        [Serializable]
        [ComVisible (true)]
+#if !MONOTOUCH && !MONOMAC
        [TypeConverter (typeof (RectangleConverter))]
+#endif
        public struct Rectangle
        {
                private int x, y, width, height;
@@ -54,6 +56,7 @@ namespace System.Drawing
                
                public static readonly Rectangle Empty;
 
+
                /// <summary>
                ///     Ceiling Shared Method
                /// </summary>
@@ -130,12 +133,12 @@ namespace System.Drawing
                ///     Inflates the Rectangle by a specified Size.
                /// </remarks>
                
-               public void Inflate (Size sz)
+               public void Inflate (Size size)
                {
-                       x -= sz.Width;
-                       y -= sz.Height;
-                       Width += sz.Width * 2;
-                       Height += sz.Height * 2;
+                       x -= size.Width;
+                       y -= size.Height;
+                       Width += size.Width * 2;
+                       Height += size.Height * 2;
                }
 
                /// <summary>
@@ -147,11 +150,18 @@ namespace System.Drawing
                ///     Rectangles. Returns null if there is no intersection.
                /// </remarks>
                
-               public static Rectangle Intersect (Rectangle r1, Rectangle r2)
+               public static Rectangle Intersect (Rectangle a, Rectangle b)
                {
-                       Rectangle r = new Rectangle (r1.Location, r1.Size);
-                       r.Intersect (r2);
-                       return r;
+                       // MS.NET returns a non-empty rectangle if the two rectangles
+                       // touch each other
+                       if (!a.IntersectsWithInclusive (b))
+                               return Empty;
+
+                       return Rectangle.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));
                }
 
                /// <summary>
@@ -163,19 +173,9 @@ namespace System.Drawing
                ///     and another Rectangle.
                /// </remarks>
                
-               public void Intersect (Rectangle r)
+               public void Intersect (Rectangle rect)
                {
-                       if (!IntersectsWith (r)) {
-                               x = 0;
-                               y = 0;
-                               width = 0;
-                               height = 0;
-                       }
-
-                       x = Math.Max (Left, r.Left);
-                       y = Math.Max (Top, r.Top);
-                       width = Math.Min (Right, r.Right) - X;
-                       height = Math.Min (Bottom, r.Bottom) - Y;
+                       this = Rectangle.Intersect (this, rect);
                }
 
                /// <summary>
@@ -233,12 +233,12 @@ namespace System.Drawing
                ///     Rectangles.
                /// </remarks>
                
-               public static Rectangle Union (Rectangle r1, Rectangle r2)
+               public static Rectangle Union (Rectangle a, Rectangle b)
                {
-                       return FromLTRB (Math.Min (r1.Left, r2.Left),
-                                        Math.Min (r1.Top, r2.Top),
-                                        Math.Max (r1.Right, r2.Right),
-                                        Math.Max (r1.Bottom, r2.Bottom));
+                       return FromLTRB (Math.Min (a.Left, b.Left),
+                                        Math.Min (a.Top, b.Top),
+                                        Math.Max (a.Right, b.Right),
+                                        Math.Max (a.Bottom, b.Bottom));
                }
 
                /// <summary>
@@ -251,10 +251,10 @@ namespace System.Drawing
                ///     properties of the two Rectangles.
                /// </remarks>
 
-               public static bool operator == (Rectangle r1, Rectangle r2)
+               public static bool operator == (Rectangle left, Rectangle right)
                {
-                       return ((r1.Location == r2.Location) && 
-                               (r1.Size == r2.Size));
+                       return ((left.Location == right.Location) && 
+                               (left.Size == right.Size));
                }
                
                /// <summary>
@@ -267,10 +267,10 @@ namespace System.Drawing
                ///     properties of the two Rectangles.
                /// </remarks>
 
-               public static bool operator != (Rectangle r1, Rectangle r2)
+               public static bool operator != (Rectangle left, Rectangle right)
                {
-                       return ((r1.Location != r2.Location) || 
-                               (r1.Size != r2.Size));
+                       return ((left.Location != right.Location) || 
+                               (left.Size != right.Size));
                }
                
 
@@ -286,12 +286,12 @@ namespace System.Drawing
                ///     Creates a Rectangle from Point and Size values.
                /// </remarks>
                
-               public Rectangle (Point loc, Size sz)
+               public Rectangle (Point location, Size size)
                {
-                       x = loc.X;
-                       y = loc.Y;
-                       width = sz.Width;
-                       height = sz.Height;
+                       x = location.X;
+                       y = location.Y;
+                       width = size.Width;
+                       height = size.Height;
                }
 
                /// <summary>
@@ -352,15 +352,11 @@ namespace System.Drawing
                ///
                /// <remarks>
                ///     Indicates if the width or height are zero. Read only.
-               /// </remarks>
-               // LAMESPEC: Documentation says "This property returns true if 
-               // the Width, Height, X, and Y properties of this RectangleF all 
-               // have values of zero; otherwise, false.". Reality returns TRUE if
-               // width or height are equal 0          
+               /// </remarks>          
                [Browsable (false)]
                public bool IsEmpty {
                        get {
-                               return ((width == 0) || (height == 0));
+                               return ((x == 0) && (y == 0) && (width == 0) && (height == 0));
                        }
                }
 
@@ -511,8 +507,8 @@ namespace System.Drawing
                
                public bool Contains (int x, int y)
                {
-                       return ((x >= Left) && (x <= Right) && 
-                               (y >= Top) && (y <= Bottom));
+                       return ((x >= Left) && (x < Right) && 
+                               (y >= Top) && (y < Bottom));
                }
 
                /// <summary>
@@ -550,12 +546,12 @@ namespace System.Drawing
                ///     Checks equivalence of this Rectangle and another object.
                /// </remarks>
                
-               public override bool Equals (object o)
+               public override bool Equals (object obj)
                {
-                       if (!(o is Rectangle))
+                       if (!(obj is Rectangle))
                                return false;
 
-                       return (this == (Rectangle) o);
+                       return (this == (Rectangle) obj);
                }
 
                /// <summary>
@@ -579,7 +575,13 @@ namespace System.Drawing
                ///     Checks if a Rectangle intersects with this one.
                /// </remarks>
                
-               public bool IntersectsWith (Rectangle r)
+               public bool IntersectsWith (Rectangle rect)
+               {
+                       return !((Left >= rect.Right) || (Right <= rect.Left) ||
+                           (Top >= rect.Bottom) || (Bottom <= rect.Top));
+               }
+
+               private bool IntersectsWithInclusive (Rectangle r)
                {
                        return !((Left > r.Right) || (Right < r.Left) ||
                            (Top > r.Bottom) || (Bottom < r.Top));
@@ -593,10 +595,10 @@ namespace System.Drawing
                ///     Moves the Rectangle a specified distance.
                /// </remarks>
 
-               public void Offset (int dx, int dy)
+               public void Offset (int x, int y)
                {
-                       x += dx;
-                       y += dy;
+                       this.x += x;
+                       this.y += y;
                }
                
                /// <summary>
@@ -607,10 +609,10 @@ namespace System.Drawing
                ///     Moves the Rectangle a specified distance.
                /// </remarks>
 
-               public void Offset (Point pt)
+               public void Offset (Point pos)
                {
-                       x += pt.X;
-                       y += pt.Y;
+                       x += pos.X;
+                       y += pos.Y;
                }
                
                /// <summary>