//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp
{
using System;
///
/// Extension methods for classes that implement .
///
internal static class ComparableExtensions
{
///
/// Restricts a to be within a specified range.
///
/// The The value to clamp.
/// The minimum value. If value is less than min, min will be returned.
/// The maximum value. If value is greater than max, max will be returned.
///
/// The representing the clamped value.
///
public static int Clamp(this int value, int min, int max)
{
if (value > max)
{
return max;
}
if (value < min)
{
return min;
}
return value;
}
///
/// Swaps the references to two objects in memory.
///
/// The first reference.
/// The second reference.
/// The type of object.
public static void Swap(ref T first, ref T second)
{
T temp = second;
second = first;
first = temp;
}
}
}