Table of Contents

Class MathUtils

Namespace
NanoByte.Common
Assembly
NanoByte.Common.dll

Provides math-related utility functions.

public static class MathUtils
Inheritance
object
MathUtils

Methods

Clamp(double, double, double)

Makes a value stay within a certain range.

[Pure]
public static double Clamp(this double value, double min = 0, double max = 1)

Parameters

value double

The number to clamp.

min double

The minimum number to return.

max double

The maximum number to return.

Returns

double

The value if it was in range, otherwise min or max.

Clamp(int, int, int)

Makes a value stay within a certain range.

[Pure]
public static int Clamp(this int value, int min = 0, int max = 1)

Parameters

value int

The number to clamp.

min int

The minimum number to return.

max int

The maximum number to return.

Returns

int

The value if it was in range, otherwise min or max.

Clamp(long, long, long)

Makes a value stay within a certain range.

[Pure]
public static long Clamp(this long value, long min = 0, long max = 1)

Parameters

value long

The number to clamp.

min long

The minimum number to return.

max long

The maximum number to return.

Returns

long

The value if it was in range, otherwise min or max.

Clamp(float, float, float)

Makes a value stay within a certain range.

[Pure]
public static float Clamp(this float value, float min = 0, float max = 1)

Parameters

value float

The number to clamp.

min float

The minimum number to return.

max float

The maximum number to return.

Returns

float

The value if it was in range, otherwise min or max.

DegreeToRadian(double)

Converts an angle in degrees to radians.

[Pure]
public static double DegreeToRadian(this double value)

Parameters

value double

The angle in degrees.

Returns

double

The angle in radians.

DegreeToRadian(float)

Converts an angle in degrees to radians.

[Pure]
public static float DegreeToRadian(this float value)

Parameters

value float

The angle in degrees.

Returns

float

The angle in radians.

EaseIn(double, EasingFunction)

Applies an ease-in function to the given normalized value (0–1).

[Pure]
public static double EaseIn(double value, EasingFunction function = EasingFunction.Sinusoidal)

Parameters

value double
function EasingFunction

Returns

double

EaseInOut(double, EasingFunction)

Applies an ease-in-out function to the given normalized value (0–1).

[Pure]
public static double EaseInOut(double value, EasingFunction function = EasingFunction.Sinusoidal)

Parameters

value double
function EasingFunction

Returns

double

EaseOut(double, EasingFunction)

Applies an ease-out function to the given normalized value (0–1).

[Pure]
public static double EaseOut(double value, EasingFunction function = EasingFunction.Sinusoidal)

Parameters

value double
function EasingFunction

Returns

double

EqualsTolerance(double, double, double)

Compares two floating-point values for equality, allowing for a certain tolerance.

[Pure]
public static bool EqualsTolerance(this double a, double b, double tolerance = 1E-05)

Parameters

a double
b double
tolerance double

Returns

bool

EqualsTolerance(float, float, float)

Compares two floating-point values for equality, allowing for a certain tolerance.

[Pure]
public static bool EqualsTolerance(this float a, float b, float tolerance = 1E-05)

Parameters

a float
b float
tolerance float

Returns

bool

GaussKernel(double, int)

Generates a Gaussian kernel.

[Pure]
public static double[] GaussKernel(double sigma, int kernelSize)

Parameters

sigma double

The standard deviation of the Gaussian distribution.

kernelSize int

The size of the kernel. Should be an uneven number.

Returns

double[]

InterpolateEased(double, double, double, EasingFunction)

Interpolates between two values with easing.

[Pure]
public static double InterpolateEased(double start, double end, double factor, EasingFunction function = EasingFunction.Sinusoidal)

Parameters

start double

The start value.

end double

The end value.

factor double

The interpolation factor. Values outside the range 0-1 will be clamped.

function EasingFunction

The easing function.

Returns

double

Lerp(double, double, double)

Linearly interpolates between two values.

[Pure]
public static double Lerp(double start, double end, double factor)

Parameters

start double

The start value.

end double

The end value.

factor double

The interpolation factor. Typically in the range 0-1. Values outside this range will extrapolate.

Returns

double

Lerp(float, float, float)

Linearly interpolates between two values.

[Pure]
public static float Lerp(float start, float end, float factor)

Parameters

start float

The start value.

end float

The end value.

factor float

The interpolation factor. Typically in the range 0-1. Values outside this range will extrapolate.

Returns

float

Modulo(double, double)

Calculates the mathematical modulo of a value.

[Pure]
public static double Modulo(this double value, double modulo)

Parameters

value double
modulo double

Returns

double

Modulo(int, int)

Calculates the mathematical modulo of a value.

[Pure]
public static int Modulo(this int value, int modulo)

Parameters

value int
modulo int

Returns

int

Modulo(long, long)

Calculates the mathematical modulo of a value.

[Pure]
public static long Modulo(this long value, long modulo)

Parameters

value long
modulo long

Returns

long

Modulo(float, float)

Calculates the mathematical modulo of a value.

[Pure]
public static float Modulo(this float value, float modulo)

Parameters

value float
modulo float

Returns

float

MultiplyAndRound(Size, SizeF)

Multiplies a System.Drawing.Size with a System.Drawing.SizeF and then rounds the components to integer values.

[Pure]
public static Size MultiplyAndRound(this Size size, SizeF factor)

Parameters

size Size
factor SizeF

Returns

Size

RadianToDegree(double)

Converts an angle in radians to degrees.

[Pure]
public static double RadianToDegree(this double value)

Parameters

value double

The angle in radians.

Returns

double

The angle in degrees.

RadianToDegree(float)

Converts an angle in radians to degrees.

[Pure]
public static float RadianToDegree(this float value)

Parameters

value float

The angle in radians.

Returns

float

The angle in degrees.