~ubuntu-branches/ubuntu/oneiric/kig/oneiric

« back to all changes in this revision

Viewing changes to misc/equation.h

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 11:57:38 UTC
  • Revision ID: james.westby@ubuntu.com-20110710115738-gdjnn1kctr49lmy9
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C)  2005  Pino Toscano <toscano.pino@tiscali.it>
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
// 02110-1301, USA.
 
17
 
 
18
#ifndef KIG_EQUATION_H
 
19
#define KIG_EQUATION_H
 
20
 
 
21
#include <qstring.h>
 
22
 
 
23
/**
 
24
 * Simple class that represents an equation.
 
25
 *
 
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...)
 
31
 */
 
32
 
 
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
 
35
// * nice form.
 
36
// *
 
37
// * \note
 
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
 
40
// * removeTerm().
 
41
// *
 
42
// * @author Pino Toscano
 
43
// */
 
44
 
 
45
 /*
 
46
  * What follows is based on code by Maurizio Paolini
 
47
  */
 
48
 
 
49
class EquationString
 
50
 : public QString
 
51
{
 
52
public:
 
53
  EquationString( const QString& string );
 
54
  double trunc( double );
 
55
  void prettify( void );
 
56
  void addTerm( double coeff, const QString& unknowns, bool& needsign );
 
57
 
 
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;
 
68
};
 
69
 
 
70
//class Equation
 
71
//{
 
72
//public:
 
73
//  /**
 
74
//   * Constructs a new empty equation.
 
75
//   */
 
76
//  Equation();
 
77
//
 
78
//  /**
 
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:
 
82
//   * \code
 
83
//   * Equation eq;
 
84
//   * // other code ...
 
85
//   * eq.addTerm( -5, 1, 2 );
 
86
//   * \endcode
 
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
 
90
//   */
 
91
//  void addTerm( double coeff, int xpower, int ypower = 0 );
 
92
//  /**
 
93
//   * Removes the term with coefficients \p xpower and \p ypower for the
 
94
//   * equations.
 
95
//   * \param xpower is the power of the \em x variable
 
96
//   * \param ypower is the power of the \em y variable
 
97
//   */
 
98
//  void removeTerm( int xpower, int ypower = 0 );
 
99
//  /**
 
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
 
106
//   */
 
107
//  bool term( double& value, int xpower, int ypower = 0 );
 
108
//
 
109
//  /**
 
110
//   * Removes all the term of the equation.
 
111
//   */
 
112
//  void clear();
 
113
//
 
114
//  /**
 
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
 
118
//   */
 
119
//  void setSecondMemberShown( bool show );
 
120
//  bool isSecondMemberShown() const;
 
121
//  /**
 
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).
 
125
//   */
 
126
//  void setSecondMemberValue( double value );
 
127
//  double secondMemberValue() const;
 
128
//
 
129
//  /**
 
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
 
132
//   */
 
133
//  QString prettyString( bool with_spaces = false ) const;
 
134
//
 
135
//private:
 
136
//  class Private;
 
137
//  Private* d;
 
138
//};
 
139
//
 
140
#endif