-
Peterson, Peter authoredPeterson, Peter authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ScaleEngine.cpp 11.12 KiB
/***************************************************************************
File : ScaleEngine.cpp
Project : QtiPlot
--------------------------------------------------------------------
Copyright : (C) 2007 by Ion Vasilief
Email (use @ for *) : ion_vasilief*yahoo.fr
Description : Extensions to QwtScaleEngine and QwtScaleTransformation
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#include "qwt_compat.h"
#include "ScaleEngine.h"
QwtScaleTransformation* ScaleEngine::transformation() const
{
return new ScaleTransformation(this);
}
double ScaleTransformation::invXForm(double p, double p1, double p2, double s1, double s2) const
{
if (!d_engine->hasBreak()){
QwtScaleTransformation *tr = new QwtScaleTransformation (d_engine->type());
double res = tr->invXForm(p, p1, p2, s1, s2);
delete tr;
return res;
}
const int d_break_space = d_engine->breakWidth();
const double lb = d_engine->axisBreakLeft();
const double rb = d_engine->axisBreakRight();
const double pm = p1 + (p2 - p1)*(double)d_engine->breakPosition()/100.0;
double pml, pmr;
if (p2 > p1){
pml = pm - d_break_space;
pmr = pm + d_break_space;
} else {
pml = pm + d_break_space;
pmr = pm - d_break_space;
}
if (p > pml && p < pmr)
return pm;
bool invertedScale = d_engine->testAttribute(QwtScaleEngine::Inverted);
QwtScaleTransformation::Type d_type = d_engine->type();
if (invertedScale){
if ((p2 > p1 && p <= pml) || (p2 < p1 && p >= pml)){
if (d_engine->log10ScaleAfterBreak())
return s1*exp((p - p1)/(pml - p1)*log(rb/s1));
else
return s1 + (rb - s1)/(pml - p1)*(p - p1);