diff --git a/src/lol/math/simplex_interpolator.h b/src/lol/math/simplex_interpolator.h index 41a3f139..97825107 100644 --- a/src/lol/math/simplex_interpolator.h +++ b/src/lol/math/simplex_interpolator.h @@ -33,14 +33,14 @@ public: } // Single interpolation - inline T Interp(vec_t position) const + inline T Interp(vec_t position) const { // Computing position in simplex referential - vec_t simplex_position = m_base_inverse * position; + vec_t simplex_position = m_base_inverse * position; // Retrieving the closest floor point and decimals vec_t floor_point; - vec_t decimal_point; + vec_t decimal_point; this->ExtractFloorDecimal(simplex_position, floor_point, decimal_point); @@ -55,12 +55,12 @@ public: protected: inline T LastInterp(vec_t const & floor_point, - vec_t const & decimal_point, + vec_t const & decimal_point, int const & sign) const { - T result = 0; - T floor_coeff = 0; - T divider = 0; + T result(0); + float floor_coeff = 0; + float divider = 0; for (int i = 0 ; i < N ; ++i) { @@ -72,7 +72,7 @@ protected: divider += decimal_point[i]; } - T sqr_norm = N; + float sqr_norm = N; result += (1 - 2 * floor_coeff / sqr_norm) * this->m_samples[floor_point]; divider += (1 - 2 * floor_coeff / sqr_norm); @@ -87,12 +87,12 @@ protected: return ret >= 0 ? ret : ret + dim; } - inline void GetReference(vec_t & floor_point, vec_t & decimal_point, int & sign) const + inline void GetReference(vec_t & floor_point, vec_t & decimal_point, int & sign) const { // Choosing the reference point which determines in which simplex we are working // ie. (0, 0, 0, …) and upper or (1, 1, 1, …) and lower - T cumul = 0; + float cumul = 0; for (int i = 0 ; i < N ; ++i) cumul += decimal_point[i]; @@ -102,12 +102,12 @@ protected: { sign = -1; - decimal_point = vec_t(1) - decimal_point; + decimal_point = vec_t(1) - decimal_point; floor_point = floor_point + vec_t(1); } } - inline void ExtractFloorDecimal(vec_t const & simplex_position, vec_t & floor_point, vec_t & decimal_point) const + inline void ExtractFloorDecimal(vec_t const & simplex_position, vec_t & floor_point, vec_t & decimal_point) const { // Finding floor point index for (int i = 0 ; i < N ; ++i) @@ -140,7 +140,7 @@ protected: } } - mat_t m_base, m_base_inverse; + mat_t m_base, m_base_inverse; arraynd m_samples; }; diff --git a/src/t/math/simplex_interpolator.cpp b/src/t/math/simplex_interpolator.cpp index c97cee0c..818c00f4 100644 --- a/src/t/math/simplex_interpolator.cpp +++ b/src/t/math/simplex_interpolator.cpp @@ -23,7 +23,7 @@ lolunit_declare_fixture(SimplexInterpolatorTest) void TearDown() {} - lolunit_declare_test(GridPoints2D1x1) + lolunit_declare_test(FloatGridPoints2D1x1) { simplex_interpolator<2> s({{1.f}}); float val; @@ -48,6 +48,16 @@ lolunit_declare_fixture(SimplexInterpolatorTest) lolunit_assert_doubles_equal(1.f, val, 1e-5f); } + lolunit_declare_test(VectorGridPoints2D1x1) + { + simplex_interpolator<2, vec3> s({{vec3(1.f, 2.f, 3.f)}}); + + vec3 val = s.Interp(GridPoint2D(-1, 0)); + lolunit_assert_doubles_equal(1.f, val.x, 1e-5f); + lolunit_assert_doubles_equal(2.f, val.y, 1e-5f); + lolunit_assert_doubles_equal(3.f, val.z, 1e-5f); + } + lolunit_declare_test(GridPoints2D2x2) { simplex_interpolator<2> s({{1.f, 1.f}, {1.f, 2.f}});