Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System.Drawing / System.Drawing / RectangleF.cs
index 3d34b67efdc7060f886c10fd535e1c87fa0966d3..0c651fe097749b4dedf847894835e31d1109686a 100644 (file)
@@ -5,11 +5,7 @@
 //   Mike Kestner (mkestner@speakeasy.net)
 //
 // Copyright (C) 2001 Mike Kestner
-// Copyright (C) 2004 Novell, Inc. http://www.novell.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -83,10 +79,10 @@ namespace System.Drawing
                ///     RectangleF by the specified coordinate values.
                /// </remarks>
                
-               public static RectangleF Inflate (RectangleF r, 
+               public static RectangleF Inflate (RectangleF rect
                                                  float x, float y)
                {
-                       RectangleF ir = new RectangleF (r.X, r.Y, r.Width, r.Height);
+                       RectangleF ir = new RectangleF (rect.X, rect.Y, rect.Width, rect.Height);
                        ir.Inflate (x, y);
                        return ir;
                }
@@ -99,9 +95,9 @@ namespace System.Drawing
                ///     Inflates the RectangleF by a specified width and height.
                /// </remarks>
                
-               public void Inflate (float width, float height)
+               public void Inflate (float x, float y)
                {
-                       Inflate (new SizeF (width, height));
+                       Inflate (new SizeF (x, y));
                }
 
                /// <summary>
@@ -112,12 +108,12 @@ namespace System.Drawing
                ///     Inflates the RectangleF by a specified Size.
                /// </remarks>
                
-               public void Inflate (SizeF sz)
+               public void Inflate (SizeF 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>
@@ -129,17 +125,19 @@ namespace System.Drawing
                ///     RectangleFs. Returns null if there is no intersection.
                /// </remarks>
                
-               public static RectangleF Intersect (RectangleF r1
-                                                   RectangleF r2)
+               public static RectangleF Intersect (RectangleF a
+                                                   RectangleF b)
                {
-                       if (!r1.IntersectsWith (r2)) 
+                       // MS.NET returns a non-empty rectangle if the two rectangles
+                       // touch each other
+                       if (!a.IntersectsWithInclusive (b))
                                return Empty;
 
                        return FromLTRB (
-                               Math.Max (r1.Left, r2.Left),
-                               Math.Max (r1.Top, r2.Top),
-                               Math.Min (r1.Right, r2.Right),
-                               Math.Min (r1.Bottom, r2.Bottom));
+                               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>
@@ -151,9 +149,9 @@ namespace System.Drawing
                ///     and another RectangleF.
                /// </remarks>
                
-               public void Intersect (RectangleF r)
+               public void Intersect (RectangleF rect)
                {
-                       this = RectangleF.Intersect (this, r);
+                       this = RectangleF.Intersect (this, rect);
                }
 
                /// <summary>
@@ -165,12 +163,12 @@ namespace System.Drawing
                ///     RectangleFs.
                /// </remarks>
                
-               public static RectangleF Union (RectangleF r1, RectangleF r2)
+               public static RectangleF Union (RectangleF a, RectangleF 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>
@@ -183,10 +181,10 @@ namespace System.Drawing
                ///     properties of the two RectangleFs.
                /// </remarks>
 
-               public static bool operator == (RectangleF r1, RectangleF r2)
+               public static bool operator == (RectangleF left, RectangleF right)
                {
-                       return (r1.X == r2.X) && (r1.Y == r2.Y) &&
-                                (r1.Width == r2.Width) && (r1.Height == r2.Height);
+                       return (left.X == right.X) && (left.Y == right.Y) &&
+                                (left.Width == right.Width) && (left.Height == right.Height);
                }
                
                /// <summary>
@@ -199,10 +197,10 @@ namespace System.Drawing
                ///     properties of the two RectangleFs.
                /// </remarks>
 
-               public static bool operator != (RectangleF r1, RectangleF r2)
+               public static bool operator != (RectangleF left, RectangleF right)
                {
-                       return (r1.X != r2.X) && (r1.Y != r2.Y) &&
-                                (r1.Width != r2.Width) && (r1.Height != r2.Height);
+                       return (left.X != right.X) || (left.Y != right.Y) ||
+                                (left.Width != right.Width) || (left.Height != right.Height);
                }
                
                /// <summary>
@@ -231,12 +229,12 @@ namespace System.Drawing
                ///     Creates a RectangleF from PointF and SizeF values.
                /// </remarks>
                
-               public RectangleF (PointF loc, SizeF sz)
+               public RectangleF (PointF location, SizeF 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>
@@ -310,7 +308,7 @@ namespace System.Drawing
                [Browsable (false)]
                public bool IsEmpty {
                        get {
-                               return (width == 0 || height == 0);
+                               return (width <= 0 || height <= 0);
                        }
                }
 
@@ -489,7 +487,7 @@ namespace System.Drawing
                
                public bool Contains (RectangleF rect)
                {
-                       return (rect == Intersect (this, rect));
+                       return X <= rect.X && Right >= rect.Right && Y <= rect.Y && Bottom >= rect.Bottom;
                }
 
                /// <summary>
@@ -500,12 +498,12 @@ namespace System.Drawing
                ///     Checks equivalence of this RectangleF and an object.
                /// </remarks>
                
-               public override bool Equals (object o)
+               public override bool Equals (object obj)
                {
-                       if (!(o is RectangleF))
+                       if (!(obj is RectangleF))
                                return false;
 
-                       return (this == (RectangleF) o);
+                       return (this == (RectangleF) obj);
                }
 
                /// <summary>
@@ -529,10 +527,16 @@ namespace System.Drawing
                ///     Checks if a RectangleF intersects with this one.
                /// </remarks>
 
-               public bool IntersectsWith (RectangleF r)
+               public bool IntersectsWith (RectangleF rect)
+               {
+                       return !((Left >= rect.Right) || (Right <= rect.Left) ||
+                           (Top >= rect.Bottom) || (Bottom <= rect.Top));
+               }
+
+               private bool IntersectsWithInclusive (RectangleF r)
                {
-                       return !((Left >= r.Right) || (Right <= r.Left) ||
-                           (Top >= r.Bottom) || (Bottom <= r.Top));
+                       return !((Left > r.Right) || (Right < r.Left) ||
+                           (Top > r.Bottom) || (Bottom < r.Top));
                }
 
                /// <summary>
@@ -543,10 +547,10 @@ namespace System.Drawing
                ///     Moves the RectangleF a specified distance.
                /// </remarks>
 
-               public void Offset (float dx, float dy)
+               public void Offset (float x, float y)
                {
-                       X += dx;
-                       Y += dy;
+                       X += x;
+                       Y += y;
                }
                
                /// <summary>
@@ -557,9 +561,9 @@ namespace System.Drawing
                ///     Moves the RectangleF a specified distance.
                /// </remarks>
 
-               public void Offset (PointF pt)
+               public void Offset (PointF pos)
                {
-                       Offset(pt.X, pt.Y);
+                       Offset (pos.X, pos.Y);
                }
                
                /// <summary>