aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2023-07-10 11:59:42 +0200
committerThomas White <taw@physics.org>2023-07-28 13:22:05 +0200
commit59709a8fb3b3f39fef4b2f4e97ad1b25a9358c8a (patch)
treea885b2eb0931c92e8a1e727dca942dbfd57a7aaa
parent4476b7b18e263a70356fa93b257e7a2a3439c569 (diff)
Move rotate2d to utils
-rw-r--r--libcrystfel/src/datatemplate.c27
-rw-r--r--libcrystfel/src/utils.c9
-rw-r--r--libcrystfel/src/utils.h2
3 files changed, 20 insertions, 18 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 8651d76e..2c689a43 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -2192,15 +2192,6 @@ static int group_center(DataTemplate *dtempl,
}
-static void rot(double *x, double *y, double cx, double cy, double ang)
-{
- double nx, ny;
- nx = cx + (*x-cx)*cos(ang) - (*y-cy)*sin(ang);
- ny = cy + (*x-cx)*sin(ang) + (*y-cy)*cos(ang);
- *x = nx; *y = ny;
-}
-
-
static int rotate_all_panels(DataTemplate *dtempl,
struct panel_group_template *group,
char axis, double ang,
@@ -2220,23 +2211,23 @@ static int rotate_all_panels(DataTemplate *dtempl,
switch ( axis )
{
case 'x':
- rot(&cnz_px, &p->cny, cz, cy, ang);
- rot(&p->fsz, &p->fsy, 0, 0, ang);
- rot(&p->ssz, &p->ssy, 0, 0, ang);
+ rotate2d(&cnz_px, &p->cny, cz, cy, ang);
+ rotate2d(&p->fsz, &p->fsy, 0, 0, ang);
+ rotate2d(&p->ssz, &p->ssy, 0, 0, ang);
p->cnz_offset = cnz_px * p->pixel_pitch;
break;
case 'y':
- rot(&p->cnx, &cnz_px, cx, cz, ang);
- rot(&p->fsx, &p->fsz, 0, 0, ang);
- rot(&p->ssx, &p->ssz, 0, 0, ang);
+ rotate2d(&p->cnx, &cnz_px, cx, cz, ang);
+ rotate2d(&p->fsx, &p->fsz, 0, 0, ang);
+ rotate2d(&p->ssx, &p->ssz, 0, 0, ang);
p->cnz_offset = cnz_px * p->pixel_pitch;
break;
case 'z':
- rot(&p->cnx, &p->cny, cx, cy, ang);
- rot(&p->fsx, &p->fsy, 0, 0, ang);
- rot(&p->ssx, &p->ssy, 0, 0, ang);
+ rotate2d(&p->cnx, &p->cny, cx, cy, ang);
+ rotate2d(&p->fsx, &p->fsy, 0, 0, ang);
+ rotate2d(&p->ssx, &p->ssy, 0, 0, ang);
break;
default:
diff --git a/libcrystfel/src/utils.c b/libcrystfel/src/utils.c
index 262a32cc..10e4c38e 100644
--- a/libcrystfel/src/utils.c
+++ b/libcrystfel/src/utils.c
@@ -470,6 +470,15 @@ void progress_bar(int val, int total, const char *text)
}
+void rotate2d(double *x, double *y, double cx, double cy, double ang)
+{
+ double nx, ny;
+ nx = cx + (*x-cx)*cos(ang) - (*y-cy)*sin(ang);
+ ny = cy + (*x-cx)*sin(ang) + (*y-cy)*cos(ang);
+ *x = nx; *y = ny;
+}
+
+
double random_flat(gsl_rng *rng, double max)
{
return max * gsl_rng_uniform(rng);
diff --git a/libcrystfel/src/utils.h b/libcrystfel/src/utils.h
index 6d2ff253..67940ad4 100644
--- a/libcrystfel/src/utils.h
+++ b/libcrystfel/src/utils.h
@@ -168,6 +168,8 @@ static inline int within_tolerance(double a, double b, double percent)
return 0;
}
+extern void rotate2d(double *x, double *y, double cx, double cy, double ang);
+
/* ----------------------------- Useful macros ------------------------------ */