using System;
using System.Runtime.CompilerServices;
namespace OpenMacroBoard.SDK
{
///
/// Represents an ordered pair of integer x- and y-coordinates that defines a point in
/// a two-dimensional plane.
///
public readonly struct OmbPoint : IEquatable
{
///
/// Represents a that has X and Y values set to zero.
///
public static readonly OmbPoint Empty = default;
///
/// Initializes a new instance of the struct.
///
/// The horizontal position of the point.
/// The vertical position of the point.
public OmbPoint(int x, int y)
: this()
{
X = x;
Y = y;
}
///
/// Initializes a new instance of the struct from the given .
///
/// The size.
public OmbPoint(OmbSize size)
{
X = size.Width;
Y = size.Height;
}
///
/// Gets or sets the x-coordinate of this .
///
public int X { get; }
///
/// Gets or sets the y-coordinate of this .
///
public int Y { get; }
///
/// Gets a value indicating whether this is empty.
///
public bool IsEmpty => Equals(Empty);
///
/// Creates a with the coordinates of the specified .
///
/// The point.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator OmbSize(OmbPoint point)
{
return new OmbSize(point.X, point.Y);
}
///
/// Divides by a producing .
///
/// Dividend of type .
/// Divisor of type .
/// Result of type .
public static OmbPoint operator /(OmbPoint left, int right)
{
return new OmbPoint(left.X / right, left.Y / right);
}
///
/// Compares two objects for equality.
///
/// 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.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(OmbPoint left, OmbPoint right)
{
return left.Equals(right);
}
///
/// Compares two objects for inequality.
///
/// 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.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(OmbPoint left, OmbPoint right)
{
return !left.Equals(right);
}
///
/// Deconstructs this point into two integers.
///
/// The out value for X.
/// The out value for Y.
public void Deconstruct(out int x, out int y)
{
x = X;
y = Y;
}
///
public override int GetHashCode()
{
return HashCode.Combine(X, Y);
}
///
public override string ToString()
{
return $"Point [ X={X}, Y={Y} ]";
}
///
public override bool Equals(object obj)
{
return obj is OmbPoint other && Equals(other);
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(OmbPoint other)
{
return X.Equals(other.X) && Y.Equals(other.Y);
}
}
}