Skip to content

Commit

Permalink
Merge pull request #22135 from mantidproject/22134_UnitCell_bug
Browse files Browse the repository at this point in the history
Fix numerical error in UnitCell/ OrientedLattice
  • Loading branch information
NickDraper authored Mar 19, 2018
2 parents 64d0870 + 4e41c90 commit 26e7693
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Framework/Geometry/src/Crystal/UnitCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,13 @@ double UnitCell::recAngle(double h1, double k1, double l1, double h2, double k2,
double E, ang;
Q1 = Gstar * Q1;
E = Q1.scalar_prod(Q2);
ang = acos(E / dstar(h1, k1, l1) / dstar(h2, k2, l2));
double temp = E / dstar(h1, k1, l1) / dstar(h2, k2, l2);
if (temp > 1)
ang = 0.;
else if (temp < -1)
ang = M_PI;
else
ang = acos(temp);
if (angleunit == angDegrees)
return rad2deg * ang;
else
Expand Down
6 changes: 6 additions & 0 deletions Framework/Geometry/test/UnitCellTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ class UnitCellTest : public CxxTest::TestSuite {
}
}

void testReciprocalAngle0() {
UnitCell cell(5.45, 5.45, 5.45);
TS_ASSERT_EQUALS(cell.recAngle(0., 4., 0., 0., 4., 0.), 0.);
TS_ASSERT_EQUALS(cell.recAngle(0., -4., 0., 0., 4., 0.), 180.);
}

void testStrToUnitCell() {
UnitCell cell(2.0, 4.0, 5.0, 90.0, 100.0, 102.0);
std::string cellString = unitCellToStr(cell);
Expand Down

0 comments on commit 26e7693

Please sign in to comment.