Fix: convert math::Axis to vector

This commit is contained in:
Jacques Lucke
2024-06-28 12:16:56 +02:00
parent 4bff6ba655
commit 7866fcd869
2 changed files with 9 additions and 2 deletions

View File

@@ -321,9 +321,9 @@ template<> inline AxisSigned abs(const AxisSigned &axis)
/** Create basis vector. */
template<typename T> T to_vector(const Axis axis)
{
BLI_assert(axis <= AxisSigned::from_int(T::type_length - 1));
BLI_assert(axis.as_int() < T::type_length);
T vec{};
vec[axis] = 1;
vec[axis.as_int()] = 1;
return vec;
}

View File

@@ -60,6 +60,13 @@ TEST(math_rotation_types, AxisSignedConvertToVec)
EXPECT_EQ(to_vector<float2>(AxisSigned::Y_NEG), float2(0, -1));
}
TEST(math_rotation_types, AxisConvertToVec)
{
EXPECT_EQ(to_vector<float3>(Axis::X), float3(1, 0, 0));
EXPECT_EQ(to_vector<float3>(Axis::Y), float3(0, 1, 0));
EXPECT_EQ(to_vector<float3>(Axis::Z), float3(0, 0, 1));
}
TEST(math_rotation_types, Euler3Order)
{
/* Asserts those match.