Boost C++ Libraries: Ticket #9768: difference of multi-polygon and box returns multi-polygon with redundant points https://svn.boost.org/trac10/ticket/9768 <p> boost::geometry::difference should not add redundant points to a polygon. In the following example I subtract an empty box from a polygon, and the result ends up representing the empty box even though obviously it should not. My polygon type is <strong>oriented 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(((249 509,5103 509,5103 3566,249 3566)))" ) - _TRect&lt;int&gt;( "POLYGON((1220 1019,1220 1019,1220 1019,1220 1019,1220 1019))" ); </pre><p> This is the resulting multi-polygon, with the additional/redundant empty box: </p> <pre class="wiki">MULTIPOLYGON(((249 509,5103 509,5103 3566,249 3566),(1220 1019,1220 1019,1220 1019))) </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::unique( polygonOut ); return polygonOut; } </pre><p> These are the traits as defined to use _TRect&lt;...&gt; as a boost::geometry box: </p> <pre class="wiki">namespace boost { namespace geometry { namespace traits { template&lt;typename T&gt; struct tag&lt; _TRect&lt;T&gt; &gt; { typedef box_tag type; }; template&lt;typename T&gt; struct point_type&lt; _TRect&lt;T&gt; &gt; { typedef _TPoint&lt;T&gt; type; }; template&lt;typename T, std::size_t Dimension&gt; struct indexed_access&lt; _TRect&lt;T&gt;, min_corner, Dimension &gt; { typedef typename geometry::coordinate_type&lt; _TPoint&lt;T&gt; &gt;::type coordinate_type; static inline coordinate_type get(_TRect&lt;T&gt; const&amp; rect) { return geometry::get&lt;Dimension&gt;( rect.TopLeft() ); } static inline void set(_TRect&lt;T&gt;&amp; rect, coordinate_type const&amp; value) { geometry::set&lt;Dimension&gt;( rect.TopLeft(), value ); } }; template&lt;typename T, std::size_t Dimension&gt; struct indexed_access&lt; _TRect&lt;T&gt;, max_corner, Dimension &gt; { typedef typename geometry::coordinate_type&lt; _TPoint&lt;T&gt; &gt;::type coordinate_type; static inline coordinate_type get(_TRect&lt;T&gt; const&amp; rect) { return geometry::get&lt;Dimension&gt;( rect.BottomRight() ); } static inline void set(_TRect&lt;T&gt;&amp; rect, coordinate_type const&amp; value) { geometry::set&lt;Dimension&gt;( rect.BottomRight(), value ); } }; } } } // namespace boost::geometry::traits </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9768 Trac 1.4.3 vschoech@… Mon, 13 Oct 2014 11:23:19 GMT version changed https://svn.boost.org/trac10/ticket/9768#comment:1 https://svn.boost.org/trac10/ticket/9768#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.55.0</span> → <span class="trac-field-new">Boost 1.56.0</span> </li> </ul> <p> Originally filed for 1.55.0, still present in 1.56.0. </p> Ticket Barend Gehrels Wed, 26 Jun 2019 10:14:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9768#comment:2 https://svn.boost.org/trac10/ticket/9768#comment:2 <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">duplicate</span> </li> </ul> <p> Transfered to <a class="ext-link" href="https://github.com/boostorg/geometry/issues/602"><span class="icon">​</span>https://github.com/boostorg/geometry/issues/602</a> </p> Ticket