diff --git a/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h b/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h index f6435051313..76f7468d469 100644 --- a/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h +++ b/Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h @@ -143,10 +143,9 @@ public: } // endpoints of constraints are unremovable - // vertices which have more than 1 constraint passing through are unremovable + // vertices which are not endpoint and have != 2 incident constrained edges are unremovable void initialize_unremovable() { - std::unordered_map degrees; Constraint_iterator cit = pct.constraints_begin(), e = pct.constraints_end(); for(; cit!=e; ++cit){ Constraint_id cid = *cit; @@ -155,18 +154,30 @@ public: (*it)->set_removable(false); ++it; for(; it != ite; ++it){ - Vertex_handle vh = *it; - ++degrees[vh]; - if((boost::next(it) != ite) && (boost::prior(it)== boost::next(it))){ - (*it)->set_removable(false); + if(boost::next(it) != ite){ + Vertex_handle vp = *boost::prior(it), vn = *boost::next(it); + if(vp == vn){ + (*it)->set_removable(false); + } } } it = boost::prior(it); (*it)->set_removable(false); } + std::unordered_map degrees; + for (Constrained_edges_iterator it = pct.constrained_edges_begin(); it != pct.constrained_edges_end(); ++it) { + Edge e = *it; + Face_handle fh = e.first; + int ei = e.second; + Vertex_handle vh = fh->vertex(pct.cw(ei)); + ++degrees[vh]; + vh = fh->vertex(pct.ccw(ei)); + ++degrees[vh]; + } + for(Finite_vertices_iterator it = pct.finite_vertices_begin(); it != pct.finite_vertices_end(); ++it){ - if( it->is_removable() && (degrees[it] > 1) ){ + if( it->is_removable() && (degrees[it] != 2) ){ it->set_removable(false); } }