/// <summary> /// Constructor which sets the initial values to bound the (0,0) point and the point /// that results from (0,0) + size. /// </summary> public Rect(Size size) { if (size.IsEmpty) { this = s_empty; } else { _x = _y = 0; _width = size.Width; _height = size.Height; } }
/// <summary> /// Constructor which sets the initial values to the values of the parameters /// </summary> public Rect(Point location, Size size) { if (size.IsEmpty) { this = s_empty; } else { _x = location._x; _y = location._y; _width = size._width; _height = size._height; } }
/// <summary> /// Inflate - return the result of inflating rect by the size provided, in all directions /// If this is Empty, this method is illegal. /// </summary> public static Rect Inflate(Rect rect, Size size) { rect.Inflate(size._width, size._height); return rect; }
/// <summary> /// Inflate - inflate the bounds by the size provided, in all directions /// If this is Empty, this method is illegal. /// </summary> public void Inflate(Size size) { Inflate(size._width, size._height); }
/// <summary> /// Equals - compares this Size with the passed in object. In this equality /// Double.NaN is equal to itself, unlike in numeric equality. /// Note that double values can acquire error when operated upon, such that /// an exact comparison between two values which /// are logically equal may fail. /// </summary> /// <returns> /// bool - true if "value" is equal to "this". /// </returns> /// <param name='value'>The Size to compare to "this"</param> public bool Equals(Size value) { return Size.Equals(this, value); }
/// <summary> /// Compares two Size instances for object equality. In this equality /// Double.NaN is equal to itself, unlike in numeric equality. /// Note that double values can acquire error when operated upon, such that /// an exact comparison between two values which /// are logically equal may fail. /// </summary> /// <returns> /// bool - true if the two Size instances are exactly equal, false otherwise /// </returns> /// <param name='size1'>The first Size to compare</param> /// <param name='size2'>The second Size to compare</param> public static bool Equals(Size size1, Size size2) { if (size1.IsEmpty) { return size2.IsEmpty; } else { return size1.Width.Equals(size2.Width) && size1.Height.Equals(size2.Height); } }
static private Size CreateEmptySize() { Size size = new Size(); // We can't set these via the property setters because negatives widths // are rejected in those APIs. size._width = Double.NegativeInfinity; size._height = Double.NegativeInfinity; return size; }
// Normalizes the point in the given size to the range [-1, 1]. internal static Point GetNormalizedPoint(Point point, Size size) { return new Point( ((2 * point.X) / size.Width) - 1, -(((2 * point.Y) / size.Height) - 1)); }
// Returns the aspect ratio of the given size. internal static double GetAspectRatio(Size viewSize) { return viewSize.Width / viewSize.Height; }
/// <summary> /// Compares two Size instances for fuzzy equality. This function /// helps compensate for the fact that double values can /// acquire error when operated upon /// </summary> /// <param name='size1'>The first size to compare</param> /// <param name='size2'>The second size to compare</param> /// <returns>Whether or not the two Size instances are equal</returns> public static bool AreClose(Size size1, Size size2) { return DoubleUtil.AreClose(size1.Width, size2.Width) && DoubleUtil.AreClose(size1.Height, size2.Height); }