Polygon: Fix erase(Vertex_circulator)

This commit is contained in:
Andreas Fabri 2023-01-31 08:36:31 +00:00
parent 3cabebf827
commit 81f127d50c
2 changed files with 34 additions and 2 deletions

View File

@ -238,8 +238,11 @@ class Polygon_2 {
/// Erases the vertex pointed to by `i`. /// Erases the vertex pointed to by `i`.
Vertex_circulator erase(Vertex_circulator i) Vertex_circulator erase(Vertex_circulator i)
{ {
return Vertex_circulator(&d_container, auto it = d_container.erase(i.mod_iterator());
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)`. /// Erases the vertices in the range `[first, last)`.

View File

@ -0,0 +1,29 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polygon_2.h>
#include <vector>
#include <array>
#include <cassert>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point;
typedef CGAL::Polygon_2<K> Polygon;
typedef Polygon::Vertex_circulator Vertex_circulator;
int main()
{
std::array<Point,4> 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;
}