Roblox-File-Format/DataTypes/NumberRange.cs

54 lines
1.2 KiB
C#
Raw Normal View History

using System;
2020-09-13 01:16:19 +00:00
using System.Diagnostics.Contracts;
namespace RobloxFiles.DataTypes
{
public class NumberRange
{
public readonly float Min;
public readonly float Max;
public override string ToString() => $"{Min} {Max}";
public NumberRange(float num)
{
Min = num;
Max = num;
}
2020-09-13 01:16:19 +00:00
public NumberRange(float min = 0, float max = 0)
{
2020-09-13 01:16:19 +00:00
Contract.Requires(max - min >= 0, "Max must be greater than min.");
Contract.EndContractBlock();
Min = min;
Max = max;
}
2020-09-13 01:16:19 +00:00
internal NumberRange(Attribute attr) : this(attr.readFloat(), attr.readFloat())
{
2020-09-13 01:16:19 +00:00
}
2020-09-13 01:16:19 +00:00
public override int GetHashCode()
{
return Min.GetHashCode() ^ Max.GetHashCode();
}
2020-09-13 01:16:19 +00:00
public override bool Equals(object obj)
{
2020-09-13 01:16:19 +00:00
if (!(obj is NumberRange))
return false;
2020-09-13 01:16:19 +00:00
var other = obj as NumberRange;
2020-09-13 01:16:19 +00:00
if (!Min.Equals(other.Min))
return false;
if (!Max.Equals(other.Max))
return false;
return true;
}
}
}