Opened 9 years ago

Last modified 9 years ago

#9427 new Bugs

svg_mapper bugs

Reported by: yuyoyuppe Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

Code highlighting:

#include <iostream>
#include <fstream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

void main()
{
        typedef boost::geometry::model::d2::point_xy<double> point_type;

        point_type a(10, 10);

        boost::geometry::model::polygon<point_type> b;
        boost::geometry::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", b);

        std::ofstream svg("my_map.svg");
        boost::geometry::svg_mapper<point_type> mapper(svg, 100, 100);

        //mapper.add(a);
        mapper.add(b);

        //mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
        mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2");
}

This code can produce 2 kinds of suspicious behavior:

1)If I output only single point(a), it's coordinates are invalid(svg output fragment: circle cx="-2147483648" cy="-2147483648").
2)If I add polygon to the output(a and b), I get more relevant output, but still invalid(svg output fragment: circle cx="1000" cy="0").

I use msvssp4 with debug-x64 configuration.

Change History (3)

comment:1 by Mateusz Loskot, 9 years ago

I see you've diagnosed the problem well, would you be able to provide patch? It would speed things up a lot.

in reply to:  1 comment:2 by yuyoyuppe, 9 years ago

Replying to mloskot:

I see you've diagnosed the problem well, would you be able to provide patch? It would speed things up a lot.

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]]

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

BOOST_ASSERT_MSG(+std::numeric_limits<type>::infinity() != sx && -std::numeric_limits<type>::infinity() != sx, "svg_mapper cannot contain only one point");

at map_transformer.hpp:121.

And regarding second point, I was wrong because of my own error - not paying enough attention:).

Thank you.

comment:3 by yuyoyuppe, 9 years ago

Also there is more... When using difference 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?

Note: See TracTickets for help on using tickets.