mirror of https://github.com/CGAL/cgal
added public type Boolean to Algebraic_structure_traits
This commit is contained in:
parent
97dcbd0649
commit
cf6fe3a5ec
|
|
@ -60,6 +60,13 @@ A model of \ccc{AlgebraicStructureTraits} is supposed to provide:\\
|
|||
number of an algorithm.
|
||||
}
|
||||
|
||||
\ccNestedType{Boolean}
|
||||
{ This type specifies the return type of the predicates provided
|
||||
by this traits. The type must be convertible to \ccc{bool} and
|
||||
typically the type indeed maps to \ccc{bool}. However, there are also
|
||||
cases such as interval arithmetic, in which it is \ccc{Uncertain<bool>}
|
||||
or some similar type.
|
||||
}
|
||||
|
||||
\ccHeading{Functors}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ The second operator returns $c$ via the additional third argument.
|
|||
|
||||
\ccTypes
|
||||
\ccNestedType{result_type}
|
||||
{ Type convertible to \ccc{bool}.}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Boolean}.}
|
||||
\ccGlue
|
||||
\ccNestedType{first_argument}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Type}.}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ returns true in case the argument is the one of the ring.
|
|||
|
||||
\ccTypes
|
||||
\ccNestedType{result_type}
|
||||
{ Type convertible to \ccc{bool}.}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Boolean}.}
|
||||
\ccNestedType{argument_type}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Type}.}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ $y$ is uniquely defined up to multiplication by units. \\
|
|||
|
||||
\ccTypes
|
||||
\ccNestedType{result_type}
|
||||
{ Type convertible to \ccc{bool}.}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Boolean}.}
|
||||
\ccGlue
|
||||
\ccNestedType{first_argument}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Type}.}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
\ccTypes
|
||||
\ccNestedType{result_type}
|
||||
{ Type convertible to \ccc{bool}.}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Boolean}.}
|
||||
\ccNestedType{argument_type}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Type}.}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,13 +78,15 @@ Moreover, \ccc{CGAL::Algebraic_structure_traits< IntegralDomainWithoutDivision >
|
|||
|
||||
Equality comparable:
|
||||
|
||||
\ccFunction{bool
|
||||
\ccFunction{ result_type
|
||||
operator==(const IntegralDomainWithoutDivision &a,
|
||||
const IntegralDomainWithoutDivision &b);}{}
|
||||
const IntegralDomainWithoutDivision &b);}
|
||||
{The \ccc{result_type} is convertible to \ccc{bool}. }
|
||||
\ccGlue
|
||||
\ccFunction{bool
|
||||
\ccFunction{ result_type
|
||||
operator!=(const IntegralDomainWithoutDivision &a,
|
||||
const IntegralDomainWithoutDivision &b);}{}
|
||||
const IntegralDomainWithoutDivision &b);}
|
||||
{The \ccc{result_type} is convertible to \ccc{bool}. }
|
||||
\ccGlue
|
||||
|
||||
\ccSeeAlso
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ class Algebraic_structure_traits_base< Type_, Null_tag > {
|
|||
typedef Null_tag Algebraic_category;
|
||||
typedef Tag_false Is_exact;
|
||||
typedef Null_tag Is_numerical_sensitive;
|
||||
typedef Null_tag Boolean;
|
||||
|
||||
// does nothing by default
|
||||
class Simplify
|
||||
|
|
@ -137,8 +138,9 @@ class Algebraic_structure_traits_base< Type_,
|
|||
: public Algebraic_structure_traits_base< Type_,
|
||||
Null_tag > {
|
||||
public:
|
||||
typedef Type_ Type;
|
||||
typedef Type_ Type;
|
||||
typedef Integral_domain_without_division_tag Algebraic_category;
|
||||
typedef bool Boolean;
|
||||
|
||||
// returns Type(1) by default
|
||||
class Unit_part
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ void test_algebraic_structure_intern( const CGAL::Integral_domain_tag& ) {
|
|||
typedef typename AST::Is_exact Is_exact;
|
||||
// VC7 produced an ICE for
|
||||
// assert( ! Is_exact::value || ... );
|
||||
bool ie = Is_exact::value;
|
||||
bool ie = Is_exact::value; (void) ie;
|
||||
AS tmp;
|
||||
assert( divides(b,AS(0),tmp));
|
||||
assert( !ie || tmp == integral_division(AS(0),b));
|
||||
|
|
@ -749,6 +749,15 @@ void test_Type_functions( const CGAL::Field_with_root_of_tag&) {
|
|||
*/
|
||||
}
|
||||
|
||||
// checks the result type of a functor
|
||||
template <typename AdaptableFunctor, typename ResultType>
|
||||
void check_result_type(AdaptableFunctor, ResultType){
|
||||
typedef typename AdaptableFunctor::result_type result_type;
|
||||
BOOST_STATIC_ASSERT((::boost::is_same<result_type,ResultType>::value));
|
||||
}
|
||||
// check nothing for CGAL::Null_functor
|
||||
template <typename ResultType>
|
||||
void check_result_type(CGAL::Null_functor, ResultType){}
|
||||
|
||||
template <class AS , class Algebraic_category, class Is_exact>
|
||||
void test_algebraic_structure(){
|
||||
|
|
@ -756,11 +765,18 @@ void test_algebraic_structure(){
|
|||
test_Type_functions< AS >(Algebraic_category());
|
||||
|
||||
typedef CGAL::Algebraic_structure_traits< AS > AST;
|
||||
BOOST_STATIC_ASSERT((::boost::is_same<AS,typename AST::Type>::value));
|
||||
|
||||
CGAL_SNAP_AST_FUNCTORS(AST);
|
||||
typedef typename AST::Algebraic_category Tag;
|
||||
|
||||
BOOST_STATIC_ASSERT((::boost::is_same<AS,typename AST::Type>::value));
|
||||
|
||||
typedef typename AST::Boolean Boolean;
|
||||
assert(!Boolean());
|
||||
check_result_type(Is_zero(), Boolean());
|
||||
check_result_type(Is_one(), Boolean());
|
||||
check_result_type(Divides(), Boolean());
|
||||
check_result_type(Is_square(), Boolean());
|
||||
|
||||
typedef typename AST::Algebraic_category Tag;
|
||||
using CGAL::Integral_domain_without_division_tag;
|
||||
using CGAL::Null_functor;
|
||||
// Test for desired exactness
|
||||
|
|
@ -879,7 +895,8 @@ void test_algebraic_structure(){
|
|||
}
|
||||
|
||||
template <class AS , class Algebraic_category, class Is_exact >
|
||||
void test_algebraic_structure( const AS & a, const AS & b, const AS & c) {
|
||||
void test_algebraic_structure( const AS & a, const AS & b, const AS & c) {
|
||||
|
||||
assert( a != AS (0));
|
||||
assert( b != AS (0));
|
||||
assert( c != AS (0));
|
||||
|
|
|
|||
|
|
@ -1183,19 +1183,20 @@ class Algebraic_structure_traits< Interval_nt<B> >
|
|||
typedef Interval_nt<B> Type;
|
||||
typedef Tag_false Is_exact;
|
||||
typedef Tag_true Is_numerical_sensitive;
|
||||
typedef Uncertain<bool> Boolean;
|
||||
|
||||
class Is_zero
|
||||
: public std::unary_function< Type, Uncertain<bool> > {
|
||||
: public std::unary_function< Type, Boolean > {
|
||||
public:
|
||||
Uncertain<bool> operator()( const Type& x ) const {
|
||||
Boolean operator()( const Type& x ) const {
|
||||
return INTERN_INTERVAL_NT::is_zero( x );
|
||||
}
|
||||
};
|
||||
|
||||
class Is_one
|
||||
: public std::unary_function< Type, Uncertain<bool> > {
|
||||
: public std::unary_function< Type, Boolean > {
|
||||
public:
|
||||
Uncertain<bool> operator()( const Type& x ) const {
|
||||
Boolean operator()( const Type& x ) const {
|
||||
return INTERN_INTERVAL_NT::is_one( x );
|
||||
}
|
||||
};
|
||||
|
|
@ -1217,16 +1218,16 @@ class Algebraic_structure_traits< Interval_nt<B> >
|
|||
};
|
||||
|
||||
struct Is_square
|
||||
:public std::binary_function<Interval_nt<B>,Interval_nt<B>&,Uncertain<bool> >
|
||||
:public std::binary_function<Interval_nt<B>,Interval_nt<B>&,Boolean >
|
||||
{
|
||||
bool operator()(const Interval_nt<B>& x) const {
|
||||
Boolean operator()(const Interval_nt<B>& x) const {
|
||||
return INTERN_INTERVAL_NT::is_positive( x );
|
||||
}
|
||||
|
||||
bool operator()(
|
||||
Boolean operator()(
|
||||
const Interval_nt<B>& x,
|
||||
Interval_nt<B> & result) const {
|
||||
Uncertain<bool> is_positive = INTERN_INTERVAL_NT::is_positive( x );
|
||||
Boolean is_positive = INTERN_INTERVAL_NT::is_positive( x );
|
||||
if ( is_positive.inf() == true ){
|
||||
typename Algebraic_structure_traits<Interval_nt<B> >::Sqrt sqrt;
|
||||
result = sqrt(x);
|
||||
|
|
@ -1238,6 +1239,21 @@ class Algebraic_structure_traits< Interval_nt<B> >
|
|||
return is_positive;
|
||||
}
|
||||
};
|
||||
|
||||
class Divides
|
||||
: public std::binary_function< Type, Type, Boolean > {
|
||||
public:
|
||||
Boolean operator()( const Type& x, const Type&) const {
|
||||
return ! Is_zero()(x);
|
||||
}
|
||||
// second operator computing q
|
||||
Boolean operator()( const Type& x, const Type& y, Type& q) const {
|
||||
if (! Is_zero()(x) )
|
||||
q = y/x ;
|
||||
return Boolean(true);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -421,7 +421,8 @@ class NTC_AST_base
|
|||
template < typename NT1, typename NT2, typename Cmp >
|
||||
class NTC_AST_base
|
||||
< Number_type_checker<NT1, NT2, Cmp> , Integral_domain_without_division_tag>
|
||||
:public Algebraic_structure_traits_base<Number_type_checker<NT1, NT2, Cmp>, Null_tag>
|
||||
:public Algebraic_structure_traits_base<Number_type_checker<NT1, NT2, Cmp>,
|
||||
Integral_domain_without_division_tag>
|
||||
{
|
||||
private:
|
||||
typedef Algebraic_structure_traits<NT1> AST1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue