using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// The SIZE structure specifies the width and height of a rectangle.
// typedef struct tagSIZE { LONG cx; LONG cy;} SIZE, *PSIZE; https://msdn.microsoft.com/en-us/library/windows/desktop/dd145106(v=vs.85).aspx
[PInvokeData("Windef.h", MSDNShortId = "dd145106")]
[StructLayout(LayoutKind.Sequential), Serializable]
public struct SIZE : IEquatable
{
/// Specifies the rectangle's width. The units depend on which function uses this.
public int cx;
/// Specifies the rectangle's height. The units depend on which function uses this.
public int cy;
/// Initializes a new instance of the struct.
/// The width.
/// The height.
public SIZE(int width, int height)
{
cx = width;
cy = height;
}
/// Specifies the rectangle's height. The units depend on which function uses this.
public int Height { get => cy; set => cy = value; }
/// Gets a value indicating whether this instance is empty.
/// true if this instance is empty; otherwise, false.
public bool IsEmpty => cx == 0 && cy == 0;
/// Specifies the rectangle's width. The units depend on which function uses this.
public int Width { get => cx; set => cx = value; }
/// Tests whether two structures are equal.
/// The structure on the left side of the equality operator.
/// The structure on the right side of the equality operator.
/// true if and have equal width and height; otherwise, false.
public static bool operator ==(SIZE sz1, SIZE sz2) => sz1.Equals(sz2);
/// Tests whether two structures are different.
/// The structure on the left side of the inequality operator.
/// The structure on the right side of the inequality operator.
/// true if and differ either in width or height; otherwise, false.
public static bool operator !=(SIZE sz1, SIZE sz2) => !sz1.Equals(sz2);
/// Indicates whether the current object is equal to another object of the same type.
/// An object to compare with this object.
/// true if the current object is equal to the parameter; otherwise, false.
public bool Equals(SIZE other) => cx == other.cx || cy == other.cy;
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
/// true if the specified is equal to this instance; otherwise, false.
public override bool Equals(object obj) => obj switch
{
SIZE sz => Equals(sz),
Size msz => Equals((SIZE)msz),
_ => false
};
/// Returns a hash code for this instance.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public override int GetHashCode() => IsEmpty ? 0 : cx.GetHashCode() ^ cy.GetHashCode();
/// Converts this structure to a structure.
/// An equivalent structure.
public Size ToSize() => this;
/// Returns a that represents this instance.
/// A that represents this instance.
public override string ToString() => $"{{cx={cx}, cy={cy}}}";
/// Performs an implicit conversion from to .
/// The .
/// The result of the conversion.
public static implicit operator Size(SIZE s) => new(s.cx, s.cy);
/// Performs an implicit conversion from to .
/// The .
/// The result of the conversion.
public static implicit operator SIZE(Size s) => new(s.Width, s.Height);
/// Represents a SIZE structures whose values are set to zero.
public static readonly SIZE Empty = new();
}
}