Class MathUtility
Math utilities.
Inherited Members
Namespace: Unity.XR.CoreUtils
Assembly: Unity.XR.CoreUtils.dll
Syntax
public static class MathUtility
Methods
Approximately(float, float)
A faster replacement for Approximately(float, float).
Declaration
public static bool Approximately(float a, float b)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The first float to compare. |
| float | b | The second float to compare. |
Returns
| Type | Description |
|---|---|
| bool |
Remarks
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.
ApproximatelyZero(float)
A slightly faster way to do Approximately(a, 0f).
Declaration
public static bool ApproximatelyZero(float a)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The floating point value to compare with 0. |
Returns
| Type | Description |
|---|---|
| bool |
Clamp(double, double, double)
Constrains 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(int)
Returns the index of the first true bit of a flag.
Declaration
public static int FirstActiveFlagIndex(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The flags value to check. |
Returns
| Type | Description |
|---|---|
| int | 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 |
|---|---|
| bool | True if the vector is aligned with any axis, otherwise false. |
IsPositivePowerOfTwo(int)
Checks if a value is a positive power of two.
Declaration
public static bool IsPositivePowerOfTwo(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is a positive power of two, false otherwise. |
IsUndefined(float)
Checks whether a value is undefined (PositiveInfinity, NegativeInfinity, or NaN).
Declaration
public static bool IsUndefined(this float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The float value. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is infinity or NaN (not a number), otherwise false. |
See Also
ShortestAngleDistance(double, double, double, double)
Finds the smallest angle between two angles.
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(float, float, float, float)
Finds the smallest angle between two angles.
Declaration
public static float ShortestAngleDistance(float start, float end, float halfMax, float max)
Parameters
| Type | Name | Description |
|---|---|---|
| float | start | The start value. |
| float | end | The end value. |
| float | halfMax | Half of the max angle. |
| float | max | The max angle value. |
Returns
| Type | Description |
|---|---|
| float | The angle distance between start and end. |