Skip to content

Commit

Permalink
Make read_WKT() work with Multipolygon_with_holes
Browse files Browse the repository at this point in the history
  • Loading branch information
afabri committed Apr 15, 2024
1 parent 92ccdbc commit 2af58ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Polygon/include/CGAL/Multipolygon_with_holes_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Multipolygon_with_holes_2 {

/// polygon with holes type
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<Kernel, Container>;

using value_type = Polygon_with_holes_2;
/// @}

using Polygon_with_holes_container = std::deque<Polygon_with_holes_2>;
Expand Down Expand Up @@ -72,10 +72,19 @@ class Multipolygon_with_holes_2 {

Polygon_with_holes_iterator polygons_with_holes_end() { return m_polygons.end(); }

Polygon_with_holes_iterator begin() { return m_polygons.begin(); }

Polygon_with_holes_iterator end() { return m_polygons.end(); }

Polygon_with_holes_const_iterator polygons_with_holes_begin() const { return m_polygons.begin(); }

Polygon_with_holes_const_iterator polygons_with_holes_end() const { return m_polygons.end(); }

Polygon_with_holes_const_iterator begin() const { return m_polygons.begin(); }

Polygon_with_holes_const_iterator end() const { return m_polygons.end(); }


void add_polygon(const Polygon_2& pgn) { m_polygons.push_back(Polygon_with_holes_2(pgn)); }

void add_polygon(Polygon_2&& pgn) { m_polygons.push_back(Polygon_with_holes_2(std::forward<Polygon_with_holes_2>(pgn))); }
Expand All @@ -84,6 +93,8 @@ class Multipolygon_with_holes_2 {

void add_polygon_with_holes(Polygon_with_holes_2&& pgn) { m_polygons.emplace_back(std::move(pgn)); }

void push_back(const Polygon_with_holes_2& pgn) { m_polygons.push_back(pgn); }

void erase_polygon_with_holes(Polygon_with_holes_iterator pit) { m_polygons.erase(pit); }

void clear() { m_polygons.clear(); }
Expand Down
32 changes: 32 additions & 0 deletions Polygon_repair/examples/Polygon_repair/polygons2multipolygon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <fstream>
#include <deque>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_repair/repair.h>
#include <CGAL/IO/WKT.h>

using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_2 = Kernel::Point_2;
using Polygon_2 = CGAL::Polygon_2<Kernel>;
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<Kernel>;
using Multipolygon_with_holes_2 = CGAL::Multipolygon_with_holes_2<Kernel>;

int main(int argc, char* argv[])
{
std::ifstream in((argc > 1) ? argv[1] : CGAL::data_file_path("wkt/norway-polygons.wkt"));

typedef std::vector<Point_2> MultiPoint;
typedef std::vector<Point_2> LineString;
typedef std::deque<LineString> MultiLineString;

MultiPoint points;
MultiLineString polylines;
Multipolygon_with_holes_2 polygons;
CGAL::IO::read_WKT(in, points,polylines,polygons);

Multipolygon_with_holes_2 mp = CGAL::Polygon_repair::repair(polygons);
CGAL::IO::write_multi_polygon_WKT(std::cout, mp);

return 0;
}

0 comments on commit 2af58ec

Please sign in to comment.