diff --git a/Polygon/include/CGAL/Polygon_2.h b/Polygon/include/CGAL/Polygon_2.h index e4305cccfed..b2b7ab7340a 100644 --- a/Polygon/include/CGAL/Polygon_2.h +++ b/Polygon/include/CGAL/Polygon_2.h @@ -242,8 +242,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..623a8633130 --- /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_2; +typedef Polygon_2::Vertex_circulator Vertex_circulator; + +int main() +{ + std::array points = { Point(0,0), Point(1,0), Point(1,1), Point(0,1) }; + Polygon_2 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; +}