diff --git a/Polynomial/include/CGAL/Polynomial/Polynomial_type.h b/Polynomial/include/CGAL/Polynomial/Polynomial_type.h index 5c3059d2ec2..cc5ede35344 100644 --- a/Polynomial/include/CGAL/Polynomial/Polynomial_type.h +++ b/Polynomial/include/CGAL/Polynomial/Polynomial_type.h @@ -276,7 +276,7 @@ public: { coeff(0) = NT(a0); reduce(); simplify_coefficients(); } //! construct the constant polynomial a0 - Polynomial(const NT& a0) + explicit Polynomial(const NT& a0) : Base(Rep(1, &a0)) { reduce(); simplify_coefficients(); } @@ -336,7 +336,8 @@ public: template Polynomial(Forward_iterator first, Forward_iterator last) : Base(Rep(first,last)) - { reduce(); simplify_coefficients(); } + { std::cout << "FROM IT" << std::endl; + reduce(); simplify_coefficients(); } #if defined(CGAL_USE_LEDA) || defined(DOXYGEN_RUNNING) /*! \brief construct a polynomial from a LEDA \c array diff --git a/Polynomial/include/CGAL/Polynomial/modular_gcd_utcf_algorithm_M.h b/Polynomial/include/CGAL/Polynomial/modular_gcd_utcf_algorithm_M.h index d2b4e7961e6..05ea2936cbd 100644 --- a/Polynomial/include/CGAL/Polynomial/modular_gcd_utcf_algorithm_M.h +++ b/Polynomial/include/CGAL/Polynomial/modular_gcd_utcf_algorithm_M.h @@ -97,7 +97,7 @@ Polynomial modular_gcd_utcf_algorithm_M( } if(FF1.degree() == 0 || FF2.degree() == 0){ Poly result; - result = CGAL::gcd(FF1.content(),FF2.content()); + result = Poly(CGAL::gcd(FF1.content(),FF2.content())); return CGAL::canonicalize(result); } diff --git a/Polynomial/include/CGAL/Polynomial/polynomial_gcd.h b/Polynomial/include/CGAL/Polynomial/polynomial_gcd.h index 790320e5284..b6f819e4b13 100644 --- a/Polynomial/include/CGAL/Polynomial/polynomial_gcd.h +++ b/Polynomial/include/CGAL/Polynomial/polynomial_gcd.h @@ -479,11 +479,11 @@ Polynomial pseudo_gcdex( // handle trivial cases if (x.is_zero()) { if (y.is_zero()) CGAL_error_msg("gcdex(0,0) is undefined"); - xf = NT(0); yf = NT(1); vf = y.unit_part(); + xf = POLY(0); yf = POLY(1); vf = y.unit_part(); return y / vf; } if (y.is_zero()) { - xf = NT(1); yf = NT(0); vf = x.unit_part(); + xf = POLY(1); yf = POLY(0); vf = x.unit_part(); return x / vf; } bool swapped = x.degree() < y.degree(); diff --git a/Polynomial/include/CGAL/Polynomial/square_free_factorize.h b/Polynomial/include/CGAL/Polynomial/square_free_factorize.h index 6931bee2658..6937356639c 100644 --- a/Polynomial/include/CGAL/Polynomial/square_free_factorize.h +++ b/Polynomial/include/CGAL/Polynomial/square_free_factorize.h @@ -84,18 +84,19 @@ inline int square_free_factorize { typedef Polynomial POLY; typedef Polynomial_traits_d< POLY > PT; + typedef typename PT::Construct_polynomial Construct_polynomial; typedef typename PT::Univariate_content_up_to_constant_factor Ucont_utcf; typedef typename PT::Integral_division_up_to_constant_factor Idiv_utcf; if (typename PT::Total_degree()(poly) == 0){return 0;} Coeff ucont_utcf = Ucont_utcf()(poly); - POLY regular_poly = Idiv_utcf()(poly,ucont_utcf); + POLY regular_poly = Idiv_utcf()(poly,Construct_polynomial()(ucont_utcf)); int result = square_free_factorize_for_regular_polynomial( regular_poly, factors, multiplicities); - if (typename PT::Total_degree()(ucont_utcf) > 0){ + if (CGAL::total_degree(ucont_utcf) > 0){ typedef std::vector< Coeff > Factors_uc; typedef std::vector< int > Multiplicities_uc; Factors_uc factors_uc; @@ -106,7 +107,7 @@ inline int square_free_factorize for( typename Factors_uc::iterator it = factors_uc.begin(); it != factors_uc.end(); ++it ){ - *factors++ = POLY(*it); + *factors++ = Construct_polynomial()(*it); } for( Multiplicities_uc::iterator it = multiplicities_uc.begin(); it != multiplicities_uc.end(); ++it ){ diff --git a/Polynomial/include/CGAL/Polynomial/subresultants.h b/Polynomial/include/CGAL/Polynomial/subresultants.h index adab7a87f47..8a9e524152e 100644 --- a/Polynomial/include/CGAL/Polynomial/subresultants.h +++ b/Polynomial/include/CGAL/Polynomial/subresultants.h @@ -156,8 +156,8 @@ CGAL_BEGIN_NAMESPACE typename CGAL::Algebraic_structure_traits::Is_zero is_zero; if(degree(P) < 1 || degree(Q) < 1) { - *out++ = CGAL::internal::resultant_for_constant_polynomial - (P,Q); + *out++ = Polynomial(CGAL::internal::resultant_for_constant_polynomial + (P,Q)); return out; } @@ -260,8 +260,8 @@ CGAL_BEGIN_NAMESPACE typename Polynomial_traits_d::Construct_polynomial construct; if(degree(P) < 1 || degree(Q) < 1) { - *out++ = CGAL::internal::resultant_for_constant_polynomial - (P,Q); + *out++ = Polynomial(CGAL::internal::resultant_for_constant_polynomial + (P,Q)); return out; } @@ -395,10 +395,10 @@ CGAL_BEGIN_NAMESPACE typename Polynomial_traits_d::Construct_polynomial construct; if(degree(P) < 1 || degree(Q) < 1) { - *sres_out++ = CGAL::internal::resultant_for_constant_polynomial - (P,Q); - *coP_out++ = lcoeff(Q); - *coQ_out++ = lcoeff(P); + *sres_out++ = Polynomial(CGAL::internal::resultant_for_constant_polynomial + (P,Q)); + *coP_out++ = Polynomial(lcoeff(Q)); + *coQ_out++ = Polynomial(lcoeff(P)); return sres_out; } @@ -541,7 +541,7 @@ CGAL_BEGIN_NAMESPACE sResP[q]=eps_p_minus_1*CGAL::ipower(lcoeff(Q),p-q-1)*Q; s[q]=eps_p_minus_1*CGAL::ipower(lcoeff(Q),p-q); sResU[q]=construct(NT(0)); - sResV[q]=eps_p_minus_1*CGAL::ipower(lcoeff(Q),p-q-1); + sResV[q]=construct(eps_p_minus_1*CGAL::ipower(lcoeff(Q),p-q-1)); for(int i=q+1;i<=p-2;i++) { sResP[i]=sResU[i]=sResV[i]=construct(NT(0)); s[i]=NT(0); diff --git a/Polynomial/include/CGAL/Polynomial_traits_d.h b/Polynomial/include/CGAL/Polynomial_traits_d.h index e03df387c84..d56d0f88f30 100644 --- a/Polynomial/include/CGAL/Polynomial_traits_d.h +++ b/Polynomial/include/CGAL/Polynomial_traits_d.h @@ -895,7 +895,7 @@ public: :public std::binary_function{ // Evaluate with respect to one variable Coefficient_type - operator()(const Polynomial_d& p, Coefficient_type x) const { + operator()(const Polynomial_d& p, const Coefficient_type& x) const { return p.evaluate(x); } #define ICOEFF typename First_if_different::Type @@ -915,7 +915,7 @@ public: typedef Coefficient_type third_argument_type; Coefficient_type operator()( - const Polynomial_d& p, Coefficient_type a, Coefficient_type b) const + const Polynomial_d& p, const Coefficient_type& a, const Coefficient_type& b) const { return p.evaluate_homogeneous(a,b); } @@ -1128,10 +1128,13 @@ struct Construct_innermost_coefficient_const_iterator_range struct Integral_division_up_to_constant_factor :public std::binary_function { + + + Polynomial_d operator()(const Polynomial_d& p, const Polynomial_d& q) const { typedef Innermost_coefficient_type IC; - + typename PT::Construct_polynomial construct; typename PT::Innermost_leading_coefficient ilcoeff; typename PT::Construct_innermost_coefficient_const_iterator_range range; diff --git a/Polynomial/include/CGAL/Test/_test_polynomial_traits_d.h b/Polynomial/include/CGAL/Test/_test_polynomial_traits_d.h index 9929d0be96a..2ccd49ed797 100644 --- a/Polynomial/include/CGAL/Test/_test_polynomial_traits_d.h +++ b/Polynomial/include/CGAL/Test/_test_polynomial_traits_d.h @@ -826,7 +826,7 @@ void test_make_square_free(const Polynomial_traits_d&){ Polynomial_d p; p = generate_sparse_random_polynomial(3); - p = idiv_utcf(p, ucontent_utcf(p)); + p = idiv_utcf(p, Constructor()(ucontent_utcf(p))); p = make_square_free(p); Coeff f_intern = lcoeff(p); diff --git a/Polynomial/include/CGAL/polynomial_utils.h b/Polynomial/include/CGAL/polynomial_utils.h index 4a8c51634ba..bf7c14eed8b 100644 --- a/Polynomial/include/CGAL/polynomial_utils.h +++ b/Polynomial/include/CGAL/polynomial_utils.h @@ -130,11 +130,9 @@ CGAL_UNARY_POLY_FUNCTION_INDEX(Differentiate, differentiate) // Evaluate CGAL_BINARY_POLY_FUNCTION(Evaluate,evaluate) // EvaluateHomogeneous -template inline +template inline typename Polynomial_traits_d::Evaluate_homogeneous::result_type -evaluate_homogeneous(const Polynomial_d& p, - const typename Polynomial_traits_d::Coefficient_type& num, - const typename Polynomial_traits_d::Coefficient_type& den){ +evaluate_homogeneous(const Polynomial_d& p,const T& num, const T& den){ typedef Polynomial_traits_d PT; return typename PT::Evaluate_homogeneous()(p,num,den); } diff --git a/Polynomial/test/Polynomial/subresultants.cpp b/Polynomial/test/Polynomial/subresultants.cpp index da18cca25cb..bb6af4de812 100644 --- a/Polynomial/test/Polynomial/subresultants.cpp +++ b/Polynomial/test/Polynomial/subresultants.cpp @@ -28,6 +28,7 @@ void test_routine() { typedef typename Arithmetic_kernel::Rational Rational; typedef typename Arithmetic_kernel::Integer Integer; + typedef CGAL::Polynomial Poly_int1; typedef CGAL::Polynomial_traits_d Poly_int1_traits; @@ -323,15 +324,15 @@ void test_routine() { CGAL::internal::prs_polynomial_subresultants (f,g,std::back_inserter(sres)); CGAL_assertion(sres.size()==1); - CGAL_assertion(sres[0].degree()==0); - CGAL_assertion(sres[0][0]==Integer(8*8*8)); + //CGAL_assertion(sres[0].degree()==0); + CGAL_assertion(sres[0]==Integer(8*8*8)); sres.clear(); CGAL::internal::bezout_polynomial_subresultants (f,g,std::back_inserter(sres)); CGAL_assertion(sres.size()==1); - CGAL_assertion(sres[0].degree()==0); - CGAL_assertion(sres[0][0]==Integer(8*8*8)); + //CGAL_assertion(sres[0].degree()==0); + CGAL_assertion(sres[0]==Integer(8*8*8)); std::vector psres; CGAL::internal::prs_principal_subresultants @@ -352,19 +353,19 @@ void test_routine() { CGAL::internal::prs_polynomial_subresultants (f,g,std::back_inserter(sres)); CGAL_assertion(sres.size()==1); - CGAL_assertion(sres[0].is_zero()); + CGAL_assertion(CGAL::is_zero(sres[0])); sres.clear(); CGAL::internal::bezout_polynomial_subresultants (f,g,std::back_inserter(sres)); CGAL_assertion(sres.size()==1); - CGAL_assertion(sres[0].is_zero()); + CGAL_assertion(CGAL::is_zero(sres[0])); } { Poly_int1 f(Integer(7)); Poly_int1 g(Integer(-12)); - std::vector sres; + std::vector sres; CGAL::internal::prs_principal_subresultants (f,g,std::back_inserter(sres)); CGAL_assertion(sres.size()==1); diff --git a/Polynomial/test/Polynomial/test_polynomial.h b/Polynomial/test/Polynomial/test_polynomial.h index 993bef1a266..c352ae268b3 100644 --- a/Polynomial/test/Polynomial/test_polynomial.h +++ b/Polynomial/test/Polynomial/test_polynomial.h @@ -859,10 +859,10 @@ void test_total_degree(){ assert(CGAL::total_degree(Poly_2(0)) == 0); assert(CGAL::total_degree(Poly_2(1)) == 0); assert(CGAL::total_degree(Poly_2(Poly_1(1),Poly_1(1))) == 1); - assert(CGAL::total_degree(Poly_2(0,0,0,1))== 3); + assert(CGAL::total_degree(Poly_2(Poly_1(0),Poly_1(0),Poly_1(0),Poly_1(1)))== 3); assert(CGAL::total_degree(Poly_2(Poly_1(1,1),Poly_1(1))) == 1); - assert(CGAL::total_degree(Poly_2(0,0,1))== 2); + assert(CGAL::total_degree(Poly_2(Poly_1(0),Poly_1(0),Poly_1(1)))== 2); assert(CGAL::total_degree(Poly_2(Poly_1(0),Poly_1(0),Poly_1(1)))== 2); assert(CGAL::total_degree(Poly_2(Poly_1(0),Poly_1(0),Poly_1(1,1)))== 3); assert(CGAL::total_degree(Poly_2(Poly_1(1),Poly_1(0),Poly_1(1,1)))== 3);