Photon Fusion 2.0.3

Classes | Static Public Member Functions | List of all members
Maths Class Reference

Math utility methods. More...

Classes

struct  FastAbs
 Represents a structure that allows quick setting of the sign bit of floats using field offsets. More...
 

Static Public Member Functions

static int BitScanReverse (int v)
 Finds the index of the most significant set bit (1-bit) in a 32-bit integer. More...
 
static int BitScanReverse (long v)
 Finds the index of the most significant set bit (1-bit) in a 64-bit integer. More...
 
static int BitScanReverse (uint v)
 Finds the index of the most significant set bit (1-bit) in a 32-bit unsigned integer. More...
 
static int BitScanReverse (ulong v)
 Finds the index of the most significant set bit (1-bit) in a 64-bit unsigned integer. More...
 
static int BitsRequiredForNumber (int n)
 Determines the number of bits required to represent the specified integer. More...
 
static int BitsRequiredForNumber (uint n)
 Determines the number of bits required to represent a uint value. More...
 
static int BytesRequiredForBits (int b)
 Calculates the number of bytes required to store the specified number of bits. More...
 
static short BytesRequiredForBits (short b)
 Calculates the number of bytes required to store the specified number of bits. More...
 
static int CeilToInt (double value)
 Rounds a double value up to the nearest integer. More...
 
static double Clamp (double v, double min, double max)
 Clamps a double value to the specified range. More...
 
static float Clamp (float v, float min, float max)
 Clamps a float value to the specified range. More...
 
static int Clamp (int v, int min, int max)
 Clamps an integer value to the specified range. More...
 
static uint Clamp (uint v, uint min, uint max)
 Clamps an unsigned integer value to the specified range. More...
 
static double Clamp01 (double v)
 Clamps a double value to the range [0, 1]. More...
 
static float Clamp01 (float v)
 Clamps a float value to the range [0, 1]. More...
 
static byte ClampToByte (int v)
 Clamps an integer value to the range [0, 255] and returns it as a byte. More...
 
static double CosineInterpolate (double a, double b, double t)
 Performs cosine interpolation between two values. More...
 
static int CountSetBits (ulong x)
 Counts the number of bits set to 1 in a ulong value. More...
 
static int CountUsedBitsMinOne (uint value)
 Counts the number of bits set to 1 in a uint value, minus one. More...
 
static int FloorToInt (double value)
 Rounds a double value down to the nearest integer. More...
 
static int IntsRequiredForBits (int b)
 Calculates the number of integers required to store the specified number of bits. More...
 
static double Lerp (double a, double b, double t)
 Linearly interpolates between two double values. More...
 
static float Lerp (float a, float b, float t)
 Linearly interpolates between two float values. More...
 
static double MicrosecondsToSeconds (long microseconds)
 Converts microseconds to seconds. More...
 
static long MillisecondsToMicroseconds (long milliseconds)
 Converts milliseconds to microseconds. More...
 
static double MillisecondsToSeconds (double seconds)
 Converts milliseconds to seconds. More...
 
static uint Min (uint v, uint max)
 Returns the minimum of two unsigned integer values. More...
 
static uint NextPowerOfTwo (uint v)
 Calculates the next power of two greater than or equal to a given uint value. More...
 
static unsafe string PrintBits (byte *data, int count)
 Converts a byte array to a string representation of its bits. More...
 
static uint QuaternionCompress (Quaternion rot)
 Primary Compression Method. Converts a quaternion into a ulong buffer. Depending on size most of the top bits will be 0. More...
 
static Quaternion QuaternionDecompress (uint buffer)
 Primary Decompression Method. Decompress the 3 channels and missing channel ID from the serialized ULong buffer. More...
 
static long SecondsToMicroseconds (double seconds)
 Converts seconds to microseconds. More...
 
static long SecondsToMilliseconds (double seconds)
 Converts seconds to milliseconds. More...
 
static unsafe int SizeOfBits< T > ()
 Returns the size of the specified unmanaged type in bits. More...
 
static int ZigZagDecode (int i)
 Decodes a ZigZag encoded integer. More...
 
static long ZigZagDecode (long i)
 Decodes a ZigZag encoded long integer. More...
 
static int ZigZagEncode (int i)
 Encodes an integer using ZigZag encoding. More...
 
static long ZigZagEncode (long i)
 Encodes a long integer using ZigZag encoding. More...
 

Detailed Description

Math utility methods.

Member Function Documentation

◆ BitScanReverse() [1/4]

static int BitScanReverse ( int  v)
static

Finds the index of the most significant set bit (1-bit) in a 32-bit integer.

Parameters
vThe 32-bit integer to scan.
Returns
The index of the most significant set bit.

◆ BitScanReverse() [2/4]

static int BitScanReverse ( long  v)
static

Finds the index of the most significant set bit (1-bit) in a 64-bit integer.

Parameters
vThe 64-bit integer to scan.
Returns
The index of the most significant set bit.

◆ BitScanReverse() [3/4]

static int BitScanReverse ( uint  v)
static

Finds the index of the most significant set bit (1-bit) in a 32-bit unsigned integer.

Parameters
vThe 32-bit unsigned integer to scan.
Returns
The index of the most significant set bit.

◆ BitScanReverse() [4/4]

static int BitScanReverse ( ulong  v)
static

Finds the index of the most significant set bit (1-bit) in a 64-bit unsigned integer.

Parameters
vThe 64-bit unsigned integer to scan.
Returns
The index of the most significant set bit.

◆ BitsRequiredForNumber() [1/2]

static int BitsRequiredForNumber ( int  n)
static

Determines the number of bits required to represent the specified integer.

Parameters
nThe integer to evaluate.
Returns
The number of bits required to represent the integer.

◆ BitsRequiredForNumber() [2/2]

static int BitsRequiredForNumber ( uint  n)
static

Determines the number of bits required to represent a uint value.

Parameters
nThe uint value to evaluate.
Returns
The number of bits required to represent the value.

◆ BytesRequiredForBits() [1/2]

static int BytesRequiredForBits ( int  b)
static

Calculates the number of bytes required to store the specified number of bits.

Parameters
bThe number of bits.
Returns
The number of bytes required.

◆ BytesRequiredForBits() [2/2]

static short BytesRequiredForBits ( short  b)
static

Calculates the number of bytes required to store the specified number of bits.

Parameters
bThe number of bits.
Returns
The number of bytes required.

◆ CeilToInt()

static int CeilToInt ( double  value)
static

Rounds a double value up to the nearest integer.

Parameters
valueThe double value to round up.
Returns
The smallest integer greater than or equal to the specified value.

◆ Clamp() [1/4]

static double Clamp ( double  v,
double  min,
double  max 
)
static

Clamps a double value to the specified range.

Parameters
vThe value to clamp.
minThe minimum value of the range.
maxThe maximum value of the range.
Returns
The clamped value.

◆ Clamp() [2/4]

static float Clamp ( float  v,
float  min,
float  max 
)
static

Clamps a float value to the specified range.

Parameters
vThe value to clamp.
minThe minimum value of the range.
maxThe maximum value of the range.
Returns
The clamped value.

◆ Clamp() [3/4]

static int Clamp ( int  v,
int  min,
int  max 
)
static

Clamps an integer value to the specified range.

Parameters
vThe value to clamp.
minThe minimum value of the range.
maxThe maximum value of the range.
Returns
The clamped value.

◆ Clamp() [4/4]

static uint Clamp ( uint  v,
uint  min,
uint  max 
)
static

Clamps an unsigned integer value to the specified range.

Parameters
vThe value to clamp.
minThe minimum value of the range.
maxThe maximum value of the range.
Returns
The clamped value.

◆ Clamp01() [1/2]

static double Clamp01 ( double  v)
static

Clamps a double value to the range [0, 1].

Parameters
vThe value to clamp.
Returns
The clamped value.

◆ Clamp01() [2/2]

static float Clamp01 ( float  v)
static

Clamps a float value to the range [0, 1].

Parameters
vThe value to clamp.
Returns
The clamped value.

◆ ClampToByte()

static byte ClampToByte ( int  v)
static

Clamps an integer value to the range [0, 255] and returns it as a byte.

Parameters
vThe value to clamp.
Returns
The clamped value as a byte.

◆ CosineInterpolate()

static double CosineInterpolate ( double  a,
double  b,
double  t 
)
static

Performs cosine interpolation between two values.

Parameters
aThe start value.
bThe end value.
tThe interpolation factor, typically between 0 and 1.
Returns
The interpolated value.

◆ CountSetBits()

static int CountSetBits ( ulong  x)
static

Counts the number of bits set to 1 in a ulong value.

Parameters
xThe ulong value to count bits in.
Returns
The number of bits set to 1.

◆ CountUsedBitsMinOne()

static int CountUsedBitsMinOne ( uint  value)
static

Counts the number of bits set to 1 in a uint value, minus one.

Parameters
valueThe uint value to count bits in.
Returns
The number of bits set to 1, minus one.

◆ FloorToInt()

static int FloorToInt ( double  value)
static

Rounds a double value down to the nearest integer.

Parameters
valueThe double value to round down.
Returns
The largest integer less than or equal to the specified value.

◆ IntsRequiredForBits()

static int IntsRequiredForBits ( int  b)
static

Calculates the number of integers required to store the specified number of bits.

Parameters
bThe number of bits.
Returns
The number of integers required.

◆ Lerp() [1/2]

static double Lerp ( double  a,
double  b,
double  t 
)
static

Linearly interpolates between two double values.

Parameters
aThe start value.
bThe end value.
tThe interpolation factor, typically between 0 and 1.
Returns
The interpolated value.

◆ Lerp() [2/2]

static float Lerp ( float  a,
float  b,
float  t 
)
static

Linearly interpolates between two float values.

Parameters
aThe start value.
bThe end value.
tThe interpolation factor, typically between 0 and 1.
Returns
The interpolated value.

◆ MicrosecondsToSeconds()

static double MicrosecondsToSeconds ( long  microseconds)
static

Converts microseconds to seconds.

Parameters
microsecondsThe time in microseconds.
Returns
The time in seconds.

◆ MillisecondsToMicroseconds()

static long MillisecondsToMicroseconds ( long  milliseconds)
static

Converts milliseconds to microseconds.

Parameters
millisecondsThe time in milliseconds.
Returns
The time in microseconds.

◆ MillisecondsToSeconds()

static double MillisecondsToSeconds ( double  seconds)
static

Converts milliseconds to seconds.

Parameters
secondsThe time in milliseconds.
Returns
The time in seconds.

◆ Min()

static uint Min ( uint  v,
uint  max 
)
static

Returns the minimum of two unsigned integer values.

Parameters
vThe first value.
maxThe second value.
Returns
The minimum value.

◆ NextPowerOfTwo()

static uint NextPowerOfTwo ( uint  v)
static

Calculates the next power of two greater than or equal to a given uint value.

Parameters
vThe uint value to evaluate.
Returns
The next power of two greater than or equal to the value.

◆ PrintBits()

static unsafe string PrintBits ( byte *  data,
int  count 
)
static

Converts a byte array to a string representation of its bits.

Parameters
dataPointer to the byte array.
countThe number of bytes to convert.
Returns
A string representation of the bits.

◆ QuaternionCompress()

static uint QuaternionCompress ( Quaternion  rot)
static

Primary Compression Method. Converts a quaternion into a ulong buffer. Depending on size most of the top bits will be 0.

Parameters
rotThe quaternion to be compressed
Returns
A ulong buffer of the compressed quat.

◆ QuaternionDecompress()

static Quaternion QuaternionDecompress ( uint  buffer)
static

Primary Decompression Method. Decompress the 3 channels and missing channel ID from the serialized ULong buffer.

Parameters
bufferThe ulong that represents the compressed quaternion.
Returns
The restored Quaternion.

◆ SecondsToMicroseconds()

static long SecondsToMicroseconds ( double  seconds)
static

Converts seconds to microseconds.

Parameters
secondsThe time in seconds.
Returns
The time in microseconds.

◆ SecondsToMilliseconds()

static long SecondsToMilliseconds ( double  seconds)
static

Converts seconds to milliseconds.

Parameters
secondsThe time in seconds.
Returns
The time in milliseconds.

◆ SizeOfBits< T >()

static unsafe int SizeOfBits< T > ( )
static

Returns the size of the specified unmanaged type in bits.

Template Parameters
TThe unmanaged type.
Returns
The size of the type in bits.
Type Constraints
T :unmanaged 

◆ ZigZagDecode() [1/2]

static int ZigZagDecode ( int  i)
static

Decodes a ZigZag encoded integer.

Parameters
iThe ZigZag encoded integer to decode.
Returns
The decoded integer.

◆ ZigZagDecode() [2/2]

static long ZigZagDecode ( long  i)
static

Decodes a ZigZag encoded long integer.

Parameters
iThe ZigZag encoded long integer to decode.
Returns
The decoded long integer.

◆ ZigZagEncode() [1/2]

static int ZigZagEncode ( int  i)
static

Encodes an integer using ZigZag encoding.

Parameters
iThe integer to encode.
Returns
The ZigZag encoded integer.

◆ ZigZagEncode() [2/2]

static long ZigZagEncode ( long  i)
static

Encodes a long integer using ZigZag encoding.

Parameters
iThe long integer to encode.
Returns
The ZigZag encoded long integer.