Compression functions for Vector4

This commit is contained in:
mischa 2024-09-19 22:18:17 +02:00
parent 1bfb469821
commit 85e42f80ad

View File

@ -78,6 +78,13 @@ public static bool ScaleToLong(Vector3 value, float precision, out Vector3Long q
return ScaleToLong(value, precision, out quantized.x, out quantized.y, out quantized.z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool ScaleToLong(Vector4 value, float precision, out Vector4Long quantized)
{
quantized = Vector4Long.zero;
return ScaleToLong(value, precision, out quantized.x, out quantized.y, out quantized.z);
}
// multiple by precision.
// for example, 0.1 cm precision converts '50' long to '5.0f' float.
public static float ScaleToFloat(long value, float precision)
@ -103,10 +110,25 @@ public static Vector3 ScaleToFloat(long x, long y, long z, float precision)
return v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 ScaleToFloat(long x, long y, long z, long w, float precision)
{
Vector4 v;
v.x = ScaleToFloat(x, precision);
v.y = ScaleToFloat(y, precision);
v.z = ScaleToFloat(z, precision);
v.w = ScaleToFloat(w, precision);
return v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ScaleToFloat(Vector3Long value, float precision) =>
ScaleToFloat(value.x, value.y, value.z, precision);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 ScaleToFloat(Vector4Long value, float precision) =>
ScaleToFloat(value.x, value.y, value.z, value.w, precision);
// scale a float within min/max range to an ushort between min/max range
// note: can also use this for byte range from byte.MinValue to byte.MaxValue
public static ushort ScaleFloatToUShort(float value, float minValue, float maxValue, ushort minTarget, ushort maxTarget)