示例#1
0
point joueur::calculAngle(point cible, double angle2)
{
//prendre l'angle du point
/*double adj;
double opp;
double hyp;
double angle;
adj = cible.getX();
opp = cible.getZ();
hyp = sqrt(double(adj * adj) + double(opp * opp));
angle = acos(adj/hyp) * 180/3.14159265358979323846;
if(adj < 0 && opp <0)
{
angle = 180 - angle;
angle += 180;
}*/
anglePts angleHorizontale = cible.calculAngles();
//std::cout << "angle : " << angleHorizontale.angleX << std::endl;
/*double angle = angleHorizontale.angleX;
angle-=angle2;
double hyp = angleHorizontale.longueur1;
point resultat;
resultat.setX(cos(angle*3.14159265358979323846/180)*hyp);
resultat.setZ(sin(angle*3.14159265358979323846/180)*hyp);*/
angleHorizontale.angleX-=angle2;
point resultat(0, 0,0);
resultat.calculPoint(angleHorizontale);
return resultat;
}
示例#2
0
Duree Duree::operator+(const Duree &duree)
{
    int heures = m_heures;
    int minutes = m_minutes;
    int secondes = m_secondes;

    // 1 : ajout des secondes
    secondes += duree.m_secondes; // Exceptionnellement autorisé car même classe
    // Si le nombre de secondes dépasse 60, on rajoute des minutes et on met un nombre de secondes inférieur à 60
    minutes += secondes / 60;
    secondes %= 60;

    // 2 : ajout des minutes
    minutes += duree.m_minutes;
    // Si le nombre de minutes dépasse 60, on rajoute des heures et on met un nombre de minutes inférieur à 60
    heures += minutes / 60;
    minutes %= 60;

    // 3 : ajout des heures
    heures += duree.m_heures;

    // Création de l'objet resultat et retour
    Duree resultat(heures, minutes, secondes);
    return resultat;
}
示例#3
0
Matrice Matrice::InversionLignes(int Ligne1, int Ligne2) const
{
	int i;
	Matrice resultat(*this);
	std::vector <float> inter;
	
	//On rentre les valeurs de la Ligne1 dans un vector
	for(i=0; i<m_colonnes; i++)
	{
		inter.push_back(resultat.ObtenirValeur(Ligne1, i));
	}
	
	//On assigne les valeurs de la ligne2 à la ligne1 
	for(i=0; i<m_colonnes; i++)
	{
		resultat.FixerValeur(Ligne1, i, resultat.ObtenirValeur(Ligne2,i));
	}
	
	//On assigne les valeurs du vector à la ligne 2
	for(i=0; i<m_colonnes; i++)
	{
		resultat.FixerValeur(Ligne2, i, inter[i]);
	}
	return resultat;
}
示例#4
0
int		get_next_line(int const fd, char **line)
{
	static char	*buf_save = NULL;
	char		buffer[BUFF_SIZE + 1];
	char		*line_tmp;
	int			ret;

	if (NULL == line || 0 > fd || BUFF_SIZE <= 0)
		return (-1);
	if (NULL == buf_save)
		buf_save = ft_strnew(0);
	while (!ft_strchr(buf_save, '\n'))
	{
		ret = read(fd, buffer, BUFF_SIZE);
		if (-1 == ret)
			return (-1);
		if (0 == ret)
			break ;
		buffer[ret] = '\0';
		line_tmp = ft_strjoin(buf_save, buffer);
		free(buf_save);
		buf_save = line_tmp;
	}
	return (resultat(line, buf_save));
}
       void TestListe::TestParcoursListeTemporaire()
       {
 
 
         Entier resultat(0) ;
 
 
 	      // itération sur une liste temporaire
         for(
         IterateurListeAssociation< ElementTestListe > i(f()) ; 
         i.Valide() ;
         ++i)
   
           resultat += i->valeur ;
 
   
 
         CPPUNIT_ASSERT(resultat == 3) ;
 
         resultat = 0 ;
 
         for(
         IterateurListeComposition< ElementTestListe > j(liste) ; 
         j.Valide() ;
         ++j)
   
  
          resultat += j->valeur ;
 
 
         CPPUNIT_ASSERT(resultat == 3) ;
 
 
       }
      Chaine TypeTemplate::Afficher() const
      {
        
        rDebug("TypeTemplate::Afficher") ;
        
        Chaine resultat(NomComplet(this->espaceDeNom)) ;

        rDebug("TypeTemplate::Afficher 2") ;        

        Chaine sortieParametres ;
//        if (parametres)
//          sortieParametres = (parametres->ToString()) ;

        for(IterateurListeComposition<ParametreTemplate> parametre(this->_parametres) ;
            parametre.Valide() ;
            ++parametre)
        {
        
          sortieParametres += ',' ;
          sortieParametres += parametre->Afficher() ;
          rDebug("parametre = " + parametre->Afficher()) ;
        }


        rDebug("fin TypeTemplate::Afficher") ;
        
        return "template " + resultat + Chaine("::") + 
               classeTemplate->Name()->ToString() + 
               "<" + sortieParametres +">" ;

        
      }
      /*!
        Est capable de reconnaitre les templates préfixés par des 
        namespaces, ainsi que ceux déjà identifiés comme des templates par 
        opencxx.
      */
      TypeTemplate* TypeTemplate::IdentifierTypeTemplate
                    (TypeInfo informationType, 
                     Environment* environement)
      {


        rDebug("TypeTemplate::IdentifierTypeTemplate") ;
        
      
        switch(informationType.WhatIs())
        {
        case TemplateType:  
          
        { 
         
          rDebug("whatis dit que c'ets un template") ;

          
               
          TemplateClass* classeTemplate 
            =  informationType.TemplateClassMetaobject() ;


          Base::Composition<TypeTemplate>
            resultat(new TypeTemplate(classeTemplate)) ;


          // arguments
          int nombreArguments = 0 ;
          TypeInfo typeArgument ;
      
          while(informationType.NthTemplateArgument(nombreArguments++,typeArgument))
          {
            
            if (typeArgument.WhatIs() == UndefType)
            {
              rDebug("parametre n'a pas de type") ;
              
              
            }
            else
            
              resultat->_parametres.AjouterEnQueue(Type::Construire(typeArgument, environement)) ;
          }

      
          return resultat.Liberer() ;
          break ;
        }
          
        default:
        
          rDebug("whatis dit que c'ets autre chose") ;
        
          return NULL ;
        
        }
        
      }
QVector<double> PrevisionPlusProchesVoisinsNormeUn::Estimation(QVector<double> const& donnees, int t, int h)
{
    QVector<double> resultat(h);
    QVector<double> x(3);
    x=KLmax(donnees, t, h);
    resultat=EstimationKL(donnees, x[1], x[2], t, h);
    return resultat;
}
QVector<double> PrevisionPlusProchesVoisinsNormeUn::EstimationKL(QVector<double> const& donnees, int k, int l, int t, int h)
{
    QVector<double> resultat(h);
    QVector< QVector<double> > y(l, QVector<double>(h+2));
    y=Lplusprochesvoisins(donnees, k, l, t, h);
    resultat=Moyenne(y, h);

    return resultat;
}
 /// Ajoute un point de vue.
 Base::Association<PointDeVue> AjouterPointDeVue(PointDeVue* _pdv)
 {
   Base::Composition<PointDeVue> temp(_pdv) ;
   Base::Association<PointDeVue> resultat(temp) ;
   
   pointsDeVue.Ajouter(temp.Liberer()) ;
   
   return resultat ;
 }
QVector<double> PrevisionPlusProchesVoisinsNormeUn::KLmax(QVector<double> const& donnees, int t, int h)
{
    QVector<double> resultat(3, 100000);
    double borne(0);
    borne=t/5;   // Creation of a boundary for K and L
    int kmax(0);
    kmax = borne;
    kmax = qMin(kmax+1,11);
    kmax=qMin(kmax, t-h+1);
     // First we consider K as given
    for(int k(2) ; k <kmax; ++k)
    {
        // We create a vector which will contains the value L which maximizes the prediction for K. The
        // vector also contains the score of this estimation
        QVector<double> x(3);
        x[0]=10000000; // We initiliaze a very high score to start the function for
        x[1]=k;
        x[2]=1;
        double lmax(0); // L cannot exceed 10
        lmax=qMin(kmax,t-k+2-h);
        for(int l(1) ; l < lmax; ++l)
        {
            double scoreKL(0);
            // For K and L we estimate the score of such a prediction method
            // to do this, we compute the average score for predictions from all the past values

            for(int j(k+l) ; j < t-h+1 ; ++j)
            {
                QVector<double> estimationKLJ(h);
                estimationKLJ=EstimationKL(donnees, k, l, j, h);
                scoreKL += Scoreestimation(estimationKLJ, donnees, k, l, j, h);
            }
            scoreKL/=(t-k-h-l+1);
            if (scoreKL < x[0]) // We replace the former L if the estimation is better
            {
                x[0]=scoreKL;
                x[2]=l;
            }  // We get for a given K the better L and the score of the (K,L) method
        }
        if (x[0]<resultat[0]) // We replace the former vector (K,L) if the new one provides a better estimation
        {
            resultat[0]=x[0];
            resultat[1]=x[1];
            resultat[2]=x[2];
        }
    }
    return resultat;
}
    PointDeVue* 
      PointDeVue::Construire(const Base::Association<Modele::Objet>& _observateur)
    {
      
      Base::Traceur::MessageInterne("Entering Affichage::PointDeVue::Construire(const Base::Association<Modele::Objet>&)") ;
      
      /// implantation à l'aide de Ogre
      Base::Composition<PointDeVue> resultat(
          new Implantation::Ogre::PointDeVue(_observateur)) ;
      
      resultat->Construire() ;

      Base::Traceur::MessageInterne("Leaving Affichage::PointDeVue::Construire(const Base::Association<Modele::Objet>&)") ;
      
      return resultat.Liberer() ;

    }
    Base::Association<Objet> Objet::Ajouter(Objet* _objet)
    {
      /// Pour le détruire au cas où ca foire
      Base::Composition<Objet> temporaire(_objet) ;
      Base::Association<Objet> resultat(temporaire) ;

      /// on met à jour le lien contenu/contenant
      temporaire->conteneur = *this ;
      contenu.Ajouter(temporaire.Liberer()) ;
      
      /// On enregistre l'objet dans le modèle
      Enregistrer(resultat) ;
      
      this->Notifier() ;
      
      return resultat ;
    }
        void TestListe::TestAjouter()
        {
  	      // 
          ListeAssociation< ElementTestListe > temp ;
  
          Composition< ElementTestListe > element1(new ElementTestListe(1)) ;
          Composition< ElementTestListe > element2(new ElementTestListe(2)) ;
  
          temp.AjouterEnTete(element1) ;
          temp.AjouterEnTete(element2) ;
  
          CPPUNIT_ASSERT(temp.NombreDElements() == 2) ;
  
          CPPUNIT_ASSERT(temp.Contient(element1)) ;
          CPPUNIT_ASSERT(temp.Contient(element2)) ;
  
          Entier resultat(0) ;
  
          for(
            IterateurListeAssociation< ElementTestListe > i(temp) ;
            i.Valide() ;
            ++i)
          {
            resultat += i->valeur ;
          }
          
          CPPUNIT_ASSERT(resultat == 3) ;

          // liste de valeurs
   
          listeChaine.AjouterEnTete("toto") ;
          listeChaine.AjouterEnTete("titi") ;
  
          CPPUNIT_ASSERT(listeChaine.Contient("toto")) ;
          CPPUNIT_ASSERT(listeChaine.Contient("titi")) ;
          
          // test de l'itérateur
          
          IterateurListeValeur<Chaine> chaine(listeChaine) ;

          CPPUNIT_ASSERT(chaine == Chaine("titi")) ;
          ++chaine ;

          CPPUNIT_ASSERT(chaine == "toto") ;
          
        }
QVector< QVector<double> > PrevisionPlusProchesVoisinsNormeUn::Lplusprochesvoisins(QVector<double> const& donnees, int k, int l, int t, int h)
{
    QVector<double> kdernieres(k);
    // We separate the last K observations from the rest of the serie
    kdernieres=Isoleleskdernieres(donnees, k, t);
    QVector< QVector<double> > resultat(l, QVector<double>(2+h));
    // We create a matrix  with the L nearest neighbors,
    // in each subvector we have 1) The Euclidean distance 2) the observation 3) the H following observations
    for (int g(0) ; g < l ; ++g)
    {resultat[g][0]=10000000000;
    }
    for (int i(k-1) ; i < t-h ; ++i)
    {QVector<double> x(h+2);
        x[1]=donnees[i]; // We register the observation
        for (int g(2) ; g < h+2 ; ++g)
        {x[g]=donnees[i+g-1];
        }
        QVector<double> kvaleursprecedantsi(k);
       // For each i, we create a vector with the observation i and K-1 observations before i

        kvaleursprecedantsi=Isoleleskdernieres(donnees, k, i+1);
        // In the first column we have the one norm distance

        x[0]=Normeun(kdernieres,kvaleursprecedantsi);

        if (x[0]<resultat[l-1][0]) // If the observation is nearer we replace it
        {
            resultat[l-1][0]=x[0];
            resultat[l-1][1]=x[1];
            for (int g(2) ; g < h+2 ; ++g)
            {
                resultat[l-1][g]=x[g];
            }
            resultat=Trieurtableau(resultat);// we always have to sort the matrix to have the farther nearet
            // neighbor at the end of the matrix
        }
    }

    return resultat;
}
示例#16
0
/**
- FUNCTION: + operator
- FUNCTIONALITY: Joins the blobs in source with the current ones
- PARAMETERS:
- source: object to copy the blobs
- RESULT:
- object with the actual blobs and the source blobs
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
CBlobResult CBlobResult::operator+( const CBlobResult& source )
{	
  //creem el resultat a partir dels blobs actuals
  CBlobResult resultat( *this );

  // reservem memòria per als nous blobs
  resultat.m_blobs.resize( resultat.GetNumBlobs() + source.GetNumBlobs() );

  // declarem els iterador per recòrrer els blobs d'origen i desti
  blob_vector::const_iterator pBlobsSrc = source.m_blobs.begin();
  blob_vector::iterator pBlobsDst = resultat.m_blobs.end();

  // insertem els blobs de l'origen a l'actual
  while( pBlobsSrc != source.m_blobs.end() )
  {
    pBlobsDst--;
    *pBlobsDst = new CBlob(**pBlobsSrc);
    pBlobsSrc++;
  }

  return resultat;
}
/*function for cursor movement*/
void curser(int no){
    int count=1,DG=0;
    char ch='0';
    gotoxy(10,23);
    while(1){
        switch(ch){
        case 77:
            DG++;
            if (DG>5) DG=0;
            if(R==1) {clr();R=0;co=0;a[0]='\o';};
            break;
        case 75:
            DG--;
            if(DG<0) DG=4;
            if(R==1) {clr();R=0;co=0;a[0]='\o';};
            break;
        case 80:
            count++;
            if (count==no+1) count=1;
            if(R==1) {clr();R=0;co=0;a[0]='\o';};
            break;
        case 72:
            count--;
            if(count==0) count=no;
            if(R==1) {clr();R=0;co=0;a[0]='\o';};
            break;
        }


          switch(DG){
        case 0:
            highlight(count);
            ch=getch();
            if(ch=='\r'){
                if(no==4)
                {
                    if (count==1) OP('1') ;
                    else if(count==2) OP('4');
                    else if(count==3) OP('7');
                    else if (count==4) C();
                    else   exit(0);
                }
            }
            break;
        case 1:
            highlight2(count);
            ch=getch();
            if(ch=='\r'){
                if(no==4){
                    if (count==1) OP('2') ;
                    else if(count==2) OP('5');
                    else if(count==3) OP('8');
                    else if (count==4) OP('0');
                    else   exit(0);
                }
            }
            break;
        case 2:
            highlight3(count);
            ch=getch();
            if(ch=='\r'){
                if(no==4){
                    if (count==1) OP('3') ;
                    else if(count==2) OP('6');
                    else if(count==3) OP('9');
                    else if (count==4) resultat();
                    else   exit(0);
                }
            }
            break;
        case 3:
             highlight4(count);
            ch=getch();
            if(ch=='\r'){
                if(no==4){
                    if (count==1) OP('+') ;
                    else if(count==2) OP('-');
                    else if(count==3) OP('*');
                    else if (count==4) OP('/');
                    else   exit(0);
                }
            }
            break;
        case 4:
            highlight5(count);
            ch=getch();
            if(ch=='\r'){
                if(no==4){
                    if (count==1) OP('(') ;
                    else if(count==2) OP(')');
                    else if(count==3) about_me();
                    else if (count==4) contact_me();
                    else   exit(0);
                }
            }
             break;
          }
    }
}
 /*!
   @par Etat 
     OK
 */
 Base::Association<Objet> AccesObjet(const Base::Chaine& _nom)
 {
   Base::Association<Objet> resultat(registreObjets[_nom]) ;
   VerifieCondition(resultat, Exception("pas d'objet de ce nom")) ;
   return resultat ;
 }