diff --git a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_melkman_impl.h b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_melkman_impl.h index 6ee62979250..4af027e992d 100644 --- a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_melkman_impl.h +++ b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_melkman_impl.h @@ -15,14 +15,14 @@ #include - #ifndef CGAL_CH_NO_POSTCONDITIONS #include #endif // CGAL_CH_NO_POSTCONDITIONS #include -#include -#include + +#include +#include namespace CGAL { diff --git a/Convex_hull_2/test/Convex_hull_2/ch2_point_with_info.cpp b/Convex_hull_2/test/Convex_hull_2/ch2_point_with_info.cpp index 7181e31ecec..72dee810a9a 100644 --- a/Convex_hull_2/test/Convex_hull_2/ch2_point_with_info.cpp +++ b/Convex_hull_2/test/Convex_hull_2/ch2_point_with_info.cpp @@ -1,14 +1,17 @@ -#include #include + #include #include + #include +#include +#include +#include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef K::Point_2 Point_2; - template struct Forward_bool_functor : public F @@ -128,5 +131,5 @@ int main() assert( result.size() == 3 ); - return 0; + return EXIT_SUCCESS; } diff --git a/Convex_hull_2/test/Convex_hull_2/ch2_projection_3.cpp b/Convex_hull_2/test/Convex_hull_2/ch2_projection_3.cpp index 31fdb40cb25..f9dd6532695 100644 --- a/Convex_hull_2/test/Convex_hull_2/ch2_projection_3.cpp +++ b/Convex_hull_2/test/Convex_hull_2/ch2_projection_3.cpp @@ -1,6 +1,8 @@ #include + #include #include + #include #include @@ -8,18 +10,20 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Projection_traits_xy_3 Traits; typedef Traits::Point_2 Point_2; -int main(){ +int main() +{ std::vector points; std::ifstream input("data/CD500"); double x,y; - while (input >> x >> y){ + while(input >> x >> y) + { points.push_back(Point_2(x,y,3.)); } std::vector ch2; - CGAL::convex_hull_2(points.begin(),points.end(),std::back_inserter(ch2),Traits()); - std::cout << ch2.size() << std::endl; + + return EXIT_SUCCESS; } diff --git a/Convex_hull_2/test/Convex_hull_2/ch_test_CH.cpp b/Convex_hull_2/test/Convex_hull_2/ch_test_CH.cpp index 54d23ac3f68..bb9bccab77c 100644 --- a/Convex_hull_2/test/Convex_hull_2/ch_test_CH.cpp +++ b/Convex_hull_2/test/Convex_hull_2/ch_test_CH.cpp @@ -1,33 +1,9 @@ -// ============================================================================ -// -// Copyright (c) 1999 The CGAL Consortium -// -// -// -// -// -// ---------------------------------------------------------------------------- -// release : -// release_date : -// -// file : ch_test_CH.C -// revision : $Id$ -// revision_date : $Date$ -// author(s) : Stefan Schirra -// -// coordinator : MPI, Saarbruecken -// ============================================================================ +#include #include -#include -#include + #include -#include - -#include -#include - #ifdef CGAL_USE_LEDA #include #include @@ -37,28 +13,23 @@ #include #endif -#include - -int -main() +int main() { #ifdef CGAL_USE_LEDA - CGAL::Convex_hull_constructive_traits_2< CGAL::Homogeneous > - cch_H_integer; - std::cout << "Homogeneous: C "; - CGAL::ch__batch_test( cch_H_integer ); + CGAL::Convex_hull_constructive_traits_2< CGAL::Homogeneous > cch_H_integer; + std::cout << "Homogeneous:" << std::endl; + CGAL::ch__batch_test(cch_H_integer); #endif #ifdef CGAL_USE_GMP - CGAL::Convex_hull_constructive_traits_2< CGAL::Homogeneous > - cch_H_gmp; - std::cout << "Homogeneous: C "; - CGAL::ch__batch_test( cch_H_gmp ); + CGAL::Convex_hull_constructive_traits_2< CGAL::Homogeneous > cch_H_gmp; + std::cout << "Homogeneous:" << std::endl; + CGAL::ch__batch_test(cch_H_gmp); #endif - CGAL::Convex_hull_constructive_traits_2< CGAL::Homogeneous > - cch_H_double; - std::cout << "Homogeneous: C "; - CGAL::ch__batch_test( cch_H_double ); - return 0; + CGAL::Convex_hull_constructive_traits_2< CGAL::Homogeneous > cch_H_double; + std::cout << "Homogeneous:" << std::endl; + CGAL::ch__batch_test(cch_H_double); + + return EXIT_SUCCESS; } diff --git a/Convex_hull_2/test/Convex_hull_2/ch_test_SC.cpp b/Convex_hull_2/test/Convex_hull_2/ch_test_SC.cpp index abb4139ff1c..26a2c4dca9d 100644 --- a/Convex_hull_2/test/Convex_hull_2/ch_test_SC.cpp +++ b/Convex_hull_2/test/Convex_hull_2/ch_test_SC.cpp @@ -1,31 +1,6 @@ -// ============================================================================ -// -// Copyright (c) 1999 The CGAL Consortium -// -// -// -// -// -// ---------------------------------------------------------------------------- -// release : -// release_date : -// -// file : ch_test_SC.C -// revision : $Id$ -// revision_date : $Date$ -// author(s) : Stefan Schirra -// -// coordinator : MPI, Saarbruecken -// ============================================================================ +#include #include -#include -#include - -#include - -#include -#include #ifdef CGAL_USE_LEDA #include @@ -36,25 +11,23 @@ #include #endif -#include - -int -main() +int main() { #ifdef CGAL_USE_LEDA - CGAL::Cartesian ch_C_rational; - std::cout << "Cartesian: "; - CGAL::ch__batch_test( ch_C_rational ); + CGAL::Cartesian ch_C_rational; + std::cout << "Cartesian:" << std::endl; + CGAL::ch__batch_test(ch_C_rational); #endif #ifdef CGAL_USE_GMP - CGAL::Cartesian > ch_C_Qgmp; - std::cout << "Cartesian > >: "; - CGAL::ch__batch_test( ch_C_Qgmp ); + CGAL::Cartesian > ch_C_Qgmp; + std::cout << "Cartesian > >:" << std::endl; + CGAL::ch__batch_test(ch_C_Qgmp); #endif - CGAL::Cartesian ch_C_double; - std::cout << "Cartesian: "; - CGAL::ch__batch_test( ch_C_double ); - return 0; + CGAL::Cartesian ch_C_double; + std::cout << "Cartesian:" << std::endl; + CGAL::ch__batch_test(ch_C_double); + + return EXIT_SUCCESS; } diff --git a/Convex_hull_2/test/Convex_hull_2/ch_test_SH.cpp b/Convex_hull_2/test/Convex_hull_2/ch_test_SH.cpp index c0ddcb07d92..d8318360621 100644 --- a/Convex_hull_2/test/Convex_hull_2/ch_test_SH.cpp +++ b/Convex_hull_2/test/Convex_hull_2/ch_test_SH.cpp @@ -1,31 +1,6 @@ -// ============================================================================ -// -// Copyright (c) 1999 The CGAL Consortium -// -// -// -// -// -// ---------------------------------------------------------------------------- -// release : -// release_date : -// -// file : ch_test_SH.C -// revision : $Id$ -// revision_date : $Date$ -// author(s) : Stefan Schirra -// -// coordinator : MPI, Saarbruecken -// ============================================================================ +#include #include -#include -#include - -#include - -#include -#include #ifdef CGAL_USE_LEDA #include @@ -35,25 +10,24 @@ #ifdef CGAL_USE_GMP #include #endif -#include -int -main() +int main() { #ifdef CGAL_USE_LEDA - CGAL::Homogeneous ch_H_integer; - std::cout << "Homogeneous: "; + CGAL::Homogeneous ch_H_integer; + std::cout << "Homogeneous:" << std::endl; CGAL::ch__batch_test( ch_H_integer ); #endif #ifdef CGAL_USE_GMP - CGAL::Homogeneous ch_H_gmp; - std::cout << "Homogeneous: "; + CGAL::Homogeneous ch_H_gmp; + std::cout << "Homogeneous:" << std::endl; CGAL::ch__batch_test( ch_H_gmp ); #endif - CGAL::Homogeneous ch_H_double; - std::cout << "Homogeneous: "; + CGAL::Homogeneous ch_H_double; + std::cout << "Homogeneous:" << std::endl; CGAL::ch__batch_test( ch_H_double ); - return 0; + + return EXIT_SUCCESS; } diff --git a/Convex_hull_2/test/Convex_hull_2/ch_test_SS.cpp b/Convex_hull_2/test/Convex_hull_2/ch_test_SS.cpp index 3a5b9edf77e..521f1b41b5a 100644 --- a/Convex_hull_2/test/Convex_hull_2/ch_test_SS.cpp +++ b/Convex_hull_2/test/Convex_hull_2/ch_test_SS.cpp @@ -1,32 +1,6 @@ -// ============================================================================ -// -// Copyright (c) 1999 The CGAL Consortium -// -// -// -// -// -// ---------------------------------------------------------------------------- -// release : -// release_date : -// -// file : ch_test_SS.C -// revision : $Id$ -// revision_date : $Date$ -// author(s) : Stefan Schirra -// -// coordinator : MPI, Saarbruecken -// ============================================================================ - +#include #include -#include -#include - -#include - -#include -#include #ifdef CGAL_USE_LEDA #include @@ -36,25 +10,24 @@ #ifdef CGAL_USE_GMP #include #endif -#include -int -main() +int main() { #ifdef CGAL_USE_LEDA - CGAL::Simple_cartesian ch_S_rational; - std::cout << "SimpleCartesian: "; + CGAL::Simple_cartesian ch_S_rational; + std::cout << "SimpleCartesian:" << std::endl; CGAL::ch__batch_test( ch_S_rational ); #endif #ifdef CGAL_USE_GMP - CGAL::Simple_cartesian > ch_S_Qgmp; - std::cout << "SimpleCartesian > >: "; + CGAL::Simple_cartesian > ch_S_Qgmp; + std::cout << "SimpleCartesian > >:" << std::endl; CGAL::ch__batch_test( ch_S_Qgmp ); #endif - CGAL::Simple_cartesian ch_S_double; - std::cout << "SimpleCartesian: "; + CGAL::Simple_cartesian ch_S_double; + std::cout << "SimpleCartesian:" << std::endl; CGAL::ch__batch_test( ch_S_double ); - return 0; + + return EXIT_SUCCESS; } diff --git a/Convex_hull_2/test/Convex_hull_2/include/CGAL/_test_fct_ch_I_2.h b/Convex_hull_2/test/Convex_hull_2/include/CGAL/_test_fct_ch_I_2.h index 1c7a4b24999..9570bcdb409 100644 --- a/Convex_hull_2/test/Convex_hull_2/include/CGAL/_test_fct_ch_I_2.h +++ b/Convex_hull_2/test/Convex_hull_2/include/CGAL/_test_fct_ch_I_2.h @@ -18,21 +18,243 @@ // coordinator : MPI, Saarbruecken // ============================================================================ - #ifndef _TEST_FCT_CH_I_2_H #define _TEST_FCT_CH_I_2_H -#include #include +#include + +#include + namespace CGAL { template -bool -ch__batch_test( const Traits& chI ); +void ch__batch_test_simple(const Traits& chI) +{ + using Point_2 = typename Traits::Point_2; -} //namespace CGAL + std::cout << std::endl << " == Test Simple ==" << std::endl; -#include + std::vector points; + points.push_back(Point_2( -10, 0, 1)); + points.push_back(Point_2( -15, -1, 1)); + points.push_back(Point_2( -7, -10, 1)); + points.push_back(Point_2( -9, -20, 1)); + points.push_back(Point_2( -3, -20, 1)); + points.push_back(Point_2( 74, 0, 1)); + points.push_back(Point_2( 1, 1, 1)); + points.push_back(Point_2( 0, 100, 1)); + + assert(ch__test(points.begin(), points.end(), chI)); +} + +template +void ch__batch_test_cocircular(const Traits& chI) +{ + using Point_2 = typename Traits::Point_2; + + std::cout << std::endl << " == Test Cocircular ==" << std::endl; + + std::vector cocircular_points; + cocircular_points.push_back(Point_2( 39, 80, 89)); + cocircular_points.push_back(Point_2( 180, 299, 349)); + cocircular_points.push_back(Point_2( -3, -4, 5)); + cocircular_points.push_back(Point_2(-651, 260, 701)); + cocircular_points.push_back(Point_2( 180, -19, 181)); + cocircular_points.push_back(Point_2(-153, 104, 185)); + cocircular_points.push_back(Point_2(-247, -96, 265)); + cocircular_points.push_back(Point_2( -32, 255, 257)); + cocircular_points.push_back(Point_2( 45, -28, 53)); + cocircular_points.push_back(Point_2( -12, -35, 37)); + + assert(!ch_brute_force_check_2(cocircular_points.begin(), cocircular_points.end(), + cocircular_points.begin(), cocircular_points.end(), chI)); + assert(ch_brute_force_check_2(cocircular_points.begin(), cocircular_points.begin(), + cocircular_points.begin(), cocircular_points.end(), chI)); + assert(ch__test(cocircular_points.begin(), cocircular_points.end(), chI, ch_ALL, ch_CHECK_CONVEXITY)); + + std::vector extreme_points; + convex_hull_2(cocircular_points.begin(), cocircular_points.end(), + std::back_inserter(extreme_points), chI); + + assert(is_ccw_strongly_convex_2(extreme_points.begin(), extreme_points.begin(), chI)); + assert(is_cw_strongly_convex_2(extreme_points.rend(), extreme_points.rend(), chI)); + assert(is_ccw_strongly_convex_2(extreme_points.begin(), extreme_points.begin() + 1, chI)); + assert(is_cw_strongly_convex_2(extreme_points.begin(), extreme_points.begin() + 1, chI)); + assert(is_ccw_strongly_convex_2(extreme_points.begin(), extreme_points.end(), chI)); + assert(is_cw_strongly_convex_2(extreme_points.rbegin(), extreme_points.rend(), chI)); +} + +template +void ch__batch_test_cocircular_ordered(const Traits& chI) +{ + using Point_2 = typename Traits::Point_2; + + std::cout << std::endl << " == Test Cocircular (ordered) ==" << std::endl; + + std::vector cocircular_points; + cocircular_points.push_back(Point_2( 180, -19, 181)); + cocircular_points.push_back(Point_2( 45, -28, 53)); + cocircular_points.push_back(Point_2( -12, -35, 37)); + cocircular_points.push_back(Point_2( -3, -4, 5)); + cocircular_points.push_back(Point_2(-247, -96, 265)); + cocircular_points.push_back(Point_2(-651, 260, 701)); + cocircular_points.push_back(Point_2(-153, 104, 185)); + cocircular_points.push_back(Point_2( -32, 255, 257)); + cocircular_points.push_back(Point_2( 39, 80, 89)); + cocircular_points.push_back(Point_2( 180, 299, 349)); + + assert(!ch_brute_force_check_2(cocircular_points.begin(), cocircular_points.end(), + cocircular_points.begin(), cocircular_points.end(), chI)); + assert(ch_brute_force_check_2(cocircular_points.begin(), cocircular_points.begin(), + cocircular_points.begin(), cocircular_points.end(), chI)); + assert(ch__test(cocircular_points.begin(), cocircular_points.end(), chI, ch_ALL, ch_CHECK_CONVEXITY)); + + std::vector extreme_points; + convex_hull_2(cocircular_points.begin(), cocircular_points.end(), + std::back_inserter(extreme_points), chI); + + assert(is_ccw_strongly_convex_2(extreme_points.begin(), extreme_points.begin(), chI)); + assert(is_cw_strongly_convex_2(extreme_points.rend(), extreme_points.rend(), chI)); + assert(is_ccw_strongly_convex_2(extreme_points.begin(), extreme_points.begin() + 1, chI)); + assert(is_cw_strongly_convex_2(extreme_points.begin(), extreme_points.begin() + 1, chI)); + assert(is_ccw_strongly_convex_2(extreme_points.begin(), extreme_points.end(), chI)); + assert(is_cw_strongly_convex_2(extreme_points.rbegin(), extreme_points.rend(), chI)); +} + +template +void ch__batch_test_collinear(const Traits& chI) +{ + using Point_2 = typename Traits::Point_2; + + std::cout << std::endl << " == Test Collinear ==" << std::endl; + + std::vector collinear_points; + collinear_points.push_back(Point_2( 16, 20, 1)); + collinear_points.push_back(Point_2( 46, 40, 1)); + collinear_points.push_back(Point_2( 76, 60, 1)); + collinear_points.push_back(Point_2(106, 80, 1)); + collinear_points.push_back(Point_2(-14, 0, 1)); + collinear_points.push_back(Point_2(136, 100, 1)); + + assert(ch__test(collinear_points.begin(), collinear_points.end(), chI)); +} + +template +void ch__batch_test_multiple(const Traits& chI) +{ + using Point_2 = typename Traits::Point_2; + + std::cout << std::endl << " == Test Multiple ==" << std::endl; + + std::vector multiple_points; + multiple_points.push_back(Point_2(17, 80, 1)); + multiple_points.push_back(Point_2(17, 80, 1)); + multiple_points.push_back(Point_2(17, 80, 1)); + multiple_points.push_back(Point_2(17, 80, 1)); + + assert(ch_brute_force_check_2(multiple_points.begin(), multiple_points.end(), + multiple_points.begin(), multiple_points.begin() + 1, chI)); + assert(is_ccw_strongly_convex_2(multiple_points.begin(), multiple_points.begin(), chI)); + + assert(ch__test(multiple_points.begin(), multiple_points.end(), chI)); + assert(ch__test(multiple_points.begin() + 2, multiple_points.begin() + 3, chI)); +} + +template +void ch__batch_test_iso_rectangle(const Traits& chI) +{ + using Point_2 = typename Traits::Point_2; + + std::cout << std::endl << " == Test Iso Rectangle ==" << std::endl; + + std::vector iso_rectangle_points; + iso_rectangle_points.push_back(Point_2( 15, 0, 1)); + iso_rectangle_points.push_back(Point_2( 45, 0, 1)); + iso_rectangle_points.push_back(Point_2( 70, 0, 10)); + iso_rectangle_points.push_back(Point_2( 12, 0, 1)); + iso_rectangle_points.push_back(Point_2( 56, 118, 1)); + iso_rectangle_points.push_back(Point_2( 27, 118, 1)); + iso_rectangle_points.push_back(Point_2( 56, 118, 1)); + iso_rectangle_points.push_back(Point_2(112, 118, 1)); + iso_rectangle_points.push_back(Point_2( 0, 9, 1)); + iso_rectangle_points.push_back(Point_2( 0, 78, 1)); + iso_rectangle_points.push_back(Point_2( 0, 16, 1)); + iso_rectangle_points.push_back(Point_2( 0, 77, 1)); + iso_rectangle_points.push_back(Point_2(150, 56, 1)); + iso_rectangle_points.push_back(Point_2(150, 57, 1)); + iso_rectangle_points.push_back(Point_2(150, 58, 1)); + iso_rectangle_points.push_back(Point_2(150, 58, 1)); + + assert(ch__test(iso_rectangle_points.begin(), iso_rectangle_points.end(), chI)); + assert(ch__test(iso_rectangle_points.begin(), iso_rectangle_points.begin()+3, chI)); + assert(ch__test(iso_rectangle_points.begin()+4, iso_rectangle_points.begin()+7, chI)); + assert(ch__test(iso_rectangle_points.begin()+5, iso_rectangle_points.begin()+5, chI)); +} + +// https://github.com/CGAL/cgal/issues/6723 +template +void ch__batch_test_issue_6723(const Traits& chI) +{ + using Point_2 = typename Traits::Point_2; + + std::cout << std::endl << " == Test issue_6723 ==" << std::endl; + + std::vector points = { Point_2( 4, 2, 1), + Point_2( 0, 0, 1), + Point_2(10, 0, 1), + Point_2( 3, 1, 1), + Point_2( 3,-1, 1), + Point_2( 2, 2, 1), + Point_2( 5, 2, 1), + Point_2( 9, 2, 1), + Point_2( 3, 2, 1) }; + + assert(ch__test(points.begin(), points.end(), chI)); +} + +template +void ch__batch_test_random(const Traits& chI) +{ + using Point_2 = typename Traits::Point_2; + + std::cout << std::endl << " == Test Random ==" << std::endl; + + CGAL::Random rnd; + std::cout << "Random seed = " << rnd.get_seed() << std::endl; + + std::vector points; + + const int h = rnd.get_int(1, 100); + for(int i=0; i<10; ++i) + { + const int x = rnd.get_int(-100, 100); + const int y = rnd.get_int(-100, 100); + points.emplace_back(x, y, h); + } + + assert(ch__test(points.begin(), points.end(), chI)); +} + +template +bool ch__batch_test(const Traits& chI) +{ + std::cout << "Testing Convex Hulls" << std::endl;; + + ch__batch_test_simple(chI); + ch__batch_test_cocircular(chI); + ch__batch_test_cocircular_ordered(chI); // so melkman gets called + ch__batch_test_collinear(chI); + ch__batch_test_multiple(chI); + ch__batch_test_iso_rectangle(chI); + ch__batch_test_issue_6723(chI); + ch__batch_test_random(chI); + + std::cout << "done" << std::endl; + return true; +} + +} // namespace CGAL #endif // _TEST_FCT_CH_I_2_H diff --git a/Convex_hull_2/test/Convex_hull_2/include/CGAL/_test_fct_ch_I_2_impl.h b/Convex_hull_2/test/Convex_hull_2/include/CGAL/_test_fct_ch_I_2_impl.h deleted file mode 100644 index 5c17cea7554..00000000000 --- a/Convex_hull_2/test/Convex_hull_2/include/CGAL/_test_fct_ch_I_2_impl.h +++ /dev/null @@ -1,137 +0,0 @@ -// ============================================================================ -// -// Copyright (c) 1999 The CGAL Consortium -// -// -// -// -// -// ---------------------------------------------------------------------------- -// release : -// release_date : -// -// file : _test_fct_ch_I_2.C -// revision : $Id$ -// revision_date : $Date$ -// author(s) : Stefan Schirra -// -// coordinator : MPI, Saarbruecken -// ============================================================================ - - -#ifndef _TEST_FCT_CH_I_2_IMPL_H -#define _TEST_FCT_CH_I_2_IMPL_H - -#include -#include - -namespace CGAL { - -template -bool -ch__batch_test( const Traits& chI ) -{ - typedef typename Traits::Point_2 Point_2; - - std::cout << "Testing ch"; - std::vector< Point_2 > Cocircular_points; - Cocircular_points.push_back( Point_2( 39, 80, 89 )); - Cocircular_points.push_back( Point_2( 180, 299, 349 )); - Cocircular_points.push_back( Point_2( -3, -4, 5 )); - Cocircular_points.push_back( Point_2( -651, 260, 701 )); - Cocircular_points.push_back( Point_2( 180, -19, 181 )); - Cocircular_points.push_back( Point_2( -153, 104, 185 )); - Cocircular_points.push_back( Point_2( -247, -96, 265 )); - Cocircular_points.push_back( Point_2( -32, 255, 257 )); - Cocircular_points.push_back( Point_2( 45, -28, 53 )); - Cocircular_points.push_back( Point_2( -12, -35, 37 )); - assert( ! ch_brute_force_check_2( \ - Cocircular_points.begin(), Cocircular_points.end(), \ - Cocircular_points.begin(), Cocircular_points.end(), chI )); - assert( ch_brute_force_check_2( \ - Cocircular_points.begin(), Cocircular_points.begin(), \ - Cocircular_points.begin(), Cocircular_points.end(), chI )); - assert( ch__test( Cocircular_points.begin(), \ - Cocircular_points.end(), \ - chI, ch_ALL, ch_CHECK_CONVEXITY )); - std::vector< Point_2 > extreme_points; - convex_hull_2(Cocircular_points.begin(), Cocircular_points.end(), - std::back_inserter(extreme_points), chI ); - assert( is_ccw_strongly_convex_2( extreme_points.begin(), \ - extreme_points.begin(), \ - chI )); - assert( is_cw_strongly_convex_2( extreme_points.rend(), - extreme_points.rend(), \ - chI )); - assert( is_ccw_strongly_convex_2( extreme_points.begin(), \ - extreme_points.begin() + 1, chI )); - assert( is_cw_strongly_convex_2( extreme_points.begin(), \ - extreme_points.begin() + 1, chI )); - assert( is_ccw_strongly_convex_2( extreme_points.begin(), \ - extreme_points.end(), \ - chI )); - assert( is_cw_strongly_convex_2( extreme_points.rbegin(), - extreme_points.rend(), \ - chI )); - - std::cout << '.'; - std::vector< Point_2 > Collinear_points; - Collinear_points.push_back( Point_2( 16, 20, 1 )); - Collinear_points.push_back( Point_2( 46, 40, 1 )); - Collinear_points.push_back( Point_2( 76, 60, 1 )); - Collinear_points.push_back( Point_2( 106, 80, 1 )); - Collinear_points.push_back( Point_2( -14, 0 , 1)); - Collinear_points.push_back( Point_2( 136, 100, 1 )); - assert( ch__test( Collinear_points.begin(), \ - Collinear_points.end(), chI )); - - std::cout << '.'; - std::vector< Point_2 > Multiple_points; - Multiple_points.push_back( Point_2( 17, 80, 1 )); - Multiple_points.push_back( Point_2( 17, 80, 1 )); - Multiple_points.push_back( Point_2( 17, 80, 1 )); - Multiple_points.push_back( Point_2( 17, 80, 1 )); - assert( ch_brute_force_check_2( \ - Multiple_points.begin(), Multiple_points.end(),\ - Multiple_points.begin(), Multiple_points.begin() + 1, chI )); - assert( is_ccw_strongly_convex_2(Multiple_points.begin(), \ - Multiple_points.begin(), chI )); - assert( ch__test( Multiple_points.begin(), \ - Multiple_points.end(), chI )); - assert( ch__test( Multiple_points.begin() + 2, \ - Multiple_points.begin() + 3, chI )); - - std::cout << '.'; - std::vector< Point_2 > Iso_rectangle_points; - Iso_rectangle_points.push_back( Point_2( 15, 0, 1 )); - Iso_rectangle_points.push_back( Point_2( 45, 0, 1 )); - Iso_rectangle_points.push_back( Point_2( 70, 0, 10 )); - Iso_rectangle_points.push_back( Point_2( 12, 0, 1 )); - Iso_rectangle_points.push_back( Point_2( 56, 118, 1 )); - Iso_rectangle_points.push_back( Point_2( 27, 118, 1 )); - Iso_rectangle_points.push_back( Point_2( 56, 118, 1 )); - Iso_rectangle_points.push_back( Point_2( 112, 118, 1)); - Iso_rectangle_points.push_back( Point_2( 0, 9, 1)); - Iso_rectangle_points.push_back( Point_2( 0, 78, 1)); - Iso_rectangle_points.push_back( Point_2( 0, 16, 1)); - Iso_rectangle_points.push_back( Point_2( 0, 77, 1)); - Iso_rectangle_points.push_back( Point_2( 150, 56, 1)); - Iso_rectangle_points.push_back( Point_2( 150, 57, 1)); - Iso_rectangle_points.push_back( Point_2( 150, 58, 1)); - Iso_rectangle_points.push_back( Point_2( 150, 58, 1)); - assert( ch__test( Iso_rectangle_points.begin(), \ - Iso_rectangle_points.end(), chI )); - assert( ch__test( Iso_rectangle_points.begin(), \ - Iso_rectangle_points.begin()+3, chI )); - assert( ch__test( Iso_rectangle_points.begin()+4, \ - Iso_rectangle_points.begin()+7, chI )); - assert( ch__test( Iso_rectangle_points.begin()+5, \ - Iso_rectangle_points.begin()+5, chI )); - - std::cout << "done" << std::endl; - return true; -} - -} //namespace CGAL - -#endif // _TEST_FCT_CH_I_2_IMPL_H diff --git a/Convex_hull_2/test/Convex_hull_2/include/CGAL/ch__test.h b/Convex_hull_2/test/Convex_hull_2/include/CGAL/ch__test.h index c88cd33d911..2f22efd9c27 100644 --- a/Convex_hull_2/test/Convex_hull_2/include/CGAL/ch__test.h +++ b/Convex_hull_2/test/Convex_hull_2/include/CGAL/ch__test.h @@ -29,46 +29,210 @@ #include #include #include +#include +#include + +#include +#include +#include +#include +#include namespace CGAL { -enum ch_Algorithm{ ch_JARVIS, - ch_GRAHAM_ANDREW, - ch_EDDY, - ch_BYKAT, - ch_BYKAT_WITH_THRESHOLD, - ch_LOWER_UPPER, - ch_AKL_TOUSSAINT, - ch_ALL, - ch_DEFAULT }; +enum ch_Algorithm +{ + ch_AKL_TOUSSAINT = 0, + ch_BYKAT, + ch_BYKAT_WITH_THRESHOLD, + ch_EDDY, + ch_JARVIS, + ch_GRAHAM_ANDREW, + ch_LOWER_UPPER, + ch_MELKMAN, + ch_ALL, + ch_DEFAULT +}; -enum ch_Check_status{ ch_CHECK_ALL, - ch_CHECK_CONVEXITY, - ch_CHECK_CONTAINEMENT, - ch_NO_CHECK }; +static std::array algorithm_names = {{ "AKL TOUSSAINT", + "BYKAT", + "BYKAT WITH THRESHOLD", + "EDDY", + "JARVIS", + "GRAHAM ANDREW", + "LOWER UPPER", + "MELKMAN", + "ALL", + "DEFAULT" + }}; + +enum ch_Check_status +{ + ch_CHECK_ALL, + ch_CHECK_CONVEXITY, + ch_CHECK_CONTAINEMENT, + ch_NO_CHECK +}; + +// Also compare the results +template +bool test_all_and_compare(InputIterator first, InputIterator beyond, + const Traits& ch_traits, + ch_Check_status check_level = ch_CHECK_ALL) +{ + using Point_2 = typename Traits::Point_2; + + bool call_melkman = is_simple_2(first, beyond, ch_traits); + + std::cout << "Input:"; + InputIterator first_o = first; + for(; first_o!=beyond;++first_o) + std::cout << " " << first_o->x() << " " << first_o->y() << " 0"; + std::cout << std::endl; + + if(!ch__test(first, beyond, ch_traits, ch_AKL_TOUSSAINT, check_level)) + return false; + if(!ch__test(first, beyond, ch_traits, ch_BYKAT, check_level)) + return false; + if(!ch__test(first, beyond, ch_traits, ch_BYKAT_WITH_THRESHOLD, check_level)) + return false; + if(!ch__test(first, beyond, ch_traits, ch_EDDY, check_level)) + return false; + if(!ch__test(first, beyond, ch_traits, ch_JARVIS, check_level)) + return false; + if(!ch__test(first, beyond, ch_traits, ch_GRAHAM_ANDREW, check_level)) + return false; + if(!ch__test(first, beyond, ch_traits, ch_LOWER_UPPER, check_level)) + return false; + if(call_melkman) + { + if(!ch__test(first, beyond, ch_traits, ch_MELKMAN, check_level)) + return false; + } + + std::set V0; + ch_akl_toussaint(first, beyond, std::inserter(V0, V0.end()), ch_traits); + + { + std::set V0_other; + ch_bykat(first, beyond, std::inserter(V0_other, V0_other.end()), ch_traits); + assert(V0 == V0_other); + } + + { + std::set V0_other; + ch_bykat_with_threshold(first, beyond, std::inserter(V0_other, V0_other.end()), ch_traits); + assert(V0 == V0_other); + } + + { + std::set V0_other; + ch_eddy(first, beyond, std::inserter(V0_other, V0_other.end()), ch_traits); + assert(V0 == V0_other); + } + + { + std::set V0_other; + ch_jarvis(first, beyond, std::inserter(V0_other, V0_other.end()), ch_traits); + assert(V0 == V0_other); + } + + { + std::set V0_other; + ch_graham_andrew(first, beyond, std::inserter(V0_other, V0_other.end()), ch_traits); + assert(V0 == V0_other); + } + + { + std::set V0_other; + lower_hull_points_2(first, beyond, std::inserter(V0_other, V0_other.end()), ch_traits); + upper_hull_points_2(first, beyond, std::inserter(V0_other, V0_other.end()), ch_traits); + assert(V0 == V0_other); + } + + if(call_melkman) + { + std::cout << "Simple polyline, proceed with melkman check" << std::endl; + std::set V0_other; + ch_melkman(first, beyond, std::inserter(V0_other, V0_other.end()), ch_traits); + + assert(V0 == V0_other); + } + else + { + std::cout << "Cannot call melkman on non-simple polyline" << std::endl; + } + + return true; +} template bool -ch__test(InputIterator first, InputIterator last, - const Traits& ch_traits, - ch_Algorithm alg, - ch_Check_status check_level); +ch__test(InputIterator first, InputIterator beyond, + const Traits& ch_traits, + ch_Algorithm alg = ch_ALL, + ch_Check_status check_level = ch_CHECK_ALL) +{ + using Point_2 = typename Traits::Point_2; + std::vector VI(first, beyond); + std::vector VO; -template -bool -ch__test(InputIterator first, InputIterator last, - const Traits& ch_traits, - ch_Algorithm alg); + using V_iter = typename std::vector::iterator; + V_iter VIfirst = VI.begin(); + V_iter VIlast = VI.end(); -template -bool -ch__test(InputIterator first, InputIterator last, - const Traits& ch_traits); + std::cout << "Algorithm: " << algorithm_names[std::size_t(alg)] << std::endl; + switch(alg) + { + case ch_AKL_TOUSSAINT: + ch_akl_toussaint(first, beyond, std::back_inserter(VO), ch_traits); + break; + case ch_BYKAT: + ch_bykat(first, beyond, std::back_inserter(VO), ch_traits); + break; + case ch_BYKAT_WITH_THRESHOLD: + ch_bykat_with_threshold(first, beyond, std::back_inserter(VO), ch_traits); + break; + case ch_EDDY: + ch_eddy(first, beyond, std::back_inserter(VO), ch_traits); + break; + case ch_JARVIS: + ch_jarvis(first, beyond, std::back_inserter(VO), ch_traits); + break; + case ch_GRAHAM_ANDREW: + ch_graham_andrew(first, beyond, std::back_inserter(VO), ch_traits); + break; + case ch_LOWER_UPPER: + lower_hull_points_2(first, beyond, std::back_inserter(VO), ch_traits); + upper_hull_points_2(first, beyond, std::back_inserter(VO), ch_traits); + break; + case ch_MELKMAN: + ch_melkman(first, beyond, std::back_inserter(VO), ch_traits); + break; + case ch_ALL: + return test_all_and_compare(first, beyond, ch_traits, check_level); + case ch_DEFAULT: + default: + convex_hull_2(first, beyond, std::back_inserter(VO), ch_traits); + break; + } + switch(check_level) + { + case ch_CHECK_CONVEXITY: + return is_ccw_strongly_convex_2(VO.begin(), VO.end(), ch_traits); + case ch_CHECK_CONTAINEMENT: + return ch_brute_force_check_2(first, beyond, VO.begin(), VO.end(), ch_traits); + case ch_NO_CHECK: + return true; + case ch_CHECK_ALL: + default: + return is_ccw_strongly_convex_2(VO.begin(), VO.end(), ch_traits) && + ch_brute_force_check_2(first, beyond, VO.begin(), VO.end(), ch_traits); + } +} -} //namespace CGAL - -#include +} // namespace CGAL #endif // CGAL_CH__TEST_H diff --git a/Convex_hull_2/test/Convex_hull_2/include/CGAL/ch__test_impl.h b/Convex_hull_2/test/Convex_hull_2/include/CGAL/ch__test_impl.h deleted file mode 100644 index bfcd439c68a..00000000000 --- a/Convex_hull_2/test/Convex_hull_2/include/CGAL/ch__test_impl.h +++ /dev/null @@ -1,290 +0,0 @@ -// ============================================================================ -// -// Copyright (c) 1999 The CGAL Consortium -// -// -// -// -// -// ---------------------------------------------------------------------------- -// release : -// release_date : -// -// file : ch__test.C -// revision : $Id$ -// revision_date : $Date$ -// author(s) : Stefan Schirra -// -// coordinator : MPI, Saarbruecken -// ============================================================================ - - -#ifndef CGAL_CH__TEST_IMPL_H -#define CGAL_CH__TEST_IMPL_H - -#include - -namespace CGAL { -template -bool -ch__test(InputIterator first, InputIterator last, const Traits& ch_traits) -{ - ch_Algorithm alg = ch_ALL; - ch_Check_status check_level = ch_CHECK_ALL; - typedef typename Traits::Point_2 Point_2; - std::vector< Point_2 > VI (first, last); - std::vector< Point_2 > VO; - typedef typename std::vector< Point_2 >::iterator V_iter; - V_iter VIfirst = VI.begin(); - V_iter VIlast = VI.end(); - switch (alg) - { - case ch_JARVIS: - ch_jarvis(VIfirst, VIlast, std::back_inserter(VO), ch_traits); - break; - case ch_GRAHAM_ANDREW: - ch_graham_andrew(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_EDDY: - ch_eddy(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_AKL_TOUSSAINT: - ch_akl_toussaint( VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_BYKAT: - ch_bykat(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_BYKAT_WITH_THRESHOLD: - ch_bykat_with_threshold(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_LOWER_UPPER: - lower_hull_points_2(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - upper_hull_points_2(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_ALL: - return - ch__test(VIfirst, VIlast, ch_traits, - ch_JARVIS, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_GRAHAM_ANDREW, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_EDDY, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_BYKAT, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_BYKAT_WITH_THRESHOLD, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_LOWER_UPPER, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_AKL_TOUSSAINT, check_level); - case ch_DEFAULT: - default: - convex_hull_2( VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - } - - switch (check_level) - { - case ch_CHECK_CONVEXITY: - return is_ccw_strongly_convex_2( VO.begin(), VO.end(), - ch_traits); - case ch_CHECK_CONTAINEMENT: - return ch_brute_force_check_2( VIfirst, VIlast, - VO.begin(), VO.end(), - ch_traits); - case ch_NO_CHECK: - return true; - case ch_CHECK_ALL: - default: - return is_ccw_strongly_convex_2( VO.begin(), VO.end(), - ch_traits) - && ch_brute_force_check_2( VIfirst, VIlast, - VO.begin(), VO.end(), - ch_traits); - } -} - -template -bool -ch__test(InputIterator first, InputIterator last, const Traits& ch_traits, - ch_Algorithm alg ) -{ - ch_Check_status check_level = ch_CHECK_ALL; - typedef typename Traits::Point_2 Point_2; - std::vector< Point_2 > VI (first, last); - std::vector< Point_2 > VO; - typedef typename std::vector< Point_2 >::iterator V_iter; - V_iter VIfirst = VI.begin(); - V_iter VIlast = VI.end(); - switch (alg) - { - case ch_JARVIS: - ch_jarvis(VIfirst, VIlast, std::back_inserter(VO), ch_traits); - break; - case ch_GRAHAM_ANDREW: - ch_graham_andrew(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_EDDY: - ch_eddy(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_AKL_TOUSSAINT: - ch_akl_toussaint( VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_BYKAT: - ch_bykat(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_BYKAT_WITH_THRESHOLD: - ch_bykat_with_threshold(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_LOWER_UPPER: - lower_hull_points_2(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - upper_hull_points_2(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_ALL: - return - ch__test(VIfirst, VIlast, ch_traits, - ch_JARVIS, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_GRAHAM_ANDREW, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_EDDY, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_BYKAT, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_BYKAT_WITH_THRESHOLD, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_LOWER_UPPER, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_AKL_TOUSSAINT, check_level); - case ch_DEFAULT: - default: - ( VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - } - - switch (check_level) - { - case ch_CHECK_CONVEXITY: - return is_ccw_strongly_convex_2( VO.begin(), VO.end(), - ch_traits); - case ch_CHECK_CONTAINEMENT: - return ch_brute_force_check_2( VIfirst, VIlast, - VO.begin(), VO.end(), - ch_traits); - case ch_NO_CHECK: - return true; - case ch_CHECK_ALL: - default: - return is_ccw_strongly_convex_2( VO.begin(), VO.end(), - ch_traits) - && ch_brute_force_check_2( VIfirst, VIlast, - VO.begin(), VO.end(), - ch_traits); - } -} - -template -bool -ch__test(InputIterator first, InputIterator last, const Traits& ch_traits, - ch_Algorithm alg, ch_Check_status check_level) -{ - typedef typename Traits::Point_2 Point_2; - std::vector< Point_2 > VI (first, last); - std::vector< Point_2 > VO; - typedef typename std::vector< Point_2 >::iterator V_iter; - V_iter VIfirst = VI.begin(); - V_iter VIlast = VI.end(); - switch (alg) - { - case ch_JARVIS: - ch_jarvis(VIfirst, VIlast, std::back_inserter(VO), ch_traits); - break; - case ch_GRAHAM_ANDREW: - ch_graham_andrew(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_EDDY: - ch_eddy(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_AKL_TOUSSAINT: - ch_akl_toussaint( VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_BYKAT: - ch_bykat(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_BYKAT_WITH_THRESHOLD: - ch_bykat_with_threshold(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_LOWER_UPPER: - lower_hull_points_2(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - upper_hull_points_2(VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - case ch_ALL: - return - ch__test(VIfirst, VIlast, ch_traits, - ch_JARVIS, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_GRAHAM_ANDREW, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_EDDY, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_BYKAT, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_BYKAT_WITH_THRESHOLD, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_LOWER_UPPER, check_level) - && ch__test(VIfirst, VIlast, ch_traits, - ch_AKL_TOUSSAINT, check_level); - case ch_DEFAULT: - default: - convex_hull_2( VIfirst, VIlast, std::back_inserter(VO), - ch_traits); - break; - } - - switch (check_level) - { - case ch_CHECK_CONVEXITY: - return is_ccw_strongly_convex_2( VO.begin(), VO.end(), - ch_traits); - case ch_CHECK_CONTAINEMENT: - return ch_brute_force_check_2( VIfirst, VIlast, - VO.begin(), VO.end(), - ch_traits); - case ch_NO_CHECK: - return true; - case ch_CHECK_ALL: - default: - return is_ccw_strongly_convex_2( VO.begin(), VO.end(), - ch_traits) - && ch_brute_force_check_2( VIfirst, VIlast, - VO.begin(), VO.end(), - ch_traits); - } -} - -} //namespace CGAL - -#endif // CGAL_CH__TEST_IMPL_H