summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmpolynomexponents.cpp
blob: fdda7bdf769fa9429c49d869793f841c80d94216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2002 by Andreas Zehender
    email                : [email protected]
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/

#include "pmpolynomexponents.h"
#include "pmdebug.h"

bool PMPolynomExponents::m_created[6] = { false, false, false,
                                          false, false, false };
QValueList<PMPolynomExponents> PMPolynomExponents::m_lists[6];

PMPolynomExponents operator+ ( const PMPolynomExponents& p1,
                               const PMPolynomExponents& p2 )
{
   return PMPolynomExponents( p1.m_exponents[0] + p2.m_exponents[0],
                              p1.m_exponents[1] + p2.m_exponents[1],
                              p1.m_exponents[2] + p2.m_exponents[2] );
}

QValueList<PMPolynomExponents>& PMPolynomExponents::polynom( int n )
{
   if( ( n < 2 ) || ( n > 7 ) )
   {
      n = 2;
      kdError( PMArea ) << "Wrong polynom order in PMPolynomExponents::polynom( )\n";
   }

   if( !m_created[n-2] )
   {
      m_lists[n-2] = recPolynom( PMPolynomExponents( 0, 0, 0 ), 0, n, 0 );
      m_created[n-2] = true;
//      kdDebug( PMArea ) << "Polynom n: " << n << " size: " << m_lists[n-2].count( ) << endl;
   }

   return m_lists[n-2];
}

QValueList<PMPolynomExponents>
PMPolynomExponents::recPolynom( const PMPolynomExponents& base,
                               int xyz, int n, int rem )
{
   QValueList<PMPolynomExponents> res;

   if( n >= 0 )
   {
      if( ( ( rem + n ) == 0 ) || ( xyz > 2 ) )
         res.append( base );
      else
      {
         PMPolynomExponents newBase = base;
         newBase.setExponent( xyz, n );
         res += recPolynom( newBase, xyz + 1, rem, 0 );
         res += recPolynom( base, xyz, n - 1, rem + 1 );
      }
   }
   
   return res;
}