BUILD_INDEX \
\
int s_xi = (int)pos.x, s_yi = (int)pos.y, s_zi = (int)pos.z; \
Real s_s1 = pos.x-(Real)s_xi, s_s0 = 1.-s_s1; \
Real s_t1 = pos.y-(Real)s_yi, s_t0 = 1.-s_t1; \
Real s_f1 = pos.z-(Real)s_zi, s_f0 = 1.-s_f1; \
\
if (pos.x < 0) { s_xi = 0; s_s0 = 1.0; s_s1 = 0.0; } \
if (pos.y < 0) { s_yi = 0; s_t0 = 1.0; s_t1 = 0.0; } \
if (pos.z < 0) { s_zi = 0; s_f0 = 1.0; s_f1 = 0.0; } \
if (s_xi >= size.x-1) { s_xi = size.x-2; s_s0 = 0.0; s_s1 = 1.0; } \
if (s_yi >= size.y-1) { s_yi = size.y-2; s_t0 = 0.0; s_t1 = 1.0; } \
if (size.z>1) { if (s_zi >= size.z-1) { s_zi = size.z-2; s_f0 = 0.0; s_f1 = 1.0; } }