Skip to content

Commit

Permalink
Fix function that expands box limits.
Browse files Browse the repository at this point in the history
It was ignoring the initial sign of the value and so sometimes the value
would move in the wrong direction.
Refs #11056
  • Loading branch information
martyngigg committed Mar 9, 2016
1 parent 192a80c commit 5209c40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"
#include "MantidKernel/UnitLabel.h"

#include <cmath>

namespace Mantid {
namespace Geometry {

Expand Down Expand Up @@ -33,11 +35,11 @@ class MANTID_GEOMETRY_DLL MDHistoDimensionBuilder {
// Always use minimum float value as DBL_EPS is always too small
static constexpr CoordT twoEps = 2 * std::numeric_limits<float>::epsilon();
if (std::fabs(min) > twoEps)
min *= (1 + twoEps);
min *= (1 - std::copysign(twoEps, min));
else
min -= twoEps;
if (std::fabs(max) > twoEps)
max *= (1 + twoEps);
max *= (1 + std::copysign(twoEps, max));
else
max += twoEps;
}
Expand Down
22 changes: 19 additions & 3 deletions Framework/Geometry/test/MDHistoDimensionBuilderTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@ using Mantid::Geometry::IMDDimension_sptr;

class MDHistoDimensionBuilderTest : public CxxTest::TestSuite {
public:
void test_resizeToFit() {
void test_resizeToFit_Min_Positive_Max_Positive() {
const Mantid::coord_t min0(0.1f), max0(0.5f);
Mantid::coord_t min1(min0), max1(max0);
MDHistoDimensionBuilder::resizeToFitMDBox(min1, max1);
TS_ASSERT(min1 < min0);
TS_ASSERT(max1 > max0);
}

void test_resizeToFit_Min_Negative_Max_Positive() {
const Mantid::coord_t min0(-0.1f), max0(0.5f);
Mantid::coord_t min1(min0), max1(max0);
MDHistoDimensionBuilder::resizeToFitMDBox(min1, max1);
TS_ASSERT_DIFFERS(min1, min0);
TS_ASSERT_DIFFERS(max1, max0);
TS_ASSERT(min1 < min0);
TS_ASSERT(max1 > max0);
}

void test_resizeToFit_Min_Negative_Max_Negative() {
const Mantid::coord_t min0(-0.5f), max0(-0.1f);
Mantid::coord_t min1(min0), max1(max0);
MDHistoDimensionBuilder::resizeToFitMDBox(min1, max1);
TS_ASSERT(min1 < min0);
TS_ASSERT(max1 > max0);
}

void testConstructRaw() {
Expand Down

0 comments on commit 5209c40

Please sign in to comment.