diff --git a/Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h b/Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h index 82270ff35f2..011b79896d7 100644 --- a/Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h +++ b/Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -39,10 +40,16 @@ public: //! void add_elements() { clear(); + m_visited.clear(); + + std::random_device rd; + m_rng.seed(rd()); + m_uni = std::uniform_int_distribution(0, 255); + if (m_arr.is_empty()) return; for (auto it = m_arr.unbounded_faces_begin(); it != m_arr.unbounded_faces_end(); ++it) - add_face(it, Face_const_handle()); + add_face(it); // Add edges that do not separe faces. for (auto it = m_arr.edges_begin(); it != m_arr.edges_end(); ++it) @@ -51,6 +58,8 @@ public: // Add all points for (auto it = m_arr.vertices_begin(); it != m_arr.vertices_end(); ++it) draw_point(it->point()); + + m_visited.clear(); } protected: @@ -98,7 +107,7 @@ protected: //! virtual void draw_region(Ccb_halfedge_const_circulator circ) { - CGAL::IO::Color color(std::rand()%256, std::rand()%256, std::rand()%256); + CGAL::IO::Color color(m_uni(m_rng), m_uni(m_rng), m_uni(m_rng)); this->face_begin(color); auto ext = find_smallest(circ); @@ -128,27 +137,25 @@ protected: virtual void draw_point(const Point& p) { this->add_point(p); } //! - void add_ccb(Ccb_halfedge_const_circulator circ, Face_const_handle parent) { - std::unordered_map visited; + void add_ccb(Ccb_halfedge_const_circulator circ) { auto face = circ->face(); auto curr = circ; do { auto new_face = curr->twin()->face(); - if ((new_face == face) || (new_face == parent)) continue; - if (visited.find(new_face) != visited.end()) continue; - visited[new_face] = true; - add_face(new_face, face); + if (m_visited.find(new_face) != m_visited.end()) continue; + m_visited[new_face] = true; + add_face(new_face); } while (++curr != circ); } //! - void add_face(Face_const_handle face, Face_const_handle parent) { + void add_face(Face_const_handle face) { for (auto it = face->inner_ccbs_begin(); it != face->inner_ccbs_end(); ++it) - add_ccb(*it, parent); + add_ccb(*it); for (auto it = face->outer_ccbs_begin(); it != face->outer_ccbs_end(); ++it) { - add_ccb(*it, parent); + add_ccb(*it); draw_region(*it); } } @@ -172,6 +179,12 @@ protected: protected: //! The arrangement to draw const Arr& m_arr; + + std::unordered_map m_visited; + + std::mt19937 m_rng; + std::uniform_int_distribution m_uni; // guaranteed unbiased + }; //! Basic viewer of a 2D arrangement. @@ -225,7 +238,9 @@ public: //! virtual void draw_region(Ccb_halfedge_const_circulator circ) { - CGAL::IO::Color color(std::rand()%256, std::rand()%256, std::rand()%256); + auto& uni = this->m_uni; + auto& rng = this->m_rng; + CGAL::IO::Color color(uni(rng), uni(rng), uni(rng)); this->face_begin(color); const auto* traits = this->m_arr.geometry_traits(); @@ -242,7 +257,9 @@ public: curr = curr->twin()->next(); std::vector polyline; - approx(curr->curve(), std::back_inserter(polyline), 10); + double density(10); + bool l2r = curr->direction() == ARR_LEFT_TO_RIGHT; + approx(std::back_inserter(polyline), density, curr->curve(), l2r); auto it = polyline.begin(); auto prev = it++; for (; it != polyline.end(); prev = it++) { @@ -260,8 +277,8 @@ public: const auto* traits = this->m_arr.geometry_traits(); auto approx = traits->approximate_2_object(); std::vector polyline; - approx(curve, std::back_inserter(polyline), 10); - + double density(10); + approx(std::back_inserter(polyline), density, curve); auto it = polyline.begin(); auto prev = it++; for (; it != polyline.end(); prev = it++) this->add_segment(*prev, *it);