Boost C++ Libraries: Ticket #11121: Invalid result of difference() for integral coordinates. https://svn.boost.org/trac10/ticket/11121 <p> For polygons: </p> <pre class="wiki">green = "POLYGON((-8042 -1485,-8042 250,-8042 250,15943 254,15943 -1485,-8042 -1485))", blue = "POLYGON((-7901 -1485,-7901 529,-7901 529, 15802 544, 15802 -1485, -7901 -1485))" </pre><p> The result of difference(green, blue) and/or difference(blue, green) is invalid if the polygons use <code>int</code> coordinate type. </p> <p> I think it may be related to get_turns/cart_intersect and ratios/fractions but it needs further investigation. I noticed that turns has wrong coordinates, always endpoints of segments are picked as if internally ratios were always truncated to 0. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11121 Trac 1.4.3 mkaravel Sat, 28 Mar 2015 18:59:25 GMT status, milestone changed; cc, resolution set https://svn.boost.org/trac10/ticket/11121#comment:1 https://svn.boost.org/trac10/ticket/11121#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">mkaravel</span> added </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> <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> <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/10658" title="#10658: Bugs: sym_difference yields bad result for int polygons (closed: fixed)">#10658</a>. </p> Ticket