Skip to content

Commit

Permalink
fix table column for vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
rboston628 committed Oct 11, 2024
1 parent 734a62f commit ccf0586
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
33 changes: 13 additions & 20 deletions Framework/DataObjects/inc/MantidDataObjects/TableColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,14 @@ inline bool TableColumn<API::Boolean>::compareVectors(const std::vector<API::Boo
/// Template specialisation for V3D for comparison
template <>
inline bool TableColumn<Kernel::V3D>::compareVectors(const std::vector<Kernel::V3D> &newVector, double tolerance,
bool const) const {
bool const nanEqual) const {
for (size_t i = 0; i < m_data.size(); i++) {
double dif_x = fabs(m_data[i].X() - newVector[i].X());
double dif_y = fabs(m_data[i].Y() - newVector[i].Y());
double dif_z = fabs(m_data[i].Z() - newVector[i].Z());
if (dif_x > tolerance || dif_y > tolerance || dif_z > tolerance) {
return false;
for (std::size_t xyz = 0; xyz < m_data[i].size(); xyz++) {
double left = m_data[i][xyz], right = newVector[i][xyz];
if (nanEqual && std::isnan(left) && isnan(right))
continue;
else if (!Kernel::withinAbsoluteDifference(left, right, tolerance))
return false;
}
}
return true;
Expand All @@ -328,22 +329,14 @@ inline bool TableColumn<API::Boolean>::compareVectorsRelError(const std::vector<
/// Template specialisation for V3D for comparison
template <>
inline bool TableColumn<Kernel::V3D>::compareVectorsRelError(const std::vector<Kernel::V3D> &newVector,
double tolerance, bool const) const {
double tolerance, bool const nanEqual) const {
for (size_t i = 0; i < m_data.size(); i++) {
double dif_x = fabs(m_data[i].X() - newVector[i].X());
double dif_y = fabs(m_data[i].Y() - newVector[i].Y());
double dif_z = fabs(m_data[i].Z() - newVector[i].Z());
double den_x = 0.5 * (fabs(m_data[i].X()) + fabs(newVector[i].X()));
double den_y = 0.5 * (fabs(m_data[i].X()) + fabs(newVector[i].X()));
double den_z = 0.5 * (fabs(m_data[i].X()) + fabs(newVector[i].X()));
if (den_x > tolerance || den_y > tolerance || den_z > tolerance) {
if (dif_x / den_x > tolerance || dif_y / den_y > tolerance || dif_z / den_z > tolerance) {
return false;
}
} else {
if (dif_x > tolerance || dif_y > tolerance || dif_z > tolerance) {
for (std::size_t xyz = 0; xyz < m_data[i].size(); xyz++) {
double left = m_data[i][xyz], right = newVector[i][xyz];
if (nanEqual && std::isnan(left) && isnan(right))
continue;
else if (!Kernel::withinRelativeDifference(m_data[i][xyz], newVector[i][xyz], tolerance))
return false;
}
}
}
return true;
Expand Down
6 changes: 6 additions & 0 deletions Framework/Kernel/inc/MantidKernel/V3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class MANTID_KERNEL_DLL V3D final {
// explicit conversion into vector
operator std::vector<double>() const { return std::vector<double>(m_pt.cbegin(), m_pt.cend()); }

/**
Number of components in V3D
@return 3
*/
std::size_t size() const noexcept { return m_pt.size(); }

/**
Addtion operator
@param v :: Vector to add
Expand Down
1 change: 1 addition & 0 deletions Framework/Kernel/test/V3DTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class V3DTest : public CxxTest::TestSuite {
Mantid::Kernel::V3D a, b, c, d;

public:
void testSize() { TS_ASSERT_EQUALS(a.size(), 3); }
void testEmptyConstructor() {
// very important as a MD geometry rely on it later
TS_ASSERT_EQUALS(a.X(), 0.0);
Expand Down

0 comments on commit ccf0586

Please sign in to comment.