mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 14:08:48 +00:00
✨ Add Clamp() for integral types
This commit is contained in:
parent
44b6773cc8
commit
cae360edc3
@ -11,6 +11,18 @@
|
||||
/// </summary>
|
||||
public static class DoubleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Clamps a value between a minimum and a maximum value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
|
||||
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
|
||||
/// or <paramref name="value"/> itself otherwise.</returns>
|
||||
public static double Clamp(this double value, double min, double max) =>
|
||||
Math.Min(Math.Max(value, min), max);
|
||||
|
||||
/// <summary>
|
||||
/// Converts an angle from degrees to radians.
|
||||
/// </summary>
|
||||
|
@ -52,6 +52,30 @@
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a value between a minimum and a maximum value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
|
||||
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
|
||||
/// or <paramref name="value"/> itself otherwise.</returns>
|
||||
public static short Clamp(this short value, short min, short max) =>
|
||||
Math.Min(Math.Max(value, min), max);
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a value between a minimum and a maximum value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
|
||||
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
|
||||
/// or <paramref name="value"/> itself otherwise.</returns>
|
||||
public static ushort Clamp(this ushort value, ushort min, ushort max) =>
|
||||
Math.Min(Math.Max(value, min), max);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="Int16"/> to a <see cref="DateTime"/> treating it as a Unix timestamp.
|
||||
/// </summary>
|
||||
|
@ -52,6 +52,30 @@
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a value between a minimum and a maximum value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
|
||||
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
|
||||
/// or <paramref name="value"/> itself otherwise.</returns>
|
||||
public static int Clamp(this int value, int min, int max) =>
|
||||
Math.Min(Math.Max(value, min), max);
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a value between a minimum and a maximum value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
|
||||
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
|
||||
/// or <paramref name="value"/> itself otherwise.</returns>
|
||||
public static uint Clamp(this uint value, uint min, uint max) =>
|
||||
Math.Min(Math.Max(value, min), max);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="Int32"/> to a <see cref="DateTime"/> treating it as a Unix timestamp.
|
||||
/// </summary>
|
||||
|
@ -49,6 +49,30 @@
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a value between a minimum and a maximum value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
|
||||
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
|
||||
/// or <paramref name="value"/> itself otherwise.</returns>
|
||||
public static long Clamp(this long value, long min, long max) =>
|
||||
Math.Min(Math.Max(value, min), max);
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a value between a minimum and a maximum value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
|
||||
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
|
||||
/// or <paramref name="value"/> itself otherwise.</returns>
|
||||
public static ulong Clamp(this ulong value, ulong min, ulong max) =>
|
||||
Math.Min(Math.Max(value, min), max);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="Int64"/> to a <see cref="DateTime"/> treating it as a Unix timestamp.
|
||||
/// </summary>
|
||||
|
@ -11,6 +11,18 @@
|
||||
/// </summary>
|
||||
public static class SingleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Clamps a value between a minimum and a maximum value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
|
||||
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
|
||||
/// or <paramref name="value"/> itself otherwise.</returns>
|
||||
public static float Clamp(this float value, float min, float max) =>
|
||||
Math.Min(Math.Max(value, min), max);
|
||||
|
||||
/// <summary>
|
||||
/// Converts an angle from degrees to radians.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user