Skip to content

Commit

Permalink
refs #8794 Replaced vector by std::pair structure
Browse files Browse the repository at this point in the history
I am unsure about it, as the functional equivalent of this function for ConvertToMD methods would return more then 2 values. And some functional modifications of this method may also return more then 2 values. But after some thinking decide to make the change for the time being and then see if expansion is necessary.
  • Loading branch information
abuts committed Jan 31, 2014
1 parent 982ef22 commit a4c0ff5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Kernel/inc/MantidKernel/Unit.h
Expand Up @@ -167,7 +167,7 @@ class MANTID_KERNEL_DLL Unit
virtual double conversionTOFMax()const=0;

/**The range where conversion to TOF from given units is monotonic and reversible*/
virtual std::vector<double> conversionRange()const;
virtual std::pair<double,double> conversionRange()const;

protected:
// Add a 'quick conversion' for a unit pair
Expand Down
8 changes: 3 additions & 5 deletions Code/Mantid/Framework/Kernel/src/Unit.cpp
Expand Up @@ -161,14 +161,12 @@ double Unit::convertSingleFromTOF(const double xvalue, const double& l1, const d
return this->singleFromTOF(xvalue);
}

std::vector<double> Unit::conversionRange()const
std::pair<double,double> Unit::conversionRange()const
{
double u1=this->singleFromTOF(this->conversionTOFMin());
double u2=this->singleFromTOF(this->conversionTOFMax());
std::vector<double> range(2);
range[0] = std::min(u1,u2);
range[1] = std::max(u1,u2);
return range;
//
return std::pair<double,double>(std::min(u1,u2),std::max(u1,u2));
}

namespace Units
Expand Down
10 changes: 5 additions & 5 deletions Code/Mantid/Framework/Kernel/test/UnitTest.h
Expand Up @@ -36,8 +36,8 @@ std::string convert_units_check_range(const Unit &aUnit,std::vector<double> &sam


auto range = aUnit.conversionRange();
double tof1=aUnit.singleToTOF(range[0]);
double tof2=aUnit.singleToTOF(range[1]);
double tof1=aUnit.singleToTOF(range.first);
double tof2=aUnit.singleToTOF(range.second);
bool t_increases(true);
if (tof1>tof2)
t_increases=false;
Expand All @@ -61,16 +61,16 @@ std::string convert_units_check_range(const Unit &aUnit,std::vector<double> &sam

const size_t nSteps(100);

double step = (range[1]-range[0])/nSteps;
double step = (range.second-range.first)/nSteps;
if (step == std::numeric_limits<double>::infinity())
{
step =(DBL_MAX/nSteps)*2;
}

double t1 = aUnit.singleToTOF(range[0]);
double t1 = aUnit.singleToTOF(range.first);
for(size_t i=1;i<=nSteps;i++)
{
double unitVal=range[0]+double(i)*step;
double unitVal=range.first+double(i)*step;
double tofVal = aUnit.singleToTOF(unitVal);
if (t_increases)
{
Expand Down

0 comments on commit a4c0ff5

Please sign in to comment.