#nullable enable using System; namespace UVC.UIToolkit { /// /// 범위 값을 나타내는 제네릭 구조체 /// public struct UTKRangeValue : IEquatable> where T : struct { public T Min { get; set; } public T Max { get; set; } public UTKRangeValue(T min, T max) { Min = min; Max = max; } public bool Equals(UTKRangeValue other) { return Min.Equals(other.Min) && Max.Equals(other.Max); } public override bool Equals(object? obj) { return obj is UTKRangeValue other && Equals(other); } public override int GetHashCode() { return HashCode.Combine(Min, Max); } public override string ToString() { return $"{Min} ~ {Max}"; } public static bool operator ==(UTKRangeValue left, UTKRangeValue right) { return left.Equals(right); } public static bool operator !=(UTKRangeValue left, UTKRangeValue right) { return !left.Equals(right); } } /// /// 정수 범위 (IntRange) /// public struct UTKIntRange : IEquatable { public int Min { get; set; } public int Max { get; set; } public UTKIntRange(int min, int max) { Min = min; Max = max; } public bool Contains(int value) => value >= Min && value <= Max; public int Clamp(int value) => Math.Max(Min, Math.Min(Max, value)); public int Range => Max - Min; public bool Equals(UTKIntRange other) => Min == other.Min && Max == other.Max; public override bool Equals(object? obj) => obj is UTKIntRange other && Equals(other); public override int GetHashCode() => HashCode.Combine(Min, Max); public override string ToString() => $"{Min} ~ {Max}"; public static bool operator ==(UTKIntRange left, UTKIntRange right) => left.Equals(right); public static bool operator !=(UTKIntRange left, UTKIntRange right) => !left.Equals(right); } /// /// 실수 범위 (FloatRange) /// public struct UTKFloatRange : IEquatable { public float Min { get; set; } public float Max { get; set; } public UTKFloatRange(float min, float max) { Min = min; Max = max; } public bool Contains(float value) => value >= Min && value <= Max; public float Clamp(float value) => Math.Max(Min, Math.Min(Max, value)); public float Range => Max - Min; public bool Equals(UTKFloatRange other) => Math.Abs(Min - other.Min) < float.Epsilon && Math.Abs(Max - other.Max) < float.Epsilon; public override bool Equals(object? obj) => obj is UTKFloatRange other && Equals(other); public override int GetHashCode() => HashCode.Combine(Min, Max); public override string ToString() => $"{Min:F2} ~ {Max:F2}"; public static bool operator ==(UTKFloatRange left, UTKFloatRange right) => left.Equals(right); public static bool operator !=(UTKFloatRange left, UTKFloatRange right) => !left.Equals(right); } /// /// 날짜 범위 (DateRange) /// public struct UTKDateRange : IEquatable { public DateTime Start { get; set; } public DateTime End { get; set; } public UTKDateRange(DateTime start, DateTime end) { Start = start.Date; End = end.Date; } public bool Contains(DateTime date) => date.Date >= Start && date.Date <= End; public TimeSpan Duration => End - Start; public int TotalDays => (int)Duration.TotalDays; public bool Equals(UTKDateRange other) => Start == other.Start && End == other.End; public override bool Equals(object? obj) => obj is UTKDateRange other && Equals(other); public override int GetHashCode() => HashCode.Combine(Start, End); public override string ToString() => $"{Start:yyyy-MM-dd} ~ {End:yyyy-MM-dd}"; public static bool operator ==(UTKDateRange left, UTKDateRange right) => left.Equals(right); public static bool operator !=(UTKDateRange left, UTKDateRange right) => !left.Equals(right); } /// /// 날짜시간 범위 (DateTimeRange) /// public struct UTKDateTimeRange : IEquatable { public DateTime Start { get; set; } public DateTime End { get; set; } public UTKDateTimeRange(DateTime start, DateTime end) { Start = start; End = end; } public bool Contains(DateTime dateTime) => dateTime >= Start && dateTime <= End; public TimeSpan Duration => End - Start; public bool Equals(UTKDateTimeRange other) => Start == other.Start && End == other.End; public override bool Equals(object? obj) => obj is UTKDateTimeRange other && Equals(other); public override int GetHashCode() => HashCode.Combine(Start, End); public override string ToString() => $"{Start:yyyy-MM-dd HH:mm} ~ {End:yyyy-MM-dd HH:mm}"; public static bool operator ==(UTKDateTimeRange left, UTKDateTimeRange right) => left.Equals(right); public static bool operator !=(UTKDateTimeRange left, UTKDateTimeRange right) => !left.Equals(right); } }