From 58bfc9f886ed037eb89aed59f192489d68b4e653 Mon Sep 17 00:00:00 2001
From: Matthew D Jones <Matthew.D.Jones@tessella.com>
Date: Mon, 10 Aug 2015 15:44:04 +0100
Subject: [PATCH] Re #11422 Scale transformation now of correct form

---
 .../src/plot2D/PowerScaleEngine.cpp           | 33 ++++++++++++-------
 .../MantidPlot/src/plot2D/PowerScaleEngine.h  |  4 ++-
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.cpp b/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.cpp
index 04e2d11d390..5bd32be0915 100644
--- a/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.cpp
+++ b/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.cpp
@@ -4,7 +4,7 @@
     --------------------------------------------------------------------
     Copyright            : (C) 2009 by Ion Vasilief
     Email (use @ for *)  : ion_vasilief*yahoo.fr
-    Description          : Return a transformation for reciprocal (1/t) scales
+    Description          : Return a transformation for power (X^n) scales
 
  ***************************************************************************/
 
@@ -141,15 +141,6 @@ void PowerScaleEngine::buildTicks(
     for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
     {
         ticks[i] = strip(ticks[i], interval);
-
-        // ticks very close to 0.0 are
-        // explicitely set to 0.0
-
-        for ( int j = 0; j < (int)ticks[i].count(); j++ )
-        {
-            if ( QwtScaleArithmetic::compareEps(ticks[i][j], 0.0, stepSize) == 0 )
-                ticks[i][j] = 0.0;
-        }
     }
 }
 
@@ -244,15 +235,33 @@ QwtScaleTransformation *PowerScaleTransformation::copy() const
 	return new PowerScaleTransformation(d_engine);
 }
 
+/*
+ * Transform a value between 2 linear intervals
+ *
+ * \param s value related to the interval [s1, s2]
+ * \param s1 first border of scale interval
+ * \param s2 second border of scale interval
+ * \param p1 first border of target interval
+ * \param p2 second border of target interval
+ */
 double PowerScaleTransformation::xForm(
     double s, double s1, double s2, double p1, double p2) const
 {
-	return p1 + (p2 - p1) * s2 * (s1 - s)/(s * (s1 - s2));
+	return p1 + (p2 - p1) / (pow(s2, nth_power) - pow(s1, nth_power)) * (pow(s, nth_power) - pow(s1, nth_power));
 }
 
+/*
+ * Transform a value from a linear to a power scale interval
+ *
+ * \param p value related to the linear interval [p1, p2]
+ * \param p1 first border of linear interval
+ * \param p2 second border of linear interval
+ * \param s1 first border of logarithmic interval
+ * \param s2 second border of logarithmic interval
+ */
 double PowerScaleTransformation::invXForm(double p, double p1, double p2,
     double s1, double s2) const
 {
-	return s1*s2*(p2 - p1)/(s2*(p2 - p) + s1*(p - p1));
+	return pow((p - p1) / (p2 - p1) * (pow(s2, nth_power) - pow(s1, nth_power)), 1.0/nth_power) * s1;
 }
 
diff --git a/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h b/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h
index b910d4b9263..03602089d91 100644
--- a/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h
+++ b/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h
@@ -37,10 +37,12 @@
 class PowerScaleTransformation: public ScaleTransformation
 {
 public:
-	PowerScaleTransformation(const ScaleEngine *engine):ScaleTransformation(engine){};
+	PowerScaleTransformation(const ScaleEngine *engine):ScaleTransformation(engine){nth_power = 2.0;};
 	virtual double xForm(double x, double, double, double p1, double p2) const;
 	virtual double invXForm(double x, double s1, double s2, double p1, double p2) const;
 	QwtScaleTransformation* copy() const;
+private:
+  double nth_power;
 };
 
 /*!
-- 
GitLab