From b2671811b9fc5182fb6f8f4d59d42ded43d7720d Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Mon, 17 Nov 2014 15:39:55 +0000 Subject: [PATCH] simplex_interpolator: still refactoring --- src/lol/math/simplex_interpolator.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lol/math/simplex_interpolator.h b/src/lol/math/simplex_interpolator.h index c4f28be9..38fb63c2 100644 --- a/src/lol/math/simplex_interpolator.h +++ b/src/lol/math/simplex_interpolator.h @@ -43,7 +43,6 @@ public: this->ExtractFloorDecimal(simplex_position, floor_point, decimal_point); // Retrieving simplex samples to use - vec_t reference; int sign; this->GetReference(floor_point, decimal_point, reference, sign); @@ -53,22 +52,28 @@ public: protected: - inline T LastInterp(vec_t const & floor_point, vec_t const & decimal_point, vec_t const & reference, int const & sign) + inline T LastInterp(vec_t const & floor_point, vec_t const & decimal_point, int const & sign) { T result = 0; + T divider = 0; for (int i = 0 ; i < N ; ++i) { vec_t samples_index = floor_point; samples_index[i] = this->mod(samples_index[i] + sign, i); - result += (1 - decimal_point[i]) * this->samples[samples_index]; + result += decimal_point[i] * this->samples[samples_index]; + divider += decimal_point[i]; } + T floor_coeff = 0; for (int i = 0 ; i < N ; ++i) - result += samples[floor_point] * decimal_point[i]; + floor_coeff += (1 - decimal_point[i]); - return result / N; + result += (2 * sqrt(floor_coeff) / sqrt(N)) * this->samples[floor_point]; + divider += (2 * sqrt(floor_coeff) / sqrt(N)); + + return result / divider; } inline int Mod(int value, int index) @@ -76,7 +81,7 @@ protected: samples_index[index] %= this->samples.GetSize()[index]; } - inline void GetReference(vec_t & floor_point, vec_t & decimal_point, vec_t & reference, int & sign) + inline void GetReference(vec_t & floor_point, vec_t & decimal_point, int & sign) { // Choosing the reference point which determines in which simplex we are working // ie. (0, 0, 0, …) and upper or (this->diagonal) and lower @@ -89,12 +94,10 @@ protected: if (cumul < (sqrt(N) / 2)) { - reference = zeros; sign = 1; } else { - reference = ones; sign = -1; decimal_point = 1 - decimal_point; @@ -112,6 +115,7 @@ protected: for (int i = 0 ; i < N ; ++i) decimal_point[i] = simplex_position[i] - floor_point[i]; + // Never exceed the size of the samples and loop on it for (int i = 0 ; i < N ; ++i) floor_point[i] = this->Mod(floor_point[i], i); }