// --------------------------------------------------------------------------------------------------------------------
//
// Copyright © James South and contributors.
// Licensed under the Apache License, Version 2.0.
//
//
// Stores an ordered pair of integers, which specify a height and width.
//
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor
{
using System;
using System.ComponentModel;
using System.Globalization;
///
/// Stores an ordered pair of integers, which specify a height and width.
///
public struct Size : IEquatable
{
///
/// Represents a that has Width and Height values set to zero.
///
public static readonly Size Empty = new Size();
///
/// The width of this .
///
public int Width;
///
/// The height of this .
///
public int Height;
///
/// Initializes a new instance of the struct.
///
///
/// The width of the size.
///
///
/// The height of the size.
///
public Size(int width, int height)
{
this.Width = width;
this.Height = height;
}
///
/// Gets a value indicating whether this is empty.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public bool IsEmpty
{
get
{
return this.Width == 0 && this.Height == 0;
}
}
///
/// Compares two objects. The result specifies whether the values
/// and the properties of the two
/// objects are equal.
///
///
/// The on the left side of the operand.
///
///
/// The on the right side of the operand.
///
///
/// True if the current left is equal to the parameter; otherwise, false.
///
public static bool operator ==(Size left, Size right)
{
return left.Equals(right);
}
///
/// Compares two objects. The result specifies whether the values
/// and the properties of the two
/// objects are unequal.
///
///
/// The on the left side of the operand.
///
///
/// The on the right side of the operand.
///
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
public static bool operator !=(Size left, Size right)
{
return !left.Equals(right);
}
///
/// Indicates whether this instance and a specified object are equal.
///
///
/// True if and this instance are the same type and represent the same value; otherwise, false.
///
/// The object to compare with the current instance.
public override bool Equals(object obj)
{
if (!(obj is Size))
{
return false;
}
Size other = (Size)obj;
return other.Width == this.Width && other.Height == this.Height;
}
///
/// Returns the hash code for this instance.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
///
public override int GetHashCode()
{
return this.GetHashCode(this);
}
///
/// Returns the fully qualified type name of this instance.
///
///
/// A containing a fully qualified type name.
///
public override string ToString()
{
return "{Width=" + this.Width.ToString(CultureInfo.CurrentCulture)
+ ",Height=" + this.Height.ToString(CultureInfo.CurrentCulture) + "}";
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
///
/// True if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(Size other)
{
return this.Width.Equals(other.Width) && this.Height.Equals(other.Height);
}
///
/// Returns the hash code for this instance.
///
///
/// The instance of to return the hash code for.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
///
private int GetHashCode(Size size)
{
unchecked
{
int hashCode = size.Width.GetHashCode();
hashCode = (hashCode * 397) ^ size.Height.GetHashCode();
return hashCode;
}
}
}
}