aboutsummaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-02-22 10:32:21 +0100
committerThomas White <taw@physics.org>2010-02-22 10:32:21 +0100
commitf86c9795c72d0a75692f010c0f3ef37f1c899eca (patch)
tree95f9f8e8e28836be63dc25691eb07ace81f03101 /src/index.c
parent79fcc8f0938f0d8056b7b745eb96b89d133a571e (diff)
Add find_panel() routine to clean up a lot of things
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/src/index.c b/src/index.c
index 49e21bb7..7439cf66 100644
--- a/src/index.c
+++ b/src/index.c
@@ -36,34 +36,20 @@ int map_position(struct image *image, double dx, double dy,
double d;
double twotheta, psi;
const double k = 1.0 / image->lambda;
- int p;
- int found = 0;
+ struct panel *p;
double x = 0.0;
double y = 0.0;
- /* Perform the detector mapping for these coordinates */
- for ( p=0; p<image->det.n_panels; p++ ) {
- if ( (dx >= image->det.panels[p].min_x)
- && (dx <= image->det.panels[p].max_x)
- && (dy >= image->det.panels[p].min_y)
- && (dy <= image->det.panels[p].max_y) ) {
- x = ((double)dx - image->det.panels[p].cx);
- y = ((double)dy - image->det.panels[p].cy);
- found = 1;
- break;
- }
- }
- if ( !found ) {
- ERROR("No mapping found for %f,%f (map_position)\n", dx, dy);
- *rx = 0.0; *ry = 0.0; *rz = 0.0;
- return 1;
- }
+ p = find_panel(&image->det, dx, dy);
+
+ x = ((double)dx - p->cx);
+ y = ((double)dy - p->cy);
/* Convert pixels to metres */
- x /= image->det.panels[p].res;
- y /= image->det.panels[p].res; /* Convert pixels to metres */
+ x /= p->res;
+ y /= p->res; /* Convert pixels to metres */
d = sqrt((x*x) + (y*y));
- twotheta = atan2(d, image->det.panels[p].clen);
+ twotheta = atan2(d, p->clen);
psi = atan2(y, x);