From 59709a8fb3b3f39fef4b2f4e97ad1b25a9358c8a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 10 Jul 2023 11:59:42 +0200 Subject: Move rotate2d to utils --- libcrystfel/src/datatemplate.c | 27 +++++++++------------------ libcrystfel/src/utils.c | 9 +++++++++ libcrystfel/src/utils.h | 2 ++ 3 files changed, 20 insertions(+), 18 deletions(-) (limited to 'libcrystfel/src') 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 ------------------------------ */ -- cgit v1.2.3