Commit 363864f4 authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Add method to round single HKL value

Also use std::round over boost::iround in Peak
Refs #26829
parent c805cf06
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "MantidKernel/System.h" #include "MantidKernel/System.h"
#include "boost/make_shared.hpp" #include "boost/make_shared.hpp"
#include <boost/math/special_functions/round.hpp>
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
...@@ -807,16 +806,14 @@ void Peak::setHKL(const Mantid::Kernel::V3D &HKL) { ...@@ -807,16 +806,14 @@ void Peak::setHKL(const Mantid::Kernel::V3D &HKL) {
* @param HKL :: vector with integer x,y,z -> h,k,l * @param HKL :: vector with integer x,y,z -> h,k,l
*/ */
void Peak::setIntHKL(V3D HKL) { void Peak::setIntHKL(V3D HKL) {
m_intHKL = V3D(boost::math::iround(HKL[0]), boost::math::iround(HKL[1]), m_intHKL = V3D(std::round(HKL[0]), std::round(HKL[1]), std::round(HKL[2]));
boost::math::iround(HKL[2]));
} }
/** Sets the modulated peak structure number /** Sets the modulated peak structure number
* @param MNP :: modulated peak structure value * @param MNP :: modulated peak structure value
*/ */
void Peak::setIntMNP(const V3D &MNP) { void Peak::setIntMNP(const V3D &MNP) {
m_intMNP = V3D(boost::math::iround(MNP[0]), boost::math::iround(MNP[1]), m_intMNP = V3D(std::round(MNP[0]), std::round(MNP[1]), std::round(MNP[2]));
boost::math::iround(MNP[2]));
} }
/** Set sample position /** Set sample position
......
...@@ -147,6 +147,9 @@ public: ...@@ -147,6 +147,9 @@ public:
double required_tolerance, double len_tol, double required_tolerance, double len_tol,
double ang_tol); double ang_tol);
/// Round all the components of a HKL objects to the nearest integer
static void RoundHKL(Kernel::V3D &hkl);
/// Round all the components of a list of V3D objects, to the nearest integer /// Round all the components of a list of V3D objects, to the nearest integer
static void RoundHKLs(std::vector<Kernel::V3D> &hkl_list); static void RoundHKLs(std::vector<Kernel::V3D> &hkl_list);
......
...@@ -2099,6 +2099,16 @@ void IndexingUtils::DiscardDuplicates(std::vector<V3D> &new_list, ...@@ -2099,6 +2099,16 @@ void IndexingUtils::DiscardDuplicates(std::vector<V3D> &new_list,
directions.clear(); directions.clear();
} }
/**
Round all of the components of the V3D to the nearest integer.
@param hkl_list Vector of V3D objects whose components will be rounded.
*/
void IndexingUtils::RoundHKL(Mantid::Kernel::V3D &hkl) {
for (size_t i = 0; i < 3; i++) {
hkl[i] = std::round(hkl[i]);
}
}
/** /**
Round all of the components of all vectors to the nearest integer. This Round all of the components of all vectors to the nearest integer. This
is useful when the vectors in the list represent Miller indices. Since is useful when the vectors in the list represent Miller indices. Since
...@@ -2110,9 +2120,7 @@ void IndexingUtils::DiscardDuplicates(std::vector<V3D> &new_list, ...@@ -2110,9 +2120,7 @@ void IndexingUtils::DiscardDuplicates(std::vector<V3D> &new_list,
*/ */
void IndexingUtils::RoundHKLs(std::vector<V3D> &hkl_list) { void IndexingUtils::RoundHKLs(std::vector<V3D> &hkl_list) {
for (auto &entry : hkl_list) { for (auto &entry : hkl_list) {
for (size_t i = 0; i < 3; i++) { RoundHKL(entry);
entry[i] = std::round(entry[i]);
}
} }
} }
......
...@@ -494,6 +494,20 @@ public: ...@@ -494,6 +494,20 @@ public:
TS_ASSERT_DELTA(new_list[4].norm(), 9.93006, 1e-4); TS_ASSERT_DELTA(new_list[4].norm(), 9.93006, 1e-4);
} }
void test_RoundHKL() {
V3D hkl(-1.234, 0.345, 7.5765);
IndexingUtils::RoundHKL(hkl);
TS_ASSERT_EQUALS(V3D(-1, 0, 8), hkl)
}
void test_RoundHKLs() {
std::vector<V3D> hkls{V3D(-1.234, 0.345, 7.5765),
V3D(3.5345, -1.346, 0.2347)};
IndexingUtils::RoundHKLs(hkls);
TS_ASSERT_EQUALS(V3D(-1, 0, 8), hkls[0])
TS_ASSERT_EQUALS(V3D(4, -1, 0), hkls[1])
}
void test_ValidIndex() { void test_ValidIndex() {
V3D hkl(0, 0, 0); V3D hkl(0, 0, 0);
TS_ASSERT_EQUALS(IndexingUtils::ValidIndex(hkl, 0.1), false); TS_ASSERT_EQUALS(IndexingUtils::ValidIndex(hkl, 0.1), false);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment