introduce more utility templates for metric unit conversions
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
#include "Containers/Array.h"
|
||||
#include "Templates/UnrealTemplate.h"
|
||||
|
||||
#include "SGUtils/SGUnits.h"
|
||||
|
||||
class SENSEGLOVEUTILS_API FSGArrayUtils final
|
||||
{
|
||||
public:
|
||||
@@ -536,6 +538,33 @@ public:
|
||||
static TArray<float> FromMillimeters(const std::vector<float>& Vector);
|
||||
static TArray<TArray<float>> FromMillimeters(const std::vector<std::vector<float>>& NestedVector);
|
||||
|
||||
template<typename V3D, typename V3DImpl>
|
||||
static TArray<FVector> FromMillimeters(const std::vector<V3D>& Vector)
|
||||
{
|
||||
TArray<FVector> Array;
|
||||
|
||||
for (const V3D& Value: Vector)
|
||||
{
|
||||
Array.Add(FSGUnits::MillimetersToCentimeters<V3D, V3DImpl>(Value));
|
||||
}
|
||||
|
||||
return MoveTemp(Array);
|
||||
}
|
||||
|
||||
template<typename V3D, typename V3DImpl>
|
||||
static TArray<TArray<FVector>> FromMillimeters(const std::vector<std::vector<V3D>>& NestedVector)
|
||||
{
|
||||
TArray<TArray<FVector>> NestedArray;
|
||||
|
||||
for (const std::vector<V3D>& InnerVector: NestedVector)
|
||||
{
|
||||
TArray<FVector> InnerArray{FromMillimeters<V3D, V3DImpl>(InnerVector)};
|
||||
NestedArray.Add(MoveTemp(InnerArray));
|
||||
}
|
||||
|
||||
return MoveTemp(NestedArray);
|
||||
}
|
||||
|
||||
static std::vector<float> ToMillimeters(const TArray<float>& Array);
|
||||
static std::vector<std::vector<float>> ToMillimeters(const TArray<TArray<float>>& NestedArray);
|
||||
|
||||
@@ -553,6 +582,33 @@ public:
|
||||
return MoveTemp(NestedVector);
|
||||
}
|
||||
|
||||
template<typename V3D, typename V3DImpl>
|
||||
static std::vector<V3D> ToMillimeters(const TArray<FVector>& Array)
|
||||
{
|
||||
std::vector<V3D> Vector;
|
||||
|
||||
for (const FVector& Value: Array)
|
||||
{
|
||||
Vector.emplace_back(FSGUnits::CentimetersToMillimeters<V3D, V3DImpl>(Value));
|
||||
}
|
||||
|
||||
return MoveTemp(Vector);
|
||||
}
|
||||
|
||||
template<typename V3D, typename V3DImpl>
|
||||
static std::vector<std::vector<V3D>> ToMillimeters(const TArray<TArray<FVector>>& NestedArray)
|
||||
{
|
||||
std::vector<std::vector<V3D>> NestedVector;
|
||||
|
||||
for (const TArray<FVector>& InnerArray: NestedArray)
|
||||
{
|
||||
std::vector<V3D> InnerVector{ToMillimeters<V3D, V3DImpl>(InnerArray)};
|
||||
NestedVector.emplace_back(MoveTemp(InnerVector));
|
||||
}
|
||||
|
||||
return MoveTemp(NestedVector);
|
||||
}
|
||||
|
||||
public:
|
||||
FSGArrayUtils() = delete;
|
||||
virtual ~FSGArrayUtils() = delete;
|
||||
|
||||
@@ -55,11 +55,23 @@ public:
|
||||
return Value * CentimetersToMillimetersMultiplier();
|
||||
}
|
||||
|
||||
template<typename V3D, typename V3DImpl>
|
||||
static FORCEINLINE V3D CentimetersToMillimeters(const FVector& Vector)
|
||||
{
|
||||
return V3DImpl(Vector * CentimetersToMillimetersMultiplier()).ToVect3D();
|
||||
}
|
||||
|
||||
static FORCEINLINE float MillimetersToCentimeters(const float Value)
|
||||
{
|
||||
return Value * MillimetersToCentimetersMultiplier();
|
||||
}
|
||||
|
||||
template<typename V3D, typename V3DImpl>
|
||||
static FORCEINLINE FVector MillimetersToCentimeters(const V3D& Vect3D)
|
||||
{
|
||||
return V3DImpl(Vect3D).ToFVector() * MillimetersToCentimetersMultiplier();
|
||||
}
|
||||
|
||||
public:
|
||||
FSGUnits() = delete;
|
||||
virtual ~FSGUnits() = delete;
|
||||
|
||||
Reference in New Issue
Block a user