Skip to content

Commit

Permalink
Refs #10280. Added V3R constructor from integer vector
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Sep 29, 2014
1 parent 79bd522 commit 71c37e6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Expand Up @@ -54,6 +54,8 @@ class MANTID_GEOMETRY_DLL V3R
public:
V3R();
V3R(const RationalNumber &x, const RationalNumber &y, const RationalNumber &z);
V3R(const std::vector<int> &vector);

V3R(const V3R &other);
V3R &operator =(const V3R &other);

Expand Down
12 changes: 12 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Crystal/V3R.cpp
Expand Up @@ -18,6 +18,18 @@ V3R::V3R(const RationalNumber &x, const RationalNumber &y, const RationalNumber
{
}

/// Constructor from an appropriately sized integer vector
V3R::V3R(const std::vector<int> &vector)
{
if(vector.size() != 3) {
throw Kernel::Exception::MisMatch<size_t>(vector.size(),3,"V3R(const std::vector<int> &vector)");
}

m_x = vector[0];
m_y = vector[1];
m_z = vector[2];
}

/// Copy constructor
V3R::V3R(const V3R &other) :
m_x(other.m_x), m_y(other.m_y), m_z(other.m_z)
Expand Down
9 changes: 9 additions & 0 deletions Code/Mantid/Framework/Geometry/test/V3RTest.h
Expand Up @@ -34,6 +34,15 @@ class V3RTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(rationalV3D.Y(), 0.5);
TS_ASSERT_EQUALS(rationalV3D.Z(), 2.0/3.0);

std::vector<int> good(3, 1);
V3R rationalIntVec(good);
TS_ASSERT_EQUALS(rationalIntVec.x(), 1);
TS_ASSERT_EQUALS(rationalIntVec.y(), 1);
TS_ASSERT_EQUALS(rationalIntVec.z(), 1);

std::vector<int> bad(4, 1);
TS_ASSERT_THROWS(V3R rationalIntVecBad(bad), Mantid::Kernel::Exception::MisMatch<size_t>);

// copy constructor
V3R copied(rational);
TS_ASSERT_EQUALS(copied.x(), rational.x());
Expand Down

0 comments on commit 71c37e6

Please sign in to comment.