BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/certified_numeric_predicates.h
Go to the documentation of this file.
00001 // Copyright (c) 2006-2008 Fernando Luis Cacciola Carballal. All rights reserved.
00002 //
00003 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public License as
00005 // published by the Free Software Foundation; version 2.1 of the License.
00006 // See the file LICENSE.LGPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Straight_skeleton_2/include/CGAL/certified_numeric_predicates.h $
00015 // $Id: certified_numeric_predicates.h 44650 2008-07-30 13:13:26Z spion $
00016 //
00017 // Author(s)     : Fernando Cacciola <fernando_cacciola@ciudad.com.ar>
00018 //
00019 #ifndef CGAL_CERTIFIED_NUMERIC_PREDICATES_H
00020 #define CGAL_CERTIFIED_NUMERIC_PREDICATES_H
00021 
00022 #include <CGAL/number_utils.h>
00023 #include <CGAL/Interval_arithmetic.h>
00024 #include <CGAL/Uncertain.h>
00025 
00026 CGAL_BEGIN_NAMESPACE
00027 
00028 inline Uncertain<bool> logical_or ( Uncertain<bool> a, Uncertain<bool> b ) { return a | b ; }
00029 inline Uncertain<bool> logical_and( Uncertain<bool> a, Uncertain<bool> b ) { return a & b ; }
00030 
00031 inline Uncertain<bool> logical_or ( Uncertain<bool> a, Uncertain<bool> b, Uncertain<bool> c ) { return a | b | c ; }
00032 inline Uncertain<bool> logical_and( Uncertain<bool> a, Uncertain<bool> b, Uncertain<bool> c ) { return a & b & c ; }
00033 
00034 template <class NT>
00035 inline Uncertain<bool> certified_is_zero(const NT& x)
00036 {
00037   return CGAL_NTS is_valid(x) ? make_uncertain(CGAL_NTS is_zero(x)) : Uncertain<bool>::indeterminate() ; 
00038 }
00039 
00040 template <class NT>
00041 inline Uncertain<bool> certified_is_not_zero(const NT& x)
00042 {
00043   return CGAL_NTS is_valid(x) ? make_uncertain(!CGAL_NTS is_zero(x)) : Uncertain<bool>::indeterminate() ; 
00044 }
00045 
00046 template <class NT>
00047 inline Uncertain<bool> certified_is_one(const NT& x)
00048 {
00049   return CGAL_NTS is_valid(x) ? make_uncertain(CGAL_NTS is_one(x) ) : Uncertain<bool>::indeterminate() ;
00050 }
00051 
00052 template <class NT>
00053 inline Uncertain<bool> certified_is_negative(const NT& x)
00054 {
00055   return CGAL_NTS is_valid(x) ? make_uncertain(CGAL_NTS is_negative(x) ) : Uncertain<bool>::indeterminate()  ;
00056 }
00057 
00058 template <class NT>
00059 inline Uncertain<bool> certified_is_positive(const NT& x)
00060 {
00061   return CGAL_NTS is_valid(x) ? make_uncertain(CGAL_NTS is_positive(x) ) : Uncertain<bool>::indeterminate() ;
00062 }
00063 
00064 template <class NT>
00065 inline Uncertain<Sign> certified_sign(const NT& x)
00066 {
00067   return CGAL_NTS is_valid(x) ? make_uncertain(CGAL_NTS sign(x)) : Uncertain<Sign>::indeterminate() ;
00068 }
00069 
00070 template <class NT1, class NT2>
00071 inline Uncertain<Comparison_result> certified_compare(const NT1& n1, const NT2& n2)
00072 {
00073   return CGAL_NTS is_valid(n1) && CGAL_NTS is_valid(n2) ? make_uncertain(CGAL_NTS compare(n1,n2)) 
00074                                                         : Uncertain<Comparison_result>::indeterminate()  ;
00075 }
00076 
00077 inline Uncertain<bool> certified_is_smaller( Uncertain<Comparison_result> c )
00078 {
00079   return c == SMALLER;
00080 }
00081 
00082 inline Uncertain<bool> certified_is_equal( Uncertain<Comparison_result> c )
00083 {
00084   return c == EQUAL;
00085 }
00086 
00087 inline Uncertain<bool> certified_is_larger( Uncertain<Comparison_result> c )
00088 {
00089   return c == LARGER;
00090 }
00091 
00092 inline Uncertain<bool> certified_is_smaller_or_equal( Uncertain<Comparison_result> c )
00093 {
00094   return logical_or( c == SMALLER , c == EQUAL ) ;
00095 }
00096 
00097 inline Uncertain<bool> certified_is_larger_or_equal( Uncertain<Comparison_result> c )
00098 {
00099   return logical_or( c == LARGER , c == EQUAL ) ;
00100 }
00101 
00102 template <class NT1, class NT2>
00103 inline Uncertain<bool> certified_is_smaller(const NT1& n1, const NT2& n2)
00104 {
00105   return certified_is_smaller(certified_compare(n1,n2));
00106 }
00107 
00108 template <class NT1, class NT2>
00109 inline Uncertain<bool> certified_is_equal(const NT1& n1, const NT2& n2)
00110 {
00111   return certified_is_equal(certified_compare(n1,n2));
00112 }
00113 
00114 template <class NT1, class NT2>
00115 inline Uncertain<bool> certified_is_larger(const NT1& n1, const NT2& n2)
00116 {
00117   return certified_is_larger(certified_compare(n1,n2));
00118 }
00119 
00120 template <class NT1, class NT2>
00121 inline Uncertain<bool> certified_is_smaller_or_equal(const NT1& n1, const NT2& n2)
00122 {
00123   return certified_is_smaller_or_equal(certified_compare(n1,n2)) ;
00124 }
00125 
00126 template <class NT1, class NT2>
00127 inline Uncertain<bool> certified_is_larger_or_equal(const NT1& n1, const NT2& n2)
00128 {
00129   return certified_is_larger_or_equal(certified_compare(n1,n2)) ;
00130 }
00131 
00132 template <class NT>
00133 inline Uncertain<Sign> certified_sign_of_determinant2x2( const NT& a00
00134                                                        , const NT& a01
00135                                                        , const NT& a10
00136                                                        , const NT& a11
00137                                                        )
00138 {
00139   return certified_compare(a00*a11, a10*a01) ;
00140 }
00141 
00142 CGAL_END_NAMESPACE
00143 
00144 #endif // CGAL_CERTIFIED_NUMERIC_PREDICATES_H
00145 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines