// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex { using System; using System.Globalization; /// /// Defines a size. /// public struct Size { /// /// The width. /// private double width; /// /// The height. /// private double height; /// /// Initializes a new instance of the structure. /// /// The width. /// The height. public Size(double width, double height) { this.width = width; this.height = height; } /// /// Gets the width. /// public double Width { get { return this.width; } } /// /// Gets the height. /// public double Height { get { return this.height; } } /// /// Constrains the size. /// /// The size to constrain to. /// The constrained size. public Size Constrain(Size constraint) { return new Size( Math.Min(this.width, constraint.width), Math.Min(this.height, constraint.height)); } /// /// Deflates the size by a . /// /// The thickness. /// The deflated size. /// The deflated size cannot be less than 0. public Size Deflate(Thickness thickness) { return new Size( Math.Max(0, this.width - thickness.Left - thickness.Right), Math.Max(0, this.height - thickness.Top - thickness.Bottom)); } /// /// Inflates the size by a . /// /// The thickness. /// The inflated size. public Size Inflate(Thickness thickness) { return new Size( this.width + thickness.Left + thickness.Right, this.height + thickness.Top + thickness.Bottom); } /// /// Returns the string representation of the size. /// /// The string representation of the size public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", this.width, this.height); } } }