Boost C++ Libraries: Ticket #10658: sym_difference yields bad result for int polygons https://svn.boost.org/trac10/ticket/10658 <p> My "_TPolygon" type is actually a <strong>multi-polygon</strong>, based on a polygon type that is oriented <strong>counter-clockwise</strong> and <strong>open</strong> (not closed). Please consider the following example, which apparently works fine: </p> <pre class="wiki">_TPolygon&lt;double&gt; polygonA; // _TPolygon&lt;...&gt; is actually a MULTIPOLYGON, with polygons oriented COUNTER-CLOCKWISE and OPEN (not closed). boost::geometry::read_wkt("MULTIPOLYGON(((516 1608,1308 1932,2094 2466,2094 32767,516 32767,516 1608)))", polygonA); // does not throw boost::geometry::correct(polygonA); // read_wkt(...) does not deal correctly with closing point _TPolygon&lt;double&gt; polygonB; boost::geometry::read_wkt("MULTIPOLYGON(((516 2484,1308 3066,2094 3150,2094 32767,516 32767,516 2484)))", polygonB); // does not throw boost::geometry::correct(polygonB); // read_wkt(...) does not deal correctly with closing point _TPolygon&lt;double&gt; polygonC; boost::geometry::sym_difference(polygonA, polygonB, polygonC); // does not throw // polygonC is now "MULTIPOLYGON(((516 2484,516 1608,1308 1932,2094 2466,2094 3150,1308 3066,516 2484)))" </pre><p> Now, simply replace <strong>double</strong> by <strong>int</strong>: </p> <pre class="wiki">_TPolygon&lt;int&gt; polygonA; // _TPolygon&lt;...&gt; is actually a MULTIPOLYGON, with polygons oriented COUNTER-CLOCKWISE and OPEN (not closed). boost::geometry::read_wkt("MULTIPOLYGON(((516 1608,1308 1932,2094 2466,2094 32767,516 32767,516 1608)))", polygonA); // does not throw boost::geometry::correct(polygonA); // read_wkt(...) does not deal correctly with closing point _TPolygon&lt;int&gt; polygonB; boost::geometry::read_wkt("MULTIPOLYGON(((516 2484,1308 3066,2094 3150,2094 32767,516 32767,516 2484)))", polygonB); // does not throw boost::geometry::correct(polygonB); // read_wkt(...) does not deal correctly with closing point _TPolygon&lt;int&gt; polygonC; boost::geometry::sym_difference(polygonA, polygonB, polygonC); // does not throw // polygonC is now "MULTIPOLYGON(((516 2484,516 1608,1308 1932,2094 2466,2094 *!*32725*!*,1308 3066,516 2484)))" </pre><p> As you can see, one value is completely off. This seems to happen reliably whenever the input is based on int and contains large numbers. However, the particular example <strong>worked well with boost 1.55.0</strong>. </p> <p> This issue may be related to Ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/8380" title="#8380: Bugs: sym_difference yields bad result for large numbers (new)">#8380</a>. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10658 Trac 1.4.3 Volker Schöch <vschoech@…> Tue, 18 Nov 2014 14:21:14 GMT <link>https://svn.boost.org/trac10/ticket/10658#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10658#comment:1</guid> <description> <p> Note for think-cell: RT 10356 </p> </description> <category>Ticket</category> </item> <item> <author>Volker Schöch <vschoech@…></author> <pubDate>Tue, 18 Nov 2014 14:22:38 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/10658#comment:2 https://svn.boost.org/trac10/ticket/10658#comment:2 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.56.0</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> </ul> <p> Problem is still present in 1.57.0. </p> Ticket mkaravel Sat, 28 Mar 2015 18:56:53 GMT milestone changed; cc set https://svn.boost.org/trac10/ticket/10658#comment:3 https://svn.boost.org/trac10/ticket/10658#comment:3 <ul> <li><strong>cc</strong> <span class="trac-author">mkaravel</span> added </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.58.0</span> </li> </ul> <p> The problem was in the computation of the intersection points. In particular, integer overflow was taking place, yielding the wrong results. </p> <p> The problem has been fixed by locally promoting the coordinates to a number type with increased precision, thus avoiding the overflow. </p> Ticket mkaravel Sat, 28 Mar 2015 18:57:59 GMT <link>https://svn.boost.org/trac10/ticket/10658#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10658#comment:4</guid> <description> <p> See also tickets <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/10835" title="#10835: Bugs: difference of multilinestring and polygon yields wrong result (closed: fixed)">#10835</a> and <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/11121" title="#11121: Bugs: Invalid result of difference() for integral coordinates. (closed: fixed)">#11121</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>mkaravel</dc:creator> <pubDate>Sat, 28 Mar 2015 18:58:22 GMT</pubDate> <title>status changed; resolution set; cc deleted https://svn.boost.org/trac10/ticket/10658#comment:5 https://svn.boost.org/trac10/ticket/10658#comment:5 <ul> <li><strong>cc</strong> <span class="trac-author">mkaravel</span> removed </li> <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> Ticket vschoech@… Mon, 21 Sep 2015 14:37:41 GMT <link>https://svn.boost.org/trac10/ticket/10658#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10658#comment:6</guid> <description> <p> A related issue came up in boost 1.59.0, see Ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/11675" title="#11675: Bugs: sym_difference yields bad result for int polygons (new)">#11675</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>