Skip to content
Snippets Groups Projects
Commit 0063ba44 authored by Owen Arnold's avatar Owen Arnold
Browse files

Merge pull request #14480 from mantidproject/14477_Fix_V2D_tolerance

Polygon Intersection Bug Fix
parents 6c42e5ba 8719ad2b
No related merge requests found
......@@ -191,6 +191,25 @@ public:
TS_ASSERT(!intersection(squareTwo, squareOne, overlap));
TS_ASSERT(!overlap.isValid());
}
void test_Overlap_Small_Polygon() {
V2D ll1(-1.06675e-06, 0.010364);
V2D lr1(-9.335e-07, 0.010364);
V2D ur1(-9.335e-07, 0.010376);
V2D ul1(-1.06675e-06, 0.010376);
Quadrilateral squareOne(ll1, lr1, ur1, ul1);
V2D ll2(-1.4650627e-06, 0.010410755);
V2D lr2(-7.4121856e-07, 0.01034716581);
V2D ur2(-7.43843122e-07, 0.0103851998);
V2D ul2(-1.47044797837e-06, 0.010449023);
Quadrilateral squareTwo(ll2, lr2, ur2, ul2);
ConvexPolygon overlap;
TS_ASSERT(intersection(squareOne, squareTwo, overlap));
TS_ASSERT(overlap.isValid());
}
};
//------------------------------------------------------------------------
......
......@@ -3,13 +3,19 @@
//-----------------------------------------------------------------------------
#include "MantidKernel/V2D.h"
#include "MantidKernel/V3D.h"
#include "MantidKernel/Tolerance.h"
#include "MantidKernel/Exception.h"
#include <limits>
#include <ostream>
namespace Mantid {
namespace Kernel {
namespace {
// Smallest possible double value
const double EPSILON = std::numeric_limits<double>::epsilon();
}
//-----------------------------------------------------------------------------
// Public member functions
//-----------------------------------------------------------------------------
......@@ -82,8 +88,8 @@ V2D &V2D::operator*=(const double factor) {
* @returns True if they are considered equal false otherwise
*/
bool V2D::operator==(const V2D &rhs) const {
return (std::fabs(m_x - rhs.m_x) < Tolerance &&
std::fabs(m_y - rhs.m_y) < Tolerance);
return (std::fabs(m_x - rhs.m_x) < EPSILON &&
std::fabs(m_y - rhs.m_y) < EPSILON);
}
/**
......
......@@ -6,10 +6,10 @@
//-----------------------------------------------------------------------------
#include "MantidKernel/V2D.h"
#include "MantidKernel/V3D.h"
#include "MantidKernel/Tolerance.h"
#include "MantidKernel/Exception.h"
#include <cxxtest/TestSuite.h>
#include <cfloat>
#include <limits>
using Mantid::Kernel::V2D;
using Mantid::Kernel::V3D;
......@@ -108,20 +108,20 @@ public:
}
void test_Equality_Gives_True_When_Diff_Less_Than_Tolerance() {
using Mantid::Kernel::Tolerance;
const double tolerance = std::numeric_limits<double>::epsilon();
V2D first(5, 10);
V2D second(5 + 0.5 * Tolerance, 10 - 0.5 * Tolerance);
V2D second(5 + 0.5 * tolerance, 10 - 0.5 * tolerance);
TS_ASSERT_EQUALS(first, second);
TS_ASSERT(!(first != second));
}
void test_Equality_Gives_False_When_Diff_More_Than_Tolerance() {
using Mantid::Kernel::Tolerance;
const double tolerance = std::numeric_limits<double>::epsilon();
V2D first(5, 10);
V2D second(5 + 0.5 * Tolerance, 11);
V2D second(5 + 0.5 * tolerance, 11);
TS_ASSERT(!(first == second));
second = V2D(6, 10 + 0.5 * Tolerance);
second = V2D(6, 10 + 0.5 * tolerance);
TS_ASSERT(!(first == second));
}
......@@ -197,6 +197,14 @@ public:
// Symmetric in arguments
TS_ASSERT_DELTA(second.angle(first), M_PI / 3.0, DBL_EPSILON);
}
void test_Equality_Operator() {
V2D first(1E-7, 0.1);
V2D second(1.5E-7, 0.1);
TS_ASSERT(first != second);
}
};
#endif // MANTID_KERNEL_V2DTEST_H_
f77e74c92f68c8b89f714c20ecab1ea7
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment