TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.Helpers.Math Class Reference

Various helper methods for working with math. More...

Static Public Member Functions

static byte Clamp (byte value, byte min, byte max)
 Clamps the specified byte between a minimum and maximum value. More...
 
static short Clamp (short value, short min, short max)
 Clamps the specified short between a minimum and maximum value. More...
 
static ushort Clamp (ushort value, ushort min, ushort max)
 Clamps the specified unsigned short between a minimum and maximum value. More...
 
static int Clamp (int value, int min, int max)
 Clamps the specified integer between a minimum and maximum value. More...
 
static uint Clamp (uint value, uint min, uint max)
 Clamps the specified unsigned integer between a minimum and maximum value. More...
 
static long Clamp (long value, long min, long max)
 Clamps the specified 64-bit integer between a minimum and maximum value. More...
 
static ulong Clamp (ulong value, ulong min, ulong max)
 Clamps the specified 64-bit unsigned integer between a minimum and maximum value. More...
 
static float Clamp (float value, float min, float max)
 Clamps the specified float between a minimum and maximum value. More...
 
static double Clamp (double value, double min, double max)
 Clamps the specified double between a minimum and maximum value. More...
 
static decimal Clamp (decimal value, decimal min, decimal max)
 Clamps the specified decimal between a minimum and maximum value. More...
 

Detailed Description

Various helper methods for working with math.

Member Function Documentation

static byte TriDevs.TriEngine.Helpers.Math.Clamp ( byte  value,
byte  min,
byte  max 
)
static

Clamps the specified byte between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified byte is below this value, then this will be returned.
maxIf the specified byte is above this value, then this will be returned.
Returns
The clamped value of the byte.
41  {
42  if (min > max)
43  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
44 
45  return value < min ? min : (value > max ? max : value);
46  }
static short TriDevs.TriEngine.Helpers.Math.Clamp ( short  value,
short  min,
short  max 
)
static

Clamps the specified short between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified short is below this value, then this will be returned.
maxIf the specified short is above this value, then this will be returned.
Returns
The clamped value of the short.
56  {
57  if (min > max)
58  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
59 
60  return value < min ? min : (value > max ? max : value);
61  }
static ushort TriDevs.TriEngine.Helpers.Math.Clamp ( ushort  value,
ushort  min,
ushort  max 
)
static

Clamps the specified unsigned short between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified unsigned short is below this value, then this will be returned.
maxIf the specified unsigned short is above this value, then this will be returned.
Returns
The clamped value of the unsigned short.
71  {
72  if (min > max)
73  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
74 
75  return value < min ? min : (value > max ? max : value);
76  }
static int TriDevs.TriEngine.Helpers.Math.Clamp ( int  value,
int  min,
int  max 
)
static

Clamps the specified integer between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified integer is below this value, then this will be returned.
maxIf the specified integer is above this value, then this will be returned.
Returns
The clamped value of the integer.
86  {
87  if (min > max)
88  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
89 
90  return value < min ? min : (value > max ? max : value);
91  }
static uint TriDevs.TriEngine.Helpers.Math.Clamp ( uint  value,
uint  min,
uint  max 
)
static

Clamps the specified unsigned integer between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified unsigned integer is below this value, then this will be returned.
maxIf the specified unsigned integer is above this value, then this will be returned.
Returns
The clamped value of the unsigned integer.
101  {
102  if (min > max)
103  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
104 
105  return value < min ? min : (value > max ? max : value);
106  }
static long TriDevs.TriEngine.Helpers.Math.Clamp ( long  value,
long  min,
long  max 
)
static

Clamps the specified 64-bit integer between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified 64-bit integer is below this value, then this will be returned.
maxIf the specified 64-bit integer is above this value, then this will be returned.
Returns
The clamped value of the 64-bit integer.
116  {
117  if (min > max)
118  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
119 
120  return value < min ? min : (value > max ? max : value);
121  }
static ulong TriDevs.TriEngine.Helpers.Math.Clamp ( ulong  value,
ulong  min,
ulong  max 
)
static

Clamps the specified 64-bit unsigned integer between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified 64-bit unsigned integer is below this value, then this will be returned.
maxIf the specified 64-bit unsigned integer is above this value, then this will be returned.
Returns
The clamped value of the 64-bit unsigned integer.
131  {
132  if (min > max)
133  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
134 
135  return value < min ? min : (value > max ? max : value);
136  }
static float TriDevs.TriEngine.Helpers.Math.Clamp ( float  value,
float  min,
float  max 
)
static

Clamps the specified float between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified float is below this value, then this will be returned.
maxIf the specified float is above this value, then this will be returned.
Returns
The clamped value of the float.
146  {
147  if (min > max)
148  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
149 
150  return value < min ? min : (value > max ? max : value);
151  }
static double TriDevs.TriEngine.Helpers.Math.Clamp ( double  value,
double  min,
double  max 
)
static

Clamps the specified double between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified double is below this value, then this will be returned.
maxIf the specified double is above this value, then this will be returned.
Returns
The clamped value of the double.
161  {
162  if (min > max)
163  throw new ArgumentException("Minimum value cannot be greater than maximum value.", "min");
164 
165  return value < min ? min : (value > max ? max : value);
166  }
static decimal TriDevs.TriEngine.Helpers.Math.Clamp ( decimal  value,
decimal  min,
decimal  max 
)
static

Clamps the specified decimal between a minimum and maximum value.

Parameters
valueValue to clamp.
minIf the specified decimal is below this value, then this will be returned.
maxIf the specified decimal is above this value, then this will be returned.
Returns
The clamped value of the decimal.
176  {
177  if (min > max)
178  throw new ArgumentException("Minimum value cannot be grater than maximum value.", "min");
179 
180  return value < min ? min : (value > max ? max : value);
181  }

The documentation for this class was generated from the following file: