0
0
Fork 0

me-main #1

Merged
Nate Rupsis merged 123 commits from me-main into main 2023-02-13 18:39:11 +01:00
2 changed files with 36 additions and 0 deletions
Showing only changes of commit 0ab3ac7a41 - Show all commits

View File

@ -910,6 +910,27 @@ struct MutableMatView
unroll<NumCol>([&](auto i) { (*this)[i] *= b; });
return *this;
}
/** Vector operators. Need to be redefined to avoid operator priority issue. */
friend col_type operator*(MutableMatView &a, const row_type &b)
{
/* This is the reference implementation.
* Might be overloaded with vectorized / optimized code. */
col_type result(0);
unroll<NumCol>([&](auto c) { result += b[c] * a[c]; });
return result;
}
/** Multiply by the transposed. */
friend row_type operator*(const col_type &a, MutableMatView &b)
{
/* This is the reference implementation.
* Might be overloaded with vectorized / optimized code. */
row_type result(0);
unroll<NumCol>([&](auto c) { unroll<NumRow>([&](auto r) { result[c] += b[c][r] * a[r]; }); });
return result;
}
};
using float2x2 = MatBase<float, 2, 2>;

View File

@ -388,6 +388,21 @@ TEST(math_matrix_types, ViewMatrixMultiplyOperator)
EXPECT_EQ(view[1][1], 46);
}
TEST(math_matrix_types, ViewVectorMultiplyOperator)
{
float4x4 mat = float4x4({1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16});
auto view = mat.view<2, 3, 1, 1>();
float3 result = view * float2(4, 5);
EXPECT_EQ(result[0], 74);
EXPECT_EQ(result[1], 83);
EXPECT_EQ(result[2], 92);
float2 result2 = float3(1, 2, 3) * view;
EXPECT_EQ(result2[0], 44);
EXPECT_EQ(result2[1], 68);
}
TEST(math_matrix_types, ViewMatrixNormalize)
{
float4x4 mat = float4x4({1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16});