From 5899ac451feebc4b0a0cbacd4bc6bfddbdc23fdf Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 28 Jan 2015 12:40:46 +0200 Subject: [PATCH 1/3] [algorithms][is_simple] fix bug in is_simple(multilinestring): is_simple was considering a simple closed linestring (living inside a multilinestring) as non-simple because it was wrongly detecting the turn associated with the first and last (closing) point as an unacceptable turn; fix: allow such turns acceptable; --- .../algorithms/detail/is_simple/linear.hpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/boost/geometry/algorithms/detail/is_simple/linear.hpp b/include/boost/geometry/algorithms/detail/is_simple/linear.hpp index f2efcb309..90810d27e 100644 --- a/include/boost/geometry/algorithms/detail/is_simple/linear.hpp +++ b/include/boost/geometry/algorithms/detail/is_simple/linear.hpp @@ -93,6 +93,19 @@ private: || geometry::equals(point, range::back(linestring)) ); } + template + static inline bool is_closing_point_of(Point const& point, + Linestring const& linestring) + { + BOOST_ASSERT( boost::size(linestring) > 1 ); + return + geometry::equals(range::front(linestring), + range::back(linestring)) + && + geometry::equals(range::front(linestring), point) + ; + } + template static inline bool have_same_boundary_points(Linestring1 const& ls1, Linestring2 const& ls2) @@ -130,6 +143,13 @@ private: range::at(m_multilinestring, turn.operations[1].seg_id.multi_index); + if (turn.operations[0].seg_id.multi_index + == turn.operations[1].seg_id.multi_index) + { + BOOST_ASSERT(is_closing_point_of(turn.point, ls1)); + return true; + } + return is_boundary_point_of(turn.point, ls1) && is_boundary_point_of(turn.point, ls2) From 300577d68e45d2bbe151499a093019d8e79c19b5 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 28 Jan 2015 12:47:01 +0200 Subject: [PATCH 2/3] [test][algorithms][is_simple] add more test cases including one that was failing before the recent bug fix --- test/algorithms/is_simple.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/algorithms/is_simple.cpp b/test/algorithms/is_simple.cpp index 34ec07e54..e4acf36e5 100644 --- a/test/algorithms/is_simple.cpp +++ b/test/algorithms/is_simple.cpp @@ -161,6 +161,7 @@ BOOST_AUTO_TEST_CASE( test_is_simple_linestring ) // simple closed linestrings test_simple(from_wkt("LINESTRING(0 0,1 0,1 1,0 0)"), true); test_simple(from_wkt("LINESTRING(0 0,1 0,1 1,0 1,0 0)"), true); + test_simple(from_wkt("LINESTRING(0 0,10 0,10 10,0 10,0 0)"), true); // non-simple linestrings test_simple(from_wkt("LINESTRING(0 0,1 0,0 0)"), false); @@ -173,6 +174,7 @@ BOOST_AUTO_TEST_CASE( test_is_simple_linestring ) test_simple(from_wkt("LINESTRING(0 0,3 0,5 0,4 0,2 0)"), false); test_simple(from_wkt("LINESTRING(0 0,3 0,2 0,5 0)"), false); test_simple(from_wkt("LINESTRING(0 0,2 0,2 2,1 0,0 0)"), false); + test_simple(from_wkt("LINESTRING(0 0,0 10,5 10,0 0,10 10,10 5,10 0,0 0)"), false); } BOOST_AUTO_TEST_CASE( test_is_simple_multilinestring ) @@ -208,6 +210,7 @@ BOOST_AUTO_TEST_CASE( test_is_simple_multilinestring ) true); test_simple(from_wkt("MULTILINESTRING((0 0,1 0),(0 0,0 1),(0 0,-1 0),(0 0,0 -1))"), true); + test_simple(from_wkt("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0))"), true); // non-simple multilinestrings test_simple(from_wkt("MULTILINESTRING((0 0,2 2),(0 0,2 2))"), false); @@ -246,6 +249,7 @@ BOOST_AUTO_TEST_CASE( test_is_simple_multilinestring ) false); test_simple(from_wkt("MULTILINESTRING((0 0,1 0,1 1,0 1,0 0),(-1 -1,-1 0,0 0,0 -1,-1 -1))"), false); + test_simple(from_wkt("MULTILINESTRING((0 0,0 10,5 10,0 0,10 10,10 5,10 0,0 0))"), false); } BOOST_AUTO_TEST_CASE( test_is_simple_areal ) From c2589a451a2784ffbb6a710bbbc609b37b68de4e Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 28 Jan 2015 12:48:33 +0200 Subject: [PATCH 3/3] [doc][release notes] mention bug fix in is_simple about simple closed linestring in multilinestrings --- doc/release_notes.qbk | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/release_notes.qbk b/doc/release_notes.qbk index 86d0b8743..1138591ea 100644 --- a/doc/release_notes.qbk +++ b/doc/release_notes.qbk @@ -54,6 +54,7 @@ * Bug in buffers for joins with a imited number of points * Bug in buffers for joins with large buffer distances * Bug in closing iterator not working properly when the input range is empty +* Bug in is_simple, not handling properly closed simple linestrings within multilinestrings [/=================] [heading Boost 1.57]