Skip to content

trilinear_interp is inconsistent between listings and src #722

@rjkilpatrick

Description

@rjkilpatrick

When we are introduced to trilinear_interp, it is a function outside of the perlin class (listing 33):

inline double trilinear_interp(double c[2][2][2], double u, double v, double w) {
auto accum = 0.0;
for (int i=0; i < 2; i++)
for (int j=0; j < 2; j++)
for (int k=0; k < 2; k++)
accum += (i*u + (1-i)*(1-u))*
(j*v + (1-j)*(1-v))*
(k*w + (1-k)*(1-w))*c[i][j][k];
return accum;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
class perlin {

However, when later amended (listing 39), it is moved into the class and marked with const (only valid for class member functions).

class perlin {
...
private:
...
inline double perlin_interp(vec3 c[2][2][2], double u, double v, double w) const {
auto uu = u*u*(3-2*u);
auto vv = v*v*(3-2*v);
auto ww = w*w*(3-2*w);
auto accum = 0.0;
for (int i=0; i < 2; i++)
for (int j=0; j < 2; j++)
for (int k=0; k < 2; k++) {
vec3 weight_v(u-i, v-j, w-k);
accum += (i*uu + (1-i)*(1-uu))
* (j*vv + (1-j)*(1-vv))
* (k*ww + (1-k)*(1-ww))
* dot(c[i][j][k], weight_v);
}
return accum;
}
...
}

In the src directory, the const is missing but it's given a static

inline static double perlin_interp(vec3 c[2][2][2], double u, double v, double w) {
auto uu = u*u*(3-2*u);
auto vv = v*v*(3-2*v);
auto ww = w*w*(3-2*w);
auto accum = 0.0;
for (int i=0; i < 2; i++)
for (int j=0; j < 2; j++)
for (int k=0; k < 2; k++) {
vec3 weight_v(u-i, v-j, w-k);
accum += (i*uu + (1-i)*(1-uu))*
(j*vv + (1-j)*(1-vv))*
(k*ww + (1-k)*(1-ww))*dot(c[i][j][k], weight_v);
}
return accum;
}

I propose changing listing 33 to a private member function for consistency.

Can someone advise about which function signature (i.e. static and/or const) should be the authoritative version? I can then put a PR together

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions