Quantum 3 3.1.0

Static Public Member Functions | List of all members
Photon.Deterministic.FPMath Struct Reference

A collection of common math functions. More...

Static Public Member Functions

static FP Abs (FP value)
 Returns the absolute value of the argument. More...
 
static Int32 Abs (Int32 value)
 Returns the absolute value of the argument. More...
 
static Int64 Abs (Int64 value)
 Returns the absolute value of the argument. More...
 
static FP AngleBetweenDegrees (FP source, FP target)
 Calculates the smallest signed angle between any two angles. F.e. angle between -179 and 179 is -2. Rotation is ccw. More...
 
static Int64 AngleBetweenDegreesRaw (Int64 source, Int64 target)
 Same as AngleBetweenDegrees using Raw optimization. More...
 
static FP AngleBetweenRadians (FP source, FP target)
 Calculates the smallest signed angle between any two angles. More...
 
static Int64 AngleBetweenRadiansRaw (Int64 source, Int64 target)
 Same as AngleBetweenDegrees using Raw optimization. More...
 
static FP Barycentric (FP value1, FP value2, FP value3, FP t1, FP t2)
 Performs barycentric interpolation. More...
 
static FP CatmullRom (FP value1, FP value2, FP value3, FP value4, FP t)
 Performs Cotmull-Rom interpolation. More...
 
static FP Ceiling (FP value)
 Returns the smallest integer larger than or equal to value . More...
 
static Int32 CeilToInt (FP value)
 Returns the smallest integer larger than or equal to value . More...
 
static FP Clamp (FP value, FP min, FP max)
 Clamps the given value between the given minimum and maximum values. More...
 
static Int32 Clamp (Int32 value, Int32 min, Int32 max)
 Clamps the given value between the given minimum and maximum values. More...
 
static Int64 Clamp (Int64 value, Int64 min, Int64 max)
 Clamps the given value between the given minimum and maximum values. More...
 
static FP Clamp01 (FP value)
 Clamps the given value between 0 and 1. More...
 
static FP ClampUseable (FP value)
 Clamps the given value between FP.UseableMin and FP.UseableMax. More...
 
static FP Floor (FP value)
 Returns the largest integer smaller than or equal to value . More...
 
static Int64 FloorRaw (Int64 value)
 
static Int32 FloorToInt (FP value)
 Returns the largest integer smaller than or equal to value . More...
 
static FP Fraction (FP value)
 Returns the fractional part of the argument. More...
 
static FP Hermite (FP value1, FP tangent1, FP value2, FP tangent2, FP t)
 Performs cubic Hermite interpolation. More...
 
static FP InverseLerp (FP start, FP end, FP value)
 Calculates the linear parameter that produces the interpolant value within the range [start , end ]. The result is clamped to the range [0, 1]. More...
 
static FP InverseLerpUnclamped (FP start, FP end, FP value)
 Calculates the linear parameter that produces the interpolant value within the range [start , end ]. More...
 
static FP Lerp (FP start, FP end, FP t)
 Linearly interpolates between start and end by t . t is clamped to the range [0, 1] More...
 
static FP LerpRadians (FP start, FP end, FP t)
 Linearly interpolates between start and end by t . t is clamped to the range [0, 1]. The difference between start and end is converted to a [-Pi/2, Pi/2] range. More...
 
static FP LerpUnclamped (FP start, FP end, FP t)
 Linearly interpolates between start and end by t . More...
 
static Int32 Log2CeilingToInt (FP value)
 Returns celining of the logarithm of value in base 2. It is much faster than calling FPMath.Log2(FP) and then FPMath.CeilToInt(FP) More...
 
static Int32 Log2FloorToInt (FP value)
 Returns floor of the logarithm of value in base 2. It is much faster than calling FPMath.Log2(FP) and then FPMath.FloorToInt(FP) More...
 
static FP Max (FP a, FP b, FP c)
 Returns the maximum of three values. More...
 
static FP Max (FP val1, FP val2)
 Returns the largest of two or more values. More...
 
static Int32 Max (Int32 a, Int32 b)
 Returns the larger of two values. More...
 
static Int64 Max (Int64 a, Int64 b)
 Returns the larger of two values. More...
 
static FP Max (params FP[] numbers)
 Returns the largest of two or more values. More...
 
static FP Min (FP a, FP b, FP c)
 Returns the minimum of three values. More...
 
static FP Min (FP val1, FP val2)
 Returns the smallest of two or more values. More...
 
static Int32 Min (Int32 a, Int32 b)
 Returns the smaller of two values. More...
 
static Int64 Min (Int64 a, Int64 b)
 Returns the smaller of two values. More...
 
static FP Min (params FP[] numbers)
 Returns the smallest of two or more values. More...
 
static void MinMax (FP a, FP b, out FP min, out FP max)
 
static FP ModuloClamped (FP a, FP n)
 Performs modulo operation without forcing the sign of the dividend: So that ModuloClamped(-9, 10) = 1. More...
 
static Int64 ModuloClamped (Int64 a, Int64 n)
 Performs modulo operation without forcing the sign of the dividend: So that ModuloClamped(-9, 10) = 1. More...
 
static FP MoveTowards (FP from, FP to, FP maxDelta)
 Moves a value from towards to by a value no greater than maxDelta . Negative values of maxDelta push the value away from to . More...
 
static Int32 NextPowerOfTwo (Int32 value)
 Returns the next power of two that is equal to, or greater than, the argument. More...
 
static FP Repeat (FP t, FP length)
 Loops the value t , so that it is never larger than length and never smaller than 0. More...
 
static FP Round (FP value)
 Returns value rounded to the nearest integer. More...
 
static Int32 RoundToInt (FP value)
 Returns value rounded to the nearest integer. More...
 
static FP Sign (FP value)
 Returns the sign of value . More...
 
static Int32 SignInt (FP value)
 Returns the sign of value . More...
 
static FP SignZero (FP value)
 Returns the sign of value if it is non-zero. More...
 
static Int32 SignZeroInt (FP value)
 Returns the sign of value if it is non-zero. More...
 
static FP SmoothStep (FP start, FP end, FP t)
 Interpolates between start and end with smoothing at the limits. Equivalent of calling Hermite(FP, FP, FP, FP, FP) with tangents set to 0 and clamping t between 0 and 1. More...
 
static unsafe void Sort< T > (Span< T > span, int lo, int hi, delegate *< T *, T *, int > comparer)
 Sorts elements in a buffer using an introsort algorithm with guaranteed O(n log n) worst-case time complexity. The sort is unstable and deterministic. More...
 
static unsafe void Sort< T > (T *buffer, int lo, int hi, delegate *< T *, T *, int > comparer)
 Sorts elements in a buffer using an introsort algorithm with guaranteed O(n log n) worst-case time complexity. The sort is unstable and deterministic. More...
 
static unsafe void Sort< T, TField > (Span< T > span, int lo, int hi, int fieldOffset)
 Sorts elements in a buffer using an introsort algorithm with guaranteed O(n log n) worst-case time complexity. The sort is unstable and deterministic. More...
 
static unsafe void Sort< T, TField > (T *buffer, int lo, int hi, int fieldOffset)
 Sorts elements in a buffer using an introsort algorithm with guaranteed O(n log n) worst-case time complexity. The sort is unstable and deterministic. More...
 

Detailed Description

A collection of common math functions.

Member Function Documentation

◆ Sign()

static FP Photon.Deterministic.FPMath.Sign ( FP  value)
inlinestatic

Returns the sign of value .

Parameters
value
Returns
1 when positive or zero, -1 when negative

◆ SignZero()

static FP Photon.Deterministic.FPMath.SignZero ( FP  value)
inlinestatic

Returns the sign of value if it is non-zero.

Parameters
value
Returns
1 when positive, 0 when zero, -1 when negative

◆ SignInt()

static Int32 Photon.Deterministic.FPMath.SignInt ( FP  value)
inlinestatic

Returns the sign of value .

Parameters
value
Returns
1 when positive or zero, -1 when negative

◆ SignZeroInt()

static Int32 Photon.Deterministic.FPMath.SignZeroInt ( FP  value)
inlinestatic

Returns the sign of value if it is non-zero.

Parameters
value
Returns
1 when positive, 0 when zero, -1 when negative

◆ NextPowerOfTwo()

static Int32 Photon.Deterministic.FPMath.NextPowerOfTwo ( Int32  value)
inlinestatic

Returns the next power of two that is equal to, or greater than, the argument.

Parameters
value
Returns

◆ Abs() [1/3]

static FP Photon.Deterministic.FPMath.Abs ( FP  value)
inlinestatic

Returns the absolute value of the argument.

Parameters
value
Returns

◆ Round()

static FP Photon.Deterministic.FPMath.Round ( FP  value)
inlinestatic

Returns value rounded to the nearest integer.

Parameters
value
Returns

◆ RoundToInt()

static Int32 Photon.Deterministic.FPMath.RoundToInt ( FP  value)
inlinestatic

Returns value rounded to the nearest integer.

Parameters
value
Returns

◆ Floor()

static FP Photon.Deterministic.FPMath.Floor ( FP  value)
inlinestatic

Returns the largest integer smaller than or equal to value .

Parameters
value
Returns

◆ FloorToInt()

static Int32 Photon.Deterministic.FPMath.FloorToInt ( FP  value)
inlinestatic

Returns the largest integer smaller than or equal to value .

Parameters
value
Returns

◆ Ceiling()

static FP Photon.Deterministic.FPMath.Ceiling ( FP  value)
inlinestatic

Returns the smallest integer larger than or equal to value .

Parameters
value
Returns

◆ CeilToInt()

static Int32 Photon.Deterministic.FPMath.CeilToInt ( FP  value)
inlinestatic

Returns the smallest integer larger than or equal to value .

Parameters
value
Returns

◆ Max() [1/5]

static FP Photon.Deterministic.FPMath.Max ( FP  val1,
FP  val2 
)
inlinestatic

Returns the largest of two or more values.

Parameters
val1
val2
Returns

◆ Min() [1/5]

static FP Photon.Deterministic.FPMath.Min ( FP  val1,
FP  val2 
)
inlinestatic

Returns the smallest of two or more values.

Parameters
val1
val2
Returns

◆ Min() [2/5]

static FP Photon.Deterministic.FPMath.Min ( params FP[]  numbers)
inlinestatic

Returns the smallest of two or more values.

Parameters
numbers
Returns

◆ Min() [3/5]

static FP Photon.Deterministic.FPMath.Min ( FP  a,
FP  b,
FP  c 
)
inlinestatic

Returns the minimum of three values.

Parameters
a
b
c

◆ Max() [2/5]

static FP Photon.Deterministic.FPMath.Max ( FP  a,
FP  b,
FP  c 
)
inlinestatic

Returns the maximum of three values.

Parameters
a
b
c
Returns

◆ Max() [3/5]

static FP Photon.Deterministic.FPMath.Max ( params FP[]  numbers)
inlinestatic

Returns the largest of two or more values.

Parameters
numbers
Returns

◆ MinMax()

static void Photon.Deterministic.FPMath.MinMax ( FP  a,
FP  b,
out FP  min,
out FP  max 
)
inlinestatic

Parameters
a
b
min
max

◆ Clamp() [1/3]

static FP Photon.Deterministic.FPMath.Clamp ( FP  value,
FP  min,
FP  max 
)
inlinestatic

Clamps the given value between the given minimum and maximum values.

Parameters
value
min
max
Returns

◆ Clamp01()

static FP Photon.Deterministic.FPMath.Clamp01 ( FP  value)
inlinestatic

Clamps the given value between 0 and 1.

Parameters
value
Returns

◆ Clamp() [2/3]

static Int32 Photon.Deterministic.FPMath.Clamp ( Int32  value,
Int32  min,
Int32  max 
)
inlinestatic

Clamps the given value between the given minimum and maximum values.

Parameters
value
min
max
Returns

◆ Clamp() [3/3]

static Int64 Photon.Deterministic.FPMath.Clamp ( Int64  value,
Int64  min,
Int64  max 
)
inlinestatic

Clamps the given value between the given minimum and maximum values.

Parameters
value
min
max
Returns

◆ Abs() [2/3]

static Int32 Photon.Deterministic.FPMath.Abs ( Int32  value)
inlinestatic

Returns the absolute value of the argument.

◆ Abs() [3/3]

static Int64 Photon.Deterministic.FPMath.Abs ( Int64  value)
inlinestatic

Returns the absolute value of the argument.

◆ Min() [4/5]

static Int32 Photon.Deterministic.FPMath.Min ( Int32  a,
Int32  b 
)
inlinestatic

Returns the smaller of two values.

◆ Min() [5/5]

static Int64 Photon.Deterministic.FPMath.Min ( Int64  a,
Int64  b 
)
inlinestatic

Returns the smaller of two values.

◆ Max() [4/5]

static Int32 Photon.Deterministic.FPMath.Max ( Int32  a,
Int32  b 
)
inlinestatic

Returns the larger of two values.

◆ Max() [5/5]

static Int64 Photon.Deterministic.FPMath.Max ( Int64  a,
Int64  b 
)
inlinestatic

Returns the larger of two values.

◆ ClampUseable()

static FP Photon.Deterministic.FPMath.ClampUseable ( FP  value)
inlinestatic

Clamps the given value between FP.UseableMin and FP.UseableMax.

Parameters
value
Returns

◆ Fraction()

static FP Photon.Deterministic.FPMath.Fraction ( FP  value)
inlinestatic

Returns the fractional part of the argument.

Parameters
value
Returns

◆ Repeat()

static FP Photon.Deterministic.FPMath.Repeat ( FP  t,
FP  length 
)
inlinestatic

Loops the value t , so that it is never larger than length and never smaller than 0.

Parameters
t
length
Returns

◆ LerpRadians()

static FP Photon.Deterministic.FPMath.LerpRadians ( FP  start,
FP  end,
FP  t 
)
inlinestatic

Linearly interpolates between start and end by t . t is clamped to the range [0, 1]. The difference between start and end is converted to a [-Pi/2, Pi/2] range.

Parameters
start
end
t
Returns

◆ Lerp()

static FP Photon.Deterministic.FPMath.Lerp ( FP  start,
FP  end,
FP  t 
)
inlinestatic

Linearly interpolates between start and end by t . t is clamped to the range [0, 1]

Parameters
start
end
t
Returns

◆ LerpUnclamped()

static FP Photon.Deterministic.FPMath.LerpUnclamped ( FP  start,
FP  end,
FP  t 
)
inlinestatic

Linearly interpolates between start and end by t .

Parameters
start
end
t
Returns

◆ InverseLerp()

static FP Photon.Deterministic.FPMath.InverseLerp ( FP  start,
FP  end,
FP  value 
)
inlinestatic

Calculates the linear parameter that produces the interpolant value within the range [start , end ]. The result is clamped to the range [0, 1].

Returns 0 if start and end are equal.

Parameters
start
end
value
Returns

◆ InverseLerpUnclamped()

static FP Photon.Deterministic.FPMath.InverseLerpUnclamped ( FP  start,
FP  end,
FP  value 
)
inlinestatic

Calculates the linear parameter that produces the interpolant value within the range [start , end ].

The resultant factor is NOT clamped to the range [0, 1].

Returns 0 if start and end are equal.

Parameters
start
end
value
Returns

◆ MoveTowards()

static FP Photon.Deterministic.FPMath.MoveTowards ( FP  from,
FP  to,
FP  maxDelta 
)
inlinestatic

Moves a value from towards to by a value no greater than maxDelta . Negative values of maxDelta push the value away from to .

Parameters
from
to
maxDelta
Returns

◆ SmoothStep()

static FP Photon.Deterministic.FPMath.SmoothStep ( FP  start,
FP  end,
FP  t 
)
inlinestatic

Interpolates between start and end with smoothing at the limits. Equivalent of calling Hermite(FP, FP, FP, FP, FP) with tangents set to 0 and clamping t between 0 and 1.

Parameters
start
end
t
Returns

◆ Barycentric()

static FP Photon.Deterministic.FPMath.Barycentric ( FP  value1,
FP  value2,
FP  value3,
FP  t1,
FP  t2 
)
inlinestatic

Performs barycentric interpolation.

Parameters
value1
value2
value3
t1
t2
Returns
value1 + (value2 - value1 ) * t1 + (value3 - value1 ) * t2

◆ CatmullRom()

static FP Photon.Deterministic.FPMath.CatmullRom ( FP  value1,
FP  value2,
FP  value3,
FP  value4,
FP  t 
)
inlinestatic

Performs Cotmull-Rom interpolation.

Parameters
value1
value2
value3
value4
t
Returns

◆ Hermite()

static FP Photon.Deterministic.FPMath.Hermite ( FP  value1,
FP  tangent1,
FP  value2,
FP  tangent2,
FP  t 
)
inlinestatic

Performs cubic Hermite interpolation.

Parameters
value1
tangent1
value2
tangent2
t
Returns

◆ ModuloClamped() [1/2]

static Int64 Photon.Deterministic.FPMath.ModuloClamped ( Int64  a,
Int64  n 
)
inlinestatic

Performs modulo operation without forcing the sign of the dividend: So that ModuloClamped(-9, 10) = 1.

Parameters
aDividend
nDivisor
Returns
Remainder after division
Exceptions
System.InvalidOperationExceptionWhen n > Int64.MaxValue >> 2 or n < Int64.MinValue >> 2
System.DivideByZeroExceptionWhen n == 0

◆ ModuloClamped() [2/2]

static FP Photon.Deterministic.FPMath.ModuloClamped ( FP  a,
FP  n 
)
inlinestatic

Performs modulo operation without forcing the sign of the dividend: So that ModuloClamped(-9, 10) = 1.

Parameters
aDividend
nDivisor
Returns
Remainder after division
Exceptions
System.InvalidOperationExceptionWhen n > FP.UseableMax or n < FP.UseableMin
System.DivideByZeroExceptionWhen n == 0

◆ AngleBetweenDegrees()

static FP Photon.Deterministic.FPMath.AngleBetweenDegrees ( FP  source,
FP  target 
)
inlinestatic

Calculates the smallest signed angle between any two angles. F.e. angle between -179 and 179 is -2. Rotation is ccw.

Parameters
sourceSource angle in degrees
targetTarget angle in degrees
Returns

◆ AngleBetweenDegreesRaw()

static Int64 Photon.Deterministic.FPMath.AngleBetweenDegreesRaw ( Int64  source,
Int64  target 
)
inlinestatic

Same as AngleBetweenDegrees using Raw optimization.

Parameters
sourceSource angle in degrees (Raw)
targetTarget angle in degrees (Raw)
Returns

◆ AngleBetweenRadians()

static FP Photon.Deterministic.FPMath.AngleBetweenRadians ( FP  source,
FP  target 
)
inlinestatic

Calculates the smallest signed angle between any two angles.

Parameters
sourceSource angle in radians
targetTarget angle in radians
Returns

◆ AngleBetweenRadiansRaw()

static Int64 Photon.Deterministic.FPMath.AngleBetweenRadiansRaw ( Int64  source,
Int64  target 
)
inlinestatic

Same as AngleBetweenDegrees using Raw optimization.

Parameters
sourceSource angle in radians (Raw)
targetTarget angle in radians (Raw)
Returns

◆ Log2FloorToInt()

static Int32 Photon.Deterministic.FPMath.Log2FloorToInt ( FP  value)
inlinestatic

Returns floor of the logarithm of value in base 2. It is much faster than calling FPMath.Log2(FP) and then FPMath.FloorToInt(FP)

Parameters
value
Returns

◆ Log2CeilingToInt()

static Int32 Photon.Deterministic.FPMath.Log2CeilingToInt ( FP  value)
inlinestatic

Returns celining of the logarithm of value in base 2. It is much faster than calling FPMath.Log2(FP) and then FPMath.CeilToInt(FP)

Parameters
value
Returns

◆ Sort< T >() [1/2]

static unsafe void Photon.Deterministic.FPMath.Sort< T > ( Span< T >  span,
int  lo,
int  hi,
delegate *< T *, T *, int >  comparer 
)
inlinestatic

Sorts elements in a buffer using an introsort algorithm with guaranteed O(n log n) worst-case time complexity. The sort is unstable and deterministic.

Parameters
spanSpan to sort.
loInclusive lower bound index.
hiInclusive upper bound index.
comparerFunction pointer returning negative if *a < *b, positive if *a > *b, zero if equal.
Type Constraints
T :unmanaged 

◆ Sort< T >() [2/2]

static unsafe void Photon.Deterministic.FPMath.Sort< T > ( T *  buffer,
int  lo,
int  hi,
delegate *< T *, T *, int >  comparer 
)
inlinestatic

Sorts elements in a buffer using an introsort algorithm with guaranteed O(n log n) worst-case time complexity. The sort is unstable and deterministic.

Parameters
bufferPointer to the first element of the buffer to sort.
loInclusive lower bound index.
hiInclusive upper bound index.
comparerFunction pointer returning negative if *a < *b, positive if *a > *b, zero if equal.
Type Constraints
T :unmanaged 

◆ Sort< T, TField >() [1/2]

static unsafe void Photon.Deterministic.FPMath.Sort< T, TField > ( Span< T >  span,
int  lo,
int  hi,
int  fieldOffset 
)
inlinestatic

Sorts elements in a buffer using an introsort algorithm with guaranteed O(n log n) worst-case time complexity. The sort is unstable and deterministic.

Parameters
spanSpan to sort.
loInclusive lower bound index.
hiInclusive upper bound index.
fieldOffsetOffset of the comparable field that will be used for sorting.
Template Parameters
TType of the elements in buffer to sort.
TFieldType of the field in each element that will be used for comparison when sorting.
Type Constraints
T :unmanaged 
TField :unmanaged 
TField :IComparable<TField> 

◆ Sort< T, TField >() [2/2]

static unsafe void Photon.Deterministic.FPMath.Sort< T, TField > ( T *  buffer,
int  lo,
int  hi,
int  fieldOffset 
)
inlinestatic

Sorts elements in a buffer using an introsort algorithm with guaranteed O(n log n) worst-case time complexity. The sort is unstable and deterministic.

Parameters
bufferPointer to the first element of the buffer to sort.
loInclusive lower bound index.
hiInclusive upper bound index.
fieldOffsetOffset of the comparable field that will be used for sorting.
Template Parameters
TType of the elements in buffer to sort.
TFieldType of the field in each element that will be used for comparison when sorting.
Type Constraints
T :unmanaged 
TField :unmanaged 
TField :IComparable<TField>