aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-05-19 18:32:22 +0200
committerThomas White <taw@physics.org>2012-02-22 15:27:27 +0100
commit190be719f2bae938e8dabe0b1ef9eb6d25acd47f (patch)
tree35c81adf57ce89f66c0e5b36e0fcc3e61eacd657
parent1a452bc91890a03ffe58fd97ae88253ece720918 (diff)
Use vector types in match_cell_ab(), and correct left handed cells
-rw-r--r--src/cell.c63
1 files changed, 25 insertions, 38 deletions
diff --git a/src/cell.c b/src/cell.c
index b1579251..ff9ff3d9 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -844,9 +844,7 @@ UnitCell *match_cell(UnitCell *cell, UnitCell *template, int verbose,
}
-/* FIXME: Unify with proper match_cell(), or work out if it's even possible.
- * FIXME: Negative vectors are allowable, but keep a right-handed unit cell.
- * FIXME: Make sure unit cell is right handed. */
+/* FIXME: Unify with proper match_cell(), or work out if it's even possible. */
UnitCell *match_cell_ab(UnitCell *cell, UnitCell *template)
{
double ax, ay, az;
@@ -855,16 +853,13 @@ UnitCell *match_cell_ab(UnitCell *cell, UnitCell *template)
int i;
double lengths[3];
int used[3];
- double real_ax, real_ay, real_az;
- double real_bx, real_by, real_bz;
- double real_cx, real_cy, real_cz;
- double params[3][3];
+ struct rvec real_a, real_b, real_c;
+ struct rvec params[3];
double alen, blen, clen;
float ltl = 5.0; /* percent */
int have_real_a;
int have_real_b;
int have_real_c;
- UnitCell *new_cell;
/* Get the lengths to match */
if ( cell_get_cartesian(template, &ax, &ay, &az,
@@ -889,53 +884,43 @@ UnitCell *match_cell_ab(UnitCell *cell, UnitCell *template)
lengths[0] = modulus(ax, ay, az);
lengths[1] = modulus(bx, by, bz);
lengths[2] = modulus(cx, cy, cz);
- used[0] = 0;
- used[1] = 0;
- used[2] = 0;
- params[0][0] = ax; params[0][1] = ay; params[0][2] = az;
- params[1][0] = bx; params[1][1] = by; params[1][2] = bz;
- params[2][0] = cx; params[2][1] = cy; params[2][2] = cz;
+ used[0] = 0; used[1] = 0; used[2] = 0;
+ params[0].u = ax; params[0].v = ay; params[0].w = az;
+ params[1].u = bx; params[1].v = by; params[1].w = bz;
+ params[2].u = cx; params[2].v = cy; params[2].w = cz;
- real_ax = 0.0; real_ay = 0.0; real_az = 0.0;
- real_bx = 0.0; real_by = 0.0; real_bz = 0.0;
- real_cx = 0.0; real_cy = 0.0; real_cz = 0.0;
+ real_a.u = 0.0; real_a.v = 0.0; real_a.w = 0.0;
+ real_b.u = 0.0; real_b.v = 0.0; real_b.w = 0.0;
+ real_c.u = 0.0; real_c.v = 0.0; real_c.w = 0.0;
/* Check each vector against a and b */
have_real_a = 0;
have_real_b = 0;
for ( i=0; i<3; i++ ) {
- if ( within_tolerance(lengths[i], alen, ltl) && !used[i]
- && !have_real_a )
+ if ( within_tolerance(lengths[i], alen, ltl)
+ && !used[i] && !have_real_a )
{
used[i] = 1;
- real_ax = params[i][0];
- real_ay = params[i][1];
- real_az = params[i][2];
+ memcpy(&real_a, &params[i], sizeof(struct rvec));
have_real_a = 1;
}
- if ( within_tolerance(lengths[i], blen, ltl) && !used[i]
- && !have_real_b )
+ if ( within_tolerance(lengths[i], blen, ltl)
+ && !used[i] && !have_real_b )
{
used[i] = 1;
- real_bx = params[i][0];
- real_by = params[i][1];
- real_bz = params[i][2];
+ memcpy(&real_b, &params[i], sizeof(struct rvec));
have_real_b = 1;
}
}
/* Have we matched both a and b? */
- if ( !(have_real_a && have_real_b) ) {
- return NULL;
- }
+ if ( !(have_real_a && have_real_b) ) return NULL;
/* "c" is "the other one" */
have_real_c = 0;
for ( i=0; i<3; i++ ) {
if ( !used[i] ) {
- real_cx = params[i][0];
- real_cy = params[i][1];
- real_cz = params[i][2];
+ memcpy(&real_c, &params[i], sizeof(struct rvec));
have_real_c = 1;
}
}
@@ -946,12 +931,14 @@ UnitCell *match_cell_ab(UnitCell *cell, UnitCell *template)
return NULL;
}
- new_cell = cell_new();
- cell_set_cartesian(new_cell, real_ax, real_ay, real_az,
- real_bx, real_by, real_bz,
- real_cx, real_cy, real_cz);
+ /* Flip c if not right-handed */
+ if ( !right_handed(real_a, real_b, real_c) ) {
+ real_c.u = -real_c.u;
+ real_c.v = -real_c.v;
+ real_c.w = -real_c.w;
+ }
- return new_cell;
+ return cell_new_from_direct_axes(real_a, real_b, real_c);
}