Boost C++ Libraries: Ticket #11470: Invalid results using convex_hull with unsigned integer points coordinates https://svn.boost.org/trac10/ticket/11470 <p> Hi, I think convex_hull algorithm does not support unsigned integer points coordinates. </p> <p> The following code works well with signed integer but return a wrong result for unsigned version : </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;deque&gt; int main() { typedef boost::geometry::model::d2::point_xy&lt;unsigned int&gt; PointInt; typedef boost::geometry::model::polygon&lt;PointInt&gt; polygon_type; polygon_type poly1, convPoly1; polygon_type poly2, convPoly2; boost::geometry::read_wkt("POLYGON((245 143, 243 113, 236 101, 228 100, 222 106, 217 121, 217 144, 220 155, 227 165, 233 166, 237 163, 245 143))", poly1); boost::geometry::convex_hull(poly1, convPoly1); return 0; } </pre><p> Attached file is a representation of input polygon (orange) and output result (blue) curve. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11470 Trac 1.4.3 Eric Noirfalise <eric.noirfalise@…> Fri, 10 Jul 2015 11:18:05 GMT attachment set https://svn.boost.org/trac10/ticket/11470 https://svn.boost.org/trac10/ticket/11470 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">Clipboard02.tif</span> </li> </ul> Ticket Eric Noirfalise <eric.noirfalise@…> Fri, 10 Jul 2015 13:20:21 GMT <link>https://svn.boost.org/trac10/ticket/11470#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11470#comment:1</guid> <description> <p> Ok after some code exploration I think that problem comes from : </p> <pre class="wiki">template &lt; typename CoordinateType, typename PromotedType, typename P1, typename P2, typename P, typename EpsPolicy &gt; static inline PromotedType side_value(P1 const&amp; p1, P2 const&amp; p2, P const&amp; p, EpsPolicy &amp; eps_policy) { CoordinateType const x = get&lt;0&gt;(p); CoordinateType const y = get&lt;1&gt;(p); CoordinateType const sx1 = get&lt;0&gt;(p1); CoordinateType const sy1 = get&lt;1&gt;(p1); CoordinateType const sx2 = get&lt;0&gt;(p2); CoordinateType const sy2 = get&lt;1&gt;(p2); PromotedType const dx = sx2 - sx1; PromotedType const dy = sy2 - sy1; PromotedType const dpx = x - sx1; PromotedType const dpy = y - sy1; eps_policy = EpsPolicy(dx, dy, dpx, dpy); return geometry::detail::determinant&lt;PromotedType&gt; ( dx, dy, dpx, dpy ); } </pre><p> in file boost/geometry/trategies/cartesian/side_by_triangle.hpp </p> <p> In my case : </p> <ul><li><a class="missing wiki">CoordinateType</a> = unsigned int </li><li><a class="missing wiki">PromotedType</a> = double </li></ul><p> So, for example, on line </p> <pre class="wiki">PromotedType const dpy = y - sy1; </pre><p> a case where y &lt; sy1 will lead to wrong result. A simple cast of y to <a class="missing wiki">PromotedType</a> like </p> <pre class="wiki">PromotedType const dpy = PromotedType (y) - sy1; </pre><p> should in my case solve the problem. </p> <p> If my understanding is good, <a class="missing wiki">PromotedType</a> will be the most precise type between double and <a class="missing wiki">CoordinateType</a>. So if I use input unsigned int 64, a similar error can happen and my correction will fail... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 18 Nov 2015 11:06:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11470#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11470#comment:2</guid> <description> <p> Hi, </p> <p> I just come to the news, will that bug be planned for correction ? </p> <p> Regards, Eric Noirfalise </p> </description> <category>Ticket</category> </item> </channel> </rss>