Boost C++ Libraries: Ticket #9942: Result of difference of multi-polygons contains spike https://svn.boost.org/trac10/ticket/9942 <p> boost::geometry::difference(...) should not introduce spikes to a polygon. In the following example I subtract a multi-polygon from another multi-polygon, and the result contains a spike. My polygon type is oriented <strong>counter-clockwise</strong> and <strong>not closed</strong>, my point type is based on <strong>int</strong>. </p> <p> This is the data used as input to difference: </p> <pre class="wiki">_TPolygon&lt;int&gt; const polygon = _TPolygon&lt;int&gt;( "MULTIPOLYGON(((2058 1761,1996 1700,1660 1370,1324 1040,982 1148,881 981,2644 981,2338 1982)),((1996 1760,2338 2078,2674 1010,3010 1160,3254 2085,3352 2522,3427 2562,3688 2930,3688 2924,3688 2702,3439 2568,3352 2444,3218 1926,3010 998,2959 981,3773 981,3773 3702,732 3702,732 981,770 981,982 1310,1324 1148,1660 1442,1697 1472,1660 1436,1698 1473,1697 1472)))" ) - _TPolygon&lt;int&gt;( "MULTIPOLYGON(((646 932,646 788,870 1136)),((3032 1096,3010 1040,2981 988,3010 998)),((3688 2702,3352 2522,3032 1096,3352 1916,3688 2018)),((2981 988,2674 884,2338 1982,1996 1712,1660 1442,1324 1148,982 1310,870 1136,982 1238,1324 1136,1660 1304,1996 1460,2338 1610,2674 434)))" ) </pre><p> This is the resulting multi-polygon, with the spike: </p> <pre class="wiki">MULTIPOLYGON(((2338 1982,2058 1761,2057 1760)),((2517 981,2338 1610,1996 1460,1660 1304,1523 1235,1324 1040,982 1148,881 981)),((1695 1470,1697 1472,1996 1760,2338 2078,2674 1010,3010 1160,3253 2083,3352 2522,3427 2562,3688 2930,3688 2924,3688 2702,3688 2018,3352 1916,3032 1096,3219 1933,3218 1926,3031 1095,3032 1096,3010 998,2981 988,2959 981,2960 981,2981 988,2977 981,3773 981,3773 3702,732 3702,732 1010,869 1135,982 1310,1324 1148,1660 1442,1697 1472))) </pre><p> This is the multi-polygon I'd expect to see, without the spike: </p> <pre class="wiki">MULTIPOLYGON(((2338 1982,2058 1761,2057 1760)),((2517 981,2338 1610,1996 1460,1660 1304,1523 1235,1324 1040,982 1148,881 981)),((1996 1760,2338 2078,2674 1010,3010 1160,3253 2083,3352 2522,3427 2562,3688 2930,3688 2924,3688 2702,3688 2018,3352 1916,3032 1096,3219 1933,3218 1926,3031 1095,3032 1096,3010 998,2981 988,2959 981,2960 981,2981 988,2977 981,3773 981,3773 3702,732 3702,732 1010,869 1135,982 1310,1324 1148,1660 1442,1697 1472))) </pre><p> This is my code that wraps boost::geometry to implement the operator used above: </p> <pre class="wiki">template&lt;typename T&gt; template&lt;typename Geometry&gt; _TPolygon&lt; T &gt; _TPolygon&lt; T &gt;::operator-(Geometry geometry) const { _TPolygon&lt; T &gt; polygonOut; boost::geometry::difference(*this, geometry, polygonOut); // the following line fixes the problem but should not be necessary //boost::geometry::remove_spikes( polygonOut ); return polygonOut; } </pre><p> (I apologize for the huge amount of nodes in the polygons. These are real life examples taken directly from our system. I admit that I did not try to boil them down to the minimal set of nodes needed to reproduce the problem.) </p> <p> Releated issues: </p> <p> <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/9768"><span class="icon">​</span>difference of multi-polygon and box returns multi-polygon with redundant points</a> </p> <p> <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/9828"><span class="icon">​</span>boost::geometry::union_(...) creates redundant closing point</a> </p> <p> <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/9871"><span class="icon">​</span>remove_spikes does not remove spike</a> </p> <p> Note to self: RT<a class="new ticket" href="https://svn.boost.org/trac10/ticket/9769" title="#9769: Feature Requests: Add conversion from boost::exception_ptr to std::exception_ptr when ... (new)">#9769</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9942 Trac 1.4.3 vschoech@… Tue, 22 Sep 2015 08:17:26 GMT <link>https://svn.boost.org/trac10/ticket/9942#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9942#comment:1</guid> <description> <p> The problem is still present in boost 1.59.0. </p> </description> <category>Ticket</category> </item> <item> <author>Volker Schöch <vschoech@…></author> <pubDate>Thu, 12 Jan 2017 13:20:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9942#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9942#comment:2</guid> <description> <p> This problem is still present in boost 1.63.0. </p> </description> <category>Ticket</category> </item> <item> <author>Volker Schöch <vschoech@…></author> <pubDate>Thu, 04 Jan 2018 16:09:17 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/9942#comment:3 https://svn.boost.org/trac10/ticket/9942#comment:3 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.55.0</span> → <span class="trac-field-new">Boost 1.66.0</span> </li> </ul> <p> Still present in boost 1.66.0. </p> Ticket Volker Schöch <vschoech@…> Mon, 25 Jun 2018 07:32:24 GMT <link>https://svn.boost.org/trac10/ticket/9942#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9942#comment:4</guid> <description> <p> No longer reproducible in 1.67.0. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Barend Gehrels</dc:creator> <pubDate>Mon, 25 Jun 2018 18:32:56 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/9942#comment:5 https://svn.boost.org/trac10/ticket/9942#comment:5 <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> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.67.0</span> </li> </ul> <p> Thanks for verifying! </p> Ticket