Просмотр исходного кода

simplex_interpolator: starting first test. Too tired, go to bed :)

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 10 лет назад
Родитель
Сommit
7e01c3afd7
2 измененных файлов: 15 добавлений и 7 удалений
  1. +10
    -7
      src/lol/math/simplex_interpolator.h
  2. +5
    -0
      src/t/math/simplex_interpolator.cpp

+ 10
- 7
src/lol/math/simplex_interpolator.h Просмотреть файл

@@ -31,14 +31,14 @@ public:
}

// Single interpolation
inline T interp(vec_t<T, N> position)
inline T Interp(vec_t<T, N> position)
{
// Computing position in simplex referential
vec_t<T, N> simplex_position = this->ToSimplexRef(position);

// Retrieving the closest floor point and decimals
vec_t<int, N> & floor_point;
vec_t<T, N> & decimal_point;
vec_t<int, N> floor_point;
vec_t<T, N> decimal_point;

this->ExtractFloorDecimal(simplex_position, floor_point, decimal_point);

@@ -60,7 +60,7 @@ protected:
for (int i = 0 ; i < N ; ++i)
{
vec_t<int, N> samples_index = floor_point;
samples_index[i] = this->mod(samples_index[i] + sign, i);
samples_index[i] = this->Mod(samples_index[i] + sign, i);

result += decimal_point[i] * this->samples[samples_index];
divider += decimal_point[i];
@@ -81,7 +81,7 @@ protected:
return value %= this->samples.GetSize()[index];
}

inline void GetReference(vec_t<T, N> & floor_point, vec_t<T, N> & decimal_point, int & sign)
inline void GetReference(vec_t<int, N> & floor_point, vec_t<T, N> & 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
@@ -100,8 +100,11 @@ protected:
{
sign = -1;

decimal_point = 1 - decimal_point;
floor_point += 1;
for (int i = 0 ; i < N ; ++i)
{
decimal_point[i] = 1 - decimal_point[i];
floor_point[i] += 1;
}
}
}



+ 5
- 0
src/t/math/simplex_interpolator.cpp Просмотреть файл

@@ -13,6 +13,7 @@
#include <lolunit.h>

// To be removed when fully tested
#include <iostream>
#include <lol/math/simplex_interpolator.h>
namespace lol
@@ -27,6 +28,10 @@ lolunit_declare_fixture(SimplexInterpolatorTest)
lolunit_declare_test(Interp2D)
{
simplex_interpolator<2> interpolator;

interpolator.GetSamples() = arraynd<2, float>({{1, 1, 2}, {1, 1, 2}, {2, 2, 2}});

std::cout << interpolator.Interp(vec_t<float, 2>{0, 0}) << std::endl;
}
};



Загрузка…
Отмена
Сохранить