// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Diagnostics;
namespace RGB.NET.Core;
///
/// Represents a scaling.
///
[DebuggerDisplay("[Horizontal: {Horizontal}, Vertical: {Vertical}]")]
public readonly struct Scale : IEquatable
{
#region Properties & Fields
///
/// Gets the horizontal scaling value.
///
public float Horizontal { get; }
///
/// Gets the vertical scaling value.
///
public float Vertical { get; }
#endregion
#region Constructors
///
/// Initializes a new instance of the class using the provided values.
///
/// The value used for horizontal and vertical scaling. 0 if not set.
public Scale(float scale = 1.0f) : this(scale, scale)
{ }
///
/// Initializes a new instance of the class using the provided values.
///
/// The value used for horizontal scaling.
/// The value used for vertical scaling.
public Scale(float horizontal, float vertical)
{
this.Horizontal = horizontal;
this.Vertical = vertical;
}
#endregion
#region Methods
///
/// Tests whether the specified is equivalent to this .
///
/// The scale to test.
/// true if is equivalent to this ; otherwise, false.
public bool Equals(Scale other) => Horizontal.EqualsInTolerance(other.Horizontal) && Vertical.EqualsInTolerance(other.Vertical);
///
/// 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) => obj is Scale other && Equals(other);
///
/// Returns a hash code for this .
///
/// An integer value that specifies the hash code for this .
public override int GetHashCode() => HashCode.Combine(Horizontal, Vertical);
///
/// Deconstructs the scale into the horizontal and vertical value.
///
/// The horizontal scaling value.
/// The vertical scaling value.
public void Deconstruct(out float horizontalScale, out float verticalScale)
{
horizontalScale = Horizontal;
verticalScale = Vertical;
}
#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 ==(Scale scale1, Scale scale2) => scale1.Equals(scale2);
///
/// 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 !=(Scale scale1, Scale scale2) => !(scale1 == scale2);
///
/// Returns a new representing the addition of the and the provided value.
///
/// The .
/// The value to add.
/// A new representing the addition of the and the provided value.
public static Scale operator +(Scale scale, float value) => new(scale.Horizontal + value, scale.Vertical + value);
///
/// Returns a new representing the subtraction of the and the provided value.
///
/// The .
/// The value to substract.
/// A new representing the subtraction of the and the provided value.
public static Scale operator -(Scale scale, float value) => new(scale.Horizontal - value, scale.Vertical - value);
///
/// Returns a new representing the multiplication of the and the provided value.
///
/// The .
/// The value to multiply with.
/// A new representing the multiplication of the and the provided value.
public static Scale operator *(Scale scale, float value) => new(scale.Horizontal * value, scale.Vertical * value);
///
/// Returns a new representing the division of the and the provided value.
///
/// The .
/// The value to device with.
/// A new representing the division of the and the provided value.
public static Scale operator /(Scale scale, float value) => value.EqualsInTolerance(0) ? new Scale(0) : new Scale(scale.Horizontal / value, scale.Vertical / value);
///
/// Converts a float to a .
///
/// The scale value to convert.
public static implicit operator Scale(float scale) => new(scale);
#endregion
}