Ejemplo n.º 1
0
	glm::vec2 minimumTranslation(const AABB& a, const AABB& b)
	{
		glm::vec2 amin = a.min;
        glm::vec2 amax = a.max;
        glm::vec2 bmin = b.min;
        glm::vec2 bmax = b.max;

        glm::vec2 mtd(0.0f, 0.0f);

        float left = (bmin.x - amax.x);
        float right = (bmax.x - amin.x);
        float top = (bmin.y - amax.y);
        float bottom = (bmax.y - amin.y);

        if (left > 0 || right < 0) return glm::vec2(0.0f, 0.0f);
        if (top > 0 || bottom < 0) return glm::vec2(0.0f, 0.0f);

        if (abs(left) < right)
            mtd.x = left;
        else
            mtd.x = right;

        if (abs(top) < bottom)
            mtd.y = top;
        else
            mtd.y = bottom;

        if (abs(mtd.x) < abs(mtd.y))
            mtd.y = 0;
        else
            mtd.x = 0; 
        return mtd;
	}
Ejemplo n.º 2
0
bool FLManager::alterTable(const QString &n)
{
#ifndef FL_QUICK_CLIENT
  QString mtd(db_->managerModules()->contentCached(n + QString::fromLatin1(".mtd")));

  if (!db_->dbAux())
    return false;

  QSqlCursor c("flmetadata", true, db_->dbAux());
  c.setForwardOnly(true);
  c.setFilter(QString::fromLatin1("tabla='") + n + QString::fromLatin1("'"));
  c.select();
  if (c.next())
    return alterTable(c.value("xml").toString(), mtd);
  else
    return false;
#else
  return true;
#endif
}
Ejemplo n.º 3
0
NM_Status
SubspaceIteration :: solve(SparseMtrx &a, SparseMtrx &b, FloatArray &_eigv, FloatMatrix &_r, double rtol, int nroot)
//
// this function solve the generalized eigenproblem using the Generalized
// jacobi iteration
//
{
    if ( a.giveNumberOfColumns() != b.giveNumberOfColumns() ) {
        OOFEM_ERROR("matrices size mismatch");
    }

    FloatArray temp, w, d, tt, f, rtolv, eigv;
    FloatMatrix r;
    int nn, nc1, ij = 0, is;
    double rt, art, brt, eigvt;
    FloatMatrix ar, br, vec;
    std :: unique_ptr< SparseLinearSystemNM > solver( GiveClassFactory().createSparseLinSolver(ST_Direct, domain, engngModel) );

    GJacobi mtd(domain, engngModel);
    int nc = min(2 * nroot, nroot + 8);
    nn = a.giveNumberOfColumns();
    if ( nc > nn ) {
        nc = nn;
    }

    ar.resize(nc, nc);
    ar.zero();
    br.resize(nc, nc);
    br.zero();

    //
    // creation of initial iteration vectors
    //
    nc1 = nc - 1;

    w.resize(nn);
    w.zero();
    d.resize(nc);
    d.zero();
    tt.resize(nn);
    tt.zero();
    rtolv.resize(nc);
    rtolv.zero();
    vec.resize(nc, nc);
    vec.zero();                   // eigen vectors of reduced problem

    //
    // create work arrays
    //
    r.resize(nn, nc);
    r.zero();
    eigv.resize(nc);
    eigv.zero();

    FloatArray h(nn);
    for ( int i = 1; i <= nn; i++ ) {
        h.at(i) = 1.0;
        w.at(i) = b.at(i, i) / a.at(i, i);
    }

    b.times(h, tt);
    r.setColumn(tt, 1);

    for ( int j = 2; j <= nc; j++ ) {
        rt = 0.0;
        for ( int i = 1; i <= nn; i++ ) {
            if ( fabs( w.at(i) ) >= rt ) {
                rt = fabs( w.at(i) );
                ij = i;
            }
        }

        tt.at(j) = ij;
        w.at(ij) = 0.;
        for ( int i = 1; i <= nn; i++ ) {
            if ( i == ij ) {
                h.at(i) = 1.0;
            } else {
                h.at(i) = 0.0;
            }
        }

        b.times(h, tt);
        r.setColumn(tt, j);
    } // (r = z)

# ifdef DETAILED_REPORT
    OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Degrees of freedom invoked by initial vectors :\n");
    tt.printYourself();
    OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: initial vectors for iteration:\n");
    r.printYourself();
# endif

    //ish = 0;
    a.factorized();
    //
    // start of iteration loop
    //
    for ( int nite = 0; ; ++nite ) {               // label 100
# ifdef DETAILED_REPORT
        printf("SubspaceIteration :: solveYourselfAt: Iteration loop no. %d\n", nite);
# endif
        //
        // compute projection ar and br of matrices a , b
        //
        for ( int j = 1; j <= nc; j++ ) {
            f.beColumnOf(r, j);

            solver->solve(a, f, tt);

            for ( int i = j; i <= nc; i++ ) {
                art = 0.;
                for ( int k = 1; k <= nn; k++ ) {
                    art += r.at(k, i) * tt.at(k);
                }

                ar.at(j, i) = art;
            }

            r.setColumn(tt, j);            // (r = xbar)
        }

        ar.symmetrized();        // label 110
#ifdef DETAILED_REPORT
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Printing projection matrix ar\n");
        ar.printYourself();
#endif
        //
        for ( int j = 1; j <= nc; j++ ) {
            tt.beColumnOf(r, j);

            b.times(tt, temp);
            for ( int i = j; i <= nc; i++ ) {
                brt = 0.;
                for ( int k = 1; k <= nn; k++ ) {
                    brt += r.at(k, i) * temp.at(k);
                }

                br.at(j, i) = brt;
            }                   // label 180

            r.setColumn(temp, j);        // (r=zbar)
        }                       // label 160

        br.symmetrized();
#ifdef DETAILED_REPORT
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Printing projection matrix br\n");
        br.printYourself();
#endif

        //
        // solution of reduced eigenvalue problem
        //
        mtd.solve(ar, br, eigv, vec);

        // START EXPERIMENTAL
#if 0
        // solve the reduced problem by Inverse iteration
        {
            FloatMatrix x(nc,nc), z(nc,nc), zz(nc,nc), arinv;
            FloatArray  w(nc), ww(nc), tt(nc), t(nc);
            double c;

            //  initial setting
            for ( int i = 1;i <= nc; i++ ) {
                ww.at(i)=1.0;
            }
            
            
            for ( int i = 1;i <= nc; i++ )
                for ( int j = 1; j <= nc;j++ )
                    z.at(i,j)=1.0;
            
            arinv.beInverseOf (ar);
            
            for ( int i = 0;i < nitem; i++ ) {
                //  copy zz=z
                zz = z;
                
                // solve matrix equation K.X = M.X
                x.beProductOf(arinv, z);
                //  evaluation of Rayleigh quotients
                for ( int j = 1;j <= nc; j++ ) {
                    w.at(j) = 0.0;
                    for (k = 1; k<= nc; k++) w.at(j) += zz.at(k,j) * x.at(k,j);
                }

                z.beProductOf (br, x);

                for ( int j = 1;j <= nc; j++ ) {
                    c = 0;
                    for ( int k = 1; k<= nc; k++ ) c += z.at(k,j) * x.at(k,j);
                    w.at(j) /= c;
                }

                //  check convergence
                int ac = 0;
                for ( int j = 1;j <= nc; j++ ) {
                    if (fabs((ww.at(j)-w.at(j))/w.at(j))< rtol)  ac++;
                    ww.at(j) = w.at(j);
                }

                //printf ("\n iterace cislo  %d   %d",i,ac);
                //w.printYourself();

                //  Gramm-Schmidt ortogonalization
                for ( int j = 1;j <= nc;j++ ) {
                    for ( int k = 1; k<= nc; k++ ) tt.at(k) = x.at(k,j);
                    t.beProductOf(br,tt) ;
                    for ( int ii = 1;ii < j; ii++ ) {
                        c = 0.0;
                        for ( int k = 1; k<= nc; k++ ) c += x.at(k,ii) * t.at(k);
                        for ( int k = 1; k<= nc; k++ ) x.at(k,j) -= x.at(k,ii) * c;
                    }
                    for ( int k = 1; k<= nc; k++) tt.at(k) = x.at(k,j);
                    t.beProductOf(br, tt);
                    c = 0.0;
                    for ( int k = 1; k<= nc; k++) c += x.at(k,j)*t.at(k);
                    for ( int k = 1; k<= nc; k++) x.at(k,j) /= sqrt(c);
                }

                if ( ac > nroot ) {
                    break;
                }

                //  compute new approximation of Z
                z.beProductOf(br,x);
            }
            
            eigv = w;
            vec = x;
        }
#endif


        //
        // sorting eigenvalues according to their values
        //
        do {
            is = 0; // label 350
            for ( int i = 1; i <= nc1; i++ ) {
                if ( fabs( eigv.at(i + 1) ) < fabs( eigv.at(i) ) ) {
                    is++;
                    eigvt = eigv.at(i + 1);
                    eigv.at(i + 1) = eigv.at(i);
                    eigv.at(i)   = eigvt;
                    for ( int k = 1; k <= nc; k++ ) {
                        rt = vec.at(k, i + 1);
                        vec.at(k, i + 1) = vec.at(k, i);
                        vec.at(k, i)   = rt;
                    }
                }
            }                   // label 360
        } while ( is != 0 );

# ifdef DETAILED_REPORT
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: current eigen values of reduced problem \n");
        eigv.printYourself();
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: current eigen vectors of reduced problem \n");
        vec.printYourself();
# endif
        //
        // compute eigenvectors
        //
        for ( int i = 1; i <= nn; i++ ) { // label 375
            for ( int j = 1; j <= nc; j++ ) {
                tt.at(j) = r.at(i, j);
            }

            for ( int k = 1; k <= nc; k++ ) {
                rt = 0.;
                for ( int j = 1; j <= nc; j++ ) {
                    rt += tt.at(j) * vec.at(j, k);
                }

                r.at(i, k) = rt;
            }
        }                       // label 420   (r = z)

        //
        // convergency check
        //
        for ( int i = 1; i <= nc; i++ ) {
            double dif = ( eigv.at(i) - d.at(i) );
            rtolv.at(i) = fabs( dif / eigv.at(i) );
        }

# ifdef DETAILED_REPORT
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Reached precision of eigenvalues:\n");
        rtolv.printYourself();
# endif
        for ( int i = 1; i <= nroot; i++ ) {
            if ( rtolv.at(i) > rtol ) {
                goto label400;
            }
        }

        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Convergence reached for RTOL=%20.15f\n", rtol);
        break;
label400:
        if ( nite >= nitem ) {
            OOFEM_WARNING("SubspaceIteration :: solveYourselfAt: Convergence not reached in %d iteration - using current values", nitem);
            break;
        }

        d = eigv;                     // label 410 and 440

        continue;
    }


    // compute eigenvectors
    for ( int j = 1; j <= nc; j++ ) {
        tt.beColumnOf(r, j);

        a.backSubstitutionWith(tt);
        r.setColumn(tt, j);                          // r = xbar
    }

    // one cad add a normalization of eigen-vectors here

    // initialize original index locations
    _r.resize(nn, nroot);
    _eigv.resize(nroot);
    for ( int i = 1; i <= nroot; i++ ) {
        _eigv.at(i) = eigv.at(i);
        for ( int j = 1; j <= nn; j++ ) {
            _r.at(j, i) = r.at(j, i);
        }
    }

    return NM_Success;
}
Ejemplo n.º 4
0
void KatePluginSymbolViewerView::parsePythonSymbols(void)
{
  if (!m_mainWindow->activeView())
   return;

  m_macro->setText(i18n("Show Globals"));
  m_struct->setText(i18n("Show Methods"));
  m_func->setText(i18n("Show Classes"));

  QString cl; // Current Line
  QPixmap cls( ( const char** ) class_xpm );
  QPixmap mtd( ( const char** ) method_xpm );
  QPixmap mcr( ( const char** ) macro_xpm );
  
  int in_class = 0, state = 0, j;
  QString name;
  
  QTreeWidgetItem *node = NULL;
  QTreeWidgetItem *mcrNode = NULL, *mtdNode = NULL, *clsNode = NULL;
  QTreeWidgetItem *lastMcrNode = NULL, *lastMtdNode = NULL, *lastClsNode = NULL;
  
  KTextEditor::Document *kv = m_mainWindow->activeView()->document();

 //kdDebug(13000)<<"Lines counted :"<<kv->numLines()<<endl;
  if(m_plugin->treeOn)
    {
      clsNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Classes") ) );
      mcrNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Globals") ) );
      mcrNode->setIcon(0, QIcon(mcr));
      clsNode->setIcon(0, QIcon(cls));
  
      if (m_plugin->expandedOn)
        {
        m_symbols->expandItem(mcrNode);
        m_symbols->expandItem(clsNode);
        }
      lastClsNode = clsNode;
      lastMcrNode = mcrNode;
      mtdNode = clsNode;
      lastMtdNode = clsNode;
      m_symbols->setRootIsDecorated(1);
    }
  else
      m_symbols->setRootIsDecorated(0);

for (int i=0; i<kv->lines(); i++)
 {
    int line=i;
    cl = kv->line(i);
    // concatenate continued lines and remove continuation marker
    if (cl.length()==0) continue;
    while (cl[cl.length()-1]==QLatin1Char('\\'))
    {
      cl=cl.left(cl.length()-1);
      i++;
      if (i<kv->lines())
        cl+=kv->line(i);
      else
        break;
    }

    if(cl.indexOf( QRegExp(QLatin1String("^class [a-zA-Z0-9_,\\s\\(\\).]+:")) ) >= 0) in_class = 1;

     //if(cl.find( QRegExp(QLatin1String("[\\s]+def [a-zA-Z_]+[^#]*:")) ) >= 0) in_class = 2;
     if(cl.indexOf( QRegExp(QLatin1String("^def\\s+[a-zA-Z_]+[^#]*:")) ) >= 0 ) in_class = 0;

     if (cl.indexOf(QLatin1String("def ")) >= 0 || (cl.indexOf(QLatin1String("class ")) >= 0 && in_class == 1))
       {
        if (cl.indexOf(QLatin1String("def ")) >= 0 && in_class == 1) in_class = 2;
        state = 1;
        if (cl.indexOf(QLatin1Char(':')) >= 0) state = 3; // found in the same line. Done
        else if (cl.indexOf(QLatin1Char('(')) >= 0) state = 2;

        if (state == 2 || state == 3) name = cl.left (cl.indexOf (QLatin1Char('(')));
       }

     if (state > 0 && state < 3)
       {
        for (j = 0; j < cl.length(); j++)
           {
            if (cl.at(j) == QLatin1Char('(')) state = 2;
            else if (cl.at(j) == QLatin1Char(':')) { state = 3; break; }

            if (state == 1) name += cl.at(j);
           }
       }
     if (state == 3)
       {
        //qDebug(13000)<<"Function -- Inserted : "<<name<<" at row : "<<i;
        if (in_class == 1) //strip off the word "class "
            name = name.trimmed ().mid (6);
        else //strip off the word "def "
            name = name.trimmed ().mid (4);

          if (func_on == true && in_class == 1)
            {
             if (m_plugin->treeOn)
               {
                node = new QTreeWidgetItem(clsNode, lastClsNode);
                if (m_plugin->expandedOn) m_symbols->expandItem(node);
                lastClsNode = node;
                mtdNode = lastClsNode;
                lastMtdNode = lastClsNode;
               }
             else node = new QTreeWidgetItem(m_symbols);

             node->setText(0, name);
             node->setIcon(0, QIcon(cls));
             node->setText(1, QString::number( line, 10));
            }

         if (struct_on == true && in_class == 2)
           {
            if (m_plugin->treeOn)
              {
               node = new QTreeWidgetItem(mtdNode, lastMtdNode);
               lastMtdNode = node;
              }
            else node = new QTreeWidgetItem(m_symbols);

            node->setText(0, name);
            node->setIcon(0, QIcon(mtd));
            node->setText(1, QString::number( line, 10));
           }

          if (macro_on == true && in_class == 0)
            {
             if (m_plugin->treeOn)
               {
                node = new QTreeWidgetItem(mcrNode, lastMcrNode);
                lastMcrNode = node;
               }
             else node = new QTreeWidgetItem(m_symbols);

             node->setText(0, name);
             node->setIcon(0, QIcon(mcr));
             node->setText(1, QString::number( line, 10));
            }

         state = 0;
         name.clear();
        }
    }

}
Ejemplo n.º 5
0
CollisionResult GD_API PolygonCollisionTest(Polygon2d& p1,
                                            Polygon2d& p2,
                                            bool ignoreTouchingEdges) {
  if (p1.vertices.size() < 3 || p2.vertices.size() < 3) {
    CollisionResult result;
    result.collision = false;
    result.move_axis.x = 0.0f;
    result.move_axis.y = 0.0f;
    return result;
  }

  p1.ComputeEdges();
  p2.ComputeEdges();

  sf::Vector2f edge;
  sf::Vector2f move_axis(0, 0);
  sf::Vector2f mtd(0, 0);

  float min_dist = FLT_MAX;

  CollisionResult result;

  // Iterate over all the edges composing the polygons
  for (std::size_t i = 0; i < p1.vertices.size() + p2.vertices.size(); i++) {
    if (i < p1.vertices.size())  // or <=
    {
      edge = p1.edges[i];
    } else {
      edge = p2.edges[i - p1.vertices.size()];
    }

    sf::Vector2f axis(
        -edge.y, edge.x);  // Get the axis to which polygons will be projected
    normalise(axis);

    float minA = 0;
    float minB = 0;
    float maxA = 0;
    float maxB = 0;

    project(axis, p1, minA, maxA);
    project(axis, p2, minB, maxB);

    float dist = distance(minA, maxA, minB, maxB);
    if (dist > 0.0f || (dist == 0.0 && ignoreTouchingEdges)) {
      // If the projections on the axis do not overlap, then
      // there is no collision
      result.collision = false;
      result.move_axis.x = 0.0f;
      result.move_axis.y = 0.0f;

      return result;
    }

    float absDist = std::abs(dist);

    if (absDist < min_dist) {
      min_dist = absDist;
      move_axis = axis;
    }
  }

  result.collision = true;

  sf::Vector2f d = p1.ComputeCenter() - p2.ComputeCenter();
  if (dotProduct(d, move_axis) < 0.0f) move_axis = -move_axis;
  result.move_axis = move_axis * min_dist;

  return result;
}
Ejemplo n.º 6
0
NM_Status
SubspaceIteration :: solve(SparseMtrx &a, SparseMtrx &b, FloatArray &_eigv, FloatMatrix &_r, double rtol, int nroot)
//
// this function solve the generalized eigenproblem using the Generalized
// jacobi iteration
//
//
{
    FILE *outStream;
    FloatArray temp, w, d, tt, rtolv, eigv;
    FloatMatrix r;
    int nn, nc1, i, j, k, ij = 0, nite, is;
    double rt, art, brt, eigvt, dif;
    FloatMatrix ar, br, vec;

    GJacobi mtd(domain, engngModel);
    outStream = domain->giveEngngModel()->giveOutputStream();
    nc = min(2 * nroot, nroot + 8);
    //
    // check matrix size
    //
    if ( a.giveNumberOfColumns() != b.giveNumberOfColumns() ) {
        OOFEM_ERROR("matrices size mismatch");
    }

    // check matrix for factorization support
    if ( !a.canBeFactorized() ) {
        OOFEM_ERROR("a matrix not support factorization");
    }

    //
    // check for wery small problem
    //
    nn = a.giveNumberOfColumns();
    if ( nc > nn ) {
        nc = nn;
    }

    ar.resize(nc, nc);
    ar.zero();
    br.resize(nc, nc);
    br.zero();

    //
    // creation of initial iteration vectors
    //
    nc1 = nc - 1;

    w.resize(nn);
    w.zero();
    d.resize(nc);
    d.zero();
    tt.resize(nn);
    tt.zero();
    rtolv.resize(nc);
    rtolv.zero();
    vec.resize(nc, nc);
    vec.zero();                   // eigen vectors of reduced problem

    _r.resize(nn, nroot);
    _eigv.resize(nroot);

    //
    // create work arrays
    //
    r.resize(nn, nc);
    r.zero();
    eigv.resize(nc);
    eigv.zero();

    FloatArray h(nn);
    for ( i = 1; i <= nn; i++ ) {
        h.at(i) = 1.0;
        w.at(i) = b.at(i, i) / a.at(i, i);
    }

    b.times(h, tt);
    for ( i = 1; i <= nn; i++ ) {
        r.at(i, 1) = tt.at(i);
    }

    for ( j = 2; j <= nc; j++ ) {
        rt = 0.0;
        for ( i = 1; i <= nn; i++ ) {
            if ( fabs( w.at(i) ) >= rt ) {
                rt = fabs( w.at(i) );
                ij = i;
            }
        }

        tt.at(j) = ij;
        w.at(ij) = 0.;
        for ( i = 1; i <= nn; i++ ) {
            if ( i == ij ) {
                h.at(i) = 1.0;
            } else {
                h.at(i) = 0.0;
            }
        }

        b.times(h, tt);
        for ( i = 1; i <= nn; i++ ) {
            r.at(i, j) = tt.at(i);
        }
    } // (r = z)

# ifdef DETAILED_REPORT
    printf("SubspaceIteration :: solveYourselfAt: Degrees of freedom invoked by initial vectors :\n");
    tt.printYourself();
    printf("SubspaceIteration :: solveYourselfAt: initial vectors for iteration:\n");
    r.printYourself();
# endif

    //ish = 0;
    a.factorized();
    //
    // start of iteration loop
    //
    nite = 0;
    do {                        // label 100
        nite++;
# ifdef DETAILED_REPORT
        printf("SubspaceIteration :: solveYourselfAt: Iteration loop no. %d\n", nite);
# endif
        //
        // compute projection ar and br of matrices a , b
        //
        for ( j = 1; j <= nc; j++ ) {
            for ( k = 1; k <= nn; k++ ) {
                tt.at(k) = r.at(k, j);
            }

            //a. forwardReductionWith(&tt) -> diagonalScalingWith (&tt)
            //  -> backSubstitutionWithtt) ;
            a.backSubstitutionWith(tt);

            for ( i = j; i <= nc; i++ ) {
                art = 0.;
                for ( k = 1; k <= nn; k++ ) {
                    art += r.at(k, i) * tt.at(k);
                }

                ar.at(j, i) = art;
            }

            for ( k = 1; k <= nn; k++ ) {
                r.at(k, j) = tt.at(k);                 // (r = xbar)
            }
        }

        ar.symmetrized();        // label 110
#ifdef DETAILED_REPORT
        printf("SubspaceIteration :: solveYourselfAt: Printing projection matrix ar\n");
        ar.printYourself();
#endif
        //
        for ( j = 1; j <= nc; j++ ) {
            for ( k = 1; k <= nn; k++ ) {
                tt.at(k) = r.at(k, j);
            }

            b.times(tt, temp);
            for ( i = j; i <= nc; i++ ) {
                brt = 0.;
                for ( k = 1; k <= nn; k++ ) {
                    brt += r.at(k, i) * temp.at(k);
                }

                br.at(j, i) = brt;
            }                   // label 180

            for ( k = 1; k <= nn; k++ ) {
                r.at(k, j) = temp.at(k);             // (r=zbar)
            }
        }                       // label 160

        br.symmetrized();
#ifdef DETAILED_REPORT
        printf("SubspaceIteration :: solveYourselfAt: Printing projection matrix br\n");
        br.printYourself();
#endif

        //
        // solution of reduced eigenvalue problem
        //
        mtd.solve(ar, br, eigv, vec);

        /// START EXPERIMENTAL
        // solve the reduced problem by Inverse iteration
        /*
         * {
         * FloatMatrix x(nc,nc), z(nc,nc), zz(nc,nc), arinv;
         * FloatArray  w(nc), ww(nc), tt(nc), t(nc);
         * double c;
         * int ii, i,j,k,ac;
         *
         *
         * //  initial setting
         * for (i=1;i<=nc;i++){
         * ww.at(i)=1.0;
         * }
         *
         * for (i=1;i<=nc;i++)
         * for (j=1; j<=nc;j++)
         *   z.at(i,j)=1.0;
         *
         * arinv.beInverseOf (ar);
         *
         * for (i=0;i<nitem;i++) {
         *
         * //  copy zz=z
         * zz = z;
         *
         * // solve matrix equation K.X = M.X
         * x.beProductOf (arinv, z);
         * //  evaluation of Rayleigh quotients
         * for (j=1;j<=nc;j++){
         *   w.at(j) = 0.0;
         *   for (k = 1; k<= nc; k++) w.at(j) += zz.at(k,j)*x.at(k,j);
         * }
         *
         * z.beProductOf (br, x);
         *
         * for (j=1;j<=nc;j++){
         *   c = 0;
         *   for (k = 1; k<= nc; k++) c+= z.at(k,j)*x.at(k,j);
         *   w.at(j) /= c;
         * }
         *
         * //  check convergence
         * ac=0;
         * for (j=1;j<=nc;j++){
         *   if (fabs((ww.at(j)-w.at(j))/w.at(j))< rtol)  ac++;
         *   ww.at(j)=w.at(j);
         * }
         *
         * printf ("\n iterace cislo  %d   %d",i,ac);
         * w.printYourself();
         *
         * //  Gramm-Schmidt ortogonalization
         * for (j=1;j<=nc;j++) {
         *   for (k = 1; k<= nc; k++) tt.at(k) = x.at(k,j) ;
         *   t.beProductOf(br,tt) ;
         *   for (ii=1;ii<j;ii++) {
         *     c = 0.0;
         *     for (k = 1; k<= nc; k++) c += x.at(k,ii)*t.at(k);
         *     for (k = 1; k<= nc; k++) x.at(k,j) -= x.at(k,ii)*c;
         *   }
         *   for (k = 1; k<= nc; k++) tt.at(k) = x.at(k,j) ;
         *   t.beProductOf (br,tt) ;
         *   c = 0.0;
         *   for (k = 1; k<= nc; k++) c += x.at(k,j)*t.at(k);
         *   for (k = 1; k<= nc; k++) x.at(k,j) /= sqrt(c);
         * }
         *
         * if (ac>nroot){
         *   break;
         * }
         *
         * //  compute new approximation of Z
         * z.beProductOf (br,x);
         * }
         *
         * eigv = w;
         * vec = x;
         * }
         * /// END EXPERIMANTAL
         */


        //
        // sorting eigenvalues according to their values
        //
        do {
            is = 0; // label 350
            for ( i = 1; i <= nc1; i++ ) {
                if ( fabs( eigv.at(i + 1) ) < fabs( eigv.at(i) ) ) {
                    is++;
                    eigvt = eigv.at(i + 1);
                    eigv.at(i + 1) = eigv.at(i);
                    eigv.at(i)   = eigvt;
                    for ( k = 1; k <= nc; k++ ) {
                        rt = vec.at(k, i + 1);
                        vec.at(k, i + 1) = vec.at(k, i);
                        vec.at(k, i)   = rt;
                    }
                }
            }                   // label 360
        } while ( is != 0 );

# ifdef DETAILED_REPORT
        printf("SubspaceIteration :: solveYourselfAt: current eigen values of reduced problem \n");
        eigv.printYourself();
        printf("SubspaceIteration :: solveYourselfAt: current eigen vectors of reduced problem \n");
        vec.printYourself();
# endif
        //
        // compute eigenvectors
        //
        for ( i = 1; i <= nn; i++ ) { // label 375
            for ( j = 1; j <= nc; j++ ) {
                tt.at(j) = r.at(i, j);
            }

            for ( k = 1; k <= nc; k++ ) {
                rt = 0.;
                for ( j = 1; j <= nc; j++ ) {
                    rt += tt.at(j) * vec.at(j, k);
                }

                r.at(i, k) = rt;
            }
        }                       // label 420   (r = z)

        //
        // convergency check
        //
        for ( i = 1; i <= nc; i++ ) {
            dif = ( eigv.at(i) - d.at(i) );
            rtolv.at(i) = fabs( dif / eigv.at(i) );
        }

# ifdef DETAILED_REPORT
        printf("SubspaceIteration :: solveYourselfAt: Reached precision of eigenvalues:\n");
        rtolv.printYourself();
# endif
        for ( i = 1; i <= nroot; i++ ) {
            if ( rtolv.at(i) > rtol ) {
                goto label400;
            }
        }

        fprintf(outStream,
                "SubspaceIteration :: solveYourselfAt: Convergence reached for RTOL=%20.15f",
                rtol);
        break;
label400:
        if ( nite >= nitem ) {
            fprintf(outStream, " SubspaceIteration :: solveYourselfAt: Convergence not reached in %d iteration - using current values", nitem);
            break;
        }

        for ( i = 1; i <= nc; i++ ) {
            d.at(i) = eigv.at(i);                     // label 410 and 440
        }

        continue;
    } while ( 1 );


    // compute eigenvectors
    for ( j = 1; j <= nc; j++ ) {
        for ( k = 1; k <= nn; k++ ) {
            tt.at(k) = r.at(k, j);
        }

        a.backSubstitutionWith(tt);
        for ( k = 1; k <= nn; k++ ) {
            r.at(k, j) = tt.at(k);                   // (r = xbar)
        }
    }

    // one cad add a normalization of eigen-vectors here

    for ( i = 1; i <= nroot; i++ ) {
        _eigv.at(i) = eigv.at(i);
        for ( j = 1; j <= nn; j++ ) {
            _r.at(j, i) = r.at(j, i);
        }
    }

    solved = 1;
    return NM_Success;
}
Ejemplo n.º 7
0
void KatePluginSymbolViewerView::parseEcmaSymbols(void)
{
  // make sure there is an active view to attach to
  if (!mainWindow()->activeView()) return;

  // the current line
  QString cl;
  // the current line stripped of all comments and strings
  QString stripped;
  // a parsed class/function identifier
  QString identifier;
  // temporary characters
  QChar current, next, string_start = '\0';
  // whether we are in a multiline comment
  bool in_comment = false;
  // the current line index
  int line = 0;
  // indices into the string
  int c, function_start = 0;
  // the current depth of curly brace encapsulation
  int brace_depth = 0;
  // a list of inserted nodes with the index being the brace depth at insertion
  QList<QTreeWidgetItem *> nodes;

  QPixmap cls( ( const char** ) class_xpm );
  QPixmap mtd( ( const char** ) method_xpm );
  QTreeWidgetItem *node = NULL;

  if (m_plugin->treeOn) {
    m_symbols->setRootIsDecorated(1);
  }
  else {
    m_symbols->setRootIsDecorated(0);
  }

  // read the document line by line
  KTextEditor::Document *kv = mainWindow()->activeView()->document();
  for (line=0; line < kv->lines(); line++) {
    // get a line to process, trimming off whitespace
    cl = kv->line(line);
    cl = cl.trimmed();
    stripped = "";
    bool in_string = false;
    for (c = 0; c < cl.length(); c++) {
      // get the current character and the next
      current = cl.at(c);
      if ((c+1) < cl.length()) next = cl.at(c+1);
      else next = '\0';
      // skip the rest of the line if we find a line comment
      if ((! in_comment) && (current == '/') && (next == '/')) break;
      // open/close multiline comments
      if ((! in_string) && (current == '/') && (next == '*')) {
        in_comment = true;
        c++;
        continue;
      }
      else if ((in_comment) && (current == '*') && (next == '/')) {
        in_comment = false;
        c++;
        continue;
      }
      // open strings
      if ((! in_comment) && (! in_string)) {
        if ((current == '\'') || (current == '"')) {
          string_start = current;
          in_string = true;
          continue;
        }
      }
      // close strings
      if (in_string) {
        // skip escaped backslashes
        if ((current == '\\') && (next == '\\')) {
          c++;
          continue;
        }
        // skip escaped string closures
        if ((current == '\\') && (next == string_start)) {
          c++;
          continue;
        }
        else if (current == string_start) {
          in_string = false;
          continue;
        }
      }
      // add anything outside strings and comments to the stripped line
      if ((! in_comment) && (! in_string)) {
        stripped += current;
      }
    }

    // scan the stripped line
    for (c = 0; c < stripped.length(); c++) {
      current = stripped.at(c);
      
      // look for class definitions (for ActionScript)
      if ((current == 'c') && (stripped.indexOf("class", c) == c)) {
        identifier = "";
        c += 6;
        for (c = c; c < stripped.length(); c++) {
          current = stripped.at(c);
          // look for the beginning of the class itself
          if ((current == '(') || (current == '{')) {
            c--;
            break;
          }
          else {
            identifier += current;
          }
        }
        // trim whitespace
        identifier = identifier.trimmed();
        // get the node to add the class entry to
        if ((m_plugin->treeOn) && (! nodes.isEmpty())) {
          node = new QTreeWidgetItem(nodes.last());
          if (m_plugin->expandedOn) m_symbols->expandItem(node);
        }
        else {
          node = new QTreeWidgetItem(m_symbols);
        }
        // add an entry for the class
        node->setText(0, identifier);
        node->setIcon(0, QIcon(cls));
        node->setText(1, QString::number(line, 10));
        if (m_plugin->expandedOn) m_symbols->expandItem(node);
      } // (look for classes)
      
      // look for function definitions
      if ((current == 'f') && (stripped.indexOf("function", c) == c)) {
        function_start = c;
        c += 8;
        // look for the beginning of the parameters
        identifier = "";
        for (c = c; c < stripped.length(); c++) {
          current = stripped.at(c);
          // look for the beginning of the function definition
          if ((current == '(') || (current == '{')) {
            c--;
            break;
          }
          else {
            identifier += current;
          }
        }
        // trim off whitespace
        identifier = identifier.trimmed();
        // if we have an anonymous function, back up to see if it's assigned to anything
        if (! (identifier.length() > 0)) {
          QChar ch = '\0';
          for (int end = function_start - 1; end >= 0; end--) {
            ch = stripped.at(end);
            // skip whitespace
            if ((ch == ' ') || (ch == '\t')) continue;
            // if we hit an assignment or object property operator,
            //  get the preceding identifier
            if ((ch == '=') || (ch == ':')) {
              end--;
              while (end >= 0) {
                ch = stripped.at(end);
                if ((ch != ' ') && (ch != '\t')) break;
                end--;
              }
              int start = end;
              while (start >= 0) {
                ch = stripped.at(start);
                if (((ch >= 'a') && (ch <= 'z')) ||
                    ((ch >= 'A') && (ch <= 'Z')) ||
                    ((ch >= '0') && (ch <= '9')) ||
                    (ch == '_')) start--;
                else {
                  start++;
                  break;
                }
              }
              identifier = stripped.mid(start, (end - start) + 1);
              break;
            }
            // if we hit something else, we're not going to be able
            //  to read an assignment identifier
            else break;
          }
        }
        // if we have a function identifier, make a node
        if (identifier.length() > 0) {
          // make a node for the function
          QTreeWidgetItem *parent = NULL;
          if (! nodes.isEmpty()) {
            parent = nodes.last();
          }
          if ((m_plugin->treeOn) && (parent != NULL))
            node = new QTreeWidgetItem(parent);
          else
            node = new QTreeWidgetItem(m_symbols);
          // mark the parent as a class (if it's not the root level)
          if (parent != NULL) {
            parent->setIcon(0, QIcon(cls));
            // mark this function as a method of the parent
            node->setIcon(0, QIcon(mtd));
          }
          // mark root-level functions as classes
          else {
            node->setIcon(0, QIcon(cls));
          }
          // add the function
          node->setText(0, identifier);
          node->setText(1, QString::number(line, 10));
          if (m_plugin->expandedOn) m_symbols->expandItem(node);
        }
      } // (look for functions)
      
      // keep track of brace depth
      if (current == '{') {
        brace_depth++;
        // if a node has been added at this level or above, 
        //  use it to extend the stack
        if (node != NULL)
          nodes.append(node);
        // if no node has been added, extend the last node to this depth
        else if (! nodes.isEmpty()) 
          nodes.append(nodes.last());
      }
      else if (current == '}') {
        brace_depth--;
        // pop the last node off the stack
        node = NULL;
        if (! nodes.isEmpty()) nodes.removeLast();
      }
    } // (scan the stripped line)
    
  } // (iterate through lines of the document)

}