// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System.Diagnostics;
namespace RGB.NET.Core
{
///
/// Represents a size consisting of a width and a height.
///
[DebuggerDisplay("[Width: {Width}, Height: {Height}]")]
public class Size : AbstractBindable
{
#region Properties & Fields
private double _width;
///
/// Gets or sets the width component value of this .
///
public double Width
{
get => _width;
set => SetProperty(ref _width, value);
}
private double _height;
///
/// Gets or sets the height component value of this .
///
public double Height
{
get => _height;
set => SetProperty(ref _height, value);
}
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
public Size()
{ }
///
/// Initializes a new instance of the using the provided size to define a square.
///
/// The size used for the component value and the component value.
public Size(double size)
: this(size, size)
{ }
///
/// Initializes a new instance of the class using the provided values.
///
/// The size used for the component value.
/// The size used for the component value.
public Size(double width, double height)
{
this.Width = width;
this.Height = height;
}
#endregion
#region Methods
///
/// Converts the and of this to a human-readable string.
///
/// A string that contains the and of this . For example "[Width: 100, Height: 20]".
public override string ToString()
{
return $"[Width: {Width}, Height: {Height}]";
}
///
/// Tests whether the specified object is a and is equivalent to this .
///
/// The object to test.
/// true if is a equivalent to this ; otherwise, false.
public override bool Equals(object obj)
{
Size compareSize = obj as Size;
if (ReferenceEquals(compareSize, null))
return false;
if (ReferenceEquals(this, compareSize))
return true;
if (GetType() != compareSize.GetType())
return false;
return Width.EqualsInTolerance(compareSize.Width) && Height.EqualsInTolerance(compareSize.Height);
}
///
/// Returns a hash code for this .
///
/// An integer value that specifies the hash code for this .
public override int GetHashCode()
{
unchecked
{
int hashCode = Width.GetHashCode();
hashCode = (hashCode * 397) ^ Height.GetHashCode();
return hashCode;
}
}
#endregion
#region Operators
///
/// Returns a value that indicates whether two specified are equal.
///
/// The first to compare.
/// The second to compare.
/// true if and are equal; otherwise, false.
public static bool operator ==(Size size1, Size size2)
{
return ReferenceEquals(size1, null) ? ReferenceEquals(size2, null) : size1.Equals(size2);
}
///
/// Returns a value that indicates whether two specified are equal.
///
/// The first to compare.
/// The second to compare.
/// true if and are not equal; otherwise, false.
public static bool operator !=(Size size1, Size size2)
{
return !(size1 == size2);
}
///
/// Returns a new representing the addition of the two provided .
///
/// The first .
/// The second .
/// A new representing the addition of the two provided .
public static Size operator +(Size size1, Size size2)
{
return new Size(size1.Width + size2.Width, size1.Height + size2.Height);
}
///
/// Returns a new representing the substraction of the two provided .
///
/// The first .
/// The second .
/// A new representing the substraction of the two provided .
public static Size operator -(Size size1, Size size2)
{
return new Size(size1.Width - size2.Width, size1.Height - size2.Height);
}
///
/// Returns a new representing the multiplication of the two provided .
///
/// The first .
/// The second .
/// A new representing the multiplication of the two provided .
public static Size operator *(Size size1, Size size2)
{
return new Size(size1.Width * size2.Width, size1.Height * size2.Height);
}
///
/// Returns a new representing the division of the two provided .
///
/// The first .
/// The second .
/// A new representing the division of the two provided .
public static Size operator /(Size size1, Size size2)
{
if (size2.Width.EqualsInTolerance(0) || size2.Height.EqualsInTolerance(0)) return new Size();
return new Size(size1.Width / size2.Width, size1.Height / size2.Height);
}
#endregion
}
}