From df0d8d5a50e89f722c5a1e16dd80695a9c74d832 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 27 Nov 2020 23:03:28 +0700 Subject: [PATCH] fix clang-6.0 tests compilation --- untests/vmath_mat_fun_tests.cpp | 141 +++++++++++++++++++------------- untests/vmath_tests.hpp | 101 +++++++++++++++-------- 2 files changed, 150 insertions(+), 92 deletions(-) diff --git a/untests/vmath_mat_fun_tests.cpp b/untests/vmath_mat_fun_tests.cpp index 4fcab3b..ddcf612 100644 --- a/untests/vmath_mat_fun_tests.cpp +++ b/untests/vmath_mat_fun_tests.cpp @@ -35,7 +35,7 @@ namespace } TEST_CASE("vmath/mat_fun") { - SECTION("Detail") { + SECTION("detail") { STATIC_REQUIRE(map([](const int2& x){ return x * 2; }, int2x2{}) == int2x2(2,0,0,2)); @@ -61,7 +61,7 @@ TEST_CASE("vmath/mat_fun") { }, int2x2{}) == int2(1,1)); } - SECTION("Operators") { + SECTION("operators") { STATIC_REQUIRE(-int2x2(1,2,3,4) == int2x2(-1,-2,-3,-4)); STATIC_REQUIRE(int2x2(1,2,3,4) + 2 == int2x2(3,4,5,6)); @@ -134,68 +134,93 @@ TEST_CASE("vmath/mat_fun") { } } - SECTION("Matrix Functions") { + SECTION("transpose") { + STATIC_REQUIRE(transpose(int2x2( + 1, 2, + 3, 4 + )) == int2x2( + 1, 3, + 2, 4 + )); + + STATIC_REQUIRE(transpose(int3x3( + 1, 2, 3, + 4, 5, 6, + 7, 8, 9 + )) == int3x3( + 1, 4, 7, + 2, 5, 8, + 3, 6, 9 + )); + + STATIC_REQUIRE(transpose(int4x4( + 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16 + )) == int4x4( + 1, 5, 9, 13, + 2, 6, 10, 14, + 3, 7, 11, 15, + 4, 8, 12, 16 + )); + } + + SECTION("determinant") { + constexpr int2x2 m2{1,2,3,4}; + constexpr int3x3 m3{1,2,3,4,5,6,7,8,9}; + constexpr int4x4 m4{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; + STATIC_REQUIRE(determinant(m2) == determinant(transpose(m2))); + STATIC_REQUIRE(determinant(m3) == determinant(transpose(m3))); + STATIC_REQUIRE(determinant(m4) == determinant(transpose(m4))); + + STATIC_REQUIRE(determinant(generate_frank_matrix()) == 1); + STATIC_REQUIRE(determinant(generate_frank_matrix()) == 1); + STATIC_REQUIRE(determinant(generate_frank_matrix()) == 1); + + STATIC_REQUIRE(determinant(transpose(generate_frank_matrix())) == 1); + STATIC_REQUIRE(determinant(transpose(generate_frank_matrix())) == 1); + STATIC_REQUIRE(determinant(transpose(generate_frank_matrix())) == 1); + } + + SECTION("inverse") { + STATIC_REQUIRE(inverse(float2x2()) == float2x2()); + STATIC_REQUIRE(inverse(float3x3()) == float3x3()); + STATIC_REQUIRE(inverse(float4x4()) == float4x4()); + + STATIC_REQUIRE(inverse(float2x2(0.5)) == float2x2(2.f)); + STATIC_REQUIRE(inverse(float3x3(0.5)) == float3x3(2.f)); + STATIC_REQUIRE(inverse(float4x4(0.5)) == float4x4(2.f)); + { - STATIC_REQUIRE(transpose(int2x2( - 1, 2, - 3, 4 - )) == int2x2( - 1, 3, - 2, 4 - )); - - STATIC_REQUIRE(transpose(int3x3( - 1, 2, 3, - 4, 5, 6, - 7, 8, 9 - )) == int3x3( - 1, 4, 7, - 2, 5, 8, - 3, 6, 9 - )); - - STATIC_REQUIRE(transpose(int4x4( - 1, 2, 3, 4, - 5, 6, 7, 8, - 9, 10, 11, 12, - 13, 14, 15, 16 - )) == int4x4( - 1, 5, 9, 13, - 2, 6, 10, 14, - 3, 7, 11, 15, - 4, 8, 12, 16 - )); + constexpr float4x4 m1 = translate(float3{1.f,2.f,3.f}); + constexpr float4x4 inv_m1 = inverse(m1); + constexpr float4x4 ref_m1 = translate(float3{-1.f,-2.f,-3.f}); + STATIC_REQUIRE(inv_m1 == approx4x4(ref_m1)); } + { - constexpr int2x2 m2{1,2,3,4}; - constexpr int3x3 m3{1,2,3,4,5,6,7,8,9}; - constexpr int4x4 m4{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; - STATIC_REQUIRE(determinant(m2) == determinant(transpose(m2))); - STATIC_REQUIRE(determinant(m3) == determinant(transpose(m3))); - STATIC_REQUIRE(determinant(m4) == determinant(transpose(m4))); - - STATIC_REQUIRE(determinant(generate_frank_matrix()) == 1); - STATIC_REQUIRE(determinant(generate_frank_matrix()) == 1); - STATIC_REQUIRE(determinant(generate_frank_matrix()) == 1); - - STATIC_REQUIRE(determinant(transpose(generate_frank_matrix())) == 1); - STATIC_REQUIRE(determinant(transpose(generate_frank_matrix())) == 1); - STATIC_REQUIRE(determinant(transpose(generate_frank_matrix())) == 1); + const float3 axis = normalize(float3{1.f,2.f,3.f}); + const float4x4 m1 = rotate(0.5f,axis); + const float4x4 inv_m1 = inverse(m1); + const float4x4 ref_m1 = rotate(-0.5f,axis); + REQUIRE(inv_m1 == approx4x4(ref_m1)); } + { - STATIC_REQUIRE(inverse(float2x2()) == float2x2()); - STATIC_REQUIRE(inverse(float3x3()) == float3x3()); - STATIC_REQUIRE(inverse(float4x4()) == float4x4()); + const float3 axis = normalize(float3{1.f,2.f,3.f}); + const float3x3 m1 = float3x3(rotate(0.5f,axis)); + const float3x3 inv_m1 = inverse(m1); + const float3x3 ref_m1 = float3x3(rotate(-0.5f,axis)); + REQUIRE(inv_m1 == approx3x3(ref_m1)); + } - STATIC_REQUIRE(inverse(float2x2(0.5)) == float2x2(2.f)); - STATIC_REQUIRE(inverse(float3x3(0.5)) == float3x3(2.f)); - STATIC_REQUIRE(inverse(float4x4(0.5)) == float4x4(2.f)); - - STATIC_REQUIRE(inverse(translate(float3{1.f,2.f,3.f})) == approx4x4(translate(float3{-1.f,-2.f,-3.f}))); - - REQUIRE(inverse(rotate(0.5f,normalize(float3{1.f,2.f,3.f}))) == approx4x4(rotate(-0.5f,normalize(float3{1.f,2.f,3.f})))); - REQUIRE(inverse(float3x3(rotate(0.5f,normalize(float3{1.f,2.f,3.f})))) == approx3x3(float3x3(rotate(-0.5f,normalize(float3{1.f,2.f,3.f}))))); - REQUIRE(inverse(float2x2(rotate(0.5f,float3{0,0,1}))) == approx2x2(float2x2(rotate(-0.5f,float3{0,0,1})))); + { + const float3 axis = normalize(float3{0.f,0.f,3.f}); + const float2x2 m1 = float2x2(rotate(0.5f,axis)); + const float2x2 inv_m1 = inverse(m1); + const float2x2 ref_m1 = float2x2(rotate(-0.5f,axis)); + REQUIRE(inv_m1 == approx2x2(ref_m1)); } } } diff --git a/untests/vmath_tests.hpp b/untests/vmath_tests.hpp index c57ce5f..8b5bdf9 100644 --- a/untests/vmath_tests.hpp +++ b/untests/vmath_tests.hpp @@ -20,10 +20,6 @@ namespace vmath_tests struct approx { T value; explicit constexpr approx(T v) : value(v) {} - - friend constexpr bool operator==(const T& l, const approx& r) { - return equal_to(l, r.value, epsilon); - } }; template < typename T > @@ -32,10 +28,6 @@ namespace vmath_tests constexpr explicit approx2(T v) : value(v) {} constexpr explicit approx2(T x, T y) : value(x, y) {} constexpr explicit approx2(const vec& v) : value(v) {} - - friend constexpr bool operator==(const vec& l, const approx2& r) { - return all(equal_to(l, r.value, epsilon)); - } }; template < typename T > @@ -44,10 +36,6 @@ namespace vmath_tests constexpr explicit approx3(T v) : value(v) {} constexpr explicit approx3(T x, T y, T z) : value(x, y, z) {} constexpr explicit approx3(const vec& v) : value(v) {} - - friend constexpr bool operator==(const vec& l, const approx3& r) { - return all(equal_to(l, r.value, epsilon)); - } }; template < typename T > @@ -56,45 +44,90 @@ namespace vmath_tests constexpr explicit approx4(T v) : value(v) {} constexpr explicit approx4(T x, T y, T z, T w) : value(x, y, z, w) {} constexpr explicit approx4(const vec& v) : value(v) {} - - friend constexpr bool operator==(const vec& l, const approx4& r) { - return all(equal_to(l, r.value, epsilon)); - } }; template < typename T > struct approx2x2 { mat value; constexpr explicit approx2x2(const mat& v) : value(v) {} - - friend constexpr bool operator==(const mat& l, const approx2x2& r) { - return l[0] == approx2(r.value[0]) - && l[1] == approx2(r.value[1]); - } }; template < typename T > struct approx3x3 { mat value; constexpr explicit approx3x3(const mat& v) : value(v) {} - - friend constexpr bool operator==(const mat& l, const approx3x3& r) { - return l[0] == approx3(r.value[0]) - && l[1] == approx3(r.value[1]) - && l[2] == approx3(r.value[2]); - } }; template < typename T > struct approx4x4 { mat value; constexpr explicit approx4x4(const mat& v) : value(v) {} - - friend constexpr bool operator==(const mat& l, const approx4x4& r) { - return l[0] == approx4(r.value[0]) - && l[1] == approx4(r.value[1]) - && l[2] == approx4(r.value[2]) - && l[3] == approx4(r.value[3]); - } }; + + // + // + // + + template < typename T > + approx2(const vec&) -> approx2; + + template < typename T > + approx3(const vec&) -> approx3; + + template < typename T > + approx4(const vec&) -> approx4; + + template < typename T > + approx2x2(const mat&) -> approx2x2; + + template < typename T > + approx3x3(const mat&) -> approx3x3; + + template < typename T > + approx4x4(const mat&) -> approx4x4; + + // + // + // + + template < typename T > + constexpr bool operator==(const T& l, const approx& r) { + return equal_to(l, r.value, epsilon); + } + + template < typename T > + constexpr bool operator==(const vec& l, const approx2& r) { + return all(equal_to(l, r.value, epsilon)); + } + + template < typename T > + constexpr bool operator==(const vec& l, const approx3& r) { + return all(equal_to(l, r.value, epsilon)); + } + + template < typename T > + constexpr bool operator==(const vec& l, const approx4& r) { + return all(equal_to(l, r.value, epsilon)); + } + + template < typename T > + constexpr bool operator==(const mat& l, const approx2x2& r) { + return l[0] == approx2(r.value[0]) + && l[1] == approx2(r.value[1]); + } + + template < typename T > + constexpr bool operator==(const mat& l, const approx3x3& r) { + return l[0] == approx3(r.value[0]) + && l[1] == approx3(r.value[1]) + && l[2] == approx3(r.value[2]); + } + + template < typename T > + constexpr bool operator==(const mat& l, const approx4x4& r) { + return l[0] == approx4(r.value[0]) + && l[1] == approx4(r.value[1]) + && l[2] == approx4(r.value[2]) + && l[3] == approx4(r.value[3]); + } }