From e64f93044bf72b49fbd7ea0e4c5256d63c42d52a Mon Sep 17 00:00:00 2001
From: Michael Wedel <michael.wedel@psi.ch>
Date: Thu, 19 Feb 2015 15:09:59 +0100
Subject: [PATCH] Refs #11104. Not giving up on setIntensity so quickly

If intensity is 0, we first try to set height to a different, arbitrary value, following Roman's suggestion. If it's still 0 after that, there's nothing left to do.
---
 Code/Mantid/Framework/API/src/IPeakFunction.cpp     | 13 +++++++++++--
 .../Framework/CurveFitting/test/GaussianTest.h      |  7 +++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/Code/Mantid/Framework/API/src/IPeakFunction.cpp b/Code/Mantid/Framework/API/src/IPeakFunction.cpp
index f5995bf995b..07053b760fd 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 e7bc607d789..ee2a682fdf6 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);
   }
 
 
-- 
GitLab