From 6490d2db4add74ff96307988c8f246a884cd83f1 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 2 Jul 2014 02:29:06 +0300 Subject: [PATCH 1/2] [test][is_valid] add one more test case: add a polygon with many holes (important note here: many means more than the number of turns) --- test/algorithms/is_valid.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/algorithms/is_valid.cpp b/test/algorithms/is_valid.cpp index 3d52b4365..03b93bbe5 100644 --- a/test/algorithms/is_valid.cpp +++ b/test/algorithms/is_valid.cpp @@ -579,6 +579,9 @@ void test_open_polygons() // 1st hole touches 2nd hole at two points test::apply(from_wkt("POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 8,2 8,2 1),(2 5,5 8,5 5))"), false); + // polygon with many holes, where the last two touch at two points + test::apply(from_wkt("POLYGON((0 0,20 0,20 20,0 20),(1 18,1 19,2 19,2 18),(3 18,3 19,4 19,4 18),(5 18,5 19,6 19,6 18),(7 18,7 19,8 19,8 18),(9 18,9 19,10 19,10 18),(11 18,11 19,12 19,12 18),(13 18,13 19,14 19,14 18),(15 18,15 19,16 19,16 18),(17 18,17 19,18 19,18 18),(1 1,1 9,9 9,9 8,2 8,2 1),(2 5,5 8,5 5))"), + false); // two holes completely inside exterior ring but touching each // other at a point test::apply(from_wkt("POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,2 9),(1 1,9 2,9 1))"), From bda78a815374a5e712f908587d572f08fff7dc7c Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 2 Jul 2014 02:30:24 +0300 Subject: [PATCH 2/2] [algorithms][is_valid] fix bug in initialization of DFS data for detecting cycles --- .../detail/is_valid/complement_graph.hpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/is_valid/complement_graph.hpp b/include/boost/geometry/algorithms/detail/is_valid/complement_graph.hpp index ba54d42ba..2272bbf32 100644 --- a/include/boost/geometry/algorithms/detail/is_valid/complement_graph.hpp +++ b/include/boost/geometry/algorithms/detail/is_valid/complement_graph.hpp @@ -100,8 +100,8 @@ private: { public: has_cycles_dfs_data(std::size_t num_nodes) - : m_visited(num_nodes) - , m_parent_id(num_nodes) + : m_visited(num_nodes, false) + , m_parent_id(num_nodes, -1) {} inline int parent_id(vertex_handle v) const @@ -139,7 +139,7 @@ private: { vertex_handle v = stack.top(); stack.pop(); - + data.set_visited(v, true); for (typename neighbor_container::const_iterator nit = m_neighbors[v->id()].begin(); @@ -205,15 +205,9 @@ public: inline bool has_cycles() const { - has_cycles_dfs_data data(m_vertices.size()); - // initialize all vertices as non-visited and with no parent set - for (vertex_handle it = m_vertices.begin(); - it != m_vertices.end(); ++it) - { - data.set_visited(it, false); - data.set_parent_id(it, -1); - } + // this is done by the constructor of has_cycles_dfs_data + has_cycles_dfs_data data(m_num_rings + m_num_turns); // for each non-visited vertex, start a DFS from that vertex for (vertex_handle it = m_vertices.begin();