diff --git a/Source/OpenTK/Math/MathHelper.cs b/Source/OpenTK/Math/MathHelper.cs
index 215f540f..87fad768 100644
--- a/Source/OpenTK/Math/MathHelper.cs
+++ b/Source/OpenTK/Math/MathHelper.cs
@@ -288,6 +288,46 @@ namespace OpenTK
#endregion
+ #region Clamp
+
+ ///
+ /// Clamps a number between a minimum and a maximum.
+ ///
+ /// The number to clamp.
+ /// The minimum allowed value.
+ /// The maximum allowed value.
+ /// min, if n is lower than min; max, if n is higher than max; n otherwise.
+ public static int Clamp(int n, int min, int max)
+ {
+ return Math.Max(Math.Min(n, max), min);
+ }
+
+ ///
+ /// Clamps a number between a minimum and a maximum.
+ ///
+ /// The number to clamp.
+ /// The minimum allowed value.
+ /// The maximum allowed value.
+ /// min, if n is lower than min; max, if n is higher than max; n otherwise.
+ public static float Clamp(float n, float min, float max)
+ {
+ return Math.Max(Math.Min(n, max), min);
+ }
+
+ ///
+ /// Clamps a number between a minimum and a maximum.
+ ///
+ /// The number to clamp.
+ /// The minimum allowed value.
+ /// The maximum allowed value.
+ /// min, if n is lower than min; max, if n is higher than max; n otherwise.
+ public static double Clamp(double n, double min, double max)
+ {
+ return Math.Max(Math.Min(n, max), min);
+ }
+
+ #endregion
+
#endregion
}
}