BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Straight_skeleton_2/test.h
Go to the documentation of this file.
00001 // Copyright (c) 2007 Fernando Luis Cacciola Carballal. All rights reserved.
00002 //
00003 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00004 // the terms of the Q Public License version 1.0.
00005 // See the file LICENSE.QPL distributed with CGAL.
00006 //
00007 // Licensees holding a valid commercial license may use this file in
00008 // accordance with the commercial license agreement provided with the software.
00009 //
00010 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 //
00013 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Straight_skeleton_2/include/CGAL/Straight_skeleton_2/test.h $
00014 // $Id: test.h 41590 2008-01-14 13:44:13Z fcacciola $
00015 // 
00016 // Author(s)     : Fernando Cacciola <fernando_cacciola@ciudad.com.ar>
00017 
00018 #ifndef CGAL_STRAIGHT_SKELETON_TEST_H
00019 #define CGAL_STRAIGHT_SKELETON_TEST_H 1
00020 
00021 //
00022 // INTRINSIC UNIT TESTING macros.
00023 //
00024 // These are OFF by default and should only be turn on by the testsuite.
00025 //
00026 
00027 //
00028 // These are assertions that may not be true unless certain external conditions are met, such as the kernel 
00029 // beigng exact or the input being specifically designed to be non-degenerate, avoid significant round-off, etc.
00030 //
00031 #ifdef CGAL_STRAIGHT_SKELETON_ENABLE_INTRINSIC_TESTING
00032 #  define CGAL_stskel_intrinsic_test_assertion(EX)          ((EX)?(static_cast<void>(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__, 0))
00033 #  define CGAL_stskel_intrinsic_test_assertion_msg(EX,MSG)  ((EX)?(static_cast<void>(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__, MSG))
00034 #  define CGAL_stskel_intrinsic_test_assertion_code(CODE)   CODE
00035 #  define CGAL_stskel_intrinsic_test_trace(m)               std::cerr << m << std::endl 
00036 #  define CGAL_stskel_intrinsic_test_trace_if(EX,m)         if ( (EX) ) { std::cerr << m << std::endl ; }
00037 #else
00038 #  define CGAL_stskel_intrinsic_test_assertion(EX)         (static_cast<void>(0))
00039 #  define CGAL_stskel_intrinsic_test_assertion_msg(EX,MSG) (static_cast<void>(0))
00040 #  define CGAL_stskel_intrinsic_test_assertion_code(CODE)
00041 #  define CGAL_stskel_intrinsic_test_trace(m)    
00042 #  define CGAL_stskel_intrinsic_test_trace_if(EX,m)
00043 #endif
00044 
00045 #ifdef CGAL_STRAIGHT_SKELETON_ENABLE_INTRINSIC_TESTING
00046 
00047 CGAL_BEGIN_NAMESPACE
00048 
00049 namespace CGAL_SS_i {
00050 
00051 //
00052 // The following tests are used by the testsuite only.
00053 //
00054 // Their purpose is to detect clearly wrong results without resorting to exact constructions.
00055 //
00056 // These are negative tests only. For instance, they don't test whether a number is zero (since it can be 
00057 // near zero but not exactly due to roundoff); rather, they test whether a number is clearly not zero,
00058 // which is a test that can be done robustelly if a pesimistic upper bound on the error is know.
00059 //  
00060 // The test are overloaded on number types so if exact constructions are used, the tests are exact.
00061 
00062 inline bool is_possibly_inexact_distance_clearly_not_zero ( double n, double eps )
00063 {
00064   return std::abs( CGAL_NTS to_double(n) ) > eps ; 
00065 }
00066 
00067 #ifdef CGAL_CORE_EXPR_H
00068 inline bool is_possibly_inexact_distance_clearly_not_zero ( CORE::Expr const& n ) 
00069 { 
00070   return ! CGAL_NTS is_zero(n);
00071 }  
00072 #endif
00073 
00074 #ifdef CGAL_LEDA_REAL_H
00075 inline bool is_possibly_inexact_distance_clearly_not_zero ( leda_real const& n ) 
00076 { 
00077   return ! CGAL_NTS is_zero(n);
00078 }  
00079 #endif
00080 
00081 #ifdef CGAL_GMPQ_H
00082 inline bool is_possibly_inexact_distance_clearly_not_zero ( Gmpq const& n ) 
00083 { 
00084   return is_possibly_inexact_distance_clearly_not_zero( to_double(n), 1e-8 ) ;
00085 }  
00086 #endif
00087     
00088 #ifdef CGAL_MP_FLOAT_H
00089 inline bool is_possibly_inexact_distance_clearly_not_zero ( MP_Float const& n ) 
00090 { 
00091   return is_possibly_inexact_distance_clearly_not_zero( to_double(n), 1e-8 ) ;
00092 }  
00093 
00094 inline bool is_possibly_inexact_distance_clearly_not_zero ( Quotient<MP_Float> const& n ) 
00095 { 
00096   return is_possibly_inexact_distance_clearly_not_zero( to_double(n), 1e-8 ) ;
00097 }  
00098 #endif
00099 
00100 #if defined(CGAL_LAZY_EXACT_NT_H)
00101 template<class NT>
00102 inline bool is_possibly_inexact_distance_clearly_not_zero ( Lazy_exact_nt<NT> const& n ) 
00103 { 
00104   return is_possibly_inexact_distance_clearly_not_zero( to_double(n), 1e-8 ) ;
00105 }  
00106 #endif
00107 
00108 
00109 inline bool is_possibly_inexact_distance_clearly_not_zero ( double n )
00110 {
00111   return std::abs( CGAL_NTS to_double(n) ) > 1e-5 ; 
00112 }
00113 
00114 inline bool is_possibly_inexact_distance_clearly_not_zero ( Interval_nt_advanced const& n )
00115 {
00116   return is_possibly_inexact_distance_clearly_not_zero(to_double(n)); 
00117 }
00118 
00119 
00120 
00121 
00122 
00123 template<class NT>
00124 inline bool is_possibly_inexact_distance_clearly_not_equal_to( NT const& n, NT const& m ) 
00125 { 
00126   return is_possibly_inexact_distance_clearly_not_zero(n-m);
00127 }
00128 
00129 template<class NT>
00130 inline bool is_possibly_inexact_time_clearly_not_zero( NT const& n ) 
00131 { 
00132   return is_possibly_inexact_distance_clearly_not_zero(n);
00133 }
00134 
00135 template<class NT>
00136 inline bool is_possibly_inexact_time_clearly_not_equal_to( NT const& n, NT const& m ) 
00137 { 
00138   return is_possibly_inexact_distance_clearly_not_zero(n-m);
00139 }
00140 
00141 template<class FT, class Bisector>
00142 inline bool is_time_clearly_not_within_possibly_inexact_bisector_time_interval( FT const& aT , Bisector const& aBisector )
00143 {
00144   FT lSrcT = aBisector->opposite()->vertex()->time() ;
00145   FT lTgtT = aBisector->vertex()->time() ;
00146   FT lLoT  = std::min(lSrcT,lTgtT);
00147   FT lHiT  = std::max(lSrcT,lTgtT);
00148   
00149   return    ( aT < lLoT || aT > lHiT )
00150          && is_possibly_inexact_time_clearly_not_equal_to(aT,lLoT)
00151          && is_possibly_inexact_time_clearly_not_equal_to(aT,lHiT) ;
00152 }
00153 
00154 template<class FT, class Bisector>
00155 inline bool is_time_clearly_within_possibly_inexact_bisector_time_interval( FT const& aT , Bisector const& aBisector )
00156 {
00157   FT lSrcT = aBisector->opposite()->vertex()->time() ;
00158   FT lTgtT = aBisector->vertex()->time() ;
00159   FT lLoT  = std::min(lSrcT,lTgtT);
00160   FT lHiT  = std::max(lSrcT,lTgtT);
00161   
00162   return    ( lLoT < aT && aT < lHiT )
00163          && is_possibly_inexact_time_clearly_not_equal_to(aT,lLoT)
00164          && is_possibly_inexact_time_clearly_not_equal_to(aT,lHiT) ;
00165 }
00166 
00167 
00168 } // namespace CGAL_SS_i
00169 
00170 CGAL_END_NAMESPACE
00171 
00172 #endif
00173 
00174 #endif // CGAL_STRAIGHT_SKELETON_TEST_H //
00175 // EOF //
00176 
00177  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines