From 9afcd23be8716bd52a723279c2ad4db91b4e1aef Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 3 Aug 2018 11:24:47 +0200 Subject: [PATCH] Implement the check that avoids to insert a constraint twice --- .../CGAL/Constrained_triangulation_plus_2.h | 2 +- .../CGAL/Polyline_constraint_hierarchy_2.h | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Triangulation_2/include/CGAL/Constrained_triangulation_plus_2.h b/Triangulation_2/include/CGAL/Constrained_triangulation_plus_2.h index 952bf614e56..32aba4bff77 100644 --- a/Triangulation_2/include/CGAL/Constrained_triangulation_plus_2.h +++ b/Triangulation_2/include/CGAL/Constrained_triangulation_plus_2.h @@ -265,7 +265,7 @@ public: { // protects against inserting a zero length constraint if(va == vb){ - return Constraint_id(NULL); + return Constraint_id(NULL); } // protects against inserting twice the same constraint Constraint_id cid = hierarchy.insert_constraint(va, vb); diff --git a/Triangulation_2/include/CGAL/Polyline_constraint_hierarchy_2.h b/Triangulation_2/include/CGAL/Polyline_constraint_hierarchy_2.h index a7ae9e9eda2..f667ab3d3f7 100644 --- a/Triangulation_2/include/CGAL/Polyline_constraint_hierarchy_2.h +++ b/Triangulation_2/include/CGAL/Polyline_constraint_hierarchy_2.h @@ -191,9 +191,10 @@ private: Compare comp; Constraint_set constraint_set; Sc_to_c_map sc_to_c_map; - std::map, - Constraint_id, - Pair_compare> constraint_map; + typedef std::map, + Constraint_id, + Pair_compare> Constraint_map; + Constraint_map constraint_map; public: Polyline_constraint_hierarchy_2(const Compare& comp) @@ -866,6 +867,14 @@ typename Polyline_constraint_hierarchy_2::Vertex_list* Polyline_constraint_hierarchy_2:: insert_constraint(T va, T vb){ Edge he = make_edge(va, vb); + + // First, check if the constraint was already inserted. + // If it was not, then the iterator to the lower bound will serve as + // the hint of the insertion. + typename Constraint_map::iterator c_map_it = constraint_map.lower_bound(he); + if(c_map_it != constraint_map.end() && he == c_map_it->first) + return 0; + Vertex_list* children = new Vertex_list; Context_list* fathers; @@ -885,7 +894,8 @@ insert_constraint(T va, T vb){ ctxt.pos = children->skip_begin(); fathers->push_front(ctxt); - constraint_map[he] = children; + constraint_map.insert(c_map_it, + typename Constraint_map::value_type(he, children)); return children; }