瀏覽代碼

simplex_interpolator: compilation fixes + testing Interp function

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 11 年之前
父節點
當前提交
b65af37e7c
共有 2 個檔案被更改,包括 32 行新增17 行删除
  1. +6
    -7
      src/lol/math/simplex_interpolator.h
  2. +26
    -10
      src/t/math/simplex_interpolator.cpp

+ 6
- 7
src/lol/math/simplex_interpolator.h 查看文件

@@ -15,8 +15,7 @@
namespace lol namespace lol
{ {


template<int N, /* Dimension of the space */
typename T = float> /* Interpolated type */
template<int N>
class simplex_interpolator class simplex_interpolator
{ {
public: public:
@@ -38,7 +37,7 @@ public:
} }


// Single interpolation // Single interpolation
inline T Interp(vec_t<float, N> position) const
inline float Interp(vec_t<float, N> position) const
{ {
// Computing position in simplex referential // Computing position in simplex referential
vec_t<float, N> simplex_position = m_base_inverse * position; vec_t<float, N> simplex_position = m_base_inverse * position;
@@ -49,7 +48,7 @@ public:


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


vec_t<float, N> index_order = this->GetIndexOrder(decimal_point);
vec_t<int, N> index_order = this->GetIndexOrder(decimal_point);


// Resetting decimal point in regular orthonormal coordinates // Resetting decimal point in regular orthonormal coordinates
decimal_point = m_base * decimal_point; decimal_point = m_base * decimal_point;
@@ -59,9 +58,9 @@ public:


protected: protected:


inline T LastInterp(vec_t<int, N> const & floor_point,
inline float LastInterp(vec_t<int, N> & floor_point,
vec_t<float, N> const & decimal_point, vec_t<float, N> const & decimal_point,
vec_t<float, N> index_order) const
vec_t<int, N> index_order) const
{ {
vec_t<float, N> point_of_interest; vec_t<float, N> point_of_interest;
float result = 0; float result = 0;
@@ -83,7 +82,7 @@ protected:
return result; return result;
} }


inline vec_t<int, N> GetIndexOrder(vec_t<float, N> const & decimal_point)
inline vec_t<int, N> GetIndexOrder(vec_t<float, N> const & decimal_point) const
{ {
vec_t<int, N> result; vec_t<int, N> result;
for (int i = 0 ; i < N ; ++i) for (int i = 0 ; i < N ; ++i)


+ 26
- 10
src/t/math/simplex_interpolator.cpp 查看文件

@@ -19,13 +19,13 @@
namespace lol namespace lol
{ {


template<int N, typename T = float>
class test_interpolator : public simplex_interpolator<N, T>
template<int N>
class test_interpolator : public simplex_interpolator<N>
{ {
public: public:


test_interpolator() : test_interpolator() :
simplex_interpolator<N, T>()
simplex_interpolator<N>()
{ {
} }


@@ -86,7 +86,7 @@ public:


vec_t<int, N> GetIndexOrder(vec_t<float, N> const & decimal_point) vec_t<int, N> GetIndexOrder(vec_t<float, N> const & decimal_point)
{ {
return simplex_interpolator<N, T>::GetIndexOrder(decimal_point);
return simplex_interpolator<N>::GetIndexOrder(decimal_point);
} }
}; };


@@ -96,12 +96,6 @@ lolunit_declare_fixture(SimplexInterpolatorTest)


void TearDown() {} void TearDown() {}


// lolunit_declare_test(CompoundVariable)
// {
// test_interpolator<2, real> b({{ real(0) }});
// test_interpolator<2, vec2> c({{ vec2(0) }});
// }

template<int N> template<int N>
void check_base_matrix() void check_base_matrix()
{ {
@@ -210,6 +204,28 @@ lolunit_declare_fixture(SimplexInterpolatorTest)
check_index_ordering<10>(); check_index_ordering<10>();
} }


void check_sample_creation_order2()
{
static int gen = 12345678;

arraynd<2, vec_t<float, 2> > gradients(vec_t<ptrdiff_t, 2>({10, 10}));
for (int i = 0 ; i < 10 ; ++i)
{
for (int j = 0 ; j < 10 ; ++j)
{
float x1 = (gen = gen * gen + gen) % 255;
float x2 = (gen = gen * gen + gen) % 255;

vec_t<float, 2> v = {x1, x2};

gradients[i][j] = v;
}
}

simplex_interpolator<2> s;
s.SetGradients(gradients);
}

#if 0 #if 0
lolunit_declare_test(FloatGridPoints2D1x1) lolunit_declare_test(FloatGridPoints2D1x1)
{ {


Loading…
取消
儲存