|
|
|
@ -6,6 +6,7 @@ |
|
|
|
namespace ImageSharp |
|
|
|
{ |
|
|
|
using System; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Extension methods for classes that implement <see cref="IComparable{T}"/>.
|
|
|
|
@ -21,6 +22,7 @@ namespace ImageSharp |
|
|
|
/// <returns>
|
|
|
|
/// The <see cref="byte"/> representing the clamped value.
|
|
|
|
/// </returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static byte Clamp(this byte value, byte min, byte max) |
|
|
|
{ |
|
|
|
// Order is important here as someone might set min to higher than max.
|
|
|
|
@ -46,6 +48,7 @@ namespace ImageSharp |
|
|
|
/// <returns>
|
|
|
|
/// The <see cref="int"/> representing the clamped value.
|
|
|
|
/// </returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static uint Clamp(this uint value, uint min, uint max) |
|
|
|
{ |
|
|
|
if (value >= max) |
|
|
|
@ -70,6 +73,7 @@ namespace ImageSharp |
|
|
|
/// <returns>
|
|
|
|
/// The <see cref="int"/> representing the clamped value.
|
|
|
|
/// </returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static int Clamp(this int value, int min, int max) |
|
|
|
{ |
|
|
|
if (value >= max) |
|
|
|
@ -94,6 +98,7 @@ namespace ImageSharp |
|
|
|
/// <returns>
|
|
|
|
/// The <see cref="float"/> representing the clamped value.
|
|
|
|
/// </returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static float Clamp(this float value, float min, float max) |
|
|
|
{ |
|
|
|
if (value >= max) |
|
|
|
@ -118,6 +123,7 @@ namespace ImageSharp |
|
|
|
/// <returns>
|
|
|
|
/// The <see cref="double"/> representing the clamped value.
|
|
|
|
/// </returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static double Clamp(this double value, double min, double max) |
|
|
|
{ |
|
|
|
if (value >= max) |
|
|
|
@ -172,6 +178,7 @@ namespace ImageSharp |
|
|
|
/// <param name="first">The first reference.</param>
|
|
|
|
/// <param name="second">The second reference.</param>
|
|
|
|
/// <typeparam name="T">The type of object.</typeparam>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static void Swap<T>(ref T first, ref T second) |
|
|
|
{ |
|
|
|
T temp = second; |
|
|
|
|