JD2022-TU1/main/tools/framework/JD.Kernel/Structs/RangeExtension.cs

40 lines
No EOL
1.1 KiB
C#

namespace JD.Kernel.Structs
{
/// <summary>
/// A numerical range (a max and a min).
/// </summary>
/// <remarks>
/// This class is immutable.
/// </remarks>
public static class RangeExtension
{
#region Properties
/// <summary>
/// Width of the range.
/// </summary>
public static float Width(this Range<float> range)
{
return range.Max - range.Min;
}
#endregion
#region Methods
/// <summary>
/// Returns a new range with min and max inflated by the given <paramref name="value"/> on each side.
/// </summary>
/// <remarks>
/// Note that the width of the range gets increased/decreased by 2 * <paramref name="value"/>.
/// </remarks>
/// <param name="value"></param>
/// <returns></returns>
public static Range<float> Inflate(this Range<float> range, float value)
{
return new Range<float>(range.Min - value, range.Max + value);
}
#endregion
}
}