Class MathUtils
- Namespace
- NanoByte.Common
- Assembly
- NanoByte.Common.dll
Provides math-related utility functions.
public static class MathUtils
- Inheritance
-
objectMathUtils
Methods
Clamp(double, double, double)
Makes a value stay within a certain range.
public static double Clamp(this double value, double min = 0, double max = 1)
Parameters
valuedoubleThe number to clamp.
mindoubleThe minimum number to return.
maxdoubleThe maximum number to return.
Returns
- double
The
valueif it was in range, otherwiseminormax.
Exceptions
- ArgumentException
minwas larger thanmax.
Clamp(int, int, int)
Makes a value stay within a certain range.
public static int Clamp(this int value, int min = 0, int max = 1)
Parameters
valueintThe number to clamp.
minintThe minimum number to return.
maxintThe maximum number to return.
Returns
- int
The
valueif it was in range, otherwiseminormax.
Exceptions
- ArgumentException
minwas larger thanmax.
Clamp(long, long, long)
Makes a value stay within a certain range.
public static long Clamp(this long value, long min = 0, long max = 1)
Parameters
valuelongThe number to clamp.
minlongThe minimum number to return.
maxlongThe maximum number to return.
Returns
- long
The
valueif it was in range, otherwiseminormax.
Exceptions
- ArgumentException
minwas larger thanmax.
Clamp(float, float, float)
Makes a value stay within a certain range.
public static float Clamp(this float value, float min = 0, float max = 1)
Parameters
valuefloatThe number to clamp.
minfloatThe minimum number to return.
maxfloatThe maximum number to return.
Returns
- float
The
valueif it was in range, otherwiseminormax.
Exceptions
- ArgumentException
minwas larger thanmax.
DegreeToRadian(double)
Converts an angle in degrees to radians.
public static double DegreeToRadian(this double value)
Parameters
valuedoubleThe angle in degrees.
Returns
- double
The angle in radians.
DegreeToRadian(float)
Converts an angle in degrees to radians.
public static float DegreeToRadian(this float value)
Parameters
valuefloatThe angle in degrees.
Returns
- float
The angle in radians.
EaseIn(double, EasingFunction)
Applies an ease-in function to the given normalized value (0–1).
public static double EaseIn(double value, EasingFunction function = EasingFunction.Sinusoidal)
Parameters
valuedoublefunctionEasingFunction
Returns
EaseInOut(double, EasingFunction)
Applies an ease-in-out function to the given normalized value (0–1).
public static double EaseInOut(double value, EasingFunction function = EasingFunction.Sinusoidal)
Parameters
valuedoublefunctionEasingFunction
Returns
EaseOut(double, EasingFunction)
Applies an ease-out function to the given normalized value (0–1).
public static double EaseOut(double value, EasingFunction function = EasingFunction.Sinusoidal)
Parameters
valuedoublefunctionEasingFunction
Returns
EqualsTolerance(double, double, double)
Compares two floating-point values for equality, allowing for a certain tolerance.
public static bool EqualsTolerance(this double a, double b, double tolerance = 1E-05)
Parameters
Returns
EqualsTolerance(float, float, float)
Compares two floating-point values for equality, allowing for a certain tolerance.
public static bool EqualsTolerance(this float a, float b, float tolerance = 1E-05)
Parameters
Returns
GaussKernel(double, int)
Generates a Gaussian kernel.
public static double[] GaussKernel(double sigma, int kernelSize)
Parameters
sigmadoubleThe standard deviation of the Gaussian distribution.
kernelSizeintThe size of the kernel. Should be an uneven number.
Returns
- double[]
InterpolateEased(double, double, double, EasingFunction)
Interpolates between two values with easing.
public static double InterpolateEased(double start, double end, double factor, EasingFunction function = EasingFunction.Sinusoidal)
Parameters
startdoubleThe start value.
enddoubleThe end value.
factordoubleThe interpolation factor. Values outside the range 0-1 will be clamped.
functionEasingFunctionThe easing function.
Returns
Lerp(double, double, double)
Linearly interpolates between two values.
public static double Lerp(double start, double end, double factor)
Parameters
startdoubleThe start value.
enddoubleThe end value.
factordoubleThe interpolation factor. Typically in the range 0-1. Values outside this range will extrapolate.
Returns
Lerp(float, float, float)
Linearly interpolates between two values.
public static float Lerp(float start, float end, float factor)
Parameters
startfloatThe start value.
endfloatThe end value.
factorfloatThe interpolation factor. Typically in the range 0-1. Values outside this range will extrapolate.
Returns
Modulo(double, double)
Calculates the mathematical modulo of a value.
public static double Modulo(this double value, double modulo)
Parameters
Returns
Modulo(int, int)
Calculates the mathematical modulo of a value.
public static int Modulo(this int value, int modulo)
Parameters
Returns
Modulo(long, long)
Calculates the mathematical modulo of a value.
public static long Modulo(this long value, long modulo)
Parameters
Returns
Modulo(float, float)
Calculates the mathematical modulo of a value.
public static float Modulo(this float value, float modulo)
Parameters
Returns
MultiplyAndRound(Size, SizeF)
public static Size MultiplyAndRound(this Size size, SizeF factor)
Parameters
Returns
RadianToDegree(double)
Converts an angle in radians to degrees.
public static double RadianToDegree(this double value)
Parameters
valuedoubleThe angle in radians.
Returns
- double
The angle in degrees.
RadianToDegree(float)
Converts an angle in radians to degrees.
public static float RadianToDegree(this float value)
Parameters
valuefloatThe angle in radians.
Returns
- float
The angle in degrees.