-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re #11422 Implement functions for scaling transformations
- Loading branch information
Matthew D Jones
authored and
Matthew D Jones
committed
Aug 6, 2015
1 parent
c267193
commit 225eb1b
Showing
3 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Code/Mantid/MantidQt/API/src/MantidQwtScaleTransformation.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "MantidQwtScaleTransformation.h" | ||
|
||
double MantidQwtScaleTransformation::xForm( | ||
double s, double s1, double s2, double p1, double p2) const | ||
{ | ||
if (d_type == Log10) | ||
return p1 + (p2 - p1) / log(s2 / s1) * log(s / s1); | ||
else if (d_type == Power) | ||
return p1 + (p2 - p1) / pow(s2, nth_power) - pow(s1, nth_power)) * (pow(s, nth_power) - pow(s1, nth_power)); | ||
else | ||
return p1 + (p2 - p1) / (s2 - s1) * (s - s1); | ||
} | ||
|
||
/* | ||
Transform a value from a linear to a logarithmic 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 | ||
@return logarithmic or power interval | ||
*/ | ||
double QwtScaleTransformation::invXForm(double p, double p1, double p2, | ||
double s1, double s2) const | ||
{ | ||
if (d_type == Log10) | ||
return exp((p - p1) / (p2 - p1) * log(s2 / s1)) * s1; | ||
else if (d_type == Power){ | ||
const double one_over_n = 1.0/nth_power; | ||
return pow((p - p1) / (p2 - p1) * pow(s2, nth_power) - pow(s1, nth_power)), one_over_n) * s1; | ||
} | ||
else | ||
return s1 + (s2 - s1) / (p2 - p1) * (p - p1); | ||
} |