Merge pull request #4710 from Unity-Technologies/additional-config-checks
[mono.git] / mcs / class / System.Drawing / System.Drawing / RectangleF.cs
index 3d34b67efdc7060f886c10fd535e1c87fa0966d3..dc2ea17506ee790732f14e1e3baedf71a8df13d8 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
@@ -51,13 +47,6 @@ namespace System.Drawing
                
                public static readonly RectangleF Empty;
 
-#if TARGET_JVM
-               internal java.awt.geom.Rectangle2D NativeObject {
-                       get {
-                               return new java.awt.geom.Rectangle2D.Float(X,Y,Width,Height);
-                       }
-               }
-#endif
 
                /// <summary>
                ///     FromLTRB Shared Method
@@ -83,10 +72,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 +88,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 +101,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 +118,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 +142,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 +156,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 +174,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 +190,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 +222,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>
@@ -257,14 +248,6 @@ namespace System.Drawing
                }
 
 
-#if TARGET_JVM
-               internal RectangleF (java.awt.geom.RectangularShape r2d) {
-                       this.x = (float) r2d.getX ();
-                       this.y = (float) r2d.getY ();
-                       this.width = (float) r2d.getWidth ();
-                       this.height = (float) r2d.getHeight ();
-               }
-#endif
 
                /// <summary>
                ///     Bottom Property
@@ -310,7 +293,7 @@ namespace System.Drawing
                [Browsable (false)]
                public bool IsEmpty {
                        get {
-                               return (width == 0 || height == 0);
+                               return (width <= 0 || height <= 0);
                        }
                }
 
@@ -489,7 +472,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 +483,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 +512,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 +532,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 +546,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>