Boost C++ Libraries: Ticket #10647: backlog in for_each_range.hpp causes incorrect result of disjoint https://svn.boost.org/trac10/ticket/10647 <p> simple test program, Polygon poly2 is entirely within the hole in the polygon poly1, the result of disjonit may be true, but is false. </p> <pre class="wiki">#include &lt;boost/geometry.hpp&gt; #include &lt;boost/geometry/geometries/point_xy.hpp&gt; #include &lt;boost/geometry/geometries/polygon.hpp&gt; #include &lt;assert.h&gt; void test_polygon_disjoint() { typedef boost::geometry::model::point&lt;double, 2, boost::geometry::cs::cartesian&gt; Point; boost::geometry::model::polygon&lt;Point&gt; poly1, poly2; boost::geometry::read_wkt("POLYGON((0.0 0.0, 0.0 5.0, 5.0 5.0, 5.0 0.0, 0.0 0.0)(1.0 1.0, 4.0 1.0, 4.0 4.0, 1.0 4.0, 1.0 1.0))", poly1); boost::geometry::correct(poly1); boost::geometry::read_wkt("POLYGON((2.0 2.0, 2.0 3.0, 3.0 3.0, 3.0 2.0, 2.0 2.0))", poly2); boost::geometry::correct(poly2); bool res=boost::geometry::disjoint(poly1,poly2); assert(res==true); // res is false :-( } int main(int argc, char* argv[]) { test_polygon_disjoint(); return 0; } </pre><p> The reason is probably this backlog in boost\geometry\algorithms\detail\for_each_range.hpp </p> <pre class="wiki">... template &lt;typename Polygon, typename Actor&gt; struct fe_range_polygon { static inline void apply(Polygon &amp; polygon, Actor &amp; actor) { actor.apply(exterior_ring(polygon)); // TODO: If some flag says true, also do the inner rings. // for convex hull, it's not necessary } }; ... </pre><p> I created this workaround and disjoint works correctly in this case. </p> <pre class="wiki">template &lt;typename Polygon, typename Actor&gt; struct fe_range_polygon { static inline void apply(Polygon &amp; polygon, Actor &amp; actor) { actor.apply(exterior_ring(polygon)); if (actor.has_within) { Polygon::inner_container_type::const_iterator it=interior_rings(polygon).begin(); for (;it!=interior_rings(polygon).end();++it) { actor.apply(*it); if (actor.has_within) { actor.has_within = false; break; } } } } }; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10647 Trac 1.4.3 awulkiew Fri, 19 Dec 2014 20:28:34 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10647#comment:1 https://svn.boost.org/trac10/ticket/10647#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in 1.57 </p> <p> PR: <a class="ext-link" href="https://github.com/boostorg/geometry/pull/163"><span class="icon">​</span>https://github.com/boostorg/geometry/pull/163</a> </p> Ticket