You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class KeepInRangeExtensions
|
|
|
|
|
{
|
|
|
|
|
public static double EnsureRange(this double input, double max) => EnsureRange(input, 0.0, max);
|
|
|
|
|
public static double EnsureRange(this double input, double min, double max) => Math.Max(min, Math.Min(max, input));
|
|
|
|
|
public static byte EnsureRange(this byte input, byte max) => EnsureRange(input, (byte)0, max);
|
|
|
|
|
public static byte EnsureRange(this byte input, byte min, byte max) => Math.Max(min, Math.Min(max, input));
|
|
|
|
|
public static byte EnsureRangeToByte(this int input) => (byte)EnsureRange(input, 0, 255);
|
|
|
|
|
public static int EnsureRange(this int input, int max) => EnsureRange(input, 0, max);
|
|
|
|
|
public static int EnsureRange(this int input, int min, int max) => Math.Max(min, Math.Min(max, input));
|
|
|
|
|
}
|
|
|
|
|
}
|