Exemplo n.º 1
0
template <class Type> REAL  BoxFreemanCompil<Type>::D2BoxSeg(const Box2d<Type> & b,const SegComp & s)
{
   if (s.p0() == s.p1())
      return b.SquareDist(s.p0());

   INT c1 = b.freeman_pos (s.p0());
   INT c2 = b.freeman_pos (s.p1());


   switch ( TAB_CONF_CPLE_FREEM[c1][c2])
   {
      case INTER_TOUJ  : return 0.0;
      case CFF_00      :
           return ElMin(b.SquareDist(s.p0(),c1),b.SquareDist(s.p1(),c2));

      case CFF_11      :
      {
           return  s.square_dist_seg(PQ1(b,c1,c2));
      }

      case CFF_13      :
      {
           return  ElMin
                   (
                       s.square_dist_seg(PQ1(b,c1,c2)),
                       s.square_dist_seg(PQ2(b,c1,c2))
                   );
      }
      case CFF_01      :
      {
           return ElMin3
                  (
                     b.SquareDist(s.p0(),c1),
                     b.SquareDist(s.p1(),c2),
                     s.square_dist_seg(PQ1(b,c1,c2))
                  );
     }


      case CFF_02      :
      {
           REAL ord1 = s.ordonnee(PQ1(b,c1,c2));
           if (TAB_TRIGO_CF[c1][c2] )
               return ( (ord1 > 0) ? ElSquare(ord1) : 0.0);
           else
               return ( (ord1 < 0) ? ElSquare(ord1) : 0.0);
      }

      case CFF_03      :
      {
           REAL ord1 = s.ordonnee(PQ1(b,c1,c2));

            return (TAB_TRIGO_CF[c1][c2] == (ord1>0.0)) ?
                   ElSquare(ord1)                       :
                   0.0                                  ;
      }

      case CFF_15      :
      {
           REAL ord1 = s.ordonnee(PQ1(b,c1,c2));
           REAL ord2 = s.ordonnee(PQ2(b,c1,c2));

           return ((ord1 < 0) == (ord2 < 0))             ?
                    ElMin(ElSquare(ord1),ElSquare(ord2)) :
                    0.0                                  ;
      }

      default  : ;
   }

   cout << "CODE " << c1 << "  " << c2  <<  " " << TAB_CONF_CPLE_FREEM[c1][c2] << endl;

   ELISE_ASSERT(false,"Dist Box/seg ??? ");
   return 0;
}
Exemplo n.º 2
0
int main()
{
    srand(time(NULL));
    int counter=0;
    int random[100];
    int n =5;


    std::cout<<"---------Deque Tests start here------------------v"<<std::endl;

    Deque Q;
    for(int i=0;i<100;i++)
        {
        random[i]=rand() % 10;
        Q.addRight(random[i]);
        counter++;
        if(counter==10)
            {
                counter=0;
                std::cout<<std::endl;
            }

        }

        std::cout<<std::endl;
        std::cout<<"Default 100 Deque filled completely listed head to tail"<<std::endl;
        std::cout<<Q.listLeftRight()<<std::endl;
        std::cout<<"Default 100 Deque filled completely listed tail to head"<<std::endl;
        std::cout<<Q.listRightLeft()<<std::endl;

         std::cout<<"Now removing a random number of elements from the left"<<std::endl;
      for(int i=0;i<random[1];i++)
        {
        std::cout<<Q.getLeft()<<std::endl;
        }

        std::cout<<"How the deque looks now, listed tail to head"<<std::endl;
        std::cout<<Q.listRightLeft()<<std::endl;

        std::cout<<"How the deque looks now, listed head to tail"<<std::endl;
        std::cout<<Q.listLeftRight()<<std::endl;

        std::cout<<"Now removing a random number of elements from the right"<<std::endl;
      for(int i=0;i<random[99];i++)
        {
        std::cout<<Q.getRight()<<std::endl;
        }
        std::cout<<std::endl<<std::endl;

        std::cout<<"How the deque looks now, listed tail to head"<<std::endl;
        std::cout<<Q.listRightLeft()<<std::endl;

        std::cout<<"How the deque looks now, listed head to tail"<<std::endl;
        std::cout<<Q.listLeftRight()<<std::endl;

    Deque Q1(n);

    for(int i=0;i<6;i++)
        {
        Q1.addRight(random[i]);

        }

        std::cout<<std::endl<<std::endl<<std::endl;

        std::cout<<Q1.listLeftRight()<<std::endl;
        std::cout<<"Deque 6 filled completely listed head to tail"<<std::endl;
        std::cout<<Q1.listRightLeft()<<std::endl;
        std::cout<<"Deque 6 filled completely listed tail to head"<<std::endl;


        std::cout<<std::endl<<std::endl<<std::endl;

        std::cout<<Q1.getLeft()<<std::endl;
        std::cout<<Q1.getLeft()<<std::endl;

        std::cout<<"How the deque looks now, listed head to tail"<<std::endl<<Q1.listLeftRight()<<std::endl;
        std::cout<<"How the deque looks now, listed tail to head"<<std::endl<<Q1.listRightLeft()<<std::endl;

        std::cout<<"Adding 9 to the array on the right four times"<<std::endl;
        Q1.addRight(9);
        Q1.addRight(9);
        Q1.addRight(9);
        Q1.addRight(9);

        std::cout<<std::endl;

        std::cout<<"How the deque looks now, listed head to tail"<<std::endl<<Q1.listLeftRight()<<std::endl;
        std::cout<<"How the deque looks now, listed tail to head"<<std::endl<<Q1.listRightLeft()<<std::endl;

std::cout<<"v--------------Stack Tests start here------------------v"<<std::endl;


    Stack S1(n);

    for(int i=0;i<5;i++)
        {
        random[i]=rand() % 10;
        S1.push(random[i]);
        }
        std::cout<<S1.peek()<<std::endl;
    for(int i=0;i<3;i++)
        {
        std::cout<<S1.pop()<<std::endl;
        }
        std::cout<<S1.peek()<<std::endl;
std::cout<<"v--------------Priority Queue Tests start here------------------v"<<std::endl;
    PQueue PQ1(n);
      for(int i=0;i<100;i++)
        {
        random[i]=rand() % 10;
        PQ1.addValue(random[i]);
        }
        for(int i=0;i<5;i++)
        {
        std::cout<<PQ1.removeSmallest()<<' ';
        }
        std::cout<<std::endl;
         for(int i=0;i<5;i++)
        {
         PQ1.addValue(random[i]);
        }
        for(int i=0;i<5;i++)
        {
        std::cout<<PQ1.removeLargest()<<' ';
        }

    return 0;
}