using Newtonsoft.Json;
using RhythmBase.Converters;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace RhythmBase.Components
{
///
/// A size whose horizontal and vertical coordinates are non-nullable
///
[JsonConverter(typeof(RDPointsConverter))]
[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
public struct RDSizeN(float width, float height) : IRDVortex
{
///
/// Initializes a new instance of the struct with the specified point.
///
/// The point to initialize the size with.
public RDSizeN(RDPointN pt) : this(pt.X, pt.Y) { }
///
/// Gets or sets the width of the size.
///
public float Width { get; set; } = width;
///
/// Gets or sets the height of the size.
///
public float Height { get; set; } = height;
///
/// Gets the area of the size.
///
public readonly float Area => Width * Height;
///
/// Adds two sizes together.
///
/// The first size.
/// The second size.
/// The result of adding the two sizes.
public static RDSizeN Add(RDSizeN sz1, RDSizeN sz2) => new(sz1.Width + sz2.Width, sz1.Height + sz2.Height);
///
/// Subtracts one size from another.
///
/// The size to subtract from.
/// The size to subtract.
/// The result of subtracting the second size from the first size.
public static RDSizeN Subtract(RDSizeN sz1, RDSizeN sz2) => new(sz1.Width - sz2.Width, sz1.Height - sz2.Height);
///
public override readonly int GetHashCode() => HashCode.Combine(Width, Height);
///
public override readonly string ToString() => $"[{Width},{Height}]";
///
public readonly bool Equals(RDSizeN other) => Width == other.Width && Height == other.Height;
///
/// Converts the current size to an integer size.
///
/// A new instance with the width and height rounded to the nearest integer.
public readonly RDSizeNI ToSizeI() => new((int)Math.Round((double)Width), (int)Math.Round((double)Height));
///
/// Converts the current size to a point.
///
/// A new instance with the width as the X coordinate and the height as the Y coordinate.
public readonly RDPointN ToPoint() => new(Width, Height);
///
public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is RDSizeN e && Equals(e);
///
public static RDSizeN operator +(RDSizeN sz1, RDSizeN sz2) => Add(sz1, sz2);
///
public static RDSizeN operator -(RDSizeN sz1, RDSizeN sz2) => Subtract(sz1, sz2);
///
public static RDSizeN operator *(float left, RDSizeN right) => new(left * right.Width, left * right.Height);
///
public static RDSizeN operator *(RDSizeN left, float right) => new(left.Width * right, left.Height * right);
///
public static RDSizeN operator /(RDSizeN left, float right) => new(left.Width / right, left.Height / right);
///
public static bool operator ==(RDSizeN sz1, RDSizeN sz2) => sz1.Equals(sz2);
///
public static bool operator !=(RDSizeN sz1, RDSizeN sz2) => !sz1.Equals(sz2);
///
/// Implicitly converts an to an .
///
/// The to convert.
/// A new instance.
public static implicit operator RDSize(RDSizeN size) => new(new float?(size.Width), new float?(size.Height));
///
/// Implicitly converts an to an .
///
/// The to convert.
/// A new instance.
public static implicit operator RDSizeE(RDSizeN size) => new(size.Width, size.Height);
///
/// Explicitly converts an to an .
///
/// The to convert.
/// A new instance.
public static explicit operator RDPointN(RDSizeN size) => new(size.Width, size.Height);
private readonly string GetDebuggerDisplay() => ToString();
}
}