mirror of https://github.com/CGAL/cgal
apply modular filter to gcd functors
This commit is contained in:
parent
1ca86be74c
commit
b6aa6d8644
|
|
@ -192,6 +192,16 @@ class Polynomial_algebraic_structure_traits_base< POLY, Unique_factorization_dom
|
||||||
|
|
||||||
class Gcd
|
class Gcd
|
||||||
: public std::binary_function< POLY, POLY, POLY > {
|
: public std::binary_function< POLY, POLY, POLY > {
|
||||||
|
typedef typename Polynomial_traits_d<POLY>::Multivariate_content Mcontent;
|
||||||
|
typedef typename Mcontent::result_type ICoeff;
|
||||||
|
|
||||||
|
ICoeff gcd_help(const ICoeff& x, const ICoeff& y, Field_tag) const {
|
||||||
|
return ICoeff(1);
|
||||||
|
}
|
||||||
|
ICoeff gcd_help(const ICoeff& x, const ICoeff& y,
|
||||||
|
Unique_factorization_domain_tag) const {
|
||||||
|
return CGAL::gcd(x,y);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
POLY operator()( const POLY& x, const POLY& y ) const {
|
POLY operator()( const POLY& x, const POLY& y ) const {
|
||||||
typedef Algebraic_structure_traits<POLY> AST;
|
typedef Algebraic_structure_traits<POLY> AST;
|
||||||
|
|
@ -199,19 +209,23 @@ class Polynomial_algebraic_structure_traits_base< POLY, Unique_factorization_dom
|
||||||
typename AST::Unit_part upart;
|
typename AST::Unit_part upart;
|
||||||
|
|
||||||
// First: the extreme cases and negative sign corrections.
|
// First: the extreme cases and negative sign corrections.
|
||||||
if (x == POLY(0)) {
|
if (CGAL::is_zero(x)) {
|
||||||
if (y == POLY(0))
|
if (CGAL::is_zero(y))
|
||||||
return POLY(0);
|
return POLY(0);
|
||||||
return idiv(y,upart(y));
|
return idiv(y,upart(y));
|
||||||
}
|
}
|
||||||
if (y == POLY(0))
|
if (CGAL::is_zero(y))
|
||||||
return idiv(x,upart(x));
|
return idiv(x,upart(x));
|
||||||
|
|
||||||
|
if (CGALi::may_have_common_factor(x,y))
|
||||||
return CGALi::gcd(x,y);
|
return CGALi::gcd(x,y);
|
||||||
|
else{
|
||||||
|
typename Algebraic_structure_traits<ICoeff>::Algebraic_category category;
|
||||||
|
return POLY(gcd_help(Mcontent()(x),Mcontent()(y), category));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR( POLY )
|
CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR( POLY )
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1111,9 +1111,15 @@ public:
|
||||||
:public std::binary_function<Polynomial_d, Polynomial_d, Polynomial_d> {
|
:public std::binary_function<Polynomial_d, Polynomial_d, Polynomial_d> {
|
||||||
Polynomial_d
|
Polynomial_d
|
||||||
operator()(const Polynomial_d& p, const Polynomial_d& q) const {
|
operator()(const Polynomial_d& p, const Polynomial_d& q) const {
|
||||||
if (CGAL::is_zero(p) && CGAL::is_zero(q))
|
if (CGAL::is_zero(p) && CGAL::is_zero(q)){
|
||||||
return Polynomial_d(0);
|
return Polynomial_d(0);
|
||||||
|
}
|
||||||
|
// apply modular filter first
|
||||||
|
if (CGALi::may_have_common_factor(p,q)){
|
||||||
return CGALi::gcd_utcf(p,q);
|
return CGALi::gcd_utcf(p,q);
|
||||||
|
}else{
|
||||||
|
return Polynomial_d(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue