Table of Contents

Class MathUtilities

Namespace
Avalonia.Utilities
Assembly
Avalonia.Base.dll

Provides math utilities not provided in System.Math.

[Unstable("This API might be removed in next major version. Please use corresponding BCL APIs.")]
public static class MathUtilities
Inheritance
MathUtilities
Inherited Members

Methods

AreClose(double, double)

AreClose - Returns whether or not two doubles are "close". That is, whether or not they are within epsilon of each other.

public static bool AreClose(double value1, double value2)

Parameters

value1 double

The first double to compare.

value2 double

The second double to compare.

Returns

bool

AreClose(double, double, double)

AreClose - Returns whether or not two doubles are "close". That is, whether or not they are within epsilon of each other.

public static bool AreClose(double value1, double value2, double eps)

Parameters

value1 double

The first double to compare.

value2 double

The second double to compare.

eps double

The fixed epsilon value used to compare.

Returns

bool

AreClose(float, float)

AreClose - Returns whether or not two floats are "close". That is, whether or not they are within epsilon of each other.

public static bool AreClose(float value1, float value2)

Parameters

value1 float

The first float to compare.

value2 float

The second float to compare.

Returns

bool

Clamp(decimal, decimal, decimal)

Clamps a value between a minimum and maximum value.

public static decimal Clamp(decimal val, decimal min, decimal max)

Parameters

val decimal

The value.

min decimal

The minimum value.

max decimal

The maximum value.

Returns

decimal

The clamped value.

Clamp(double, double, double)

Clamps a value between a minimum and maximum value.

public static double Clamp(double val, double min, double max)

Parameters

val double

The value.

min double

The minimum value.

max double

The maximum value.

Returns

double

The clamped value.

Clamp(int, int, int)

Clamps a value between a minimum and maximum value.

public static int Clamp(int val, int min, int max)

Parameters

val int

The value.

min int

The minimum value.

max int

The maximum value.

Returns

int

The clamped value.

Clamp(float, float, float)

Clamps a value between a minimum and maximum value.

public static float Clamp(float value, float min, float max)

Parameters

value float

The value.

min float

The minimum value.

max float

The maximum value.

Returns

float

The clamped value.

Deg2Rad(double)

Converts an angle in degrees to radians.

public static double Deg2Rad(double angle)

Parameters

angle double

The angle in degrees.

Returns

double

The angle in radians.

GetEllipsePoint(Point, double, double, double)

Calculates the point of an angle on an ellipse.

public static Point GetEllipsePoint(Point centre, double radiusX, double radiusY, double angle)

Parameters

centre Point

The centre point of the ellipse.

radiusX double

The x radius of the ellipse.

radiusY double

The y radius of the ellipse.

angle double

The angle in radians.

Returns

Point

A point on the ellipse.

GetMinMax(double, double)

Gets the minimum and maximum from the specified numbers.

public static (double min, double max) GetMinMax(double a, double b)

Parameters

a double

The first number.

b double

The second number.

Returns

(double min, double max)

A tuple containing the minimum and maximum of the two specified numbers.

GetMinMaxFromDelta(double, double)

Gets the minimum and maximum from the specified number and the difference with that number.

public static (double min, double max) GetMinMaxFromDelta(double initialValue, double delta)

Parameters

initialValue double

The initial value to use.

delta double

The difference for initialValue.

Returns

(double min, double max)

A tuple containing the minimum and maximum of the specified number and the difference with that number.

Grad2Rad(double)

Converts an angle in gradians to radians.

public static double Grad2Rad(double angle)

Parameters

angle double

The angle in gradians.

Returns

double

The angle in radians.

GreaterThan(double, double)

GreaterThan - Returns whether or not the first double is greater than the second double. That is, whether or not the first is strictly greater than and not within epsilon of the other number.

public static bool GreaterThan(double value1, double value2)

Parameters

value1 double

The first double to compare.

value2 double

The second double to compare.

Returns

bool

GreaterThan(float, float)

GreaterThan - Returns whether or not the first float is greater than the second float. That is, whether or not the first is strictly greater than and not within epsilon of the other number.

public static bool GreaterThan(float value1, float value2)

Parameters

value1 float

The first float to compare.

value2 float

The second float to compare.

Returns

bool

GreaterThanOrClose(double, double)

GreaterThanOrClose - Returns whether or not the first double is greater than or close to the second double. That is, whether or not the first is strictly greater than or within epsilon of the other number.

public static bool GreaterThanOrClose(double value1, double value2)

Parameters

value1 double

The first double to compare.

value2 double

The second double to compare.

Returns

bool

GreaterThanOrClose(float, float)

GreaterThanOrClose - Returns whether or not the first float is greater than or close to the second float. That is, whether or not the first is strictly greater than or within epsilon of the other number.

public static bool GreaterThanOrClose(float value1, float value2)

Parameters

value1 float

The first float to compare.

value2 float

The second float to compare.

Returns

bool

IsOne(double)

IsOne - Returns whether or not the double is "close" to 1. Same as AreClose(double, 1), but this is faster.

public static bool IsOne(double value)

Parameters

value double

The double to compare to 1.

Returns

bool

IsOne(float)

IsOne - Returns whether or not the float is "close" to 1. Same as AreClose(float, 1), but this is faster.

public static bool IsOne(float value)

Parameters

value float

The float to compare to 1.

Returns

bool

IsZero(double)

IsZero - Returns whether or not the double is "close" to 0. Same as AreClose(double, 0), but this is faster.

public static bool IsZero(double value)

Parameters

value double

The double to compare to 0.

Returns

bool

IsZero(float)

IsZero - Returns whether or not the float is "close" to 0. Same as AreClose(float, 0), but this is faster.

public static bool IsZero(float value)

Parameters

value float

The float to compare to 0.

Returns

bool

LessThan(double, double)

LessThan - Returns whether or not the first double is less than the second double. That is, whether or not the first is strictly less than and not within epsilon of the other number.

public static bool LessThan(double value1, double value2)

Parameters

value1 double

The first double to compare.

value2 double

The second double to compare.

Returns

bool

LessThan(float, float)

LessThan - Returns whether or not the first float is less than the second float. That is, whether or not the first is strictly less than and not within epsilon of the other number.

public static bool LessThan(float value1, float value2)

Parameters

value1 float

The first single float to compare.

value2 float

The second single float to compare.

Returns

bool

LessThanOrClose(double, double)

LessThanOrClose - Returns whether or not the first double is less than or close to the second double. That is, whether or not the first is strictly less than or within epsilon of the other number.

public static bool LessThanOrClose(double value1, double value2)

Parameters

value1 double

The first double to compare.

value2 double

The second double to compare.

Returns

bool

LessThanOrClose(float, float)

LessThanOrClose - Returns whether or not the first float is less than or close to the second float. That is, whether or not the first is strictly less than or within epsilon of the other number.

public static bool LessThanOrClose(float value1, float value2)

Parameters

value1 float

The first float to compare.

value2 float

The second float to compare.

Returns

bool

Turn2Rad(double)

Converts an angle in turns to radians.

public static double Turn2Rad(double angle)

Parameters

angle double

The angle in turns.

Returns

double

The angle in radians.