rename geometry -> path ( geometry_type -> path_type)

This commit is contained in:
artemp 2015-03-24 13:17:07 +01:00
parent ac1ffa2bfb
commit 323fdd5212
10 changed files with 96 additions and 98 deletions

View file

@ -28,12 +28,11 @@
#include <mapnik/box2d.hpp>
#include <mapnik/util/noncopyable.hpp>
namespace mapnik {
namespace mapnik { namespace detail {
template <typename T, template <typename> class Container=vertex_vector>
class geometry : private util::noncopyable
class path : private util::noncopyable
{
public:
static const std::uint8_t geometry_bits = 7;
enum types : std::uint8_t
@ -53,11 +52,11 @@ public:
types type_;
public:
geometry()
path()
: type_(Unknown)
{}
explicit geometry(types type)
explicit path(types type)
: type_(type)
{}
@ -106,31 +105,31 @@ public:
}
};
namespace detail {
template <typename Geometry>
template <typename T>
struct vertex_adapter : private util::noncopyable
{
using size_type = typename Geometry::size_type;
using value_type = typename Geometry::value_type;
using types = typename Geometry::types;
using path_type = T;
using size_type = typename path_type::size_type;
using value_type = typename path_type::value_type;
using types = typename path_type::types;
vertex_adapter(Geometry const& geom)
: geom_(geom),
vertex_adapter(path_type const& path)
: path_(path),
itr_(0) {}
size_type size() const
{
return geom_.size();
return path_.size();
}
unsigned vertex(double* x, double* y) const
{
return geom_.cont_.get_vertex(itr_++,x,y);
return path_.cont_.get_vertex(itr_++,x,y);
}
unsigned vertex(std::size_t index, double* x, double* y) const
{
return geom_.cont_.get_vertex(index, x, y);
return path_.cont_.get_vertex(index, x, y);
}
void rewind(unsigned ) const
@ -140,7 +139,7 @@ struct vertex_adapter : private util::noncopyable
types type() const
{
return geom_.type();
return path_.type();
}
box2d<double> envelope() const
@ -149,8 +148,8 @@ struct vertex_adapter : private util::noncopyable
double x = 0;
double y = 0;
rewind(0);
size_type geom_size = size();
for (size_type i = 0; i < geom_size; ++i)
size_type path_size = size();
for (size_type i = 0; i < path_size; ++i)
{
unsigned cmd = vertex(&x,&y);
if (cmd == SEG_CLOSE) continue;
@ -165,20 +164,20 @@ struct vertex_adapter : private util::noncopyable
}
return result;
}
Geometry const& geom_;
path_type const& path_;
mutable size_type itr_;
};
}
template <typename Geometry>
box2d<double> envelope(Geometry const& geom)
template <typename PathType>
box2d<double> envelope(PathType const& path)
{
detail::vertex_adapter<Geometry> va(geom);
detail::vertex_adapter<PathType> va(path);
return va.envelope();
}
using geometry_type = geometry<double,vertex_vector>;
using vertex_adapter = detail::vertex_adapter<geometry_type>;
using path_type = detail::path<double,vertex_vector>;
using vertex_adapter = detail::vertex_adapter<path_type>;
}

View file

@ -26,7 +26,6 @@
#include <mapnik/segment.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/geometry_impl.hpp>
#include <mapnik/geometry_type.hpp>
#include <mapnik/path.hpp>
#include <algorithm>
@ -39,8 +38,8 @@ namespace detail {
template <typename F1, typename F2, typename F3>
void make_building(new_geometry::polygon const& poly, double height, F1 const& face_func, F2 const& frame_func, F3 const& roof_func)
{
const std::unique_ptr<geometry_type> frame(new geometry_type(geometry_type::types::LineString));
const std::unique_ptr<geometry_type> roof(new geometry_type(geometry_type::types::Polygon));
const std::unique_ptr<path_type> frame(new path_type(path_type::types::LineString));
const std::unique_ptr<path_type> roof(new path_type(path_type::types::Polygon));
std::deque<segment_t> face_segments;
double x0 = 0;
double y0 = 0;
@ -70,7 +69,7 @@ void make_building(new_geometry::polygon const& poly, double height, F1 const& f
std::sort(face_segments.begin(),face_segments.end(), y_order);
for (auto const& seg : face_segments)
{
const std::unique_ptr<geometry_type> faces(new geometry_type(geometry_type::types::Polygon));
const std::unique_ptr<path_type> faces(new path_type(path_type::types::Polygon));
faces->move_to(std::get<0>(seg),std::get<1>(seg));
faces->line_to(std::get<2>(seg),std::get<3>(seg));
faces->line_to(std::get<2>(seg),std::get<3>(seg) + height);

View file

@ -109,11 +109,11 @@ namespace mapnik { namespace svg {
template <typename T>
struct get_first
{
using geometry_type = T;
using result_type = typename geometry_type::value_type const;
result_type operator() (geometry_type const& geom) const
using path_type = T;
using result_type = typename path_type::value_type const;
result_type operator() (path_type const& geom) const
{
typename geometry_type::value_type coord;
typename path_type::value_type coord;
geom.rewind(0);
std::get<0>(coord) = geom.vertex(&std::get<1>(coord),&std::get<2>(coord));
return coord;
@ -121,13 +121,13 @@ namespace mapnik { namespace svg {
};
template <>
struct get_first<mapnik::geometry_type>
struct get_first<mapnik::path_type>
{
using geometry_type = mapnik::geometry_type;
using result_type = geometry_type::value_type const;
result_type operator() (geometry_type const& geom) const
using path_type = mapnik::path_type;
using result_type = path_type::value_type const;
result_type operator() (path_type const& geom) const
{
geometry_type::value_type coord;
path_type::value_type coord;
std::get<0>(coord) = geom.cont_.get_vertex(0, &std::get<1>(coord),&std::get<2>(coord));
return coord;
}
@ -143,27 +143,27 @@ namespace mapnik { namespace svg {
};
}
template <typename OutputIterator, typename Geometry>
template <typename OutputIterator, typename Path>
struct svg_path_generator :
karma::grammar<OutputIterator, Geometry const& ()>
karma::grammar<OutputIterator, Path const& ()>
{
using geometry_type = Geometry;
using coord_type = typename boost::remove_pointer<typename geometry_type::value_type>::type;
using path_type = Path;
using coord_type = typename boost::remove_pointer<typename path_type::value_type>::type;
svg_path_generator();
// 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, path_type const& ()> svg;
karma::rule<OutputIterator, path_type const& ()> point;
karma::rule<OutputIterator, path_type const& ()> linestring;
karma::rule<OutputIterator, path_type const& ()> polygon;
karma::rule<OutputIterator, coord_type ()> svg_point;
karma::rule<OutputIterator, karma::locals<unsigned>, geometry_type const& ()> svg_path;
karma::rule<OutputIterator, karma::locals<unsigned>, path_type const& ()> svg_path;
// phoenix functions
phoenix::function<svg_detail::get_type<geometry_type> > _type;
phoenix::function<svg_detail::get_first<geometry_type> > _first;
phoenix::function<svg_detail::get_type<path_type> > _type;
phoenix::function<svg_detail::get_first<path_type> > _first;
//
karma::real_generator<double, svg_detail::coordinate_policy<double> > coordinate;

View file

@ -29,8 +29,8 @@ namespace mapnik { namespace svg {
namespace karma = boost::spirit::karma;
namespace phoenix = boost::phoenix;
template <typename OutputIterator, typename Geometry>
svg_path_generator<OutputIterator,Geometry>::svg_path_generator()
template <typename OutputIterator, typename Path>
svg_path_generator<OutputIterator,Path>::svg_path_generator()
: svg_path_generator::base_type(svg)
{
boost::spirit::karma::uint_type uint_;

View file

@ -37,7 +37,7 @@
namespace boost { namespace spirit { namespace traits {
template <>
struct is_container<mapnik::geometry_type const> : mpl::true_ {} ;
struct is_container<mapnik::path_type const> : mpl::true_ {} ;
template <>
struct is_container<mapnik::vertex_adapter const> : mpl::true_ {} ;
@ -49,9 +49,9 @@ struct is_container<mapnik::vertex_adapter const> : mpl::true_ {} ;
//
template <>
struct container_iterator<mapnik::geometry_type const>
struct container_iterator<mapnik::path_type const>
{
using type = mapnik::util::path_iterator<mapnik::geometry_type>;
using type = mapnik::util::path_iterator<mapnik::path_type>;
};
template <>
@ -61,12 +61,12 @@ struct container_iterator<mapnik::vertex_adapter const>
};
template <>
struct begin_container<mapnik::geometry_type const>
struct begin_container<mapnik::path_type const>
{
static mapnik::util::path_iterator<mapnik::geometry_type>
call (mapnik::geometry_type const& g)
static mapnik::util::path_iterator<mapnik::path_type>
call (mapnik::path_type const& p)
{
return mapnik::util::path_iterator<mapnik::geometry_type>(g);
return mapnik::util::path_iterator<mapnik::path_type>(p);
}
};
@ -74,19 +74,19 @@ template <>
struct begin_container<mapnik::vertex_adapter const>
{
static mapnik::util::path_iterator<mapnik::vertex_adapter>
call (mapnik::vertex_adapter const& g)
call (mapnik::vertex_adapter const& p)
{
return mapnik::util::path_iterator<mapnik::vertex_adapter>(g);
return mapnik::util::path_iterator<mapnik::vertex_adapter>(p);
}
};
template <>
struct end_container<mapnik::geometry_type const>
struct end_container<mapnik::path_type const>
{
static mapnik::util::path_iterator<mapnik::geometry_type>
call (mapnik::geometry_type const&)
static mapnik::util::path_iterator<mapnik::path_type>
call (mapnik::path_type const&)
{
return mapnik::util::path_iterator<mapnik::geometry_type>();
return mapnik::util::path_iterator<mapnik::path_type>();
}
};

View file

@ -80,17 +80,17 @@ private:
const path_type *vertices_;
};
// specialization for mapnik::geometry_type - vertex interface has been removed
// specialization for mapnik::path_type - vertex interface has been removed
template <>
class path_iterator<geometry_type>
: public boost::iterator_facade< path_iterator<geometry_type>,
class path_iterator<path_type>
: public boost::iterator_facade< path_iterator<path_type>,
std::tuple<unsigned,double,double> const,
boost::forward_traversal_tag
>
{
public:
using path_type = mapnik::geometry_type;
using path_type = mapnik::path_type;
using value_type = std::tuple<unsigned, double, double>;
using size_type = path_type::size_type;
path_iterator()

View file

@ -54,7 +54,7 @@ void agg_renderer<T0,T1>::process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans)
{
using path_type = transform_path_adapter<view_transform, vertex_adapter>;
using transform_path_type = transform_path_adapter<view_transform, vertex_adapter>;
using ren_base = agg::renderer_base<agg::pixfmt_rgba32_pre>;
using renderer = agg::renderer_scanline_aa_solid<ren_base>;
@ -85,30 +85,30 @@ void agg_renderer<T0,T1>::process(building_symbolizer const& sym,
render_building_symbolizer(
feature, height,
[&,r,g,b,a,opacity](geometry_type const& faces)
[&,r,g,b,a,opacity](path_type const& faces)
{
vertex_adapter va(faces);
path_type faces_path (this->common_.t_,va,prj_trans);
transform_path_type faces_path (this->common_.t_,va,prj_trans);
ras_ptr->add_path(faces_path);
ren.color(agg::rgba8_pre(int(r*0.8), int(g*0.8), int(b*0.8), int(a * opacity)));
agg::render_scanlines(*ras_ptr, sl, ren);
this->ras_ptr->reset();
},
[&,r,g,b,a,opacity](geometry_type const& frame)
[&,r,g,b,a,opacity](path_type const& frame)
{
vertex_adapter va(frame);
path_type path(common_.t_,va, prj_trans);
agg::conv_stroke<path_type> stroke(path);
transform_path_type path(common_.t_,va, prj_trans);
agg::conv_stroke<transform_path_type> stroke(path);
stroke.width(common_.scale_factor_);
ras_ptr->add_path(stroke);
ren.color(agg::rgba8_pre(int(r*0.8), int(g*0.8), int(b*0.8), int(a * opacity)));
agg::render_scanlines(*ras_ptr, sl, ren);
ras_ptr->reset();
},
[&,r,g,b,a,opacity](geometry_type const& roof)
[&,r,g,b,a,opacity](path_type const& roof)
{
vertex_adapter va(roof);
path_type roof_path (common_.t_,va,prj_trans);
transform_path_type roof_path (common_.t_,va,prj_trans);
ras_ptr->add_path(roof_path);
ren.color(agg::rgba8_pre(r, g, b, int(a * opacity)));
agg::render_scanlines(*ras_ptr, sl, ren);

View file

@ -43,7 +43,7 @@ void cairo_renderer<T>::process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans)
{
using path_type = transform_path_adapter<view_transform,vertex_adapter>;
using transform_path_type = transform_path_adapter<view_transform,vertex_adapter>;
cairo_save_restore guard(context_);
composite_mode_e comp_op = get<composite_mode_e, keys::comp_op>(sym, feature, common_.vars_);
mapnik::color fill = get<color, keys::fill>(sym, feature, common_.vars_);
@ -54,29 +54,29 @@ void cairo_renderer<T>::process(building_symbolizer const& sym,
render_building_symbolizer(
feature, height,
[&](geometry_type const& faces)
[&](path_type const& faces)
{
vertex_adapter va(faces);
path_type faces_path(common_.t_, va, prj_trans);
transform_path_type faces_path(common_.t_, va, prj_trans);
context_.set_color(fill.red() * 0.8 / 255.0, fill.green() * 0.8 / 255.0,
fill.blue() * 0.8 / 255.0, fill.alpha() * opacity / 255.0);
context_.add_path(faces_path);
context_.fill();
},
[&](geometry_type const& frame)
[&](path_type const& frame)
{
vertex_adapter va(frame);
path_type path(common_.t_, va, prj_trans);
transform_path_type path(common_.t_, va, prj_trans);
context_.set_color(fill.red() * 0.8 / 255.0, fill.green() * 0.8/255.0,
fill.blue() * 0.8 / 255.0, fill.alpha() * opacity / 255.0);
context_.set_line_width(common_.scale_factor_);
context_.add_path(path);
context_.stroke();
},
[&](geometry_type const& roof)
[&](path_type const& roof)
{
vertex_adapter va(roof);
path_type roof_path(common_.t_, va, prj_trans);
transform_path_type roof_path(common_.t_, va, prj_trans);
context_.set_color(fill, opacity);
context_.add_path(roof_path);
context_.fill();

View file

@ -56,7 +56,7 @@ void grid_renderer<T>::process(building_symbolizer const& sym,
using pixfmt_type = typename grid_renderer_base_type::pixfmt_type;
using color_type = typename grid_renderer_base_type::pixfmt_type::color_type;
using renderer_type = agg::renderer_scanline_bin_solid<grid_renderer_base_type>;
using path_type = transform_path_adapter<view_transform, vertex_adapter>;
using transform_path_type = transform_path_adapter<view_transform, vertex_adapter>;
agg::scanline_bin sl;
grid_rendering_buffer buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_);
@ -71,29 +71,29 @@ void grid_renderer<T>::process(building_symbolizer const& sym,
render_building_symbolizer(
feature, height,
[&](geometry_type const& faces)
[&](path_type const& faces)
{
vertex_adapter va(faces);
path_type faces_path (common_.t_,va,prj_trans);
transform_path_type faces_path (common_.t_,va,prj_trans);
ras_ptr->add_path(faces_path);
ren.color(color_type(feature.id()));
agg::render_scanlines(*ras_ptr, sl, ren);
ras_ptr->reset();
},
[&](geometry_type const& frame)
[&](path_type const& frame)
{
vertex_adapter va(frame);
path_type path(common_.t_,va,prj_trans);
agg::conv_stroke<path_type> stroke(path);
transform_path_type path(common_.t_,va,prj_trans);
agg::conv_stroke<transform_path_type> stroke(path);
ras_ptr->add_path(stroke);
ren.color(color_type(feature.id()));
agg::render_scanlines(*ras_ptr, sl, ren);
ras_ptr->reset();
},
[&](geometry_type const& roof)
[&](path_type const& roof)
{
vertex_adapter va(roof);
path_type roof_path (common_.t_,va,prj_trans);
transform_path_type roof_path (common_.t_,va,prj_trans);
ras_ptr->add_path(roof_path);
ren.color(color_type(feature.id()));
agg::render_scanlines(*ras_ptr, sl, ren);

View file

@ -45,16 +45,16 @@ std::string dump_path(T & path)
}
std::string clip_line(mapnik::box2d<double> const& bbox,
mapnik::geometry_type const& geom)
mapnik::path_type const& path)
{
using line_clipper = agg::conv_clip_polyline<mapnik::vertex_adapter>;
mapnik::vertex_adapter va(geom);
mapnik::vertex_adapter va(path);
line_clipper clipped(va);
clipped.clip_box(bbox.minx(),bbox.miny(),bbox.maxx(),bbox.maxy());
return dump_path(clipped);
}
void parse_geom(mapnik::geometry_type & geom,
void parse_geom(mapnik::path_type & path,
std::string const& geom_string) {
std::vector<std::string> vertices;
boost::split(vertices, geom_string, boost::is_any_of(","));
@ -73,7 +73,7 @@ void parse_geom(mapnik::geometry_type & geom,
&& mapnik::util::string2double(commands[1],y)
&& mapnik::util::string2int(commands[2],c))
{
geom.push_vertex(x,y,(mapnik::CommandType)c);
path.push_vertex(x,y,(mapnik::CommandType)c);
}
else
{
@ -112,11 +112,11 @@ int main(int argc, char** argv)
throw std::runtime_error(std::string("could not parse bbox '") + parts[0] + "'");
}
// second part is input geometry
mapnik::geometry_type geom;
parse_geom(geom,parts[1]);
//std::clog << dump_path(geom) << "\n";
mapnik::path_type path;
parse_geom(path, parts[1]);
//std::clog << dump_path(path) << "\n";
// third part is expected, clipped geometry
BOOST_TEST_EQ(clip_line(bbox,geom),mapnik::util::trim_copy(parts[2]));
BOOST_TEST_EQ(clip_line(bbox, path),mapnik::util::trim_copy(parts[2]));
}
stream.close();
}