1
/*************************************************************************************
2
* Copyright (C) 2007-2009 by Aleix Pol <aleixpol@kde.org> *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License *
6
* as published by the Free Software Foundation; either version 2 *
7
* of the License, or (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the Free Software *
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17
*************************************************************************************/
19
#include "functionimpl.h"
20
#include "analitza/variables.h"
21
#include "analitza/expression.h"
22
#include "functionfactory.h"
28
using namespace Analitza;
30
FunctionImpl::FunctionImpl(const Expression& newFunc, Variables* v, double defDl, double defUl)
31
: points(), func(v), m_deriv(0), m_res(0), mUplimit(defUl), mDownlimit(defDl)
33
func.setExpression(newFunc);
39
FunctionImpl::FunctionImpl(const FunctionImpl& fi)
40
: points(), func(fi.func.variables()), m_deriv(0), m_res(fi.m_res)
41
, mUplimit(fi.mUplimit), mDownlimit(fi.mDownlimit)
43
// Q_ASSERT(fi.isCorrect());
44
func.setExpression(fi.func.expression());
46
m_deriv = new Expression(*fi.m_deriv);
49
FunctionImpl::~FunctionImpl()
54
bool FunctionImpl::isSimilar(double a, double b, double diff)
56
return fabs(a-b)<diff;
59
bool FunctionImpl::addValue(const QPointF& p)
61
int count=points.count();
67
double angle1=std::atan2(points[count-1].y()-points[count-2].y(), points[count-1].x()-points[count-2].x());
68
double angle2=std::atan2(p.y()-points[count-1].y(), p.x()-points[count-1].x());
70
bool append=!isSimilar(angle1, angle2);
79
void FunctionImpl::setResolution(uint res)
90
double FunctionImpl::uplimit() const
95
double FunctionImpl::downlimit() const
100
void FunctionImpl::setLimits(double d, double u)