more of the new matrix vector implementation

This commit is contained in:
Hartmut Seichter 2024-07-11 23:38:43 +02:00
parent 63135466a2
commit 3989c0f68e
7 changed files with 293 additions and 48 deletions

View file

@ -10,12 +10,9 @@ set(pixwerx_test_files
pw_test_core.cpp
)
add_executable(pixwerx_tests ${pixwerx_test_files})
target_link_libraries(pixwerx_tests PRIVATE
target_link_libraries(pixwerx_tests PRIVATE
snitch::snitch
pwcore
)

View file

@ -3,42 +3,55 @@
#include <pw/core/matrix.hpp>
#include <pw/core/vector.hpp>
TEST_CASE("core", "[matrix]") {
auto m44 = pw::matrix<float,2,2>{};
auto mat = pw::matrix<float,2,2>{};
REQUIRE(m44[0][0] == 0);
REQUIRE(m44[0][1] == 0);
REQUIRE(m44[1][0] == 0);
REQUIRE(m44[1][1] == 0);
REQUIRE(mat[0][0] == 0);
REQUIRE(mat[0][1] == 0);
REQUIRE(mat[1][0] == 0);
REQUIRE(mat[1][1] == 0);
// auto m44_1 = pw::matrix<2, 2, float>{ 5, 4, 3, 2 };
auto mat_1 = pw::matrix<float,2, 2>{
pw::vector{5.f, 4},
pw::vector{3.f, 2}
};
// REQUIRE(m44_1(0, 0) == 5);
// REQUIRE(m44_1(0, 1) == 3);
// REQUIRE(m44_1(1, 0) == 4);
// REQUIRE(m44_1(1, 1) == 2);
REQUIRE(mat_1[0][0] == 5);
REQUIRE(mat_1[0][1] == 4);
REQUIRE(mat_1[1][0] == 3);
REQUIRE(mat_1[1][1] == 2);
// auto m44_2 = pw::matrix2x2_<float>::all(42.42f);
const auto val {42.42f};
// REQUIRE(m44_2(0, 0) == 42.42f);
// REQUIRE(m44_2(0, 1) == 42.42f);
// REQUIRE(m44_2(1, 0) == 42.42f);
// REQUIRE(m44_2(1, 1) == 42.42f);
auto mat_2 = pw::matrix<float,2,2>::all(val);
// m44 *= 2;
// REQUIRE(m44(0, 0) == 84.84f);
// REQUIRE(m44(0, 1) == 84.84f);
// REQUIRE(m44(1, 0) == 84.84f);
// REQUIRE(m44(1, 1) == 84.84f);
REQUIRE(mat_2[0][0] == val);
REQUIRE(mat_2[0][1] == val);
REQUIRE(mat_2[1][0] == val);
REQUIRE(mat_2[1][1] == val);
// m44.set_identity();
// REQUIRE(m44(0, 0) == 1.0f);
// REQUIRE(m44(0, 1) == 0.0f);
// REQUIRE(m44(1, 0) == 0.0f);
// REQUIRE(m44(1, 1) == 1.0f);
mat_2 *= 2;
REQUIRE(mat_2[0][0] == (val * 2));
REQUIRE(mat_2[0][1] == (val * 2));
REQUIRE(mat_2[1][0] == (val * 2));
REQUIRE(mat_2[1][1] == (val * 2));
mat_2 = pw::matrix<float, 2, 2>::identity();
REQUIRE(mat_2[0][0] == 1.0f);
REQUIRE(mat_2[0][1] == 0.0f);
REQUIRE(mat_2[1][0] == 0.0f);
REQUIRE(mat_2[1][1] == 1.0f);
auto mat_2_inv = mat_2.inverse();
REQUIRE(mat_2_inv[0][0] == 1.0f);
REQUIRE(mat_2_inv[0][1] == 0.0f);
REQUIRE(mat_2_inv[1][0] == 0.0f);
REQUIRE(mat_2_inv[1][1] == 1.0f);
// auto m44_2 = pw::matrix2x2::make(0, 1, 2, 3);
@ -60,7 +73,14 @@ TEST_CASE("core", "[matrix]") {
TEST_CASE("core", "[vector.matrix]") {
// auto vec4_1 = pw::vector4_<float>{};
auto vec4_1 = pw::vector4<float>{};
REQUIRE(vec4_1[0] == 0.0f);
REQUIRE(vec4_1[1] == 0.0f);
REQUIRE(vec4_1[2] == 0.0f);
REQUIRE(vec4_1[3] == 0.0f);
// auto mat4_1 = pw::matrix_<4,1,float>{};