From 0a26d1824e3e2dac8652c709ceece475e48a6904 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 24 Nov 2020 22:27:22 +0700 Subject: [PATCH] more constexpr --- headers/vmath.hpp/vmath_mat_ext.hpp | 18 +++++++++--------- untests/vmath_mat_ext_tests.cpp | 20 ++++++++++---------- untests/vmath_mat_fun_tests.cpp | 8 ++++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/headers/vmath.hpp/vmath_mat_ext.hpp b/headers/vmath.hpp/vmath_mat_ext.hpp index 9771b31..bd431d7 100644 --- a/headers/vmath.hpp/vmath_mat_ext.hpp +++ b/headers/vmath.hpp/vmath_mat_ext.hpp @@ -17,7 +17,7 @@ namespace vmath_hpp // identity template < typename T > - mat identity() { + constexpr mat identity() { return { {1, 0, 0, 0}, {0, 1, 0, 0}, @@ -28,7 +28,7 @@ namespace vmath_hpp // translate template < typename T > - mat translate(T x, T y, T z) { + constexpr mat translate(T x, T y, T z) { return { {1, 0, 0, 0}, {0, 1, 0, 0}, @@ -37,17 +37,17 @@ namespace vmath_hpp } template < typename T > - mat translate(const vec& xyz) { + constexpr mat translate(const vec& xyz) { return translate(xyz.x, xyz.y, xyz.z); } template < typename T > - mat translate(const mat& m, T x, T y, T z) { + constexpr mat translate(const mat& m, T x, T y, T z) { return m * translate(x, y, z); } template < typename T > - mat translate(const mat& m, const vec& xyz) { + constexpr mat translate(const mat& m, const vec& xyz) { return m * translate(xyz); } @@ -95,7 +95,7 @@ namespace vmath_hpp // scale template < typename T > - mat scale(T x, T y, T z) { + constexpr mat scale(T x, T y, T z) { return { {x, 0, 0, 0}, {0, y, 0, 0}, @@ -104,17 +104,17 @@ namespace vmath_hpp } template < typename T > - mat scale(const vec& xyz) { + constexpr mat scale(const vec& xyz) { return scale(xyz.x, xyz.y, xyz.z); } template < typename T > - mat scale(const mat& m, T x, T y, T z) { + constexpr mat scale(const mat& m, T x, T y, T z) { return m * scale(x, y, z); } template < typename T > - mat scale(const mat& m, const vec& xyz) { + constexpr mat scale(const mat& m, const vec& xyz) { return m * scale(xyz); } } diff --git a/untests/vmath_mat_ext_tests.cpp b/untests/vmath_mat_ext_tests.cpp index 3a3ceb0..4e2e74a 100644 --- a/untests/vmath_mat_ext_tests.cpp +++ b/untests/vmath_mat_ext_tests.cpp @@ -73,16 +73,16 @@ namespace TEST_CASE("vmath/mat_ext") { SECTION("identity") { - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * identity() == approx4(2.f,3.f,4.f,1.f)); - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * identity() == approx4(2.f,3.f,4.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * identity() == approx4(2.f,3.f,4.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * identity() == approx4(2.f,3.f,4.f,1.f)); } SECTION("translate") { - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * translate(1.f,2.f,3.f) == approx4(3.f,5.f,7.f,1.f)); - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * translate(vec3f{1.f,2.f,3.f}) == approx4(3.f,5.f,7.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * translate(1.f,2.f,3.f) == approx4(3.f,5.f,7.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * translate(vec3f{1.f,2.f,3.f}) == approx4(3.f,5.f,7.f,1.f)); - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * translate(translate(1.f,2.f,3.f), 1.f,2.f,3.f) == approx4(4.f,7.f,10.f,1.f)); - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * translate(translate(1.f,2.f,3.f), vec3f{1.f,2.f,3.f}) == approx4(4.f,7.f,10.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * translate(translate(1.f,2.f,3.f), 1.f,2.f,3.f) == approx4(4.f,7.f,10.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * translate(translate(1.f,2.f,3.f), vec3f{1.f,2.f,3.f}) == approx4(4.f,7.f,10.f,1.f)); } SECTION("rotate") { @@ -94,10 +94,10 @@ TEST_CASE("vmath/mat_ext") { } SECTION("scale") { - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * scale(2.f,3.f,4.f) == approx4(4.f,9.f,16.f,1.f)); - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * scale(vec3f{2.f,3.f,4.f}) == approx4(4.f,9.f,16.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * scale(2.f,3.f,4.f) == approx4(4.f,9.f,16.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * scale(vec3f{2.f,3.f,4.f}) == approx4(4.f,9.f,16.f,1.f)); - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * scale(scale(2.f,2.f,2.f), 2.f,3.f,4.f) == approx4(8.f,18.f,32.f,1.f)); - REQUIRE(vec4f(2.f,3.f,4.f,1.f) * scale(scale(2.f,2.f,2.f), vec3f{2.f,3.f,4.f}) == approx4(8.f,18.f,32.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * scale(scale(2.f,2.f,2.f), 2.f,3.f,4.f) == approx4(8.f,18.f,32.f,1.f)); + STATIC_REQUIRE(vec4f(2.f,3.f,4.f,1.f) * scale(scale(2.f,2.f,2.f), vec3f{2.f,3.f,4.f}) == approx4(8.f,18.f,32.f,1.f)); } } diff --git a/untests/vmath_mat_fun_tests.cpp b/untests/vmath_mat_fun_tests.cpp index b0fd699..a2d1f97 100644 --- a/untests/vmath_mat_fun_tests.cpp +++ b/untests/vmath_mat_fun_tests.cpp @@ -213,11 +213,11 @@ TEST_CASE("vmath/mat_fun") { STATIC_REQUIRE(inverse(mat3i()) == mat3i()); STATIC_REQUIRE(inverse(mat4i()) == mat4i()); - REQUIRE(inverse(mat2f(0.5)) == mat2f(2.f)); - REQUIRE(inverse(mat3f(0.5)) == mat3f(2.f)); - REQUIRE(inverse(mat4f(0.5)) == mat4f(2.f)); + STATIC_REQUIRE(inverse(mat2f(0.5)) == mat2f(2.f)); + STATIC_REQUIRE(inverse(mat3f(0.5)) == mat3f(2.f)); + STATIC_REQUIRE(inverse(mat4f(0.5)) == mat4f(2.f)); - REQUIRE(inverse(translate(1.f,2.f,3.f)) == approx4x4(translate(-1.f,-2.f,-3.f))); + STATIC_REQUIRE(inverse(translate(1.f,2.f,3.f)) == approx4x4(translate(-1.f,-2.f,-3.f))); REQUIRE(inverse(rotate(0.5f,normalize(vec3f{1.f,2.f,3.f}))) == approx4x4(rotate(-0.5f,normalize(vec3f{1.f,2.f,3.f})))); REQUIRE(inverse(mat3f(rotate(0.5f,normalize(vec3f{1.f,2.f,3.f})))) == approx3x3(mat3f(rotate(-0.5f,normalize(vec3f{1.f,2.f,3.f})))));