Skip to content

Commit 9408024

Browse files
committedFeb 10, 2023
Merge pull request CGAL#7230 from afabri/Polygon_2-erase_circulator-GF
Polygon: Fix erase(Vertex_circulator)
2 parents d979e07 + 0379f9c commit 9408024

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
 

‎Polygon/include/CGAL/Polygon_2.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,11 @@ class Polygon_2 {
242242
/// Erases the vertex pointed to by `i`.
243243
Vertex_circulator erase(Vertex_circulator i)
244244
{
245-
return Vertex_circulator(&d_container,
246-
d_container.erase(i.mod_iterator()));
245+
auto it = d_container.erase(i.mod_iterator());
246+
if(it == d_container.end()){
247+
it = d_container.begin();
248+
}
249+
return Vertex_circulator(&d_container, it);
247250
}
248251

249252
/// Erases the vertices in the range `[first, last)`.

‎Polygon/test/Polygon/issue7228.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <CGAL/Simple_cartesian.h>
2+
#include <CGAL/Polygon_2.h>
3+
4+
#include <vector>
5+
#include <array>
6+
#include <cassert>
7+
8+
typedef CGAL::Simple_cartesian<double> K;
9+
typedef K::Point_2 Point;
10+
typedef CGAL::Polygon_2<K> Polygon_2;
11+
typedef Polygon_2::Vertex_circulator Vertex_circulator;
12+
13+
int main()
14+
{
15+
std::array<Point,4> points = { Point(0,0), Point(1,0), Point(1,1), Point(0,1) };
16+
Polygon_2 poly(points.begin(), points.end());
17+
18+
Vertex_circulator vc = poly.vertices_circulator();
19+
20+
++vc;
21+
++vc;
22+
++vc;
23+
24+
vc = poly.erase(vc);
25+
26+
assert(*vc == Point(0,0));
27+
28+
return 0;
29+
}

0 commit comments

Comments
 (0)