25 using System.Globalization;
26 using System.Runtime.InteropServices;
28 namespace SiliconStudio.Core.Mathematics
34 [StructLayout(LayoutKind.Sequential)]
75 set { _left = value; }
96 get {
return _right; }
97 set { _right = value; }
107 get {
return _bottom; }
108 set { _bottom = value; }
124 _right = value + Width;
142 _bottom = value + Height;
154 get {
return _right - _left; }
155 set { _right = _left + value; }
165 get {
return _bottom - _top; }
166 set { _bottom = _top + value; }
176 public Point Location
180 return new Point(X, Y);
200 return new Point(X + (Width / 2), Y + (Height / 2));
214 return (Width == 0) && (Height == 0) && (X == 0) && (Y == 0);
227 return new Size2(Width, Height);
232 Height = value.Height;
240 public Point TopLeft {
get {
return new Point(_left, _top); } }
246 public Point TopRight {
get {
return new Point(_right, _top); } }
252 public Point BottomLeft {
get {
return new Point(_left, _bottom); } }
258 public Point BottomRight {
get {
return new Point(_right, _bottom); } }
264 Offset(amount.
X, amount.
Y);
270 public void Offset(
int offsetX,
int offsetY)
279 public void Inflate(
int horizontalAmount,
int verticalAmount)
281 X -= horizontalAmount;
283 Width += horizontalAmount * 2;
284 Height += verticalAmount * 2;
292 return (X <= x) && (x < Right) && (Y <= y) && (y < Bottom);
309 result = (X <= value.X) && (value.X < Right) && (Y <= value.Y) && (value.Y < Bottom);
326 result = (X <= value.X) && (value.Right <= Right) && (Y <= value.Y) && (value.Bottom <= Bottom);
337 return (x >= _left && x <= _right && y >= _top && y <= _bottom);
366 result = (value.X < Right) && (X < value.Right) && (value.Y < Bottom) && (Y < value.Bottom);
378 Intersect(ref value1, ref value2, out result);
388 int newLeft = (value1.X > value2.X) ? value1.X : value2.X;
389 int newTop = (value1.Y > value2.Y) ? value1.Y : value2.Y;
390 int newRight = (value1.Right < value2.Right) ? value1.Right : value2.Right;
391 int newBottom = (value1.Bottom < value2.Bottom) ? value1.Bottom : value2.Bottom;
392 if ((newRight > newLeft) && (newBottom > newTop))
394 result =
new Rectangle(newLeft, newTop, newRight - newLeft, newBottom - newTop);
411 Union(ref value1, ref value2, out result);
423 var left = Math.Min(value1.Left, value2.Left);
424 var right = Math.Max(value1.Right, value2.Right);
425 var top = Math.Min(value1.Top, value2.Top);
426 var bottom = Math.Max(value1.Bottom, value2.Bottom);
427 result =
new Rectangle(left, top, right - left, bottom - top);
439 if (ReferenceEquals(null, obj))
return false;
440 if (obj.GetType() != typeof(
Rectangle))
return false;
453 return other._left == _left && other._top == _top && other._right == _right && other._bottom == _bottom;
467 result = (result * 397) ^ _top;
468 result = (result * 397) ^ _right;
469 result = (result * 397) ^ _bottom;
482 return left.Equals(right);
493 return !(left == right);
507 internal void MakeXYAndWidthHeight()
509 _right = (_right - _left);
510 _bottom = (_bottom - _top);
515 return string.Format(CultureInfo.CurrentCulture,
"X:{0} Y:{1} Width:{2} Height:{3}", X, Y, Width, Height);
override int GetHashCode()
Returns a hash code for this instance.
void Contains(ref Rectangle value, out bool result)
Determines whether this rectangle entirely contains a specified rectangle.
override bool Equals(object obj)
Determines whether the specified System.Object is equal to this instance.
int X
Gets or sets the X position.
bool Contains(Point value)
Determines whether this rectangle contains a specified Point.
void Inflate(int horizontalAmount, int verticalAmount)
Pushes the edges of the rectangle out by the horizontal and vertical values specified.
Represents a two dimensional mathematical vector.
static readonly Rectangle Empty
An empty rectangle.
bool Contains(int x, int y)
Determines whether this rectangle contains a specified point represented by its x- and y-coordinates...
static Rectangle Union(Rectangle value1, Rectangle value2)
Creates a new rectangle that exactly contains two other rectangles.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
bool Equals(Rectangle other)
Determines whether the specified SharpDX.Rectangle is equal to this instance.
Rectangle(int x, int y, int width, int height)
Initializes a new instance of the Rectangle struct.
One bounding volume completely contains another.
int Y
Gets or sets the Y position.
bool Intersects(Rectangle value)
Determines whether a specified rectangle intersects with this rectangle.
static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
Creates a new rectangle that exactly contains two other rectangles.
The two bounding volumes overlap.
void Contains(ref Point value, out bool result)
Determines whether this rectangle contains a specified Point.
bool Contains(Vector2 vector2D)
Checks, if specified SharpDX.Vector2 is inside SharpDX.Rectangle.
Structure using the same layout than System.Drawing.Point.
void Intersects(ref Rectangle value, out bool result)
Determines whether a specified rectangle intersects with this rectangle.
float Y
The Y component of the vector.
int Height
Gets or sets the height.
override string ToString()
static Rectangle Intersect(Rectangle value1, Rectangle value2)
Creates a rectangle defining the area where one rectangle overlaps with another rectangle.
int Width
Gets or sets the width.
Structure using the same layout than System.Drawing.Size.
bool Contains(float x, float y)
Checks, if specified point is inside SharpDX.Rectangle.
System.Windows.Shapes.Rectangle Rectangle
float X
The X component of the vector.
bool Contains(Rectangle value)
Determines whether this rectangle entirely contains a specified rectangle.
void Offset(int offsetX, int offsetY)
Changes the position of the rectangle.
Structure using the same layout than System.Drawing.Rectangle
void Offset(Point amount)
Changes the position of the rectangle.
SiliconStudio.Core.Mathematics.RectangleF RectangleF
System.Windows.Point Point
static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
Creates a rectangle defining the area where one rectangle overlaps with another rectangle.