optimizing network stuff
This commit is contained in:
25
Runtime/Engine/Code/Foundation/QuantizationUtility.cs
Normal file
25
Runtime/Engine/Code/Foundation/QuantizationUtility.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace RebootKit.Engine.Foundation {
|
||||
public static class QuantizationUtility {
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ushort FloatToUShort(float value, float min, float max) {
|
||||
return (ushort)((value - min) / (max - min) * ushort.MaxValue);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float UShortToFloat(ushort value, float min, float max) {
|
||||
return min + (value / (float)ushort.MaxValue) * (max - min);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static byte FloatToByte(float value, float min, float max) {
|
||||
return (byte)((value - min) / (max - min) * byte.MaxValue);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float ByteToFloat(byte value, float min, float max) {
|
||||
return min + (value / (float)byte.MaxValue) * (max - min);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user