aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils.c106
-rw-r--r--src/utils.h37
2 files changed, 23 insertions, 120 deletions
diff --git a/src/utils.c b/src/utils.c
index 034a2b2d..d5e1b874 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -16,50 +16,6 @@
#include "utils.h"
-/* Return the MOST POSITIVE of two numbers */
-unsigned int biggest(signed int a, signed int b)
-{
- if ( a>b ) {
- return a;
- }
- return b;
-}
-
-
-/* Return the LEAST POSITIVE of two numbers */
-unsigned int smallest(signed int a, signed int b)
-{
- if ( a<b ) {
- return a;
- }
- return b;
-}
-
-
-double distance(double x1, double y1, double x2, double y2)
-{
- return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
-}
-
-
-double modulus(double x, double y, double z)
-{
- return sqrt(x*x + y*y + z*z);
-}
-
-
-double modulus_squared(double x, double y, double z) {
- return x*x + y*y + z*z;
-}
-
-
-double distance3d(double x1, double y1, double z1,
- double x2, double y2, double z2)
-{
- return modulus(x1-x2, y1-y2, z1-z2);
-}
-
-
/* Angle between two vectors. Answer in radians */
double angle_between(double x1, double y1, double z1,
double x2, double y2, double z2)
@@ -70,26 +26,6 @@ double angle_between(double x1, double y1, double z1,
}
-/* As above, answer in degrees */
-double angle_between_d(double x1, double y1, double z1,
- double x2, double y2, double z2)
-{
- return rad2deg(angle_between(x1, y1, z1, x2, y2, z2));
-}
-
-
-/* Wavelength of an electron (in m) given accelerating potential (in V) */
-double lambda(double V)
-{
- double m = 9.110E-31;
- double h = 6.625E-34;
- double e = 1.60E-19;
- double c = 2.998E8;
-
- return h / sqrt(2*m*e*V*(1+((e*V) / (2*m*c*c))));
-}
-
-
size_t skipspace(const char *s)
{
size_t i;
@@ -117,48 +53,6 @@ void chomp(char *s)
}
-int sign(double a)
-{
- if ( a < 0 ) return -1;
- if ( a > 0 ) return +1;
- return 0;
-}
-
-
-void mapping_rotate(double x, double y, double z,
- double *ddx, double *ddy, double *ddz,
- double omega, double tilt)
-{
- double nx, ny, nz;
- double x_temp, y_temp, z_temp;
-
- /* First: rotate image clockwise until tilt axis is aligned
- * horizontally. */
- nx = x*cos(omega) + y*sin(omega);
- ny = -x*sin(omega) + y*cos(omega);
- nz = z;
-
- /* Now, tilt about the x-axis ANTICLOCKWISE around +x, i.e. the
- * "wrong" way. This is because the crystal is rotated in the
- * experiment, not the Ewald sphere. */
- x_temp = nx; y_temp = ny; z_temp = nz;
- nx = x_temp;
- ny = cos(tilt)*y_temp + sin(tilt)*z_temp;
- nz = -sin(tilt)*y_temp + cos(tilt)*z_temp;
-
- /* Finally, reverse the omega rotation to restore the location of the
- * image in 3D space */
- x_temp = nx; y_temp = ny; z_temp = nz;
- nx = x_temp*cos(-omega) + y_temp*sin(-omega);
- ny = -x_temp*sin(-omega) + y_temp*cos(-omega);
- nz = z_temp;
-
- *ddx = nx;
- *ddy = ny;
- *ddz = nz;
-}
-
-
void progress_bar(int val, int total)
{
double frac;
diff --git a/src/utils.h b/src/utils.h
index 8e9fb6cc..9e6458cf 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -48,26 +48,35 @@ struct quaternion
};
-extern unsigned int biggest(signed int a, signed int b);
-extern unsigned int smallest(signed int a, signed int b);
-extern double distance(double x1, double y1, double x2, double y2);
-extern double modulus(double x, double y, double z);
-extern double modulus_squared(double x, double y, double z);
+/* --------------------------- Useful functions ----------------------------- */
+
extern double angle_between(double x1, double y1, double z1,
double x2, double y2, double z2);
-extern double angle_between_d(double x1, double y1, double z1,
- double x2, double y2, double z2);
-extern double lambda(double voltage);
-extern double distance3d(double x1, double y1, double z1,
- double x2, double y2, double z2);
extern size_t skipspace(const char *s);
extern void chomp(char *s);
-extern int sign(double a);
-extern void mapping_rotate(double x, double y, double z,
- double *ddx, double *ddy, double *ddz,
- double omega, double tilt);
extern void progress_bar(int val, int total);
+/* Keep these ones inline, to avoid function call overhead */
+static inline double distance(double x1, double y1, double x2, double y2)
+{
+ return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
+}
+
+static inline double modulus(double x, double y, double z)
+{
+ return sqrt(x*x + y*y + z*z);
+}
+
+static inline double modulus_squared(double x, double y, double z) {
+ return x*x + y*y + z*z;
+}
+
+static inline double distance3d(double x1, double y1, double z1,
+ double x2, double y2, double z2)
+{
+ return modulus(x1-x2, y1-y2, z1-z2);
+}
+
/* ----------------------------- Useful macros ------------------------------ */