Files
UVtools/UVtools.Core/Extensions/MathExtensions.cs
T
Tiago Conceição c76a68c29b v0.6.3.3
* (Add) Allow to save properties to clipboard
* (Add) Tool: Layer Repair - Allow remove islands below or equal to a pixel count (Suggested by: Nicholas Taylor)
* (Add) Issues: Allow sort columns by click them (Suggested by: Nicholas Taylor)
* (Improvement) Tool: Pattern - Prevent open this tool when unable to pattern due lack of space
* (Fix) Tool: Layer Repair - When issues are not caculated before, they are computed but user settings are ignored
2020-07-26 02:46:18 +01:00

60 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace UVtools.Core.Extensions
{
public static class MathExtensions
{
public static byte Clamp(this byte value, byte min, byte max)
{
return value <= min ? min : value >= max ? max : value;
}
public static sbyte Clamp(this sbyte value, sbyte min, sbyte max)
{
return value <= min ? min : value >= max ? max : value;
}
public static ushort Clamp(this ushort value, ushort min, ushort max)
{
return value <= min ? min : value >= max ? max : value;
}
public static short Clamp(this short value, short min, short max)
{
return value <= min ? min : value >= max ? max : value;
}
public static uint Clamp(this uint value, uint min, uint max)
{
return value <= min ? min : value >= max ? max : value;
}
public static int Clamp(this int value, int min, int max)
{
return value <= min ? min : value >= max ? max : value;
}
public static ulong Clamp(this ulong value, ulong min, ulong max)
{
return value <= min ? min : value >= max ? max : value;
}
public static long Clamp(this long value, long min, long max)
{
return value <= min ? min : value >= max ? max : value;
}
public static T Clamp<T>(T value, T min, T max) where T : IComparable<T>
{
if (value.CompareTo(min) < 0)
return min;
if (value.CompareTo(max) > 0)
return max;
return value;
}
}
}