aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-09-19 00:41:27 +0200
committerThomas White <taw@physics.org>2012-02-22 15:26:58 +0100
commit35338e838250e9e745a94e82696ac6dae5531c0d (patch)
tree5d54abbedbb082881b535241b6e14d4473134d65 /src
parent369ca66599307c119db481b4b5585f38d01417ad (diff)
cubeit: Fix interpolation
Diffstat (limited to 'src')
-rw-r--r--src/cubeit.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/cubeit.c b/src/cubeit.c
index 587aafdb..9dd01953 100644
--- a/src/cubeit.c
+++ b/src/cubeit.c
@@ -89,8 +89,12 @@ static void interpolate_linear(double *vals, double v,
double val1, val2;
float f, c;
- c = (zv+0.5)*(float)(zs-1);
+ c = (zv+0.5)*(float)zs;
k = (int)c;
+ if ( k == zs ) {
+ /* Intensity belongs entirely to the next reflection */
+ return;
+ }
f = c - (float)k;
assert(f >= 0.0);
assert(k+1 <= zs);
@@ -99,7 +103,7 @@ static void interpolate_linear(double *vals, double v,
val2 = v*f;
vals[xs*ys*k + xs*yv + xv] += val1;
- /* If "zv" is right at the edge, then f=0.0 and ks=zs */
+ /* Intensity may belong to the next reflection along */
if ( k+1 < zs ) {
vals[xs*ys*(k+1) + xs*yv + xv] += val2;
}
@@ -114,8 +118,12 @@ static void interpolate_bilinear(double *vals, double v,
double val1, val2;
float f, c;
- c = (yv+0.5)*(float)(ys-1);
+ c = (yv+0.5)*(float)ys;
k = (int)c;
+ if ( k == ys ) {
+ /* Intensity belongs entirely to the next reflection */
+ return;
+ }
f = c - (float)k;
assert(f >= 0.0);
assert(k+1 <= ys);
@@ -124,7 +132,7 @@ static void interpolate_bilinear(double *vals, double v,
val2 = v*f;
interpolate_linear(vals, val1, xs, ys, zs, xv, k, zv);
- /* If "yv" is right at the edge, then f=0.0 and ks=ys */
+ /* Intensity may belong to the next reflection along */
if ( k+1 < ys ) {
interpolate_linear(vals, val2, xs, ys, zs, xv, k+1, zv);
}
@@ -139,8 +147,12 @@ static void interpolate_onto_grid(double *vals, double v,
double val1, val2;
float f, c;
- c = (xv+0.5)*(float)(xs-1);
+ c = (xv+0.5)*(float)xs;
k = (int)c;
+ if ( k == xs ) {
+ /* Intensity belongs entirely to the next reflection */
+ return;
+ }
f = c - (float)k;
assert(f >= 0.0);
assert(k+1 <= xs);
@@ -149,7 +161,7 @@ static void interpolate_onto_grid(double *vals, double v,
val2 = v*f;
interpolate_bilinear(vals, val1, xs, ys, zs, k, yv, zv);
- /* If "xv" is right at the edge, then f=0.0 and ks=xs */
+ /* Intensity may belong to the next reflection along */
if ( k+1 < xs ) {
interpolate_bilinear(vals, val2, xs, ys, zs, k+1, yv, zv);
}