From c0e49e7a292fab41b39d09d9e257299aba64bb0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rik=20Paradis?= Date: Fri, 2 Dec 2016 13:56:14 -0500 Subject: [PATCH] Refactoring of the enum Half to Cones_selected and fix bugs in cone spanners ipelet --- .../demo/CGAL_ipelets/cone_spanners.cpp | 17 ++++++++------- ...anners_2_enum.h => Cone_spanners_enum_2.h} | 21 +++++++++++++------ .../include/CGAL/Construct_theta_graph_2.h | 20 +++++++++--------- .../include/CGAL/Construct_yao_graph_2.h | 20 +++++++++--------- 4 files changed, 44 insertions(+), 34 deletions(-) rename Cone_spanners_2/include/CGAL/{Cone_spanners_2_enum.h => Cone_spanners_enum_2.h} (68%) diff --git a/CGAL_ipelets/demo/CGAL_ipelets/cone_spanners.cpp b/CGAL_ipelets/demo/CGAL_ipelets/cone_spanners.cpp index 7c3cbcc3215..81780dc5aaa 100644 --- a/CGAL_ipelets/demo/CGAL_ipelets/cone_spanners.cpp +++ b/CGAL_ipelets/demo/CGAL_ipelets/cone_spanners.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -40,10 +41,10 @@ const std::string hmsg[] = { }; class Cone_spanners_ipelet - : public CGAL::Ipelet_base { + : public CGAL::Ipelet_base { public: Cone_spanners_ipelet() - :CGAL::Ipelet_base("Cone Spanners",labels,hmsg){} + :CGAL::Ipelet_base("Cone Spanners",labels,hmsg){} void protected_run(int); private: }; @@ -94,11 +95,11 @@ void Cone_spanners_ipelet::protected_run(int fn) } if(fn >= 0 && fn <= 5) { - CGAL::Half half = CGAL::ALL_CONES; + CGAL::Cones_selected cones_selected = CGAL::ALL_CONES; if(fn == 2 || fn == 3) - half = CGAL::EVEN_CONES; + cones_selected = CGAL::EVEN_CONES; else if(fn == 4 || fn == 5) - half = CGAL::ODD_CONES; + cones_selected = CGAL::ODD_CONES; Graph g; switch (fn){ @@ -106,7 +107,7 @@ void Cone_spanners_ipelet::protected_run(int fn) case 2: case 4: { - CGAL::Construct_theta_graph_2 theta(number_of_cones, Direction_2(1,0), half); + CGAL::Construct_theta_graph_2 theta(number_of_cones, Direction_2(1,0), cones_selected); theta(lst.begin(), lst.end(), g); break; } @@ -114,7 +115,7 @@ void Cone_spanners_ipelet::protected_run(int fn) case 3: case 5: { - CGAL::Construct_yao_graph_2 yao(number_of_cones, Direction_2(1,0), half); + CGAL::Construct_yao_graph_2 yao(number_of_cones, Direction_2(1,0), cones_selected); yao(lst.begin(), lst.end(), g); break; } @@ -128,7 +129,7 @@ void Cone_spanners_ipelet::protected_run(int fn) } group_selected_objects_(); } - else if(fn == 4) { + else if(fn == 6) { CGAL::Compute_cone_boundaries_2 cones; std::vector directions(number_of_cones); cones(number_of_cones, Direction_2(1,0), directions.begin()); diff --git a/Cone_spanners_2/include/CGAL/Cone_spanners_2_enum.h b/Cone_spanners_2/include/CGAL/Cone_spanners_enum_2.h similarity index 68% rename from Cone_spanners_2/include/CGAL/Cone_spanners_2_enum.h rename to Cone_spanners_2/include/CGAL/Cone_spanners_enum_2.h index 89e3b5960ee..9dbb2f40027 100644 --- a/Cone_spanners_2/include/CGAL/Cone_spanners_2_enum.h +++ b/Cone_spanners_2/include/CGAL/Cone_spanners_enum_2.h @@ -16,22 +16,31 @@ // $Id$ // // -// Authors: Weisheng Si, Quincy Tse +// Authors: Frédérk Paradis -/*! \file Cone_spanners_2_enum.h +/*! \file Cone_spanners_enum_2.h * * This header defines enumerators for the cone spanners functors. */ -#ifndef CONE_SPANNERS_2_ENUM_H -#define CONE_SPANNERS_2_ENUM_H +#ifndef CONE_SPANNERS_ENUM_2_H +#define CONE_SPANNERS_ENUM_2_H namespace CGAL { /*! \ingroup PkgConeBasedSpanners - \brief An enum of the types of cone spanners. + \brief An enum of the choice of cones in cone spanners. */ - enum Half { EVEN_CONES = 0, ODD_CONES = 1, ALL_CONES = 2 }; + enum Cones_selected { + /*! \brief Select even cones. + */ + EVEN_CONES = 0, + /*! \brief Select odd cones. + */ + ODD_CONES = 1, + /*! \brief Select all cones. + */ + ALL_CONES = 2 }; } // namespace CGAL diff --git a/Cone_spanners_2/include/CGAL/Construct_theta_graph_2.h b/Cone_spanners_2/include/CGAL/Construct_theta_graph_2.h index 6cecb089d33..464e18fc196 100644 --- a/Cone_spanners_2/include/CGAL/Construct_theta_graph_2.h +++ b/Cone_spanners_2/include/CGAL/Construct_theta_graph_2.h @@ -16,7 +16,7 @@ // $Id$ // // -// Authors: Weisheng Si, Quincy Tse +// Authors: Weisheng Si, Quincy Tse, Frédérk Paradis /*! \file Construct_theta_graph_2.h * @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include @@ -79,8 +79,8 @@ private: /* Store the number of cones. */ unsigned int cone_number; - /* Store whether this is an half-theta graph */ - Half half; + /* Store whether even, odd or all cones are selected to construct graph. */ + Cones_selected cones_choice; /* Store the directions of the rays dividing the plane. The initial direction will be * stored in rays[0]. @@ -94,13 +94,13 @@ public: \param initial_direction A direction denoting one of the rays dividing the cones. This allows arbitary rotations of the rays that divide the plane. (default: positive x-axis) - \param half_theta Indicates whether all the cones are used or just half of - them (default: all cones). + \param cones_selected Indicates whether even, odd or all cones are + selected to construct graph. */ Construct_theta_graph_2 (unsigned int k, Direction_2 initial_direction = Direction_2(1,0), - Half half_theta = ALL_CONES - ): cone_number(k), rays(std::vector(k)), half(half_theta) + Cones_selected cones_selected = ALL_CONES + ): cone_number(k), rays(std::vector(k)), cones_choice(cones_selected) { if (k<2) { @@ -138,8 +138,8 @@ public: unsigned int j; // index of the ccw ray // add edges into the graph for every cone - int new_start = half != ALL_CONES ? half : 0; - int increment = half != ALL_CONES ? 2 : 1; + int new_start = cones_choice != ALL_CONES ? cones_choice : 0; + int increment = cones_choice != ALL_CONES ? 2 : 1; for (i = new_start; i < cone_number; i += increment) { j = (i+1) % cone_number; add_edges_in_cone(rays[i], rays[j], g); diff --git a/Cone_spanners_2/include/CGAL/Construct_yao_graph_2.h b/Cone_spanners_2/include/CGAL/Construct_yao_graph_2.h index c9cf32927d2..2fb9618cffb 100644 --- a/Cone_spanners_2/include/CGAL/Construct_yao_graph_2.h +++ b/Cone_spanners_2/include/CGAL/Construct_yao_graph_2.h @@ -16,7 +16,7 @@ // $Id$ // // -// Authors: Weisheng Si, Quincy Tse +// Authors: Weisheng Si, Quincy Tse, Frédérk Paradis /*! \file Construct_yao_graph_2.h * @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -74,8 +74,8 @@ private: /* Store the number of cones. */ unsigned int cone_number; - /* Store whether this is an half-yao graph */ - Half half; + /* Store whether even, odd or all cones are selected to construct graph. */ + Cones_selected cones_choice; /* Store the directions of the rays dividing the plane. The initial direction will be stored in rays[0]. */ @@ -89,13 +89,13 @@ public: \param initial_direction A direction denoting one of the rays dividing the cones. This allows arbitary rotations of the rays that divide the plane. (default: positive x-axis) - \param half_yao Indicates whether all the cones are used or just half of - them (default: all cones). + \param cones_selected Indicates whether even, odd or all cones are + selected to construct graph. */ Construct_yao_graph_2 (unsigned int k, Direction_2 initial_direction = Direction_2(1,0), - Half half_yao = ALL_CONES - ): cone_number(k), rays(std::vector(k)), half(half_yao) + Cones_selected cones_selected = ALL_CONES + ): cone_number(k), rays(std::vector(k)), cones_choice(cones_selected) { if (k<2) { @@ -134,8 +134,8 @@ public: unsigned int j; // index of the ccw ray // add edges into the graph for every cone - int new_start = half != ALL_CONES ? half : 0; - int increment = half != ALL_CONES ? 2 : 1; + int new_start = cones_choice != ALL_CONES ? cones_choice : 0; + int increment = cones_choice != ALL_CONES ? 2 : 1; for (i = new_start; i < cone_number; i += increment) { j = (i+1) % cone_number; add_edges_in_cone(rays[i], rays[j], g);