diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/MDGeometry.h b/Code/Mantid/Framework/API/inc/MantidAPI/MDGeometry.h index 33a0804517ca1b926ee94e8994fd8db42154dd4f..4b4a60750661406e54d55011595fab6cd5176a2c 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/MDGeometry.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/MDGeometry.h @@ -80,6 +80,7 @@ public: Mantid::Kernel::VMD &getBasisVector(size_t index); const Mantid::Kernel::VMD &getBasisVector(size_t index) const; void setBasisVector(size_t index, const Mantid::Kernel::VMD &vec); + bool allBasisNormalized() const; // -------------------------------------------------------------------------------------------- bool hasOriginalWorkspace(size_t index = 0) const; diff --git a/Code/Mantid/Framework/API/src/MDGeometry.cpp b/Code/Mantid/Framework/API/src/MDGeometry.cpp index 2a1bd0b46e99f7aa37579ed42b0078f359c8869d..044635dcc2a728a8219f89f9084d06f3aedda655 100644 --- a/Code/Mantid/Framework/API/src/MDGeometry.cpp +++ b/Code/Mantid/Framework/API/src/MDGeometry.cpp @@ -279,6 +279,17 @@ void MDGeometry::setBasisVector(size_t index, const Mantid::Kernel::VMD &vec) { m_basisVectors[index] = vec; } +bool MDGeometry::allBasisNormalized() const { + bool allNormalized = true; + for (auto it = m_basisVectors.begin(); it != m_basisVectors.end(); ++it) { + if (it->length() != 1.0) { + allNormalized = false; + break; + } + } + return allNormalized; +} + //--------------------------------------------------------------------------------------------------- /// @return true if the geometry is defined relative to another workspace. /// @param index :: index into the vector of original workspaces diff --git a/Code/Mantid/Framework/API/test/MDGeometryTest.h b/Code/Mantid/Framework/API/test/MDGeometryTest.h index 15f35676ff5c379e2ff2ef012438e86d3176f9ab..8262b3c3475fda17d6bdaf96437fef3e696c5a4d 100644 --- a/Code/Mantid/Framework/API/test/MDGeometryTest.h +++ b/Code/Mantid/Framework/API/test/MDGeometryTest.h @@ -256,6 +256,29 @@ public: TSM_ASSERT_EQUALS("Wrong number of transforms to original reported.", 2, g.getNumberTransformsToOriginal()); } + void test_all_normalized(){ + MDGeometry geometry; + std::vector<IMDDimension_sptr> dims; + IMDDimension_sptr dim1(new MDHistoDimension("Qx", "Qx", "Ang", -1, +1, 10)); + IMDDimension_sptr dim2(new MDHistoDimension("Qy", "Qy", "Ang", -1, +1, 20)); + dims.push_back(dim1); + dims.push_back(dim2); + geometry.initGeometry(dims); + + // Both basis vectors are not normalized + geometry.setBasisVector(0, VMD(2.0, 0.0)); + geometry.setBasisVector(1, VMD(0.0, 4.0)); + TSM_ASSERT("All Not all basis vectors are normalized", !geometry.allBasisNormalized()); + + // First basis vector is now normalized. The other is not. + geometry.setBasisVector(1, VMD(0.0, 1.0)); + TSM_ASSERT("Not all basis vectors are normalized", !geometry.allBasisNormalized()); + + // We overwrite the zeroth basis vector to be normalized. Now both are normalized + geometry.setBasisVector(0, VMD(1.0, 0.0)); + TSM_ASSERT("All basis vectors are normalized", geometry.allBasisNormalized()); + } + };