Photon Fusion 2.1.1

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

Detailed Description

Math utility methods.

Member Function Documentation

◆ BitScanReverse() [1/4]

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]

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]

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]

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]

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]

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]

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]

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

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]

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]

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]

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]

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]

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]

float Clamp01 ( float v)
static

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

Parameters
vThe value to clamp.
Returns
The clamped value.

◆ ClampToByte()

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

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

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

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

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

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]

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]

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

double MicrosecondsToSeconds ( long microseconds)
static

Converts microseconds to seconds.

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

◆ MillisecondsToMicroseconds()

long MillisecondsToMicroseconds ( long milliseconds)
static

Converts milliseconds to microseconds.

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

◆ MillisecondsToSeconds()

double MillisecondsToSeconds ( double seconds)
static

Converts milliseconds to seconds.

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

◆ Min()

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

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

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

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

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.

◆ RoundsEvenlyToBytesOrThrow()

int RoundsEvenlyToBytesOrThrow ( int bits)
static

Converts the number of bits to bytes, ensuring the number of bits is a multiple of 8.

Parameters
bitsThe number of bits to convert.
Returns
The number of bytes.
Exceptions
ArgumentExceptionThrown if the number of bits is not a multiple of 8.

◆ SecondsToMicroseconds()

long SecondsToMicroseconds ( double seconds)
static

Converts seconds to microseconds.

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

◆ SecondsToMilliseconds()

long SecondsToMilliseconds ( double seconds)
static

Converts seconds to milliseconds.

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

◆ SizeOfBits< T >()

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]

int ZigZagDecode ( int i)
static

Decodes a ZigZag encoded integer.

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

◆ ZigZagDecode() [2/2]

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]

int ZigZagEncode ( int i)
static

Encodes an integer using ZigZag encoding.

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

◆ ZigZagEncode() [2/2]

long ZigZagEncode ( long i)
static

Encodes a long integer using ZigZag encoding.

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