dust3d/thirdparty/cgal/CGAL-5.1/include/CGAL/Straight_skeleton_2/test.h

170 lines
5.5 KiB
C
Raw Normal View History

// Copyright (c) 2007 Fernando Luis Cacciola Carballal. All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
2020-10-13 12:44:25 +00:00
// $URL: https://github.com/CGAL/cgal/blob/v5.1/Straight_skeleton_2/include/CGAL/Straight_skeleton_2/test.h $
// $Id: test.h e9d41d7 2020-04-21T10:03:00+02:00 Maxime Gimeno
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Fernando Cacciola <fernando_cacciola@ciudad.com.ar>
#ifndef CGAL_STRAIGHT_SKELETON_TEST_H
#define CGAL_STRAIGHT_SKELETON_TEST_H 1
#include <CGAL/license/Straight_skeleton_2.h>
//
// INTRINSIC UNIT TESTING macros.
//
// These are OFF by default and should only be turn on by the testsuite.
//
//
2020-10-13 12:44:25 +00:00
// These are assertions that may not be true unless certain external conditions are met, such as the kernel
// beigng exact or the input being specifically designed to be non-degenerate, avoid significant round-off, etc.
//
#ifdef CGAL_STRAIGHT_SKELETON_ENABLE_INTRINSIC_TESTING
# define CGAL_stskel_intrinsic_test_assertion(EX) ((EX)?(static_cast<void>(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__, 0))
# define CGAL_stskel_intrinsic_test_assertion_msg(EX,MSG) ((EX)?(static_cast<void>(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__, MSG))
# define CGAL_stskel_intrinsic_test_assertion_code(CODE) CODE
2020-10-13 12:44:25 +00:00
# define CGAL_stskel_intrinsic_test_trace(m) std::cerr << m << std::endl
# define CGAL_stskel_intrinsic_test_trace_if(EX,m) if ( (EX) ) { std::cerr << m << std::endl ; }
#else
# define CGAL_stskel_intrinsic_test_assertion(EX) (static_cast<void>(0))
# define CGAL_stskel_intrinsic_test_assertion_msg(EX,MSG) (static_cast<void>(0))
# define CGAL_stskel_intrinsic_test_assertion_code(CODE)
2020-10-13 12:44:25 +00:00
# define CGAL_stskel_intrinsic_test_trace(m)
# define CGAL_stskel_intrinsic_test_trace_if(EX,m)
#endif
namespace CGAL {
namespace CGAL_SS_i {
//
// The following tests are used by the testsuite only.
//
// Their purpose is to detect clearly wrong results without resorting to exact constructions.
//
2020-10-13 12:44:25 +00:00
// These are negative tests only. For instance, they don't test whether a number is zero (since it can be
// near zero but not exactly due to roundoff); rather, they test whether a number is clearly not zero,
// which is a test that can be done robustelly if a pesimistic upper bound on the error is know.
2020-10-13 12:44:25 +00:00
//
// The test are overloaded on number types so if exact constructions are used, the tests are exact.
inline bool is_possibly_inexact_distance_clearly_not_zero ( double n, double eps )
{
2020-10-13 12:44:25 +00:00
return std::abs( CGAL_NTS to_double(n) ) > eps ;
}
#ifdef CGAL_CORE_EXPR_H
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_distance_clearly_not_zero ( CORE::Expr const& n )
{
return ! CGAL_NTS is_zero(n);
2020-10-13 12:44:25 +00:00
}
#endif
#ifdef CGAL_LEDA_REAL_H
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_distance_clearly_not_zero ( leda_real const& n )
{
return ! CGAL_NTS is_zero(n);
2020-10-13 12:44:25 +00:00
}
#endif
#ifdef CGAL_GMPQ_H
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_distance_clearly_not_zero ( Gmpq const& n )
{
return is_possibly_inexact_distance_clearly_not_zero( to_double(n), 1e-8 ) ;
2020-10-13 12:44:25 +00:00
}
#endif
2020-10-13 12:44:25 +00:00
#ifdef CGAL_MP_FLOAT_H
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_distance_clearly_not_zero ( MP_Float const& n )
{
return is_possibly_inexact_distance_clearly_not_zero( to_double(n), 1e-8 ) ;
2020-10-13 12:44:25 +00:00
}
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_distance_clearly_not_zero ( Quotient<MP_Float> const& n )
{
return is_possibly_inexact_distance_clearly_not_zero( to_double(n), 1e-8 ) ;
2020-10-13 12:44:25 +00:00
}
#endif
#if defined(CGAL_LAZY_EXACT_NT_H)
template<class NT>
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_distance_clearly_not_zero ( Lazy_exact_nt<NT> const& n )
{
return is_possibly_inexact_distance_clearly_not_zero( to_double(n), 1e-8 ) ;
2020-10-13 12:44:25 +00:00
}
#endif
inline bool is_possibly_inexact_distance_clearly_not_zero ( double n )
{
2020-10-13 12:44:25 +00:00
return std::abs( CGAL_NTS to_double(n) ) > 1e-5 ;
}
inline bool is_possibly_inexact_distance_clearly_not_zero ( Interval_nt_advanced const& n )
{
2020-10-13 12:44:25 +00:00
return is_possibly_inexact_distance_clearly_not_zero(to_double(n));
}
template<class NT>
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_distance_clearly_not_equal_to( NT const& n, NT const& m )
{
return is_possibly_inexact_distance_clearly_not_zero(n-m);
}
template<class NT>
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_time_clearly_not_zero( NT const& n )
{
return is_possibly_inexact_distance_clearly_not_zero(n);
}
template<class NT>
2020-10-13 12:44:25 +00:00
inline bool is_possibly_inexact_time_clearly_not_equal_to( NT const& n, NT const& m )
{
return is_possibly_inexact_distance_clearly_not_zero(n-m);
}
template<class FT, class Bisector>
inline bool is_time_clearly_not_within_possibly_inexact_bisector_time_interval( FT const& aT , Bisector const& aBisector )
{
FT lSrcT = aBisector->opposite()->vertex()->time() ;
FT lTgtT = aBisector->vertex()->time() ;
2020-10-13 12:44:25 +00:00
FT lLoT = (std::min)(lSrcT,lTgtT);
FT lHiT = (std::max)(lSrcT,lTgtT);
return ( aT < lLoT || aT > lHiT )
&& is_possibly_inexact_time_clearly_not_equal_to(aT,lLoT)
&& is_possibly_inexact_time_clearly_not_equal_to(aT,lHiT) ;
}
template<class FT, class Bisector>
inline bool is_time_clearly_within_possibly_inexact_bisector_time_interval( FT const& aT , Bisector const& aBisector )
{
FT lSrcT = aBisector->opposite()->vertex()->time() ;
FT lTgtT = aBisector->vertex()->time() ;
2020-10-13 12:44:25 +00:00
FT lLoT = (std::min)(lSrcT,lTgtT);
FT lHiT = (std::max)(lSrcT,lTgtT);
return ( lLoT < aT && aT < lHiT )
&& is_possibly_inexact_time_clearly_not_equal_to(aT,lLoT)
&& is_possibly_inexact_time_clearly_not_equal_to(aT,lHiT) ;
}
} // namespace CGAL_SS_i
} // end namespace CGAL
#endif // CGAL_STRAIGHT_SKELETON_TEST_H //
// EOF //
2020-10-13 12:44:25 +00:00