Boost C++ Libraries: Ticket #9427: svg_mapper bugs https://svn.boost.org/trac10/ticket/9427 <div class="wikipage" style="font-size: 80%"><p> Code highlighting: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;fstream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry/geometries/point_xy.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry/geometries/polygon.hpp&gt;</span><span class="cp"></span> <span class="kt">void</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">model</span><span class="o">::</span><span class="n">d2</span><span class="o">::</span><span class="n">point_xy</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;</span> <span class="n">point_type</span><span class="p">;</span> <span class="n">point_type</span> <span class="n">a</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">model</span><span class="o">::</span><span class="n">polygon</span><span class="o">&lt;</span><span class="n">point_type</span><span class="o">&gt;</span> <span class="n">b</span><span class="p">;</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">read_wkt</span><span class="p">(</span><span class="s">&quot;POLYGON((0 0,0 7,4 2,2 0,0 0))&quot;</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">ofstream</span> <span class="n">svg</span><span class="p">(</span><span class="s">&quot;my_map.svg&quot;</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">svg_mapper</span><span class="o">&lt;</span><span class="n">point_type</span><span class="o">&gt;</span> <span class="n">mapper</span><span class="p">(</span><span class="n">svg</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">);</span> <span class="c1">//mapper.add(a);</span> <span class="n">mapper</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">);</span> <span class="c1">//mapper.map(a, &quot;fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2&quot;);</span> <span class="n">mapper</span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="s">&quot;fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2&quot;</span><span class="p">);</span> <span class="p">}</span> </pre></div></div></div><p> This code can produce 2 kinds of suspicious behavior:<br /> </p> <p> 1)If I output only single point(a), it's coordinates are invalid(svg output fragment: <em>circle cx="-2147483648" cy="-2147483648"</em>).<br /> 2)If I add polygon to the output(a and b), I get more relevant output, but still invalid(svg output fragment: <em>circle cx="1000" cy="0"</em>). </p> <p> I use msvssp4 with debug-x64 configuration. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9427 Trac 1.4.3 Mateusz Loskot Sat, 23 Nov 2013 10:19:33 GMT <link>https://svn.boost.org/trac10/ticket/9427#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9427#comment:1</guid> <description> <p> I see you've diagnosed the problem well, would you be able to provide patch? It would speed things up a lot. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>yuyoyuppe</dc:creator> <pubDate>Sat, 23 Nov 2013 12:28:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9427#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9427#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9427#comment:1" title="Comment 1">mloskot</a>: </p> <blockquote class="citation"> <p> I see you've diagnosed the problem well, would you be able to provide patch? It would speed things up a lot. </p> </blockquote> <p> I did a quick debugging and discovered that the reason of the first case behavior was initializing transformation matrix(svg_mapper.hpp:248) with invalid values, because it uses bounding box, which has zero-length side if only one point was supplied to svg_mapper instance. Which is why division by zero happenes at map_transformer.hpp:119-120.[[BR]] </p> <p> Since the situation where svg_mapper object'll have only one point is a degenerated case, I think it's more like a design issue, than a bug. However it's possible to include this case by adding something like this </p> <pre class="wiki">BOOST_ASSERT_MSG(+std::numeric_limits&lt;type&gt;::infinity() != sx &amp;&amp; -std::numeric_limits&lt;type&gt;::infinity() != sx, "svg_mapper cannot contain only one point"); </pre><p> at map_transformer.hpp:121. </p> <p> And regarding second point, I was wrong because of my own error - not paying enough attention:).<br /> </p> <p> Thank you. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>yuyoyuppe</dc:creator> <pubDate>Sat, 23 Nov 2013 12:50:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9427#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9427#comment:3</guid> <description> <p> Also there is more... When using <a href="http://www.boost.org/doc/libs/1_54_0/libs/geometry/doc/html/geometry/reference/algorithms/difference.html/">difference</a> in case of geometry1 object is the same as output_collection object, difference will produce incorrect output. May be it needs some assert or documentation note too? </p> </description> <category>Ticket</category> </item> </channel> </rss>