diff --git a/Code/Mantid/Framework/API/src/IPeakFunction.cpp b/Code/Mantid/Framework/API/src/IPeakFunction.cpp index f5995bf995bbe7eb9be9ab74ba8c4d35e4f7886c..07053b760fda6e59503cae3d84d4067ba2fb90b6 100644 --- a/Code/Mantid/Framework/API/src/IPeakFunction.cpp +++ b/Code/Mantid/Framework/API/src/IPeakFunction.cpp @@ -153,8 +153,17 @@ void IPeakFunction::setIntensity(const double newIntensity) { double currentIntensity = intensity(); if (currentIntensity == 0.0) { - throw std::invalid_argument( - "Cannot set new intensity, not enough information available."); + // Try to set a different height first. + setHeight(2.0); + + currentHeight = height(); + currentIntensity = intensity(); + + // If the current intensity is still 0, there's nothing left to do. + if (currentIntensity == 0.0) { + throw std::invalid_argument( + "Cannot set new intensity, not enough information available."); + } } setHeight(newIntensity / currentIntensity * currentHeight); diff --git a/Code/Mantid/Framework/CurveFitting/test/GaussianTest.h b/Code/Mantid/Framework/CurveFitting/test/GaussianTest.h index e7bc607d78989211b0b7c8f7b5664eda7e9173e8..ee2a682fdf6ac9c614ed4a267ee0b7348fc3b732 100644 --- a/Code/Mantid/Framework/CurveFitting/test/GaussianTest.h +++ b/Code/Mantid/Framework/CurveFitting/test/GaussianTest.h @@ -621,8 +621,15 @@ public: TS_ASSERT_EQUALS(fn->intensity(), 0.0); + // This does not work, because fwhm is 0 and height is 0 TS_ASSERT_THROWS(fn->setIntensity(20.0), std::invalid_argument); TS_ASSERT_EQUALS(fn->intensity(), 0.0); + + // Now, fwhm is not zero + fn->setFwhm(0.02); + + TS_ASSERT_THROWS_NOTHING(fn->setIntensity(20.0)); + TS_ASSERT_DELTA(fn->intensity(), 20.0, 1e-10); }