Beispiel #1
0
void algebraic_number_test()
{
    typedef Coefficient_ Coefficient;
    typedef Rational_ Rational;
    
    typedef CGAL::internal::Algebraic_real_d_1<Coefficient,Rational, CGAL::Handle_policy_no_union, RepClass > Algebraic_real_d_1; 
    typedef typename CGAL::Polynomial_type_generator<Coefficient,1>::Type Poly;
    CGAL::test_real_embeddable<Algebraic_real_d_1>();
    // general test of comparable functionality  

    // TODO generates a precondition error in Algebraic_real_rep
    //NiX::test_real_comparable<Algebraic_real_d_1>();

    // test of constructors
    Poly P_00(Coefficient(0));                   // zero polynomial
    Poly P_01(Coefficient(1));                   // constant polynomial
    Poly P_1(Coefficient(-1),Coefficient(1));       //(x-1)
    Poly P_2(Coefficient(-2),Coefficient(1));       //(x-2)
    Poly P_3(Coefficient(-3),Coefficient(1));       //(x-3)
    Poly P_4(Coefficient(-4),Coefficient(1));       //(x-4)
    Poly P_12=P_1*P_2;    //(x-1)(x-2)
    Poly P_123=P_1*P_2*P_3;    //(x-1)(x-2)(x-3)
    Poly P_s2(Coefficient(-2),Coefficient(0),Coefficient(1)); //(x^2-2)
    Poly P_s3(Coefficient(-3),Coefficient(0),Coefficient(1)); //(x^2-3)
    Poly P_s5(-Coefficient(5),Coefficient(0),Coefficient(1)); 
    Poly P_s10(-Coefficient(10),Coefficient(0),Coefficient(1));
    Poly P_s30(-Coefficient(30),Coefficient(0),Coefficient(1));
    Poly P_s2510= P_s2*P_s5*P_s10;
    Poly P_s530= P_s5 * P_s30;
   
    Algebraic_real_d_1 tmp;
    Algebraic_real_d_1 tmp1,tmp2;    

    Rational m;
    // general constructors;
    // default 
    // tmp = IS_Rational_ = 0
    tmp = Algebraic_real_d_1();
    assert(tmp.is_rational());
    assert(tmp.rational()==0); 
    // from int 
    tmp = Algebraic_real_d_1(1);
    assert(tmp.is_rational());
    assert(tmp.rational()==1);

    tmp = Algebraic_real_d_1(5);
    assert(tmp.is_rational());
    assert(tmp.rational()==5);
    
    // from Field
    tmp = Algebraic_real_d_1(Rational(0));
    assert(tmp.is_rational());
    assert(tmp.rational()==0); 
    
    tmp = Algebraic_real_d_1(Rational(1));
    assert(tmp.is_rational());
    assert(tmp.rational()==1);

    tmp = Algebraic_real_d_1(Rational(5)/ Rational(2));
    assert(tmp.is_rational());
    assert(tmp.rational()== Rational(5)/ Rational(2));    

    // general constructor 
    // tmp = 1
#if 0
    tmp = Algebraic_real_d_1(P_1,-2,+2);
    // TODO different behavior with leda and core
    assert(!tmp.is_rational());
    assert(tmp==Rational(1));
    assert(tmp.is_rational());
    assert(tmp.rational()==1);
#endif

    // special constructors 
    // from int
    tmp = Algebraic_real_d_1(2);
    assert(tmp.is_rational());
    assert(tmp.rational()==Rational(2)); 
    //from Rational
    tmp = Algebraic_real_d_1(Rational(2));
    assert(tmp.is_rational());
    assert(tmp.rational()==Rational(2)); 

    // member functions
    // tmp IS_GENERAL == 2;  

    tmp = Algebraic_real_d_1(P_123,Rational(3)/2,Rational(5)/2);
    assert(!tmp.is_rational());
    assert(tmp.polynomial()==P_123);
    assert(tmp.low()==Rational(3)/2);
    assert(tmp.high()==Rational(5)/2);
    assert(tmp.sign_at_low()==P_123.sign_at(Rational(3)/2));  
    
    // refine
    tmp = Algebraic_real_d_1(P_123,Rational(3)/2,Rational(5)/2);
    tmp.refine();
    assert(tmp.is_rational());
    assert(tmp.rational()==Rational(2));
    // tmp IS_GENERAL = sqrt 2
    tmp = Algebraic_real_d_1(P_s2*P_3,Rational(1),Rational(2));
    tmp.refine();
    assert(tmp.low()  >= Rational(1)); 
    assert(tmp.high() <= Rational(3)/2);   
    
    // strong_refine
    // tmp IS_GENERAL == 2;  
    
    tmp = Algebraic_real_d_1(P_123,Rational(3)/2,Rational(5)/2);
    m = Rational(2);
    tmp.strong_refine(m);
    assert(tmp.is_rational());
    assert(tmp.rational()==Rational(2));
    // tmp IS_GENERAL = sqrt 2
    tmp = Algebraic_real_d_1(P_s2*P_3,Rational(1),Rational(2));
    m = Rational(3)/2;
    tmp.strong_refine(m);
    assert(tmp.low()!=m);      
    assert(tmp.high()!=m); 
    
    // refine_to(a,b)
    // tmp IS_GENERAL = sqrt 2
    tmp = Algebraic_real_d_1(P_s2*P_4,Rational(0),Rational(3));
    assert(!tmp.is_rational());
    tmp.refine_to(Rational(1), Rational(2));
    assert(tmp.low()  >= Rational(1));
    assert(tmp.high() <= Rational(2));

    // tmp IS_REAL = sqrt 2
    tmp = Algebraic_real_d_1(P_s2,Rational(0),Rational(3));
    assert(!tmp.is_rational());
    tmp.refine_to(Rational(1), Rational(2));
    assert(tmp.low()  >= Rational(1));
    assert(tmp.high() <= Rational(2));

    // compare(rat)
    // tmp IS_GENERAL = sqrt 2
    tmp = Algebraic_real_d_1(P_s2*P_3,Rational(1),Rational(2));
    m = Rational(1);
    assert(tmp.compare(m)==1);
    m = Rational(2);
    assert(tmp.compare(m)==-1);
    // tmp IS_GENERAL = 3
    tmp = Algebraic_real_d_1(P_s2*P_3,Rational(2),Rational(4));
    m = Rational(3);
    assert(tmp.compare(m)==0);
    assert(tmp.is_rational());
    assert(tmp.rational()==Rational(3));
    assert(CGAL::degree(tmp.polynomial()) == 1);
    assert(tmp.polynomial().evaluate(Coefficient(3)) == Coefficient(0));
    
    // compare_distinct()
    
    tmp1 = Algebraic_real_d_1(P_s530, Rational(2), Rational(3)); // sqrt(5)  = 2.236...
    tmp2 = Algebraic_real_d_1(P_s530, Rational(5), Rational(6)); // sqrt(30) = 5.477...
    assert(tmp1.compare_distinct(tmp2) == CGAL::SMALLER);
    assert(tmp2.compare_distinct(tmp1) == CGAL::LARGER);

    //member functions
    // is_root_of
    tmp1 = Algebraic_real_d_1(P_s2510,Rational(1)/2,Rational(3)/2); 
    assert(tmp1.is_root_of(P_s530*P_s2));
    tmp1 = Algebraic_real_d_1(P_s2510,Rational(1)/2,Rational(3)/2); 
    assert(!tmp1.is_root_of(P_s530));

    //rational_between
    {
        Rational r;
        tmp1 = Algebraic_real_d_1(P_s2,Rational(1),Rational(2)); //sqrt2
        tmp2 = Algebraic_real_d_1(P_s3,Rational(1),Rational(3)); //sqrt3
        r = tmp1.rational_between(tmp2);
        assert(tmp1.compare(r)==CGAL::SMALLER);
        assert(tmp2.compare(r)==CGAL::LARGER);
        
        r = tmp2.rational_between(tmp1);
        assert(tmp1.compare(r)==CGAL::SMALLER);
        assert(tmp2.compare(r)==CGAL::LARGER);
    }

    // to_double()
    tmp = Algebraic_real_d_1(P_1*P_3*P_4, Rational(0), Rational(2));
    assert(fabs(tmp.to_double() - 1.0) < 1e-10);
    tmp = Algebraic_real_d_1(P_1*P_3, Rational(0), Rational(2));
    assert(fabs(tmp.to_double() - 1.0) < 1e-10);
    tmp = Algebraic_real_d_1(P_1, Rational(0), Rational(2));
    assert(fabs(tmp.to_double() - 1.0) < 1e-10);

    //IO tested in _test_algebraic_kernel_1.h 

    // test for Handle with union 
    {
        typedef 
            CGAL::internal::Algebraic_real_d_1
            <Coefficient,Rational,::CGAL::Handle_policy_union> Int;
        Int i(5);
        Int j(5);
        Int k(6);
        assert( ! i.identical( j));
        assert( ! i.identical( k));
        assert( ! j.identical( k));
        assert( i == j);
        assert( ! (i == k));
        assert( i.identical( j));
        assert( ! i.identical( k));
        assert( ! j.identical( k));
        // code coverage 
        assert( i == j);
    }
    // test for Handle without union 
    {
        typedef 
            CGAL::internal::Algebraic_real_d_1
            <Coefficient,Rational,::CGAL::Handle_policy_no_union> Int;
        Int i(5);
        Int j(5);
        Int k(6);
        assert( ! i.identical( j));
        assert( ! i.identical( k));
        assert( ! j.identical( k));
        assert( i == j);
        assert( ! (i == k));
        assert( ! i.identical( j));
        assert( ! i.identical( k));
        assert( ! j.identical( k));
    }

    
//     to_interval
//     {
//       Algebraic_real_d_1 TMP;              
//       assert(CGAL::in(25.0,CGAL::to_interval(Algebraic_real_d_1(25))));
//       assert(CGAL::in(sqrt(2),CGAL::to_interval(Algebraic_real_d_1(P_s2,1,2))));
//       assert(CGAL::in(sqrt(2),CGAL::to_interval(Algebraic_real_d_1(P_s2510,1,2))));
//       assert(CGAL::in(-sqrt(2),CGAL::to_interval(Algebraic_real_d_1(P_s2510,-2,-1))));
//       assert(CGAL::in(sqrt(5),CGAL::to_interval(Algebraic_real_d_1(P_s2510,2,3))));
//       assert(CGAL::in(-sqrt(5),CGAL::to_interval(Algebraic_real_d_1(P_s2510,-3,-2))));
//       assert(CGAL::in(sqrt(10),CGAL::to_interval(Algebraic_real_d_1(P_s2510,3,4))));
//       assert(CGAL::in(-sqrt(10),CGAL::to_interval(Algebraic_real_d_1(P_s2510,-4,-3))));
//     } 

    //simplify
    {
        // just a synatx check
        Algebraic_real_d_1(P_s2510,1,2).simplify();
    }
}
Beispiel #2
0
template <class Type> void  Bench_PackB_IM<Type>::verif()
{
        INT def = (INT)(NRrandom3() * 1000);  
        verif( rectangle(Pt2di(1,0),Pt2di(2,1)));
	for (INT k=0; k<10 ; k++)
	{
            verif( rectangle(Pt2di(k,0),Pt2di(k+1,10)  ),def);
            verif( rectangle(Pt2di(k,0),Pt2di(k+10,10) ),def);
            verif( rectangle(Pt2di(k,0),Pt2di(k+100,10)),def);
            verif( rectangle(Pt2di(k,0),Pt2di(k+200,10)),def);
	}



	verif( im1.all_pts());
	verif( rectangle(Pt2di(-10,-20),sz+Pt2di(30,40)),def);
	verif( disc(sz/2.0,euclid(sz)/1.8),def);


	{
	for (INT k=0 ; k<10 ; k++)
	{
		Pt2dr c = sz/2.0 + Pt2dr(NRrandom3(),NRrandom3())*20;
		REAL ray = 1+NRrandom3()*100;
        verif(disc(c,ray),def);
	}
	}



    ELISE_COPY(disc(CentreRand(),RayonRand()),1,im1.out()| pck.out());
	verif(im1.all_pts());

    ELISE_COPY(disc(CentreRand(),RayonRand()),frandr()*8,im1.out()| pck.out());
	verif(im1.all_pts());

    INT NbPts = (INT)(3 + NRrandom3()*10);

    ElList<Pt2di> Lpt;
	{
    for (INT k=0; k<NbPts ; k++)
       Lpt = Lpt+Pt2di(CentreRand());
	}

    ELISE_COPY(polygone(Lpt),NRrandom3()<0.1,im1.out()| pck.out());
	verif(im1.all_pts());



      ModifCSte(rectangle(Pt2di(5,0),Pt2di(10,10)),2);
      verif(im1.all_pts());

      ModifLut(rectangle(Pt2di(0,5),Pt2di(12,12)),FX&3);
      verif(im1.all_pts());

      //ModifCSte(disc(Pt2di(50,50),20),3);
      ModifCSte(disc(Pt2dr(50,50),20),3); // __NEW
      verif(im1.all_pts());


      for (INT NbC =0 ; NbC < 20 ; NbC++)
      {
          ElList<Pt2di> lPt;
          for (INT iPt =0 ; iPt < 20; iPt ++)
          {
              lPt  = lPt + Pt2di(CentreRand());
          }
          ModifCSte(polygone(lPt),INT(NRrandom3() * 3));
          verif(im1.all_pts());
      }

      Pt2di P_00 (0,0);
      Pt2di P_10 (sz.x,0);
      Pt2di P_01 (0,sz.y);
      ElList<Pt2di> lP1;
      lP1 =  lP1 + P_00; lP1 =  lP1 + P_01; lP1 =  lP1 + P_10;

      ModifCSte(polygone(lP1),7);
      verif(im1.all_pts());





    TiffVerif();

}