Photon Quantum 2.1.1

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 FP Acos (FP value)
 Returns the arc-cosine of value - the angle in radians whose cosine is value . 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 Asin (FP value)
 Returns the arc-sine of value - the angle in radians whose sine is value . More...
 
static FP Atan (FP value)
 Returns the arc-tangent of value - the angle in radians whose tangent is value . More...
 
static FP Atan2 (FP y, FP x)
 Returns the angle in radians whose Tan(FP) is y /x . This function returns correct angle even if x is zero. 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 Cos (FP rad)
 Returns the cosine of angle rad . More...
 
static FP CosHighPrecision (FP rad)
 Returns the high precision cosine of angle rad . More...
 
static FP Exp (FP x)
 Returns e raised to the specified power. The max relative error is ~0.3% in the range of [-6, 32]. More...
 
static FP Floor (FP value)
 Returns the largest integer smaller than or equal to value . More...
 
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 FP Ln (FP value)
 Returns natural logarithm of value . More...
 
static FP Log (FP value, FP logBase)
 Returns logarithm of value in base logBase . It is much more performant and precise to use Log2, Log10 and Ln if logBase is 2, 10 or e. More...
 
static FP Log10 (FP value)
 Returns logarithm of value in base 10. More...
 
static FP Log2 (FP value)
 Returns logarithm of value in base 2. 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 val1, FP val2)
 Returns the largest of two or more values. More...
 
static FP Max (params FP[] numbers)
 Returns the largest of two or more values. More...
 
static FP Min (FP val1, FP val2)
 Returns the smallest of two or more 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 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 Sin (FP rad)
 Returns the sine of angle rad . More...
 
static void SinCos (FP rad, out FP sin, out FP cos)
 Calculates sine and cosine of angle rad . It is faster than calling Sin(FP) and Cos(FP) separately. More...
 
static void SinCosHighPrecision (FP rad, out FP sin, out FP cos)
 Calculates high precision sine and cosine of angle rad . It is faster than calling SinHighPrecision(FP) and CosHighPrecision(FP) separately. More...
 
static FP SinHighPrecision (FP rad)
 Returns the high precision sine of angle rad . 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 FP Sqrt (FP value)
 Returns square root of value . More...
 
static FP Tan (FP rad)
 Returns the tangent of angle rad . 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()

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/2]

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/2]

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/2]

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

Returns the smallest of two or more values.

Parameters
numbers
Returns

◆ Max() [2/2]

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

◆ 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

◆ 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

◆ Sqrt()

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

Returns square root of value .

FPLut needs to be initialised.

Parameters
value
Returns
Exceptions
System.ArgumentOutOfRangeExceptionThrown when value is less than 0

◆ 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)

FPLut needs to be initialised.

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)

FPLut needs to be initialised.

Parameters
value
Returns

◆ Log2()

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

Returns logarithm of value in base 2.

FPLut needs to be initialised.

Parameters
value
Returns

◆ Ln()

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

Returns natural logarithm of value .

FPLut needs to be initialised.

Parameters
value
Returns

◆ Log10()

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

Returns logarithm of value in base 10.

FPLut needs to be initialised.

Parameters
value
Returns

◆ Log()

static FP Photon.Deterministic.FPMath.Log ( FP  value,
FP  logBase 
)
inlinestatic

Returns logarithm of value in base logBase . It is much more performant and precise to use Log2, Log10 and Ln if logBase is 2, 10 or e.

FPLut needs to be initialised.

Parameters
value
logBase
Returns

◆ Exp()

static FP Photon.Deterministic.FPMath.Exp ( FP  x)
inlinestatic

Returns e raised to the specified power. The max relative error is ~0.3% in the range of [-6, 32].

Parameters
x
Returns

◆ Sin()

static FP Photon.Deterministic.FPMath.Sin ( FP  rad)
inlinestatic

Returns the sine of angle rad .

FPLut needs to be initialised.

Parameters
radAngle in radians
Returns

◆ SinHighPrecision()

static FP Photon.Deterministic.FPMath.SinHighPrecision ( FP  rad)
inlinestatic

Returns the high precision sine of angle rad .

FPLut needs to be initialised.

Parameters
radAngle in radians
Returns

◆ Cos()

static FP Photon.Deterministic.FPMath.Cos ( FP  rad)
inlinestatic

Returns the cosine of angle rad .

FPLut needs to be initialised.

Parameters
radAngle in radians
Returns

◆ CosHighPrecision()

static FP Photon.Deterministic.FPMath.CosHighPrecision ( FP  rad)
inlinestatic

Returns the high precision cosine of angle rad .

FPLut needs to be initialised.

Parameters
radAngle in radians
Returns

◆ SinCos()

static void Photon.Deterministic.FPMath.SinCos ( FP  rad,
out FP  sin,
out FP  cos 
)
inlinestatic

Calculates sine and cosine of angle rad . It is faster than calling Sin(FP) and Cos(FP) separately.

FPLut needs to be initialised.

Parameters
radAngle in radians
sin
cos

◆ SinCosHighPrecision()

static void Photon.Deterministic.FPMath.SinCosHighPrecision ( FP  rad,
out FP  sin,
out FP  cos 
)
inlinestatic

Calculates high precision sine and cosine of angle rad . It is faster than calling SinHighPrecision(FP) and CosHighPrecision(FP) separately.

FPLut needs to be initialised.

Parameters
radAngle in radians
sin
cos

◆ Tan()

static FP Photon.Deterministic.FPMath.Tan ( FP  rad)
inlinestatic

Returns the tangent of angle rad .

FPLut needs to be initialised.

Parameters
radAngle in radians
Returns

◆ Asin()

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

Returns the arc-sine of value - the angle in radians whose sine is value .

FPLut needs to be initialised.

Parameters
value
Returns

◆ Acos()

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

Returns the arc-cosine of value - the angle in radians whose cosine is value .

FPLut needs to be initialised.

Parameters
value
Returns

◆ Atan()

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

Returns the arc-tangent of value - the angle in radians whose tangent is value .

FPLut needs to be initialised.

Parameters
value
Returns

◆ Atan2()

static FP Photon.Deterministic.FPMath.Atan2 ( FP  y,
FP  x 
)
inlinestatic

Returns the angle in radians whose Tan(FP) is y /x . This function returns correct angle even if x is zero.

FPLut needs to be initialised.

Parameters
y
x
Returns