Merge branch 'master' into geometry_cleanup

This commit is contained in:
Artem Pavlenko 2011-12-09 11:43:51 +00:00
commit 4ca89c4801
2 changed files with 94 additions and 12 deletions

View file

@ -30,7 +30,6 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/util/vertex_iterator.hpp> #include <mapnik/util/vertex_iterator.hpp>
#include <mapnik/util/container_adapter.hpp> #include <mapnik/util/container_adapter.hpp>
// boost // boost
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/spirit/include/karma.hpp> #include <boost/spirit/include/karma.hpp>
@ -38,6 +37,8 @@
#include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_function.hpp> #include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/home/phoenix/statement/if.hpp>
#include <boost/fusion/include/boost_tuple.hpp>
//#define BOOST_SPIRIT_USE_PHOENIX_V3 1 //#define BOOST_SPIRIT_USE_PHOENIX_V3 1
@ -46,20 +47,100 @@ namespace mapnik { namespace util {
namespace karma = boost::spirit::karma; namespace karma = boost::spirit::karma;
namespace phoenix = boost::phoenix; namespace phoenix = boost::phoenix;
template <typename OutputIterator> namespace detail {
bool generate_svg (OutputIterator sink, mapnik::geometry_type const& geom) struct get_type
{ {
using boost::spirit::karma::double_; template <typename T>
using boost::spirit::karma::uint_; struct result { typedef int type; };
using boost::spirit::karma::generate;
return generate (sink, int operator() (geometry_type const& geom) const
// begin grammar {
((&uint_(mapnik::SEG_MOVETO) << 'M' | 'L') return (int)geom.type();
<< " " << double_ << " " << double_) % ' ' }
// end grammar };
, geom);
struct get_first
{
template <typename T>
struct result { typedef geometry_type::value_type const type; };
geometry_type::value_type const operator() (geometry_type const& geom) const
{
geometry_type::value_type coord;
boost::get<0>(coord) = geom.get_vertex(0,&boost::get<1>(coord),&boost::get<2>(coord));
return coord;
}
};
template <typename T>
struct coordinate_policy : karma::real_policies<T>
{
typedef boost::spirit::karma::real_policies<T> base_type;
static int floatfield(T n) { return base_type::fmtflags::fixed; }
static unsigned precision(T n) { return 6u ;}
};
} }
template <typename OutputIterator>
struct svg_generator :
karma::grammar<OutputIterator, geometry_type const& ()>
{
svg_generator()
: svg_generator::base_type(svg)
{
using boost::spirit::karma::uint_;
using boost::spirit::karma::_val;
using boost::spirit::karma::_1;
using boost::spirit::karma::lit;
using boost::spirit::karma::_a;
svg = point | linestring | polygon
;
point = &uint_(mapnik::Point)[_1 = _type(_val)]
<< svg_point [_1 = _first(_val)]
;
svg_point = &uint_
<< lit("cx=\"") << coord_type
<< lit("\" cy=\"") << coord_type
<< lit('\"')
;
linestring = &uint_(mapnik::LineString)[_1 = _type(_val)]
<< svg_path
;
polygon = &uint_(mapnik::Polygon)[_1 = _type(_val)]
<< svg_path
;
svg_path %= ((&uint_(mapnik::SEG_MOVETO) << lit('M')
| &uint_(mapnik::SEG_LINETO) [_a +=1] << karma::string [if_(_a == 1) [_1 = "L" ] ])
<< lit(' ') << coord_type << lit(' ') << coord_type) % lit(' ')
;
}
// rules
karma::rule<OutputIterator, geometry_type const& ()> svg;
karma::rule<OutputIterator, geometry_type const& ()> point;
karma::rule<OutputIterator, geometry_type const& ()> linestring;
karma::rule<OutputIterator, geometry_type const& ()> polygon;
karma::rule<OutputIterator, geometry_type::value_type ()> svg_point;
karma::rule<OutputIterator, karma::locals<unsigned>, geometry_type const& ()> svg_path;
// phoenix functions
phoenix::function<detail::get_type > _type;
phoenix::function<detail::get_first> _first;
//
karma::real_generator<double, detail::coordinate_policy<double> > coord_type;
};
}} }}
#endif // MAPNIK_GEOMETRY_SVG_GENERATOR_HPP #endif // MAPNIK_GEOMETRY_SVG_GENERATOR_HPP

View file

@ -78,6 +78,7 @@ struct coordinate_policy : karma::real_policies<T>
{ {
typedef boost::spirit::karma::real_policies<T> base_type; typedef boost::spirit::karma::real_policies<T> base_type;
static int floatfield(T n) { return base_type::fmtflags::fixed; } static int floatfield(T n) { return base_type::fmtflags::fixed; }
static unsigned precision(T n) { return 6u ;}
}; };