diff --git a/Polygon/include/CGAL/Polygon_2.h b/Polygon/include/CGAL/Polygon_2.h index 987215691ac..9920d8f25f4 100644 --- a/Polygon/include/CGAL/Polygon_2.h +++ b/Polygon/include/CGAL/Polygon_2.h @@ -238,8 +238,11 @@ class Polygon_2 { /// Erases the vertex pointed to by `i`. Vertex_circulator erase(Vertex_circulator i) { - return Vertex_circulator(&d_container, - d_container.erase(i.mod_iterator())); + auto it = d_container.erase(i.mod_iterator()); + if(it == d_container.end()){ + it = d_container.begin(); + } + return Vertex_circulator(&d_container, it); } /// Erases the vertices in the range `[first, last)`. diff --git a/Polygon/test/Polygon/issue7228.cpp b/Polygon/test/Polygon/issue7228.cpp new file mode 100644 index 00000000000..2740f7afa42 --- /dev/null +++ b/Polygon/test/Polygon/issue7228.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef K::Point_2 Point; +typedef CGAL::Polygon_2 Polygon; +typedef Polygon::Vertex_circulator Vertex_circulator; + +int main() +{ + std::array points = { Point(0,0), Point(1,0), Point(1,1), Point(0,1) }; + Polygon poly(points.begin(), points.end()); + + Vertex_circulator vc = poly.vertices_circulator(); + + ++vc; + ++vc; + ++vc; + + vc = poly.erase(vc); + + assert(*vc == Point(0,0)); + + return 0; +}