From 8dd4ccc08b8236e2622e41b504d2153d3cf3cc4a Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 25 Nov 2020 18:55:41 +0700 Subject: [PATCH] lerp instead mix --- headers/vmath.hpp/vmath_fun.hpp | 7 +------ headers/vmath.hpp/vmath_vec_fun.hpp | 18 ++++-------------- untests/vmath_fun_tests.cpp | 4 +--- untests/vmath_vec_fun_tests.cpp | 10 ++-------- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/headers/vmath.hpp/vmath_fun.hpp b/headers/vmath.hpp/vmath_fun.hpp index e1059d9..d317b20 100644 --- a/headers/vmath.hpp/vmath_fun.hpp +++ b/headers/vmath.hpp/vmath_fun.hpp @@ -101,15 +101,10 @@ namespace vmath_hpp } template < typename T > - constexpr T mix(T x, T y, T a) noexcept { + constexpr T lerp(T x, T y, T a) noexcept { return x * (T(1) - a) + y * a; } - template < typename T > - constexpr T mix(T x, T y, bool a) noexcept { - return a ? y : x; - } - template < typename T > constexpr T step(T edge, T x) noexcept { return x < edge ? T(0) : T(1); diff --git a/headers/vmath.hpp/vmath_vec_fun.hpp b/headers/vmath.hpp/vmath_vec_fun.hpp index c79cc1e..7429762 100644 --- a/headers/vmath.hpp/vmath_vec_fun.hpp +++ b/headers/vmath.hpp/vmath_vec_fun.hpp @@ -462,23 +462,13 @@ namespace vmath_hpp } template < typename T, std::size_t Size > - constexpr vec mix(const vec& xs, const vec& ys, T a) { - return zip([a](T x, T y) { return mix(x, y, a); }, xs, ys); + constexpr vec lerp(const vec& xs, const vec& ys, T a) { + return zip([a](T x, T y) { return lerp(x, y, a); }, xs, ys); } template < typename T, std::size_t Size > - constexpr vec mix(const vec& xs, const vec& ys, bool a) { - return zip([a](T x, T y) { return mix(x, y, a); }, xs, ys); - } - - template < typename T, std::size_t Size > - constexpr vec mix(const vec& xs, const vec& ys, const vec& as) { - return zip([](T x, T y, T a) { return mix(x, y, a); }, xs, ys, as); - } - - template < typename T, std::size_t Size > - constexpr vec mix(const vec& xs, const vec& ys, const vec& as) { - return zip([](T x, T y, bool a) { return mix(x, y, a); }, xs, ys, as); + constexpr vec lerp(const vec& xs, const vec& ys, const vec& as) { + return zip([](T x, T y, T a) { return lerp(x, y, a); }, xs, ys, as); } template < typename T, std::size_t Size > diff --git a/untests/vmath_fun_tests.cpp b/untests/vmath_fun_tests.cpp index 2db00a1..419a4f3 100644 --- a/untests/vmath_fun_tests.cpp +++ b/untests/vmath_fun_tests.cpp @@ -90,9 +90,7 @@ TEST_CASE("vmath/fun") { STATIC_REQUIRE(saturate(0.5f) == approx(0.5f)); STATIC_REQUIRE(saturate(1.5f) == approx(1.f)); - STATIC_REQUIRE(mix(0.f, 10.f, 0.5f) == approx(5.f)); - STATIC_REQUIRE(mix(0.f, 10.f, false) == approx(0.f)); - STATIC_REQUIRE(mix(0.f, 10.f, true) == approx(10.f)); + STATIC_REQUIRE(lerp(0.f, 10.f, 0.5f) == approx(5.f)); STATIC_REQUIRE(step(0.5f, 0.4f) == approx(0.f)); STATIC_REQUIRE(step(0.5f, 0.6f) == approx(1.f)); STATIC_REQUIRE(smoothstep(0.f, 1.f, 0.1f) == approx(0.028f)); diff --git a/untests/vmath_vec_fun_tests.cpp b/untests/vmath_vec_fun_tests.cpp index 247716d..6cd0631 100644 --- a/untests/vmath_vec_fun_tests.cpp +++ b/untests/vmath_vec_fun_tests.cpp @@ -128,14 +128,8 @@ TEST_CASE("vmath/vec_fun") { STATIC_REQUIRE(saturate(vec3f(-1.f,0.5,1.5f)) == approx3(0.f,0.5f,1.f)); - STATIC_REQUIRE(mix(vec2f(0.f), vec2f(10.f), 0.5f) == approx2(5.f)); - STATIC_REQUIRE(mix(vec2f(0.f), vec2f(10.f), vec2f(0.5f)) == approx2(5.f)); - - STATIC_REQUIRE(mix(vec2f(0.f), vec2f(10.f), true) == approx2(10.f)); - STATIC_REQUIRE(mix(vec2f(0.f), vec2f(10.f), false) == approx2(0.f)); - - STATIC_REQUIRE(mix(vec2f(0.f,5.f), vec2f(10.f,20.f), vec2f(true,false)) == approx2(10.f, 5.f)); - STATIC_REQUIRE(mix(vec2f(0.f,5.f), vec2f(10.f,20.f), vec2f(true,false)) == approx2(10.f, 5.f)); + STATIC_REQUIRE(lerp(vec2f(0.f), vec2f(10.f), 0.5f) == approx2(5.f)); + STATIC_REQUIRE(lerp(vec2f(0.f), vec2f(10.f), vec2f(0.5f)) == approx2(5.f)); STATIC_REQUIRE(step(0.5f, vec2f(0.4f)) == approx2(0.f)); STATIC_REQUIRE(step(0.5f, vec2f(0.6f)) == approx2(1.f));