diff --git a/headers/vmath.hpp/vmath_fun.hpp b/headers/vmath.hpp/vmath_fun.hpp index 7e8ba90..c753df6 100644 --- a/headers/vmath.hpp/vmath_fun.hpp +++ b/headers/vmath.hpp/vmath_fun.hpp @@ -229,13 +229,13 @@ namespace vmath_hpp template < typename T > [[nodiscard]] std::enable_if_t, T> constexpr min(T x, T y) noexcept { - return std::min(x, y); + return x < y ? x : y; } template < typename T > [[nodiscard]] std::enable_if_t, T> constexpr max(T x, T y) noexcept { - return std::max(x, y); + return x < y ? y : x; } template < typename T > @@ -287,8 +287,6 @@ namespace vmath_hpp return std::isfinite(x); } - // - template < typename T > [[nodiscard]] std::enable_if_t, T> fma(T x, T y, T z) noexcept { diff --git a/headers/vmath.hpp/vmath_fwd.hpp b/headers/vmath.hpp/vmath_fwd.hpp index 01f8ea6..81a8bbc 100644 --- a/headers/vmath.hpp/vmath_fwd.hpp +++ b/headers/vmath.hpp/vmath_fwd.hpp @@ -9,8 +9,6 @@ #include #include -#include -#include #include #include #include diff --git a/headers/vmath.hpp/vmath_mat_fun.hpp b/headers/vmath.hpp/vmath_mat_fun.hpp index 273295d..1fedbb1 100644 --- a/headers/vmath.hpp/vmath_mat_fun.hpp +++ b/headers/vmath.hpp/vmath_mat_fun.hpp @@ -103,7 +103,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr mat operator-(const mat& xs) { - return map(std::negate<>(), xs); + return map([](const vec& x){ return -x; }, xs); } // operator+ @@ -120,7 +120,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr mat operator+(const mat& xs, const mat& ys) { - return zip(std::plus<>(), xs, ys); + return zip([](const vec& x, const vec& y){ return x + y; }, xs, ys); } // operator+= @@ -149,7 +149,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr mat operator-(const mat& xs, const mat& ys) { - return zip(std::minus<>(), xs, ys); + return zip([](const vec& x, const vec& y){ return x - y; }, xs, ys); } // operator-= @@ -281,7 +281,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr mat operator/(const mat& xs, const mat& ys) { - return zip(std::divides<>(), xs, ys); + return zip([](const vec& x, const vec& y){ return x / y; }, xs, ys); } // operator/= diff --git a/headers/vmath.hpp/vmath_vec_fun.hpp b/headers/vmath.hpp/vmath_vec_fun.hpp index 4227849..a4a3fbd 100644 --- a/headers/vmath.hpp/vmath_vec_fun.hpp +++ b/headers/vmath.hpp/vmath_vec_fun.hpp @@ -100,7 +100,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr vec operator-(const vec& xs) { - return map(std::negate<>(), xs); + return map([](T x){ return -x; }, xs); } // operator+ @@ -117,7 +117,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr vec operator+(const vec& xs, const vec& ys) { - return zip(std::plus<>(), xs, ys); + return zip([](T x, T y){ return x + y; }, xs, ys); } // operator+= @@ -146,7 +146,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr vec operator-(const vec& xs, const vec& ys) { - return zip(std::minus<>(), xs, ys); + return zip([](T x, T y){ return x - y; }, xs, ys); } // operator-= @@ -175,7 +175,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr vec operator*(const vec& xs, const vec& ys) { - return zip(std::multiplies<>(), xs, ys); + return zip([](T x, T y){ return x * y; }, xs, ys); } // operator*= @@ -204,7 +204,7 @@ namespace vmath_hpp template < typename T, std::size_t Size > [[nodiscard]] constexpr vec operator/(const vec& xs, const vec& ys) { - return zip(std::divides<>(), xs, ys); + return zip([](T x, T y){ return x / y; }, xs, ys); } // operator/= diff --git a/untests/vmath_mat_fun_tests.cpp b/untests/vmath_mat_fun_tests.cpp index 705f76f..d67d99b 100644 --- a/untests/vmath_mat_fun_tests.cpp +++ b/untests/vmath_mat_fun_tests.cpp @@ -191,14 +191,14 @@ TEST_CASE("vmath/mat_fun") { STATIC_REQUIRE(inverse(float4x4(0.5)) == float4x4(2.f)); { - constexpr float4x4 m1 = translate(float3{1.f,2.f,3.f}); + 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}); + constexpr float4x4 ref_m1 = translate(float3(-1.f, -2.f, -3.f)); STATIC_REQUIRE(inv_m1 == approx4x4(ref_m1)); } { - const float3 axis = normalize(float3{1.f,2.f,3.f}); + 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); @@ -206,7 +206,7 @@ TEST_CASE("vmath/mat_fun") { } { - const float3 axis = normalize(float3{1.f,2.f,3.f}); + 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)); @@ -214,7 +214,7 @@ TEST_CASE("vmath/mat_fun") { } { - const float3 axis = normalize(float3{0.f,0.f,3.f}); + 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)); diff --git a/untests/vmath_tests.hpp b/untests/vmath_tests.hpp index ac1f22f..d76de7c 100644 --- a/untests/vmath_tests.hpp +++ b/untests/vmath_tests.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #define STATIC_REQUIRE(...)\ static_assert(__VA_ARGS__, #__VA_ARGS__);\ @@ -25,7 +25,29 @@ namespace vmath_tests using namespace vmath_hpp; template < typename T > - inline constexpr T epsilon = std::numeric_limits::epsilon() * 100; + struct approx_epsilon; + + template <> + struct approx_epsilon { + static constexpr int value = 0; + }; + + template <> + struct approx_epsilon { + static constexpr float value = FLT_EPSILON * 100; + }; + + template <> + struct approx_epsilon { + static constexpr float value = DBL_EPSILON * 100; + }; + + template < typename T > + inline constexpr T approx_epsilon_v = approx_epsilon::value; + + // + // + // template < typename T > struct approx { @@ -103,22 +125,22 @@ namespace vmath_tests template < typename T > constexpr bool operator==(const T& l, const approx& r) { - return equal_to(l, r.value, epsilon); + return equal_to(l, r.value, approx_epsilon_v); } template < typename T > constexpr bool operator==(const vec& l, const approx2& r) { - return all(equal_to(l, r.value, epsilon)); + return all(equal_to(l, r.value, approx_epsilon_v)); } template < typename T > constexpr bool operator==(const vec& l, const approx3& r) { - return all(equal_to(l, r.value, epsilon)); + return all(equal_to(l, r.value, approx_epsilon_v)); } template < typename T > constexpr bool operator==(const vec& l, const approx4& r) { - return all(equal_to(l, r.value, epsilon)); + return all(equal_to(l, r.value, approx_epsilon_v)); } template < typename T >