File indexing completed on 2024-04-28 03:40:46
0001 /************************************************************************************* 0002 * Copyright (C) 2011 by Aleix Pol <aleixpol@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 0020 #ifndef POLYNOMIAL_H 0021 #define POLYNOMIAL_H 0022 0023 #include <QList> 0024 #include "operator.h" 0025 0026 namespace Analitza { 0027 0028 class Apply; 0029 class Object; 0030 class Operator; 0031 0032 /** 0033 * \class Monomial 0034 * 0035 * \ingroup AnalitzaModule 0036 * 0037 * \brief Monomial object. 0038 * 0039 * It allows you compose and create a Polynomial. 0040 */ 0041 0042 class Monomial 0043 { 0044 public: 0045 Monomial(const Operator& o, Object* o2, bool& sign); 0046 Monomial(Monomial &&m) : first(m.first), second(m.second) {} 0047 Monomial(const Monomial &m) : first(m.first), second(m.second) {} 0048 0049 void operator=(const Monomial &m) { 0050 if (this != &m) { 0051 first = m.first; 0052 second = m.second; 0053 } 0054 } 0055 0056 Analitza::Object* createMono(const Analitza::Operator& o) const; 0057 bool isValue() const; 0058 static bool isScalar(const Object* o); 0059 0060 qreal first; 0061 Analitza::Object* second; 0062 }; 0063 0064 /** 0065 * \class Polynomial 0066 * 0067 * \ingroup AnalitzaModule 0068 * 0069 * \brief Polynomial object. 0070 * 0071 * The important method in this class is negate, which change the sign of the Monomial 0072 * referenced by an index. 0073 * 0074 * \author Aleix Pol <aleixpol@kde.org> 0075 */ 0076 0077 class Polynomial : public QList<Monomial> 0078 { 0079 public: 0080 explicit Polynomial(Apply* c); 0081 0082 Analitza::Object* toObject(); 0083 void negate(int i); 0084 0085 private: 0086 void addMonomial(const Monomial& m); 0087 void addValue(Analitza::Object* value); 0088 void simpScalars(bool firstValue); 0089 0090 QVector<Object*> m_scalars; 0091 Operator m_operator; 0092 bool m_sign; 0093 }; 0094 0095 } 0096 0097 #endif // POLYNOMIAL_H