From 6c35826afdbaafebd4d2b002df7d363c49669ea9 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 3 Jan 2020 10:51:19 +0100 Subject: [PATCH] Fixes and apply to multipolygon --- Stream_support/include/CGAL/IO/WKT.h | 13 +++++++++++-- .../test/Stream_support/test_write_WKT.cpp | 4 +--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Stream_support/include/CGAL/IO/WKT.h b/Stream_support/include/CGAL/IO/WKT.h index 22b134921b0..62809e5b282 100644 --- a/Stream_support/include/CGAL/IO/WKT.h +++ b/Stream_support/include/CGAL/IO/WKT.h @@ -44,7 +44,7 @@ namespace internal { template void pop_back_if_equal_to_front(CGAL::Polygon_2& poly) { - CGAL::Polygon_2::iterator it = poly.end(); + typename CGAL::Polygon_2::iterator it = poly.end(); --it; if( (*poly.begin()) == *it){ poly.erase(it); @@ -233,7 +233,16 @@ read_multi_polygon_WKT( std::istream& in, if(type.substr(0, 12).compare("MULTIPOLYGON")==0) { - boost::geometry::read_wkt(line, gc); + try { + boost::geometry::read_wkt(line, gc); + } catch( ...){ + in.setstate(std::ios::failbit); + return in; + }; + for( typename + internal::Geometry_container::iterator it + = gc.begin(); it != gc.end(); ++it) + pop_back_if_equal_to_front(*it); break; } } diff --git a/Stream_support/test/Stream_support/test_write_WKT.cpp b/Stream_support/test/Stream_support/test_write_WKT.cpp index ac602a67a93..4d690001eb7 100644 --- a/Stream_support/test/Stream_support/test_write_WKT.cpp +++ b/Stream_support/test/Stream_support/test_write_WKT.cpp @@ -60,17 +60,14 @@ Polygon generate_polygon() border.push_back(bl); border.push_back(t); border.push_back(br); - border.push_back(bl); Polygon::Polygon_2 hole1; hole1.push_back(Point((xt+xmax)/2, (ymin+ymid)/2)); hole1.push_back(Point(((xt+xmax)/2), ymid)); hole1.push_back(Point(xt+(xmax-xt)/4, (ymin+ymid)/2)); - hole1.push_back(Point((xt+xmax)/2, (ymin+ymid)/2)); Polygon::Polygon_2 hole2; hole2.push_back(Point((xt+xmin)/2, (ymin+ymid)/2)); hole2.push_back(Point(((xt+xmin)/2), ymid)); hole2.push_back(Point(xmin+(xt-xmin)/4, (ymin+ymid)/2)); - hole2.push_back(Point((xt+xmin)/2, (ymin+ymid)/2)); Polygon::Holes_container holes; holes.push_back(hole1); holes.push_back(hole2); @@ -150,6 +147,7 @@ int main() CGAL::read_polygon_WKT(is, test_poly); is.close(); } + CGAL_assertion(poly == test_poly); MultiPoint pees = generate_multipoint();