common: add qmat::transpose()

This commit is contained in:
Eric Wasylishen 2023-07-06 17:13:14 -06:00
parent f03fc2183c
commit aa74b76815
2 changed files with 29 additions and 0 deletions

View File

@ -984,6 +984,17 @@ public:
}
return res;
}
[[nodiscard]] constexpr qmat<T, NCol, NRow> transpose() const
{
qmat<T, NCol, NRow> res;
for (size_t i = 0; i < NRow; i++) {
for (size_t j = 0; j < NCol; j++) {
res.at(j, i) = at(i, j);
}
}
return res;
}
};
// Fmt support

View File

@ -294,3 +294,21 @@ TEST_SUITE("common")
CHECK(texture->height_scale == 1);
}
}
TEST_SUITE("qmat")
{
TEST_CASE("transpose")
{
// clang-format off
auto in = qmat<float, 2, 3>::row_major(
{1.0, 2.0, 3.0,
4.0, 5.0, 6.0});
auto exp = qmat<float, 3, 2>::row_major(
{1.0, 4.0,
2.0, 5.0,
3.0, 6.0});
// clang-format on
CHECK(in.transpose() == exp);
}
}