Class MathUtility
Math utilities
Namespace: Unity.XR.CoreUtils
Syntax
public static class MathUtility
Methods
Approximately(Single, Single)
A faster drop-in replacement for Mathf.Approximately(a, b). Compares two floating point values and returns true if they are similar. As an optimization, this method does not take into account the magnitude of the values it is comparing. This method may not provide the same results as Mathf.Approximately for extremely large values
Declaration
public static bool Approximately(float a, float b)
Parameters
Type | Name | Description |
---|---|---|
Single | a | The first float being compared |
Single | b | The second float being compared |
Returns
Type | Description |
---|---|
Boolean |
ApproximatelyZero(Single)
A slightly faster way to do Approximately(a, 0f).
Declaration
public static bool ApproximatelyZero(float a)
Parameters
Type | Name | Description |
---|---|---|
Single | a | The floating point value to compare with 0 |
Returns
Type | Description |
---|---|
Boolean |
Clamp(Double, Double, Double)
Constrain a value between a minimum and a maximum
Declaration
public static double Clamp(double input, double min, double max)
Parameters
Type | Name | Description |
---|---|---|
Double | input | The input number |
Double | min | The minimum output |
Double | max | The maximum output |
Returns
Type | Description |
---|---|
Double | The |
FirstActiveFlagIndex(Int32)
Return the index of the first flag bit set to true
Declaration
public static int FirstActiveFlagIndex(int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The flags value to check |
Returns
Type | Description |
---|---|
Int32 | The index of the first active flag |
IsAxisAligned(Vector3)
Checks if a vector is aligned with one of the axis vectors
Declaration
public static bool IsAxisAligned(this Vector3 v)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | v | The vector |
Returns
Type | Description |
---|---|
Boolean | True if the vector is aligned with any axis, otherwise false |
IsPositivePowerOfTwo(Int32)
Check if a value is a positive power of two
Declaration
public static bool IsPositivePowerOfTwo(int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The value to check |
Returns
Type | Description |
---|---|
Boolean | True if the value is a positive power of two, false otherwise |
IsUndefined(Single)
Is the float value infinity or NaN?
Declaration
public static bool IsUndefined(this float value)
Parameters
Type | Name | Description |
---|---|---|
Single | value | The float value |
Returns
Type | Description |
---|---|
Boolean | True if the value is infinity or NaN (not a number), otherwise false |
ShortestAngleDistance(Double, Double, Double, Double)
Finds the shortest angle distance between two angle values
Declaration
public static double ShortestAngleDistance(double start, double end, double halfMax, double max)
Parameters
Type | Name | Description |
---|---|---|
Double | start | The start value |
Double | end | The end value |
Double | halfMax | Half of the max angle |
Double | max | The max angle value |
Returns
Type | Description |
---|---|
Double | The angle distance between start and end |
ShortestAngleDistance(Single, Single, Single, Single)
Finds the shortest angle distance between two angle values
Declaration
public static float ShortestAngleDistance(float start, float end, float halfMax, float max)
Parameters
Type | Name | Description |
---|---|---|
Single | start | The start value |
Single | end | The end value |
Single | halfMax | Half of the max angle |
Single | max | The max angle value |
Returns
Type | Description |
---|---|
Single | The angle distance between start and end |