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 RDSizeNI(int width, int height) : IRDVortex { /// /// Initializes a new instance of the struct with the specified point. /// /// The point to initialize the size with. public RDSizeNI(RDPointNI pt) : this(pt.X, pt.Y) { } /// /// Gets or sets the width of the size. /// public int Width { get; set; } = width; /// /// Gets or sets the height of the size. /// public int Height { get; set; } = height; /// /// Gets the area of the size. /// public readonly int Area => Width * Height; /// /// Gets the screen size. /// public static RDSizeNI Screen => new(352, 198); /// /// Adds two sizes together. /// /// The first size. /// The second size. /// The sum of the two sizes. public static RDSizeNI Add(RDSizeNI sz1, RDSizeNI sz2) => new(sz1.Width + sz2.Width, sz1.Height + sz2.Height); /// /// Truncates the specified size to integer values. /// /// The size to truncate. /// The truncated size. public static RDSizeNI Truncate(RDSizeN value) => new((int)value.Width, (int)value.Height); /// /// Subtracts one size from another. /// /// The first size. /// The second size. /// The difference between the two sizes. public static RDSizeNI Subtract(RDSizeNI sz1, RDSizeNI sz2) => new(sz1.Width - sz2.Width, sz1.Height - sz2.Height); /// /// Rounds up the specified size to the nearest integer values. /// /// The size to round up. /// The rounded-up size. public static RDSizeNI Ceiling(RDSizeN value) => new( (int)Math.Ceiling((double)value.Width), (int)Math.Ceiling((double)value.Height)); /// /// Rounds the specified size to the nearest integer values. /// /// The size to round. /// The rounded size. public static RDSizeNI Round(RDSizeN value) => new( (int)Math.Round((double)value.Width), (int)Math.Round((double)value.Height)); /// /// Converts the current size to a point. /// /// A with the same width and height as the current size. public readonly RDPointNI ToPoint() => new(Width, Height); /// public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is RDSizeNI e && Equals(e); /// public override readonly int GetHashCode() => HashCode.Combine(Width, Height); /// public override readonly string ToString() => $"[{Width},{Height}]"; /// public readonly bool Equals(RDSizeNI other) => Width == other.Width && Height == other.Height; /// public static RDSizeNI operator +(RDSizeNI sz1, RDSizeNI sz2) => Add(sz1, sz2); /// public static RDSizeNI operator -(RDSizeNI sz1, RDSizeNI sz2) => Subtract(sz1, sz2); /// public static RDSizeN operator *(float left, RDSizeNI right) => new(left * right.Width, left * right.Height); /// public static RDSizeN operator *(RDSizeNI left, float right) => new(left.Width * right, left.Height * right); /// public static RDSizeNI operator *(int left, RDSizeNI right) => new(left * right.Width, left * right.Height); /// public static RDSizeNI operator *(RDSizeNI left, int right) => new(left.Width * right, left.Height * right); /// public static RDSizeN operator /(RDSizeNI left, float right) => new(left.Width / right, left.Height / right); /// public static RDSizeNI operator /(RDSizeNI left, int right) => new( left.Width / right, left.Height / right); /// public static bool operator ==(RDSizeNI sz1, RDSizeNI sz2) => sz1.Equals(sz2); /// public static bool operator !=(RDSizeNI sz1, RDSizeNI sz2) => !sz1.Equals(sz2); /// /// Implicitly converts an to an . /// /// The to convert. /// An with the same width and height as the input. public static implicit operator RDSizeN(RDSizeNI p) => new(p.Width, p.Height); /// /// Implicitly converts an to an . /// /// The to convert. /// An with the same width and height as the input. public static implicit operator RDSizeI(RDSizeNI p) => new(p.Width, p.Height); /// /// Implicitly converts an to an . /// /// The to convert. /// An with the same width and height as the input. public static implicit operator RDSizeE(RDSizeNI p) => new(p.Width, p.Height); /// /// Explicitly converts an to an . /// /// The to convert. /// An with the same width and height as the input. public static explicit operator RDPointNI(RDSizeNI size) => new(size.Width, size.Height); private readonly string GetDebuggerDisplay() => ToString(); } }