From 15acb63eb306f37235fedc3128c2334e462f84ef Mon Sep 17 00:00:00 2001 From: Michael Hemmer Date: Sun, 28 Jun 2009 13:10:48 +0000 Subject: [PATCH] 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. --- .../NumberTypeSupport_ref/Sqrt_extension.tex | 2 +- .../CGAL/Sqrt_extension/Sqrt_extension_type.h | 13 +++++-- .../test/Number_types/Sqrt_extension.cpp | 36 +++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Number_types/doc_tex/NumberTypeSupport_ref/Sqrt_extension.tex b/Number_types/doc_tex/NumberTypeSupport_ref/Sqrt_extension.tex index 6a33954c33b..da322c6b147 100644 --- a/Number_types/doc_tex/NumberTypeSupport_ref/Sqrt_extension.tex +++ b/Number_types/doc_tex/NumberTypeSupport_ref/Sqrt_extension.tex @@ -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. diff --git a/Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h b/Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h index 72c646b327a..86bb1943709 100644 --- a/Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h +++ b/Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h @@ -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 & y){ return (std::max)(x,y); } +template inline +CGAL::Comparison_result compare ( + const Sqrt_extension& x, + const Sqrt_extension& y, + bool in_same_extension = true ){ + return x.compare(y,in_same_extension); +} CGAL_END_NAMESPACE diff --git a/Number_types/test/Number_types/Sqrt_extension.cpp b/Number_types/test/Number_types/Sqrt_extension.cpp index 86f58c8d595..104afa64b6b 100644 --- a/Number_types/test/Number_types/Sqrt_extension.cpp +++ b/Number_types/test/Number_types/Sqrt_extension.cpp @@ -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 +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 void general_test(){ typedef typename CGAL::Algebraic_structure_traits::Is_exact Is_exact; @@ -379,6 +411,10 @@ void general_test(){ io_test(); to_double_test(); + + test_compare(); + test_compare(); + test_compare(); }