mirror of https://github.com/CGAL/cgal
semantic change
change default of .compare: now expecting that two numbers are from the same extension added CGAL::compare with analog interface, added test, updated documentation This is more consistent with all compare operators which expect the same anyway. This change should increase the performace of related code considerably.
This commit is contained in:
parent
7e57232a0d
commit
15acb63eb3
|
|
@ -143,7 +143,7 @@ $a0 + a1 * sqrt(root)$.
|
|||
|
||||
\ccMethod{
|
||||
Sqrt_extension compare
|
||||
(const Sqrt_extension& y, bool in_same_extension = false) const;}{
|
||||
(const Sqrt_extension& y, bool in_same_extension = true) const;}{
|
||||
Compares \ccVar\ with y. \\
|
||||
The optional bool \ccc{in_same_extension} indicates whether \ccVar\
|
||||
and $y$ are in the same extension of NT.
|
||||
|
|
|
|||
|
|
@ -422,9 +422,11 @@ compare (const NT& num) const {
|
|||
return ((Self(a0_ - num, a1_, root_)).sign_());
|
||||
}
|
||||
|
||||
// compare of two values with different extension
|
||||
// compare of two values that may be in different extension
|
||||
// However, the default is, that the the numbers are defined over the same
|
||||
// extension.
|
||||
CGAL::Comparison_result
|
||||
compare(const Self& y, bool in_same_extension = false ) const
|
||||
compare(const Self& y, bool in_same_extension = true ) const
|
||||
{
|
||||
if (! is_extended_)
|
||||
return (CGAL::opposite (y.compare (a0_)));
|
||||
|
|
@ -619,6 +621,13 @@ const Sqrt_extension<NT,ROOT> & y){
|
|||
return (std::max)(x,y);
|
||||
}
|
||||
|
||||
template <class NT, class ROOT> inline
|
||||
CGAL::Comparison_result compare (
|
||||
const Sqrt_extension<NT,ROOT>& x,
|
||||
const Sqrt_extension<NT,ROOT>& y,
|
||||
bool in_same_extension = true ){
|
||||
return x.compare(y,in_same_extension);
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -339,6 +339,38 @@ void to_double_test(){
|
|||
assert(to_interval(ext)==CGAL_NTS to_interval(-3.0) );
|
||||
}
|
||||
}
|
||||
|
||||
//This test is dedicated to the comaprison of numbers from different extensions
|
||||
template <class EXT>
|
||||
void test_compare(){
|
||||
typedef typename EXT::NT NT;
|
||||
typedef typename EXT::ROOT ROOT;
|
||||
|
||||
EXT a(NT(1),NT(-5),ROOT(7));
|
||||
EXT b(NT(2),NT(8),ROOT(5));
|
||||
EXT c(NT(3),NT(0),ROOT(3));
|
||||
|
||||
assert(a.compare(b,false)==CGAL::SMALLER);
|
||||
assert(a.compare(c,false)==CGAL::SMALLER);
|
||||
assert(b.compare(c,false)==CGAL::LARGER );
|
||||
assert(a.compare(a,false)==CGAL::EQUAL);
|
||||
assert(b.compare(b,false)==CGAL::EQUAL);
|
||||
assert(c.compare(c,false)==CGAL::EQUAL);
|
||||
assert(a.compare(a,true)==CGAL::EQUAL);
|
||||
assert(b.compare(b,true)==CGAL::EQUAL);
|
||||
assert(c.compare(c,true)==CGAL::EQUAL);
|
||||
|
||||
assert(CGAL::compare(a,b,false)==CGAL::SMALLER);
|
||||
assert(CGAL::compare(a,c,false)==CGAL::SMALLER);
|
||||
assert(CGAL::compare(b,c,false)==CGAL::LARGER );
|
||||
assert(CGAL::compare(a,a,false)==CGAL::EQUAL);
|
||||
assert(CGAL::compare(b,b,false)==CGAL::EQUAL);
|
||||
assert(CGAL::compare(c,c,false)==CGAL::EQUAL);
|
||||
assert(CGAL::compare(a,a,true)==CGAL::EQUAL);
|
||||
assert(CGAL::compare(b,b,true)==CGAL::EQUAL);
|
||||
assert(CGAL::compare(c,c,true)==CGAL::EQUAL);
|
||||
}
|
||||
|
||||
template <class NT, class ROOT, class Algebraic_type>
|
||||
void general_test(){
|
||||
typedef typename CGAL::Algebraic_structure_traits<NT>::Is_exact Is_exact;
|
||||
|
|
@ -379,6 +411,10 @@ void general_test(){
|
|||
io_test<EXT3>();
|
||||
|
||||
to_double_test<EXT1>();
|
||||
|
||||
test_compare<EXT1>();
|
||||
test_compare<EXT2>();
|
||||
test_compare<EXT3>();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue