-
Notifications
You must be signed in to change notification settings - Fork 944
Description
When we are introduced to trilinear_interp
, it is a function outside of the perlin
class (listing 33):
raytracing.github.io/books/RayTracingTheNextWeek.html
Lines 1597 to 1611 in 80a955b
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).
raytracing.github.io/books/RayTracingTheNextWeek.html
Lines 1842 to 1865 in 80a955b
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
raytracing.github.io/src/common/perlin.h
Lines 100 to 116 in 80a955b
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