File indexing completed on 2024-04-21 03:40:38
0001 /************************************************************************************* 0002 * Copyright (C) 2007-2009 by Aleix Pol <aleixpol@kde.org> * 0003 * Copyright (C) 2010 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU General Public License * 0007 * as published by the Free Software Foundation; either version 2 * 0008 * of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the Free Software * 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0018 *************************************************************************************/ 0019 0020 #include "abstractplanecurve.h" 0021 #include "functiongraph.h" 0022 0023 #include <cmath> 0024 0025 #include "analitza/analyzer.h" 0026 #include "analitza/value.h" 0027 #include "analitza/variable.h" 0028 #include "utils/mathutils.h" 0029 0030 using namespace Analitza; 0031 0032 AbstractPlaneCurve::AbstractPlaneCurve(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v) 0033 : AbstractFunctionGraph(e, v) 0034 {} 0035 0036 AbstractPlaneCurve::~AbstractPlaneCurve() 0037 {} 0038 0039 bool AbstractPlaneCurve::addPoint(const QPointF& p) 0040 { 0041 int count=points.count(); 0042 if(count<2) { 0043 points.append(p); 0044 return false; 0045 } 0046 0047 double angle1=std::atan2(points[count-1].y()-points[count-2].y(), points[count-1].x()-points[count-2].x()); 0048 double angle2=std::atan2(p.y()-points[count-1].y(), p.x()-points[count-1].x()); 0049 0050 bool append=!isSimilar(angle1, angle2); 0051 if(append) 0052 points.append(p); 0053 else 0054 points.last()=p; 0055 0056 return append; 0057 }