From dd8e500654eaab1bb4164b2435bcb93194a748fa Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Sun, 6 May 2018 15:53:12 +0300 Subject: [PATCH 01/18] Added a test case that inserts a bunch of segments and then deletes them before applying a point-location op --- .../data/point_location/segments/ops/test11.txt | 15 +++++++++++++++ .../point_location/segments/xcurves/test11.txt | 8 ++++++++ .../test_point_location_dynamic.segments.cmd | 1 + 3 files changed, 24 insertions(+) create mode 100644 Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/ops/test11.txt create mode 100644 Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/xcurves/test11.txt diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/ops/test11.txt b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/ops/test11.txt new file mode 100644 index 00000000000..494bf6ff4e1 --- /dev/null +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/ops/test11.txt @@ -0,0 +1,15 @@ +i 0 +i 1 +i 2 +i 3 +i 4 +i 5 +i 6 +i 7 +d 7 +d 6 +d 5 +d 4 +d 3 +d 2 +d 1 diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/xcurves/test11.txt b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/xcurves/test11.txt new file mode 100644 index 00000000000..dad879e7557 --- /dev/null +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/xcurves/test11.txt @@ -0,0 +1,8 @@ +0 0 0 1 +1 1 2 2 +2 2 3 3 +3 3 4 4 +4 4 5 5 +5 5 6 6 +6 6 7 7 +7 7 8 8 diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_point_location_dynamic.segments.cmd b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_point_location_dynamic.segments.cmd index 1c22dfed49c..701bf4d2231 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_point_location_dynamic.segments.cmd +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_point_location_dynamic.segments.cmd @@ -1 +1,2 @@ ./data/empty.zero ./data/point_location/segments/xcurves/test10.txt ./data/empty.zero ./data/point_location/segments/ops/test10.txt ./data/point_location/segments/queries/test10.txt +./data/empty.zero ./data/point_location/segments/xcurves/test11.txt ./data/empty.zero ./data/point_location/segments/ops/test11.txt ./data/point_location/segments/queries/test03.txt From 2c3c59921351df57905512c3ad183eb1f158bc44 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Sun, 6 May 2018 15:53:44 +0300 Subject: [PATCH 02/18] Added missing namespace --- .../test/Arrangement_on_surface_2/Point_location_dynamic_test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_dynamic_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_dynamic_test.h index 5735c5884b5..4c851cb0e72 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_dynamic_test.h +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_dynamic_test.h @@ -132,7 +132,7 @@ read_perform_opts(std::istream& is) rc = false; continue; } - if (cmd == 'i') insert(*(this->m_arr), this->m_xcurves[id]); + if (cmd == 'i') CGAL::insert(*(this->m_arr), this->m_xcurves[id]); if (cmd == 'd') { if (!remove(this->m_xcurves[id])) rc = false; From 37ff684b6fcd15b45221020eec7413f4b0396a09 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Sun, 6 May 2018 15:54:46 +0300 Subject: [PATCH 03/18] Uncommented a necessary call to update the container of the curves when rebuilding --- .../CGAL/Arr_point_location/Trapezoidal_decomposition_2.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h index 31838a2a0ed..302c64b08ae 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h @@ -1758,11 +1758,7 @@ public: #endif Halfedge_container container; - -#ifdef CGAL_TD_DEBUG unsigned long rep = Halfedge_filter(container, &dag_root()); -#endif - clear(); //// initialize container to point to curves in Td_map_item Tree From 746d7d333c350906f94f623b8ca9f4b227c7c491 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Wed, 9 May 2018 17:45:01 +0300 Subject: [PATCH 04/18] Fixed typo --- .../data/point_location/segments/xcurves/test11.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/xcurves/test11.txt b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/xcurves/test11.txt index dad879e7557..c3c7ebf7d38 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/xcurves/test11.txt +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/xcurves/test11.txt @@ -1,4 +1,4 @@ -0 0 0 1 +0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 From bd946f51d05b752328a0ee3f3e4ae59d039c10da Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Thu, 10 May 2018 07:39:34 +0300 Subject: [PATCH 05/18] Added c++11 support --- .../Arrangement_on_surface_2/CMakeLists.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/CMakeLists.txt b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/CMakeLists.txt index 14fc5649284..2ffece8e931 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/CMakeLists.txt +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/CMakeLists.txt @@ -6,7 +6,17 @@ project( Arrangement_on_surface_2_Tests ) enable_testing() -cmake_minimum_required(VERSION 2.8.10) +cmake_minimum_required(VERSION 3.1) + +list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_generalized_initializers has_cpp11) +if (has_cpp11 LESS 0) + message(STATUS "NOTICE: These examples requires a C++11 compiler and will not be compiled.") + return() +endif() + +# Use C++11 for this directory and its sub-directories. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) find_package(CGAL QUIET COMPONENTS Core) @@ -33,8 +43,7 @@ if ( CGAL_FOUND ) endif() else() - - message(STATUS "This program requires the CGAL library, and will not be compiled.") - -endif() + message(STATUS "This program requires the CGAL library, and will not be compiled.") + +endif() From 24e71bdb4d0edec162a109f2e743149a548440cf Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Thu, 10 May 2018 07:39:53 +0300 Subject: [PATCH 06/18] Cleaned up and improved --- .../Point_location_test.h | 725 +++++++++--------- 1 file changed, 379 insertions(+), 346 deletions(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h index 23926c2926d..8f231fdbea4 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h @@ -1,6 +1,8 @@ #ifndef CGAL_POINT_LOCATION_TEST_H #define CGAL_POINT_LOCATION_TEST_H +#include + #include #include #include @@ -22,11 +24,11 @@ #include "IO_test.h" /*! Point location test */ -template -class Point_location_test : public IO_test { +template +class Point_location_test : public IO_test { public: - typedef Geom_traits_T Geom_traits; - typedef Topol_traits_T Topol_traits; + typedef GeomTraits Geom_traits; + typedef TopolTraits Topol_traits; typedef IO_test Base; typedef typename Base::Point_2 Point_2; @@ -64,43 +66,44 @@ public: protected: typedef typename CGAL::Arr_naive_point_location - Naive_point_location; + Naive_pl; typedef typename CGAL::Arr_simple_point_location - Simple_point_location; + Simple_pl; typedef typename CGAL::Arr_walk_along_line_point_location - Walk_point_location; + Walk_pl; typedef typename CGAL::Arr_landmarks_point_location - Lm_point_location; + Lm_pl; typedef typename CGAL::Arr_random_landmarks_generator Random_lm_generator; typedef typename CGAL::Arr_landmarks_point_location - Lm_random_point_location; + Lm_random_pl; typedef typename CGAL::Arr_grid_landmarks_generator Grid_lm_generator; typedef typename CGAL::Arr_landmarks_point_location - Lm_grid_point_location; + Lm_grid_pl; typedef typename CGAL::Arr_halton_landmarks_generator Halton_lm_generator; typedef typename CGAL::Arr_landmarks_point_location - Lm_halton_point_location; + Lm_halton_pl; typedef typename CGAL::Arr_middle_edges_landmarks_generator Middle_edges_generator; typedef typename CGAL::Arr_landmarks_point_location - Lm_middle_edges_point_location; + Lm_middle_edges_pl; typedef typename CGAL::Arr_landmarks_specified_points_generator Specified_points_generator; typedef typename CGAL::Arr_landmarks_point_location - Lm_specified_points_point_location; - typedef typename CGAL::Arr_trapezoid_ric_point_location - Trapezoid_ric_point_location; + Lm_specified_points_pl; typedef CGAL::Arr_triangulation_point_location - Triangulation_point_location; + Triangulation_pl; + + typedef typename CGAL::Arr_trapezoid_ric_point_location + Trapezoid_ric_pl; // ===> Add new point location type here <=== @@ -117,33 +120,78 @@ protected: /*! The query points */ Points_vector m_query_points; - Naive_point_location* m_naive_pl; // 0 - Simple_point_location* m_simple_pl; // 1 - Walk_point_location* m_walk_pl; // 2 - Lm_point_location* m_lm_pl; // 3 - Lm_random_point_location* m_random_lm_pl; // 4 - Lm_grid_point_location* m_grid_lm_pl; // 5 - Lm_halton_point_location* m_halton_lm_pl; // 6 - Lm_middle_edges_point_location* m_middle_edges_lm_pl; // 7 - Lm_specified_points_point_location* m_specified_points_lm_pl; // 8 - Triangulation_point_location* m_triangulation_pl; // 9 - Trapezoid_ric_point_location* m_trapezoid_ric_pl; // 10 - Trapezoid_ric_point_location* m_trapezoid_ric_no_grnt_pl; // 11 + enum Pl_strategy { + NAIVE_PL = 0, + SIMPLE_PL, + WALK_PL, + LM_PL, + LM_RANDOM_PL, + LM_GRID_PL, + LM_HALTON_PL, + LM_MIDDLE_EDGES_PL, + LM_SPECIFIED_POINTS_PL, + TRIANGULATION_PL, + TRAPEZOID_RIC_PL, + TRAPEZOID_RIC_NO_GUARANTEE_PL, + NUM_PL_STRATEGIES + }; +#define NAIVE_PL_ACTIVE 1 +#define SIMPLE_PL_ACTIVE 1 +#define WALK_PL_ACTIVE 1 +#define LM_PL_ACTIVE 1 +#define LM_RANDOM_PL_ACTIVE 1 +#define LM_GRID_PL_ACTIVE 1 +#define LM_HALTON_PL_ACTIVE 1 +#define LM_MIDDLE_EDGES_PL_ACTIVE 1 +#define LM_SPECIFIED_POINTS_PL_ACTIVE 1 +#define TRIANGULATION_PL_ACTIVE 1 +#define TRAPEZOID_RIC_PL_ACTIVE 1 +#define TRAPEZOID_RIC_NO_GUARANTEE_PL_ACTIVE 1 +#define NUM_PL_STRATEGIE_ACTIVE 1 + + struct Locator { + typedef boost::variant Pl_variant; + Pl_variant m_variant; + + //! The name of the locator. + std::string m_name; + + bool m_active; + }; + + std::array m_locators; + + // Landmark point-location generators Random_lm_generator* m_random_g; Grid_lm_generator* m_grid_g; Halton_lm_generator* m_halton_g; Middle_edges_generator* m_middle_edges_g; Specified_points_generator* m_specified_points_g; - // // ===> Change the number of point-location startegies - // // when a new point location is added. <=== - #define MAX_NUM_POINT_LOCATION_STRATEGIES 12 - - int verify(Objects_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], + /*! Verify the results (old version). + */ + int verify(Objects_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num); - int verify(Variants_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], + /*! Verify the results (new version). + */ + int verify(Variants_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num); public: @@ -161,13 +209,13 @@ public: void set_filenames(const char* points_filename, const char* xcurves_filename, const char* curves_filename, const char* queries_filename); - /*! Initialize the data structures */ + //! Initialize the data structures. virtual bool init(); - /*! Perform the test */ + //! Perform the test. virtual bool perform(); - /*! Clear the data structures */ + //! Clear the data structures. virtual void clear(); bool allocate_arrangement(); @@ -191,51 +239,146 @@ public: void query(Point_location& pl, const char* type, InputIterator begin, InputIterator end, OutputIterator oi) { - typedef InputIterator Input_iterator; - CGAL::Timer timer; timer.reset(); timer.start(); - Input_iterator piter; - for (piter = begin; piter != end; ++piter) { - Point_2 q = (*piter); - *oi++ = pl.locate(q); - } + for (auto piter = begin; piter != end; ++piter) *oi++ = pl.locate(*piter); timer.stop(); std::cout << type << " location took " << timer.time() << std::endl; } + +private: + //! Initialize point location. + template + void init_pl(const std::string& name) + { + m_locators[id].m_variant = static_cast(nullptr); + m_locators[id].m_name = name; + m_locators[id].m_active = true; + } + + //! Allocate point location. + template + bool allocate_pl() + { + auto* locator = new Strategy(); + if (! locator) return false; + m_locators[id].m_variant = locator; + return true; + } + + //! Construct point location. + template + bool construct_pl() + { + auto* locator = new Strategy(*m_arr); + if (! locator) return false; + m_locators[id].m_variant = locator; + return true; + } + + //! Construct landmark point-location with a generator. + template + bool construct_pl(Generator* generator) + { + auto* locator = new Strategy(*m_arr, generator); + if (! locator) return false; + m_locators[id].m_variant = locator; + return true; + } + + //! Delete point location. + template + void deallocate_pl() + { + auto* strategy = boost::get(m_locators[id].m_variant); + if (strategy) { + delete strategy; + m_locators[id].m_variant = static_cast(nullptr); + } + } + + //! Attach point location. + template + void attach_pl() + { + if (! m_locators[id].m_active) return; + auto* strategy = boost::get(m_locators[id].m_variant); + strategy->attach(*m_arr); + } + + //! Attach landmark point location with a generator. + template + void attach_pl(Generator* generator) + { + if (! m_locators[id].m_active) return; + auto* strategy = boost::get(m_locators[id].m_variant); + strategy->attach(*m_arr, generator); + } + + //! Query using point location. + template + void query_pl(T& objs) + { + if (! m_locators[id].m_active) return; + const auto& name = m_locators[id].m_name; + auto* strategy = boost::get(m_locators[id].m_variant); + query(*strategy, name.c_str(), m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs)); + } + + //! Measure the time consumption of an operation + template + void measure(Timer& timer, UnaryOperation op) + { + if (! m_locators[id].m_active) return; + const auto& name = m_locators[id].m_name; + timer.reset(); + timer.start(); + op(); + timer.stop(); + std::cout << name.c_str() << " took " << timer.time() << std::endl; + } }; -/*! - * Constructor. - */ -template -Point_location_test:: +//! Constructor. +template +Point_location_test:: Point_location_test(const Geom_traits& geom_traits) : Base(geom_traits), m_geom_traits(geom_traits), - m_arr(NULL), - m_naive_pl(NULL), - m_simple_pl(NULL), - m_walk_pl(NULL), - m_lm_pl(NULL), - m_random_lm_pl(NULL), - m_grid_lm_pl(NULL), - m_halton_lm_pl(NULL), - m_middle_edges_lm_pl(NULL), - m_specified_points_lm_pl(NULL), - m_triangulation_pl(NULL), - m_trapezoid_ric_pl(NULL), - m_trapezoid_ric_no_grnt_pl(NULL), - m_random_g(NULL), - m_grid_g(NULL), - m_halton_g(NULL), - m_middle_edges_g(NULL), - m_specified_points_g(NULL) -{} + m_arr(nullptr), + m_random_g(nullptr), + m_grid_g(nullptr), + m_halton_g(nullptr), + m_middle_edges_g(nullptr), + m_specified_points_g(nullptr) +{ + init_pl("Naive"); + init_pl("Simple"); + init_pl("Walk"); -/*! Set the file names */ -template -void Point_location_test:: +#if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ + (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) + + init_pl("Landmarks (vertices)"); + init_pl("Landmarks random"); + init_pl("Landmarks grid"); + init_pl("Landmarks Halton"); + init_pl("Landmarks middle edges"); + init_pl("Landmarks specified points"); +#endif + +#if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) + init_pl("Triangulation"); +#endif + + init_pl("Trapezoidal RIC"); + init_pl("Trapezoidal RIC without guarantees"); +} + +//! Set the file names. +template +void Point_location_test:: set_filenames(const char* points_filename, const char* xcurves_filename, const char* curves_filename, @@ -245,9 +388,9 @@ set_filenames(const char* points_filename, m_filename_queries.assign(queries_filename); } -/*! Initialize the data structures */ -template -bool Point_location_test::init() +//! Initialize the data structures. +template +bool Point_location_test::init() { if (!Base::init()) return false; @@ -258,119 +401,83 @@ bool Point_location_test::init() return true; } -/*! Clear the data structures */ -template -void Point_location_test::clear() +//! Clear the data structures. +template +void Point_location_test::clear() { Base::clear(); m_query_points.clear(); m_filename_queries.clear(); } -/*! Clear the data structures */ -template -void Point_location_test:: -deallocate_pl_strategies() +//! Clear the data structures. +template +void Point_location_test::deallocate_pl_strategies() { - if (m_naive_pl) { - delete m_naive_pl; - m_naive_pl = NULL; - } - if (m_simple_pl) { - delete m_simple_pl; - m_simple_pl = NULL; - } - if (m_walk_pl) { - delete m_walk_pl; - m_walk_pl = NULL; - } + deallocate_pl(); + deallocate_pl(); + deallocate_pl(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - if (m_lm_pl) { - delete m_lm_pl; - m_lm_pl = NULL; - } - if (m_random_lm_pl) { - delete m_random_lm_pl; - m_random_lm_pl = NULL; - } - if (m_grid_lm_pl) { - delete m_grid_lm_pl; - m_grid_lm_pl = NULL; - } - if (m_halton_lm_pl) { - delete m_halton_lm_pl; - m_halton_lm_pl = NULL; - } - if (m_middle_edges_lm_pl) { - delete m_middle_edges_lm_pl; - m_middle_edges_lm_pl = NULL; - } - if (m_specified_points_lm_pl) { - delete m_specified_points_lm_pl; - m_specified_points_lm_pl = NULL; - } + + deallocate_pl(); + deallocate_pl(); + deallocate_pl(); + deallocate_pl(); + deallocate_pl(); + deallocate_pl(); // Free Generators if (m_random_g) { delete m_random_g; - m_random_g = NULL; + m_random_g = nullptr; } if (m_grid_g) { delete m_grid_g; - m_grid_g = NULL; + m_grid_g = nullptr; } if (m_halton_g) { delete m_halton_g; - m_halton_g = NULL; + m_halton_g = nullptr; } if (m_middle_edges_g) { delete m_middle_edges_g; - m_middle_edges_g = NULL; + m_middle_edges_g = nullptr; } if (m_specified_points_g) { delete m_specified_points_g; - m_specified_points_g = NULL; + m_specified_points_g = nullptr; } #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - if (m_triangulation_pl) { - delete m_triangulation_pl; - m_triangulation_pl = NULL; - } + deallocate_pl(); #endif - if (m_trapezoid_ric_pl) { - delete m_trapezoid_ric_pl; - m_trapezoid_ric_pl = NULL; - } - if (m_trapezoid_ric_no_grnt_pl) { - delete m_trapezoid_ric_no_grnt_pl; - m_trapezoid_ric_no_grnt_pl = NULL; - } + deallocate_pl(); + deallocate_pl(); } -template -bool Point_location_test::allocate_arrangement() +template +bool Point_location_test::allocate_arrangement() { if (!(m_arr = new Arrangement(&m_geom_traits))) return false; return true; } -template -void Point_location_test:: +template +void Point_location_test:: deallocate_arrangement() { if (m_arr) { delete m_arr; - m_arr = NULL; + m_arr = nullptr; } } -template -bool Point_location_test:: +template +bool Point_location_test:: construct_arrangement() { // Insert all into the arrangement @@ -386,213 +493,181 @@ construct_arrangement() return true; } -template -void Point_location_test::clear_arrangement() +template +void Point_location_test::clear_arrangement() { if (m_arr) m_arr->clear(); } -template -bool Point_location_test:: -allocate_pl_strategies() +template +bool Point_location_test::allocate_pl_strategies() { // Allocate all point location strategies. - if (!(m_naive_pl = new Naive_point_location())) return false; - if (!(m_simple_pl = new Simple_point_location())) return false; - if (!(m_walk_pl = new Walk_point_location())) return false; + if (! allocate_pl()) return false; + if (! allocate_pl()) return false; + if (! allocate_pl()) return false; #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - if (!(m_lm_pl = new Lm_point_location())) return false; - if (!(m_random_lm_pl = new Lm_random_point_location())) return false; - if (!(m_grid_lm_pl = new Lm_grid_point_location())) return false; - if (!(m_halton_lm_pl = new Lm_halton_point_location())) return false; - if (!(m_middle_edges_lm_pl = new Lm_middle_edges_point_location())) - return false; - if (!(m_specified_points_lm_pl = new Lm_specified_points_point_location())) + if (! allocate_pl()) return false; + if (! allocate_pl()) return false; + if (! allocate_pl()) return false; + if (! allocate_pl()) return false; + if (! allocate_pl()) return false; + if (! allocate_pl()) return false; + #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - if (!(m_triangulation_pl = new Triangulation_point_location())) return false; + if (! allocate_pl()) return false; #endif - if (!(m_trapezoid_ric_pl = new Trapezoid_ric_point_location())) return false; - if (!(m_trapezoid_ric_no_grnt_pl = new Trapezoid_ric_point_location())) + if (! allocate_pl()) return false; + if (! allocate_pl()) return false; - // ===> Add new point location instance here. <=== return true; } -template -bool Point_location_test:: -construct_pl_strategies() +template +bool Point_location_test::construct_pl_strategies() { // Initialize all point location strategies. CGAL::Timer timer; - m_naive_pl = new Naive_point_location(*m_arr); // 0 - m_simple_pl = new Simple_point_location(*m_arr); // 1 - m_walk_pl = new Walk_point_location(*m_arr); // 2 + construct_pl(); + construct_pl(); + construct_pl(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - timer.reset(); timer.start(); - m_lm_pl = new Lm_point_location(*m_arr); // 3 - timer.stop(); - std::cout << "Lm (vert) construction took " << timer.time() << std::endl; + measure(timer, [&](){ construct_pl(); }); + // auto op = std::bind(&Point_location_test::construct_pl, this); + // measure(timer, op); - timer.reset(); timer.start(); - m_random_g = new Random_lm_generator(*m_arr); - m_random_lm_pl = new Lm_random_point_location(*m_arr, m_random_g); // 4 - timer.stop(); - std::cout << "Random lm construction took " << timer.time() << std::endl; + measure(timer, [&](){ + m_random_g = new Random_lm_generator(*m_arr); + construct_pl(m_random_g); + }); - timer.reset(); timer.start(); - m_grid_g = new Grid_lm_generator(*m_arr); - m_grid_lm_pl = new Lm_grid_point_location(*m_arr, m_grid_g); // 5 - timer.stop(); - std::cout << "Grid lm construction took " << timer.time() << std::endl; + measure(timer, [&](){ + m_grid_g = new Grid_lm_generator(*m_arr); + construct_pl(m_grid_g); + }); - timer.reset(); timer.start(); - m_halton_g = new Halton_lm_generator(*m_arr); - m_halton_lm_pl = new Lm_halton_point_location(*m_arr, m_halton_g); // 6 - timer.stop(); - std::cout << "Halton lm construction took " << timer.time() << std::endl; + measure(timer, [&](){ + m_halton_g = new Halton_lm_generator(*m_arr); + construct_pl(m_halton_g); + }); - timer.reset(); timer.start(); - m_middle_edges_g = new Middle_edges_generator(*m_arr); - m_middle_edges_lm_pl = - new Lm_middle_edges_point_location(*m_arr, m_middle_edges_g); // 7 - timer.stop(); - std::cout << "Middle edges lm construction took " << timer.time() - << std::endl; + measure(timer, [&](){ + m_middle_edges_g = new Middle_edges_generator(*m_arr); + construct_pl(m_middle_edges_g); + }); + + measure(timer, [&](){ + m_specified_points_g = new Specified_points_generator(*m_arr); + construct_pl + (m_specified_points_g); + }); - timer.reset(); timer.start(); - m_specified_points_g = new Specified_points_generator(*m_arr); - m_specified_points_lm_pl = - new Lm_specified_points_point_location(*m_arr, m_specified_points_g); // 8 - timer.stop(); - std::cout << "Specified_points lm construction took " - << timer.time() << std::endl; #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - timer.reset(); timer.start(); - m_triangulation_pl = new Triangulation_point_location(*m_arr); // 9 - timer.stop(); - std::cout << "Triangulation lm construction took " - << timer.time() << std::endl; + measure(timer, [&](){ + construct_pl(); + }); #endif - timer.reset(); timer.start(); - m_trapezoid_ric_pl = new Trapezoid_ric_point_location(*m_arr); // 10 - timer.stop(); - std::cout << "Trapezoid RIC construction took " << timer.time() << std::endl; + measure(timer, [&](){ + construct_pl(); + }); - timer.reset(); timer.start(); - m_trapezoid_ric_no_grnt_pl = - new Trapezoid_ric_point_location(*m_arr, false); // 11 - timer.stop(); - std::cout << "Trapezoid RIC without-guarantees construction took " - << timer.time() << std::endl; + measure(timer, [&](){ + construct_pl(); + }); std::cout << std::endl; - // ===> Add new point location instance here. <=== return true; } -template -bool Point_location_test::attach_pl_strategies() +template +bool Point_location_test::attach_pl_strategies() { // Initialize all point location strategies. CGAL::Timer timer; - m_naive_pl->attach(*m_arr); - m_simple_pl->attach(*m_arr); - m_walk_pl->attach(*m_arr); + attach_pl(); + attach_pl(); + attach_pl(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - timer.reset(); timer.start(); - m_lm_pl->attach(*m_arr); - timer.stop(); - std::cout << "Lm (vert) construction took " << timer.time() << std::endl; + measure(timer, [&](){ attach_pl(); }); - timer.reset(); timer.start(); - m_random_g = new Random_lm_generator(*m_arr); - m_random_lm_pl->attach(*m_arr, m_random_g); - timer.stop(); - std::cout << "Random lm construction took " << timer.time() << std::endl; + measure(timer, [&](){ + m_random_g = new Random_lm_generator(*m_arr); + attach_pl(m_random_g); + }); - timer.reset(); timer.start(); - m_grid_g = new Grid_lm_generator(*m_arr); - m_grid_lm_pl->attach(*m_arr, m_grid_g); - timer.stop(); - std::cout << "Grid lm construction took " << timer.time() << std::endl; + measure(timer, [&](){ + m_grid_g = new Grid_lm_generator(*m_arr); + attach_pl(m_grid_g); + }); - timer.reset(); timer.start(); - m_halton_g = new Halton_lm_generator(*m_arr); - m_halton_lm_pl->attach(*m_arr, m_halton_g); - timer.stop(); - std::cout << "Halton lm construction took " << timer.time() << std::endl; + measure(timer, [&](){ + m_halton_g = new Halton_lm_generator(*m_arr); + attach_pl(m_halton_g); + }); - timer.reset(); timer.start(); - m_middle_edges_g = new Middle_edges_generator(*m_arr); - m_middle_edges_lm_pl->attach(*m_arr, m_middle_edges_g); - timer.stop(); - std::cout << "Middle edges lm construction took " << timer.time() - << std::endl; + measure(timer, [&](){ + m_middle_edges_g = new Middle_edges_generator(*m_arr); + attach_pl(m_middle_edges_g); + }); - timer.reset(); timer.start(); - m_specified_points_g = new Specified_points_generator(*m_arr); - m_specified_points_lm_pl->attach(*m_arr, m_specified_points_g); - timer.stop(); - std::cout << "Specified_points lm construction took " - << timer.time() << std::endl; + measure(timer, [&](){ + m_specified_points_g = new Specified_points_generator(*m_arr); + attach_pl + (m_specified_points_g); + }); #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - timer.reset(); timer.start(); - m_triangulation_pl->attach(*m_arr); - timer.stop(); - std::cout << "Triangulation lm construction took " - << timer.time() << std::endl; + measure(timer, [&](){ + attach_pl(); + }); #endif - timer.reset(); timer.start(); - m_trapezoid_ric_pl->attach(*m_arr); - timer.stop(); - std::cout << "Trapezoid RIC construction took " << timer.time() << std::endl; + measure(timer, [&](){ + attach_pl(); + }); - timer.reset(); timer.start(); - m_trapezoid_ric_no_grnt_pl->with_guarantees(false); - m_trapezoid_ric_no_grnt_pl->attach(*m_arr); - - timer.stop(); - std::cout << "Trapezoid RIC without-guarantees construction took " - << timer.time() << std::endl; + measure(timer, [&](){ + auto& var = m_locators[TRAPEZOID_RIC_NO_GUARANTEE_PL].m_variant; + auto* strategy = boost::get(var); + strategy->with_guarantees(false); + attach_pl(); + }); std::cout << std::endl; - // ===> Add new point location instance here. <=== return true; } // Perform the test -template -bool Point_location_test::perform() +template +bool Point_location_test::perform() { #if ((CGAL_ARR_POINT_LOCATION_VERSION < 2) || \ defined(CGAL_ARR_POINT_LOCATION_CONVERSION)) - Objects_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES]; + Objects_vector objs[NUM_PL_STRATEGIES]; #else - Variants_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES]; + Variants_vector objs[NUM_PL_STRATEGIES]; #endif // Locate the points in the list using all point location strategies. @@ -602,62 +677,31 @@ bool Point_location_test::perform() size_t pl_index = 0; - query(*m_naive_pl, "Naive", m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Naive - - query(*m_simple_pl, "Simple", m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Simple - - query(*m_walk_pl, "Walk", m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Walk + query_pl(objs[pl_index++]); + query_pl(objs[pl_index++]); + query_pl(objs[pl_index++]); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - query(*m_lm_pl, "Landmarks (vertices)", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Landmarks (vertices) + query_pl(objs[pl_index++]); + query_pl(objs[pl_index++]); + query_pl(objs[pl_index++]); + query_pl(objs[pl_index++]); + query_pl(objs[pl_index++]); + query_pl(objs[pl_index++]); - query(*m_random_lm_pl, "Landmarks random", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Landmarks random - - query(*m_grid_lm_pl, "Landmarks grid", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Landmarks grid - - query(*m_halton_lm_pl, "Landmarks Halton", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Landmarks Halton - - query(*m_middle_edges_lm_pl, "Landmarks middle edges", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Landmarks middle edges - - query(*m_specified_points_lm_pl, "Landmarks specified points", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Landmarks specified points #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - query(*m_triangulation_pl, "Triangulation", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Triangulation + query_pl(objs[pl_index++]); #endif - query(*m_trapezoid_ric_pl, "Trapezoidal RIC", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); // Trapezoidal RIC - - // Trapezoidal RIC without guarantees - query(*m_trapezoid_ric_no_grnt_pl, "Trapezoidal RIC without guarantees", - m_query_points.begin(), m_query_points.end(), - std::back_inserter(objs[pl_index++])); + query_pl(objs[pl_index++]); + query_pl(objs[pl_index++]); std::cout << std::endl; - // ===> Add a call to operate the new point location. <=== - // Number of point location strategies used. size_t pls_num = pl_index; std::cout << "Number of strategies is " << pls_num << std::endl; @@ -683,11 +727,10 @@ bool Point_location_test::perform() return (result == 0); } -// Verify the results -template -int Point_location_test:: -verify(Objects_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], - size_t size, size_t pls_num) +//! Verify the results +template +int Point_location_test:: +verify(Objects_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num) { Vertex_const_handle vh_ref, vh_cur; Halfedge_const_handle hh_ref, hh_cur; @@ -799,29 +842,19 @@ verify(Objects_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], } // Verify the results -template -int Point_location_test:: -verify(Variants_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], - size_t size, size_t pls_num) +template +int Point_location_test:: +verify(Variants_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num) { - const Vertex_const_handle* vh_ref; - const Halfedge_const_handle* hh_ref; - const Face_const_handle* fh_ref; - - const Vertex_const_handle* vh_cur; - const Halfedge_const_handle* hh_cur; - const Face_const_handle* fh_cur; - int result = 0; // Assign and check results - size_t qi; //qi is the query point index - for (qi = 0; qi < size; ++qi) { + for (size_t qi = 0; qi < size; ++qi) { // Assign object to a face - fh_ref = boost::get(&(objs[0][qi])); + auto* fh_ref = boost::get(&(objs[0][qi])); if (fh_ref) { for (size_t pl = 1; pl < pls_num; ++pl) { - fh_cur = boost::get(&(objs[pl][qi])); + auto* fh_cur = boost::get(&(objs[pl][qi])); if (fh_cur) { if ((*fh_cur) != (*fh_ref)) { std::cout << "Error: point location number " << pl << std::endl; @@ -835,12 +868,12 @@ verify(Variants_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], std::cout << "Error: point location number " << pl << std::endl; std::cout << "Expected: a face." << std::endl; result += -1; - hh_cur = boost::get(&(objs[pl][qi])); + auto* hh_cur = boost::get(&(objs[pl][qi])); if (hh_cur) { std::cout << "Actual: a halfedge." << std::endl; continue; } - vh_cur = boost::get(&(objs[pl][qi])); + auto* vh_cur = boost::get(&(objs[pl][qi])); if (vh_cur) { std::cout << "Actual: a vertex." << std::endl; continue; @@ -855,10 +888,10 @@ verify(Variants_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], } // Assign object to a halfedge - hh_ref = boost::get(&(objs[0][qi])); + auto* hh_ref = boost::get(&(objs[0][qi])); if (hh_ref) { for (size_t pl = 1; pl < pls_num; ++pl) { - hh_cur = boost::get(&(objs[pl][qi])); + auto* hh_cur = boost::get(&(objs[pl][qi])); if (hh_cur) { if (((*hh_cur) != (*hh_ref)) && ((*hh_cur)->twin() != (*hh_ref))) { std::cout << "Error: point location number " << pl << std::endl; @@ -874,12 +907,12 @@ verify(Variants_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], std::cout << "Expected: a halfedge, " << (*hh_ref)->curve() << std::endl; result += -1; - fh_cur = boost::get(&(objs[pl][qi])); + auto* fh_cur = boost::get(&(objs[pl][qi])); if (fh_cur) { std::cout << "Actual: a face." << std::endl; continue; } - vh_cur = boost::get(&(objs[pl][qi])); + auto* vh_cur = boost::get(&(objs[pl][qi])); if (vh_cur) { std::cout << "Actual: a vertex." << std::endl; continue; @@ -890,10 +923,10 @@ verify(Variants_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], } // Assign object to a vertex - vh_ref = boost::get(&(objs[0][qi])); + auto* vh_ref = boost::get(&(objs[0][qi])); if (vh_ref) { for (size_t pl = 1; pl < pls_num; ++pl) { - vh_cur = boost::get(&(objs[pl][qi])); + auto vh_cur = boost::get(&(objs[pl][qi])); if (vh_cur) { if ((*vh_cur) != (*vh_ref)) { std::cout << "Error: point location number " << pl << std::endl; @@ -908,12 +941,12 @@ verify(Variants_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES], std::cout << "Error: point location number " << pl << std::endl; std::cout << "Expected: a vertex: "<< (*vh_ref)->point() << std::endl; result += -1; - fh_cur = boost::get(&(objs[pl][qi])); + auto fh_cur = boost::get(&(objs[pl][qi])); if (fh_cur) { std::cout << "Actual: a face." << std::endl; continue; } - hh_cur = boost::get(&(objs[pl][qi])); + auto hh_cur = boost::get(&(objs[pl][qi])); if (hh_cur) { std::cout << "Actual: a halfedge." << std::endl; continue; From ee4d2b51321a94b125d7c55109061f6478df9391 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Fri, 11 May 2018 14:12:42 +0300 Subject: [PATCH 07/18] Added code to simplify enabling and disabling point-location strategies. --- .../Point_location_test.h | 559 ++++++++++++------ 1 file changed, 389 insertions(+), 170 deletions(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h index 8f231fdbea4..9a7b539daee 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h @@ -1,6 +1,19 @@ #ifndef CGAL_POINT_LOCATION_TEST_H #define CGAL_POINT_LOCATION_TEST_H +#define NAIVE_PL_ENABLED 1 +#define SIMPLE_PL_ENABLED 1 +#define WALK_PL_ENABLED 1 +#define LM_PL_ENABLED 1 +#define LM_RANDOM_PL_ENABLED 1 +#define LM_GRID_PL_ENABLED 1 +#define LM_HALTON_PL_ENABLED 1 +#define LM_MIDDLE_EDGES_PL_ENABLED 1 +#define LM_SPECIFIED_POINTS_PL_ENABLED 1 +#define TRIANGULATION_PL_ENABLED 1 +#define TRAPEZOID_RIC_PL_ENABLED 1 +#define TRAPEZOID_RIC_NO_GUARANTEE_PL_ENABLED 1 + #include #include @@ -136,20 +149,6 @@ protected: NUM_PL_STRATEGIES }; -#define NAIVE_PL_ACTIVE 1 -#define SIMPLE_PL_ACTIVE 1 -#define WALK_PL_ACTIVE 1 -#define LM_PL_ACTIVE 1 -#define LM_RANDOM_PL_ACTIVE 1 -#define LM_GRID_PL_ACTIVE 1 -#define LM_HALTON_PL_ACTIVE 1 -#define LM_MIDDLE_EDGES_PL_ACTIVE 1 -#define LM_SPECIFIED_POINTS_PL_ACTIVE 1 -#define TRIANGULATION_PL_ACTIVE 1 -#define TRAPEZOID_RIC_PL_ACTIVE 1 -#define TRAPEZOID_RIC_NO_GUARANTEE_PL_ACTIVE 1 -#define NUM_PL_STRATEGIE_ACTIVE 1 - struct Locator { typedef boost::variant("Naive") +#define ALLOCATE_PL_NATIVE() allocate_pl() +#define CONSTRUCT_PL_NATIVE() construct_pl() +#define DEALLOCATE_PL_NATIVE() deallocate_pl() +#define ATTACH_PL_NATIVE() attach_pl() +#define QUERY_PL_NATIVE(obj) query_pl(obj) +#else +#define INIT_PL_NATIVE() +#define ALLOCATE_PL_NATIVE() +#define CONSTRUCT_PL_NATIVE() +#define DEALLOCATE_PL_NATIVE() +#define ATTACH_PL_NATIVE() +#define QUERY_PL_NATIVE(obj) +#endif + +// Simple +#if (SIMPLE_PL_ENABLED) +#define INIT_PL_SIMPLE() init_pl("Simple") +#define ALLOCATE_PL_SIMPLE() allocate_pl() +#define CONSTRUCT_PL_SIMPLE() construct_pl() +#define DEALLOCATE_PL_SIMPLE() deallocate_pl() +#define ATTACH_PL_SIMPLE() attach_pl() +#define QUERY_PL_SIMPLE(obj) query_pl(obj) +#else +#define INIT_PL_SIMPLE() +#define ALLOCATE_PL_SIMPLE() +#define CONSTRUCT_PL_SIMPLE() +#define DEALLOCATE_PL_SIMPLE() +#define ATTACH_PL_SIMPLE() +#define QUERY_PL_SIMPLE(obj) +#endif + +// Walk +#if (WALK_PL_ENABLED) +#define INIT_PL_WALK() init_pl("Walk") +#define ALLOCATE_PL_WALK() allocate_pl() +#define CONSTRUCT_PL_WALK() construct_pl() +#define DEALLOCATE_PL_WALK() deallocate_pl() +#define ATTACH_PL_WALK() attach_pl() +#define QUERY_PL_WALK(obj) query_pl(obj) +#else +#define INIT_PL_WALK() +#define ALLOCATE_PL_WALK() +#define CONSTRUCT_PL_WALK() +#define DEALLOCATE_PL_WALK() +#define ATTACH_PL_WALK() +#define QUERY_PL_WALK(obj) +#endif + +// Landmarks (vertices) +#if (LM_PL_ENABLED) +#define INIT_PL_LM() init_pl("Landmarks (vertices)"); +#define ALLOCATE_PL_LM() allocate_pl() +#define CONSTRUCT_PL_LM() construct_pl() +#define DEALLOCATE_PL_LM() deallocate_pl() +#define ATTACH_PL_LM() attach_pl() +#define QUERY_PL_LM(obj) query_pl(obj) +#else +#define INIT_PL_LM() +#define ALLOCATE_PL_LM() +#define CONSTRUCT_PL_LM() +#define DEALLOCATE_PL_LM() +#define ATTACH_PL_LM() +#define QUERY_PL_LM(obj) +#endif + +// Landmarks random +#if (LM_RANDOM_PL_ENABLED) +#define INIT_PL_LM_RANDOM() \ + init_pl("Landmarks random"); +#define ALLOCATE_PL_LM_RANDOM() \ + allocate_pl() + +#define CONSTRUCT_PL_LM_RANDOM() \ + m_random_g = new Random_lm_generator(*m_arr); \ + construct_pl(m_random_g) + +#define DEALLOCATE_PL_LM_RANDOM() \ + if (m_random_g) { \ + delete m_random_g; \ + m_random_g = nullptr; \ + } \ + deallocate_pl() + +#define ATTACH_PL_LM_RANDOM() \ + m_random_g = new Random_lm_generator(*m_arr); \ + attach_pl(m_random_g) + +#define QUERY_PL_LM_RANDOM(obj) query_pl(obj) +#else +#define INIT_PL_LM_RANDOM() +#define ALLOCATE_PL_LM_RANDOM() +#define CONSTRUCT_PL_LM_RANDOM() +#define DEALLOCATE_PL_LM_RANDOM() +#define ATTACH_PL_LM_RANDOM() +#define QUERY_PL_LM_RANDOM(obj) +#endif + +// Landmarks grid +#if (LM_GRID_PL_ENABLED) +#define INIT_PL_LM_GRID() init_pl("Landmarks grid") +#define ALLOCATE_PL_LM_GRID() allocate_pl() + +#define CONSTRUCT_PL_LM_GRID() \ + m_grid_g = new Grid_lm_generator(*m_arr); \ + construct_pl(m_grid_g) + +#define DEALLOCATE_PL_LM_GRID() \ + if (m_grid_g) { \ + delete m_grid_g; \ + m_grid_g = nullptr; \ + } \ + deallocate_pl() + +#define ATTACH_PL_LM_GRID() \ + m_grid_g = new Grid_lm_generator(*m_arr); \ + attach_pl(m_grid_g) + +#define QUERY_PL_LM_GRID(obj) query_pl(obj) +#else +#define INIT_PL_LM_GRID() +#define ALLOCATE_PL_LM_GRID() +#define CONSTRUCT_PL_LM_GRID() +#define DEALLOCATE_PL_LM_GRID() +#define ATTACH_PL_LM_GRID() +#define QUERY_PL_LM_GRID(obj) +#endif + +// Landmarks Halton +#if (LM_HALTON_PL_ENABLED) +#define INIT_PL_LM_HALTON() \ + init_pl("Landmarks Halton") +#define ALLOCATE_PL_LM_HALTON() allocate_pl() + +#define CONSTRUCT_PL_LM_HALTON() \ + m_halton_g = new Halton_lm_generator(*m_arr); \ + construct_pl(m_halton_g) + +#define DEALLOCATE_PL_LM_HALTON() \ + if (m_halton_g) { \ + delete m_halton_g; \ + m_halton_g = nullptr; \ + } \ + deallocate_pl() + +#define ATTACH_PL_LM_HALTON() \ + m_halton_g = new Halton_lm_generator(*m_arr); \ + attach_pl(m_halton_g) + +#define QUERY_PL_LM_HALTON(obj) query_pl(obj) +#else +#define INIT_PL_LM_HALTON() +#define ALLOCATE_PL_LM_HALTON() +#define CONSTRUCT_PL_LM_HALTON() +#define DEALLOCATE_PL_LM_HALTON() +#define ATTACH_PL_LM_HALTON() +#define QUERY_PL_LM_HALTON(obj) +#endif + +// Landmarks middle edges +#if (LM_MIDDLE_EDGES_PL_ENABLED) +#define INIT_PL_LM_MIDDLE_EDGES() \ + init_pl("Landmarks middle edges") +#define ALLOCATE_PL_LM_MIDDLE_EDGES() \ + allocate_pl() + +#define CONSTRUCT_PL_LM_MIDDLE_EDGES() \ + m_middle_edges_g = new Middle_edges_generator(*m_arr); \ + construct_pl(m_middle_edges_g) + +#define DEALLOCATE_PL_LM_MIDDLE_EDGES() \ + if (m_middle_edges_g) { \ + delete m_middle_edges_g; \ + m_middle_edges_g = nullptr; \ + } \ + deallocate_pl() + +#define ATTACH_PL_LM_MIDDLE_EDGES() \ + m_middle_edges_g = new Middle_edges_generator(*m_arr); \ + attach_pl(m_middle_edges_g) + +#define QUERY_PL_LM_MIDDLE_EDGES(obj) \ + query_pl(obj) +#else +#define INIT_PL_LM_MIDDLE_EDGES() +#define ALLOCATE_PL_LM_MIDDLE_EDGES() +#define CONSTRUCT_PL_LM_MIDDLE_EDGES() +#define DEALLOCATE_PL_LM_MIDDLE_EDGES() +#define ATTACH_PL_LM_MIDDLE_EDGES() +#define QUERY_PL_LM_MIDDLE_EDGES(obj) +#endif + +// Landmarks specified points +#if (LM_SPECIFIED_POINTS_PL_ENABLED) +#define INIT_PL_LM_SPECIFIED_POINTS() \ + init_pl("Landmarks specified points"); +#define ALLOCATE_PL_LM_SPECIFIED_POINTS() \ + allocate_pl() + +#define CONSTRUCT_PL_LM_SPECIFIED_POINTS() \ + m_specified_points_g = new Specified_points_generator(*m_arr); \ + construct_pl(m_specified_points_g) + +#define DEALLOCATE_PL_LM_SPECIFIED_POINTS() \ + if (m_specified_points_g) { \ + delete m_specified_points_g; \ + m_specified_points_g = nullptr; \ + } \ + deallocate_pl() + +#define ATTACH_PL_LM_SPECIFIED_POINTS() \ + m_specified_points_g = new Specified_points_generator(*m_arr); \ + attach_pl(m_specified_points_g) + +#define QUERY_PL_LM_SPECIFIED_POINTS(obj) \ + query_pl(obj) +#else +#define INIT_PL_LM_SPECIFIED_POINTS() +#define ALLOCATE_PL_LM_SPECIFIED_POINTS() +#define CONSTRUCT_PL_LM_SPECIFIED_POINTS() +#define DEALLOCATE_PL_LM_SPECIFIED_POINTS() +#define ATTACH_PL_LM_SPECIFIED_POINTS() +#define QUERY_PL_LM_SPECIFIED_POINTS(obj) +#endif + +// Triangulation_pl +#if (TRIANGULATION_PL_ENABLED) +#define INIT_PL_TRIANGULATION_PL() \ + init_pl("Triangulation") +#define ALLOCATE_PL_TRIANGULATION_PL() \ + allocate_pl() +#define CONSTRUCT_PL_TRIANGULATION_PL() \ + construct_pl() +#define DEALLOCATE_PL_TRIANGULATION_PL() \ + deallocate_pl() +#define ATTACH_PL_TRIANGULATION_PL() \ + attach_pl() +#define QUERY_PL_TRIANGULATION_PL(obj) \ + query_pl(obj); +#else +#define INIT_PL_TRIANGULATION_PL() +#define ALLOCATE_PL_TRIANGULATION_PL() +#define CONSTRUCT_PL_TRIANGULATION_PL() +#define DEALLOCATE_PL_TRIANGULATION_PL() +#define ATTACH_PL_TRIANGULATION_PL() +#define QUERY_PL_TRIANGULATION_PL(obj) +#endif + +// Trapezoidal RIC +#if (TRAPEZOID_RIC_PL_ENABLED) +#define INIT_PL_TRAPEZOID_RIC_PL() \ + init_pl("Trapezoidal RIC") +#define ALLOCATE_PL_TRAPEZOID_RIC_PL() \ + allocate_pl() +#define CONSTRUCT_PL_TRAPEZOID_RIC_PL() \ + construct_pl() +#define DEALLOCATE_PL_TRAPEZOID_RIC_PL() \ + deallocate_pl() +#define ATTACH_PL_TRAPEZOID_RIC_PL() \ + attach_pl() +#define QUERY_PL_TRAPEZOID_RIC_PL(obj) \ + query_pl(obj) +#else +#define INIT_PL_TRAPEZOID_RIC_PL() +#define ALLOCATE_PL_TRAPEZOID_RIC_PL() +#define CONSTRUCT_PL_TRAPEZOID_RIC_PL() +#define DEALLOCATE_PL_TRAPEZOID_RIC_PL() +#define ATTACH_PL_TRAPEZOID_RIC_PL() +#define QUERY_PL_TRAPEZOID_RIC_PL(obj) +#endif + +#if (TRAPEZOID_RIC_NO_GUARANTEE_PL_ENABLED) +#define INIT_PL_TRAPEZOID_RIC_NO_GUARANTEE() \ + init_pl("Trapezoidal RIC without guarantees") +#define ALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE() \ + allocate_pl() +#define CONSTRUCT_PL_TRAPEZOID_RIC_NO_GUARANTEE() \ + construct_pl() +#define DEALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE() \ + deallocate_pl() + +#define ATTACH_PL_TRAPEZOID_RIC_NO_GUARANTEE() \ + auto& var = m_locators[TRAPEZOID_RIC_NO_GUARANTEE_PL].m_variant; \ + auto* strategy = boost::get(var); \ + strategy->with_guarantees(false); \ + attach_pl() + +#define QUERY_PL_TRAPEZOID_RIC_NO_GUARANTEE(obj) \ + query_pl(obj) +#else +#define INIT_PL_TRAPEZOID_RIC_NO_GUARANTEE() +#define ALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE() +#define CONSTRUCT_PL_TRAPEZOID_RIC_NO_GUARANTEE() +#define DEALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE() +#define ATTACH_PL_TRAPEZOID_RIC_NO_GUARANTEE() +#define QUERY_PL_TRAPEZOID_RIC_NO_GUARANTEE(obj) +#endif + //! Constructor. template Point_location_test:: @@ -353,36 +652,35 @@ Point_location_test(const Geom_traits& geom_traits) : m_middle_edges_g(nullptr), m_specified_points_g(nullptr) { - init_pl("Naive"); - init_pl("Simple"); - init_pl("Walk"); + INIT_PL_NATIVE(); + INIT_PL_SIMPLE(); + INIT_PL_WALK(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - init_pl("Landmarks (vertices)"); - init_pl("Landmarks random"); - init_pl("Landmarks grid"); - init_pl("Landmarks Halton"); - init_pl("Landmarks middle edges"); - init_pl("Landmarks specified points"); + INIT_PL_LM(); + INIT_PL_LM_RANDOM(); + INIT_PL_LM_GRID(); + INIT_PL_LM_HALTON(); + INIT_PL_LM_MIDDLE_EDGES(); + INIT_PL_LM_SPECIFIED_POINTS(); + #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - init_pl("Triangulation"); + INIT_PL_TRIANGULATION_PL(); #endif - init_pl("Trapezoidal RIC"); - init_pl("Trapezoidal RIC without guarantees"); + INIT_PL_TRAPEZOID_RIC_PL(); + INIT_PL_TRAPEZOID_RIC_NO_GUARANTEE(); } //! Set the file names. template void Point_location_test:: -set_filenames(const char* points_filename, - const char* xcurves_filename, - const char* curves_filename, - const char* queries_filename) +set_filenames(const char* points_filename, const char* xcurves_filename, + const char* curves_filename, const char* queries_filename) { Base::set_filenames(points_filename, xcurves_filename, curves_filename); m_filename_queries.assign(queries_filename); @@ -414,49 +712,28 @@ void Point_location_test::clear() template void Point_location_test::deallocate_pl_strategies() { - deallocate_pl(); - deallocate_pl(); - deallocate_pl(); + ALLOCATE_PL_NATIVE(); + ALLOCATE_PL_SIMPLE(); + ALLOCATE_PL_WALK(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - deallocate_pl(); - deallocate_pl(); - deallocate_pl(); - deallocate_pl(); - deallocate_pl(); - deallocate_pl(); + DEALLOCATE_PL_LM(); + DEALLOCATE_PL_LM_RANDOM(); + DEALLOCATE_PL_LM_GRID(); + DEALLOCATE_PL_LM_HALTON(); + DEALLOCATE_PL_LM_MIDDLE_EDGES(); + DEALLOCATE_PL_LM_SPECIFIED_POINTS(); - // Free Generators - if (m_random_g) { - delete m_random_g; - m_random_g = nullptr; - } - if (m_grid_g) { - delete m_grid_g; - m_grid_g = nullptr; - } - if (m_halton_g) { - delete m_halton_g; - m_halton_g = nullptr; - } - if (m_middle_edges_g) { - delete m_middle_edges_g; - m_middle_edges_g = nullptr; - } - if (m_specified_points_g) { - delete m_specified_points_g; - m_specified_points_g = nullptr; - } #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - deallocate_pl(); + DEALLOCATE_PL_TRIANGULATION_PL(); #endif - deallocate_pl(); - deallocate_pl(); + DEALLOCATE_PL_TRAPEZOID_RIC_PL(); + DEALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE(); } template @@ -495,38 +772,34 @@ construct_arrangement() template void Point_location_test::clear_arrangement() -{ - if (m_arr) m_arr->clear(); -} +{ if (m_arr) m_arr->clear(); } template bool Point_location_test::allocate_pl_strategies() { // Allocate all point location strategies. - if (! allocate_pl()) return false; - if (! allocate_pl()) return false; - if (! allocate_pl()) return false; + if (! ALLOCATE_PL_NATIVE()) return false; + if (! ALLOCATE_PL_SIMPLE()) return false; + if (! ALLOCATE_PL_WALK()) return false; #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - if (! allocate_pl()) return false; - if (! allocate_pl()) return false; - if (! allocate_pl()) return false; - if (! allocate_pl()) return false; - if (! allocate_pl()) return false; - if (! allocate_pl()) - return false; + if (! ALLOCATE_PL_LM()) return false; + if (! ALLOCATE_PL_LM_RANDOM()) return false; + if (! ALLOCATE_PL_LM_GRID()) return false; + if (! ALLOCATE_PL_LM_HALTON()) return false; + if (! ALLOCATE_PL_LM_MIDDLE_EDGES()) return false; + if (! ALLOCATE_PL_LM_SPECIFIED_POINTS()) return false; #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - if (! allocate_pl()) return false; + if (! ALLOCATE_PL_TRIANGULATION_PL()) return false; #endif - if (! allocate_pl()) return false; - if (! allocate_pl()) - return false; + if (! ALLOCATE_PL_TRAPEZOID_RIC_PL()) return false; + if (! ALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE()) return false; return true; } @@ -537,57 +810,31 @@ bool Point_location_test::construct_pl_strategies() // Initialize all point location strategies. CGAL::Timer timer; - construct_pl(); - construct_pl(); - construct_pl(); + CONSTRUCT_PL_NATIVE(); + CONSTRUCT_PL_SIMPLE(); + CONSTRUCT_PL_WALK(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - measure(timer, [&](){ construct_pl(); }); - // auto op = std::bind(&Point_location_test::construct_pl, this); - // measure(timer, op); - - measure(timer, [&](){ - m_random_g = new Random_lm_generator(*m_arr); - construct_pl(m_random_g); - }); - - measure(timer, [&](){ - m_grid_g = new Grid_lm_generator(*m_arr); - construct_pl(m_grid_g); - }); - - measure(timer, [&](){ - m_halton_g = new Halton_lm_generator(*m_arr); - construct_pl(m_halton_g); - }); - - measure(timer, [&](){ - m_middle_edges_g = new Middle_edges_generator(*m_arr); - construct_pl(m_middle_edges_g); - }); - + measure(timer, [&](){ CONSTRUCT_PL_LM(); }); + measure(timer, [&](){ CONSTRUCT_PL_LM_RANDOM(); }); + measure(timer, [&](){ CONSTRUCT_PL_LM_GRID(); }); + measure(timer, [&](){ CONSTRUCT_PL_LM_HALTON(); }); + measure(timer, [&](){ CONSTRUCT_PL_LM_MIDDLE_EDGES(); }); measure(timer, [&](){ - m_specified_points_g = new Specified_points_generator(*m_arr); - construct_pl - (m_specified_points_g); + CONSTRUCT_PL_LM_SPECIFIED_POINTS(); }); #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - measure(timer, [&](){ - construct_pl(); - }); + measure(timer, [&](){ CONSTRUCT_PL_TRIANGULATION_PL(); }); #endif - measure(timer, [&](){ - construct_pl(); - }); - + measure(timer, [&](){ CONSTRUCT_PL_TRAPEZOID_RIC_PL(); }); measure(timer, [&](){ - construct_pl(); + CONSTRUCT_PL_TRAPEZOID_RIC_NO_GUARANTEE(); }); std::cout << std::endl; @@ -601,57 +848,30 @@ bool Point_location_test::attach_pl_strategies() // Initialize all point location strategies. CGAL::Timer timer; - attach_pl(); - attach_pl(); - attach_pl(); + ATTACH_PL_NATIVE(); + ATTACH_PL_SIMPLE(); + ATTACH_PL_WALK(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - measure(timer, [&](){ attach_pl(); }); - - measure(timer, [&](){ - m_random_g = new Random_lm_generator(*m_arr); - attach_pl(m_random_g); - }); - - measure(timer, [&](){ - m_grid_g = new Grid_lm_generator(*m_arr); - attach_pl(m_grid_g); - }); - - measure(timer, [&](){ - m_halton_g = new Halton_lm_generator(*m_arr); - attach_pl(m_halton_g); - }); - - measure(timer, [&](){ - m_middle_edges_g = new Middle_edges_generator(*m_arr); - attach_pl(m_middle_edges_g); - }); - + measure(timer, [&](){ ATTACH_PL_LM(); }); + measure(timer, [&](){ ATTACH_PL_LM_RANDOM(); }); + measure(timer, [&](){ ATTACH_PL_LM_GRID(); }); + measure(timer, [&](){ ATTACH_PL_LM_HALTON(); }); + measure(timer, [&](){ ATTACH_PL_LM_MIDDLE_EDGES(); }); measure(timer, [&](){ - m_specified_points_g = new Specified_points_generator(*m_arr); - attach_pl - (m_specified_points_g); + ATTACH_PL_LM_SPECIFIED_POINTS(); }); #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - measure(timer, [&](){ - attach_pl(); - }); + measure(timer, [&](){ ATTACH_PL_TRIANGULATION_PL(); }); #endif - measure(timer, [&](){ - attach_pl(); - }); - + measure(timer, [&](){ ATTACH_PL_TRAPEZOID_RIC_PL(); }); measure(timer, [&](){ - auto& var = m_locators[TRAPEZOID_RIC_NO_GUARANTEE_PL].m_variant; - auto* strategy = boost::get(var); - strategy->with_guarantees(false); - attach_pl(); + ATTACH_PL_TRAPEZOID_RIC_NO_GUARANTEE(); }); std::cout << std::endl; @@ -677,28 +897,27 @@ bool Point_location_test::perform() size_t pl_index = 0; - query_pl(objs[pl_index++]); - query_pl(objs[pl_index++]); - query_pl(objs[pl_index++]); + QUERY_PL_NATIVE(objs[pl_index++]); + QUERY_PL_SIMPLE(objs[pl_index++]); + QUERY_PL_WALK(objs[pl_index++]); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - query_pl(objs[pl_index++]); - query_pl(objs[pl_index++]); - query_pl(objs[pl_index++]); - query_pl(objs[pl_index++]); - query_pl(objs[pl_index++]); - query_pl(objs[pl_index++]); - + QUERY_PL_LM(objs[pl_index++]); + QUERY_PL_LM_RANDOM(objs[pl_index++]); + QUERY_PL_LM_GRID(objs[pl_index++]); + QUERY_PL_LM_HALTON(objs[pl_index++]); + QUERY_PL_LM_MIDDLE_EDGES(objs[pl_index++]); + QUERY_PL_LM_SPECIFIED_POINTS(objs[pl_index++]); #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - query_pl(objs[pl_index++]); + QUERY_PL_TRIANGULATION_PL(objs[pl_index++]); #endif - query_pl(objs[pl_index++]); - query_pl(objs[pl_index++]); + QUERY_PL_TRAPEZOID_RIC_PL(objs[pl_index++]); + QUERY_PL_TRAPEZOID_RIC_NO_GUARANTEE(objs[pl_index++]); std::cout << std::endl; From 972cede312f55bada2e47a1d4e3467ec85202b45 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Wed, 16 May 2018 08:37:27 +0300 Subject: [PATCH 08/18] Cleaned up, stage 1. --- .../Trapezoidal_decomposition_2_impl.h | 1531 ++++++++--------- 1 file changed, 678 insertions(+), 853 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h index e4bab72e6b3..fd1593b3b49 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h @@ -16,15 +16,15 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0+ // -// Author(s) : Michal Balas -// based on the methods implemented in Trapezoidal_decomposition.h by Oren Nechushtan +// Author(s): Michal Balas +// Efi Fogel +// based on the methods implemented by Oren Nechushtan #ifndef CGAL_TRAPEZOIDAL_DECOMPOSITION_FUNCTIONS_H #define CGAL_TRAPEZOIDAL_DECOMPOSITION_FUNCTIONS_H #include - /*! \file * Member-function definitions for the Trapezoidal_decomposition_2 * class. @@ -45,25 +45,23 @@ namespace CGAL { // Precondition: // The trapezoid is active and contains v in its closure // -template +template typename Trapezoidal_decomposition_2::Dag_node & -Trapezoidal_decomposition_2 -::split_trapezoid_by_vertex(Dag_node& split_node, - Vertex_const_handle v, - Halfedge_const_handle he) +Trapezoidal_decomposition_2:: +split_trapezoid_by_vertex(Dag_node& split_node, + Vertex_const_handle v, + Halfedge_const_handle he) { CGAL_precondition(!split_node.is_null()); if (split_node.is_null()) return split_node; - - Td_map_item curr_item (split_node.get_data()); + Td_map_item curr_item(split_node.get_data()); CGAL_precondition(traits->is_active(curr_item)); Dag_node left_node, right_node; - if (traits->is_td_trapezoid(curr_item)) - { - Td_active_trapezoid& tr (boost::get(curr_item)); + if (traits->is_td_trapezoid(curr_item)) { + Td_active_trapezoid& tr(boost::get(curr_item)); CGAL_warning(traits->is_in_closure(tr, traits->vtx_to_ce(v))); @@ -73,41 +71,40 @@ Trapezoidal_decomposition_2 right_node.set_data(Td_active_trapezoid (v, tr.right(), tr.bottom(), tr.top())); - Td_active_trapezoid& left_tr (boost::get(left_node.get_data())); - Td_active_trapezoid& right_tr (boost::get(right_node.get_data())); + Td_active_trapezoid& + left_tr(boost::get(left_node.get_data())); + Td_active_trapezoid& + right_tr(boost::get(right_node.get_data())); CGAL_warning(traits->is_trapezoids_top_equal(left_tr,right_tr)); CGAL_warning(traits->is_trapezoids_bottom_equal(left_tr,right_tr)); CGAL_warning(left_tr.is_on_left_boundary() == tr.is_on_left_boundary()); CGAL_warning(right_tr.is_on_right_boundary() == tr.is_on_right_boundary()); - left_tr.init_neighbours(tr.lb(),tr.lt(),right_node.get_data(),right_node.get_data()); - right_tr.init_neighbours(left_node.get_data(),left_node.get_data(),tr.rb(),tr.rt()); - if (!traits->is_empty_item(tr.lb())) - { + left_tr.init_neighbours(tr.lb(), tr.lt(), + right_node.get_data(), right_node.get_data()); + right_tr.init_neighbours(left_node.get_data(), left_node.get_data(), + tr.rb(), tr.rt()); + if (!traits->is_empty_item(tr.lb())) { Td_active_trapezoid& lb(boost::get(tr.lb())); lb.set_rb(left_node.get_data()); } - if (!traits->is_empty_item(tr.lt())) - { + if (!traits->is_empty_item(tr.lt())) { Td_active_trapezoid& lt(boost::get(tr.lt())); lt.set_rt(left_node.get_data()); } - if (!traits->is_empty_item(tr.rb())) - { + if (!traits->is_empty_item(tr.rb())) { Td_active_trapezoid& rb(boost::get(tr.rb())); rb.set_lb(right_node.get_data()); } - if (!traits->is_empty_item(tr.rt())) - { + if (!traits->is_empty_item(tr.rt())) { Td_active_trapezoid& rt(boost::get(tr.rt())); rt.set_lt(right_node.get_data()); } - } - else //if the curr_item is an edge - { - Td_active_edge& e (boost::get(curr_item)); + else { + // the curr_item is an edge + Td_active_edge& e(boost::get(curr_item)); CGAL_warning(traits->is_in_closure(e, traits->vtx_to_ce(v))); @@ -115,75 +112,78 @@ Trapezoidal_decomposition_2 right_node.set_data(Td_active_edge(e.halfedge())); - Td_active_edge& left_e (boost::get(left_node.get_data())); - Td_active_edge& right_e (boost::get(right_node.get_data())); + Td_active_edge& left_e(boost::get(left_node.get_data())); + Td_active_edge& right_e(boost::get(right_node.get_data())); //CGAL_warning(left_e.is_on_left_boundary() == e.is_on_left_boundary()); //CGAL_warning(right_e.is_on_right_boundary() == e.is_on_right_boundary()); - left_e.init_neighbours(boost::none);//left_e.init_neighbours(e.lb(),e.lt(),Td_map_item(),right_node.get_data()); - right_e.init_neighbours(e.next());//right_e.init_neighbours(left_node.get_data(),left_node.get_data(),e.rb(),e.rt()); - + left_e.init_neighbours(boost::none); + //left_e.init_neighbours(e.lb(),e.lt(),Td_map_item(),right_node.get_data()); + right_e.init_neighbours(e.next()); + //right_e.init_neighbours(left_node.get_data(),left_node.get_data(),e.rb(),e.rt()); } // left and right are set to the point itself, // bottom and top are set to the ray shooting resulting curves at this // stage. //need to define the boundaries flag before creating the trapezoid - Td_map_item vtx_item (build_vertex_map_item(v, he, &split_node)); - split_node.replace( vtx_item, left_node, right_node); //nodes depth are updated here - update_largest_leaf_depth( (std::max)(left_node.depth(), right_node.depth()) ); + Td_map_item vtx_item(build_vertex_map_item(v, he, &split_node)); + split_node.replace(vtx_item, left_node, right_node); //nodes depth are updated here + update_largest_leaf_depth((std::max)(left_node.depth(), right_node.depth())); m_number_of_dag_nodes += 2; #ifndef CGAL_NO_TRAPEZOIDAL_DECOMPOSITION_2_OPTIMIZATION - if (last_cv == curr_item) - last_cv = vtx_item; - if (prev_cv == curr_item) - prev_cv = vtx_item; + if (last_cv == curr_item) last_cv = vtx_item; + if (prev_cv == curr_item) prev_cv = vtx_item; #endif const Dag_node* left_ptr = &split_node.left_child(); const Dag_node* right_ptr = &split_node.right_child(); - boost::apply_visitor(set_dag_node_visitor((Dag_node*)left_ptr),left_ptr->get_data()); //(*left_ptr)->set_dag_node((Dag_node*)left_ptr); - boost::apply_visitor(set_dag_node_visitor((Dag_node*)right_ptr),right_ptr->get_data()); //(*right_ptr)->set_dag_node((Dag_node*)right_ptr); + boost::apply_visitor(set_dag_node_visitor((Dag_node*)left_ptr), + left_ptr->get_data()); + //(*left_ptr)->set_dag_node((Dag_node*)left_ptr); + boost::apply_visitor(set_dag_node_visitor((Dag_node*)right_ptr), + right_ptr->get_data()); + //(*right_ptr)->set_dag_node((Dag_node*)right_ptr); //print_dag_addresses(*m_dag_root); return split_node; } -template +template typename Trapezoidal_decomposition_2::Td_map_item -Trapezoidal_decomposition_2 -::build_vertex_map_item(Vertex_const_handle v, - Halfedge_const_handle he, - Dag_node* node) +Trapezoidal_decomposition_2:: +build_vertex_map_item(Vertex_const_handle v, + Halfedge_const_handle he, + Dag_node* node) { Curve_end ce(traits->vtx_to_ce(v)); - if ((traits->parameter_space_in_x_2_object()(ce.cv(), ce.ce()) == ARR_INTERIOR) - && (traits->parameter_space_in_y_2_object()(ce.cv(), ce.ce()) == ARR_INTERIOR)) + if ((traits->parameter_space_in_x_2_object()(ce.cv(), ce.ce()) == + ARR_INTERIOR) && + (traits->parameter_space_in_y_2_object()(ce.cv(), ce.ce()) == + ARR_INTERIOR)) { - Td_active_vertex vtx (v, he, node); + Td_active_vertex vtx(v, he, node); return vtx; } - else - { - Td_active_fictitious_vertex vtx (v, he, node); + else { + Td_active_fictitious_vertex vtx(v, he, node); return vtx; } } - //----------------------------------------------------------------------------- // Description: // the opposite operation for spliting the trapezoid with // vertical line through ce // Precondition: // tr_node data is a td vertex and is active -template -void Trapezoidal_decomposition_2 -::undo_split_trapezoid_by_vertex(Dag_node& tr_node, const Curve_end& ce) +template +void Trapezoidal_decomposition_2:: +undo_split_trapezoid_by_vertex(Dag_node& tr_node, const Curve_end& ce) { CGAL_precondition(!tr_node.is_null()); Td_map_item item = tr_node.get_data(); @@ -200,7 +200,8 @@ void Trapezoidal_decomposition_2 search_using_dag(tr_right_node, traits, ce, m_empty_he_handle); //make sure the trapezoids are active before merging them - //CGAL_assertion(traits->is_active(tr_left_node.get_data()) && traits->is_active(tr_right_node.get_data())); + //CGAL_assertion(traits->is_active(tr_left_node.get_data()) && + // traits->is_active(tr_right_node.get_data())); // bool mrg_res = merge_if_possible(tr_left_node.get_data(), tr_right_node.get_data()); @@ -209,49 +210,51 @@ void Trapezoidal_decomposition_2 CGAL_warning(!tr_right_node.is_inner_node()); - deactivate_trapezoid( tr_right_node, &tr_left_node); //tr_right_node->remove(&tr_left_node); - update_largest_leaf_depth( tr_left_node.depth()); //tr_left_node is not an inner node + deactivate_trapezoid( tr_right_node, &tr_left_node); + //tr_right_node->remove(&tr_left_node); + update_largest_leaf_depth( tr_left_node.depth()); + //tr_left_node is not an inner node // mark root as deleted deactivate_vertex(tr_node); //tr_node->remove(); - //no need to update m_number_of_dag_nodes because the number of nodes did not change. + // no need to update m_number_of_dag_nodes because the number of nodes does + // not change. // removed nodes were only marked as removed } - -template -void Trapezoidal_decomposition_2 -::deactivate_trapezoid (Dag_node& trpz_node, Dag_node* active_node) const +template +void Trapezoidal_decomposition_2:: +deactivate_trapezoid(Dag_node& trpz_node, Dag_node* active_node) const { CGAL_precondition(traits->is_active(trpz_node.get_data())); CGAL_precondition(traits->is_td_trapezoid(trpz_node.get_data())); - if ( Td_active_trapezoid* trap = boost::get(&trpz_node.get_data()) ) + if (Td_active_trapezoid* trap = + boost::get(&trpz_node.get_data())) trap->clear_neighbors(); trpz_node.set_data(Td_inactive_trapezoid()); - if (active_node) - trpz_node.set_left_child(*active_node); + if (active_node) trpz_node.set_left_child(*active_node); } -template -void Trapezoidal_decomposition_2 -::deactivate_vertex (Dag_node& vtx_node) const +template +void Trapezoidal_decomposition_2:: +deactivate_vertex(Dag_node& vtx_node) const { CGAL_precondition(traits->is_active(vtx_node.get_data())); CGAL_precondition(traits->is_td_vertex(vtx_node.get_data())); - if (traits->is_fictitious_vertex(vtx_node.get_data())) - { - Td_active_fictitious_vertex& v(boost::get(vtx_node.get_data())); + if (traits->is_fictitious_vertex(vtx_node.get_data())) { + Td_active_fictitious_vertex& + v(boost::get(vtx_node.get_data())); vtx_node.set_data(Td_inactive_fictitious_vertex(v.vertex(), &vtx_node)); } - else - { + else { Td_active_vertex& v(boost::get(vtx_node.get_data())); vtx_node.set_data(Td_inactive_vertex(v.vertex(), &vtx_node)); } } -template -void Trapezoidal_decomposition_2 -::deactivate_edge (boost::shared_ptr& cv, Dag_node& edge_node) const +template +void Trapezoidal_decomposition_2:: +deactivate_edge(boost::shared_ptr& cv, + Dag_node& edge_node) const { CGAL_precondition(traits->is_active(edge_node.get_data())); CGAL_precondition(traits->is_td_edge(edge_node.get_data())); @@ -259,8 +262,6 @@ void Trapezoidal_decomposition_2 edge_node.set_data(Td_inactive_edge(cv, &edge_node)); } - - //----------------------------------------------------------------------------- // Description: // splits the trapezoid that corresponds to the root of the @@ -268,21 +269,20 @@ void Trapezoidal_decomposition_2 // Precondition: // The root trapezoid is active // The root trapezoid is devided by he or is equal to it and is vertical. -template +template typename Trapezoidal_decomposition_2::Dag_node & -Trapezoidal_decomposition_2 -::split_trapezoid_by_halfedge(Dag_node& split_node, - Td_map_item& prev_e, - Td_map_item& prev_bottom_tr, - Td_map_item& prev_top_tr, - Halfedge_const_handle he) +Trapezoidal_decomposition_2:: +split_trapezoid_by_halfedge(Dag_node& split_node, + Td_map_item& prev_e, + Td_map_item& prev_bottom_tr, + Td_map_item& prev_top_tr, + Halfedge_const_handle he) { - CGAL_warning(traits != NULL); CGAL_precondition(traits->is_active(split_node.get_data())); CGAL_precondition(traits->is_td_trapezoid(split_node.get_data())); - Td_map_item curr_item (split_node.get_data()); + Td_map_item curr_item(split_node.get_data()); Td_active_trapezoid& split_tr = boost::get(curr_item); // sets left and right according to td_edge's source and target positions @@ -291,72 +291,67 @@ Trapezoidal_decomposition_2 // type (TD_EDGE) Td_active_edge sep(he, &split_node); - //creates a one-way path for all the td edges //that represent the Halfedge. //rb() is used to retrieve the //next on path information - Dag_node top_node(Td_active_trapezoid - (split_tr.left(), split_tr.right(), he, split_tr.top())); + Dag_node top_node(Td_active_trapezoid(split_tr.left(), split_tr.right(), he, + split_tr.top())); //Td_active_trapezoid::TD_TRAPEZOID, //split_tr.on_boundaries_flag() & // (CGAL_TD_ON_LEFT_BOUNDARY | // CGAL_TD_ON_RIGHT_BOUNDARY | // CGAL_TD_ON_TOP_BOUNDARY ))); - Dag_node bottom_node(Td_active_trapezoid - (split_tr.left(),split_tr.right(), split_tr.bottom(), he)); + Dag_node bottom_node(Td_active_trapezoid(split_tr.left(),split_tr.right(), + split_tr.bottom(), he)); //Td_active_trapezoid::TD_TRAPEZOID, //split_tr.on_boundaries_flag() & // (CGAL_TD_ON_LEFT_BOUNDARY | // CGAL_TD_ON_RIGHT_BOUNDARY | // CGAL_TD_ON_BOTTOM_BOUNDARY ))); - Td_active_trapezoid& bottom = boost::get(bottom_node.get_data()); - Td_active_trapezoid& top = boost::get(top_node.get_data()); + Td_active_trapezoid& bottom = + boost::get(bottom_node.get_data()); + Td_active_trapezoid& top = + boost::get(top_node.get_data()); top.init_neighbours(prev_top_tr, split_tr.lt(), boost::none , split_tr.rt()); - bottom.init_neighbours(split_tr.lb(), prev_bottom_tr, split_tr.rb(), boost::none); + bottom.init_neighbours(split_tr.lb(), prev_bottom_tr, split_tr.rb(), + boost::none); - if (!traits->is_empty_item(prev_bottom_tr)) - { - Td_active_trapezoid& prev_btm (boost::get(prev_bottom_tr)); + if (!traits->is_empty_item(prev_bottom_tr)) { + Td_active_trapezoid& + prev_btm(boost::get(prev_bottom_tr)); prev_btm.set_rt(bottom_node.get_data()); } - if (!traits->is_empty_item(prev_top_tr)) - { - Td_active_trapezoid& prev_top (boost::get(prev_top_tr)); + if (!traits->is_empty_item(prev_top_tr)) { + Td_active_trapezoid& prev_top(boost::get(prev_top_tr)); prev_top.set_rb(top_node.get_data()); } - if (!traits->is_empty_item(split_tr.lb())) - { - Td_active_trapezoid& lb (boost::get(split_tr.lb())); + if (!traits->is_empty_item(split_tr.lb())) { + Td_active_trapezoid& lb(boost::get(split_tr.lb())); lb.set_rb(bottom_node.get_data()); } - if (!traits->is_empty_item(split_tr.lt())) - { - Td_active_trapezoid& lt (boost::get(split_tr.lt())); + if (!traits->is_empty_item(split_tr.lt())) { + Td_active_trapezoid& lt(boost::get(split_tr.lt())); lt.set_rt(top_node.get_data()); } - if (!traits->is_empty_item(split_tr.rb())) - { - Td_active_trapezoid& rb (boost::get(split_tr.rb())); + if (!traits->is_empty_item(split_tr.rb())) { + Td_active_trapezoid& rb(boost::get(split_tr.rb())); rb.set_lb(bottom_node.get_data()); } - if (!traits->is_empty_item(split_tr.rt())) - { - Td_active_trapezoid& rt (boost::get(split_tr.rt())); + if (!traits->is_empty_item(split_tr.rt())) { + Td_active_trapezoid& rt(boost::get(split_tr.rt())); rt.set_lt(top_node.get_data()); } split_node.replace(sep,bottom_node,top_node); //nodes depth are updated here - update_largest_leaf_depth( (std::max)(bottom_node.depth(), top_node.depth()) ); + update_largest_leaf_depth((std::max)(bottom_node.depth(), top_node.depth())); m_number_of_dag_nodes += 2; //two new nodes were added to the DAG #ifndef CGAL_NO_TRAPEZOIDAL_DECOMPOSITION_2_OPTIMIZATION - if (last_cv == curr_item) - last_cv = sep; - if (prev_cv == curr_item) - prev_cv = sep; + if (last_cv == curr_item) last_cv = sep; + if (prev_cv == curr_item) prev_cv = sep; #endif const Dag_node* bottomPtr = &split_node.left_child(); @@ -368,22 +363,20 @@ Trapezoidal_decomposition_2 topPtr->get_data()); // Td_active_edge& new_e = boost::get(split_node.get_data()); - if (!traits->is_empty_item(prev_e)) - { - Td_active_edge& e ( boost::get(prev_e)); + if (!traits->is_empty_item(prev_e)) { + Td_active_edge& e( boost::get(prev_e)); e.set_next(split_node.get_data()); } //update these trapezoids pointers. // will be used for the next trapezoid that should be split // by this Halfedge prev_bottom_tr = bottomPtr->get_data(); //(*bottomPtr).operator->(); - prev_top_tr = topPtr->get_data(); //(*topPtr).operator->(); - prev_e = split_node.get_data(); //tt.operator->(); + prev_top_tr = topPtr->get_data(); //(*topPtr).operator->(); + prev_e = split_node.get_data(); //tt.operator->(); return split_node; } - //----------------------------------------------------------------------------- // Description: // update @@ -395,36 +388,37 @@ Trapezoidal_decomposition_2 // starting from this vertex // this point must be an interior point and not a point on the boundaries, // since a point on the boundaries is related to one curve only -template +template typename Trapezoidal_decomposition_2::Td_map_item & -Trapezoidal_decomposition_2 -::update_vtx_with_new_edge(Halfedge_const_handle he, - const Curve_end& ce, - Td_map_item& vtx_item, - const Locate_type& - CGAL_precondition_code(lt)) +Trapezoidal_decomposition_2:: +update_vtx_with_new_edge(Halfedge_const_handle he, + const Curve_end& ce, + Td_map_item& vtx_item, + const Locate_type& + CGAL_precondition_code(lt)) { CGAL_assertion(traits != NULL); CGAL_precondition(lt == POINT); CGAL_precondition(traits->is_active(vtx_item)); //ee is interior - CGAL_assertion((traits->parameter_space_in_x_2_object()(ce.cv(), ce.ce()) - == ARR_INTERIOR) && - (traits->parameter_space_in_y_2_object()(ce.cv(), ce.ce()) - == ARR_INTERIOR) ); + CGAL_assertion((traits->parameter_space_in_x_2_object()(ce.cv(), ce.ce()) == + ARR_INTERIOR) && + (traits->parameter_space_in_y_2_object()(ce.cv(), ce.ce()) == + ARR_INTERIOR) ); //the underlying point of ce const Point& p = (ce.ce() == ARR_MIN_END) ? - traits->construct_min_vertex_2_object()(ce.cv()) : - traits->construct_max_vertex_2_object()(ce.cv()) ; + traits->construct_min_vertex_2_object()(ce.cv()) : + traits->construct_max_vertex_2_object()(ce.cv()) ; //set cw to hold the halfedge whose source is p, // which is clockwise "smallest" starting from top (12 o'clock) - Halfedge_const_handle cw_he (boost::apply_visitor(cw_he_visitor(), vtx_item)); - if (traits->compare_cw_around_point_2_object() - (he->curve(), is_edge_to_right(he,p), - cw_he->curve(), - is_edge_to_right(cw_he,p), p) == SMALLER) + Halfedge_const_handle cw_he(boost::apply_visitor(cw_he_visitor(), vtx_item)); + if (traits->compare_cw_around_point_2_object()(he->curve(), + is_edge_to_right(he,p), + cw_he->curve(), + is_edge_to_right(cw_he,p), + p) == SMALLER) { boost::apply_visitor(set_cw_he_visitor(he),vtx_item);//v_tr->set_top(he); } @@ -434,39 +428,36 @@ Trapezoidal_decomposition_2 //----------------------------------------------------------------------------- // Description: -template +template typename Trapezoidal_decomposition_2::Td_map_item & -Trapezoidal_decomposition_2 -::insert_curve_at_vtx_using_dag (Halfedge_const_handle he, - Vertex_const_handle v, - Td_map_item& item, - const Locate_type& - CGAL_precondition_code(lt)) +Trapezoidal_decomposition_2:: +insert_curve_at_vtx_using_dag(Halfedge_const_handle he, + Vertex_const_handle v, + Td_map_item& item, + const Locate_type& + CGAL_precondition_code(lt)) { CGAL_precondition(lt==TRAPEZOID || lt==UNBOUNDED_TRAPEZOID); Dag_node* node = boost::apply_visitor(dag_node_visitor(), item); CGAL_assertion(node != NULL); - CGAL_assertion (he != m_empty_he_handle); + CGAL_assertion(he != m_empty_he_handle); //we need to use the halfedge whose source is v. //MICHAL: do we have to? if (he->source() == v) - // if ((ce_pair.second == ARR_MIN_END && he->direction() == ARR_LEFT_TO_RIGHT) || - // (ce_pair.second == ARR_MAX_END && he->direction() == ARR_RIGHT_TO_LEFT) ) - { + // if ((ce_pair.second == ARR_MIN_END && + // he->direction() == ARR_LEFT_TO_RIGHT) || + // (ce_pair.second == ARR_MAX_END && + // he->direction() == ARR_RIGHT_TO_LEFT) ) return *split_trapezoid_by_vertex(*node, v, he); - } - else - { - return *split_trapezoid_by_vertex(*node, v, he->twin()); - } + else return *split_trapezoid_by_vertex(*node, v, he->twin()); } ////----------------------------------------------------------------------------- //// Description: -//template +//template //void Trapezoidal_decomposition_2 //::set_trp_params_after_halfedge_update(Halfedge_const_handle old_he, // Halfedge_const_handle new_he, @@ -488,28 +479,26 @@ Trapezoidal_decomposition_2 //----------------------------------------------------------------------------- // Description: -template -void Trapezoidal_decomposition_2 -::update_vtx_cw_he_after_merge (const X_monotone_curve_2& old_cv, - Halfedge_const_handle new_he, - Td_map_item& vtx_item) +template +void Trapezoidal_decomposition_2:: +update_vtx_cw_he_after_merge(const X_monotone_curve_2& old_cv, + Halfedge_const_handle new_he, + Td_map_item& vtx_item) { CGAL_precondition(traits->is_td_vertex(vtx_item)); CGAL_precondition(traits->is_active(vtx_item)); - Halfedge_const_handle cw_he (boost::apply_visitor(cw_he_visitor(), vtx_item)); + Halfedge_const_handle cw_he(boost::apply_visitor(cw_he_visitor(), vtx_item)); //make sure the cw_he is added in same direction as before // such that v_tr is the source (done inside the set methods) if (traits->equal_2_object()(cw_he->curve(), old_cv)) - { boost::apply_visitor(set_cw_he_visitor(new_he), vtx_item); - } } ////MICHAL: currently not in use since split is implemented as removed and insert two //// in case the split is done differenty - this method would have to be rewritten since it is obsolete -//template +//template //void Trapezoidal_decomposition_2 //::set_trp_params_after_split_halfedge_update(Halfedge_const_handle new_he, // Td_map_item& vtx_item, @@ -544,39 +533,36 @@ void Trapezoidal_decomposition_2 // end==0 or end is on the path of the iterator // postcondition: // end is pointer to the last trapezoid encountered,if any -template -void Trapezoidal_decomposition_2 -::update_map_items_after_merge (In_face_iterator& it, - Halfedge_const_handle old_he, - Halfedge_const_handle new_he, - Vertex_const_handle /* min_v */, - Vertex_const_handle /* max_v */, - Td_map_item& end) +template +void Trapezoidal_decomposition_2:: +update_map_items_after_merge(In_face_iterator& it, + Halfedge_const_handle old_he, + Halfedge_const_handle new_he, + Vertex_const_handle /* min_v */, + Vertex_const_handle /* max_v */, + Td_map_item& end) { Td_map_item last_item = Td_map_item(0); - while (!!it && !(*it == end)) - { + while (!!it && !(*it == end)) { Td_map_item curr_item = *it; CGAL_assertion(traits->is_active(curr_item)); - if (traits->is_td_edge(curr_item)) - { + if (traits->is_td_edge(curr_item)) { Td_active_edge& e(boost::get(curr_item)); if (e.halfedge() == old_he || e.halfedge() == old_he->twin()) e.set_halfedge(new_he); } - else if (traits->is_td_trapezoid(curr_item)) - { + else if (traits->is_td_trapezoid(curr_item)) { Td_active_trapezoid& tr(boost::get(curr_item)); if (tr.bottom() == old_he || tr.bottom() == old_he->twin()) tr.set_bottom(new_he); - if (tr.top() == old_he || tr.top() == old_he->twin()) - tr.set_top(new_he); + if (tr.top() == old_he || tr.top() == old_he->twin()) tr.set_top(new_he); } - else //if is_td_vertex - { - Halfedge_const_handle cw_he (boost::apply_visitor(cw_he_visitor(), curr_item)); + else { + //if is_td_vertex + Halfedge_const_handle cw_he(boost::apply_visitor(cw_he_visitor(), + curr_item)); if (cw_he == old_he || cw_he == old_he->twin()) boost::apply_visitor(set_cw_he_visitor(new_he), curr_item); } @@ -599,65 +585,58 @@ void Trapezoidal_decomposition_2 // output is the closest active trapezoid to ce/p_he // remark: // use this function with care! -template +template typename Trapezoidal_decomposition_2::Locate_type -Trapezoidal_decomposition_2 -::search_using_dag (Dag_node& curr_node, - const Traits* traits, - const Point& p, - Halfedge_const_handle he, - Comparison_result up /*=EQUAL*/) const +Trapezoidal_decomposition_2:: +search_using_dag(Dag_node& curr_node, + const Traits* traits, + const Point& p, + Halfedge_const_handle he, + Comparison_result up /*=EQUAL*/) const { - while(true) - { + while (true) { //curr_node is the current pointer to node in the data structure //curr_item is the curent Td_map_item held in curr_node Td_map_item curr_item(curr_node.get_data()); - if (traits->is_td_vertex(curr_item)) - { // if the curr_item represents a vertex + if (traits->is_td_vertex(curr_item)) { + // the curr_item represents a vertex //bool is_fict_vtx = traits->is_fictitious_vertex(curr_item); //if ((is_fict_vtx && is_end_point_left_low(p, *(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)))) || // (!is_fict_vtx && is_end_point_left_low(p, boost::apply_visitor(point_for_vertex_visitor(), curr_item))) ) - if (is_end_point_left_low(p, curr_node)) - { + if (is_end_point_left_low(p, curr_node)) { curr_node = curr_node.left_child(); continue; } //else if ((is_fict_vtx && is_end_point_right_top(p, *(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)))) || // (!is_fict_vtx && is_end_point_right_top(p, boost::apply_visitor(point_for_vertex_visitor(), curr_item))) ) - else if (is_end_point_right_top(p, curr_node)) - { + else if (is_end_point_right_top(p, curr_node)) { curr_node = curr_node.right_child(); continue; } //else if ((is_fict_vtx && traits->equal_curve_end_2_object()(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), p)) || // (!is_fict_vtx && traits->equal_2_object()(boost::apply_visitor(point_for_vertex_visitor(), curr_item), p)) ) - else if (are_equal_end_points(p, curr_node)) - { - if (he == m_empty_he_handle) //if he is the empty handle - { - if ( up == EQUAL ) - { // point found! - if (traits->is_active(curr_item)) - return POINT; + else if (are_equal_end_points(p, curr_node)) { + if (he == m_empty_he_handle) { + // he is the empty handle + if (up == EQUAL) { + // point found! + if (traits->is_active(curr_item)) return POINT; curr_node = curr_node.left_child(); } - else if ( up == LARGER ) { // vertical ray shut up + else if (up == LARGER) { // vertical ray shut up curr_node = curr_node.right_child(); } - else /*if ( up == SMALLER ) */ { - curr_node = curr_node.left_child(); // vertical ray shut down - } + else curr_node = curr_node.left_child(); continue; } - else //if he was given - { - bool is_equal_to_he_min = traits->equal_curve_end_2_object() - (Curve_end(he,ARR_MIN_END), p); - bool is_equal_to_he_max = traits->equal_curve_end_2_object() - (Curve_end(he,ARR_MAX_END), p); + else { + // he was given + bool is_equal_to_he_min = + traits->equal_curve_end_2_object()(Curve_end(he,ARR_MIN_END), p); + bool is_equal_to_he_max = + traits->equal_curve_end_2_object()(Curve_end(he,ARR_MAX_END), p); CGAL_assertion( is_equal_to_he_min || is_equal_to_he_max ); CGAL_USE(is_equal_to_he_max); @@ -666,8 +645,7 @@ Trapezoidal_decomposition_2 continue; } } - else - { + else { CGAL_assertion(is_end_point_left_low(p,curr_node) || is_end_point_right_top(p,curr_node) || are_equal_end_points(p,curr_node)); @@ -684,96 +662,74 @@ Trapezoidal_decomposition_2 return Locate_type(); } } - if (traits->is_td_edge(curr_item)) - { // if curr_item represents an edge, + if (traits->is_td_edge(curr_item)) { + // curr_item represents an edge, // so top() is a real Halfedge with a curve() if curr_item is active // or curr_item holds the curve if it is not active const X_monotone_curve_2& he_cv = *(boost::apply_visitor(cv_for_edge_visitor(), curr_item)); Comparison_result cres = traits->compare_y_at_x_2_object()(p, he_cv); - if (cres == SMALLER) - { + if (cres == SMALLER) { curr_node = curr_node.left_child(); continue; } - else if (cres == LARGER) - { + else if (cres == LARGER) { curr_node = curr_node.right_child(); continue; } - else - { + else { // p is on the curve itself - CGAL_warning( - (cres == EQUAL) && - (traits->compare_curve_end_x_2_object() - (p, Curve_end(he_cv,ARR_MAX_END)) != LARGER) && - (traits->compare_curve_end_x_2_object() - (p, Curve_end(he_cv,ARR_MIN_END)) != SMALLER)); + CGAL_warning((cres == EQUAL) && + (traits->compare_curve_end_x_2_object() + (p, Curve_end(he_cv,ARR_MAX_END)) != LARGER) && + (traits->compare_curve_end_x_2_object() + (p, Curve_end(he_cv,ARR_MIN_END)) != SMALLER)); - if (he == m_empty_he_handle) //if he was not given - { + if (he == m_empty_he_handle) { + //f he was not given // For a vertical curve, we always visit it after visiting // one of its endpoints. - if ((up == EQUAL) || traits->is_vertical(curr_item)) - { - if (traits->is_active(curr_item)) - return CURVE; + if ((up == EQUAL) || traits->is_vertical(curr_item)) { + if (traits->is_active(curr_item)) return CURVE; curr_node = curr_node.left_child(); } - else if (up == LARGER) - { + else if (up == LARGER) { curr_node = curr_node.right_child(); } - else - { // if (up==SMALLER) - curr_node = curr_node.left_child(); - } + else curr_node = curr_node.left_child(); continue; } - else //if he was given - { + else { + // he was given //p is a parameter space interior point - bool is_min_equal = traits->equal_curve_end_2_object() - (Curve_end(he,ARR_MIN_END), - Curve_end(he_cv,ARR_MIN_END)); + bool is_min_equal = + traits->equal_curve_end_2_object()(Curve_end(he,ARR_MIN_END), + Curve_end(he_cv,ARR_MIN_END)); - bool is_max_equal = traits->equal_curve_end_2_object() - (Curve_end(he,ARR_MAX_END), - Curve_end(he_cv,ARR_MAX_END)); + bool is_max_equal = + traits->equal_curve_end_2_object()(Curve_end(he,ARR_MAX_END), + Curve_end(he_cv,ARR_MAX_END)); CGAL_warning (is_min_equal || is_max_equal); CGAL_USE(is_max_equal); - Comparison_result res = - is_min_equal ? + Comparison_result res = is_min_equal ? + traits->compare_cw_around_point_2_object() + (he_cv, is_curve_to_right(he_cv, p), + he->curve(), is_edge_to_right(he, p), p) : traits->compare_cw_around_point_2_object() - (he_cv, is_curve_to_right(he_cv,p), - he->curve(), is_edge_to_right(he,p), p) : - traits->compare_cw_around_point_2_object() - (he->curve(), is_edge_to_right(he,p), - he_cv, is_curve_to_right(he_cv,p), p ,false); + (he->curve(), is_edge_to_right(he, p), + he_cv, is_curve_to_right(he_cv,p), p, false); - switch(res) - { - case LARGER: - curr_node = curr_node.right_child(); - break; - case SMALLER: - curr_node = curr_node.left_child(); - break; + switch(res) { + case LARGER: curr_node = curr_node.right_child(); break; + case SMALLER: curr_node = curr_node.left_child(); break; case EQUAL: - switch(up) - { - case LARGER: - curr_node = curr_node.right_child(); - break; - case SMALLER: - curr_node = curr_node.left_child(); - break; + switch(up) { + case LARGER: curr_node = curr_node.right_child(); break; + case SMALLER: curr_node = curr_node.left_child(); break; case EQUAL: - if (traits->is_active(curr_item)) - return CURVE; + if (traits->is_active(curr_item)) return CURVE; curr_node = curr_node.left_child(); break; } @@ -782,11 +738,9 @@ Trapezoidal_decomposition_2 } } } - else - { + else { // if is_degenerate() == 0, meaning: curr_item is a real trapezoid - if (traits->is_active(curr_item)) - { + if (traits->is_active(curr_item)) { Td_active_trapezoid& tr = boost::get(curr_item); return tr.is_on_boundaries() ? UNBOUNDED_TRAPEZOID : TRAPEZOID; } @@ -796,8 +750,6 @@ Trapezoidal_decomposition_2 } } - - ////----------------------------------------------------------------------------- //// Description: //// advances input Data structure using data structure,input point p and @@ -810,7 +762,7 @@ Trapezoidal_decomposition_2 //// output is the closest active trapezoid to ce/p_he //// remark: //// use this function with care! -//template +//template //void //Trapezoidal_decomposition_2 //::search_and_print_using_dag (std::ostream& out, @@ -1015,19 +967,19 @@ Trapezoidal_decomposition_2 // output is the closest active trapezoid to ce/p_he // remark: // use this function with care! -template +template typename Trapezoidal_decomposition_2::Locate_type -Trapezoidal_decomposition_2 -::search_using_dag (Dag_node& curr_node, - const Traits* traits, - const Curve_end& ce, - Halfedge_const_handle he, - Comparison_result up /*=EQUAL*/) const +Trapezoidal_decomposition_2:: +search_using_dag(Dag_node& curr_node, + const Traits* traits, + const Curve_end& ce, + Halfedge_const_handle he, + Comparison_result up /*=EQUAL*/) const { if (he == m_empty_he_handle) - return search_using_dag_with_cv (curr_node,traits,ce,NULL, up); + return search_using_dag_with_cv(curr_node,traits,ce,NULL, up); else - return search_using_dag_with_cv (curr_node,traits,ce,&he->curve(), up); + return search_using_dag_with_cv(curr_node,traits,ce,&he->curve(), up); } //----------------------------------------------------------------------------- @@ -1042,77 +994,66 @@ Trapezoidal_decomposition_2 // output is the closest active trapezoid to ce/p_cv // remark: // use this function with care! -template +template typename Trapezoidal_decomposition_2::Locate_type -Trapezoidal_decomposition_2 -::search_using_dag_with_cv (Dag_node& curr_node, - const Traits* traits, - const Curve_end& ce, - const X_monotone_curve_2* p_cv, - Comparison_result up /*=EQUAL*/) const +Trapezoidal_decomposition_2:: +search_using_dag_with_cv(Dag_node& curr_node, + const Traits* traits, + const Curve_end& ce, + const X_monotone_curve_2* p_cv, + Comparison_result up /*=EQUAL*/) const { - while(true) - { + while (true) { //curr_node is the current pointer to node in the data structure //curr_item is the curent Td_map_item held in curr_node Td_map_item curr_item(curr_node.get_data()); - if (traits->is_td_vertex(curr_item)) - { // if the curr_item represents a vertex + if (traits->is_td_vertex(curr_item)) { + // the curr_item represents a vertex //bool is_fict_vtx = traits->is_fictitious_vertex(curr_item); //if ((is_fict_vtx && is_end_point_right_top(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), ce)) || // (!is_fict_vtx && is_end_point_right_top(boost::apply_visitor(point_for_vertex_visitor(), curr_item), ce)) ) - if (is_end_point_left_low(ce, curr_node)) - { + if (is_end_point_left_low(ce, curr_node)) { curr_node = curr_node.left_child(); continue; } //else if ((is_fict_vtx && is_end_point_left_low(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), ce)) || // (!is_fict_vtx && is_end_point_left_low(boost::apply_visitor(point_for_vertex_visitor(), curr_item), ce)) ) - else if (is_end_point_right_top(ce, curr_node)) - { + else if (is_end_point_right_top(ce, curr_node)) { curr_node = curr_node.right_child(); continue; } //else if ((is_fict_vtx && traits->equal_curve_end_2_object()(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), ce)) || // (!is_fict_vtx && traits->equal_curve_end_2_object()(boost::apply_visitor(point_for_vertex_visitor(), curr_item), ce)) ) - else if (are_equal_end_points(ce, curr_node)) - { - if (!p_cv) //if p_cv was not given - { - if ( up == EQUAL ) - { // point found! - if (traits->is_active(curr_item)) - return POINT; + else if (are_equal_end_points(ce, curr_node)) { + if (!p_cv) { + // p_cv was not given + if (up == EQUAL) { + // point found! + if (traits->is_active(curr_item)) return POINT; curr_node = curr_node.left_child(); } - else if ( up == LARGER ) - { // vertical ray shut up - curr_node = curr_node.right_child(); - } - else - { // if ( up == SMALLER ) - curr_node = curr_node.left_child(); // vertical ray shut down - } + else if (up == LARGER) curr_node = curr_node.right_child(); + else curr_node = curr_node.left_child(); continue; } - else //if p_cv was given - { - bool is_equal_to_he_min = traits->equal_curve_end_2_object() - (Curve_end(*p_cv,ARR_MIN_END), ce); - bool is_equal_to_he_max = traits->equal_curve_end_2_object() - (Curve_end(*p_cv,ARR_MAX_END), ce); + else { + // p_cv was given + bool is_equal_to_he_min = + traits->equal_curve_end_2_object()(Curve_end(*p_cv,ARR_MIN_END), ce); + bool is_equal_to_he_max = + traits->equal_curve_end_2_object()(Curve_end(*p_cv,ARR_MAX_END), ce); CGAL_assertion( is_equal_to_he_min || is_equal_to_he_max ); CGAL_USE(is_equal_to_he_max); - curr_node = is_equal_to_he_min ? curr_node.right_child() : curr_node.left_child(); + curr_node = is_equal_to_he_min ? + curr_node.right_child() : curr_node.left_child(); continue; } } - else - { + else { CGAL_assertion(is_end_point_left_low(ce, curr_node) || is_end_point_right_top(ce, curr_node) || are_equal_end_points(ce, curr_node)); @@ -1127,73 +1068,64 @@ Trapezoidal_decomposition_2 return Locate_type(); } } - if (traits->is_td_edge(curr_item)) - { // if curr_item represents an edge, + if (traits->is_td_edge(curr_item)) { + // curr_item represents an edge, // so top() is a real Halfedge with a curve() if curr_item is active // or curr_item holds the curve if it is not active - const X_monotone_curve_2& he_cv = *(boost::apply_visitor(cv_for_edge_visitor(), curr_item)); - Comparison_result cres = traits->compare_curve_end_y_at_x_2_object()(ce, he_cv); - if (cres == SMALLER) - { + const X_monotone_curve_2& he_cv = + *(boost::apply_visitor(cv_for_edge_visitor(), curr_item)); + Comparison_result cres = + traits->compare_curve_end_y_at_x_2_object()(ce, he_cv); + if (cres == SMALLER) { curr_node = curr_node.left_child(); continue; } - else if (cres == LARGER) - { + else if (cres == LARGER) { curr_node = curr_node.right_child(); continue; } - else - { + else { // ce is on the CURVE (he_cv = ce.cv()) itself CGAL_warning( (cres == EQUAL) && (traits->compare_curve_end_x_2_object() - (ce, Curve_end(he_cv,ARR_MAX_END)) != LARGER) && + (ce, Curve_end(he_cv,ARR_MAX_END)) != LARGER) && (traits->compare_curve_end_x_2_object() - (ce, Curve_end(he_cv,ARR_MIN_END)) != SMALLER)); + (ce, Curve_end(he_cv,ARR_MIN_END)) != SMALLER)); - if (!p_cv) //if p_cv was not given - { + if (!p_cv) { + // p_cv was not given // For a vertical curve, we always visit it after visiting // one of its endpoints. - if ((up == EQUAL) || traits->is_vertical(curr_item)) - { - if (traits->is_active(curr_item)) - return CURVE; - curr_node = curr_node.left_child(); - } - else if (up == LARGER) - { - curr_node = curr_node.right_child(); - } - else - { // if (up==SMALLER) + if ((up == EQUAL) || traits->is_vertical(curr_item)) { + if (traits->is_active(curr_item)) return CURVE; curr_node = curr_node.left_child(); } + else if (up == LARGER) curr_node = curr_node.right_child(); + else curr_node = curr_node.left_child(); continue; } - else //if p_cv was given - { + else { + // p_cv was given Comparison_result res = EQUAL; if ((traits->parameter_space_in_x_2_object() - (ce.cv(), ce.ce()) == ARR_INTERIOR) && + (ce.cv(), ce.ce()) == ARR_INTERIOR) && (traits->parameter_space_in_y_2_object() - (ce.cv(), ce.ce()) == ARR_INTERIOR) ) + (ce.cv(), ce.ce()) == ARR_INTERIOR) ) { //if ce is interior then there might be more than one curve // with ce as its endpoint - bool is_min_equal = traits->equal_curve_end_2_object() - (Curve_end(*p_cv,ARR_MIN_END), - Curve_end(he_cv,ARR_MIN_END)); + bool is_min_equal = + traits->equal_curve_end_2_object()(Curve_end(*p_cv,ARR_MIN_END), + Curve_end(he_cv,ARR_MIN_END)); - bool is_max_equal = traits->equal_curve_end_2_object() - (Curve_end(*p_cv,ARR_MAX_END), - Curve_end(he_cv,ARR_MAX_END)); + bool is_max_equal = + traits->equal_curve_end_2_object()(Curve_end(*p_cv,ARR_MAX_END), + Curve_end(he_cv,ARR_MAX_END)); - CGAL_warning (is_min_equal || is_max_equal); + CGAL_warning(is_min_equal || is_max_equal); CGAL_USE(is_max_equal); //the underlying point of ce @@ -1202,34 +1134,23 @@ Trapezoidal_decomposition_2 traits->construct_max_vertex_2_object()(ce.cv()) ; res = is_min_equal ? - traits->compare_cw_around_point_2_object() - (he_cv, is_curve_to_right(he_cv,p), - *p_cv, is_curve_to_right(*p_cv,p), p) : - traits->compare_cw_around_point_2_object() - (*p_cv, is_curve_to_right(*p_cv,p), - he_cv, is_curve_to_right(he_cv,p), p ,false); + traits->compare_cw_around_point_2_object() + (he_cv, is_curve_to_right(he_cv,p), + *p_cv, is_curve_to_right(*p_cv,p), p) : + traits->compare_cw_around_point_2_object() + (*p_cv, is_curve_to_right(*p_cv,p), + he_cv, is_curve_to_right(he_cv,p), p ,false); } - switch(res) - { - case LARGER: - curr_node = curr_node.right_child(); - break; - case SMALLER: - curr_node = curr_node.left_child(); - break; + switch(res) { + case LARGER: curr_node = curr_node.right_child(); break; + case SMALLER: curr_node = curr_node.left_child(); break; case EQUAL: - switch(up) - { - case LARGER: - curr_node = curr_node.right_child(); - break; - case SMALLER: - curr_node = curr_node.left_child(); - break; + switch(up) { + case LARGER: curr_node = curr_node.right_child(); break; + case SMALLER: curr_node = curr_node.left_child(); break; case EQUAL: - if (traits->is_active(curr_item)) - return CURVE; + if (traits->is_active(curr_item)) return CURVE; curr_node = curr_node.left_child(); break; } @@ -1238,11 +1159,9 @@ Trapezoidal_decomposition_2 } } } - else - { + else { // if is_degenerate() == 0, meaning: curr_item is a real trapezoid - if (traits->is_active(curr_item)) - { + if (traits->is_active(curr_item)) { Td_active_trapezoid& tr = boost::get(curr_item); return tr.is_on_boundaries() ? UNBOUNDED_TRAPEZOID : TRAPEZOID; } @@ -1252,11 +1171,6 @@ Trapezoidal_decomposition_2 } } - - - - - //----------------------------------------------------------------------------- // Description: // advances input Data structure using data structure,input point ce and @@ -1269,78 +1183,67 @@ Trapezoidal_decomposition_2 // output is the closest active trapezoid to ce/p_cv // remark: // use this function with care! -template +template typename Trapezoidal_decomposition_2::Locate_type -Trapezoidal_decomposition_2 -::search_using_dag_with_cv (Dag_node& curr_node, - const Traits* traits, - const Point& p, - const X_monotone_curve_2* p_cv, - Comparison_result up /*=EQUAL*/) const +Trapezoidal_decomposition_2:: +search_using_dag_with_cv(Dag_node& curr_node, + const Traits* traits, + const Point& p, + const X_monotone_curve_2* p_cv, + Comparison_result up /*=EQUAL*/) const { - while(true) - { + while (true) { //curr_node is the current pointer to node in the data structure //curr_item is the curent Td_map_item held in curr_node Td_map_item curr_item(curr_node.get_data()); - if (traits->is_td_vertex(curr_item)) - { // if the curr_item represents a vertex + if (traits->is_td_vertex(curr_item)) { + // the curr_item represents a vertex //bool is_fict_vtx = traits->is_fictitious_vertex(curr_item); //if ((is_fict_vtx && is_end_point_right_top(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), p)) || // (!is_fict_vtx && is_end_point_right_top(boost::apply_visitor(point_for_vertex_visitor(), curr_item), p)) ) - if (is_end_point_left_low(p, curr_node)) - { + if (is_end_point_left_low(p, curr_node)) { curr_node = curr_node.left_child(); continue; } //else if ((is_fict_vtx && is_end_point_left_low(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), p)) || // (!is_fict_vtx && is_end_point_left_low(boost::apply_visitor(point_for_vertex_visitor(), curr_item), p)) ) - else if (is_end_point_right_top(p, curr_node)) - { + else if (is_end_point_right_top(p, curr_node)) { curr_node = curr_node.right_child(); continue; } //else if ((is_fict_vtx && traits->equal_curve_end_2_object()(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), p)) || // (!is_fict_vtx && traits->equal_2_object()(boost::apply_visitor(point_for_vertex_visitor(), curr_item), p)) ) - else if (are_equal_end_points(p, curr_node)) - { - if (!p_cv) //if p_cv was not given - { - if ( up == EQUAL ) - { // point found! - if (traits->is_active(curr_item)) - return POINT; + else if (are_equal_end_points(p, curr_node)) { + if (!p_cv) { + // p_cv was not given + if (up == EQUAL) { + // point found! + if (traits->is_active(curr_item)) return POINT; curr_node = curr_node.left_child(); } - else if ( up == LARGER ) - { // vertical ray shut up - curr_node = curr_node.right_child(); - } - else - { // if ( up == SMALLER ) - curr_node = curr_node.left_child(); // vertical ray shut down - } + else if (up == LARGER) curr_node = curr_node.right_child(); + else curr_node = curr_node.left_child(); continue; } - else //if p_cv was given - { - bool is_equal_to_he_min = traits->equal_curve_end_2_object() - (Curve_end(*p_cv,ARR_MIN_END), p); - bool is_equal_to_he_max = traits->equal_curve_end_2_object() - (Curve_end(*p_cv,ARR_MAX_END), p); + else { + // p_cv was given + bool is_equal_to_he_min = + traits->equal_curve_end_2_object()(Curve_end(*p_cv,ARR_MIN_END), p); + bool is_equal_to_he_max = + traits->equal_curve_end_2_object()(Curve_end(*p_cv,ARR_MAX_END), p); CGAL_assertion( is_equal_to_he_min || is_equal_to_he_max ); CGAL_USE(is_equal_to_he_max); - curr_node = is_equal_to_he_min ? curr_node.right_child() : curr_node.left_child(); + curr_node = is_equal_to_he_min ? + curr_node.right_child() : curr_node.left_child(); continue; } } - else - { + else { CGAL_assertion(is_end_point_left_low(p, curr_node) || is_end_point_right_top(p, curr_node) || are_equal_end_points(p, curr_node)); @@ -1355,97 +1258,76 @@ Trapezoidal_decomposition_2 return Locate_type(); } } - if (traits->is_td_edge(curr_item)) - { // if curr_item represents an edge, + if (traits->is_td_edge(curr_item)) { + // curr_item represents an edge, // so top() is a real Halfedge with a curve() if curr_item is active // or curr_item holds the curve if it is not active - const X_monotone_curve_2& he_cv = *(boost::apply_visitor(cv_for_edge_visitor(), curr_item)); + const X_monotone_curve_2& he_cv = + *(boost::apply_visitor(cv_for_edge_visitor(), curr_item)); Comparison_result cres = traits->compare_y_at_x_2_object()(p, he_cv); - if (cres == SMALLER) - { + if (cres == SMALLER) { curr_node = curr_node.left_child(); continue; } - else if (cres == LARGER) - { + else if (cres == LARGER) { curr_node = curr_node.right_child(); continue; } - else - { + else { // p is on the CURVE itself CGAL_warning( (cres == EQUAL) && (traits->compare_curve_end_x_2_object() - (p, Curve_end(he_cv,ARR_MAX_END)) != LARGER) && + (p, Curve_end(he_cv,ARR_MAX_END)) != LARGER) && (traits->compare_curve_end_x_2_object() - (p, Curve_end(he_cv,ARR_MIN_END)) != SMALLER)); + (p, Curve_end(he_cv,ARR_MIN_END)) != SMALLER)); - if (!p_cv) //if p_cv was not given - { + if (!p_cv) { + // p_cv was not given // For a vertical curve, we always visit it after visiting // one of its endpoints. - if ((up == EQUAL) || traits->is_vertical(curr_item)) - { - if (traits->is_active(curr_item)) - return CURVE; - curr_node = curr_node.left_child(); - } - else if (up == LARGER) - { - curr_node = curr_node.right_child(); - } - else - { // if (up==SMALLER) + if ((up == EQUAL) || traits->is_vertical(curr_item)) { + if (traits->is_active(curr_item)) return CURVE; curr_node = curr_node.left_child(); } + else if (up == LARGER) curr_node = curr_node.right_child(); + else curr_node = curr_node.left_child(); continue; } - else //if p_cv was given - { + else { + // p_cv was given Comparison_result res = EQUAL; //p is interior then there might be more than one curve // with p as its endpoint - bool is_min_equal = traits->equal_curve_end_2_object() - (Curve_end(*p_cv,ARR_MIN_END), - Curve_end(he_cv,ARR_MIN_END)); + bool is_min_equal = + traits->equal_curve_end_2_object()(Curve_end(*p_cv,ARR_MIN_END), + Curve_end(he_cv,ARR_MIN_END)); - bool is_max_equal = traits->equal_curve_end_2_object() - (Curve_end(*p_cv,ARR_MAX_END), - Curve_end(he_cv,ARR_MAX_END)); + bool is_max_equal = + traits->equal_curve_end_2_object()(Curve_end(*p_cv,ARR_MAX_END), + Curve_end(he_cv,ARR_MAX_END)); - CGAL_warning (is_min_equal || is_max_equal); + CGAL_warning(is_min_equal || is_max_equal); CGAL_USE(is_max_equal); res = is_min_equal ? - traits->compare_cw_around_point_2_object() - (he_cv, is_curve_to_right(he_cv,p), - *p_cv, is_curve_to_right(*p_cv,p), p) : - traits->compare_cw_around_point_2_object() - (*p_cv, is_curve_to_right(*p_cv,p), - he_cv, is_curve_to_right(he_cv,p), p ,false); + traits->compare_cw_around_point_2_object() + (he_cv, is_curve_to_right(he_cv,p), + *p_cv, is_curve_to_right(*p_cv,p), p) : + traits->compare_cw_around_point_2_object() + (*p_cv, is_curve_to_right(*p_cv,p), + he_cv, is_curve_to_right(he_cv,p), p ,false); - switch(res) - { - case LARGER: - curr_node = curr_node.right_child(); - break; - case SMALLER: - curr_node = curr_node.left_child(); - break; + switch(res) { + case LARGER: curr_node = curr_node.right_child(); break; + case SMALLER: curr_node = curr_node.left_child(); break; case EQUAL: - switch(up) - { - case LARGER: - curr_node = curr_node.right_child(); - break; - case SMALLER: - curr_node = curr_node.left_child(); - break; + switch(up) { + case LARGER: curr_node = curr_node.right_child(); break; + case SMALLER: curr_node = curr_node.left_child(); break; case EQUAL: - if (traits->is_active(curr_item)) - return CURVE; + if (traits->is_active(curr_item)) return CURVE; curr_node = curr_node.left_child(); break; } @@ -1454,11 +1336,9 @@ Trapezoidal_decomposition_2 } } } - else - { - // if is_degenerate() == 0, meaning: curr_item is a real trapezoid - if (traits->is_active(curr_item)) - { + else { + // is_degenerate() == 0, meaning: curr_item is a real trapezoid + if (traits->is_active(curr_item)) { Td_active_trapezoid& tr = boost::get(curr_item); return tr.is_on_boundaries() ? UNBOUNDED_TRAPEZOID : TRAPEZOID; } @@ -1468,81 +1348,78 @@ Trapezoidal_decomposition_2 } } - - - - //----------------------------------------------------------------------------- // Description: // -template +template typename Trapezoidal_decomposition_2::Dag_node -Trapezoidal_decomposition_2 -::container2dag (Nodes_map& ar, int left, int right, - int& num_of_new_nodes) const +Trapezoidal_decomposition_2:: +container2dag(Nodes_map& ar, int left, int right, int& num_of_new_nodes) const { CGAL_warning(traits != NULL); - if (right > left) - { + if (right > left) { int d = (int)std::floor((double(right+left))/2); Dag_node& node(ar.find(d)->second); Td_map_item item(node.get_data()); CGAL_assertion(traits->is_active(item)); CGAL_assertion(traits->is_td_trapezoid(item)); Dag_node& tr_node( ar.find(d)->second); - Td_active_trapezoid& tr( boost::get(tr_node.get_data())); + Td_active_trapezoid& tr(boost::get(tr_node.get_data())); Vertex_const_handle v = tr.right(); Curve_end ce(traits->vtx_to_ce(v)); - bool is_interior = traits->parameter_space_in_x_2_object()(ce.cv(), ce.ce()) - && traits->parameter_space_in_y_2_object()(ce.cv(), ce.ce()); + bool is_interior = + traits->parameter_space_in_x_2_object()(ce.cv(), ce.ce()) && + traits->parameter_space_in_y_2_object()(ce.cv(), ce.ce()); Dag_node curr_node; - Dag_node left_child (container2dag(ar,left,d,num_of_new_nodes)); - Dag_node right_child (container2dag(ar,d+1,right,num_of_new_nodes)); - if (is_interior) - { - curr_node.replace(Td_map_item(Td_active_vertex(v,m_empty_he_handle)),left_child, right_child); + Dag_node left_child(container2dag(ar, left, d, num_of_new_nodes)); + Dag_node right_child(container2dag(ar, d+1, right, num_of_new_nodes)); + if (is_interior) { + curr_node.replace(Td_map_item(Td_active_vertex(v, m_empty_he_handle)), + left_child, right_child); } - else - { - curr_node.replace(Td_map_item(Td_active_fictitious_vertex(v,m_empty_he_handle)),left_child, right_child); + else { + curr_node.replace(Td_map_item(Td_active_fictitious_vertex(v, m_empty_he_handle)), left_child, right_child); } num_of_new_nodes++; - boost::apply_visitor(set_dag_node_visitor((Dag_node*)&(curr_node.left_child())),curr_node.left_child().get_data()); - boost::apply_visitor(set_dag_node_visitor((Dag_node*)&(curr_node.right_child())),curr_node.right_child().get_data()); - boost::apply_visitor(set_dag_node_visitor((Dag_node*)&curr_node),curr_node.get_data()); + boost::apply_visitor(set_dag_node_visitor((Dag_node*)&(curr_node.left_child())), curr_node.left_child().get_data()); + boost::apply_visitor(set_dag_node_visitor((Dag_node*)&(curr_node.right_child())), curr_node.right_child().get_data()); + boost::apply_visitor(set_dag_node_visitor((Dag_node*)&curr_node), + curr_node.get_data()); //curr_node.left_child()->set_dag_node(&curr_node.left_child()); //curr_node.right_child()->set_dag_node(&curr_node.right_child()); //curr_node->set_dag_node(&curr_node);// fake temporary node deactivate_vertex(curr_node); //curr_node->remove(); // mark as deleted - boost::apply_visitor(set_dag_node_visitor((Dag_node*)NULL),curr_node.get_data());//curr_node->set_dag_node(0); + boost::apply_visitor(set_dag_node_visitor((Dag_node*)NULL), + curr_node.get_data());//curr_node->set_dag_node(0); return curr_node; } - else - { + else { return ar.find(left)->second; } } -template -bool Trapezoidal_decomposition_2 -::is_last_edge(Halfedge_const_handle /* he */ , Td_map_item& vtx_item) +template +bool Trapezoidal_decomposition_2:: +is_last_edge(Halfedge_const_handle /* he */ , Td_map_item& vtx_item) { CGAL_precondition(traits->is_td_vertex(vtx_item)); CGAL_precondition(traits->is_active(vtx_item)); - Vertex_const_handle v (boost::apply_visitor(vertex_for_active_vertex_visitor(), vtx_item)); + Vertex_const_handle + v(boost::apply_visitor(vertex_for_active_vertex_visitor(), vtx_item)); - typename Arrangement_on_surface_2::Halfedge_around_vertex_const_circulator first, second; + typename Arrangement_on_surface_2::Halfedge_around_vertex_const_circulator + first, second; first = second = v->incident_halfedges(); ++second; - if (second == first) //if he is the only halfedge around v -> return true - return true; + //if he is the only halfedge around v -> return true + if (second == first) return true; return false; } @@ -1555,22 +1432,22 @@ bool Trapezoidal_decomposition_2 // Given an edge-degenerate trapezoid representing a Halfedge, // all the other trapezoids representing the Halfedge can be extracted // via moving continously to the left and right neighbours. -template +template typename Trapezoidal_decomposition_2::Td_map_item -Trapezoidal_decomposition_2 -::insert(Halfedge_const_handle he) //::insert_in_face_interior(Halfedge_const_handle he) +Trapezoidal_decomposition_2::insert(Halfedge_const_handle he) { //print_cv_data(he->curve()); - if (m_with_guarantees) - update(); + if (m_with_guarantees) update(); // locate the input Halfedge end points in the Td_map_item Dag CGAL_assertion(traits != NULL); //get the two vertices of the halfedge - Vertex_const_handle v1 = (he->direction() == ARR_LEFT_TO_RIGHT) ? he->source() : he->target(); - Vertex_const_handle v2 = (he->direction() == ARR_LEFT_TO_RIGHT) ? he->target() : he->source(); + Vertex_const_handle v1 = + (he->direction() == ARR_LEFT_TO_RIGHT) ? he->source() : he->target(); + Vertex_const_handle v2 = + (he->direction() == ARR_LEFT_TO_RIGHT) ? he->target() : he->source(); //define the Curve end points (curve end = vertex) const Curve_end ce1(he, ARR_MIN_END); //MICHAL: to be removed? @@ -1579,54 +1456,45 @@ Trapezoidal_decomposition_2 // make sure that the two endpoints are not the same point CGAL_precondition(!traits->equal_curve_end_2_object()(ce1, ce2)); - Locate_type lt1,lt2; + Locate_type lt1, lt2; //should hold the trapezoids in which the edge endpoints should be located Td_map_item item1; Td_map_item item2; #ifndef CGAL_NO_TRAPEZOIDAL_DECOMPOSITION_2_OPTIMIZATION - locate_optimization(ce1,item1,lt1); - #else //location of the left endpoint of the edge we're inserting item1 = locate(ce1,lt1); - #endif - //the inserted edge should not cut any existing edge - if (lt1 == CURVE) - { + if (lt1 == CURVE) { CGAL_precondition_msg(lt1 != CURVE, "Input is not planar as\ one of the input point inside previously inserted Halfedge."); return Td_map_item(0); } - //if the edge starts at vertex, we should not insert it into the DAG, - //but we should update all the edges incident to the vertex. - //else if this is a new vertex - insert a node to the DAG that will represent the new vertex. - //the incident edges in this case is only the edge itself, and so it is a trivial operation. + // if the edge starts at a vertex, we should not insert it into the DAG. + // Instead, we should update all the edges incident to the vertex. + // Otherwise, this is a new vertex, insert a node to the DAG that represents + // the new vertex. In this case, the the edge itself is the only incident + // edge, and so it is a trivial operation. Td_map_item p1_item = (lt1 == POINT) ? update_vtx_with_new_edge(he,ce1,item1,lt1) : insert_curve_at_vtx_using_dag(he,v1,item1,lt1); - #ifndef CGAL_NO_TRAPEZOIDAL_DECOMPOSITION_2_OPTIMIZATION - locate_optimization(ce2,item2,lt2); locate_opt_empty(); - #else // TODO(oren): locating the second endpoint. this is not necessary, // and time consuming. item2 = locate(ce2,lt2); - #endif - if (lt2==CURVE) - { + if (lt2 == CURVE) { CGAL_precondition_msg(lt2!=CURVE,"Input is not planar as\ one of the input point inside previously inserted Halfedge."); return Td_map_item(0); @@ -1657,8 +1525,7 @@ Trapezoidal_decomposition_2 CGAL_assertion(!traits->is_empty_item(*it) && traits->is_td_trapezoid(*it)); - while(!!it) //this means as long as the iterator is valid - { + while(!!it) { //this means as long as the iterator is valid curr_trp = it.trp(); CGAL_assertion(curr_trp != boost::none); prev_bottom_tr = (*curr_trp).lb(); @@ -1670,7 +1537,7 @@ Trapezoidal_decomposition_2 node = (*curr_trp).dag_node(); if(first_time) { - Halfedge_const_handle top_he ((*curr_trp).top()); + Halfedge_const_handle top_he((*curr_trp).top()); if((top_he == he) || (top_he == he->twin())) { CGAL_warning((top_he != he) && (top_he != he->twin())); return Td_map_item(0); @@ -1679,20 +1546,19 @@ Trapezoidal_decomposition_2 first_time = false; CGAL_assertion(node != NULL); - split_trapezoid_by_halfedge (*node, old_e, old_bottom_tr, old_top_tr, he); + split_trapezoid_by_halfedge(*node, old_e, old_bottom_tr, old_top_tr, he); - - - if (node->is_inner_node()) - { + if (node->is_inner_node()) { // merge adjacent trapezoids on input Halfedge's bottom side if possible // make sure we try to merge active trapezoids //node->left_child() is active Td_map_item new_btm_item = node->left_child().get_data(); - CGAL_assertion(traits->is_td_trapezoid(new_btm_item) && traits->is_active(new_btm_item)); + CGAL_assertion(traits->is_td_trapezoid(new_btm_item) && + traits->is_active(new_btm_item)); if(merge_if_possible(prev_bottom_tr, new_btm_item)) { - Dag_node* left_child_node = boost::apply_visitor(dag_node_visitor(),prev_bottom_tr); + Dag_node* left_child_node = + boost::apply_visitor(dag_node_visitor(),prev_bottom_tr); node->set_left_child(*left_child_node); old_bottom_tr = prev_bottom_tr; m_number_of_dag_nodes--; //update number of nodes in the DAG after merge @@ -1702,7 +1568,8 @@ Trapezoidal_decomposition_2 // make sure we try to merge active trapezoids //node->right_child() is active Td_map_item new_top_item = node->right_child().get_data(); - CGAL_assertion(traits->is_td_trapezoid(new_top_item) && traits->is_active(new_top_item)); + CGAL_assertion(traits->is_td_trapezoid(new_top_item) && + traits->is_active(new_top_item)); if(merge_if_possible(prev_top_tr, new_top_item)) { Dag_node* right_child_node = boost::apply_visitor(dag_node_visitor(), @@ -1714,8 +1581,7 @@ Trapezoidal_decomposition_2 // update trapezoid's left/right neighbouring relations //MICHAL: if the assertion below fails then we need to check why CGAL_assertion(!traits->is_td_trapezoid(prev)); - if(traits->is_td_trapezoid(prev)) - { + if (traits->is_td_trapezoid(prev)) { //MICHAL: if we reach here ->then this need to be uncommented // I thought that prev is always a degenerate point //curr_trp->set_lb(prev); @@ -1724,13 +1590,10 @@ Trapezoidal_decomposition_2 //prev->set_rt(curr_trp); } } - else - { + else { #ifdef CGAL_TD_DEBUG - CGAL_assertion((*curr_trp).is_valid(traits)); - #endif break; @@ -1748,20 +1611,17 @@ Trapezoidal_decomposition_2 return old_e; } - //----------------------------------------------------------------------------- // Description: // // Remark: // Assumes the map to be planar. -template -void Trapezoidal_decomposition_2 -::remove(Halfedge_const_handle he) +template +void Trapezoidal_decomposition_2::remove(Halfedge_const_handle he) { //print_dag_addresses(*m_dag_root); - if (m_with_guarantees) - update(); + if (m_with_guarantees) update(); #ifndef CGAL_NO_TRAPEZOIDAL_DECOMPOSITION_2_OPTIMIZATION locate_opt_empty(); @@ -1781,15 +1641,14 @@ void Trapezoidal_decomposition_2 //both should be located on a point degenerate trapezoid CGAL_warning(lt1==POINT && lt2==POINT); - if (lt1!=POINT || lt2!=POINT) - return; + if (lt1 != POINT || lt2 != POINT) return; CGAL_warning(boost::apply_visitor(dag_node_visitor(), p1_item) != NULL); CGAL_warning(boost::apply_visitor(dag_node_visitor(), p2_item) != NULL); //retrieve the Dag_nodes of the two point-degenerate trapezoid - Dag_node& p1_node = *(boost::apply_visitor(dag_node_visitor(), p1_item));//*t1.dag_node(); - Dag_node& p2_node = *(boost::apply_visitor(dag_node_visitor(), p2_item));//*t2.dag_node(); + Dag_node& p1_node = *(boost::apply_visitor(dag_node_visitor(), p1_item)); + Dag_node& p2_node = *(boost::apply_visitor(dag_node_visitor(), p2_item)); //calculate the immediate lower, central and upper neighbourhood of // the curve in the data structure @@ -1807,22 +1666,21 @@ void Trapezoidal_decomposition_2 int last_index[] = {0,0}; int sz = 0; - Td_active_trapezoid& btm_it_tr (btm_it.trp()); - Td_active_trapezoid& top_it_tr (top_it.trp()); + Td_active_trapezoid& btm_it_tr(btm_it.trp()); + Td_active_trapezoid& top_it_tr(top_it.trp()); Vertex_const_handle left_v = btm_it_tr.left(); Vertex_const_handle right_v; Td_map_item last_btm_tr_item = Td_map_item(0); //pointer to the last btm_it tr Td_map_item last_top_tr_item = Td_map_item(0); //pointer to the last top_it tr Td_map_item last_new_tr_item = Td_map_item(0); //last new trpz that was created - Td_map_item old_tr_item = Td_map_item(0); //old trpz on which the new is based - + Td_map_item old_tr_item = Td_map_item(0); //old trpz on which the new is based CGAL_warning((top_it.trp()).left() == left_v); //----------------------------------- //1. remove adjacency at left end point // first_cv_tr is the first trapezoid representing he (type TD_EDGE) - Td_map_item first_edge_fragment_item (*mid_it); + Td_map_item first_edge_fragment_item(*mid_it); //----------------------------------- //2. update the map & the dag with new trapezoids which are merge of the @@ -1832,14 +1690,15 @@ void Trapezoidal_decomposition_2 top_it_tr = top_it.trp(); // decide which of btm_it,top_it to increment - inc_btm = is_end_point_left_low(Curve_end(traits->vtx_to_ce(btm_it_tr.right())), - Curve_end(traits->vtx_to_ce(top_it_tr.right()))); + inc_btm = + is_end_point_left_low(Curve_end(traits->vtx_to_ce(btm_it_tr.right())), + Curve_end(traits->vtx_to_ce(top_it_tr.right()))); // the current iterator that should be incremented In_face_iterator& curr_it = inc_btm ? btm_it : top_it; - Td_active_trapezoid& curr_it_tr (curr_it.trp()); + Td_active_trapezoid& curr_it_tr(curr_it.trp()); // reference to the last curr_it tr - Td_map_item& last_tr_item (inc_btm ? last_btm_tr_item : last_top_tr_item); + Td_map_item& last_tr_item(inc_btm ? last_btm_tr_item : last_top_tr_item); //set the new trpz right end right_v = curr_it_tr.right(); @@ -1862,20 +1721,14 @@ void Trapezoidal_decomposition_2 //new_node->set_dag_node(&new_node); //new_node->set_lb(btm_it->lb()); //new_node->set_lt(top_it->lt()); - if (!traits->is_empty_item(last_new_tr_item)) - { + if (!traits->is_empty_item(last_new_tr_item)) { if (traits->is_trpz_top_equal(last_new_tr_item, new_node.get_data())) - { tr.set_lt(last_new_tr_item); //new_node->set_lt(last_new_tr); - } if (traits->is_trpz_bottom_equal(last_new_tr_item, new_node.get_data())) - { tr.set_lb(last_new_tr_item); //new_node->set_lb(last_new_tr); - } } - if (!traits->is_empty_item(tr.lb())) - { + if (!traits->is_empty_item(tr.lb())) { Td_map_item lb_item = tr.lb(); Td_active_trapezoid& lb_tr(boost::get(lb_item)); lb_tr.set_rb(new_node.get_data()); @@ -1887,7 +1740,8 @@ void Trapezoidal_decomposition_2 lt_tr.set_rt(new_node.get_data()); } - last_new_tr_item = new_node.get_data(); //new_node.operator->(); //get the last new trapezoid created + last_new_tr_item = new_node.get_data(); + //new_node.operator->(); //get the last new trapezoid created //update arguments for next iteration: left_v = right_v; //new left is curr right @@ -1902,40 +1756,44 @@ void Trapezoidal_decomposition_2 //copy neighbouring trapezoids in case top/btm are not the same for the old // trapezoid and the next trapezoid after incrementing the old one if (!btm_it || - (inc_btm && !traits->is_trpz_bottom_equal(old_tr_item,*curr_it))) + (inc_btm && !traits->is_trpz_bottom_equal(old_tr_item, *curr_it))) { - Td_map_item rb (boost::apply_visitor(rb_visitor(),old_tr_item)); - if (!traits->is_empty_item(rb)) - { - boost::apply_visitor(set_lb_visitor(last_new_tr_item),rb); //rb->set_lb(last_new_tr); - boost::apply_visitor(set_rb_visitor(rb),last_new_tr_item); //last_new_tr->set_rb(rb); + Td_map_item rb(boost::apply_visitor(rb_visitor(), old_tr_item)); + if (!traits->is_empty_item(rb)) { + boost::apply_visitor(set_lb_visitor(last_new_tr_item), rb); + //rb->set_lb(last_new_tr); + boost::apply_visitor(set_rb_visitor(rb), last_new_tr_item); + //last_new_tr->set_rb(rb); } } if (!top_it || (!inc_btm && !traits->is_trpz_top_equal(old_tr_item,*curr_it))) { - Td_map_item rt (boost::apply_visitor(rt_visitor(),old_tr_item)); + Td_map_item rt(boost::apply_visitor(rt_visitor(), old_tr_item)); if (!traits->is_empty_item(rt)) { - boost::apply_visitor(set_lt_visitor(last_new_tr_item),rt); //rt->set_lt(last_new_tr); - boost::apply_visitor(set_rt_visitor(rt),last_new_tr_item); //last_new_tr->set_rt(rt); + boost::apply_visitor(set_lt_visitor(last_new_tr_item), rt); + //rt->set_lt(last_new_tr); + boost::apply_visitor(set_rt_visitor(rt), last_new_tr_item); + //last_new_tr->set_rt(rt); } } //set the no longer relevant trapezoids as removed and add the new nodes // as their replacement - Dag_node* last_tr_node (boost::apply_visitor(dag_node_visitor(), last_tr_item)); + Dag_node* last_tr_node(boost::apply_visitor(dag_node_visitor(), + last_tr_item)); - if (prev_inc_btm != inc_btm) - { + if (prev_inc_btm != inc_btm) { int num_of_new_nodes = 0; Dag_node tmp = container2dag (new_array, last_index[inc_btm ? 0 : 1], sz-1, num_of_new_nodes); deactivate_trapezoid( *last_tr_node, &tmp); //last_tr->remove(&tmp); - m_number_of_dag_nodes += num_of_new_nodes; //new vertex nodes (rooted at tmp) were added + m_number_of_dag_nodes += num_of_new_nodes; + //new vertex nodes (rooted at tmp) were added m_number_of_dag_nodes += 1; //new node (tmp) was added last_index[inc_btm ? 0 : 1] = sz; @@ -1943,12 +1801,10 @@ void Trapezoidal_decomposition_2 //tmp is the root of a sub graph. //The largest depth in this sub-graph may be the largest leaf depth update_largest_leaf_depth( tmp.max_depth() ); - } - else - { + else { int num_of_new_nodes = 0; - Dag_node tmp = container2dag (new_array, sz-1, sz-1, num_of_new_nodes); + Dag_node tmp = container2dag(new_array, sz-1, sz-1, num_of_new_nodes); deactivate_trapezoid( *last_tr_node, &tmp); //last_tr->remove(&tmp); m_number_of_dag_nodes += 1; //new node (tmp) was added @@ -1968,7 +1824,7 @@ void Trapezoidal_decomposition_2 // get the iterator (btm_it or top_it) that holds the trapezoid that was // not removed in the last iteration In_face_iterator& it = !prev_inc_btm ? btm_it : top_it; - Td_active_trapezoid& tr (it.trp()); + Td_active_trapezoid& tr(it.trp()); // remove the last trapezoid to remove and set the last new trapezoid // created as its replacement. update the relevant data Td_map_item rb = tr.rb(); @@ -1988,24 +1844,27 @@ void Trapezoidal_decomposition_2 const Dag_node* real = &tr.dag_node()->left_child(); boost::apply_visitor(set_dag_node_visitor((Dag_node*)real),real->get_data()); //(*real)->set_dag_node((Dag_node*)real); - if (!traits->is_empty_item(rb)) - { - boost::apply_visitor(set_rb_visitor(rb),last_new_tr_item); //last_new_tr->set_rb(rb); - boost::apply_visitor(set_lb_visitor(last_new_tr_item),rb); //rb->set_lb(last_new_tr); + if (!traits->is_empty_item(rb)) { + boost::apply_visitor(set_rb_visitor(rb),last_new_tr_item); + //last_new_tr->set_rb(rb); + boost::apply_visitor(set_lb_visitor(last_new_tr_item),rb); + //rb->set_lb(last_new_tr); } - if (!traits->is_empty_item(rt)) - { - boost::apply_visitor(set_rt_visitor(rt),last_new_tr_item); //last_new_tr->set_rt(rt); - boost::apply_visitor(set_lt_visitor(last_new_tr_item),rt); //rt->set_lt(last_new_tr); + if (!traits->is_empty_item(rt)) { + boost::apply_visitor(set_rt_visitor(rt),last_new_tr_item); + //last_new_tr->set_rt(rt); + boost::apply_visitor(set_lt_visitor(last_new_tr_item),rt); + //rt->set_lt(last_new_tr); } //----------------------------------- //3. remove the trapezoids that represent the removed halfedge - boost::shared_ptr removed_cv_ptr (new X_monotone_curve_2(he->curve())); - Base_map_item_iterator last_edge_fragment_it = mid_it;//Base_trapezoid_iterator last_mid = mid_it; + boost::shared_ptr + removed_cv_ptr(new X_monotone_curve_2(he->curve())); + Base_map_item_iterator last_edge_fragment_it = mid_it; + //Base_trapezoid_iterator last_mid = mid_it; Dag_node* e_node = NULL; - while(!!++mid_it) - { + while (!!++mid_it) { e_node = boost::apply_visitor(dag_node_visitor(),*last_edge_fragment_it); deactivate_edge(removed_cv_ptr,*e_node); //last_mid->remove(); last_edge_fragment_it = mid_it; @@ -2022,27 +1881,26 @@ void Trapezoidal_decomposition_2 //5. if the halfedge vertices are now isolated, undo the split trapezoid // by point(vtx) operation if (is_last_edge(he ,p1_item)) - undo_split_trapezoid_by_vertex (p1_node, leftmost); + undo_split_trapezoid_by_vertex(p1_node, leftmost); if (is_last_edge(he ,p2_item)) - undo_split_trapezoid_by_vertex (p2_node, rightmost); + undo_split_trapezoid_by_vertex(p2_node, rightmost); //----------------------------------- //6. reevaluating number of curves m_number_of_curves--; } - //----------------------------------------------------------------------------- // Description: // // preconditions: // p is not on an edge or a vertex. -template +template typename Trapezoidal_decomposition_2::Td_map_item& -Trapezoidal_decomposition_2 -::vertical_ray_shoot(const Point & p,Locate_type & lt, - const bool up_direction /*=true*/) const +Trapezoidal_decomposition_2:: +vertical_ray_shoot(const Point & p,Locate_type & lt, + const bool up_direction /*=true*/) const { #ifdef CGAL_TD_DEBUG CGAL_assertion(traits); @@ -2055,14 +1913,12 @@ Trapezoidal_decomposition_2 Dag_node curr = *m_dag_root; - lt = search_using_dag(curr, traits, p, m_empty_he_handle , - up_direction ? - CGAL::LARGER : CGAL::SMALLER); + lt = search_using_dag(curr, traits, p, m_empty_he_handle, up_direction ? + CGAL::LARGER : CGAL::SMALLER); Td_map_item& item(curr.get_data()); - if (traits->is_td_trapezoid(item)) - { + if (traits->is_td_trapezoid(item)) { CGAL_assertion(traits->is_active(item)); /* using exact traits, it may happen that p is on the right side of the trapezoid directly under its @@ -2076,30 +1932,30 @@ Trapezoidal_decomposition_2 p x------x */ - Td_active_trapezoid& tr (boost::get(item)); + Td_active_trapezoid& tr(boost::get(item)); if ((up_direction && !tr.is_on_right_boundary() && - (traits->compare_curve_end_x_2_object() + (traits->compare_curve_end_x_2_object() (p,traits->vtx_to_ce(tr.right())) == EQUAL) && - (tr.is_on_left_boundary() || + (tr.is_on_left_boundary() || !traits->equal_curve_end_2_object()(traits->vtx_to_ce(tr.left()), traits->vtx_to_ce(tr.right())))) || (!up_direction && !tr.is_on_left_boundary() && - (traits->compare_curve_end_x_2_object() + (traits->compare_curve_end_x_2_object() (p,traits->vtx_to_ce(tr.left())) == EQUAL) && - (tr.is_on_right_boundary() || + (tr.is_on_right_boundary() || !traits->equal_curve_end_2_object()(traits->vtx_to_ce(tr.left()), traits->vtx_to_ce(tr.right()))))) { // recalculate vertical ray shoot using locate on point return up_direction ? - locate(traits->vtx_to_ce(tr.right()),lt) : locate(traits->vtx_to_ce(tr.left()),lt); + locate(traits->vtx_to_ce(tr.right()),lt) : + locate(traits->vtx_to_ce(tr.left()),lt); } if (up_direction ? tr.is_on_top_boundary() : tr.is_on_bottom_boundary()) lt = UNBOUNDED_TRAPEZOID; - else - lt = TRAPEZOID; + else lt = TRAPEZOID; } return item; @@ -2109,7 +1965,7 @@ Trapezoidal_decomposition_2 //----------------------------------------------------------------------------- //// Description: //// -//template +//template //void Trapezoidal_decomposition_2 //::before_split_edge(const X_monotone_curve_2& cv, // const X_monotone_curve_2& cv1, @@ -2281,7 +2137,7 @@ Trapezoidal_decomposition_2 //MICHAL: commented due to inefficient depth update, remove and insert instead -//template +//template //void Trapezoidal_decomposition_2 //::split_edge(const X_monotone_curve_2& cv,Halfedge_const_handle he1, // Halfedge_const_handle he2) @@ -2685,11 +2541,11 @@ Trapezoidal_decomposition_2 //----------------------------------------------------------------------------- // Description: // -template -void Trapezoidal_decomposition_2 -::merge_edge (Halfedge_const_handle he1, - Halfedge_const_handle he2, - const X_monotone_curve_2& cv) +template +void Trapezoidal_decomposition_2:: +merge_edge(Halfedge_const_handle he1, + Halfedge_const_handle he2, + const X_monotone_curve_2& cv) { //make sure the halfedge is valid CGAL_precondition_code(Halfedge_const_handle invalid_he); @@ -2704,25 +2560,20 @@ void Trapezoidal_decomposition_2 write(std::cout,*m_dag_root,*traits) << std::endl; #endif - if (m_with_guarantees) - update(); + if (m_with_guarantees) update(); #ifndef CGAL_NO_TRAPEZOIDAL_DECOMPOSITION_2_OPTIMIZATION - locate_opt_empty(); - #endif const X_monotone_curve_2& cv1 = he1->curve(); const X_monotone_curve_2& cv2 = he2->curve(); - if (!traits) - { + if (!traits) { CGAL_warning(traits != NULL); return; } - if (!traits->are_mergeable_2_object() (cv1, cv2)) - { + if (!traits->are_mergeable_2_object() (cv1, cv2)) { CGAL_warning(traits->are_mergeable_2_object() (cv1, cv2)); return; } @@ -2730,58 +2581,52 @@ void Trapezoidal_decomposition_2 // Calculate the common/merged point (Curve_end) of cv1 and cv2. // There should be one! Curve_end ce = traits->equal_curve_end_2_object() - (Curve_end(cv1,ARR_MAX_END),Curve_end(cv2,ARR_MIN_END)) ? - Curve_end(cv1,ARR_MAX_END) : + (Curve_end(cv1,ARR_MAX_END), Curve_end(cv2, ARR_MIN_END)) ? + Curve_end(cv1, ARR_MAX_END) : // [-- cv1 -->] p [-- cv2 -->] or [<-- cv2 --] p [<-- cv1 --] - traits->equal_curve_end_2_object() - (Curve_end(cv1,ARR_MIN_END),Curve_end(cv2,ARR_MAX_END)) ? + traits->equal_curve_end_2_object() + (Curve_end(cv1, ARR_MIN_END), Curve_end(cv2, ARR_MAX_END)) ? // [<-- cv1 --] p [<-- cv2 --] or [-- cv2 -->] p [-- cv1 -->] - Curve_end(cv1,ARR_MIN_END) : // - traits->equal_curve_end_2_object() - (Curve_end(cv1,ARR_MIN_END),Curve_end(cv2,ARR_MIN_END)) ? + Curve_end(cv1, ARR_MIN_END) : // + traits->equal_curve_end_2_object() + (Curve_end(cv1, ARR_MIN_END), Curve_end(cv2, ARR_MIN_END)) ? // [<-- cv1 --] p [-- cv2 -->] - Curve_end(cv1,ARR_MIN_END) : + Curve_end(cv1, ARR_MIN_END) : // [-- cv1 -->] p [<-- cv2 --] - Curve_end(cv1,ARR_MAX_END); + Curve_end(cv1, ARR_MAX_END); //find the halfedge that will contain the merged curve // [<-- cv1 --] p [<-- cv2 --] or [<-- cv1 --] p [-- cv2 -->]-> he1->twin() // [-- cv1 -->] p [-- cv2 -->] or [-- cv1 -->] p [<-- cv2 --]-> he1 // Notice the curve cv is not yet updated Halfedge_const_handle merged_he = - (traits->equal_curve_end_2_object() - (Curve_end(cv1, ARR_MIN_END), Curve_end(cv2, ARR_MAX_END)) || - traits->equal_curve_end_2_object() - (Curve_end(cv1, ARR_MIN_END), Curve_end(cv2, ARR_MIN_END)) ) - ? he1->twin() : he1; + (traits->equal_curve_end_2_object()(Curve_end(cv1, ARR_MIN_END), + Curve_end(cv2, ARR_MAX_END)) || + traits->equal_curve_end_2_object()(Curve_end(cv1, ARR_MIN_END), + Curve_end(cv2, ARR_MIN_END))) ? + he1->twin() : he1; #ifdef CGAL_TD_DEBUG // ce is interior to the union curve - CGAL_precondition( - is_end_point_left_low (Curve_end(cv, ARR_MIN_END), ce)); - CGAL_precondition( - is_end_point_right_top (Curve_end(cv, ARR_MAX_END), ce)); - + CGAL_precondition(is_end_point_left_low(Curve_end(cv, ARR_MIN_END), ce)); + CGAL_precondition(is_end_point_right_top(Curve_end(cv, ARR_MAX_END), ce)); #endif //get the leftmost & rightmost Curve_end-s - Curve_end leftmost (cv, ARR_MIN_END); - Curve_end rightmost (cv, ARR_MAX_END); + Curve_end leftmost(cv, ARR_MIN_END); + Curve_end rightmost(cv, ARR_MAX_END); //locate the leftmost, rightmost and the merged point in the data structure Locate_type lt1,lt2,lt; - Td_map_item leftp_item = locate (leftmost, lt1); - Td_map_item rightp_item = locate (rightmost, lt2); - Td_map_item mrgp_item = locate (ce, lt); - + Td_map_item leftp_item = locate(leftmost, lt1); + Td_map_item rightp_item = locate(rightmost, lt2); + Td_map_item mrgp_item = locate(ce, lt); //varifying that all trapezoids are not NULL and are of type POINT - CGAL_warning (boost::apply_visitor(dag_node_visitor(),leftp_item) != NULL); - CGAL_warning (boost::apply_visitor(dag_node_visitor(),rightp_item)!= NULL); - CGAL_warning (boost::apply_visitor(dag_node_visitor(),mrgp_item) != NULL); - - + CGAL_warning(boost::apply_visitor(dag_node_visitor(), leftp_item) != NULL); + CGAL_warning(boost::apply_visitor(dag_node_visitor(), rightp_item)!= NULL); + CGAL_warning(boost::apply_visitor(dag_node_visitor(), mrgp_item) != NULL); //define the left curve and the right curve, according // to the common point (that is merged) @@ -2789,8 +2634,7 @@ void Trapezoidal_decomposition_2 const X_monotone_curve_2* p_right_cv = &cv1; Halfedge_const_handle left_he = he2; Halfedge_const_handle right_he = he1; - if (traits->equal_curve_end_2_object() (Curve_end (cv2, ARR_MIN_END), ce)) - { + if (traits->equal_curve_end_2_object()(Curve_end (cv2, ARR_MIN_END), ce)) { p_left_cv = &cv1; p_right_cv = &cv2; left_he = he1; @@ -2804,54 +2648,54 @@ void Trapezoidal_decomposition_2 //CGAL_assertion (traits->equal_curve_end_2_object() // (rightp_item.left(), rightmost)); - CGAL_assertion (is_end_point_left_low(leftmost, ce)); - CGAL_assertion (is_end_point_left_low(ce, rightmost)); + CGAL_assertion(is_end_point_left_low(leftmost, ce)); + CGAL_assertion(is_end_point_left_low(ce, rightmost)); //compare left cv min with leftmost - CGAL_assertion (traits->equal_curve_end_2_object() - (Curve_end(*p_left_cv, ARR_MIN_END), leftmost)); + CGAL_assertion(traits->equal_curve_end_2_object() + (Curve_end(*p_left_cv, ARR_MIN_END), leftmost)); //compare left cv max with ce - CGAL_assertion (traits->equal_curve_end_2_object() - (Curve_end(*p_left_cv, ARR_MAX_END), ce)); + CGAL_assertion(traits->equal_curve_end_2_object() + (Curve_end(*p_left_cv, ARR_MAX_END), ce)); //compare right cv min with ce - CGAL_assertion (traits->equal_curve_end_2_object() - (Curve_end(*p_right_cv, ARR_MIN_END), ce)); + CGAL_assertion(traits->equal_curve_end_2_object() + (Curve_end(*p_right_cv, ARR_MIN_END), ce)); //compare right cv max with rightmost - CGAL_assertion (traits->equal_curve_end_2_object() - (Curve_end(*p_right_cv, ARR_MAX_END), rightmost)); + CGAL_assertion(traits->equal_curve_end_2_object() + (Curve_end(*p_right_cv, ARR_MAX_END), rightmost)); #endif //get the nodes of leftmost point and merge point - Dag_node& leftp_node = *(boost::apply_visitor(dag_node_visitor(),leftp_item)); - Dag_node& mrgp_node = *(boost::apply_visitor(dag_node_visitor(),mrgp_item)); + Dag_node& leftp_node = *(boost::apply_visitor(dag_node_visitor(), leftp_item)); + Dag_node& mrgp_node = *(boost::apply_visitor(dag_node_visitor(), mrgp_item)); //set iterators for below left curve, on left curve & above left curve In_face_iterator - btm_left_it (follow_curve (leftp_node, *p_left_cv, SMALLER)), - mid_left_it (follow_curve (leftp_node, *p_left_cv, EQUAL)), - top_left_it (follow_curve (leftp_node, *p_left_cv, LARGER)); + btm_left_it(follow_curve(leftp_node, *p_left_cv, SMALLER)), + mid_left_it(follow_curve(leftp_node, *p_left_cv, EQUAL)), + top_left_it(follow_curve(leftp_node, *p_left_cv, LARGER)); //set iterators for below right curve, on right curve & above right curve In_face_iterator - btm_right_it (follow_curve (mrgp_node, *p_right_cv, SMALLER)), - mid_right_it (follow_curve (mrgp_node, *p_right_cv, EQUAL)), - top_right_it (follow_curve (mrgp_node, *p_right_cv, LARGER)); + btm_right_it(follow_curve(mrgp_node, *p_right_cv, SMALLER)), + mid_right_it(follow_curve(mrgp_node, *p_right_cv, EQUAL)), + top_right_it(follow_curve(mrgp_node, *p_right_cv, LARGER)); #ifdef CGAL_TD_DEBUG - CGAL_assertion (btm_left_it.operator->()); - CGAL_assertion (mid_left_it.operator->()); - CGAL_assertion (top_left_it.operator->()); - CGAL_assertion (btm_right_it.operator->()); - CGAL_assertion (mid_right_it.operator->()); - CGAL_assertion (top_right_it.operator->()); - CGAL_assertion (traits->is_active(*btm_left_it.operator->())); - CGAL_assertion (traits->is_active(*mid_left_it.operator->())); - CGAL_assertion (traits->is_active(*top_left_it.operator->())); - CGAL_assertion (traits->is_active(*btm_right_it.operator->())); - CGAL_assertion (traits->is_active(*mid_right_it.operator->())); - CGAL_assertion (traits->is_active(*top_right_it.operator->())); + CGAL_assertion(btm_left_it.operator->()); + CGAL_assertion(mid_left_it.operator->()); + CGAL_assertion(top_left_it.operator->()); + CGAL_assertion(btm_right_it.operator->()); + CGAL_assertion(mid_right_it.operator->()); + CGAL_assertion(top_right_it.operator->()); + CGAL_assertion(traits->is_active(*btm_left_it.operator->())); + CGAL_assertion(traits->is_active(*mid_left_it.operator->())); + CGAL_assertion(traits->is_active(*top_left_it.operator->())); + CGAL_assertion(traits->is_active(*btm_right_it.operator->())); + CGAL_assertion(traits->is_active(*mid_right_it.operator->())); + CGAL_assertion(traits->is_active(*top_right_it.operator->())); #endif @@ -2869,76 +2713,81 @@ void Trapezoidal_decomposition_2 Td_map_item dummy2 = Td_map_item(0); Vertex_const_handle leftmost_v = - (left_he->direction() == ARR_LEFT_TO_RIGHT) ? left_he->source() : - left_he->target(); + (left_he->direction() == ARR_LEFT_TO_RIGHT) ? + left_he->source() : left_he->target(); Vertex_const_handle rightmost_v = - (right_he->direction() == ARR_LEFT_TO_RIGHT) ? right_he->target() : - right_he->source(); + (right_he->direction() == ARR_LEFT_TO_RIGHT) ? + right_he->target() : right_he->source(); //replacing the given curve with a new Halfedge_handle along the trapezoids // starting at the iterator, until the end (last parameter) is reached. // updating the last param as the last updated trapzoid - update_map_items_after_merge (mid_left_it, left_he, merged_he, - leftmost_v, rightmost_v, on_cv_left); - update_map_items_after_merge (mid_right_it, right_he, merged_he, - leftmost_v, rightmost_v, right_cv_fraction_item); - update_map_items_after_merge (top_left_it, left_he, merged_he, - leftmost_v, rightmost_v, above_cv_left); - update_map_items_after_merge (top_right_it, right_he, merged_he, - leftmost_v, rightmost_v, dummy1); - update_map_items_after_merge (btm_left_it, left_he, merged_he, - leftmost_v, rightmost_v, below_cv_left); - update_map_items_after_merge (btm_right_it, right_he, merged_he, - leftmost_v, rightmost_v, dummy2); - + update_map_items_after_merge(mid_left_it, left_he, merged_he, + leftmost_v, rightmost_v, on_cv_left); + update_map_items_after_merge(mid_right_it, right_he, merged_he, + leftmost_v, rightmost_v, right_cv_fraction_item); + update_map_items_after_merge(top_left_it, left_he, merged_he, + leftmost_v, rightmost_v, above_cv_left); + update_map_items_after_merge(top_right_it, right_he, merged_he, + leftmost_v, rightmost_v, dummy1); + update_map_items_after_merge(btm_left_it, left_he, merged_he, + leftmost_v, rightmost_v, below_cv_left); + update_map_items_after_merge(btm_right_it, right_he, merged_he, + leftmost_v, rightmost_v, dummy2); // merge trapezoids that were split by the upward and downward // vertical extensions from ce (the merged point) // make sure only active trapezoids are merged - CGAL_assertion( traits->is_active(above_cv_left) && traits->is_active(above_cv_right) ); - CGAL_assertion( traits->is_active(below_cv_left) && traits->is_active(below_cv_right) ); + CGAL_assertion(traits->is_active(above_cv_left) && + traits->is_active(above_cv_right) ); + CGAL_assertion(traits->is_active(below_cv_left) && + traits->is_active(below_cv_right) ); - merge_if_possible (above_cv_left, above_cv_right); - merge_if_possible (below_cv_left, below_cv_right); + merge_if_possible(above_cv_left, above_cv_right); + merge_if_possible(below_cv_left, below_cv_right); // mark older trapezoids as inactive - nodes depth are updated here - Dag_node* above_cv_right_node (boost::apply_visitor(dag_node_visitor(),above_cv_right)); - Dag_node* above_cv_left_node (boost::apply_visitor(dag_node_visitor(),above_cv_left)); - deactivate_trapezoid( *above_cv_right_node, above_cv_left_node); //above_cv_right->remove(above_cv_left->dag_node()); - Dag_node* below_cv_right_node (boost::apply_visitor(dag_node_visitor(),below_cv_right)); - Dag_node* below_cv_left_node (boost::apply_visitor(dag_node_visitor(),below_cv_left)); - deactivate_trapezoid( *below_cv_right_node, below_cv_left_node); //below_cv_right->remove(below_cv_left->dag_node()); + Dag_node* above_cv_right_node(boost::apply_visitor(dag_node_visitor(), + above_cv_right)); + Dag_node* above_cv_left_node(boost::apply_visitor(dag_node_visitor(), + above_cv_left)); + deactivate_trapezoid( *above_cv_right_node, above_cv_left_node); + //above_cv_right->remove(above_cv_left->dag_node()); + Dag_node* below_cv_right_node(boost::apply_visitor(dag_node_visitor(), + below_cv_right)); + Dag_node* below_cv_left_node(boost::apply_visitor(dag_node_visitor(), + below_cv_left)); + deactivate_trapezoid( *below_cv_right_node, below_cv_left_node); + //below_cv_right->remove(below_cv_left->dag_node()); update_largest_leaf_depth((std::max)(above_cv_left_node->depth(), below_cv_left_node->depth())); //no need to update m_number_of_dag_nodes because the number of nodes did not change. #ifdef CGAL_TD_DEBUG - - CGAL_warning (!traits->is_empty_item(on_cv_left)); - CGAL_warning (!traits->is_empty_item(on_cv_right)); - + CGAL_warning(!traits->is_empty_item(on_cv_left)); + CGAL_warning(!traits->is_empty_item(on_cv_right)); #endif // make the merged point's representative inactive deactivate_vertex(mrgp_node); //mrgp_node->remove(); - CGAL_assertion(traits->is_td_edge(on_cv_left) && traits->is_active(on_cv_left)); + CGAL_assertion(traits->is_td_edge(on_cv_left) && + traits->is_active(on_cv_left)); - Td_active_edge& e_left (boost::get(on_cv_left)); + Td_active_edge& e_left(boost::get(on_cv_left)); e_left.set_next(on_cv_right); - CGAL_assertion(traits->is_td_edge(on_cv_right) && traits->is_active(on_cv_right)); + CGAL_assertion(traits->is_td_edge(on_cv_right) && + traits->is_active(on_cv_right)); //replacing the curve in the end points' trapezoids themselves (updating top/ bottom) - update_vtx_cw_he_after_merge (*p_left_cv, merged_he, leftp_item); - update_vtx_cw_he_after_merge (*p_right_cv, merged_he, rightp_item); //MICHAL: maybe I should pass the he1 & he2? + update_vtx_cw_he_after_merge(*p_left_cv, merged_he, leftp_item); + update_vtx_cw_he_after_merge(*p_right_cv, merged_he, rightp_item); //MICHAL: maybe I should pass the he1 & he2? #ifdef CGAL_TD_DEBUG - CGAL_warning(!traits->is_empty_item(left_cv_fraction_item)); CGAL_warning(!traits->is_empty_item(right_cv_fraction_item)); - #endif // reevaluating number of curves @@ -2949,67 +2798,57 @@ void Trapezoidal_decomposition_2 << is_valid(*m_dag_root) << std::endl; write(std::cout,*m_dag_root,*traits) << std::endl; #endif - } - //----------------------------------------------------------------------------- // Description: // -template +template unsigned long -Trapezoidal_decomposition_2 -::longest_query_path_length_rec(bool minus_inf, Dag_node& min_node, - bool plus_inf, Dag_node& max_node, - Dag_node& node) +Trapezoidal_decomposition_2:: +longest_query_path_length_rec(bool minus_inf, Dag_node& min_node, + bool plus_inf, Dag_node& max_node, + Dag_node& node) { //if NULL - if (node.is_null()) - return 0; + if (node.is_null()) return 0; //if not valid range or empty return 0 - if (!minus_inf && !plus_inf) - { + if (!minus_inf && !plus_inf) { Td_map_item min_node_item(min_node.get_data()); - if (traits->is_fictitious_vertex(min_node_item)) - { + if (traits->is_fictitious_vertex(min_node_item)) { const Curve_end min_ce(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),min_node_item))); Td_map_item max_node_item(max_node.get_data()); - if (traits->is_fictitious_vertex(max_node_item)) - { + if (traits->is_fictitious_vertex(max_node_item)) { const Curve_end max_ce(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),max_node_item))); //min-fict, max-fict - if (!is_end_point_left_low(min_ce, max_ce)) - return 0; + if (!is_end_point_left_low(min_ce, max_ce)) return 0; } - else - { - const Point& max_p(boost::apply_visitor(point_for_vertex_visitor(),max_node_item)); + else { + const Point& max_p(boost::apply_visitor(point_for_vertex_visitor(), + max_node_item)); //min-fict, max-pt //if smaller than the point represented by min_node - if (!is_end_point_left_low(min_ce, max_p)) - return 0; + if (!is_end_point_left_low(min_ce, max_p)) return 0; } } - else - { - const Point& min_p(boost::apply_visitor(point_for_vertex_visitor(),min_node_item)); + else { + const Point& min_p(boost::apply_visitor(point_for_vertex_visitor(), + min_node_item)); Td_map_item max_node_item(max_node.get_data()); - if (traits->is_fictitious_vertex(max_node_item)) - { + if (traits->is_fictitious_vertex(max_node_item)) { const Curve_end max_ce(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),max_node_item))); //min-pt, max-fict - if (!is_end_point_left_low(min_p, max_ce)) - return 0; + if (!is_end_point_left_low(min_p, max_ce)) return 0; } - else - { - const Point& max_p(boost::apply_visitor(point_for_vertex_visitor(),max_node_item)); + else { + const Point& max_p(boost::apply_visitor(point_for_vertex_visitor(), + max_node_item)); //min-pt, max-pt //if smaller than the point represented by min_node @@ -3019,20 +2858,18 @@ Trapezoidal_decomposition_2 } } - //if node represents a trapezoid - if (traits->is_td_trapezoid(node.get_data()) ) - return 1; + if (traits->is_td_trapezoid(node.get_data())) return 1; //if node represents a curve - if (!traits->is_td_vertex(node.get_data()) ) + if (!traits->is_td_vertex(node.get_data())) return (1 + (std::max)( - longest_query_path_length_rec(minus_inf, min_node, - plus_inf, max_node, - node.left_child()) , - longest_query_path_length_rec(minus_inf, min_node, - plus_inf, max_node, - node.right_child()) )); + longest_query_path_length_rec(minus_inf, min_node, + plus_inf, max_node, + node.left_child()) , + longest_query_path_length_rec(minus_inf, min_node, + plus_inf, max_node, + node.right_child()))); //if node represents a vertex Td_map_item curr_item(node.get_data()); @@ -3040,28 +2877,23 @@ Trapezoidal_decomposition_2 //if node is smaller than min, use min in the next recursion min bound, otherwise use node Dag_node new_min_node = node; - if (!minus_inf) - { + if (!minus_inf) { Td_map_item min_node_item(min_node.get_data()); - if (traits->is_fictitious_vertex(min_node_item)) - { + if (traits->is_fictitious_vertex(min_node_item)) { const Curve_end min_ce(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),min_node_item))); //if smaller than the point represented by min_node //if ((is_fict_vtx && is_end_point_left_low(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), min_ce)) || // (!is_fict_vtx && is_end_point_left_low(boost::apply_visitor(point_for_vertex_visitor(), curr_item), min_ce) )) - if (is_end_point_right_top(min_ce, node)) - { + if (is_end_point_right_top(min_ce, node)) { new_min_node = min_node; } } - else - { + else { const Point& min_p(boost::apply_visitor(point_for_vertex_visitor(),min_node_item)); //if smaller than the point represented by min_node //if ((is_fict_vtx && is_end_point_left_low(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), min_p)) || // (!is_fict_vtx && is_end_point_left_low(boost::apply_visitor(point_for_vertex_visitor(), curr_item), min_p) )) - if (is_end_point_right_top(min_p, node)) - { + if (is_end_point_right_top(min_p, node)) { new_min_node = min_node; } } @@ -3069,11 +2901,9 @@ Trapezoidal_decomposition_2 //if node is larger than max, use max in the next recursion max bound, otherwise use node Dag_node new_max_node = node; - if (!plus_inf) - { + if (!plus_inf) { Td_map_item max_node_item(max_node.get_data()); - if (traits->is_fictitious_vertex(max_node_item)) - { + if (traits->is_fictitious_vertex(max_node_item)) { const Curve_end max_ce(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),max_node_item))); //if larger than the point represented by max_node //if ((is_fict_vtx && is_end_point_right_top(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), max_ce)) || @@ -3083,31 +2913,26 @@ Trapezoidal_decomposition_2 new_max_node = max_node; } } - else - { - const Point& max_p(boost::apply_visitor(point_for_vertex_visitor(),max_node_item)); + else { + const Point& max_p(boost::apply_visitor(point_for_vertex_visitor(), + max_node_item)); //if smaller than the point represented by min_node //if ((is_fict_vtx && is_end_point_right_top(*(boost::apply_visitor(curve_end_for_fict_vertex_visitor(),curr_item)), max_p)) || // (!is_fict_vtx && is_end_point_right_top(boost::apply_visitor(point_for_vertex_visitor(), curr_item), max_p) )) - if (is_end_point_left_low(max_p, node)) - { + if (is_end_point_left_low(max_p, node)) { new_max_node = max_node; } } } //o/w continue with updated parameters - return (1 + (std::max)( - longest_query_path_length_rec(minus_inf, min_node, - false, new_max_node, - node.left_child()) , - longest_query_path_length_rec(false, new_min_node, - plus_inf, max_node, - node.right_child()) )); - + return (1 + (std::max)(longest_query_path_length_rec(minus_inf, min_node, + false, new_max_node, + node.left_child()) , + longest_query_path_length_rec(false, new_min_node, + plus_inf, max_node, + node.right_child()))); } - - } //namespace CGAL #endif From cfef8106d4820e1377b7a95951c25019b6968bf5 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Wed, 16 May 2018 11:05:08 +0300 Subject: [PATCH 09/18] Fixed allocation and deallocation --- .../Point_location_test.h | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h index 9a7b539daee..40f14620a61 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h @@ -257,12 +257,11 @@ private: //! Allocate point location. template - bool allocate_pl() + void allocate_pl() { auto* locator = new Strategy(); - if (! locator) return false; + CGAL_assertion(locator); m_locators[id].m_variant = locator; - return true; } //! Construct point location. @@ -712,9 +711,9 @@ void Point_location_test::clear() template void Point_location_test::deallocate_pl_strategies() { - ALLOCATE_PL_NATIVE(); - ALLOCATE_PL_SIMPLE(); - ALLOCATE_PL_WALK(); + DEALLOCATE_PL_NATIVE(); + DEALLOCATE_PL_SIMPLE(); + DEALLOCATE_PL_WALK(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) @@ -778,28 +777,28 @@ template bool Point_location_test::allocate_pl_strategies() { // Allocate all point location strategies. - if (! ALLOCATE_PL_NATIVE()) return false; - if (! ALLOCATE_PL_SIMPLE()) return false; - if (! ALLOCATE_PL_WALK()) return false; + ALLOCATE_PL_NATIVE(); + ALLOCATE_PL_SIMPLE(); + ALLOCATE_PL_WALK(); #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - if (! ALLOCATE_PL_LM()) return false; - if (! ALLOCATE_PL_LM_RANDOM()) return false; - if (! ALLOCATE_PL_LM_GRID()) return false; - if (! ALLOCATE_PL_LM_HALTON()) return false; - if (! ALLOCATE_PL_LM_MIDDLE_EDGES()) return false; - if (! ALLOCATE_PL_LM_SPECIFIED_POINTS()) return false; + ALLOCATE_PL_LM(); + ALLOCATE_PL_LM_RANDOM(); + ALLOCATE_PL_LM_GRID(); + ALLOCATE_PL_LM_HALTON(); + ALLOCATE_PL_LM_MIDDLE_EDGES(); + ALLOCATE_PL_LM_SPECIFIED_POINTS(); #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - if (! ALLOCATE_PL_TRIANGULATION_PL()) return false; + ALLOCATE_PL_TRIANGULATION_PL(); #endif - if (! ALLOCATE_PL_TRAPEZOID_RIC_PL()) return false; - if (! ALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE()) return false; + ALLOCATE_PL_TRAPEZOID_RIC_PL(); + ALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE(); return true; } From d5a26a0bc0799b577a2774b4a1b4fb8cd8816636 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Wed, 16 May 2018 11:21:07 +0300 Subject: [PATCH 10/18] Cleaned up; stage 2 --- .../Trapezoidal_decomposition_2_impl.h | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h index fd1593b3b49..ae7b7ac627d 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h @@ -1456,17 +1456,14 @@ Trapezoidal_decomposition_2::insert(Halfedge_const_handle he) // make sure that the two endpoints are not the same point CGAL_precondition(!traits->equal_curve_end_2_object()(ce1, ce2)); - Locate_type lt1, lt2; - - //should hold the trapezoids in which the edge endpoints should be located + Locate_type lt1; Td_map_item item1; - Td_map_item item2; #ifndef CGAL_NO_TRAPEZOIDAL_DECOMPOSITION_2_OPTIMIZATION - locate_optimization(ce1,item1,lt1); + locate_optimization(ce1, item1, lt1); #else //location of the left endpoint of the edge we're inserting - item1 = locate(ce1,lt1); + item1 = locate(ce1, lt1); #endif //the inserted edge should not cut any existing edge @@ -1482,27 +1479,30 @@ Trapezoidal_decomposition_2::insert(Halfedge_const_handle he) // the new vertex. In this case, the the edge itself is the only incident // edge, and so it is a trivial operation. Td_map_item p1_item = (lt1 == POINT) ? - update_vtx_with_new_edge(he,ce1,item1,lt1) : - insert_curve_at_vtx_using_dag(he,v1,item1,lt1); + update_vtx_with_new_edge(he, ce1, item1, lt1) : + insert_curve_at_vtx_using_dag(he, v1, item1, lt1); + + Locate_type lt2; + Td_map_item item2; #ifndef CGAL_NO_TRAPEZOIDAL_DECOMPOSITION_2_OPTIMIZATION - locate_optimization(ce2,item2,lt2); + locate_optimization(ce2, item2, lt2); locate_opt_empty(); #else // TODO(oren): locating the second endpoint. this is not necessary, // and time consuming. - item2 = locate(ce2,lt2); + item2 = locate(ce2, lt2); #endif if (lt2 == CURVE) { - CGAL_precondition_msg(lt2!=CURVE,"Input is not planar as\ + CGAL_precondition_msg(lt2 != CURVE, "Input is not planar as\ one of the input point inside previously inserted Halfedge."); return Td_map_item(0); } Td_map_item p2_item = (lt2 == POINT) ? - update_vtx_with_new_edge(he,ce2,item2,lt2) : - insert_curve_at_vtx_using_dag(he,v2,item2,lt2); + update_vtx_with_new_edge(he,ce2, item2, lt2) : + insert_curve_at_vtx_using_dag(he, v2, item2, lt2); // locate and insert end points of the input halfedge to the Td_map_item // Dag if needed @@ -1535,8 +1535,7 @@ Trapezoidal_decomposition_2::insert(Halfedge_const_handle he) it++; //this is the logic of the iterator. // the iterator goes to the next trapezoid right-high. node = (*curr_trp).dag_node(); - if(first_time) - { + if (first_time) { Halfedge_const_handle top_he((*curr_trp).top()); if((top_he == he) || (top_he == he->twin())) { CGAL_warning((top_he != he) && (top_he != he->twin())); @@ -1555,8 +1554,7 @@ Trapezoidal_decomposition_2::insert(Halfedge_const_handle he) Td_map_item new_btm_item = node->left_child().get_data(); CGAL_assertion(traits->is_td_trapezoid(new_btm_item) && traits->is_active(new_btm_item)); - if(merge_if_possible(prev_bottom_tr, new_btm_item)) - { + if (merge_if_possible(prev_bottom_tr, new_btm_item)) { Dag_node* left_child_node = boost::apply_visitor(dag_node_visitor(),prev_bottom_tr); node->set_left_child(*left_child_node); @@ -1570,8 +1568,7 @@ Trapezoidal_decomposition_2::insert(Halfedge_const_handle he) Td_map_item new_top_item = node->right_child().get_data(); CGAL_assertion(traits->is_td_trapezoid(new_top_item) && traits->is_active(new_top_item)); - if(merge_if_possible(prev_top_tr, new_top_item)) - { + if (merge_if_possible(prev_top_tr, new_top_item)) { Dag_node* right_child_node = boost::apply_visitor(dag_node_visitor(), prev_top_tr); node->set_right_child(*right_child_node); @@ -1598,7 +1595,6 @@ Trapezoidal_decomposition_2::insert(Halfedge_const_handle he) break; } - } m_number_of_curves++; From 06d2fc762a653dce8441f2d9ec127aa880157efd Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Wed, 16 May 2018 17:48:15 +0300 Subject: [PATCH 11/18] Introduced member function reset_cw_he() --- .../Td_active_fictitious_vertex.h | 256 +++++++---------- .../Arr_point_location/Td_active_vertex.h | 257 +++++++----------- 2 files changed, 200 insertions(+), 313 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_fictitious_vertex.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_fictitious_vertex.h index 42abf124819..457d955a7d8 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_fictitious_vertex.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_fictitious_vertex.h @@ -16,15 +16,15 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0+ // -// Author(s) : Oren Nechushtan -// updated by: Michal Balas +// Author(s): Oren Nechushtan +// Michal Balas +// Efi Fogel #ifndef CGAL_TD_ACTIVE_FICTITIOUS_VERTEX_H #define CGAL_TD_ACTIVE_FICTITIOUS_VERTEX_H #include - /*! \file * Defintion of the Td_active_fictitious_vertex class. */ @@ -33,7 +33,6 @@ #include #include - #ifdef CGAL_TD_DEBUG #define CGAL_TD_INLINE #else @@ -46,63 +45,61 @@ namespace CGAL { * Implementation of a pseudo-trapezoid as two halfedges(top,bottom) * and two curve-ends(left,right). * Trapezoids are represented as two curve-ends called right and left and - * two halfedges called top and bottom. The curve-ends (points) lie on the - * right and left boundaries of the trapezoid respectively and the halfedges + * two halfedges called top and bottom. The curve-ends (points) lie on the + * right and left boundaries of the trapezoid respectively and the halfedges * bound the trapezoid from above and below. - * There exist degenerate trapezoids called infinite trapezoid; this happens + * There exist degenerate trapezoids called infinite trapezoid; this happens * when one of the four sides is on the parameter space boundary. * Trapezoids are created as active and become inactive when Remove() member * function called. * Each trapezoid has at most four neighbouring trapezoids. - * X_trapezoid structure can represent a real trapezoid, a Td-edge or an + * X_trapezoid structure can represent a real trapezoid, a Td-edge or an * edge-end (end point). */ -template -class Td_active_fictitious_vertex : public Handle -{ +template +class Td_active_fictitious_vertex : public Handle { public: - + //type of traits class - typedef Td_traits_ Traits; - + typedef Td_traits_ Traits; + //type of point (Point_2) - typedef typename Traits::Point Point; + typedef typename Traits::Point Point; //type of X_monotone_curve_2 - typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2; + typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2; //type of Curve_end - typedef typename Traits::Curve_end Curve_end; - + typedef typename Traits::Curve_end Curve_end; + //type of Halfedge_const_handle (trapezoid edge) - typedef typename Traits::Halfedge_const_handle Halfedge_const_handle; - + typedef typename Traits::Halfedge_const_handle Halfedge_const_handle; + //type of Vertex_const_handle (trapezoid vertex) - typedef typename Traits::Vertex_const_handle Vertex_const_handle; + typedef typename Traits::Vertex_const_handle Vertex_const_handle; //type of Halfedge_around_vertex_const_circulator - typedef typename Traits::Halfedge_around_vertex_const_circulator + typedef typename Traits::Halfedge_around_vertex_const_circulator Halfedge_around_vertex_const_circulator; //type of Td_active_fictitious_vertex (Self) - typedef typename Traits::Td_active_fictitious_vertex Self; - - typedef typename Traits::Td_map_item Td_map_item; + typedef typename Traits::Td_active_fictitious_vertex Self; + + typedef typename Traits::Td_map_item Td_map_item; //type of Trapezoidal decomposition - typedef Trapezoidal_decomposition_2 TD; - + typedef Trapezoidal_decomposition_2 TD; + //type of In face iterator - typedef typename TD::In_face_iterator In_face_iterator; + typedef typename TD::In_face_iterator In_face_iterator; //type of Trapezoidal map search structure - typedef typename TD::Dag_node Dag_node; - + typedef typename TD::Dag_node Dag_node; //friend class declarations: friend class Trapezoidal_decomposition_2; - + #ifdef CGAL_PM_FRIEND_CLASS #if defined(__SUNPRO_CC) || defined(__PGI) || defined(__INTEL_COMPILER) friend class Trapezoidal_decomposition_2::In_face_iterator; @@ -113,199 +110,146 @@ public: #else friend class Trapezoidal_decomposition_2::In_face_iterator; #endif - + #else friend class In_face_iterator; #endif #endif - + /*! \class - * Inner class Data derived from Rep class - */ - class Data : public Rep - { + * Inner class Data derived from Rep class + */ + class Data : public Rep { friend class Td_active_fictitious_vertex; public: //c'tors - Data (Vertex_const_handle _v, - Halfedge_const_handle _cw_he, - Dag_node* _p_node) - : v(_v),cw_he(_cw_he),p_node(_p_node) - { } - - ~Data() { } + Data(Vertex_const_handle _v, Halfedge_const_handle _cw_he, + Dag_node* _p_node) : + v(_v), cw_he(_cw_he), p_node(_p_node) + {} + + ~Data() {} protected: - Vertex_const_handle v; + Vertex_const_handle v; Halfedge_const_handle cw_he; //holds the first edge going cw starting at 12 o'clock Dag_node* p_node; }; - - private: - - Data* ptr() const { return (Data*)(PTR); } - + +private: + Data* ptr() const { return (Data*)(PTR); } + Curve_end vtx_to_ce(Vertex_const_handle v) const { //the circulator is of incoming halfedges - Halfedge_around_vertex_const_circulator he = v->incident_halfedges(); + Halfedge_around_vertex_const_circulator he = v->incident_halfedges(); //if the vertex is associated with a point on the bounded coords, // we can take any incident halfedge. o/w if the vertex lies at infinity, // it has 2 fictitious incident halfedges if (v->is_at_open_boundary() && he->source()->is_at_open_boundary()) ++he; if (v->is_at_open_boundary() && he->source()->is_at_open_boundary()) ++he; - return Curve_end(he->curve(), - (he->direction() == ARR_RIGHT_TO_LEFT)? - ARR_MIN_END : ARR_MAX_END); + return Curve_end(he->curve(), ((he->direction() == ARR_RIGHT_TO_LEFT) ? + ARR_MIN_END : ARR_MAX_END)); } - + #ifndef CGAL_TD_DEBUG #ifdef CGAL_PM_FRIEND_CLASS - protected: +protected: #else - public: // workaround +public: // workaround #endif #else //CGAL_TD_DEBUG - public: +public: #endif //CGAL_TD_DEBUG - /*! Set the DAG node. */ - inline void set_dag_node(Dag_node* p) - { - ptr()->p_node = p; - } - + inline void set_dag_node(Dag_node* p) { ptr()->p_node = p; } + /*! Set the vertex handle (Vertex_const_handle). */ - inline void set_vertex(Vertex_const_handle v) + inline void set_vertex(Vertex_const_handle v) { ptr()->v = v; } + + /*! Set the first he going clockwise starting at 12 o'clock. + */ + inline void set_cw_he(Halfedge_const_handle he) { - ptr()->v = v; - } - - /*! Set the first he going clockwise starting at 12 o'clock (Halfedge_const_handle). */ - inline void set_cw_he(Halfedge_const_handle he) - { - if (cw_he() != Traits::empty_he_handle() && - cw_he()->direction() != he->direction()) - { - ptr()->cw_he = he->twin(); - } - else - { - ptr()->cw_he = he; - } + ptr()->cw_he = ((cw_he() != Traits::empty_he_handle()) && + (cw_he()->direction() != he->direction())) ? + he->twin() : he; } - - public: - + /*! Reset the first he going clockwise starting at 12 o'clock. + */ + inline void reset_cw_he() { ptr()->cw_he = Traits::empty_he_handle(); } + +public: /// \name Constructors. //@{ - Td_active_fictitious_vertex () + Td_active_fictitious_vertex() { - PTR = new Data - (Traits::empty_vtx_handle(), Traits::empty_he_handle(), NULL); + PTR = new Data(Traits::empty_vtx_handle(), Traits::empty_he_handle(), NULL); } - + /*! Constructor given Vertex & Halfedge handles. */ - Td_active_fictitious_vertex (Vertex_const_handle v, - Halfedge_const_handle cw_he, - Dag_node* node = 0) - - - { - PTR = new Data(v, cw_he, node); - } - - + Td_active_fictitious_vertex(Vertex_const_handle v, + Halfedge_const_handle cw_he, + Dag_node* node = 0) + { PTR = new Data(v, cw_he, node); } + + /*! Copy constructor. */ - Td_active_fictitious_vertex (const Self& tr) : Handle(tr) - { - } - + Td_active_fictitious_vertex (const Self& tr) : Handle(tr) {} + //@} - + /// \name Operator overloading. //@{ - /*! Assignment operator. - * operator= should not copy m_dag_node (or otherwise update + /*! Assignment operator. + * operator= should not copy m_dag_node (or otherwise update * Dag_node::replace) */ - inline Self& operator= (const Self& t2) + inline Self& operator=(const Self& t2) { - Handle::operator=(t2); - return *this; + Handle::operator=(t2); + return *this; } /*! Operator==. */ - inline bool operator== (const Self& t2) const - { - return (ptr() == t2.ptr()); - } + inline bool operator==(const Self& t2) const { return (ptr() == t2.ptr()); } /*! Operator!=. */ - inline bool operator!= (const Self& t2) const - { - return !(operator==(t2)); - } + inline bool operator!=(const Self& t2) const { return !(operator==(t2)); } //@} - /// \name Access methods. //@{ - inline Self& self() - { - return *this; - } - - inline const Self& self() const - { - return *this; - } + inline Self& self() { return *this; } + + inline const Self& self() const { return *this; } /*! Access the trapezoid id (PTR). */ - inline unsigned long id() const - { - return (unsigned long) PTR; - } + inline unsigned long id() const { return (unsigned long) PTR; } - /*! Access trapezoid left. - * filters out the infinite case which returns predefined dummy values - */ - inline Vertex_const_handle vertex() const - { - return ptr()->v; - } + /*! Access trapezoid left. + * filters out the infinite case which returns predefined dummy values + */ + inline Vertex_const_handle vertex() const { return ptr()->v; } - Curve_end curve_end() const - { - return vtx_to_ce(vertex()); - } + Curve_end curve_end() const { return vtx_to_ce(vertex()); } + + /*! Access the first he starting at 12 o'clock clockwise. + */ + inline Halfedge_const_handle cw_he() const { return ptr()->cw_he; } - /*! Access the first he starting at 12 o'clock clockwise. - */ - inline Halfedge_const_handle cw_he () const - { - return ptr()->cw_he; - } - - /*! Access DAG node. */ - Dag_node* dag_node() const {return ptr()->p_node; } //m_dag_node;} - - + Dag_node* dag_node() const { return ptr()->p_node; } //m_dag_node;} + //@} - - - - - }; } //namespace CGAL diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_vertex.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_vertex.h index 73d86b494e3..d912cf09daa 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_vertex.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_vertex.h @@ -16,15 +16,15 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0+ // -// Author(s) : Oren Nechushtan -// updated by: Michal Balas +// Author(s): Oren Nechushtan +// Michal Balas +// Efi Fogel #ifndef CGAL_TD_ACTIVE_VERTEX_H #define CGAL_TD_ACTIVE_VERTEX_H #include - /*! \file * Defintion of the Td_active_vertex class. */ @@ -46,63 +46,62 @@ namespace CGAL { * Implementation of a pseudo-trapezoid as two halfedges(top,bottom) * and two curve-ends(left,right). * Trapezoids are represented as two curve-ends called right and left and - * two halfedges called top and bottom. The curve-ends (points) lie on the - * right and left boundaries of the trapezoid respectively and the halfedges + * two halfedges called top and bottom. The curve-ends (points) lie on the + * right and left boundaries of the trapezoid respectively and the halfedges * bound the trapezoid from above and below. - * There exist degenerate trapezoids called infinite trapezoid; this happens + * There exist degenerate trapezoids called infinite trapezoid; this happens * when one of the four sides is on the parameter space boundary. * Trapezoids are created as active and become inactive when Remove() member * function called. * Each trapezoid has at most four neighbouring trapezoids. - * X_trapezoid structure can represent a real trapezoid, a Td-edge or an + * X_trapezoid structure can represent a real trapezoid, a Td-edge or an * edge-end (end point). */ -template -class Td_active_vertex : public Handle -{ - public: - +template +class Td_active_vertex : public Handle { +public: + //type of traits class - typedef Td_traits_ Traits; - + typedef Td_traits_ Traits; + //type of point (Point_2) - typedef typename Traits::Point Point; + typedef typename Traits::Point Point; //type of X_monotone_curve_2 - typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2; + typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2; //type of Curve_end - typedef typename Traits::Curve_end Curve_end; + typedef typename Traits::Curve_end Curve_end; //type of Halfedge_const_handle (trapezoid edge) - typedef typename Traits::Halfedge_const_handle Halfedge_const_handle; - + typedef typename Traits::Halfedge_const_handle Halfedge_const_handle; + //type of Vertex_const_handle (trapezoid vertex) - typedef typename Traits::Vertex_const_handle Vertex_const_handle; + typedef typename Traits::Vertex_const_handle Vertex_const_handle; //type of Halfedge_around_vertex_const_circulator - typedef typename Traits::Halfedge_around_vertex_const_circulator + typedef typename Traits::Halfedge_around_vertex_const_circulator Halfedge_around_vertex_const_circulator; //type of Td_active_vertex (Self) - typedef typename Traits::Td_active_vertex Self; - - typedef typename Traits::Td_map_item Td_map_item; + typedef typename Traits::Td_active_vertex Self; + + typedef typename Traits::Td_map_item Td_map_item; //type of Trapezoidal decomposition - typedef Trapezoidal_decomposition_2 TD; - + typedef Trapezoidal_decomposition_2 TD; + //type of In face iterator - typedef typename TD::In_face_iterator In_face_iterator; + typedef typename TD::In_face_iterator In_face_iterator; //type of Trapezoidal map search structure - typedef typename TD::Dag_node Dag_node; + typedef typename TD::Dag_node Dag_node; //friend class declarations: friend class Trapezoidal_decomposition_2; - + #ifdef CGAL_PM_FRIEND_CLASS #if defined(__SUNPRO_CC) || defined(__PGI) || defined(__INTEL_COMPILER) friend class Trapezoidal_decomposition_2::In_face_iterator; @@ -113,201 +112,145 @@ class Td_active_vertex : public Handle #else friend class Trapezoidal_decomposition_2::In_face_iterator; #endif - + #else friend class In_face_iterator; #endif #endif - + /*! \class - * Inner class Data derived from Rep class - */ - class Data : public Rep - { + * Inner class Data derived from Rep class + */ + class Data : public Rep { friend class Td_active_vertex; public: //c'tors - Data (Vertex_const_handle _v, - Halfedge_const_handle _cw_he, - Dag_node* _p_node) - : v(_v),cw_he(_cw_he),p_node(_p_node) - { } - - ~Data() { } + Data(Vertex_const_handle _v, Halfedge_const_handle _cw_he, + Dag_node* _p_node) : + v(_v), cw_he(_cw_he), p_node(_p_node) + {} + + ~Data() {} protected: - Vertex_const_handle v; + Vertex_const_handle v; Halfedge_const_handle cw_he; //holds the first edge going cw starting at 12 o'clock - Dag_node* p_node; + Dag_node* p_node; }; - - private: - - Data* ptr() const { return (Data*)(PTR); } + +private: + Data* ptr() const { return (Data*)(PTR); } Curve_end vtx_to_ce(Vertex_const_handle v) const { //the circulator is of incoming halfedges - Halfedge_around_vertex_const_circulator he = v->incident_halfedges(); + Halfedge_around_vertex_const_circulator he = v->incident_halfedges(); //if the vertex is associated with a point on the bounded coords, // we can take any incident halfedge. o/w if the vertex lies at infinity, // it has 2 fictitious incident halfedges if (v->is_at_open_boundary() && he->source()->is_at_open_boundary()) ++he; if (v->is_at_open_boundary() && he->source()->is_at_open_boundary()) ++he; - return Curve_end(he->curve(), - (he->direction() == ARR_RIGHT_TO_LEFT)? - ARR_MIN_END : ARR_MAX_END); + return Curve_end(he->curve(), ((he->direction() == ARR_RIGHT_TO_LEFT) ? + ARR_MIN_END : ARR_MAX_END)); } - - + #ifndef CGAL_TD_DEBUG #ifdef CGAL_PM_FRIEND_CLASS - protected: +protected: #else - public: // workaround +public: // workaround #endif #else //CGAL_TD_DEBUG - public: +public: #endif //CGAL_TD_DEBUG - - - + /*! Set the DAG node. */ - inline void set_dag_node(Dag_node* p) - { - ptr()->p_node = p; - } - + inline void set_dag_node(Dag_node* p) { ptr()->p_node = p; } + /*! Set the vertex handle (Vertex_const_handle). */ - inline void set_vertex(Vertex_const_handle v) + inline void set_vertex(Vertex_const_handle v) { ptr()->v = v; } + + /*! Set the first he going clockwise starting at 12 o'clock. + */ + inline void set_cw_he(Halfedge_const_handle he) { - ptr()->v = v; + ptr()->cw_he = ((cw_he() != Traits::empty_he_handle()) && + (cw_he()->direction() != he->direction())) ? + he->twin() : he; } - - /*! Set the first he going clockwise starting at 12 o'clock (Halfedge_const_handle). */ - inline void set_cw_he(Halfedge_const_handle he) - { - if (cw_he() != Traits::empty_he_handle() && - cw_he()->direction() != he->direction()) - { - ptr()->cw_he = he->twin(); - } - else - { - ptr()->cw_he = he; - } - } - - - public: - + + /*! Reset the first he going clockwise starting at 12 o'clock. + */ + inline void reset_cw_he() { ptr()->cw_he = Traits::empty_he_handle(); } + +public: /// \name Constructors. //@{ - Td_active_vertex () + Td_active_vertex() { - PTR = new Data - (Traits::empty_vtx_handle(), Traits::empty_he_handle(), NULL); + PTR = new Data(Traits::empty_vtx_handle(), Traits::empty_he_handle(), NULL); } - /*! Constructor given Vertex & Halfedge handles. */ - Td_active_vertex (Vertex_const_handle v, - Halfedge_const_handle cw_he, + Td_active_vertex(Vertex_const_handle v, Halfedge_const_handle cw_he, Dag_node* node = 0) - - { - PTR = new Data (v, cw_he, node); - } - - + + { PTR = new Data(v, cw_he, node); } + + /*! Copy constructor. */ - Td_active_vertex(const Self& tr) : Handle(tr) - { - } - + Td_active_vertex(const Self& tr) : Handle(tr) {} + //@} - + /// \name Operator overloading. //@{ - /*! Assignment operator. - * operator= should not copy m_dag_node (or otherwise update + /*! Assignment operator. + * operator= should not copy m_dag_node (or otherwise update * Dag_node::replace) */ - inline Self& operator= (const Self& t2) + inline Self& operator=(const Self& t2) { - Handle::operator=(t2); - return *this; + Handle::operator=(t2); + return *this; } /*! Operator==. */ - inline bool operator== (const Self& t2) const - { - return (ptr() == t2.ptr()); - } + inline bool operator==(const Self& t2) const { return (ptr() == t2.ptr()); } /*! Operator!=. */ - inline bool operator!= (const Self& t2) const - { - return !(operator==(t2)); - } + inline bool operator!=(const Self& t2) const { return !(operator==(t2)); } //@} - /// \name Access methods. //@{ - inline Self& self() - { - return *this; - } - - inline const Self& self() const - { - return *this; - } + inline Self& self() { return *this; } + + inline const Self& self() const { return *this; } /*! Access the trapezoid id (PTR). */ - inline unsigned long id() const - { - return (unsigned long) PTR; - } + inline unsigned long id() const { return (unsigned long) PTR; } - inline Vertex_const_handle vertex() const - { - return ptr()->v; - } + inline Vertex_const_handle vertex() const { return ptr()->v; } + + Curve_end curve_end() const { return vtx_to_ce(vertex()); } + + inline const Point& point() const { return vertex()->point(); } + + /*! Access the first he starting at 12 o'clock clockwise. + */ + inline Halfedge_const_handle cw_he() const { return ptr()->cw_he; } - Curve_end curve_end() const - { - return vtx_to_ce(vertex()); - } - - inline const Point& point() const - { - return vertex()->point(); - } - - /*! Access the first he starting at 12 o'clock clockwise. - */ - inline Halfedge_const_handle cw_he () const - { - return ptr()->cw_he; - } - /*! Access DAG node. */ - Dag_node* dag_node() const {return ptr()->p_node; } - - - //@} - - - + Dag_node* dag_node() const { return ptr()->p_node; } + //@} }; } //namespace CGAL From 343ca15477145b568f86817ba668a5cd17cc4969 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Wed, 16 May 2018 17:49:02 +0300 Subject: [PATCH 12/18] Introduced set_cw_he_visitor() member function --- .../Trapezoidal_decomposition_2.h | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h index 302c64b08ae..2a847e3ae58 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h @@ -617,29 +617,36 @@ public: } }; - class set_cw_he_visitor : public boost::static_visitor - { + /*! A visitor to set the cw halfedge of a vertex node. + */ + class set_cw_he_visitor : public boost::static_visitor { public: - set_cw_he_visitor (Halfedge_const_handle he) : m_cw_he(he) {} + set_cw_he_visitor(Halfedge_const_handle he) : m_cw_he(he) {} + + void operator()(Td_active_vertex& t) const { t.set_cw_he(m_cw_he); } - void operator()(Td_active_vertex& t) const - { - t.set_cw_he(m_cw_he); - } void operator()(Td_active_fictitious_vertex& t) const - { - t.set_cw_he(m_cw_he); - } + { t.set_cw_he(m_cw_he); } + + template + void operator()(T& /*t*/) const { CGAL_assertion(false); } - template < typename T > - void operator()(T& /*t*/) const - { - CGAL_assertion(false); - } private: Halfedge_const_handle m_cw_he; }; + /*! A visitor to reset the cw halfedge of a vertex node. + */ + class reset_cw_he_visitor : public boost::static_visitor { + public: + void operator()(Td_active_vertex& t) const { t.reset_cw_he(); } + + void operator()(Td_active_fictitious_vertex& t) const { t.reset_cw_he(); } + + template + void operator()(T& /*t*/) const { CGAL_assertion(false); } + }; + class dag_node_visitor : public boost::static_visitor { public: @@ -1151,6 +1158,11 @@ protected: Halfedge_const_handle new_he, Td_map_item& vtx_item); + /*! Update the cw halfedge of an active vertex after a halfedge is removed. + */ + void update_vtx_cw_he_after_remove(Halfedge_const_handle old_he, + Td_map_item& vtx_item); + ////MICHAL: currently not in use since split is implemented as: remove and insert two //void set_trp_params_after_split_halfedge_update(Halfedge_const_handle new_he, // Td_map_item& vtx_item, From 62ee9f5c1026659174f85490db50a67327e2f853 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Wed, 16 May 2018 17:50:58 +0300 Subject: [PATCH 13/18] Added a test case that tests RIC trapezoidal point-location when removing edges from the arrangement --- .../data/point_location/segments/ops/test12.txt | 4 ++++ .../test_point_location_dynamic.segments.cmd | 1 + 2 files changed, 5 insertions(+) create mode 100644 Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/ops/test12.txt diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/ops/test12.txt b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/ops/test12.txt new file mode 100644 index 00000000000..5bd5550c751 --- /dev/null +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/point_location/segments/ops/test12.txt @@ -0,0 +1,4 @@ +i 0 +i 1 +d 1 +i 1 diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_point_location_dynamic.segments.cmd b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_point_location_dynamic.segments.cmd index 701bf4d2231..e5bc1f66d70 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_point_location_dynamic.segments.cmd +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_point_location_dynamic.segments.cmd @@ -1,2 +1,3 @@ ./data/empty.zero ./data/point_location/segments/xcurves/test10.txt ./data/empty.zero ./data/point_location/segments/ops/test10.txt ./data/point_location/segments/queries/test10.txt ./data/empty.zero ./data/point_location/segments/xcurves/test11.txt ./data/empty.zero ./data/point_location/segments/ops/test11.txt ./data/point_location/segments/queries/test03.txt +./data/empty.zero ./data/point_location/segments/xcurves/test11.txt ./data/empty.zero ./data/point_location/segments/ops/test12.txt ./data/point_location/segments/queries/test03.txt From 224a500ec78c91ad1ec0e4445d91c7b87b163f6e Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Wed, 16 May 2018 17:52:15 +0300 Subject: [PATCH 14/18] Called locate_opt_empty() after the removal of an edge to reset the hint. Introduced update_vtx_cw_he_after_remove() and called it to update the cw halfedge of an active vertex when a halfedge is removed. --- .../Trapezoidal_decomposition_2_impl.h | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h index ae7b7ac627d..b85c6fa5dc5 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2_impl.h @@ -496,6 +496,27 @@ update_vtx_cw_he_after_merge(const X_monotone_curve_2& old_cv, boost::apply_visitor(set_cw_he_visitor(new_he), vtx_item); } +//----------------------------------------------------------------------------- +// Description: +// Update the cw he after a halfedge is removed. +// +template +void Trapezoidal_decomposition_2:: +update_vtx_cw_he_after_remove(Halfedge_const_handle old_he, + Td_map_item& vtx_item) +{ + CGAL_precondition(traits->is_td_vertex(vtx_item)); + CGAL_precondition(traits->is_active(vtx_item)); + + Halfedge_const_handle cw_he(boost::apply_visitor(cw_he_visitor(), vtx_item)); + if ((old_he == cw_he) || (old_he->twin() == cw_he)) { + Halfedge_const_handle new_he = cw_he->twin()->prev(); + if (new_he != old_he) + boost::apply_visitor(set_cw_he_visitor(new_he), vtx_item); + else boost::apply_visitor(reset_cw_he_visitor(), vtx_item); + } +} + ////MICHAL: currently not in use since split is implemented as removed and insert two //// in case the split is done differenty - this method would have to be rewritten since it is obsolete //template @@ -1626,16 +1647,19 @@ void Trapezoidal_decomposition_2::remove(Halfedge_const_handle he) CGAL_warning(traits != NULL); //calculating leftmost and rightmost curve ends of he - const Curve_end leftmost(he,ARR_MIN_END); - const Curve_end rightmost(he,ARR_MAX_END); + const Curve_end leftmost(he, ARR_MIN_END); + const Curve_end rightmost(he, ARR_MAX_END); //locating leftmost & rightmost curve ends - Locate_type lt1,lt2; - Td_map_item p1_item = locate(leftmost,lt1); - Td_map_item p2_item = locate(rightmost,lt2); + Locate_type lt1, lt2; + Td_map_item p1_item = locate(leftmost, lt1); + Td_map_item p2_item = locate(rightmost, lt2); + + update_vtx_cw_he_after_remove(he, p1_item); + update_vtx_cw_he_after_remove(he, p2_item); //both should be located on a point degenerate trapezoid - CGAL_warning(lt1==POINT && lt2==POINT); + CGAL_warning(lt1 == POINT && lt2 == POINT); if (lt1 != POINT || lt2 != POINT) return; @@ -1882,6 +1906,8 @@ void Trapezoidal_decomposition_2::remove(Halfedge_const_handle he) if (is_last_edge(he ,p2_item)) undo_split_trapezoid_by_vertex(p2_node, rightmost); + locate_opt_empty(); + //----------------------------------- //6. reevaluating number of curves m_number_of_curves--; From f2b65d652fcbbb47600ba877cd797145c0d7d739 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Sun, 20 May 2018 23:43:53 +0300 Subject: [PATCH 15/18] Suppress c++11 for now. --- .../Arrangement_on_surface_2/CMakeLists.txt | 10 - .../Point_location_test.h | 206 +++++++++++------- 2 files changed, 126 insertions(+), 90 deletions(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/CMakeLists.txt b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/CMakeLists.txt index 2ffece8e931..1e9b152f714 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/CMakeLists.txt +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/CMakeLists.txt @@ -8,16 +8,6 @@ enable_testing() cmake_minimum_required(VERSION 3.1) -list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_generalized_initializers has_cpp11) -if (has_cpp11 LESS 0) - message(STATUS "NOTICE: These examples requires a C++11 compiler and will not be compiled.") - return() -endif() - -# Use C++11 for this directory and its sub-directories. -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - find_package(CGAL QUIET COMPONENTS Core) if ( CGAL_FOUND ) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h index 40f14620a61..3224dfe54eb 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h @@ -14,7 +14,7 @@ #define TRAPEZOID_RIC_PL_ENABLED 1 #define TRAPEZOID_RIC_NO_GUARANTEE_PL_ENABLED 1 -#include +#include #include #include @@ -149,23 +149,24 @@ protected: NUM_PL_STRATEGIES }; - struct Locator { - typedef boost::variant Pl_variant; + Trapezoid_ric_pl*> Pl_variant; + + struct Locator { Pl_variant m_variant; //! The name of the locator. @@ -174,7 +175,7 @@ protected: bool m_active; }; - std::array m_locators; + std::vector m_locators; // Landmark point-location generators Random_lm_generator* m_random_g; @@ -238,9 +239,11 @@ public: void query(Point_location& pl, const char* type, InputIterator begin, InputIterator end, OutputIterator oi) { + typedef InputIterator Input_iterator; CGAL::Timer timer; timer.reset(); timer.start(); - for (auto piter = begin; piter != end; ++piter) *oi++ = pl.locate(*piter); + for (Input_iterator piter = begin; piter != end; ++piter) + *oi++ = pl.locate(*piter); timer.stop(); std::cout << type << " location took " << timer.time() << std::endl; } @@ -250,7 +253,7 @@ private: template void init_pl(const std::string& name) { - m_locators[id].m_variant = static_cast(nullptr); + m_locators[id].m_variant = static_cast(NULL); m_locators[id].m_name = name; m_locators[id].m_active = true; } @@ -259,7 +262,7 @@ private: template void allocate_pl() { - auto* locator = new Strategy(); + Strategy* locator = new Strategy(); CGAL_assertion(locator); m_locators[id].m_variant = locator; } @@ -268,7 +271,7 @@ private: template bool construct_pl() { - auto* locator = new Strategy(*m_arr); + Strategy* locator = new Strategy(*m_arr); if (! locator) return false; m_locators[id].m_variant = locator; return true; @@ -278,7 +281,7 @@ private: template bool construct_pl(Generator* generator) { - auto* locator = new Strategy(*m_arr, generator); + Strategy* locator = new Strategy(*m_arr, generator); if (! locator) return false; m_locators[id].m_variant = locator; return true; @@ -288,10 +291,10 @@ private: template void deallocate_pl() { - auto* strategy = boost::get(m_locators[id].m_variant); + Strategy* strategy = boost::get(m_locators[id].m_variant); if (strategy) { delete strategy; - m_locators[id].m_variant = static_cast(nullptr); + m_locators[id].m_variant = static_cast(NULL); } } @@ -300,7 +303,7 @@ private: void attach_pl() { if (! m_locators[id].m_active) return; - auto* strategy = boost::get(m_locators[id].m_variant); + Strategy* strategy = boost::get(m_locators[id].m_variant); strategy->attach(*m_arr); } @@ -309,7 +312,7 @@ private: void attach_pl(Generator* generator) { if (! m_locators[id].m_active) return; - auto* strategy = boost::get(m_locators[id].m_variant); + Strategy* strategy = boost::get(m_locators[id].m_variant); strategy->attach(*m_arr, generator); } @@ -318,8 +321,8 @@ private: void query_pl(T& objs) { if (! m_locators[id].m_active) return; - const auto& name = m_locators[id].m_name; - auto* strategy = boost::get(m_locators[id].m_variant); + const std::string& name = m_locators[id].m_name; + Strategy* strategy = boost::get(m_locators[id].m_variant); query(*strategy, name.c_str(), m_query_points.begin(), m_query_points.end(), std::back_inserter(objs)); } @@ -329,7 +332,7 @@ private: void measure(Timer& timer, UnaryOperation op) { if (! m_locators[id].m_active) return; - const auto& name = m_locators[id].m_name; + const std::string& name = m_locators[id].m_name; timer.reset(); timer.start(); op(); @@ -420,7 +423,7 @@ private: #define DEALLOCATE_PL_LM_RANDOM() \ if (m_random_g) { \ delete m_random_g; \ - m_random_g = nullptr; \ + m_random_g = NULL; \ } \ deallocate_pl() @@ -450,7 +453,7 @@ private: #define DEALLOCATE_PL_LM_GRID() \ if (m_grid_g) { \ delete m_grid_g; \ - m_grid_g = nullptr; \ + m_grid_g = NULL; \ } \ deallocate_pl() @@ -481,7 +484,7 @@ private: #define DEALLOCATE_PL_LM_HALTON() \ if (m_halton_g) { \ delete m_halton_g; \ - m_halton_g = nullptr; \ + m_halton_g = NULL; \ } \ deallocate_pl() @@ -513,7 +516,7 @@ private: #define DEALLOCATE_PL_LM_MIDDLE_EDGES() \ if (m_middle_edges_g) { \ delete m_middle_edges_g; \ - m_middle_edges_g = nullptr; \ + m_middle_edges_g = NULL; \ } \ deallocate_pl() @@ -546,7 +549,7 @@ private: #define DEALLOCATE_PL_LM_SPECIFIED_POINTS() \ if (m_specified_points_g) { \ delete m_specified_points_g; \ - m_specified_points_g = nullptr; \ + m_specified_points_g = NULL; \ } \ deallocate_pl() @@ -621,10 +624,10 @@ private: #define DEALLOCATE_PL_TRAPEZOID_RIC_NO_GUARANTEE() \ deallocate_pl() -#define ATTACH_PL_TRAPEZOID_RIC_NO_GUARANTEE() \ - auto& var = m_locators[TRAPEZOID_RIC_NO_GUARANTEE_PL].m_variant; \ - auto* strategy = boost::get(var); \ - strategy->with_guarantees(false); \ +#define ATTACH_PL_TRAPEZOID_RIC_NO_GUARANTEE() \ + Pl_variant& var = m_locators[TRAPEZOID_RIC_NO_GUARANTEE_PL].m_variant; \ + Trapezoid_ric_pl* strategy = boost::get(var); \ + strategy->with_guarantees(false); \ attach_pl() #define QUERY_PL_TRAPEZOID_RIC_NO_GUARANTEE(obj) \ @@ -638,19 +641,57 @@ private: #define QUERY_PL_TRAPEZOID_RIC_NO_GUARANTEE(obj) #endif +#if defined(CGAL_CFG_NO_CPP0X_LAMBDAS) +#define MEASURE_NAIVE_PL(timer, op) op +#define MEASURE_SIMPLE_PL(timer, op) op +#define MEASURE_WALK_PL(timer, op) op +#define MEASURE_LM_PL(timer, op) op +#define MEASURE_LM_RANDOM_PL(timer, op) op +#define MEASURE_LM_GRID_PL(timer, op) op +#define MEASURE_LM_HALTON_PL(timer, op) op +#define MEASURE_LM_MIDDLE_EDGES_PL(timer, op) op +#define MEASURE_LM_SPECIFIED_POINTS_PL(timer, op) op +#define MEASURE_TRIANGULATION_PL(timer, op) op +#define MEASURE_TRAPEZOID_RIC_PL(timer, op) op +#define MEASURE_TRAPEZOID_RIC_NO_GUARANTEE_PL(timer, op) op +#else +#define MEASURE_NAIVE_PL(timer, op) measure(timer, [&](){ op; }); +#define MEASURE_SIMPLE_PL(timer, op) measure(timer, [&](){ op; }); +#define MEASURE_WALK_PL(timer, op) measure(timer, [&](){ op; }); +#define MEASURE_LM_PL(timer, op) measure(timer, [&](){ op; }); +#define MEASURE_LM_RANDOM_PL(timer, op) \ + measure(timer, [&](){ op; }); +#define MEASURE_LM_GRID_PL(timer, op) \ + measure(timer, [&](){ op; }); +#define MEASURE_LM_HALTON_PL(timer, op) \ + measure(timer, [&](){ op; }); +#define MEASURE_LM_MIDDLE_EDGES_PL(timer, op) \ + measure(timer, [&](){ op; }); +#define MEASURE_LM_SPECIFIED_POINTS_PL(timer, op) \ + measure(timer, [&](){ op; }); +#define MEASURE_TRIANGULATION_PL(timer, op) \ + measure(timer, [&](){ op; }); +#define MEASURE_TRAPEZOID_RIC_PL(timer, op) \ + measure(timer, [&](){ op; }); +#define MEASURE_TRAPEZOID_RIC_NO_GUARANTEE_PL(timer, op) \ + measure(timer, [&](){ op; }); +#endif + //! Constructor. template Point_location_test:: Point_location_test(const Geom_traits& geom_traits) : Base(geom_traits), m_geom_traits(geom_traits), - m_arr(nullptr), - m_random_g(nullptr), - m_grid_g(nullptr), - m_halton_g(nullptr), - m_middle_edges_g(nullptr), - m_specified_points_g(nullptr) + m_arr(NULL), + m_random_g(NULL), + m_grid_g(NULL), + m_halton_g(NULL), + m_middle_edges_g(NULL), + m_specified_points_g(NULL) { + m_locators.resize(NUM_PL_STRATEGIES); + INIT_PL_NATIVE(); INIT_PL_SIMPLE(); INIT_PL_WALK(); @@ -748,7 +789,7 @@ deallocate_arrangement() { if (m_arr) { delete m_arr; - m_arr = nullptr; + m_arr = NULL; } } @@ -816,25 +857,22 @@ bool Point_location_test::construct_pl_strategies() #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - measure(timer, [&](){ CONSTRUCT_PL_LM(); }); - measure(timer, [&](){ CONSTRUCT_PL_LM_RANDOM(); }); - measure(timer, [&](){ CONSTRUCT_PL_LM_GRID(); }); - measure(timer, [&](){ CONSTRUCT_PL_LM_HALTON(); }); - measure(timer, [&](){ CONSTRUCT_PL_LM_MIDDLE_EDGES(); }); - measure(timer, [&](){ - CONSTRUCT_PL_LM_SPECIFIED_POINTS(); - }); + MEASURE_LM_PL(timer, CONSTRUCT_PL_LM()); + MEASURE_LM_RANDOM_PL(timer, CONSTRUCT_PL_LM_RANDOM()); + MEASURE_LM_GRID_PL(timer, CONSTRUCT_PL_LM_GRID()); + MEASURE_LM_HALTON_PL(timer, CONSTRUCT_PL_LM_HALTON()); + MEASURE_LM_MIDDLE_EDGES_PL(timer, CONSTRUCT_PL_LM_MIDDLE_EDGES()); + MEASURE_LM_SPECIFIED_POINTS_PL(timer, CONSTRUCT_PL_LM_SPECIFIED_POINTS()); #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - measure(timer, [&](){ CONSTRUCT_PL_TRIANGULATION_PL(); }); + MEASURE_TRIANGULATION_PL(timer, CONSTRUCT_PL_TRIANGULATION_PL()); #endif - measure(timer, [&](){ CONSTRUCT_PL_TRAPEZOID_RIC_PL(); }); - measure(timer, [&](){ - CONSTRUCT_PL_TRAPEZOID_RIC_NO_GUARANTEE(); - }); + MEASURE_TRAPEZOID_RIC_PL(timer, CONSTRUCT_PL_TRAPEZOID_RIC_PL()); + MEASURE_TRAPEZOID_RIC_NO_GUARANTEE_PL(timer, + CONSTRUCT_PL_TRAPEZOID_RIC_NO_GUARANTEE()); std::cout << std::endl; @@ -854,24 +892,21 @@ bool Point_location_test::attach_pl_strategies() #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) || \ (TEST_GEOM_TRAITS == LINEAR_GEOM_TRAITS) - measure(timer, [&](){ ATTACH_PL_LM(); }); - measure(timer, [&](){ ATTACH_PL_LM_RANDOM(); }); - measure(timer, [&](){ ATTACH_PL_LM_GRID(); }); - measure(timer, [&](){ ATTACH_PL_LM_HALTON(); }); - measure(timer, [&](){ ATTACH_PL_LM_MIDDLE_EDGES(); }); - measure(timer, [&](){ - ATTACH_PL_LM_SPECIFIED_POINTS(); - }); + MEASURE_LM_PL(timer, ATTACH_PL_LM()); + MEASURE_LM_RANDOM_PL(timer, ATTACH_PL_LM_RANDOM()); + MEASURE_LM_GRID_PL(timer, ATTACH_PL_LM_GRID()); + MEASURE_LM_HALTON_PL(timer, ATTACH_PL_LM_HALTON()); + MEASURE_LM_MIDDLE_EDGES_PL(timer, ATTACH_PL_LM_MIDDLE_EDGES()); + MEASURE_LM_SPECIFIED_POINTS_PL(timer, ATTACH_PL_LM_SPECIFIED_POINTS()); #endif #if (TEST_GEOM_TRAITS == SEGMENT_GEOM_TRAITS) - measure(timer, [&](){ ATTACH_PL_TRIANGULATION_PL(); }); + MEASURE_TRIANGULATION_PL(timer, ATTACH_PL_TRIANGULATION_PL()); #endif - measure(timer, [&](){ ATTACH_PL_TRAPEZOID_RIC_PL(); }); - measure(timer, [&](){ - ATTACH_PL_TRAPEZOID_RIC_NO_GUARANTEE(); - }); + MEASURE_TRAPEZOID_RIC_PL(timer, ATTACH_PL_TRAPEZOID_RIC_PL()); + MEASURE_TRAPEZOID_RIC_NO_GUARANTEE_PL(timer, + ATTACH_PL_TRAPEZOID_RIC_NO_GUARANTEE()); std::cout << std::endl; @@ -1069,10 +1104,11 @@ verify(Variants_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num) // Assign and check results for (size_t qi = 0; qi < size; ++qi) { // Assign object to a face - auto* fh_ref = boost::get(&(objs[0][qi])); + Face_const_handle* fh_ref = boost::get(&(objs[0][qi])); if (fh_ref) { for (size_t pl = 1; pl < pls_num; ++pl) { - auto* fh_cur = boost::get(&(objs[pl][qi])); + Face_const_handle* fh_cur = + boost::get(&(objs[pl][qi])); if (fh_cur) { if ((*fh_cur) != (*fh_ref)) { std::cout << "Error: point location number " << pl << std::endl; @@ -1086,12 +1122,14 @@ verify(Variants_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num) std::cout << "Error: point location number " << pl << std::endl; std::cout << "Expected: a face." << std::endl; result += -1; - auto* hh_cur = boost::get(&(objs[pl][qi])); + Halfedge_const_handle* hh_cur = + boost::get(&(objs[pl][qi])); if (hh_cur) { std::cout << "Actual: a halfedge." << std::endl; continue; } - auto* vh_cur = boost::get(&(objs[pl][qi])); + Vertex_const_handle* vh_cur = + boost::get(&(objs[pl][qi])); if (vh_cur) { std::cout << "Actual: a vertex." << std::endl; continue; @@ -1106,10 +1144,12 @@ verify(Variants_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num) } // Assign object to a halfedge - auto* hh_ref = boost::get(&(objs[0][qi])); + Halfedge_const_handle* hh_ref = + boost::get(&(objs[0][qi])); if (hh_ref) { for (size_t pl = 1; pl < pls_num; ++pl) { - auto* hh_cur = boost::get(&(objs[pl][qi])); + Halfedge_const_handle* hh_cur = + boost::get(&(objs[pl][qi])); if (hh_cur) { if (((*hh_cur) != (*hh_ref)) && ((*hh_cur)->twin() != (*hh_ref))) { std::cout << "Error: point location number " << pl << std::endl; @@ -1125,12 +1165,14 @@ verify(Variants_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num) std::cout << "Expected: a halfedge, " << (*hh_ref)->curve() << std::endl; result += -1; - auto* fh_cur = boost::get(&(objs[pl][qi])); + Face_const_handle* fh_cur = + boost::get(&(objs[pl][qi])); if (fh_cur) { std::cout << "Actual: a face." << std::endl; continue; } - auto* vh_cur = boost::get(&(objs[pl][qi])); + Vertex_const_handle* vh_cur = + boost::get(&(objs[pl][qi])); if (vh_cur) { std::cout << "Actual: a vertex." << std::endl; continue; @@ -1141,10 +1183,12 @@ verify(Variants_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num) } // Assign object to a vertex - auto* vh_ref = boost::get(&(objs[0][qi])); + Vertex_const_handle* vh_ref = + boost::get(&(objs[0][qi])); if (vh_ref) { for (size_t pl = 1; pl < pls_num; ++pl) { - auto vh_cur = boost::get(&(objs[pl][qi])); + Vertex_const_handle* vh_cur = + boost::get(&(objs[pl][qi])); if (vh_cur) { if ((*vh_cur) != (*vh_ref)) { std::cout << "Error: point location number " << pl << std::endl; @@ -1159,12 +1203,14 @@ verify(Variants_vector objs[NUM_PL_STRATEGIES], size_t size, size_t pls_num) std::cout << "Error: point location number " << pl << std::endl; std::cout << "Expected: a vertex: "<< (*vh_ref)->point() << std::endl; result += -1; - auto fh_cur = boost::get(&(objs[pl][qi])); + Face_const_handle* fh_cur = + boost::get(&(objs[pl][qi])); if (fh_cur) { std::cout << "Actual: a face." << std::endl; continue; } - auto hh_cur = boost::get(&(objs[pl][qi])); + Halfedge_const_handle* hh_cur = + boost::get(&(objs[pl][qi])); if (hh_cur) { std::cout << "Actual: a halfedge." << std::endl; continue; From 8631b3c09f94c4bbaaaea42319e8d8d9d804fded Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Fri, 25 May 2018 13:21:42 +0300 Subject: [PATCH 16/18] Fixed a warning about an unsed variable. --- .../Trapezoidal_decomposition_2.h | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h index 2a847e3ae58..5a95a74b6fb 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Trapezoidal_decomposition_2.h @@ -16,8 +16,9 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0+ // -// Author(s) : Oren Nechushtan -// Iddo Hanniel +// Author(s): Oren Nechushtan +// Iddo Hanniel +// Efi Fogel #ifndef CGAL_TRAPEZOIDAL_DECOMPOSITION_2_H #define CGAL_TRAPEZOIDAL_DECOMPOSITION_2_H @@ -1770,18 +1771,20 @@ public: #endif Halfedge_container container; +#ifdef CGAL_TD_DEBUG unsigned long rep = Halfedge_filter(container, &dag_root()); +#else + Halfedge_filter(container, &dag_root()); +#endif clear(); //// initialize container to point to curves in Td_map_item Tree - //if (rep>0) - //{ + //if (rep>0) { // bool o = set_with_guarantees(false); // typename std::vector::iterator // it = container.begin(), // it_end = container.end(); - // while(it!=it_end) - // { + // while (it != it_end) { // insert(*it); // ++it; // } @@ -1795,8 +1798,7 @@ public: #ifdef CGAL_TD_DEBUG CGAL_assertion(is_valid()); unsigned long sz = number_of_curves(); - if (sz != rep) - { + if (sz != rep) { std::cerr << "\nnumber_of_curves()=" << sz; std::cerr << "\nrepresentatives.size()=" << rep; CGAL_assertion(number_of_curves() == rep); @@ -1840,46 +1842,37 @@ public: // return container.size(); //} + /* Return a container for all active curves. + */ template unsigned long Halfedge_filter(Halfedge_container& container, const Dag_node* ds) const - /* Return a container for all active curves */ { unsigned long sz = number_of_curves(); std::list representatives; - //X_trapezoid_list representatives; ds->filter(representatives, Td_active_edge_item(*traits)); #ifndef CGAL_TD_DEBUG - - CGAL_warning(sz==representatives.size()); - + CGAL_warning(sz == representatives.size()); #else - unsigned long rep=representatives.size(); - if (sz != rep) - { + unsigned long rep = representatives.size(); + if (sz != rep) { std::cerr << "\nnumber_of_curves()=" << sz; std::cerr << "\nrepresentatives.size()=" << rep; CGAL_assertion(number_of_curves()==representatives.size()); } - #endif - if (sz > 0) - { - typename std::list::iterator it = representatives.begin(), - it_end = representatives.end(); - //typename X_trapezoid_list::iterator it = representatives.begin(), - // it_end = representatives.end(); - while(!(it==it_end)) + if (sz > 0) { + for (typename std::list::iterator it = + representatives.begin(); it != representatives.end(); ++it) { - Td_active_edge e (boost::get(*it)); + Td_active_edge e(boost::get(*it)); container.push_back(e.halfedge()); //it represents an active trapezoid - ++it; } } - if(! container.empty()) { + if (! container.empty()) { CGAL::cpp98::random_shuffle(container.begin(),container.end()); } return sz; @@ -2018,7 +2011,6 @@ public: true, *m_dag_root, *m_dag_root); } - protected: //Trapezoidal Decomposition data members @@ -2146,7 +2138,6 @@ private: #endif - void print_cv_data(const X_monotone_curve_2& cv, std::ostream& out = std::cout) const { @@ -2214,7 +2205,6 @@ private: } } - void print_dag_addresses(const Dag_node& curr) const { From e3271e8f38a627c0ff8e6833d2e12fe9b3c30505 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Fri, 25 May 2018 14:12:09 +0300 Subject: [PATCH 17/18] Added guards against c++11 --- .../test/Minkowski_sum_2/CMakeLists.txt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Minkowski_sum_2/test/Minkowski_sum_2/CMakeLists.txt b/Minkowski_sum_2/test/Minkowski_sum_2/CMakeLists.txt index a5dd309437e..5ec0bc17e3b 100644 --- a/Minkowski_sum_2/test/Minkowski_sum_2/CMakeLists.txt +++ b/Minkowski_sum_2/test/Minkowski_sum_2/CMakeLists.txt @@ -6,6 +6,16 @@ project( Minkowski_sum_2_Tests ) cmake_minimum_required(VERSION 2.8.10) +list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_generalized_initializers has_cpp11) +if (has_cpp11 LESS 0) + message(STATUS "NOTICE: These examples requires a C++11 compiler and will not be compiled.") + return() +endif() + +# Use C++11 for this directory and its sub-directories. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + find_package(CGAL QUIET COMPONENTS Core ) if ( CGAL_FOUND ) @@ -23,8 +33,7 @@ if ( CGAL_FOUND ) endforeach() else() - - message(STATUS "This program requires the CGAL library, and will not be compiled.") - -endif() + message(STATUS "This program requires the CGAL library, and will not be compiled.") + +endif() From 72e66661aff0f07702307ee114e65509d4643788 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Fri, 25 May 2018 15:40:51 +0300 Subject: [PATCH 18/18] Commented out C++11 support for now. --- .../test/Minkowski_sum_2/CMakeLists.txt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Minkowski_sum_2/test/Minkowski_sum_2/CMakeLists.txt b/Minkowski_sum_2/test/Minkowski_sum_2/CMakeLists.txt index 5ec0bc17e3b..e41e969753f 100644 --- a/Minkowski_sum_2/test/Minkowski_sum_2/CMakeLists.txt +++ b/Minkowski_sum_2/test/Minkowski_sum_2/CMakeLists.txt @@ -6,15 +6,16 @@ project( Minkowski_sum_2_Tests ) cmake_minimum_required(VERSION 2.8.10) -list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_generalized_initializers has_cpp11) -if (has_cpp11 LESS 0) - message(STATUS "NOTICE: These examples requires a C++11 compiler and will not be compiled.") - return() -endif() +# Commented out C++11 for now +# list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_generalized_initializers has_cpp11) +# if (has_cpp11 LESS 0) +# message(STATUS "NOTICE: These examples requires a C++11 compiler and will not be compiled.") +# return() +# endif() -# Use C++11 for this directory and its sub-directories. -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +# # Use C++11 for this directory and its sub-directories. +# set(CMAKE_CXX_STANDARD 11) +# set(CMAKE_CXX_STANDARD_REQUIRED TRUE) find_package(CGAL QUIET COMPONENTS Core )