// 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
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
/// 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;
}
/// 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>
/// 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>
/// 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>
/// 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>
/// 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>
/// 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>
/// 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>
/// 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>
}
-#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
[Browsable (false)]
public bool IsEmpty {
get {
- return (width == 0 || height == 0);
+ return (width <= 0 || height <= 0);
}
}
public bool Contains (RectangleF rect)
{
- return (rect == Intersect (this, rect));
+ return X <= rect.X && Right >= rect.Right && Y <= rect.Y && Bottom >= rect.Bottom;
}
/// <summary>
/// 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>
/// 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>
/// 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>
/// 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>