mirror of https://github.com/CGAL/cgal
fix bug in Shift
This commit is contained in:
parent
7b0fdcd1f8
commit
b2176a7002
|
|
@ -581,6 +581,8 @@ public:
|
|||
const Coefficient& a8) const
|
||||
{return Polynomial_d(a0,a1,a2,a3,a4,a5,a6,a7,a8);}
|
||||
|
||||
|
||||
|
||||
template< class Input_iterator >
|
||||
inline
|
||||
Polynomial_d construct(
|
||||
|
|
@ -600,7 +602,6 @@ public:
|
|||
return Create_polynomial_from_monom_rep< Coefficient >()( begin, end );
|
||||
}
|
||||
|
||||
|
||||
template< class Input_iterator >
|
||||
Polynomial_d
|
||||
operator()( Input_iterator begin, Input_iterator end ) const {
|
||||
|
|
@ -608,7 +609,18 @@ public:
|
|||
typedef typename Input_iterator::value_type value_type;
|
||||
typedef Boolean_tag<boost::is_same<value_type,Coefficient>::value>
|
||||
Is_coeff;
|
||||
return construct(begin,end,Is_coeff());
|
||||
std::vector<value_type> vec(begin,end);
|
||||
return construct(vec.begin(),vec.end(),Is_coeff());
|
||||
}
|
||||
|
||||
|
||||
template< class Input_iterator >
|
||||
Polynomial_d
|
||||
operator()( Input_iterator begin, Input_iterator end , bool is_sorted) const {
|
||||
if(is_sorted)
|
||||
return Create_polynomial_from_monom_rep< Coefficient >()( begin, end );
|
||||
else
|
||||
return (*this)(begin,end);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -1226,8 +1238,9 @@ public:
|
|||
// Shift;
|
||||
struct Shift
|
||||
: public std::unary_function< Polynomial_d, Polynomial_d >{
|
||||
|
||||
Polynomial_d
|
||||
operator()(const Polynomial_d& p, int e, int i = PT::d) const {
|
||||
operator()(const Polynomial_d& p, int e, int i = (d-1)) const {
|
||||
Construct_polynomial construct;
|
||||
Get_monom_representation gmr;
|
||||
Monom_rep monom_rep;
|
||||
|
|
@ -1235,7 +1248,7 @@ public:
|
|||
for(typename Monom_rep::iterator it = monom_rep.begin();
|
||||
it != monom_rep.end();
|
||||
it++){
|
||||
it->first[i-1]+=e;
|
||||
it->first[i]+=e;
|
||||
}
|
||||
return construct(monom_rep.begin(), monom_rep.end());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ generate_sparse_random_polynomial(int max_degree = 10){
|
|||
CGAL_SNAP_CGALi_TRAITS_D(PT);
|
||||
typename PT::Construct_polynomial construct;
|
||||
|
||||
|
||||
typedef CGAL::Exponent_vector Exponent_vector;
|
||||
typedef std::pair< CGAL::Exponent_vector , ICoeff > Monom;
|
||||
typedef std::vector< Monom > Monom_rep;
|
||||
|
|
@ -105,6 +104,7 @@ void test_construct_polynomial(const Polynomial_traits_d&){
|
|||
== construct(Coeff(3),Coeff(2),Coeff(1),Coeff(0)));
|
||||
assert(construct(Coeff(3),Coeff(2),Coeff(1))
|
||||
!= construct(Coeff(3),Coeff(2),Coeff(1),Coeff(1)));
|
||||
|
||||
// construct via iterator range
|
||||
std::vector<Coeff> coeffs;
|
||||
assert(construct(coeffs.begin(),coeffs.end()) == construct(0));
|
||||
|
|
@ -135,7 +135,10 @@ void test_construct_polynomial(const Polynomial_traits_d&){
|
|||
assert(p == p1+p2);
|
||||
|
||||
assert(construct(monom_rep. begin(),monom_rep. end())
|
||||
== construct(monom_rep.rbegin(),monom_rep.rend()));
|
||||
== construct(monom_rep.rbegin(),monom_rep.rend()));
|
||||
// test with boolean flag is_sorted
|
||||
assert(construct(monom_rep. begin(),monom_rep. end(),false)
|
||||
== construct(monom_rep.rbegin(),monom_rep.rend(),false));
|
||||
}
|
||||
std::cerr << " ok "<< std::endl;
|
||||
}
|
||||
|
|
@ -489,12 +492,26 @@ void test_shift(const Polynomial_traits_d&){
|
|||
std::cerr << "start test_shift "; std::cerr.flush();
|
||||
CGAL_SNAP_CGALi_TRAITS_D(Polynomial_traits_d);
|
||||
typename PT::Shift shift;
|
||||
typename PT::Swap swap;
|
||||
typename PT::Construct_polynomial construct;
|
||||
for(int i = 0; i < 5; i++){
|
||||
Polynomial_d p = generate_sparse_random_polynomial<Polynomial_d>();
|
||||
Polynomial_d q = p*CGAL::ipower(construct(Coeff(0),Coeff(1)),5);
|
||||
assert(shift(p,5) == q);
|
||||
}
|
||||
int d = Polynomial_traits_d::d;
|
||||
if( d > 1){
|
||||
assert(shift(Polynomial_d(1),1,0) != shift(Polynomial_d(1),1,1));
|
||||
assert(shift(Polynomial_d(1),1,0) != shift(Polynomial_d(1),1,1));
|
||||
assert(shift(Polynomial_d(1),1,0) != shift(Polynomial_d(1),1,d-1));
|
||||
assert(shift(Polynomial_d(1),1,0) != shift(Polynomial_d(1),1,d-1));
|
||||
|
||||
assert(shift(Polynomial_d(1),1,0) == swap(shift(Polynomial_d(1),1,1),0,1));
|
||||
assert(shift(Polynomial_d(1),1,0) == swap(shift(Polynomial_d(1),1,1),0,1));
|
||||
assert(shift(Polynomial_d(1),1,0) == swap(shift(Polynomial_d(1),1,d-1),0,d-1));
|
||||
assert(shift(Polynomial_d(1),1,0) == swap(shift(Polynomial_d(1),1,d-1),0,d-1));
|
||||
|
||||
}
|
||||
std::cerr << " ok "<< std::endl;
|
||||
}
|
||||
// // Negate;
|
||||
|
|
|
|||
Loading…
Reference in New Issue