// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex { using System; using System.Globalization; /// /// Defines a rectangle. /// public struct Rect { /// /// The X position. /// private double x; /// /// The Y position. /// private double y; /// /// The width. /// private double width; /// /// The height. /// private double height; /// /// Initializes a new instance of the structure. /// /// The X position. /// The Y position. /// The width. /// The height. public Rect(double x, double y, double width, double height) { this.x = x; this.y = y; this.width = width; this.height = height; } /// /// Initializes a new instance of the structure. /// /// The size of the rectangle. public Rect(Size size) { this.x = 0; this.y = 0; this.width = size.Width; this.height = size.Height; } /// /// Initializes a new instance of the structure. /// /// The position of the rectangle. /// The size of the rectangle. public Rect(Point position, Size size) { this.x = position.X; this.y = position.Y; this.width = size.Width; this.height = size.Height; } /// /// Gets the X position. /// public double X { get { return this.x; } } /// /// Gets the Y position. /// public double Y { get { return this.y; } } /// /// Gets the width. /// public double Width { get { return this.width; } } /// /// Gets the height. /// public double Height { get { return this.height; } } /// /// Gets the position of the rectangle. /// public Point Position { get { return new Point(this.x, this.y); } } /// /// Gets the size of the rectangle. /// public Size Size { get { return new Size(this.width, this.height); } } /// /// Determines whether a points in in the bounds of the rectangle. /// /// The point. /// true if the point is in the bounds of the rectangle; otherwise false. public bool Contains(Point p) { return p.X >= this.x && p.X < this.x + this.width && p.Y >= this.y && p.Y < this.y + this.height; } /// /// Deflates the rectangle by a . /// /// The thickness. /// The deflated rectangle. /// The deflated rectangle size cannot be less than 0. public Rect Deflate(Thickness thickness) { return new Rect( new Point(this.x + thickness.Left, this.y + thickness.Top), this.Size.Deflate(thickness)); } /// /// Returns the string representation of the rectangle. /// /// The string representation of the rectangle. public override string ToString() { return string.Format( CultureInfo.InvariantCulture, "{0}, {1}, {2}, {3}", this.x, this.y, this.width, this.height); } } }