1
// Copyright (C) 2005 Pino Toscano <toscano.pino@tiscali.it>
3
// This program is free software; you can redistribute it and/or
4
// modify it under the terms of the GNU General Public License
5
// as published by the Free Software Foundation; either version 2
6
// of the License, or (at your option) any later version.
8
// This program is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
// GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License
14
// along with this program; if not, write to the Free Software
15
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
#ifndef KIG_EQUATION_H
19
#define KIG_EQUATION_H
24
* Simple class that represents an equation.
26
* It does not do any calculation, it serves only as a helper to write
27
* equations like \f$ 7 xy + 3 y^2 - 5 x - 2 y + 8 = 0 \f$ in a pretty form.
28
* It can handle equations of max two variables (named \em x and \em y ) with
29
* no limits on the grade of the terms. (well, the limit is 15, but I doubt
30
* anyone will ever use such a factor for a power...)
33
// * Use the addTerm() method to add a term to the equation, and removeTerm() to
34
// * remove one. After that, use prettyString() to get the equation written in a
38
// * If you want to use only the \em x variable, you can unspecify the last
39
// * parameters in the term manipulation methods, like addTerm(), term() and
42
// * @author Pino Toscano
46
* What follows is based on code by Maurizio Paolini
53
EquationString( const QString& string );
54
double trunc( double );
55
void prettify( void );
56
void addTerm( double coeff, const QString& unknowns, bool& needsign );
58
const QString x3() const;
59
const QString y3() const;
60
const QString x2y() const;
61
const QString xy2() const;
62
const QString x2() const;
63
const QString y2() const;
64
const QString xy() const;
65
const QString x() const;
66
const QString y() const;
67
const QString xnym(int n, int m) const;
74
// * Constructs a new empty equation.
79
// * Adds a new term to the equation. Use \p xpower and \p ypower to specify
80
// * the power of the relative variables. For example, if you would add
81
// * \f$-5xy^2 \f$ to the equation, then do:
84
// * // other code ...
85
// * eq.addTerm( -5, 1, 2 );
87
// * \param coeff is the coefficient of the new term
88
// * \param xpower is the power of the \em x variable
89
// * \param ypower is the power of the \em y variable
91
// void addTerm( double coeff, int xpower, int ypower = 0 );
93
// * Removes the term with coefficients \p xpower and \p ypower for the
95
// * \param xpower is the power of the \em x variable
96
// * \param ypower is the power of the \em y variable
98
// void removeTerm( int xpower, int ypower = 0 );
100
// * Gives the value of the coefficient of the term with coefficients
101
// * \p xpower and \p ypower .
102
// * \param value will contain the value of the found term, or 0 if not found
103
// * \param xpower is the power of the \em x variable
104
// * \param ypower is the power of the \em y variable
105
// * \return true or false whether the term was found
107
// bool term( double& value, int xpower, int ypower = 0 );
110
// * Removes all the term of the equation.
115
// * Set whether to show a second member for the equation, like \f$... = 0 \f$.
116
// * Note that the second member contents can be only a numeric value.
117
// * \param show whether to show the second member
119
// void setSecondMemberShown( bool show );
120
// bool isSecondMemberShown() const;
122
// * Sets \p value as the value for the second member. It is displayed only if
123
// * you activated it using setShowSecondMember().
124
// * The default value for the second member is 0 (zero).
126
// void setSecondMemberValue( double value );
127
// double secondMemberValue() const;
130
// * Returns a string with the current equation written in a nice form.
131
// * \param with_spaces specifies whether expand a bit the equation with spaces
133
// QString prettyString( bool with_spaces = false ) const;