format dir include and src

format all files

Revert "format all files"

This reverts commit 95d5812e49e7f916b68e786596f5a8eb5bcac414.

Revert "format some files"

This reverts commit ed3c8762d4d828b2b28e7b18809fc33f4f8ccaf5.

format all files

fix formatting in dir include

fix formatting of debug macro
This commit is contained in:
Mathis Logemann 2022-01-26 10:43:31 +01:00
parent 6fe46f61e2
commit e7c3d04309
648 changed files with 25217 additions and 26024 deletions

View file

@ -9,8 +9,7 @@ MAPNIK_DISABLE_WARNING_PUSH
#include "agg_conv_smooth_poly1.h" #include "agg_conv_smooth_poly1.h"
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
struct vcgen_smooth_calucate_adaptive struct vcgen_smooth_calucate_adaptive
{ {
@ -57,12 +56,8 @@ struct vcgen_smooth_calucate_adaptive
} }
} }
return { return {{v1.x + s1 * smooth_value * (v2.x - xm1), v1.y + s1 * smooth_value * (v2.y - ym1)},
{v1.x + s1 * smooth_value * (v2.x - xm1), {v2.x + s2 * smooth_value * (v1.x - xm2), v2.y + s2 * smooth_value * (v1.y - ym2)}};
v1.y + s1 * smooth_value * (v2.y - ym1)},
{v2.x + s2 * smooth_value * (v1.x - xm2),
v2.y + s2 * smooth_value * (v1.y - ym2)}
};
} }
}; };
@ -95,45 +90,34 @@ class smooth_converter
} }
public: public:
smooth_converter(Geometry & geom) : smooth_converter(Geometry& geom)
geom_(geom), : geom_(geom)
impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom))) , impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
{} {}
void algorithm(smooth_algorithm_enum algo) void algorithm(smooth_algorithm_enum algo) { impl_ = init_impl(algo, geom_); }
{
impl_ = init_impl(algo, geom_);
}
void smooth_value(double v) void smooth_value(double v)
{ {
return util::apply_visitor([=](auto & impl) { return util::apply_visitor([=](auto& impl) { impl.smooth_value(v); }, impl_);
impl.smooth_value(v);
}, impl_);
} }
void rewind(unsigned path_id) void rewind(unsigned path_id)
{ {
return util::apply_visitor([=](auto & impl) { return util::apply_visitor([=](auto& impl) { return impl.rewind(path_id); }, impl_);
return impl.rewind(path_id);
}, impl_);
} }
unsigned vertex(double* x, double* y) unsigned vertex(double* x, double* y)
{ {
return util::apply_visitor([=](auto & impl) { return util::apply_visitor([=](auto& impl) { return impl.vertex(x, y); }, impl_);
return impl.vertex(x, y);
}, impl_);
} }
unsigned type() const unsigned type() const
{ {
return util::apply_visitor([](auto const& impl) { return util::apply_visitor([](auto const& impl) { return impl.type(); }, impl_);
return impl.type();
}, impl_);
} }
}; };
} } // namespace mapnik
#endif // MAPNIK_ADAPTIVE_SMOOTH_HPP #endif // MAPNIK_ADAPTIVE_SMOOTH_HPP

View file

@ -78,41 +78,40 @@ struct agg_polygon_pattern : agg_pattern_base
using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>; using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
using wrap_x_type = agg::wrap_mode_repeat; using wrap_x_type = agg::wrap_mode_repeat;
using wrap_y_type = agg::wrap_mode_repeat; using wrap_y_type = agg::wrap_mode_repeat;
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre, using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre, wrap_x_type, wrap_y_type>;
wrap_x_type,
wrap_y_type>;
using span_gen_type = agg::span_pattern_rgba<img_source_type>; using span_gen_type = agg::span_pattern_rgba<img_source_type>;
using renderer_base = agg::renderer_base<pixfmt_type>; using renderer_base = agg::renderer_base<pixfmt_type>;
using renderer_type = agg::renderer_scanline_aa_alpha<renderer_base, using renderer_type =
agg::span_allocator<agg::rgba8>, agg::renderer_scanline_aa_alpha<renderer_base, agg::span_allocator<agg::rgba8>, span_gen_type>;
span_gen_type>;
agg_polygon_pattern(image_rgba8 const& pattern_img, agg_polygon_pattern(image_rgba8 const& pattern_img,
renderer_common const& common, renderer_common const& common,
symbolizer_base const& sym, symbolizer_base const& sym,
mapnik::feature_impl const& feature, mapnik::feature_impl const& feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans}, : agg_pattern_base{pattern_img, common, sym, feature, prj_trans}
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)), , clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
clip_box_(clipping_extent(common)), , clip_box_(clipping_extent(common))
tr_(geom_transform()), , tr_(geom_transform())
converter_(clip_box_, sym, common.t_, prj_trans, tr_, , converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
feature, common.vars_, common.scale_factor_)
{ {
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_); value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_); value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>(); if (simplify_tolerance > 0.0)
converter_.template set<simplify_tag>();
converter_.template set<affine_transform_tag>(); converter_.template set<affine_transform_tag>();
if (smooth > 0.0) converter_.template set<smooth_tag>(); if (smooth > 0.0)
converter_.template set<smooth_tag>();
} }
void render(renderer_base& ren_base, rasterizer& ras) void render(renderer_base& ren_base, rasterizer& ras)
{ {
coord<double, 2> offset(pattern_offset(sym_, feature_, prj_trans_, common_, coord<double, 2> offset(
pattern_img_.width(), pattern_img_.height())); pattern_offset(sym_, feature_, prj_trans_, common_, pattern_img_.width(), pattern_img_.height()));
agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(), agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(),
pattern_img_.width(), pattern_img_.height(), pattern_img_.width(),
pattern_img_.height(),
pattern_img_.width() * 4); pattern_img_.width() * 4);
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf); agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
img_source_type img_src(pixf_pattern); img_source_type img_src(pixf_pattern);
@ -122,8 +121,7 @@ struct agg_polygon_pattern : agg_pattern_base
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_); value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255)); renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
using apply_vertex_converter_type = detail::apply_vertex_converter< using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, rasterizer>;
VertexConverter, rasterizer>;
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>; using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
apply_vertex_converter_type apply(converter_, ras); apply_vertex_converter_type apply(converter_, ras);
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry()); mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
@ -139,5 +137,4 @@ struct agg_polygon_pattern : agg_pattern_base
} // namespace mapnik } // namespace mapnik
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP #endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP

View file

@ -59,6 +59,6 @@ void set_gamma_method(T & ras_ptr, double gamma, gamma_method_enum method)
} }
} }
} } // namespace mapnik
#endif // MAPNIK_AGG_HELPERS_HPP #endif // MAPNIK_AGG_HELPERS_HPP

View file

@ -33,24 +33,18 @@ MAPNIK_DISABLE_WARNING_PUSH
#include "agg_color_rgba.h" #include "agg_color_rgba.h"
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
class pattern_source : private util::noncopyable class pattern_source : private util::noncopyable
{ {
public: public:
pattern_source(image_rgba8 const& pattern, double opacity = 1.0) pattern_source(image_rgba8 const& pattern, double opacity = 1.0)
: pattern_(pattern), : pattern_(pattern)
opacity_(opacity) {} , opacity_(opacity)
{}
unsigned int width() const unsigned int width() const { return pattern_.width(); }
{ unsigned int height() const { return pattern_.height(); }
return pattern_.width();
}
unsigned int height() const
{
return pattern_.height();
}
agg::rgba8 pixel(int x, int y) const agg::rgba8 pixel(int x, int y) const
{ {
unsigned c = pattern_(x, y); unsigned c = pattern_(x, y);
@ -59,10 +53,11 @@ public:
static_cast<unsigned>(((c >> 16) & 0xff) * opacity_), static_cast<unsigned>(((c >> 16) & 0xff) * opacity_),
static_cast<unsigned>(((c >> 24) & 0xff) * opacity_)); static_cast<unsigned>(((c >> 24) & 0xff) * opacity_));
} }
private: private:
image_rgba8 const& pattern_; image_rgba8 const& pattern_;
double opacity_; double opacity_;
}; };
} } // namespace mapnik
#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP #endif // MAPNIK_AGG_PATTERN_SOURCE_HPP

View file

@ -26,7 +26,6 @@
// mapnik // mapnik
#include <mapnik/util/noncopyable.hpp> #include <mapnik/util/noncopyable.hpp>
#include <mapnik/warning.hpp> #include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore_agg.hpp> #include <mapnik/warning_ignore_agg.hpp>
@ -35,8 +34,10 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
struct rasterizer : agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_int_sat>, util::noncopyable {}; struct rasterizer : agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_int_sat>,
util::noncopyable
{};
} } // namespace mapnik
#endif // MAPNIK_AGG_RASTERIZER_HPP #endif // MAPNIK_AGG_RASTERIZER_HPP

View file

@ -53,9 +53,13 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
template<typename SvgRenderer, typename RasterizerType, typename RendererBaseType> template<typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, RendererBaseType & renb, void render_vector_marker(SvgRenderer& svg_renderer,
box2d<double> const& bbox, agg::trans_affine const& tr, RasterizerType& ras,
double opacity, bool snap_to_pixels) RendererBaseType& renb,
box2d<double> const& bbox,
agg::trans_affine const& tr,
double opacity,
bool snap_to_pixels)
{ {
agg::scanline_u8 sl; agg::scanline_u8 sl;
if (snap_to_pixels) if (snap_to_pixels)
@ -73,9 +77,13 @@ void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, Rend
} }
template<typename RendererType, typename RasterizerType> template<typename RendererType, typename RasterizerType>
void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 const& src, void render_raster_marker(RendererType renb,
agg::trans_affine const& tr, double opacity, RasterizerType& ras,
float scale_factor, bool snap_to_pixels) image_rgba8 const& src,
agg::trans_affine const& tr,
double opacity,
float scale_factor,
bool snap_to_pixels)
{ {
using color_type = agg::rgba8; using color_type = agg::rgba8;
using const_rendering_buffer = util::rendering_buffer<image_rgba8>; using const_rendering_buffer = util::rendering_buffer<image_rgba8>;
@ -84,11 +92,9 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
agg::scanline_u8 sl; agg::scanline_u8 sl;
double width = src.width(); double width = src.width();
double height = src.height(); double height = src.height();
if (std::fabs(1.0 - scale_factor) < 0.001 if (std::fabs(1.0 - scale_factor) < 0.001 && (std::fabs(1.0 - tr.sx) < agg::affine_epsilon) &&
&& (std::fabs(1.0 - tr.sx) < agg::affine_epsilon) (std::fabs(0.0 - tr.shy) < agg::affine_epsilon) && (std::fabs(0.0 - tr.shx) < agg::affine_epsilon) &&
&& (std::fabs(0.0 - tr.shy) < agg::affine_epsilon) (std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
&& (std::fabs(0.0 - tr.shx) < agg::affine_epsilon)
&& (std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
{ {
const_rendering_buffer src_buffer(src); const_rendering_buffer src_buffer(src);
pixfmt_pre pixf_mask(src_buffer); pixfmt_pre pixf_mask(src_buffer);
@ -102,11 +108,7 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
} }
else else
{ {
renb.blend_from(pixf_mask, renb.blend_from(pixf_mask, 0, static_cast<int>(tr.tx), static_cast<int>(tr.ty), unsigned(255 * opacity));
0,
static_cast<int>(tr.tx),
static_cast<int>(tr.ty),
unsigned(255*opacity));
} }
} }
else else
@ -115,15 +117,18 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
using interpolator_type = agg::span_interpolator_linear<>; using interpolator_type = agg::span_interpolator_linear<>;
// using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>; // using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>;
using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>; using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>;
using renderer_type = agg::renderer_scanline_aa_alpha<RendererType, using renderer_type =
agg::span_allocator<color_type>, agg::renderer_scanline_aa_alpha<RendererType, agg::span_allocator<color_type>, span_gen_type>;
span_gen_type>;
double p[8]; double p[8];
p[0] = 0; p[1] = 0; p[0] = 0;
p[2] = width; p[3] = 0; p[1] = 0;
p[4] = width; p[5] = height; p[2] = width;
p[6] = 0; p[7] = height; p[3] = 0;
p[4] = width;
p[5] = height;
p[6] = 0;
p[7] = height;
tr.transform(&p[0], &p[1]); tr.transform(&p[0], &p[1]);
tr.transform(&p[2], &p[3]); tr.transform(&p[2], &p[3]);
tr.transform(&p[4], &p[5]); tr.transform(&p[4], &p[5]);
@ -151,6 +156,6 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
} }
} }
} } // namespace mapnik
#endif // MAPNIK_AGG_RENDER_MARKER_HPP #endif // MAPNIK_AGG_RENDER_MARKER_HPP

View file

@ -41,7 +41,9 @@
#include <stack> #include <stack>
// fwd declaration to avoid dependence on agg headers // fwd declaration to avoid dependence on agg headers
namespace agg { struct trans_affine; } namespace agg {
struct trans_affine;
}
// fwd declarations to speed up compile // fwd declarations to speed up compile
namespace mapnik { namespace mapnik {
@ -55,8 +57,9 @@ namespace mapnik {
class proj_transform; class proj_transform;
struct rasterizer; struct rasterizer;
struct rgba8_t; struct rgba8_t;
template<typename T> class image; template<typename T>
} class image;
} // namespace mapnik
namespace mapnik { namespace mapnik {
@ -65,12 +68,11 @@ class buffer_stack
{ {
public: public:
buffer_stack(std::size_t width, std::size_t height) buffer_stack(std::size_t width, std::size_t height)
: width_(width), : width_(width)
height_(height), , height_(height)
buffers_(), , buffers_()
position_(buffers_.begin()) , position_(buffers_.begin())
{ {}
}
T& push() T& push()
{ {
@ -86,10 +88,7 @@ public:
} }
return *position_; return *position_;
} }
bool in_range() const bool in_range() const { return (position_ != buffers_.end()); }
{
return (position_ != buffers_.end());
}
void pop() void pop()
{ {
@ -98,10 +97,7 @@ public:
++position_; ++position_;
} }
T & top() const T& top() const { return *position_; }
{
return *position_;
}
private: private:
const std::size_t width_; const std::size_t width_;
@ -114,18 +110,31 @@ template <typename T0, typename T1=label_collision_detector4>
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>>, class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>>,
private util::noncopyable private util::noncopyable
{ {
public: public:
using buffer_type = T0; using buffer_type = T0;
using processor_impl_type = agg_renderer<T0>; using processor_impl_type = agg_renderer<T0>;
using detector_type = T1; using detector_type = T1;
// create with default, empty placement detector // create with default, empty placement detector
agg_renderer(Map const& m, buffer_type & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); agg_renderer(Map const& m,
buffer_type& pixmap,
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
// create with external placement detector, possibly non-empty // create with external placement detector, possibly non-empty
agg_renderer(Map const &m, buffer_type & pixmap, std::shared_ptr<detector_type> detector, agg_renderer(Map const& m,
double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); buffer_type& pixmap,
std::shared_ptr<detector_type> detector,
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
// pass in mapnik::request object to provide the mutable things per render // pass in mapnik::request object to provide the mutable things per render
agg_renderer(Map const& m, request const& req, attributes const& vars, buffer_type & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); agg_renderer(Map const& m,
request const& req,
attributes const& vars,
buffer_type& pixmap,
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
~agg_renderer(); ~agg_renderer();
void start_map_processing(Map const& map); void start_map_processing(Map const& map);
void end_map_processing(Map const& map); void end_map_processing(Map const& map);
@ -135,52 +144,27 @@ public:
void start_style_processing(feature_type_style const& st); void start_style_processing(feature_type_style const& st);
void end_style_processing(feature_type_style const& st); void end_style_processing(feature_type_style const& st);
void render_marker(pixel_position const& pos, marker const& marker, agg::trans_affine const& tr, void render_marker(pixel_position const& pos,
double opacity, composite_mode_e comp_op); marker const& marker,
agg::trans_affine const& tr,
double opacity,
composite_mode_e comp_op);
void process(point_symbolizer const& sym, void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_symbolizer const& sym, void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym, void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym, void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(debug_symbolizer const& sym, feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_pattern_symbolizer const& sym, void process(dot_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(raster_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(shield_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(text_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(markers_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(group_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(debug_symbolizer const& sym,
feature_impl & feature,
proj_transform const& prj_trans);
void process(dot_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
inline bool process(rule::symbolizers const&, inline bool process(rule::symbolizers const&, mapnik::feature_impl&, proj_transform const&)
mapnik::feature_impl&,
proj_transform const& )
{ {
// agg renderer doesn't support processing of multiple symbolizers. // agg renderer doesn't support processing of multiple symbolizers.
return false; return false;
@ -189,26 +173,16 @@ public:
void painted(bool painted); void painted(bool painted);
bool painted(); bool painted();
inline eAttributeCollectionPolicy attribute_collection_policy() const inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
{
return DEFAULT;
}
inline double scale_factor() const inline double scale_factor() const { return common_.scale_factor_; }
{
return common_.scale_factor_; inline attributes const& variables() const { return common_.vars_; }
}
inline attributes const& variables() const
{
return common_.vars_;
}
protected: protected:
template<typename R> template<typename R>
void debug_draw_box(R& buf, box2d<double> const& extent, void debug_draw_box(R& buf, box2d<double> const& extent, double x, double y, double angle = 0.0);
double x, double y, double angle = 0.0); void debug_draw_box(box2d<double> const& extent, double x, double y, double angle = 0.0);
void debug_draw_box(box2d<double> const& extent,
double x, double y, double angle = 0.0);
void draw_geo_extent(box2d<double> const& extent, mapnik::color const& color); void draw_geo_extent(box2d<double> const& extent, mapnik::color const& color);
private: private:

View file

@ -37,7 +37,8 @@ struct attribute
{ {
std::string name_; std::string name_;
explicit attribute(std::string const& _name) explicit attribute(std::string const& _name)
: name_(_name) {} : name_(_name)
{}
template<typename V, typename F> template<typename V, typename F>
V const& value(F const& f) const V const& value(F const& f) const
@ -61,7 +62,8 @@ struct global_attribute
{ {
std::string name; std::string name;
explicit global_attribute(std::string const& name_) explicit global_attribute(std::string const& name_)
: name(name_) {} : name(name_)
{}
template<typename V, typename C> template<typename V, typename C>
V const& operator()(C const& ctx) V const& operator()(C const& ctx)
@ -72,6 +74,6 @@ struct global_attribute
using attributes = std::unordered_map<std::string, value>; using attributes = std::unordered_map<std::string, value>;
} } // namespace mapnik
#endif // MAPNIK_ATTRIBUTE_HPP #endif // MAPNIK_ATTRIBUTE_HPP

View file

@ -55,12 +55,10 @@ template <typename Container>
struct expression_attributes struct expression_attributes
{ {
explicit expression_attributes(Container& names) explicit expression_attributes(Container& names)
: names_(names) {} : names_(names)
{}
void operator() (attribute const& attr) const void operator()(attribute const& attr) const { names_.emplace(attr.name()); }
{
names_.emplace(attr.name());
}
template<typename Tag> template<typename Tag>
void operator()(binary_node<Tag> const& x) const void operator()(binary_node<Tag> const& x) const
@ -75,18 +73,13 @@ struct expression_attributes
util::apply_visitor(*this, x.expr); util::apply_visitor(*this, x.expr);
} }
void operator() (regex_match_node const& x) const void operator()(regex_match_node const& x) const { util::apply_visitor(*this, x.expr); }
{
util::apply_visitor(*this, x.expr);
}
void operator() (regex_replace_node const& x) const void operator()(regex_replace_node const& x) const { util::apply_visitor(*this, x.expr); }
{
util::apply_visitor(*this, x.expr);
}
template<typename T> template<typename T>
void operator() (T const&) const {} void operator()(T const&) const
{}
private: private:
Container& names_; Container& names_;
@ -97,11 +90,12 @@ class group_attribute_collector : public util::noncopyable
private: private:
std::set<std::string>& names_; std::set<std::string>& names_;
bool expand_index_columns_; bool expand_index_columns_;
public: public:
group_attribute_collector(std::set<std::string>& names, group_attribute_collector(std::set<std::string>& names, bool expand_index_columns)
bool expand_index_columns) : names_(names)
: names_(names), , expand_index_columns_(expand_index_columns)
expand_index_columns_(expand_index_columns) {} {}
void operator()(group_symbolizer const& sym); void operator()(group_symbolizer const& sym);
}; };
@ -110,8 +104,9 @@ template <typename Container>
struct extract_attribute_names struct extract_attribute_names
{ {
explicit extract_attribute_names(Container& names) explicit extract_attribute_names(Container& names)
: names_(names), : names_(names)
f_attr_(names) {} , f_attr_(names)
{}
void operator()(mapnik::expression_ptr const& expr) const void operator()(mapnik::expression_ptr const& expr) const
{ {
@ -138,7 +133,8 @@ struct extract_attribute_names
expr->add_expressions(expressions); expr->add_expressions(expressions);
for (it = expressions.begin(); it != expressions.end(); ++it) for (it = expressions.begin(); it != expressions.end(); ++it)
{ {
if (*it) util::apply_visitor(f_attr_, **it); if (*it)
util::apply_visitor(f_attr_, **it);
} }
} }
} }
@ -152,7 +148,8 @@ struct extract_attribute_names
} }
template<typename T> template<typename T>
void operator() (T const&) const {} void operator()(T const&) const
{}
private: private:
Container& names_; Container& names_;
@ -161,11 +158,11 @@ private:
struct symbolizer_attributes struct symbolizer_attributes
{ {
symbolizer_attributes(std::set<std::string>& names, symbolizer_attributes(std::set<std::string>& names, double& filter_factor)
double & filter_factor) : filter_factor_(filter_factor)
: filter_factor_(filter_factor), , f_attrs_(names)
f_attrs_(names), , g_attrs_(names, true)
g_attrs_(names, true) {} {}
template<typename T> template<typename T>
void operator()(T const& sym) void operator()(T const& sym)
@ -197,10 +194,7 @@ struct symbolizer_attributes
} }
} }
void operator () (group_symbolizer const& sym) void operator()(group_symbolizer const& sym) { g_attrs_(sym); }
{
g_attrs_(sym);
}
private: private:
double& filter_factor_; double& filter_factor_;
@ -208,19 +202,20 @@ private:
group_attribute_collector g_attrs_; group_attribute_collector g_attrs_;
}; };
class attribute_collector : public util::noncopyable class attribute_collector : public util::noncopyable
{ {
private: private:
std::set<std::string>& names_; std::set<std::string>& names_;
double filter_factor_; double filter_factor_;
expression_attributes<std::set<std::string>> f_attr; expression_attributes<std::set<std::string>> f_attr;
public: public:
attribute_collector(std::set<std::string>& names) attribute_collector(std::set<std::string>& names)
: names_(names), : names_(names)
filter_factor_(1.0), , filter_factor_(1.0)
f_attr(names) {} , f_attr(names)
{}
template<typename RuleType> template<typename RuleType>
void operator()(RuleType const& r) void operator()(RuleType const& r)
{ {
@ -235,13 +230,9 @@ public:
util::apply_visitor(f_attr, *expr); util::apply_visitor(f_attr, *expr);
} }
double get_filter_factor() const double get_filter_factor() const { return filter_factor_; }
{
return filter_factor_;
}
}; };
inline void group_attribute_collector::operator()(group_symbolizer const& sym) inline void group_attribute_collector::operator()(group_symbolizer const& sym)
{ {
// find all column names referenced in the group symbolizer // find all column names referenced in the group symbolizer

View file

@ -27,35 +27,30 @@
namespace mapnik { namespace mapnik {
enum eAttributeType { enum eAttributeType { Integer = 1, Float = 2, Double = 3, String = 4, Boolean = 5, Geometry = 6, Object = 7 };
Integer=1,
Float =2,
Double =3,
String =4,
Boolean =5,
Geometry=6,
Object=7
};
class attribute_descriptor class attribute_descriptor
{ {
public: public:
attribute_descriptor(std::string const& name,unsigned type, attribute_descriptor(std::string const& name,
unsigned type,
bool primary_key = false, bool primary_key = false,
int size = -1, int size = -1,
int precision = -1) int precision = -1)
: name_(name), : name_(name)
type_(type), , type_(type)
size_(size), , size_(size)
precision_(precision), , precision_(precision)
primary_key_(primary_key) {} , primary_key_(primary_key)
{}
attribute_descriptor(attribute_descriptor const& other) attribute_descriptor(attribute_descriptor const& other)
: name_(other.name_), : name_(other.name_)
type_(other.type_), , type_(other.type_)
size_(other.size_), , size_(other.size_)
precision_(other.precision_), , precision_(other.precision_)
primary_key_(other.primary_key_) {} , primary_key_(other.primary_key_)
{}
attribute_descriptor& operator=(attribute_descriptor rhs) attribute_descriptor& operator=(attribute_descriptor rhs)
{ {
@ -68,30 +63,15 @@ public:
return *this; return *this;
} }
std::string const& get_name() const std::string const& get_name() const { return name_; }
{
return name_;
}
unsigned int get_type() const unsigned int get_type() const { return type_; }
{
return type_;
}
bool is_primary_key() const bool is_primary_key() const { return primary_key_; }
{
return primary_key_;
}
int get_size() const int get_size() const { return size_; }
{
return size_;
}
int get_precision() const int get_precision() const { return precision_; }
{
return precision_;
}
private: private:
std::string name_; std::string name_;
@ -101,6 +81,6 @@ private:
bool primary_key_; bool primary_key_;
}; };
} } // namespace mapnik
#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP #endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP

View file

@ -30,23 +30,22 @@
#include <iosfwd> #include <iosfwd>
#include <string> #include <string>
namespace mapnik namespace mapnik {
{
class MAPNIK_DECL boolean_type class MAPNIK_DECL boolean_type
{ {
public: public:
boolean_type() boolean_type()
: b_(false) {} : b_(false)
{}
boolean_type(bool b) boolean_type(bool b)
: b_(b) {} : b_(b)
{}
boolean_type(boolean_type const& b) boolean_type(boolean_type const& b)
: b_(b.b_) {} : b_(b.b_)
{}
operator bool() const operator bool() const { return b_; }
{
return b_;
}
boolean_type& operator=(boolean_type const& other) boolean_type& operator=(boolean_type const& other)
{ {
@ -62,27 +61,26 @@ private:
// Special stream input operator for boolean_type values // Special stream input operator for boolean_type values
template<typename charT, typename traits> template<typename charT, typename traits>
std::basic_istream<charT, traits> & std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& s, boolean_type& b)
operator >> ( std::basic_istream<charT, traits> & s, boolean_type & b )
{ {
if (s) if (s)
{ {
std::string word; std::string word;
s >> word; s >> word;
bool result; bool result;
if (util::string2bool(word,result)) b = result; if (util::string2bool(word, result))
b = result;
} }
return s; return s;
} }
template<typename charT, typename traits> template<typename charT, typename traits>
std::basic_ostream<charT, traits> & std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, boolean_type const& b)
operator << ( std::basic_ostream<charT, traits> & s, boolean_type const& b )
{ {
s << (b ? "true" : "false"); s << (b ? "true" : "false");
return s; return s;
} }
} } // namespace mapnik
#endif // MAPNIK_BOOLEAN_HPP #endif // MAPNIK_BOOLEAN_HPP

View file

@ -23,17 +23,21 @@
#ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP #ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
#define MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP #define MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
namespace boost { namespace spirit { namespace x3 namespace boost {
{ namespace spirit {
namespace x3 {
// helper macro // helper macro
#define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \ #define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \
template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \ template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \
rule_type rule_ \ rule_type rule_, \
, Iterator& first, Iterator const& last \ Iterator & first, \
, Context const& context, boost::spirit::x3::unused_type const& ); \ Iterator const& last, \
Context const& context, \
boost::spirit::x3::unused_type const&); \
/***/ /***/
}}} } // namespace x3
} // namespace spirit
} // namespace boost
#endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP #endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_CAIRO_CONTEXT_HPP #ifndef MAPNIK_CAIRO_CONTEXT_HPP
#define MAPNIK_CAIRO_CONTEXT_HPP #define MAPNIK_CAIRO_CONTEXT_HPP
@ -57,7 +56,8 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
template <typename T> class box2d; template<typename T>
class box2d;
using ErrorStatus = cairo_status_t; using ErrorStatus = cairo_status_t;
@ -86,12 +86,15 @@ public:
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face); cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
~cairo_face(); ~cairo_face();
cairo_font_face_t* face() const; cairo_font_face_t* face() const;
private: private:
class handle class handle
{ {
public: public:
handle(std::shared_ptr<font_library> const& library, face_ptr const& face) handle(std::shared_ptr<font_library> const& library, face_ptr const& face)
: library_(library), face_(face) {} : library_(library)
, face_(face)
{}
private: private:
std::shared_ptr<font_library> library_; std::shared_ptr<font_library> library_;
@ -127,7 +130,8 @@ struct cairo_closer
{ {
void operator()(cairo_t* obj) void operator()(cairo_t* obj)
{ {
if (obj) cairo_destroy(obj); if (obj)
cairo_destroy(obj);
} }
}; };
@ -135,7 +139,8 @@ struct cairo_surface_closer
{ {
void operator()(cairo_surface_t* surface) void operator()(cairo_surface_t* surface)
{ {
if (surface) cairo_surface_destroy(surface); if (surface)
cairo_surface_destroy(surface);
} }
}; };
@ -157,15 +162,12 @@ public:
const unsigned int* in_end = in_ptr + pixels; const unsigned int* in_end = in_ptr + pixels;
unsigned int* out_ptr; unsigned int* out_ptr;
surface_ = cairo_surface_ptr( surface_ = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
cairo_image_surface_create(
CAIRO_FORMAT_ARGB32,
static_cast<int>(data.width()), static_cast<int>(data.width()),
static_cast<int>(data.height())), static_cast<int>(data.height())),
cairo_surface_closer()); cairo_surface_closer());
out_ptr = reinterpret_cast<unsigned int *>( out_ptr = reinterpret_cast<unsigned int*>(cairo_image_surface_get_data(surface_.get()));
cairo_image_surface_get_data(surface_.get()));
while (in_ptr < in_end) while (in_ptr < in_end)
{ {
@ -186,21 +188,18 @@ public:
pattern_ = cairo_pattern_create_for_surface(surface_.get()); pattern_ = cairo_pattern_create_for_surface(surface_.get());
} }
cairo_pattern(cairo_surface_ptr const& surface) : cairo_pattern(cairo_surface_ptr const& surface)
surface_(surface), : surface_(surface)
pattern_(cairo_pattern_create_for_surface(surface_.get())) , pattern_(cairo_pattern_create_for_surface(surface_.get()))
{ {}
}
~cairo_pattern() ~cairo_pattern()
{ {
if (pattern_) cairo_pattern_destroy(pattern_); if (pattern_)
cairo_pattern_destroy(pattern_);
} }
void set_matrix(cairo_matrix_t const& matrix) void set_matrix(cairo_matrix_t const& matrix) { cairo_pattern_set_matrix(pattern_, &matrix); }
{
cairo_pattern_set_matrix(pattern_, &matrix);
}
void set_origin(double x, double y) void set_origin(double x, double y)
{ {
@ -211,27 +210,17 @@ public:
cairo_pattern_set_matrix(pattern_, &matrix); cairo_pattern_set_matrix(pattern_, &matrix);
} }
void set_extend(cairo_extend_t extend) void set_extend(cairo_extend_t extend) { cairo_pattern_set_extend(pattern_, extend); }
{
cairo_pattern_set_extend(pattern_, extend);
}
void set_filter(cairo_filter_t filter) void set_filter(cairo_filter_t filter) { cairo_pattern_set_filter(pattern_, filter); }
{
cairo_pattern_set_filter(pattern_, filter);
}
cairo_pattern_t * pattern() const cairo_pattern_t* pattern() const { return pattern_; }
{
return pattern_;
}
private: private:
cairo_surface_ptr surface_; cairo_surface_ptr surface_;
cairo_pattern_t* pattern_; cairo_pattern_t* pattern_;
}; };
class cairo_gradient : private util::noncopyable class cairo_gradient : private util::noncopyable
{ {
public: public:
@ -275,21 +264,13 @@ public:
cairo_pattern_destroy(pattern_); cairo_pattern_destroy(pattern_);
} }
cairo_pattern_t* gradient() const { return pattern_; }
cairo_pattern_t * gradient() const gradient_unit_e units() const { return units_; }
{
return pattern_;
}
gradient_unit_e units() const
{
return units_;
}
private: private:
cairo_pattern_t* pattern_; cairo_pattern_t* pattern_;
gradient_unit_e units_; gradient_unit_e units_;
}; };
class cairo_context : private util::noncopyable class cairo_context : private util::noncopyable
@ -297,10 +278,7 @@ class cairo_context : private util::noncopyable
public: public:
cairo_context(cairo_ptr const& cairo); cairo_context(cairo_ptr const& cairo);
inline ErrorStatus get_status() const inline ErrorStatus get_status() const { return cairo_status(cairo_.get()); }
{
return cairo_status(cairo_.get());
}
void clip(); void clip();
void show_page(); void show_page();
@ -434,10 +412,11 @@ template <typename Context>
struct line_pattern_rasterizer struct line_pattern_rasterizer
{ {
line_pattern_rasterizer(Context& context, cairo_pattern& pattern, unsigned width, unsigned height) line_pattern_rasterizer(Context& context, cairo_pattern& pattern, unsigned width, unsigned height)
: context_(context), : context_(context)
pattern_(pattern), , pattern_(pattern)
width_(width), , width_(width)
height_(height) {} , height_(height)
{}
template<typename T> template<typename T>
void add_path(T& path, unsigned start_index = 0) void add_path(T& path, unsigned start_index = 0)
@ -485,7 +464,6 @@ struct line_pattern_rasterizer
unsigned height_; unsigned height_;
}; };
} } // namespace mapnik
#endif // MAPNIK_CAIRO_CONTEXT_HPP #endif // MAPNIK_CAIRO_CONTEXT_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP #ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP #define MAPNIK_CAIRO_IMAGE_UTIL_HPP
@ -33,8 +32,7 @@
namespace mapnik { namespace mapnik {
static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data, static inline void cairo_image_to_rgba8(mapnik::image_rgba8& data, cairo_surface_ptr const& surface)
cairo_surface_ptr const& surface)
{ {
if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32) if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
{ {
@ -62,10 +60,15 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
unsigned int g = (in >> 8) & 0xff; unsigned int g = (in >> 8) & 0xff;
unsigned int b = (in >> 0) & 0xff; unsigned int b = (in >> 0) & 0xff;
#define DE_ALPHA(x) do { \ #define DE_ALPHA(x) \
if (a == 0) x = 0; \ do \
else x = x * 255 / a; \ { \
if (x > 255) x = 255; \ if (a == 0) \
x = 0; \
else \
x = x * 255 / a; \
if (x > 255) \
x = 255; \
} while (0) } while (0)
DE_ALPHA(r); DE_ALPHA(r);
@ -78,7 +81,6 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
} }
} }
} } // namespace mapnik
#endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP #endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP

View file

@ -32,12 +32,14 @@ namespace mapnik {
class cairo_context; class cairo_context;
void render_vector_marker(cairo_context & context, svg_path_adapter & svg_path, void render_vector_marker(cairo_context& context,
svg_path_adapter& svg_path,
svg_attribute_type const& attributes, svg_attribute_type const& attributes,
box2d<double> const& bbox, agg::trans_affine const& tr, box2d<double> const& bbox,
agg::trans_affine const& tr,
double opacity); double opacity);
} } // namespace mapnik
#endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP #endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP

View file

@ -58,10 +58,7 @@ struct cairo_save_restore
{ {
context_.save(); context_.save();
} }
~cairo_save_restore() ~cairo_save_restore() { context_.restore(); }
{
context_.restore();
}
cairo_context& context_; cairo_context& context_;
}; };
@ -71,11 +68,7 @@ class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer
{ {
public: public:
using processor_impl_type = cairo_renderer<T>; using processor_impl_type = cairo_renderer<T>;
cairo_renderer(Map const& m, cairo_renderer(Map const& m, T const& obj, double scale_factor = 1.0, unsigned offset_x = 0, unsigned offset_y = 0);
T const& obj,
double scale_factor=1.0,
unsigned offset_x=0,
unsigned offset_y=0);
cairo_renderer(Map const& m, cairo_renderer(Map const& m,
request const& req, request const& req,
attributes const& vars, attributes const& vars,
@ -97,80 +90,44 @@ public:
void end_layer_processing(layer const& lay); void end_layer_processing(layer const& lay);
void start_style_processing(feature_type_style const& st); void start_style_processing(feature_type_style const& st);
void end_style_processing(feature_type_style const& st); void end_style_processing(feature_type_style const& st);
void process(point_symbolizer const& sym, void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_symbolizer const& sym, void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym, void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym, void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(debug_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_pattern_symbolizer const& sym, inline bool
mapnik::feature_impl & feature, process(rule::symbolizers const& /*syms*/, mapnik::feature_impl& /*feature*/, proj_transform const& /*prj_trans*/)
proj_transform const& prj_trans);
void process(raster_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(shield_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(text_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(markers_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(group_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(debug_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
inline bool process(rule::symbolizers const& /*syms*/,
mapnik::feature_impl & /*feature*/,
proj_transform const& /*prj_trans*/)
{ {
// cairo renderer doesn't support processing of multiple symbolizers. // cairo renderer doesn't support processing of multiple symbolizers.
return false; return false;
} }
bool painted() bool painted() { return true; }
{
return true;
}
void painted(bool /*painted*/) void painted(bool /*painted*/)
{ {
// nothing to do // nothing to do
} }
inline eAttributeCollectionPolicy attribute_collection_policy() const inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
{
return DEFAULT;
}
inline double scale_factor() const inline double scale_factor() const { return common_.scale_factor_; }
{
return common_.scale_factor_;
}
inline attributes const& variables() const inline attributes const& variables() const { return common_.vars_; }
{
return common_.vars_;
}
void render_marker(pixel_position const& pos, void render_marker(pixel_position const& pos,
marker const& marker, marker const& marker,
agg::trans_affine const& mtx, agg::trans_affine const& mtx,
double opacity = 1.0, double opacity = 1.0,
bool recenter = true); bool recenter = true);
protected: protected:
Map const& m_; Map const& m_;
cairo_context context_; cairo_context context_;
@ -178,12 +135,11 @@ protected:
cairo_face_manager face_manager_; cairo_face_manager face_manager_;
bool style_level_compositing_; bool style_level_compositing_;
void setup(Map const& m); void setup(Map const& m);
}; };
extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>; extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>;
} } // namespace mapnik
#endif // MAPNIK_CAIRO_RENDERER_HPP #endif // MAPNIK_CAIRO_RENDERER_HPP

View file

@ -36,10 +36,9 @@ namespace mapnik {
struct cairo_renderer_process_visitor_p struct cairo_renderer_process_visitor_p
{ {
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr, cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr, double opacity)
double opacity) : image_tr_(image_tr)
: image_tr_(image_tr), , opacity_(opacity)
opacity_(opacity)
{} {}
cairo_surface_ptr operator()(marker_svg const& marker) const cairo_surface_ptr operator()(marker_svg const& marker) const
@ -50,9 +49,7 @@ struct cairo_renderer_process_visitor_p
double width = std::max(1.0, std::round(bbox.width())); double width = std::max(1.0, std::round(bbox.width()));
double height = std::max(1.0, std::round(bbox.height())); double height = std::max(1.0, std::round(bbox.height()));
cairo_rectangle_t extent{0, 0, width, height}; cairo_rectangle_t extent{0, 0, width, height};
cairo_surface_ptr surface( cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_surface_closer()); cairo_surface_closer());
cairo_ptr cairo = create_context(surface); cairo_ptr cairo = create_context(surface);
@ -60,12 +57,10 @@ struct cairo_renderer_process_visitor_p
svg_storage_type& svg = *marker.get_data(); svg_storage_type& svg = *marker.get_data();
svg_attribute_type const& svg_attributes = svg.attributes(); svg_attribute_type const& svg_attributes = svg.attributes();
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage( svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(svg.source());
svg.source());
svg::svg_path_adapter svg_path(stl_storage); svg::svg_path_adapter svg_path(stl_storage);
render_vector_marker(context, svg_path, svg_attributes, render_vector_marker(context, svg_path, svg_attributes, bbox, tr, opacity_);
bbox, tr, opacity_);
return surface; return surface;
} }
@ -76,9 +71,7 @@ struct cairo_renderer_process_visitor_p
agg::trans_affine tr(transform(bbox)); agg::trans_affine tr(transform(bbox));
cairo_rectangle_t extent{0, 0, bbox.width(), bbox.height()}; cairo_rectangle_t extent{0, 0, bbox.width(), bbox.height()};
cairo_surface_ptr surface( cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_surface_closer()); cairo_surface_closer());
cairo_ptr cairo = create_context(surface); cairo_ptr cairo = create_context(surface);
@ -91,9 +84,7 @@ struct cairo_renderer_process_visitor_p
cairo_surface_ptr operator()(marker_null const&) const cairo_surface_ptr operator()(marker_null const&) const
{ {
cairo_surface_ptr surface( cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, nullptr),
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, nullptr),
cairo_surface_closer()); cairo_surface_closer());
cairo_ptr cairo = create_context(surface); cairo_ptr cairo = create_context(surface);
cairo_context context(cairo); cairo_context context(cairo);
@ -105,9 +96,7 @@ private:
{ {
bbox *= image_tr_; bbox *= image_tr_;
coord<double, 2> c = bbox.center(); coord<double, 2> c = bbox.center();
agg::trans_affine mtx = agg::trans_affine_translation( agg::trans_affine mtx = agg::trans_affine_translation(0.5 * bbox.width() - c.x, 0.5 * bbox.height() - c.y);
0.5 * bbox.width() - c.x,
0.5 * bbox.height() - c.y);
return image_tr_ * mtx; return image_tr_ * mtx;
} }
@ -143,19 +132,20 @@ struct cairo_polygon_pattern : cairo_pattern_base
symbolizer_base const& sym, symbolizer_base const& sym,
mapnik::feature_impl const& feature, mapnik::feature_impl const& feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
: cairo_pattern_base{marker, common, sym, feature, prj_trans}, : cairo_pattern_base{marker, common, sym, feature, prj_trans}
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)), , clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
clip_box_(clipping_extent(common)), , clip_box_(clipping_extent(common))
tr_(geom_transform()), , tr_(geom_transform())
converter_(clip_box_, sym, common.t_, prj_trans, tr_, , converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
feature, common.vars_, common.scale_factor_)
{ {
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_); value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_);
value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_); value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_);
converter_.template set<affine_transform_tag>(); converter_.template set<affine_transform_tag>();
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>(); if (simplify_tolerance > 0.0)
if (smooth > 0.0) converter_.template set<smooth_tag>(); converter_.template set<simplify_tag>();
if (smooth > 0.0)
converter_.template set<smooth_tag>();
} }
void render(cairo_fill_rule_t fill_rule, cairo_context& context) void render(cairo_fill_rule_t fill_rule, cairo_context& context)
@ -181,8 +171,12 @@ struct cairo_polygon_pattern : cairo_pattern_base
cairo_rectangle_t pattern_surface_extent; cairo_rectangle_t pattern_surface_extent;
if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent)) if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent))
{ {
offset = pattern_offset(sym_, feature_, prj_trans_, common_, offset = pattern_offset(sym_,
pattern_surface_extent.width, pattern_surface_extent.height); feature_,
prj_trans_,
common_,
pattern_surface_extent.width,
pattern_surface_extent.height);
} }
cairo_pattern pattern(surface); cairo_pattern pattern(surface);
@ -207,5 +201,4 @@ struct cairo_polygon_pattern : cairo_pattern_base
} // namespace mapnik } // namespace mapnik
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP #endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP

View file

@ -44,6 +44,6 @@ MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
double scale_denominator = 0.0); double scale_denominator = 0.0);
#endif #endif
} // end ns } // namespace mapnik
#endif // MAPNIK_CAIRO_IO_HPP #endif // MAPNIK_CAIRO_IO_HPP

View file

@ -50,44 +50,50 @@ public:
// default ctor // default ctor
color() color()
: red_(0xff), : red_(0xff)
green_(0xff), , green_(0xff)
blue_(0xff), , blue_(0xff)
alpha_(0xff), , alpha_(0xff)
premultiplied_(false) , premultiplied_(false)
{} {}
color(std::uint8_t _red, std::uint8_t _green, std::uint8_t _blue, std::uint8_t _alpha = 0xff, bool premultiplied = false) color(std::uint8_t _red,
: red_(_red), std::uint8_t _green,
green_(_green), std::uint8_t _blue,
blue_(_blue), std::uint8_t _alpha = 0xff,
alpha_(_alpha), bool premultiplied = false)
premultiplied_(premultiplied) : red_(_red)
, green_(_green)
, blue_(_blue)
, alpha_(_alpha)
, premultiplied_(premultiplied)
{} {}
color(std::uint32_t _rgba, bool premultiplied = false) color(std::uint32_t _rgba, bool premultiplied = false)
: red_(_rgba & 0xff), : red_(_rgba & 0xff)
green_((_rgba >> 8) & 0xff), , green_((_rgba >> 8) & 0xff)
blue_((_rgba >> 16) & 0xff), , blue_((_rgba >> 16) & 0xff)
alpha_((_rgba >> 24) & 0xff), , alpha_((_rgba >> 24) & 0xff)
premultiplied_(premultiplied) {} , premultiplied_(premultiplied)
{}
// copy ctor // copy ctor
color(const color& rhs) color(const color& rhs)
: red_(rhs.red_), : red_(rhs.red_)
green_(rhs.green_), , green_(rhs.green_)
blue_(rhs.blue_), , blue_(rhs.blue_)
alpha_(rhs.alpha_), , alpha_(rhs.alpha_)
premultiplied_(rhs.premultiplied_) , premultiplied_(rhs.premultiplied_)
{} {}
// move ctor // move ctor
color(color&& rhs) color(color&& rhs)
: red_(std::move(rhs.red_)), : red_(std::move(rhs.red_))
green_(std::move(rhs.green_)), , green_(std::move(rhs.green_))
blue_(std::move(rhs.blue_)), , blue_(std::move(rhs.blue_))
alpha_(std::move(rhs.alpha_)), , alpha_(std::move(rhs.alpha_))
premultiplied_(std::move(rhs.premultiplied_)) {} , premultiplied_(std::move(rhs.premultiplied_))
{}
color(std::string const& str, bool premultiplied = false); color(std::string const& str, bool premultiplied = false);
@ -104,64 +110,32 @@ public:
inline bool operator==(color const& rhs) const inline bool operator==(color const& rhs) const
{ {
return (red_== rhs.red_) && return (red_ == rhs.red_) && (green_ == rhs.green_) && (blue_ == rhs.blue_) && (alpha_ == rhs.alpha_) &&
(green_ == rhs.green_) &&
(blue_ == rhs.blue_) &&
(alpha_ == rhs.alpha_) &&
(premultiplied_ == rhs.premultiplied_); (premultiplied_ == rhs.premultiplied_);
} }
inline std::uint8_t red() const inline std::uint8_t red() const { return red_; }
{
return red_;
}
inline std::uint8_t green() const inline std::uint8_t green() const { return green_; }
{
return green_;
}
inline std::uint8_t blue() const inline std::uint8_t blue() const { return blue_; }
{
return blue_;
}
inline std::uint8_t alpha() const inline std::uint8_t alpha() const { return alpha_; }
{
return alpha_;
}
inline void set_red(std::uint8_t _red) inline void set_red(std::uint8_t _red) { red_ = _red; }
{
red_ = _red;
}
inline void set_green(std::uint8_t _green) inline void set_green(std::uint8_t _green) { green_ = _green; }
{
green_ = _green;
}
inline void set_blue(std::uint8_t _blue) inline void set_blue(std::uint8_t _blue) { blue_ = _blue; }
{ inline void set_alpha(std::uint8_t _alpha) { alpha_ = _alpha; }
blue_ = _blue; inline bool get_premultiplied() const { return premultiplied_; }
} inline void set_premultiplied(bool val) { premultiplied_ = val; }
inline void set_alpha(std::uint8_t _alpha)
{
alpha_ = _alpha;
}
inline bool get_premultiplied() const
{
return premultiplied_;
}
inline void set_premultiplied(bool val)
{
premultiplied_ = val;
}
inline unsigned rgba() const inline unsigned rgba() const
{ {
return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_)); return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_));
} }
private: private:
void swap(color& rhs) void swap(color& rhs)
{ {
@ -174,8 +148,7 @@ private:
}; };
template<typename charT, typename traits> template<typename charT, typename traits>
std::basic_ostream<charT, traits> & std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, mapnik::color const& c)
operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
{ {
s << c.to_string(); s << c.to_string();
return s; return s;
@ -187,6 +160,6 @@ inline std::size_t hash_value(color const& c)
return c.rgba(); return c.rgba();
} }
} } // namespace mapnik
#endif // MAPNIK_COLOR_HPP #endif // MAPNIK_COLOR_HPP

View file

@ -36,16 +36,14 @@ class config_error : public std::exception
{ {
public: public:
config_error(std::string const& what); config_error(std::string const& what);
config_error(std::string const& what, config_error(std::string const& what, xml_node const& node);
xml_node const& node); config_error(std::string const& what, unsigned line_number, std::string const& filename);
config_error(std::string const& what,
unsigned line_number,
std::string const& filename);
virtual ~config_error() {} virtual ~config_error() {}
virtual const char* what() const noexcept; virtual const char* what() const noexcept;
void append_context(std::string const& ctx) const; void append_context(std::string const& ctx) const;
void append_context(std::string const& ctx, xml_node const& node) const; void append_context(std::string const& ctx, xml_node const& node) const;
void append_context(xml_node const& node) const; void append_context(xml_node const& node) const;
protected: protected:
mutable std::string what_; mutable std::string what_;
mutable unsigned line_number_; mutable unsigned line_number_;
@ -54,6 +52,6 @@ protected:
mutable std::string msg_; mutable std::string msg_;
}; };
} } // namespace mapnik
#endif // MAPNIK_CONFIG_ERROR_HPP #endif // MAPNIK_CONFIG_ERROR_HPP

View file

@ -31,41 +31,53 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
template<typename T, int dim> template<typename T, int dim>
struct coord { struct coord
{
using type = T; using type = T;
}; };
template<typename T> template<typename T>
struct coord<T, 2> struct coord<T, 2>
: boost::addable<coord<T,2>, : boost::addable<
boost::addable2<coord<T,2>,T, coord<T, 2>,
boost::subtractable<coord<T,2>, boost::addable2<
boost::subtractable2<coord<T,2>,T, coord<T, 2>,
boost::dividable2<coord<T,2>, T, T,
boost::multipliable2<coord<T,2>, T > > > > > > boost::subtractable<
coord<T, 2>,
boost::
subtractable2<coord<T, 2>, T, boost::dividable2<coord<T, 2>, T, boost::multipliable2<coord<T, 2>, T>>>>>>
{ {
using type = T; using type = T;
T x; T x;
T y; T y;
public: public:
coord() coord()
: x(),y() {} : x()
, y()
{}
coord(T x_, T y_) coord(T x_, T y_)
: x(x_),y(y_) {} : x(x_)
, y(y_)
{}
coord(coord<T, 2> const& rhs) coord(coord<T, 2> const& rhs)
: x(rhs.x), : x(rhs.x)
y(rhs.y) {} , y(rhs.y)
{}
template<typename T2> template<typename T2>
coord(coord<T2, 2> const& rhs) coord(coord<T2, 2> const& rhs)
: x(type(rhs.x)), : x(type(rhs.x))
y(type(rhs.y)) {} , y(type(rhs.y))
{}
coord(coord<T, 2>&& rhs) noexcept coord(coord<T, 2>&& rhs) noexcept
: x(std::move(rhs.x)), : x(std::move(rhs.x))
y(std::move(rhs.y)) {} , y(std::move(rhs.y))
{}
coord<T, 2>& operator=(coord<T, 2> rhs) coord<T, 2>& operator=(coord<T, 2> rhs)
{ {
@ -127,6 +139,7 @@ public:
y /= t; y /= t;
return *this; return *this;
} }
private: private:
void swap(coord<T, 2>& rhs) void swap(coord<T, 2>& rhs)
{ {
@ -142,22 +155,31 @@ struct coord<T,3>
T x; T x;
T y; T y;
T z; T z;
public: public:
coord() coord()
: x(),y(),z() {} : x()
, y()
, z()
{}
coord(T x_, T y_, T z_) coord(T x_, T y_, T z_)
: x(x_),y(y_),z(z_) {} : x(x_)
, y(y_)
, z(z_)
{}
template<typename T2> template<typename T2>
coord(coord<T2, 3> const& rhs) coord(coord<T2, 3> const& rhs)
: x(type(rhs.x)), : x(type(rhs.x))
y(type(rhs.y)), , y(type(rhs.y))
z(type(rhs.z)) {} , z(type(rhs.z))
{}
coord(coord<T, 3>&& rhs) noexcept coord(coord<T, 3>&& rhs) noexcept
: x(std::move(rhs.x)), : x(std::move(rhs.x))
y(std::move(rhs.y)), , y(std::move(rhs.y))
z(std::move(rhs.z)) {} , z(std::move(rhs.z))
{}
coord<T, 3> operator=(coord<T, 3> rhs) coord<T, 3> operator=(coord<T, 3> rhs)
{ {
@ -172,6 +194,7 @@ public:
swap(tmp); swap(tmp);
return *this; return *this;
} }
private: private:
void swap(coord<T, 3>& rhs) void swap(coord<T, 3>& rhs)
{ {
@ -185,6 +208,6 @@ using coord2d = coord<double,2>;
using coord2f = coord<float, 2>; using coord2f = coord<float, 2>;
using coord2i = coord<int, 2>; using coord2i = coord<int, 2>;
} } // namespace mapnik
#endif // MAPNIK_COORD_HPP #endif // MAPNIK_COORD_HPP

View file

@ -31,13 +31,11 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/spirit/home/x3.hpp> #include <boost/spirit/home/x3.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace css_color_grammar namespace css_color_grammar {
{
struct css_color_class; struct css_color_class;
using css_color_grammar_type = x3::rule<css_color_class, mapnik::color>; using css_color_grammar_type = x3::rule<css_color_class, mapnik::color>;
@ -46,6 +44,7 @@ css_color_grammar_type const css_color = "css_color";
BOOST_SPIRIT_DECLARE(css_color_grammar_type); BOOST_SPIRIT_DECLARE(css_color_grammar_type);
}} } // namespace css_color_grammar
} // namespace mapnik
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP #endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP

View file

@ -37,13 +37,8 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/fusion/adapted/std_tuple.hpp> #include <boost/fusion/adapted/std_tuple.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
BOOST_FUSION_ADAPT_STRUCT ( BOOST_FUSION_ADAPT_STRUCT(mapnik::color,
mapnik::color, (std::uint8_t, red_)(std::uint8_t, green_)(std::uint8_t, blue_)(std::uint8_t, alpha_))
(std::uint8_t, red_)
(std::uint8_t, green_)
(std::uint8_t, blue_)
(std::uint8_t, alpha_)
)
namespace mapnik { namespace mapnik {
@ -51,20 +46,21 @@ namespace x3 = boost::spirit::x3;
namespace css_color_grammar { namespace css_color_grammar {
using x3::lit;
using x3::uint_parser;
using x3::hex;
using x3::symbols;
using x3::omit;
using x3::attr; using x3::attr;
using x3::double_; using x3::double_;
using x3::hex;
using x3::lit;
using x3::no_case; using x3::no_case;
using x3::no_skip; using x3::no_skip;
using x3::omit;
using x3::symbols;
using x3::uint_parser;
struct named_colors_ : x3::symbols<color> struct named_colors_ : x3::symbols<color>
{ {
named_colors_() named_colors_()
{ {
// clang-format off
add add
("aliceblue", color(240, 248, 255)) ("aliceblue", color(240, 248, 255))
("antiquewhite", color(250, 235, 215)) ("antiquewhite", color(250, 235, 215))
@ -216,6 +212,7 @@ struct named_colors_ : x3::symbols<color>
("yellowgreen", color(154, 205, 50)) ("yellowgreen", color(154, 205, 50))
("transparent", color(0, 0, 0, 0)) ("transparent", color(0, 0, 0, 0))
; ;
// clang-format on
} }
} named_colors; } named_colors;
@ -235,97 +232,80 @@ struct clip_opacity
{ {
static double call(double val) static double call(double val)
{ {
if (val > 1.0) return 1.0; if (val > 1.0)
if (val < 0.0) return 0.0; return 1.0;
if (val < 0.0)
return 0.0;
return val; return val;
} }
}; };
struct percent_converter struct percent_converter
{ {
static std::uint8_t call(double val) static std::uint8_t call(double val) { return safe_cast<std::uint8_t>(std::lround((255.0 * val) / 100.0)); }
{
return safe_cast<std::uint8_t>(std::lround((255.0 * val)/100.0));
}
}; };
auto dec_red = [](auto& ctx) auto dec_red = [](auto& ctx) {
{
_val(ctx).red_ = _attr(ctx); _val(ctx).red_ = _attr(ctx);
}; };
auto dec_green = [](auto& ctx) auto dec_green = [](auto& ctx) {
{
_val(ctx).green_ = _attr(ctx); _val(ctx).green_ = _attr(ctx);
}; };
auto dec_blue = [](auto& ctx) auto dec_blue = [](auto& ctx) {
{
_val(ctx).blue_ = _attr(ctx); _val(ctx).blue_ = _attr(ctx);
}; };
auto opacity = [](auto& ctx) auto opacity = [](auto& ctx) {
{
_val(ctx).alpha_ = uint8_t((255.0 * clip_opacity::call(_attr(ctx))) + 0.5); _val(ctx).alpha_ = uint8_t((255.0 * clip_opacity::call(_attr(ctx))) + 0.5);
}; };
auto percent_red = [] (auto & ctx) auto percent_red = [](auto& ctx) {
{
_val(ctx).red_ = percent_converter::call(_attr(ctx)); _val(ctx).red_ = percent_converter::call(_attr(ctx));
}; };
auto percent_green = [] (auto & ctx) auto percent_green = [](auto& ctx) {
{
_val(ctx).green_ = percent_converter::call(_attr(ctx)); _val(ctx).green_ = percent_converter::call(_attr(ctx));
}; };
auto percent_blue = [] (auto & ctx) auto percent_blue = [](auto& ctx) {
{
_val(ctx).blue_ = percent_converter::call(_attr(ctx)); _val(ctx).blue_ = percent_converter::call(_attr(ctx));
}; };
auto hex1_red = [](auto& ctx) auto hex1_red = [](auto& ctx) {
{
_val(ctx).red_ = _attr(ctx) | _attr(ctx) << 4; _val(ctx).red_ = _attr(ctx) | _attr(ctx) << 4;
}; };
auto hex1_green = [](auto& ctx) auto hex1_green = [](auto& ctx) {
{
_val(ctx).green_ = _attr(ctx) | _attr(ctx) << 4; _val(ctx).green_ = _attr(ctx) | _attr(ctx) << 4;
}; };
auto hex1_blue = [](auto& ctx) auto hex1_blue = [](auto& ctx) {
{
_val(ctx).blue_ = _attr(ctx) | _attr(ctx) << 4; _val(ctx).blue_ = _attr(ctx) | _attr(ctx) << 4;
}; };
auto hex1_opacity = [](auto& ctx) auto hex1_opacity = [](auto& ctx) {
{
_val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4; _val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4;
}; };
auto hex2_red = [](auto& ctx) auto hex2_red = [](auto& ctx) {
{
_val(ctx).red_ = _attr(ctx); _val(ctx).red_ = _attr(ctx);
}; };
auto hex2_green = [](auto& ctx) auto hex2_green = [](auto& ctx) {
{
_val(ctx).green_ = _attr(ctx); _val(ctx).green_ = _attr(ctx);
}; };
auto hex2_blue = [](auto& ctx) auto hex2_blue = [](auto& ctx) {
{
_val(ctx).blue_ = _attr(ctx); _val(ctx).blue_ = _attr(ctx);
}; };
auto hex2_opacity = [](auto& ctx) auto hex2_opacity = [](auto& ctx) {
{
_val(ctx).alpha_ = _attr(ctx); _val(ctx).alpha_ = _attr(ctx);
}; };
auto hsl_to_rgba = [] (auto& ctx) auto hsl_to_rgba = [](auto& ctx) {
{
double h = std::get<0>(_attr(ctx)); double h = std::get<0>(_attr(ctx));
double s = std::get<1>(_attr(ctx)); double s = std::get<1>(_attr(ctx));
double l = std::get<2>(_attr(ctx)); double l = std::get<2>(_attr(ctx));
@ -354,7 +334,7 @@ auto hsl_to_rgba = [] (auto& ctx)
safe_cast<uint8_t>(std::lround(255.0 * b)), safe_cast<uint8_t>(std::lround(255.0 * b)),
alpha); alpha);
}; };
// clang-format off
auto const hex2_color_def = no_skip[lit('#') auto const hex2_color_def = no_skip[lit('#')
>> hex2[hex2_red] >> hex2[hex2_red]
>> hex2[hex2_green] >> hex2[hex2_green]
@ -429,21 +409,13 @@ auto const css_color_def =
| |
hsla_color hsla_color
; ;
// clang-format on
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp> #include <mapnik/warning_ignore.hpp>
BOOST_SPIRIT_DEFINE( BOOST_SPIRIT_DEFINE(css_color, hex2_color, hex1_color, rgb_color, rgba_color, rgb_color_percent, rgba_color_percent);
css_color,
hex2_color,
hex1_color,
rgb_color,
rgba_color,
rgb_color_percent,
rgba_color_percent
);
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
} // ns } // namespace css_color_grammar
} //ns mapnik } // namespace mapnik
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_DEF_HPP

View file

@ -31,8 +31,7 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/spirit/home/x3.hpp> #include <boost/spirit/home/x3.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
using property_value_type = boost::iterator_range<char const*>; using property_value_type = boost::iterator_range<char const*>;
using css_key_value = std::pair<std::string, property_value_type>; using css_key_value = std::pair<std::string, property_value_type>;
using definition_type = std::vector<css_key_value>; using definition_type = std::vector<css_key_value>;
@ -40,8 +39,7 @@ using css_data = std::unordered_multimap<std::string, definition_type>;
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace css_grammar namespace css_grammar {
{
class css_tag; class css_tag;
class ident_tag; class ident_tag;
@ -58,17 +56,14 @@ css_grammar_type const css_grammar{"css"};
css_skipper_type const css_skipper{"css skipper"}; css_skipper_type const css_skipper{"css skipper"};
css_classes_type const css_classes{"css classes"}; css_classes_type const css_classes{"css classes"};
BOOST_SPIRIT_DECLARE(ident_grammar_type, BOOST_SPIRIT_DECLARE(ident_grammar_type, css_classes_type, css_grammar_type, css_skipper_type);
css_classes_type,
css_grammar_type,
css_skipper_type);
} } // namespace css_grammar
css_grammar::ident_grammar_type const ident_grammar(); css_grammar::ident_grammar_type const ident_grammar();
css_grammar::css_classes_type const classes(); css_grammar::css_classes_type const classes();
css_grammar::css_grammar_type const grammar(); css_grammar::css_grammar_type const grammar();
css_grammar::css_skipper_type const skipper(); css_grammar::css_skipper_type const skipper();
} } // namespace mapnik
#endif // MAPNIK_CSS_GRAMMAR_X3_HPP #endif // MAPNIK_CSS_GRAMMAR_X3_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP #ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
#define MAPNIK_CSS_GRAMMAR_X3_DEF_HPP #define MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
@ -33,9 +32,10 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/fusion/adapted/std_pair.hpp> #include <boost/fusion/adapted/std_pair.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
/* /*
The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing conventions, only the CSS1 syntax). The format of the productions is optimized for human consumption and some shorthand notation beyond yacc [15] is used: The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing
conventions, only the CSS1 syntax). The format of the productions is optimized for human consumption and some shorthand
notation beyond yacc [15] is used:
* : 0 or more * : 0 or more
+ : 1 or more + : 1 or more
@ -148,34 +148,36 @@ namespace x3 = boost::spirit::x3;
namespace css_grammar { namespace css_grammar {
using x3::lit; using x3::alnum;
using x3::alpha;
using x3::attr; using x3::attr;
using x3::char_;
using x3::lexeme;
using x3::lit;
using x3::no_case; using x3::no_case;
using x3::no_skip; using x3::no_skip;
using x3::lexeme;
using x3::alpha;
using x3::alnum;
using x3::char_;
using x3::raw; using x3::raw;
using x3::standard::space; using x3::standard::space;
// import unicode string rule // import unicode string rule
namespace { auto const& css_string = mapnik::json::grammar::unicode_string; } namespace {
auto const& css_string = mapnik::json::grammar::unicode_string;
}
auto assign_def = [] (auto const& ctx) auto assign_def = [](auto const& ctx) {
{
for (auto const& k : std::get<0>(_attr(ctx))) for (auto const& k : std::get<0>(_attr(ctx)))
{ {
_val(ctx).emplace(k, std::get<1>(_attr(ctx))); _val(ctx).emplace(k, std::get<1>(_attr(ctx)));
} }
}; };
auto assign_key = [] (auto const& ctx) auto assign_key = [](auto const& ctx) {
{
_val(ctx).first = std::move(_attr(ctx)); _val(ctx).first = std::move(_attr(ctx));
}; };
auto assign_value = [] (auto const& ctx) {_val(ctx).second = std::move(_attr(ctx));}; auto assign_value = [](auto const& ctx) {
_val(ctx).second = std::move(_attr(ctx));
};
// rules // rules
x3::rule<class simple_selector_tag, std::string> const simple_selector{"Simple selector"}; x3::rule<class simple_selector_tag, std::string> const simple_selector{"Simple selector"};
@ -185,9 +187,9 @@ x3::rule<class key_value_tag, css_key_value> const key_value {"CSS Key/Value"};
x3::rule<class definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition{"CSS Definition"}; x3::rule<class definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition{"CSS Definition"};
auto const ident_def = alpha >> *(alnum | char_('-')); auto const ident_def = alpha >> *(alnum | char_('-'));
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)] auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)] |
| lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)] lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)] |
| lexeme[char_('.') >> ident >> -(char_(':') >> ident)]; lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
auto const selector_def = simple_selector % lit(','); auto const selector_def = simple_selector % lit(',');
auto const value_def = raw[lexeme[+~char_(";}")]]; auto const value_def = raw[lexeme[+~char_(";}")]];
@ -202,8 +204,7 @@ auto const css_classes_def = +lexeme[ident];
#include <mapnik/warning.hpp> #include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp> #include <mapnik/warning_ignore.hpp>
BOOST_SPIRIT_DEFINE( BOOST_SPIRIT_DEFINE(ident,
ident,
css_classes, css_classes,
simple_selector, simple_selector,
selector, selector,
@ -211,12 +212,11 @@ BOOST_SPIRIT_DEFINE(
key_value, key_value,
definition, definition,
css_grammar, css_grammar,
css_skipper css_skipper);
);
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
} //css_grammar } // namespace css_grammar
} //mapnik } // namespace mapnik
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_CSS_UNIT_VALUE_HPP #ifndef MAPNIK_CSS_UNIT_VALUE_HPP
#define MAPNIK_CSS_UNIT_VALUE_HPP #define MAPNIK_CSS_UNIT_VALUE_HPP
@ -36,7 +35,7 @@ struct css_unit_value : x3::symbols<double>
constexpr static double DPI = 96; constexpr static double DPI = 96;
css_unit_value() css_unit_value()
{ {
add add //
("px", 1.0) // pixels ("px", 1.0) // pixels
("pt", DPI / 72.0) // points ("pt", DPI / 72.0) // points
("pc", DPI / 6.0) // picas ("pc", DPI / 6.0) // picas
@ -53,14 +52,14 @@ struct css_absolute_size : x3::symbols<double>
constexpr static double EM = 10.0; // 1em == 10px constexpr static double EM = 10.0; // 1em == 10px
css_absolute_size() css_absolute_size()
{ {
add add //
("xx-small", 0.6 * EM) ("xx-small", 0.6 * EM) //
("x-small", 0.75 * EM) ("x-small", 0.75 * EM) //
("small", 0.88 * EM) ("small", 0.88 * EM) //
("medium", 1.0 * EM) ("medium", 1.0 * EM) //
("large", 1.2 * EM) ("large", 1.2 * EM) //
("x-large", 1.5 * EM) ("x-large", 1.5 * EM) //
("xx-large", 2.0 * EM) ("xx-large", 2.0 * EM) //
; ;
} }
}; };
@ -69,13 +68,12 @@ struct css_relative_size : x3::symbols<double>
{ {
css_relative_size() css_relative_size()
{ {
add add //
("larger", 1.2) ("larger", 1.2) //
("smaller", 0.8) ("smaller", 0.8);
;
} }
}; };
} //mapnik } // namespace mapnik
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP

View file

@ -36,8 +36,7 @@ struct csv_white_space_skipper : x3::parser<csv_white_space_skipper>
static bool const has_attribute = false; static bool const has_attribute = false;
template<typename Iterator, typename Context, typename Attribute> template<typename Iterator, typename Context, typename Attribute>
bool parse(Iterator& first, Iterator const& last, bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
Context const& context, x3::unused_type, Attribute& ) const
{ {
x3::skip_over(first, last, context); x3::skip_over(first, last, context);
if (first != last && *first == ' ') if (first != last && *first == ' ')
@ -64,6 +63,7 @@ csv_line_grammar_type const line = "csv-line";
BOOST_SPIRIT_DECLARE(csv_line_grammar_type); BOOST_SPIRIT_DECLARE(csv_line_grammar_type);
}} } // namespace grammar
} // namespace mapnik
#endif // MAPNIK_CSV_GRAMMAR_X3_HPP #endif // MAPNIK_CSV_GRAMMAR_X3_HPP

View file

@ -29,30 +29,30 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/csv/csv_grammar_x3.hpp> #include <mapnik/csv/csv_grammar_x3.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
namespace mapnik { namespace grammar { namespace grammar {
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace standard = boost::spirit::x3::standard; namespace standard = boost::spirit::x3::standard;
using x3::lit;
using x3::lexeme;
using standard::char_; using standard::char_;
using x3::lexeme;
using x3::lit;
struct unesc_char_ : x3::symbols<char> struct unesc_char_ : x3::symbols<char>
{ {
unesc_char_() unesc_char_()
{ {
add("\\a", '\a') add("\\a", '\a') //
("\\b", '\b') ("\\b", '\b') //
("\\f", '\f') ("\\f", '\f') //
("\\n", '\n') ("\\n", '\n') //
("\\r", '\r') ("\\r", '\r') //
("\\t", '\t') ("\\t", '\t') //
("\\v", '\v') ("\\v", '\v') //
("\\\\",'\\') ("\\\\", '\\') //
("\\\'", '\'') ("\\\'", '\'') //
("\\\"", '\"') ("\\\"", '\"') //
("\"\"", '\"') // double quote ("\"\"", '\"') // double quote
; ;
} }
@ -66,8 +66,7 @@ struct literal : x3::parser<literal<T>>
static bool const has_attribute = false; static bool const has_attribute = false;
template<typename Iterator, typename Context, typename Attribute> template<typename Iterator, typename Context, typename Attribute>
bool parse(Iterator& first, Iterator const& last, bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
Context const& context, x3::unused_type, Attribute& ) const
{ {
x3::skip_over(first, last, context); x3::skip_over(first, last, context);
if (first != last && *first == x3::get<context_tag>(context)) if (first != last && *first == x3::get<context_tag>(context))
@ -87,27 +86,18 @@ x3::rule<class csv_column, csv_value> const column("csv-column");
x3::rule<class csv_text, csv_value> const text("csv-text"); x3::rule<class csv_text, csv_value> const text("csv-text");
x3::rule<class csc_quoted_text, csv_value> const quoted_text("csv-quoted-text"); x3::rule<class csc_quoted_text, csv_value> const quoted_text("csv-quoted-text");
auto const line_def = -lit('\r') > -lit('\n') > lexeme[column] % separator auto const line_def = -lit('\r') > -lit('\n') > lexeme[column] % separator;
;
auto const column_def = quoted_text | *(char_ - separator) auto const column_def = quoted_text | *(char_ - separator);
;
auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??) auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??)
; ;
auto const text_def = *(unesc_char | (char_ - quote)) auto const text_def = *(unesc_char | (char_ - quote));
;
BOOST_SPIRIT_DEFINE ( BOOST_SPIRIT_DEFINE(line, column, quoted_text, text);
line,
column,
quoted_text,
text
);
} // grammar } // namespace grammar
} // namespace mapnik } // namespace mapnik
#endif // MAPNIK_CSV_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_CSV_GRAMMAR_X3_DEF_HPP

View file

@ -32,6 +32,6 @@ using csv_value = std::string;
using csv_line = std::vector<csv_value>; using csv_line = std::vector<csv_value>;
using csv_data = std::vector<csv_line>; using csv_data = std::vector<csv_line>;
} } // namespace mapnik
#endif // MAPNIK_CSV_TYPES_HPP #endif // MAPNIK_CSV_TYPES_HPP

View file

@ -50,10 +50,8 @@ public:
~datasource_exception() {} ~datasource_exception() {}
virtual const char* what() const noexcept virtual const char* what() const noexcept { return message_.c_str(); }
{
return message_.c_str();
}
private: private:
std::string message_; std::string message_;
}; };
@ -61,13 +59,11 @@ private:
class MAPNIK_DECL datasource : private util::noncopyable class MAPNIK_DECL datasource : private util::noncopyable
{ {
public: public:
enum datasource_t : std::uint8_t { enum datasource_t : std::uint8_t { Vector, Raster };
Vector,
Raster
};
datasource(parameters const& _params) datasource(parameters const& _params)
: params_(_params) {} : params_(_params)
{}
/*! /*!
* @brief Get the configuration parameters of the data source. * @brief Get the configuration parameters of the data source.
@ -76,25 +72,13 @@ public:
* *
* @return The configuration parameters of the data source. * @return The configuration parameters of the data source.
*/ */
parameters const& params() const parameters const& params() const { return params_; }
{
return params_;
}
parameters & params() parameters& params() { return params_; }
{
return params_;
}
bool operator==(datasource const& rhs) const bool operator==(datasource const& rhs) const { return params_ == rhs.params(); }
{
return params_ == rhs.params();
}
bool operator!=(datasource const& rhs) const bool operator!=(datasource const& rhs) const { return !(*this == rhs); }
{
return !(*this == rhs);
}
/*! /*!
* @brief Get the type of the datasource * @brief Get the type of the datasource
@ -113,6 +97,7 @@ public:
virtual box2d<double> envelope() const = 0; virtual box2d<double> envelope() const = 0;
virtual layer_descriptor get_descriptor() const = 0; virtual layer_descriptor get_descriptor() const = 0;
virtual ~datasource() {} virtual ~datasource() {}
protected: protected:
parameters params_; parameters params_;
}; };
@ -124,10 +109,7 @@ using destroy_ds = void (*) (datasource *);
class datasource_deleter class datasource_deleter
{ {
public: public:
void operator() (datasource* ds) void operator()(datasource* ds) { delete ds; }
{
delete ds;
}
}; };
using datasource_ptr = std::shared_ptr<datasource>; using datasource_ptr = std::shared_ptr<datasource>;
@ -136,20 +118,11 @@ using datasource_ptr = std::shared_ptr<datasource>;
#define DATASOURCE_PLUGIN(classname) #define DATASOURCE_PLUGIN(classname)
#else #else
#define DATASOURCE_PLUGIN(classname) \ #define DATASOURCE_PLUGIN(classname) \
extern "C" MAPNIK_EXP const char * datasource_name() \ extern "C" MAPNIK_EXP const char* datasource_name() { return classname::name(); } \
{ \ extern "C" MAPNIK_EXP datasource* create(parameters const& params) { return new classname(params); } \
return classname::name(); \ extern "C" MAPNIK_EXP void destroy(datasource* ds) { delete ds; }
} \
extern "C" MAPNIK_EXP datasource* create(parameters const& params) \
{ \
return new classname(params); \
} \
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
{ \
delete ds; \
}
#endif #endif
} } // namespace mapnik
#endif // MAPNIK_DATASOURCE_HPP #endif // MAPNIK_DATASOURCE_HPP

View file

@ -41,17 +41,18 @@ class datasource;
class parameters; class parameters;
class PluginInfo; class PluginInfo;
class MAPNIK_DECL datasource_cache class MAPNIK_DECL datasource_cache : public singleton<datasource_cache, CreateStatic>,
: public singleton<datasource_cache, CreateStatic>,
private util::noncopyable private util::noncopyable
{ {
friend class CreateStatic<datasource_cache>; friend class CreateStatic<datasource_cache>;
public: public:
std::vector<std::string> plugin_names(); std::vector<std::string> plugin_names();
std::string plugin_directories(); std::string plugin_directories();
bool register_datasources(std::string const& path, bool recurse = false); bool register_datasources(std::string const& path, bool recurse = false);
bool register_datasource(std::string const& path); bool register_datasource(std::string const& path);
std::shared_ptr<datasource> create(parameters const& params); std::shared_ptr<datasource> create(parameters const& params);
private: private:
datasource_cache(); datasource_cache();
~datasource_cache(); ~datasource_cache();
@ -66,6 +67,6 @@ private:
extern template class MAPNIK_DECL singleton<datasource_cache, CreateStatic>; extern template class MAPNIK_DECL singleton<datasource_cache, CreateStatic>;
} } // namespace mapnik
#endif // MAPNIK_DATASOURCE_CACHE_HPP #endif // MAPNIK_DATASOURCE_CACHE_HPP

View file

@ -27,15 +27,8 @@
namespace mapnik { namespace mapnik {
enum datasource_geometry_t : std::uint8_t { enum datasource_geometry_t : std::uint8_t { Unknown = 0, Point = 1, LineString = 2, Polygon = 3, Collection = 4 };
Unknown = 0,
Point = 1,
LineString = 2,
Polygon = 3,
Collection = 4
};
} }
#endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP #endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP

View file

@ -42,35 +42,21 @@
namespace mapnik { namespace mapnik {
// Global logger class that holds the configuration of severity, format // Global logger class that holds the configuration of severity, format
// and file/console redirection. // and file/console redirection.
class MAPNIK_DECL logger : class MAPNIK_DECL logger : public singleton<logger, CreateStatic>,
public singleton<logger,CreateStatic>,
private util::noncopyable private util::noncopyable
{ {
public: public:
enum severity_type enum severity_type { debug = 0, warn = 1, error = 2, none = 3 };
{
debug = 0,
warn = 1,
error = 2,
none = 3
};
using severity_map = std::unordered_map<std::string, severity_type>; using severity_map = std::unordered_map<std::string, severity_type>;
// global security level // global security level
static severity_type get_severity() static severity_type get_severity() { return severity_level_; }
{
return severity_level_;
}
static void set_severity(severity_type severity_level) static void set_severity(severity_type severity_level) { severity_level_ = severity_level; }
{
severity_level_ = severity_level;
}
// per object security levels // per object security levels
static severity_type get_object_severity(std::string const& object_name) static severity_type get_object_severity(std::string const& object_name)
@ -89,8 +75,7 @@ public:
} }
} }
static void set_object_severity(std::string const& object_name, static void set_object_severity(std::string const& object_name, severity_type const& security_level)
severity_type const& security_level)
{ {
if (!object_name.empty()) if (!object_name.empty())
{ {
@ -111,10 +96,7 @@ public:
} }
// format // format
static std::string const& get_format() static std::string const& get_format() { return format_; }
{
return format_;
}
static void set_format(std::string const& format) static void set_format(std::string const& format)
{ {
@ -151,7 +133,6 @@ private:
#endif #endif
}; };
namespace detail { namespace detail {
// Default sink, it regulates access to clog // Default sink, it regulates access to clog
@ -198,9 +179,7 @@ public:
} }
} }
#else #else
base_log(const char* /*object_name*/) base_log(const char* /*object_name*/) {}
{
}
#endif #endif
~base_log() ~base_log()
@ -217,32 +196,25 @@ public:
#ifdef MAPNIK_LOG #ifdef MAPNIK_LOG
base_log& operator<<(T const& x) base_log& operator<<(T const& x)
{ {
streambuf_ << x; streambuf_ << x;
return *this; return *this;
} }
#else #else
base_log& operator<<(T const& /*x*/) base_log& operator<<(T const& /*x*/)
{ {
return *this; return *this;
} }
#endif #endif
private: private:
#ifdef MAPNIK_LOG #ifdef MAPNIK_LOG
inline bool check_severity() inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
{
return Severity >= logger::get_object_severity(object_name_);
}
typename output_policy::stream_buffer streambuf_; typename output_policy::stream_buffer streambuf_;
std::string object_name_; std::string object_name_;
#endif #endif
}; };
// Base log class that always log, regardless of MAPNIK_LOG. // Base log class that always log, regardless of MAPNIK_LOG.
// This is used for error reporting that should always log something // This is used for error reporting that should always log something
@ -282,49 +254,56 @@ public:
} }
private: private:
inline bool check_severity() inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
{
return Severity >= logger::get_object_severity(object_name_);
}
typename output_policy::stream_buffer streambuf_; typename output_policy::stream_buffer streambuf_;
std::string object_name_; std::string object_name_;
}; };
using base_log_debug = base_log<clog_sink, logger::debug>; using base_log_debug = base_log<clog_sink, logger::debug>;
using base_log_warn = base_log<clog_sink, logger::warn>; using base_log_warn = base_log<clog_sink, logger::warn>;
using base_log_error = base_log_always<clog_sink, logger::error>; using base_log_error = base_log_always<clog_sink, logger::error>;
} // namespace detail } // namespace detail
// real interfaces // real interfaces
class MAPNIK_DECL warn : public detail::base_log_warn class MAPNIK_DECL warn : public detail::base_log_warn
{ {
public: public:
warn() : detail::base_log_warn() {} warn()
warn(const char* object_name) : detail::base_log_warn(object_name) {} : detail::base_log_warn()
{}
warn(const char* object_name)
: detail::base_log_warn(object_name)
{}
}; };
class MAPNIK_DECL debug : public detail::base_log_debug class MAPNIK_DECL debug : public detail::base_log_debug
{ {
public: public:
debug() : detail::base_log_debug() {} debug()
debug(const char* object_name) : detail::base_log_debug(object_name) {} : detail::base_log_debug()
{}
debug(const char* object_name)
: detail::base_log_debug(object_name)
{}
}; };
class MAPNIK_DECL error : public detail::base_log_error class MAPNIK_DECL error : public detail::base_log_error
{ {
public: public:
error() : detail::base_log_error() {} error()
error(const char* object_name) : detail::base_log_error(object_name) {} : detail::base_log_error()
{}
error(const char* object_name)
: detail::base_log_error(object_name)
{}
}; };
// logging helpers // logging helpers
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s) #define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)
#define MAPNIK_LOG_WARN(s) mapnik::warn(#s) #define MAPNIK_LOG_WARN(s) mapnik::warn(#s)
#define MAPNIK_LOG_ERROR(s) mapnik::error(#s) #define MAPNIK_LOG_ERROR(s) mapnik::error(#s)
} } // namespace mapnik
#endif // MAPNIK_DEBUG_HPP #endif // MAPNIK_DEBUG_HPP

View file

@ -39,25 +39,21 @@ namespace mapnik {
class illegal_enum_value : public std::exception class illegal_enum_value : public std::exception
{ {
public: public:
illegal_enum_value(): illegal_enum_value()
what_() {} : what_()
{}
illegal_enum_value( std::string const& _what ) : illegal_enum_value(std::string const& _what)
what_( _what ) : what_(_what)
{ {}
}
virtual ~illegal_enum_value() {} virtual ~illegal_enum_value() {}
virtual const char * what() const noexcept virtual const char* what() const noexcept { return what_.c_str(); }
{
return what_.c_str();
}
protected: protected:
std::string what_; std::string what_;
}; };
/** Slim wrapper for enumerations. It creates a new type from a native enum and /** Slim wrapper for enumerations. It creates a new type from a native enum and
* a char pointer array. It almost exactly behaves like a native enumeration * a char pointer array. It almost exactly behaves like a native enumeration
* type. It supports string conversion through stream operators. This is useful * type. It supports string conversion through stream operators. This is useful
@ -138,41 +134,33 @@ protected:
*/ */
template<typename ENUM, int THE_MAX> template<typename ENUM, int THE_MAX>
class MAPNIK_DECL enumeration { class MAPNIK_DECL enumeration
{
public: public:
using native_type = ENUM; using native_type = ENUM;
enumeration() enumeration()
: value_() {} : value_()
{}
enumeration(ENUM v) enumeration(ENUM v)
: value_(v) {} : value_(v)
{}
enumeration(enumeration const& other) enumeration(enumeration const& other)
: value_(other.value_) {} : value_(other.value_)
{}
/** Assignment operator for native enum values. */ /** Assignment operator for native enum values. */
void operator=(ENUM v) void operator=(ENUM v) { value_ = v; }
{
value_ = v;
}
/** Assignment operator. */ /** Assignment operator. */
void operator=(enumeration const& other) void operator=(enumeration const& other) { value_ = other.value_; }
{
value_ = other.value_;
}
/** Conversion operator for native enum values. */ /** Conversion operator for native enum values. */
operator ENUM() const operator ENUM() const { return value_; }
{
return value_;
}
enum Max enum Max { MAX = THE_MAX };
{
MAX = THE_MAX
};
/** Converts @p str to an enum. /** Converts @p str to an enum.
* @throw illegal_enum_value @p str is not a legal identifier. * @throw illegal_enum_value @p str is not a legal identifier.
@ -190,7 +178,6 @@ public:
} }
for (unsigned i = 0; i < THE_MAX; ++i) for (unsigned i = 0; i < THE_MAX; ++i)
{ {
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS MAPNIK_DISABLE_WARNING_PRAGMAS
@ -201,7 +188,10 @@ MAPNIK_DISABLE_WARNING_POP
value_ = static_cast<ENUM>(i); value_ = static_cast<ENUM>(i);
if (deprecated) if (deprecated)
{ {
MAPNIK_LOG_ERROR(enumerations) << "enumeration value (" << str << ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy << "' instead"; MAPNIK_LOG_ERROR(enumerations)
<< "enumeration value (" << str
<< ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy
<< "' instead";
} }
return; return;
} }
@ -210,8 +200,7 @@ MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS MAPNIK_DISABLE_WARNING_PRAGMAS
MAPNIK_DISABLE_LONG_LONG MAPNIK_DISABLE_LONG_LONG
throw illegal_enum_value(std::string("Illegal enumeration value '") + throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_);
str + "' for enum " + our_name_);
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
} }
@ -227,10 +216,7 @@ MAPNIK_DISABLE_WARNING_POP
} }
/** Static helper function to iterate over valid identifiers. */ /** Static helper function to iterate over valid identifiers. */
static const char * get_string(unsigned i) static const char* get_string(unsigned i) { return our_strings_[i]; }
{
return our_strings_[i];
}
/** Performs some simple checks and quits the application if /** Performs some simple checks and quits the application if
* any error is detected. Tries to print helpful error messages. * any error is detected. Tries to print helpful error messages.
@ -241,16 +227,14 @@ MAPNIK_DISABLE_WARNING_POP
{ {
if (our_strings_[i] == 0) if (our_strings_[i] == 0)
{ {
std::cerr << "### FATAL: Not enough strings for enum " std::cerr << "### FATAL: Not enough strings for enum " << our_name_ << " defined in file '" << filename
<< our_name_ << " defined in file '" << filename
<< "' at line " << line_no; << "' at line " << line_no;
} }
} }
if (std::string("") != our_strings_[THE_MAX]) if (std::string("") != our_strings_[THE_MAX])
{ {
std::cerr << "### FATAL: The string array for enum " << our_name_ std::cerr << "### FATAL: The string array for enum " << our_name_ << " defined in file '" << filename
<< " defined in file '" << filename << "' at line " << line_no << "' at line " << line_no << " has too many items or is not terminated with an "
<< " has too many items or is not terminated with an "
<< "empty string"; << "empty string";
} }
return true; return true;
@ -267,13 +251,12 @@ private:
* @relates mapnik::enumeration * @relates mapnik::enumeration
*/ */
template<class ENUM, int THE_MAX> template<class ENUM, int THE_MAX>
std::ostream & std::ostream& operator<<(std::ostream& os, const mapnik::enumeration<ENUM, THE_MAX>& e)
operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
{ {
return os << e.as_string(); return os << e.as_string();
} }
} // end of namespace } // namespace mapnik
/** Helper macro. /** Helper macro.
* @relates mapnik::enumeration * @relates mapnik::enumeration
@ -285,9 +268,12 @@ operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
#else #else
#define DEFINE_ENUM(name, e) \ #define DEFINE_ENUM(name, e) \
using name = enumeration<e, e##_MAX>; \ using name = enumeration<e, e##_MAX>; \
template <> MAPNIK_DECL const char ** name ::our_strings_; \ template<> \
template <> MAPNIK_DECL std::string name ::our_name_; \ MAPNIK_DECL const char** name ::our_strings_; \
template <> MAPNIK_DECL bool name ::our_verified_flag_; template<> \
MAPNIK_DECL std::string name ::our_name_; \
template<> \
MAPNIK_DECL bool name ::our_verified_flag_;
#endif #endif
/** Helper macro. Runs the verify_mapnik_enum() method during static initialization. /** Helper macro. Runs the verify_mapnik_enum() method during static initialization.
@ -295,8 +281,11 @@ operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
*/ */
#define IMPLEMENT_ENUM(name, strings) \ #define IMPLEMENT_ENUM(name, strings) \
template <> MAPNIK_DECL const char ** name ::our_strings_ = strings; \ template<> \
template <> MAPNIK_DECL std::string name ::our_name_ = #name; \ MAPNIK_DECL const char** name ::our_strings_ = strings; \
template <> MAPNIK_DECL bool name ::our_verified_flag_( name ::verify_mapnik_enum(__FILE__, __LINE__)); template<> \
MAPNIK_DECL std::string name ::our_name_ = #name; \
template<> \
MAPNIK_DECL bool name ::our_verified_flag_(name ::verify_mapnik_enum(__FILE__, __LINE__));
#endif // MAPNIK_ENUMERATION_HPP #endif // MAPNIK_ENUMERATION_HPP

View file

@ -44,7 +44,8 @@ struct evaluate_expression
using value_type = T; using value_type = T;
explicit evaluate_expression(Attributes const& attrs) explicit evaluate_expression(Attributes const& attrs)
: attrs_(attrs) {} : attrs_(attrs)
{}
value_type operator()(attribute const&) const value_type operator()(attribute const&) const
{ {
@ -68,22 +69,19 @@ struct evaluate_expression
value_type operator()(binary_node<tags::logical_and> const& x) const value_type operator()(binary_node<tags::logical_and> const& x) const
{ {
return (util::apply_visitor(*this, x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
&& (util::apply_visitor(*this, x.right).to_bool());
} }
value_type operator()(binary_node<tags::logical_or> const& x) const value_type operator()(binary_node<tags::logical_or> const& x) const
{ {
return (util::apply_visitor(*this,x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|| (util::apply_visitor(*this,x.right).to_bool());
} }
template<typename Tag> template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const value_type operator()(binary_node<Tag> const& x) const
{ {
typename make_op<Tag>::type operation; typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left), return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
util::apply_visitor(*this, x.right));
} }
template<typename Tag> template<typename Tag>
@ -156,22 +154,19 @@ struct evaluate_expression<T, boost::none_t>
value_type operator()(binary_node<tags::logical_and> const& x) const value_type operator()(binary_node<tags::logical_and> const& x) const
{ {
return (util::apply_visitor(*this, x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
&& (util::apply_visitor(*this, x.right).to_bool());
} }
value_type operator()(binary_node<tags::logical_or> const& x) const value_type operator()(binary_node<tags::logical_or> const& x) const
{ {
return (util::apply_visitor(*this,x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|| (util::apply_visitor(*this,x.right).to_bool());
} }
template<typename Tag> template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const value_type operator()(binary_node<Tag> const& x) const
{ {
typename make_op<Tag>::type operation; typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left), return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
util::apply_visitor(*this, x.right));
} }
template<typename Tag> template<typename Tag>
@ -221,33 +216,39 @@ struct evaluate_expression<T, boost::none_t>
struct assign_value struct assign_value
{ {
template<typename Attributes> template<typename Attributes>
static void apply(symbolizer_base::value_type & val, expression_ptr const& expr, Attributes const& attrs, property_types target ) static void apply(symbolizer_base::value_type& val,
expression_ptr const& expr,
Attributes const& attrs,
property_types target)
{ {
switch (target) switch (target)
{ {
case property_types::target_color: case property_types::target_color: {
{
// evaluate expression as a string then parse as css color // evaluate expression as a string then parse as css color
std::string str = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, std::string str =
Attributes>(attrs),*expr).to_string(); util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_string();
try { val = parse_color(str); } try
catch (...) { val = color(0,0,0);} {
val = parse_color(str);
} catch (...)
{
val = color(0, 0, 0);
}
break; break;
} }
case property_types::target_double: case property_types::target_double: {
{ val =
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_double(); util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_double();
break; break;
} }
case property_types::target_integer: case property_types::target_integer: {
{ val =
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_int(); util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_int();
break; break;
} }
case property_types::target_bool: case property_types::target_bool: {
{ val =
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_bool(); util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_bool();
break; break;
} }
default: // no-op default: // no-op
@ -256,16 +257,16 @@ struct assign_value
} }
}; };
} } // namespace
template<typename T> template<typename T>
std::tuple<T, bool> pre_evaluate_expression(expression_ptr const& expr) std::tuple<T, bool> pre_evaluate_expression(expression_ptr const& expr)
{ {
try try
{ {
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none),*expr), true); return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none), *expr),
} true);
catch (...) } catch (...)
{ {
return std::make_tuple(T(), false); return std::make_tuple(T(), false);
} }
@ -277,8 +278,9 @@ struct evaluate_global_attributes : util::noncopyable
struct evaluator struct evaluator
{ {
evaluator(symbolizer_base::cont_type::value_type& prop, Attributes const& attrs) evaluator(symbolizer_base::cont_type::value_type& prop, Attributes const& attrs)
: prop_(prop), : prop_(prop)
attrs_(attrs) {} , attrs_(attrs)
{}
void operator()(expression_ptr const& expr) const void operator()(expression_ptr const& expr) const
{ {
@ -299,7 +301,8 @@ struct evaluate_global_attributes : util::noncopyable
struct extract_symbolizer struct extract_symbolizer
{ {
extract_symbolizer(Attributes const& attrs) extract_symbolizer(Attributes const& attrs)
: attrs_(attrs) {} : attrs_(attrs)
{}
template<typename Symbolizer> template<typename Symbolizer>
void operator()(Symbolizer& sym) const void operator()(Symbolizer& sym) const
@ -328,6 +331,6 @@ struct evaluate_global_attributes : util::noncopyable
} }
}; };
} } // namespace mapnik
#endif // MAPNIK_EVALUATE_GLOBAL_ATTRIBUTES_HPP #endif // MAPNIK_EVALUATE_GLOBAL_ATTRIBUTES_HPP

View file

@ -34,14 +34,13 @@
#include <string> #include <string>
#include <set> #include <set>
namespace mapnik namespace mapnik {
{
// fwd declare to reduce compile time // fwd declare to reduce compile time
using expression_ptr = std::shared_ptr<expr_node>; using expression_ptr = std::shared_ptr<expr_node>;
using expression_set = std::set<expression_ptr>; using expression_set = std::set<expression_ptr>;
MAPNIK_DECL expression_ptr parse_expression(std::string const& wkt); MAPNIK_DECL expression_ptr parse_expression(std::string const& wkt);
} } // namespace mapnik
#endif // MAPNIK_EXPRESSION_HPP #endif // MAPNIK_EXPRESSION_HPP

View file

@ -31,8 +31,7 @@
#include <mapnik/util/variant.hpp> #include <mapnik/util/variant.hpp>
#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
namespace mapnik namespace mapnik {
{
template<typename T0, typename T1, typename T2> template<typename T0, typename T1, typename T2>
struct evaluate struct evaluate
@ -42,38 +41,21 @@ struct evaluate
using variable_type = T2; using variable_type = T2;
using result_type = T1; // we need this because automatic result_type deduction fails using result_type = T1; // we need this because automatic result_type deduction fails
explicit evaluate(feature_type const& f, variable_type const& v) explicit evaluate(feature_type const& f, variable_type const& v)
: feature_(f), : feature_(f)
vars_(v) {} , vars_(v)
{}
value_type operator() (value_integer val) const value_type operator()(value_integer val) const { return val; }
{
return val;
}
value_type operator() (value_double val) const value_type operator()(value_double val) const { return val; }
{
return val;
}
value_type operator() (value_bool val) const value_type operator()(value_bool val) const { return val; }
{
return val;
}
value_type operator() (value_null val) const value_type operator()(value_null val) const { return val; }
{
return val;
}
value_type operator() (value_unicode_string const& str) const value_type operator()(value_unicode_string const& str) const { return str; }
{
return str;
}
value_type operator() (attribute const& attr) const value_type operator()(attribute const& attr) const { return attr.value<value_type, feature_type>(feature_); }
{
return attr.value<value_type,feature_type>(feature_);
}
value_type operator()(global_attribute const& attr) const value_type operator()(global_attribute const& attr) const
{ {
@ -92,22 +74,19 @@ struct evaluate
value_type operator()(binary_node<tags::logical_and> const& x) const value_type operator()(binary_node<tags::logical_and> const& x) const
{ {
return (util::apply_visitor(*this, x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
&& (util::apply_visitor(*this, x.right).to_bool());
} }
value_type operator()(binary_node<tags::logical_or> const& x) const value_type operator()(binary_node<tags::logical_or> const& x) const
{ {
return (util::apply_visitor(*this, x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|| (util::apply_visitor(*this, x.right).to_bool());
} }
template<typename Tag> template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const value_type operator()(binary_node<Tag> const& x) const
{ {
typename make_op<Tag>::type operation; typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left), return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
util::apply_visitor(*this, x.right));
} }
template<typename Tag> template<typename Tag>
@ -151,6 +130,6 @@ struct evaluate
variable_type const& vars_; variable_type const& vars_;
}; };
} } // namespace mapnik
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP #endif // MAPNIK_EXPRESSION_EVALUATOR_HPP

View file

@ -31,7 +31,8 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/spirit/home/x3.hpp> #include <boost/spirit/home/x3.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace grammar { namespace mapnik {
namespace grammar {
#if BOOST_VERSION >= 106700 #if BOOST_VERSION >= 106700
using transcoder_type = mapnik::transcoder; using transcoder_type = mapnik::transcoder;
@ -39,7 +40,6 @@ using transcoder_type = mapnik::transcoder;
using transcoder_type = std::reference_wrapper<mapnik::transcoder const>; using transcoder_type = std::reference_wrapper<mapnik::transcoder const>;
#endif #endif
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
struct transcoder_tag; struct transcoder_tag;
struct expression_class; // top-most ID struct expression_class; // top-most ID
@ -49,6 +49,7 @@ expression_grammar_type const expression("expression");
BOOST_SPIRIT_DECLARE(expression_grammar_type); BOOST_SPIRIT_DECLARE(expression_grammar_type);
}} } // namespace grammar
} // namespace mapnik
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP #endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP

View file

@ -26,16 +26,16 @@
#include <mapnik/expression_grammar_x3.hpp> #include <mapnik/expression_grammar_x3.hpp>
#include <string> #include <string>
namespace mapnik { namespace grammar { namespace mapnik {
namespace grammar {
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
using iterator_type = std::string::const_iterator; using iterator_type = std::string::const_iterator;
using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type; using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;
// define combined context // define combined context
using context_type = x3::context<transcoder_tag, using context_type = x3::context<transcoder_tag, transcoder_type const, phrase_context_type>;
transcoder_type const,
phrase_context_type>;
}} } // namespace grammar
} // namespace mapnik
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP #endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP

View file

@ -24,47 +24,45 @@
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP #define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
#include <mapnik/expression_grammar_x3.hpp> #include <mapnik/expression_grammar_x3.hpp>
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
#include <mapnik/expression_node.hpp> #include <mapnik/expression_node.hpp>
#include <mapnik/function_call.hpp> #include <mapnik/function_call.hpp>
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
#include <mapnik/unicode.hpp> #include <mapnik/unicode.hpp>
#include <mapnik/warning.hpp> #include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/std_pair.hpp> #include <boost/fusion/include/std_pair.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <mapnik/warning_ignore.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call, BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call,
(mapnik::unary_function_impl, fun) (mapnik::unary_function_impl, fun)(mapnik::unary_function_call::argument_type, arg))
(mapnik::unary_function_call::argument_type, arg))
BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call, BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call,
(mapnik::binary_function_impl, fun) (mapnik::binary_function_impl, fun)(mapnik::binary_function_call::argument_type,
(mapnik::binary_function_call::argument_type, arg1) arg1)(mapnik::binary_function_call::argument_type, arg2))
(mapnik::binary_function_call::argument_type, arg2))
namespace mapnik {
namespace mapnik { namespace grammar { namespace grammar {
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace ascii = boost::spirit::x3::ascii; namespace ascii = boost::spirit::x3::ascii;
using ascii::char_; using ascii::char_;
using ascii::string; using ascii::string;
using x3::lit;
using x3::double_;
using x3::int_;
using x3::bool_;
using x3::_attr; using x3::_attr;
using x3::_val; using x3::_val;
using x3::no_skip;
using x3::lexeme;
using x3::no_case;
using x3::alpha;
using x3::alnum; using x3::alnum;
using x3::alpha;
using x3::bool_;
using x3::double_;
using x3::int_;
using x3::lexeme;
using x3::lit;
using x3::no_case;
using x3::no_skip;
x3::uint_parser<char, 16, 2, 2> const hex2{}; x3::uint_parser<char, 16, 2, 2> const hex2{};
namespace { namespace {
@ -77,23 +75,19 @@ namespace mapnik { namespace grammar {
return x3::get<transcoder_tag>(ctx); return x3::get<transcoder_tag>(ctx);
} }
auto append = [](auto const& ctx) auto append = [](auto const& ctx) {
{
_val(ctx) += _attr(ctx); _val(ctx) += _attr(ctx);
}; };
auto do_assign = [] (auto const& ctx) auto do_assign = [](auto const& ctx) {
{
_val(ctx) = std::move(_attr(ctx)); _val(ctx) = std::move(_attr(ctx));
}; };
auto do_negate = [] (auto const& ctx) auto do_negate = [](auto const& ctx) {
{
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx))); _val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx)));
}; };
auto do_attribute = [] (auto const& ctx) auto do_attribute = [](auto const& ctx) {
{
auto const& attr = _attr(ctx); auto const& attr = _attr(ctx);
if (attr == "mapnik::geometry_type") if (attr == "mapnik::geometry_type")
{ {
@ -105,102 +99,84 @@ namespace mapnik { namespace grammar {
} }
}; };
auto do_global_attribute = [] (auto const& ctx) auto do_global_attribute = [](auto const& ctx) {
{
_val(ctx) = std::move(global_attribute(_attr(ctx))); _val(ctx) = std::move(global_attribute(_attr(ctx)));
}; };
auto do_add = [] (auto const& ctx) auto do_add = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_subt = [] (auto const& ctx) auto do_subt = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_mult = [] (auto const& ctx) auto do_mult = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_div = [] (auto const& ctx) auto do_div = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_mod = [] (auto const& ctx) auto do_mod = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_unicode = [] (auto const& ctx) auto do_unicode = [](auto const& ctx) {
{
auto const& tr = extract_transcoder(ctx); auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str())); _val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
}; };
auto do_null = [] (auto const& ctx) auto do_null = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::value_null()); _val(ctx) = std::move(mapnik::value_null());
}; };
auto do_not = [] (auto const& ctx) auto do_not = [](auto const& ctx) {
{
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx)); mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
_val(ctx) = std::move(node); _val(ctx) = std::move(node);
}; };
auto do_and = [] (auto const& ctx) auto do_and = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_or = [] (auto const& ctx) auto do_or = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_equal = [] (auto const& ctx) auto do_equal = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_not_equal = [] (auto const& ctx) auto do_not_equal = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_less = [] (auto const& ctx) auto do_less = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_less_equal = [] (auto const& ctx) auto do_less_equal = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less_equal>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_greater = [] (auto const& ctx) auto do_greater = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_greater_equal = [] (auto const& ctx) auto do_greater_equal = [](auto const& ctx) {
{ _val(ctx) =
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx)))); std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
// regex // regex
auto do_regex_match = [] (auto const& ctx) auto do_regex_match = [](auto const& ctx) {
{
auto const& tr = extract_transcoder(ctx); auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_regex_replace = [] (auto const& ctx) auto do_regex_replace = [](auto const& ctx) {
{
auto const& tr = extract_transcoder(ctx); auto const& tr = extract_transcoder(ctx);
auto const& pair = _attr(ctx); auto const& pair = _attr(ctx);
auto const& pattern = std::get<0>(pair); auto const& pattern = std::get<0>(pair);
@ -217,9 +193,8 @@ namespace mapnik { namespace grammar {
{ {
boolean_() boolean_()
{ {
add add("true", true) //
("true", true) ("false", false) //
("false", false)
; ;
} }
} boolean; } boolean;
@ -228,10 +203,9 @@ namespace mapnik { namespace grammar {
{ {
floating_point_constants() floating_point_constants()
{ {
add add("pi", 3.1415926535897932384626433832795) //
("pi", 3.1415926535897932384626433832795) ("deg_to_rad", 0.017453292519943295769236907684886) //
("deg_to_rad",0.017453292519943295769236907684886) ("rad_to_deg", 57.295779513082320876798154814105) //
("rad_to_deg",57.295779513082320876798154814105)
; ;
} }
} float_const; } float_const;
@ -241,30 +215,27 @@ namespace mapnik { namespace grammar {
{ {
unary_function_types_() unary_function_types_()
{ {
add add("sin", sin_impl()) //
("sin", sin_impl()) ("cos", cos_impl()) //
("cos", cos_impl()) ("tan", tan_impl()) //
("tan", tan_impl()) ("atan", atan_impl()) //
("atan", atan_impl()) ("exp", exp_impl()) //
("exp", exp_impl()) ("log", log_impl()) //
("log", log_impl()) ("abs", abs_impl()) //
("abs", abs_impl()) ("length", length_impl()) //
("length",length_impl())
; ;
} }
} unary_func_types; } unary_func_types;
// binary functions // binary functions
struct binary_function_types_ : x3::symbols<binary_function_impl> struct binary_function_types_ : x3::symbols<binary_function_impl>
{ {
binary_function_types_() binary_function_types_()
{ {
add add("min", binary_function_impl(min_impl)) //
("min", binary_function_impl(min_impl)) ("max", binary_function_impl(max_impl)) //
("max", binary_function_impl(max_impl)) ("pow", binary_function_impl(pow_impl)) //
("pow", binary_function_impl(pow_impl))
; ;
} }
} binary_func_types; } binary_func_types;
@ -274,11 +245,10 @@ namespace mapnik { namespace grammar {
{ {
geometry_types_() geometry_types_()
{ {
add add("point", 1) //
("point", 1) ("linestring", 2) //
("linestring", 2) ("polygon", 3) //
("polygon",3) ("collection", 4) //
("collection",4)
; ;
} }
} geometry_type; } geometry_type;
@ -287,17 +257,16 @@ namespace mapnik { namespace grammar {
{ {
unesc_chars_() unesc_chars_()
{ {
add add("\\a", '\a') //
("\\a", '\a') ("\\b", '\b') //
("\\b", '\b') ("\\f", '\f') //
("\\f", '\f') ("\\n", '\n') //
("\\n", '\n') ("\\r", '\r') //
("\\r", '\r') ("\\t", '\t') //
("\\t", '\t') ("\\v", '\v') //
("\\v", '\v') ("\\\\", '\\') //
("\\\\", '\\') ("\\\'", '\'') //
("\\\'", '\'') ("\\\"", '\"') //
("\\\"", '\"')
; ;
} }
} unesc_char; } unesc_char;
@ -309,14 +278,18 @@ namespace mapnik { namespace grammar {
x3::rule<class equality_expression, mapnik::expr_node> const equality_expression("equality expression"); x3::rule<class equality_expression, mapnik::expr_node> const equality_expression("equality expression");
x3::rule<class relational_expression, mapnik::expr_node> const relational_expression("relational expression"); x3::rule<class relational_expression, mapnik::expr_node> const relational_expression("relational expression");
x3::rule<class additive_expression, mapnik::expr_node> const additive_expression("additive expression"); x3::rule<class additive_expression, mapnik::expr_node> const additive_expression("additive expression");
x3::rule<class multiplicative_expression, mapnik::expr_node> const multiplicative_expression("multiplicative expression"); x3::rule<class multiplicative_expression, mapnik::expr_node> const
x3::rule<class unary_func_expression, mapnik::unary_function_call> const unary_func_expression("unary function expression"); multiplicative_expression("multiplicative expression");
x3::rule<class binary_func_expression, mapnik::binary_function_call> const binary_func_expression("binary function expression"); x3::rule<class unary_func_expression, mapnik::unary_function_call> const
unary_func_expression("unary function expression");
x3::rule<class binary_func_expression, mapnik::binary_function_call> const
binary_func_expression("binary function expression");
x3::rule<class unary_expression, mapnik::expr_node> const unary_expression("unary expression"); x3::rule<class unary_expression, mapnik::expr_node> const unary_expression("unary expression");
x3::rule<class primary_expression, mapnik::expr_node> const primary_expression("primary expression"); x3::rule<class primary_expression, mapnik::expr_node> const primary_expression("primary expression");
x3::rule<class regex_match_expression, std::string> const regex_match_expression("regex match expression"); x3::rule<class regex_match_expression, std::string> const regex_match_expression("regex match expression");
x3::rule<class regex_replace_expression, std::pair<std::string,std::string> > const regex_replace_expression("regex replace expression"); x3::rule<class regex_replace_expression, std::pair<std::string, std::string>> const
regex_replace_expression("regex replace expression");
// clang-format off
// strings // strings
auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'') auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'')
>> no_skip[*(unesc_char[append] >> no_skip[*(unesc_char[append]
@ -431,9 +404,8 @@ namespace mapnik { namespace grammar {
unquoted_ustring[do_unicode] unquoted_ustring[do_unicode]
// ^ https://github.com/mapnik/mapnik/pull/3389 // ^ https://github.com/mapnik/mapnik/pull/3389
; ;
// clang-format on
BOOST_SPIRIT_DEFINE ( BOOST_SPIRIT_DEFINE(expression,
expression,
logical_expression, logical_expression,
not_expression, not_expression,
conditional_expression, conditional_expression,
@ -446,9 +418,9 @@ namespace mapnik { namespace grammar {
unary_func_expression, unary_func_expression,
binary_func_expression, binary_func_expression,
unary_expression, unary_expression,
primary_expression primary_expression);
);
}} } // namespace grammar
} // namespace mapnik
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP

View file

@ -34,41 +34,100 @@
// stl // stl
#include <memory> #include <memory>
namespace mapnik namespace mapnik {
{
using value_type = mapnik::value; using value_type = mapnik::value;
template <typename Tag> struct make_op; template<typename Tag>
template <> struct make_op<mapnik::tags::negate> { using type = std::negate<value_type>;}; struct make_op;
template <> struct make_op<mapnik::tags::plus> { using type = std::plus<value_type>;}; template<>
template <> struct make_op<mapnik::tags::minus> { using type = std::minus<value_type>;}; struct make_op<mapnik::tags::negate>
template <> struct make_op<mapnik::tags::mult> { using type = std::multiplies<value_type>;}; {
template <> struct make_op<mapnik::tags::div> { using type = std::divides<value_type>;}; using type = std::negate<value_type>;
template <> struct make_op<mapnik::tags::mod> { using type = std::modulus<value_type>;}; };
template <> struct make_op<mapnik::tags::less> { using type = std::less<value_type>;}; template<>
template <> struct make_op<mapnik::tags::less_equal> { using type = std::less_equal<value_type>;}; struct make_op<mapnik::tags::plus>
template <> struct make_op<mapnik::tags::greater> { using type = std::greater<value_type>;}; {
template <> struct make_op<mapnik::tags::greater_equal> { using type = std::greater_equal<value_type>;}; using type = std::plus<value_type>;
template <> struct make_op<mapnik::tags::equal_to> { using type = std::equal_to<value_type>;}; };
template <> struct make_op<mapnik::tags::not_equal_to> { using type = std::not_equal_to<value_type>;}; template<>
template <> struct make_op<mapnik::tags::logical_not> { using type = std::logical_not<value_type>;}; struct make_op<mapnik::tags::minus>
template <> struct make_op<mapnik::tags::logical_and> { using type = std::logical_and<value_type>;}; {
template <> struct make_op<mapnik::tags::logical_or> { using type = std::logical_or<value_type>;}; using type = std::minus<value_type>;
};
template<>
struct make_op<mapnik::tags::mult>
{
using type = std::multiplies<value_type>;
};
template<>
struct make_op<mapnik::tags::div>
{
using type = std::divides<value_type>;
};
template<>
struct make_op<mapnik::tags::mod>
{
using type = std::modulus<value_type>;
};
template<>
struct make_op<mapnik::tags::less>
{
using type = std::less<value_type>;
};
template<>
struct make_op<mapnik::tags::less_equal>
{
using type = std::less_equal<value_type>;
};
template<>
struct make_op<mapnik::tags::greater>
{
using type = std::greater<value_type>;
};
template<>
struct make_op<mapnik::tags::greater_equal>
{
using type = std::greater_equal<value_type>;
};
template<>
struct make_op<mapnik::tags::equal_to>
{
using type = std::equal_to<value_type>;
};
template<>
struct make_op<mapnik::tags::not_equal_to>
{
using type = std::not_equal_to<value_type>;
};
template<>
struct make_op<mapnik::tags::logical_not>
{
using type = std::logical_not<value_type>;
};
template<>
struct make_op<mapnik::tags::logical_and>
{
using type = std::logical_and<value_type>;
};
template<>
struct make_op<mapnik::tags::logical_or>
{
using type = std::logical_or<value_type>;
};
template<typename Tag> template<typename Tag>
struct unary_node struct unary_node
{ {
unary_node(expr_node&& a) unary_node(expr_node&& a)
: expr(std::move(a)) {} : expr(std::move(a))
{}
unary_node(expr_node const& a) unary_node(expr_node const& a)
: expr(a) {} : expr(a)
{}
static const char* type() static const char* type() { return Tag::str(); }
{
return Tag::str();
}
expr_node expr; expr_node expr;
}; };
@ -77,17 +136,16 @@ template <typename Tag>
struct binary_node struct binary_node
{ {
binary_node(expr_node&& a, expr_node&& b) binary_node(expr_node&& a, expr_node&& b)
: left(std::move(a)), : left(std::move(a))
right(std::move(b)) {} , right(std::move(b))
{}
binary_node(expr_node const& a, expr_node const& b) binary_node(expr_node const& a, expr_node const& b)
: left(a), : left(a)
right(b) {} , right(b)
{}
static const char* type() static const char* type() { return Tag::str(); }
{
return Tag::str();
}
expr_node left, right; expr_node left, right;
}; };
@ -96,7 +154,9 @@ struct unary_function_call
using argument_type = expr_node; using argument_type = expr_node;
unary_function_call() = default; unary_function_call() = default;
unary_function_call(unary_function_impl _fun, argument_type const& _arg) unary_function_call(unary_function_impl _fun, argument_type const& _arg)
: fun(_fun), arg(_arg) {} : fun(_fun)
, arg(_arg)
{}
unary_function_impl fun; unary_function_impl fun;
argument_type arg; argument_type arg;
@ -107,7 +167,10 @@ struct binary_function_call
using argument_type = expr_node; using argument_type = expr_node;
binary_function_call() = default; binary_function_call() = default;
binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2) binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2)
: fun(_fun), arg1(_arg1), arg2(_arg2) {} : fun(_fun)
, arg1(_arg1)
, arg2(_arg2)
{}
binary_function_impl fun; binary_function_impl fun;
argument_type arg1; argument_type arg1;
argument_type arg2; argument_type arg2;
@ -137,7 +200,6 @@ struct MAPNIK_DECL regex_replace_node
std::shared_ptr<_regex_replace_impl> impl_; std::shared_ptr<_regex_replace_impl> impl_;
}; };
} } // namespace mapnik
#endif // MAPNIK_EXPRESSION_NODE_HPP #endif // MAPNIK_EXPRESSION_NODE_HPP

View file

@ -28,136 +28,90 @@
#include <mapnik/value/types.hpp> #include <mapnik/value/types.hpp>
#include <mapnik/util/variant.hpp> #include <mapnik/util/variant.hpp>
namespace mapnik namespace mapnik {
{
namespace tags { namespace tags {
struct negate struct negate
{ {
static const char* str() static const char* str() { return "-"; }
{
return "-";
}
}; };
struct plus struct plus
{ {
static const char* str() static const char* str() { return "+"; }
{
return "+";
}
}; };
struct minus struct minus
{ {
static const char* str() static const char* str() { return "-"; }
{
return "-";
}
}; };
struct mult struct mult
{ {
static const char* str() static const char* str() { return "*"; }
{
return "*";
}
}; };
struct div struct div
{ {
static const char* str() static const char* str() { return "/"; }
{
return "/";
}
}; };
struct mod struct mod
{ {
static const char* str() static const char* str() { return "%"; }
{
return "%";
}
}; };
struct less struct less
{ {
static const char* str() static const char* str() { return "<"; }
{
return "<";
}
}; };
struct less_equal struct less_equal
{ {
static const char* str() static const char* str() { return "<="; }
{
return "<=";
}
}; };
struct greater struct greater
{ {
static const char* str() static const char* str() { return ">"; }
{
return ">";
}
}; };
struct greater_equal struct greater_equal
{ {
static const char* str() static const char* str() { return ">="; }
{
return ">=";
}
}; };
struct equal_to struct equal_to
{ {
static const char* str() static const char* str() { return "="; }
{
return "=";
}
}; };
struct not_equal_to struct not_equal_to
{ {
static const char* str() static const char* str() { return "!="; }
{
return "!=";
}
}; };
struct logical_not struct logical_not
{ {
static const char* str() static const char* str() { return "not "; }
{
return "not ";
}
}; };
struct logical_and struct logical_and
{ {
static const char* str() static const char* str() { return " and "; }
{
return " and ";
}
}; };
struct logical_or struct logical_or
{ {
static const char* str() static const char* str() { return " or "; }
{
return " or ";
}
}; };
} // end operation tags } // namespace tags
template<typename Tag>
template <typename Tag> struct binary_node; struct binary_node;
template <typename Tag> struct unary_node; template<typename Tag>
struct unary_node;
struct regex_match_node; struct regex_match_node;
struct regex_replace_node; struct regex_replace_node;
struct attribute; struct attribute;
@ -166,8 +120,7 @@ struct geometry_type_attribute;
struct unary_function_call; struct unary_function_call;
struct binary_function_call; struct binary_function_call;
using expr_node = util::variant< using expr_node = util::variant<value_null,
value_null,
value_bool, value_bool,
value_integer, value_integer,
value_double, value_double,
@ -193,10 +146,8 @@ util::recursive_wrapper<binary_node<mapnik::tags::logical_or> >,
util::recursive_wrapper<regex_match_node>, util::recursive_wrapper<regex_match_node>,
util::recursive_wrapper<regex_replace_node>, util::recursive_wrapper<regex_replace_node>,
util::recursive_wrapper<unary_function_call>, util::recursive_wrapper<unary_function_call>,
util::recursive_wrapper<binary_function_call> util::recursive_wrapper<binary_function_call>>;
>;
}
} // namespace mapnik
#endif // MAPNIK_EXPRESSION_NODE_HPP #endif // MAPNIK_EXPRESSION_NODE_HPP

View file

@ -35,8 +35,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
namespace mapnik namespace mapnik {
{
MAPNIK_DECL std::string to_expression_string(expr_node const& node); MAPNIK_DECL std::string to_expression_string(expr_node const& node);
/* /*
@ -63,6 +62,6 @@ std::string to_expression_string(std::shared_ptr<T> const& expr_node_ptr)
// compile error intended here; comment on the next line shows in clang output // compile error intended here; comment on the next line shows in clang output
return expr_node_ptr; // to_expression_string() called with pointer argument return expr_node_ptr; // to_expression_string() called with pointer argument
} }
} } // namespace mapnik
#endif // MAPNIK_EXPRESSION_STRING_HPP #endif // MAPNIK_EXPRESSION_STRING_HPP

View file

@ -38,11 +38,9 @@ MAPNIK_DISABLE_WARNING_POP
// stl // stl
#include <cmath> #include <cmath>
namespace mapnik namespace mapnik {
{
namespace detail namespace detail {
{
namespace msm = boost::msm; namespace msm = boost::msm;
namespace mpl = boost::mpl; namespace mpl = boost::mpl;
@ -55,26 +53,37 @@ T extend(T const & v1, T const & v2, double length)
double dy = v2.y - v1.y; double dy = v2.y - v1.y;
double l12 = std::sqrt(dx * dx + dy * dy); double l12 = std::sqrt(dx * dx + dy * dy);
double coef = 1.0 + length / l12; double coef = 1.0 + length / l12;
return vertex2d(v1.x + dx * coef, return vertex2d(v1.x + dx * coef, v1.y + dy * coef, v2.cmd);
v1.y + dy * coef, v2.cmd);
} }
namespace events namespace events {
{
struct vertex_event struct vertex_event
{ {
vertex_event(vertex2d const & vertex) : vertex(vertex) { } vertex_event(vertex2d const& vertex)
: vertex(vertex)
{}
vertex2d const& vertex; vertex2d const& vertex;
}; };
struct move_to : vertex_event { using vertex_event::vertex_event; }; struct move_to : vertex_event
struct line_to : vertex_event { using vertex_event::vertex_event; };
struct close : vertex_event { using vertex_event::vertex_event; };
struct end : vertex_event { using vertex_event::vertex_event; };
}
namespace actions
{ {
using vertex_event::vertex_event;
};
struct line_to : vertex_event
{
using vertex_event::vertex_event;
};
struct close : vertex_event
{
using vertex_event::vertex_event;
};
struct end : vertex_event
{
using vertex_event::vertex_event;
};
} // namespace events
namespace actions {
struct store struct store
{ {
template<class FSM, class EVT, class SourceState, class TargetState> template<class FSM, class EVT, class SourceState, class TargetState>
@ -126,20 +135,25 @@ namespace actions
m.v1 = e.vertex; m.v1 = e.vertex;
} }
}; };
} } // namespace actions
struct extender_def : public msm::front::state_machine_def<extender_def> struct extender_def : public msm::front::state_machine_def<extender_def>
{ {
using no_exception_thrown = int; using no_exception_thrown = int;
using no_message_queue = int; using no_message_queue = int;
struct initial : public msm::front::state<> { }; struct initial : public msm::front::state<>
struct vertex_one : public msm::front::state<> { }; {};
struct vertex_two : public msm::front::state<> { }; struct vertex_one : public msm::front::state<>
struct end : public msm::front::state<> { }; {};
struct vertex_two : public msm::front::state<>
{};
struct end : public msm::front::state<>
{};
using initial_state = initial; using initial_state = initial;
// clang-format off
struct transition_table : mpl::vector< struct transition_table : mpl::vector<
// Start Event Next Action Guard // Start Event Next Action Guard
// +------------+-----------------+------------+--------------------+------+ // +------------+-----------------+------------+--------------------+------+
@ -157,11 +171,11 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
Row < vertex_two , events::end , end , actions::output_end >, Row < vertex_two , events::end , end , actions::output_end >,
Row < end , events::end , end , actions::output > Row < end , events::end , end , actions::output >
> {}; > {};
// clang-format on
extender_def(double extend_length) extender_def(double extend_length)
: extend_length(extend_length) : extend_length(extend_length)
{ {}
}
boost::optional<vertex2d> output; boost::optional<vertex2d> output;
vertex2d v1, v2; vertex2d v1, v2;
@ -170,7 +184,7 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
using extender = msm::back::state_machine<extender_def>; using extender = msm::back::state_machine<extender_def>;
} } // namespace detail
template<typename Geometry> template<typename Geometry>
struct extend_converter struct extend_converter
@ -180,13 +194,11 @@ struct extend_converter
{} {}
extend_converter(Geometry& geom, double extend) extend_converter(Geometry& geom, double extend)
: geom_(geom), extender_(extend) : geom_(geom)
, extender_(extend)
{} {}
void set_extend(double extend) void set_extend(double extend) { extender_.extend_length = extend; }
{
extender_.extend_length = extend;
}
unsigned vertex(double* x, double* y) unsigned vertex(double* x, double* y)
{ {
@ -229,6 +241,6 @@ private:
detail::extender extender_; detail::extender extender_;
}; };
} } // namespace mapnik
#endif // MAPNIK_EXTEND_CONVERTER_HPP #endif // MAPNIK_EXTEND_CONVERTER_HPP

View file

@ -32,19 +32,14 @@
namespace mapnik { namespace mapnik {
template template<typename product_type, typename key_type, typename... Args>
< class factory : public singleton<factory<product_type, key_type, Args...>>
typename product_type,
typename key_type,
typename ...Args >
class factory : public singleton<factory <product_type,
key_type,
Args...> >
{ {
private: private:
using product_creator = product_type* (*)(Args...); using product_creator = product_type* (*)(Args...);
using product_map = std::map<key_type, product_creator>; using product_map = std::map<key_type, product_creator>;
product_map map_; product_map map_;
public: public:
bool register_product(key_type const& key, product_creator creator) bool register_product(key_type const& key, product_creator creator)
@ -52,10 +47,7 @@ public:
return map_.insert(typename product_map::value_type(key, creator)).second; return map_.insert(typename product_map::value_type(key, creator)).second;
} }
bool unregister_product(const key_type& key) bool unregister_product(const key_type& key) { return map_.erase(key) == 1; }
{
return map_.erase(key)==1;
}
product_type* create_object(key_type const& key, Args... args) product_type* create_object(key_type const& key, Args... args)
{ {
@ -67,6 +59,6 @@ public:
return 0; return 0;
} }
}; };
} } // namespace mapnik
#endif // MAPNIK_FACTORY_HPP #endif // MAPNIK_FACTORY_HPP

View file

@ -55,6 +55,7 @@ class context : private util::noncopyable
{ {
friend class feature_impl; friend class feature_impl;
public: public:
using map_type = T; using map_type = T;
using value_type = typename map_type::value_type; using value_type = typename map_type::value_type;
@ -65,7 +66,8 @@ public:
using const_iterator = typename map_type::const_iterator; using const_iterator = typename map_type::const_iterator;
context() context()
: mapping_() {} : mapping_()
{}
inline size_type push(key_type const& name) inline size_type push(key_type const& name)
{ {
@ -74,10 +76,7 @@ public:
return index; return index;
} }
inline void add(key_type const& name, size_type index) inline void add(key_type const& name, size_type index) { mapping_.emplace(name, index); }
{
mapping_.emplace(name, index);
}
inline size_type size() const { return mapping_.size(); } inline size_type size() const { return mapping_.size(); }
inline const_iterator begin() const { return mapping_.begin(); } inline const_iterator begin() const { return mapping_.begin(); }
@ -95,6 +94,7 @@ static const value default_feature_value{};
class MAPNIK_DECL feature_impl : private util::noncopyable class MAPNIK_DECL feature_impl : private util::noncopyable
{ {
friend class feature_kv_iterator; friend class feature_kv_iterator;
public: public:
using value_type = mapnik::value; using value_type = mapnik::value;
@ -102,11 +102,12 @@ public:
using iterator = feature_kv_iterator; using iterator = feature_kv_iterator;
feature_impl(context_ptr const& ctx, mapnik::value_integer _id) feature_impl(context_ptr const& ctx, mapnik::value_integer _id)
: id_(_id), : id_(_id)
ctx_(ctx), , ctx_(ctx)
data_(ctx_->mapping_.size()), , data_(ctx_->mapping_.size())
geom_(geometry::geometry_empty()), , geom_(geometry::geometry_empty())
raster_() {} , raster_()
{}
inline mapnik::value_integer id() const { return id_; } inline mapnik::value_integer id() const { return id_; }
inline void set_id(mapnik::value_integer _id) { id_ = _id; } inline void set_id(mapnik::value_integer _id) { id_ = _id; }
@ -125,8 +126,7 @@ public:
inline void put(context_type::key_type const& key, value&& val) inline void put(context_type::key_type const& key, value&& val)
{ {
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key); context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
if (itr != ctx_->mapping_.end() if (itr != ctx_->mapping_.end() && itr->second < data_.size())
&& itr->second < data_.size())
{ {
data_[itr->second] = std::move(val); data_[itr->second] = std::move(val);
} }
@ -139,8 +139,7 @@ public:
inline void put_new(context_type::key_type const& key, value&& val) inline void put_new(context_type::key_type const& key, value&& val)
{ {
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key); context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
if (itr != ctx_->mapping_.end() if (itr != ctx_->mapping_.end() && itr->second < data_.size())
&& itr->second < data_.size())
{ {
data_[itr->second] = std::move(val); data_[itr->second] = std::move(val);
} }
@ -152,10 +151,7 @@ public:
} }
} }
inline bool has_key(context_type::key_type const& key) const inline bool has_key(context_type::key_type const& key) const { return (ctx_->mapping_.count(key) == 1); }
{
return (ctx_->mapping_.count(key) == 1);
}
inline value_type const& get(context_type::key_type const& key) const inline value_type const& get(context_type::key_type const& key) const
{ {
@ -173,70 +169,31 @@ public:
return default_feature_value; return default_feature_value;
} }
inline std::size_t size() const inline std::size_t size() const { return data_.size(); }
{
return data_.size();
}
inline cont_type const& get_data() const inline cont_type const& get_data() const { return data_; }
{
return data_;
}
inline void set_data(cont_type const& data) inline void set_data(cont_type const& data) { data_ = data; }
{
data_ = data;
}
inline context_ptr context() const inline context_ptr context() const { return ctx_; }
{
return ctx_;
}
inline void set_geometry(geometry::geometry<double> && geom) inline void set_geometry(geometry::geometry<double>&& geom) { geom_ = std::move(geom); }
{
geom_ = std::move(geom);
}
inline void set_geometry_copy(geometry::geometry<double> const& geom) inline void set_geometry_copy(geometry::geometry<double> const& geom) { geom_ = geom; }
{
geom_ = geom;
}
inline geometry::geometry<double> const& get_geometry() const inline geometry::geometry<double> const& get_geometry() const { return geom_; }
{
return geom_;
}
inline geometry::geometry<double> & get_geometry() inline geometry::geometry<double>& get_geometry() { return geom_; }
{
return geom_;
}
inline box2d<double> envelope() const inline box2d<double> envelope() const { return mapnik::geometry::envelope(geom_); }
{
return mapnik::geometry::envelope(geom_);
}
inline raster_ptr const& get_raster() const inline raster_ptr const& get_raster() const { return raster_; }
{
return raster_;
}
inline void set_raster(raster_ptr const& raster) inline void set_raster(raster_ptr const& raster) { raster_ = raster; }
{
raster_ = raster;
}
inline feature_kv_iterator begin() const inline feature_kv_iterator begin() const { return feature_kv_iterator(*this, true); }
{
return feature_kv_iterator(*this,true);
}
inline feature_kv_iterator end() const inline feature_kv_iterator end() const { return feature_kv_iterator(*this); }
{
return feature_kv_iterator(*this);
}
std::string to_string() const std::string to_string() const
{ {
@ -269,7 +226,6 @@ private:
raster_ptr raster_; raster_ptr raster_;
}; };
inline std::ostream& operator<<(std::ostream& out, feature_impl const& f) inline std::ostream& operator<<(std::ostream& out, feature_impl const& f)
{ {
out << f.to_string(); out << f.to_string();
@ -278,6 +234,6 @@ inline std::ostream& operator<< (std::ostream & out,feature_impl const& f)
using feature_ptr = std::shared_ptr<feature_impl>; using feature_ptr = std::shared_ptr<feature_impl>;
} } // namespace mapnik
#endif // MAPNIK_FEATURE_HPP #endif // MAPNIK_FEATURE_HPP

View file

@ -30,8 +30,7 @@
// boost // boost
//#include <boost/pool/pool_alloc.hpp> //#include <boost/pool/pool_alloc.hpp>
namespace mapnik namespace mapnik {
{
struct feature_factory struct feature_factory
{ {
static std::shared_ptr<feature_impl> create(context_ptr const& ctx, mapnik::value_integer fid) static std::shared_ptr<feature_impl> create(context_ptr const& ctx, mapnik::value_integer fid)
@ -41,6 +40,6 @@ struct feature_factory
return std::make_shared<feature_impl>(ctx, fid); return std::make_shared<feature_impl>(ctx, fid);
} }
}; };
} } // namespace mapnik
#endif // MAPNIK_FEATURE_FACTORY_HPP #endif // MAPNIK_FEATURE_FACTORY_HPP

View file

@ -45,14 +45,14 @@ namespace mapnik {
class feature_impl; class feature_impl;
class MAPNIK_DECL feature_kv_iterator : class MAPNIK_DECL feature_kv_iterator : public boost::iterator_facade<feature_kv_iterator,
public boost::iterator_facade<feature_kv_iterator,
std::tuple<std::string, value> const, std::tuple<std::string, value> const,
boost::forward_traversal_tag> boost::forward_traversal_tag>
{ {
public: public:
using value_type = std::tuple<std::string, value>; using value_type = std::tuple<std::string, value>;
feature_kv_iterator(feature_impl const& f, bool begin = false); feature_kv_iterator(feature_impl const& f, bool begin = false);
private: private:
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
void increment(); void increment();
@ -65,7 +65,6 @@ private:
feature_impl const& f_; feature_impl const& f_;
std::map<std::string, std::size_t>::const_iterator itr_; std::map<std::string, std::size_t>::const_iterator itr_;
mutable value_type kv_; mutable value_type kv_;
}; };
struct value_not_null struct value_not_null
@ -78,6 +77,6 @@ struct value_not_null
using feature_kv_iterator2 = boost::filter_iterator<value_not_null, feature_kv_iterator>; using feature_kv_iterator2 = boost::filter_iterator<value_not_null, feature_kv_iterator>;
} } // namespace mapnik
#endif // MAPNIK_FEATURE_KV_ITERATOR_HPP #endif // MAPNIK_FEATURE_KV_ITERATOR_HPP

View file

@ -32,83 +32,58 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
namespace mapnik namespace mapnik {
{
class layer_descriptor class layer_descriptor
{ {
public: public:
layer_descriptor(std::string const& name, std::string const& encoding) layer_descriptor(std::string const& name, std::string const& encoding)
: name_(name), : name_(name)
encoding_(encoding), , encoding_(encoding)
descriptors_(), , descriptors_()
extra_params_() {} , extra_params_()
{}
layer_descriptor(layer_descriptor const& other) layer_descriptor(layer_descriptor const& other)
: name_(other.name_), : name_(other.name_)
encoding_(other.encoding_), , encoding_(other.encoding_)
descriptors_(other.descriptors_), , descriptors_(other.descriptors_)
extra_params_(other.extra_params_) {} , extra_params_(other.extra_params_)
{}
void set_name(std::string const& name) void set_name(std::string const& name) { name_ = name; }
{
name_ = name;
}
std::string const& get_name() const std::string const& get_name() const { return name_; }
{
return name_;
}
void set_encoding(std::string const& encoding) void set_encoding(std::string const& encoding) { encoding_ = encoding; }
{
encoding_ = encoding;
}
std::string const& get_encoding() const std::string const& get_encoding() const { return encoding_; }
{
return encoding_;
}
void add_descriptor(attribute_descriptor const& desc) void add_descriptor(attribute_descriptor const& desc) { descriptors_.push_back(desc); }
{
descriptors_.push_back(desc);
}
std::vector<attribute_descriptor> const& get_descriptors() const std::vector<attribute_descriptor> const& get_descriptors() const { return descriptors_; }
{
return descriptors_;
}
std::vector<attribute_descriptor>& get_descriptors() std::vector<attribute_descriptor>& get_descriptors() { return descriptors_; }
{
return descriptors_;
}
parameters const& get_extra_parameters() const parameters const& get_extra_parameters() const { return extra_params_; }
{
return extra_params_;
}
parameters& get_extra_parameters() parameters& get_extra_parameters() { return extra_params_; }
{
return extra_params_;
}
bool has_name(std::string const& name) const bool has_name(std::string const& name) const
{ {
auto result = std::find_if(std::begin(descriptors_), std::end(descriptors_), auto result = std::find_if(std::begin(descriptors_),
std::end(descriptors_),
[&name](attribute_descriptor const& desc) { return name == desc.get_name(); }); [&name](attribute_descriptor const& desc) { return name == desc.get_name(); });
return result != std::end(descriptors_); return result != std::end(descriptors_);
} }
void order_by_name() void order_by_name()
{ {
std::sort(std::begin(descriptors_), std::end(descriptors_), std::sort(
[](attribute_descriptor const& d0, attribute_descriptor const& d1) std::begin(descriptors_),
{ std::end(descriptors_),
return d0.get_name() < d1.get_name(); [](attribute_descriptor const& d0, attribute_descriptor const& d1) { return d0.get_name() < d1.get_name(); });
});
} }
private: private:
std::string name_; std::string name_;
std::string encoding_; std::string encoding_;
@ -116,6 +91,6 @@ private:
parameters extra_params_; parameters extra_params_;
}; };
} } // namespace mapnik
#endif // MAPNIK_FEATURE_LAYER_DESC_HPP #endif // MAPNIK_FEATURE_LAYER_DESC_HPP

View file

@ -34,8 +34,7 @@
#include <set> #include <set>
#include <string> #include <string>
namespace mapnik namespace mapnik {
{
class Map; class Map;
class layer; class layer;
@ -45,18 +44,13 @@ class feature_type_style;
class rule_cache; class rule_cache;
struct layer_rendering_material; struct layer_rendering_material;
enum eAttributeCollectionPolicy enum eAttributeCollectionPolicy { DEFAULT = 0, COLLECT_ALL = 1 };
{
DEFAULT = 0,
COLLECT_ALL = 1
};
template<typename Processor> template<typename Processor>
class feature_style_processor class feature_style_processor
{ {
public: public:
explicit feature_style_processor(Map const& m, explicit feature_style_processor(Map const& m, double scale_factor = 1.0);
double scale_factor = 1.0);
/*! /*!
* \brief apply renderer to all map layers. * \brief apply renderer to all map layers.
@ -66,9 +60,7 @@ public:
/*! /*!
* \brief apply renderer to a single layer, providing pre-populated set of query attribute names. * \brief apply renderer to a single layer, providing pre-populated set of query attribute names.
*/ */
void apply(mapnik::layer const& lyr, void apply(mapnik::layer const& lyr, std::set<std::string>& names, double scale_denom_override = 0.0);
std::set<std::string>& names,
double scale_denom_override=0.0);
/*! /*!
* \brief render a layer given a projection and scale. * \brief render a layer given a projection and scale.
@ -122,6 +114,6 @@ private:
Map const& m_; Map const& m_;
}; };
} } // namespace mapnik
#endif // MAPNIK_FEATURE_STYLE_PROCESSOR_HPP #endif // MAPNIK_FEATURE_STYLE_PROCESSOR_HPP

View file

@ -30,8 +30,8 @@
namespace mapnik { namespace mapnik {
class IProcessorContext
class IProcessorContext { {
public: public:
virtual ~IProcessorContext() {} virtual ~IProcessorContext() {}
}; };
@ -39,6 +39,6 @@ public:
using processor_context_ptr = std::shared_ptr<IProcessorContext>; using processor_context_ptr = std::shared_ptr<IProcessorContext>;
using feature_style_context_map = std::map<std::string, processor_context_ptr>; using feature_style_context_map = std::map<std::string, processor_context_ptr>;
} } // namespace mapnik
#endif // FEATURE_STYLE_PROCESSOR_CONTEXT_HPP #endif // FEATURE_STYLE_PROCESSOR_CONTEXT_HPP

View file

@ -50,8 +50,7 @@
#include <vector> #include <vector>
#include <stdexcept> #include <stdexcept>
namespace mapnik namespace mapnik {
{
// Store material for layer rendering in a two step process // Store material for layer rendering in a two step process
struct layer_rendering_material struct layer_rendering_material
@ -66,9 +65,10 @@ struct layer_rendering_material
std::vector<layer_rendering_material> materials_; std::vector<layer_rendering_material> materials_;
layer_rendering_material(layer const& lay, projection const& dest) layer_rendering_material(layer const& lay, projection const& dest)
: lay_(lay), : lay_(lay)
proj0_(dest), , proj0_(dest)
proj1_(lay.srs(), true) {} , proj1_(lay.srs(), true)
{}
layer_rendering_material(layer_rendering_material&& rhs) = default; layer_rendering_material(layer_rendering_material&& rhs) = default;
}; };
@ -197,16 +197,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay,
feature_style_context_map ctx_map; feature_style_context_map ctx_map;
layer_rendering_material mat(lay, proj0); layer_rendering_material mat(lay, proj0);
prepare_layer(mat, prepare_layer(mat, ctx_map, p, scale, scale_denom, width, height, extent, buffer_size, names);
ctx_map,
p,
scale,
scale_denom,
width,
height,
extent,
buffer_size,
names);
prepare_layers(mat, lay.layers(), ctx_map, p, scale_denom); prepare_layers(mat, lay.layers(), ctx_map, p, scale_denom);
@ -240,16 +231,14 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
std::size_t num_styles = style_names.size(); std::size_t num_styles = style_names.size();
if (num_styles == 0) if (num_styles == 0)
{ {
MAPNIK_LOG_DEBUG(feature_style_processor) MAPNIK_LOG_DEBUG(feature_style_processor) << "feature_style_processor: No style for layer=" << lay.name();
<< "feature_style_processor: No style for layer=" << lay.name();
return; return;
} }
mapnik::datasource_ptr ds = lay.datasource(); mapnik::datasource_ptr ds = lay.datasource();
if (!ds) if (!ds)
{ {
MAPNIK_LOG_DEBUG(feature_style_processor) MAPNIK_LOG_DEBUG(feature_style_processor) << "feature_style_processor: No datasource for layer=" << lay.name();
<< "feature_style_processor: No datasource for layer=" << lay.name();
return; return;
} }
@ -295,15 +284,15 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
early_return = true; early_return = true;
} }
// next try intersection of layer extent back projected into map srs // next try intersection of layer extent back projected into map srs
else if (proj_trans_ptr->backward(layer_ext, PROJ_ENVELOPE_POINTS) && buffered_query_ext_map_srs.intersects(layer_ext)) else if (proj_trans_ptr->backward(layer_ext, PROJ_ENVELOPE_POINTS) &&
buffered_query_ext_map_srs.intersects(layer_ext))
{ {
layer_ext.clip(buffered_query_ext_map_srs); layer_ext.clip(buffered_query_ext_map_srs);
// forward project layer extent back into native projection // forward project layer extent back into native projection
if (!proj_trans_ptr->forward(layer_ext, PROJ_ENVELOPE_POINTS)) if (!proj_trans_ptr->forward(layer_ext, PROJ_ENVELOPE_POINTS))
{ {
MAPNIK_LOG_ERROR(feature_style_processor) MAPNIK_LOG_ERROR(feature_style_processor)
<< "feature_style_processor: Layer=" << lay.name() << "feature_style_processor: Layer=" << lay.name() << " extent=" << layer_ext << " in map projection "
<< " extent=" << layer_ext << " in map projection "
<< " did not reproject properly back to layer projection"; << " did not reproject properly back to layer projection";
} }
} }
@ -374,8 +363,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
boost::optional<feature_type_style const&> style = m_.find_style(style_name); boost::optional<feature_type_style const&> style = m_.find_style(style_name);
if (!style) if (!style)
{ {
MAPNIK_LOG_ERROR(feature_style_processor) MAPNIK_LOG_ERROR(feature_style_processor) << "feature_style_processor: Style=" << style_name
<< "feature_style_processor: Style=" << style_name
<< " required for layer=" << lay.name() << " does not exist."; << " required for layer=" << lay.name() << " does not exist.";
continue; continue;
@ -408,8 +396,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
double qw = query_ext.width() > 0 ? query_ext.width() : 1; double qw = query_ext.width() > 0 ? query_ext.width() : 1;
double qh = query_ext.height() > 0 ? query_ext.height() : 1; double qh = query_ext.height() > 0 ? query_ext.height() : 1;
query::resolution_type res(width/qw, query::resolution_type res(width / qw, height / qh);
height/qh);
query q(layer_ext, res, scale_denom, extent); query q(layer_ext, res, scale_denom, extent);
q.set_variables(p.variables()); q.set_variables(p.variables());
@ -455,8 +442,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
} }
template<typename Processor> template<typename Processor>
void feature_style_processor<Processor>::render_submaterials(layer_rendering_material const & parent_mat, void feature_style_processor<Processor>::render_submaterials(layer_rendering_material const& parent_mat, Processor& p)
Processor & p)
{ {
for (layer_rendering_material const& mat : parent_mat.materials_) for (layer_rendering_material const& mat : parent_mat.materials_)
{ {
@ -473,8 +459,7 @@ void feature_style_processor<Processor>::render_submaterials(layer_rendering_mat
} }
template<typename Processor> template<typename Processor>
void feature_style_processor<Processor>::render_material(layer_rendering_material const & mat, void feature_style_processor<Processor>::render_material(layer_rendering_material const& mat, Processor& p)
Processor & p)
{ {
std::vector<feature_type_style const*> const& active_styles = mat.active_styles_; std::vector<feature_type_style const*> const& active_styles = mat.active_styles_;
std::vector<featureset_ptr> const& featureset_ptr_list = mat.featureset_ptr_list_; std::vector<featureset_ptr> const& featureset_ptr_list = mat.featureset_ptr_list_;
@ -518,12 +503,8 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
std::size_t i = 0; std::size_t i = 0;
for (feature_type_style const* style : active_styles) for (feature_type_style const* style : active_styles)
{ {
cache->prepare(); cache->prepare();
render_style(p, style, render_style(p, style, rule_caches[i++], cache, *proj_trans_ptr);
rule_caches[i++],
cache,
*proj_trans_ptr);
} }
cache->clear(); cache->clear();
} }
@ -550,7 +531,6 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
feature_ptr feature; feature_ptr feature;
while ((feature = features->next())) while ((feature = features->next()))
{ {
cache->push(feature); cache->push(feature);
} }
} }
@ -558,9 +538,7 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
for (feature_type_style const* style : active_styles) for (feature_type_style const* style : active_styles)
{ {
cache->prepare(); cache->prepare();
render_style(p, style, render_style(p, style, rule_caches[i++], cache, *proj_trans_ptr);
rule_caches[i++],
cache, *proj_trans_ptr);
} }
} }
// We only have a single style and no grouping. // We only have a single style and no grouping.
@ -571,17 +549,13 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
for (feature_type_style const* style : active_styles) for (feature_type_style const* style : active_styles)
{ {
featureset_ptr features = *featuresets++; featureset_ptr features = *featuresets++;
render_style(p, style, render_style(p, style, rule_caches[i++], features, *proj_trans_ptr);
rule_caches[i++],
features,
*proj_trans_ptr);
} }
} }
} }
template<typename Processor> template<typename Processor>
void feature_style_processor<Processor>::render_style( void feature_style_processor<Processor>::render_style(Processor& p,
Processor & p,
feature_type_style const* style, feature_type_style const* style,
rule_cache const& rc, rule_cache const& rc,
featureset_ptr features, featureset_ptr features,
@ -603,7 +577,8 @@ void feature_style_processor<Processor>::render_style(
for (rule const* r : rc.get_if_rules()) for (rule const* r : rc.get_if_rules())
{ {
expression_ptr const& expr = r->get_filter(); expression_ptr const& expr = r->get_filter();
value_type result = util::apply_visitor(evaluate<feature_impl,value_type,attributes>(*feature,vars),*expr); value_type result =
util::apply_visitor(evaluate<feature_impl, value_type, attributes>(*feature, vars), *expr);
if (result.to_bool()) if (result.to_bool())
{ {
was_painted = true; was_painted = true;
@ -660,4 +635,4 @@ void feature_style_processor<Processor>::render_style(
p.end_style_processing(*style); p.end_style_processing(*style);
} }
} } // namespace mapnik

View file

@ -39,16 +39,11 @@ MAPNIK_DISABLE_WARNING_POP
#include <vector> #include <vector>
#include <cstddef> #include <cstddef>
namespace mapnik namespace mapnik {
{
class rule; class rule;
enum filter_mode_enum { enum filter_mode_enum { FILTER_ALL, FILTER_FIRST, filter_mode_enum_MAX };
FILTER_ALL,
FILTER_FIRST,
filter_mode_enum_MAX
};
DEFINE_ENUM(filter_mode_e, filter_mode_enum); DEFINE_ENUM(filter_mode_e, filter_mode_enum);
@ -67,6 +62,7 @@ private:
float opacity_; float opacity_;
bool image_filters_inflate_; bool image_filters_inflate_;
friend void swap(feature_type_style& lhs, feature_type_style& rhs); friend void swap(feature_type_style& lhs, feature_type_style& rhs);
public: public:
// ctor // ctor
feature_type_style(); feature_type_style();
@ -98,14 +94,10 @@ public:
float get_opacity() const; float get_opacity() const;
void set_image_filters_inflate(bool inflate); void set_image_filters_inflate(bool inflate);
bool image_filters_inflate() const; bool image_filters_inflate() const;
inline void reserve(std::size_t size) inline void reserve(std::size_t size) { rules_.reserve(size); }
{
rules_.reserve(size);
}
~feature_type_style() {} ~feature_type_style() {}
}; };
} } // namespace mapnik
#endif // MAPNIK_FEATURE_TYPE_STYLE_HPP #endif // MAPNIK_FEATURE_TYPE_STYLE_HPP

View file

@ -43,10 +43,7 @@ struct MAPNIK_DECL Featureset : private util::noncopyable
struct MAPNIK_DECL invalid_featureset final : Featureset struct MAPNIK_DECL invalid_featureset final : Featureset
{ {
feature_ptr next() feature_ptr next() { return feature_ptr(); }
{
return feature_ptr();
}
~invalid_featureset() {} ~invalid_featureset() {}
}; };
@ -62,6 +59,6 @@ inline bool is_valid(featureset_ptr const& ptr)
return (dynamic_cast<invalid_featureset*>(ptr.get()) == nullptr) ? true : false; return (dynamic_cast<invalid_featureset*>(ptr.get()) == nullptr) ? true : false;
} }
} } // namespace mapnik
#endif // MAPNIK_FEATURESET_HPP #endif // MAPNIK_FEATURESET_HPP

View file

@ -36,7 +36,9 @@ class filter_featureset : public Featureset
public: public:
filter_featureset(featureset_ptr const& fs, filter_type&& filter) filter_featureset(featureset_ptr const& fs, filter_type&& filter)
: fs_(fs), filter_(std::move(filter)) {} : fs_(fs)
, filter_(std::move(filter))
{}
feature_ptr next() feature_ptr next()
{ {
@ -52,6 +54,6 @@ private:
featureset_ptr fs_; featureset_ptr fs_;
filter_type filter_; filter_type filter_;
}; };
} } // namespace mapnik
#endif // MAPNIK_FILTER_FEATURESET_HPP #endif // MAPNIK_FILTER_FEATURESET_HPP

View file

@ -36,10 +36,12 @@
#include <utility> // pair #include <utility> // pair
#include <vector> #include <vector>
namespace boost { template <class T> class optional; } namespace boost {
template<class T>
class optional;
}
namespace mapnik namespace mapnik {
{
class stroker; class stroker;
using stroker_ptr = std::shared_ptr<stroker>; using stroker_ptr = std::shared_ptr<stroker>;
@ -53,6 +55,7 @@ class MAPNIK_DECL freetype_engine : public singleton<freetype_engine, CreateUsin
{ {
friend class CreateUsingNew<freetype_engine>; friend class CreateUsingNew<freetype_engine>;
friend class Map; friend class Map;
public: public:
using font_file_mapping_type = std::map<std::string, std::pair<int, std::string>>; using font_file_mapping_type = std::map<std::string, std::pair<int, std::string>>;
using font_memory_cache_type = std::map<std::string, std::pair<std::unique_ptr<char[]>, std::size_t>>; using font_memory_cache_type = std::map<std::string, std::pair<std::unique_ptr<char[]>, std::size_t>>;
@ -74,6 +77,7 @@ public:
freetype_engine::font_memory_cache_type const& font_cache, freetype_engine::font_memory_cache_type const& font_cache,
font_file_mapping_type const& global_font_file_mapping, font_file_mapping_type const& global_font_file_mapping,
freetype_engine::font_memory_cache_type& global_memory_fonts); freetype_engine::font_memory_cache_type& global_memory_fonts);
private: private:
bool is_font_file_impl(std::string const& file_name); bool is_font_file_impl(std::string const& file_name);
std::vector<std::string> face_names_impl(); std::vector<std::string> face_names_impl();
@ -94,9 +98,8 @@ private:
bool register_fonts_impl(std::string const& dir, bool recurse); bool register_fonts_impl(std::string const& dir, bool recurse);
bool register_font_impl(std::string const& file_name, FT_LibraryRec_* library); bool register_font_impl(std::string const& file_name, FT_LibraryRec_* library);
bool register_fonts_impl(std::string const& dir, FT_LibraryRec_* library, bool recurse = false); bool register_fonts_impl(std::string const& dir, FT_LibraryRec_* library, bool recurse = false);
bool register_font_impl(std::string const& file_name, bool
font_library & libary, register_font_impl(std::string const& file_name, font_library& libary, font_file_mapping_type& font_file_mapping);
font_file_mapping_type & font_file_mapping);
bool register_fonts_impl(std::string const& dir, bool register_fonts_impl(std::string const& dir,
font_library& libary, font_library& libary,
font_file_mapping_type& font_file_mapping, font_file_mapping_type& font_file_mapping,
@ -130,6 +133,6 @@ private:
using face_manager_freetype = face_manager; using face_manager_freetype = face_manager;
extern template class MAPNIK_DECL singleton<freetype_engine, CreateUsingNew>; extern template class MAPNIK_DECL singleton<freetype_engine, CreateUsingNew>;
} } // namespace mapnik
#endif // MAPNIK_FONT_ENGINE_FREETYPE_HPP #endif // MAPNIK_FONT_ENGINE_FREETYPE_HPP

View file

@ -30,8 +30,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace mapnik namespace mapnik {
{
class MAPNIK_DECL font_set class MAPNIK_DECL font_set
{ {
public: public:
@ -54,6 +53,6 @@ private:
std::string name_; std::string name_;
std::vector<std::string> face_names_; std::vector<std::string> face_names_;
}; };
} } // namespace mapnik
#endif // MAPNIK_FONT_SET_HPP #endif // MAPNIK_FONT_SET_HPP

View file

@ -43,74 +43,50 @@ char const* binary_function_name(binary_function_impl const& fun);
struct exp_impl struct exp_impl
{ {
// using type = T; // using type = T;
value_type operator() (value_type const& val) const value_type operator()(value_type const& val) const { return std::exp(val.to_double()); }
{
return std::exp(val.to_double());
}
}; };
// log // log
struct log_impl struct log_impl
{ {
// using type = T; // using type = T;
value_type operator() (value_type const& val) const value_type operator()(value_type const& val) const { return std::log(val.to_double()); }
{
return std::log(val.to_double());
}
}; };
// sin // sin
struct sin_impl struct sin_impl
{ {
value_type operator() (value_type const& val) const value_type operator()(value_type const& val) const { return std::sin(val.to_double()); }
{
return std::sin(val.to_double());
}
}; };
// cos // cos
struct cos_impl struct cos_impl
{ {
value_type operator() (value_type const& val) const value_type operator()(value_type const& val) const { return std::cos(val.to_double()); }
{
return std::cos(val.to_double());
}
}; };
// tan // tan
struct tan_impl struct tan_impl
{ {
value_type operator() (value_type const& val) const value_type operator()(value_type const& val) const { return std::tan(val.to_double()); }
{
return std::tan(val.to_double());
}
}; };
// atan // atan
struct atan_impl struct atan_impl
{ {
value_type operator()(value_type const& val) const value_type operator()(value_type const& val) const { return std::atan(val.to_double()); }
{
return std::atan(val.to_double());
}
}; };
// abs // abs
struct abs_impl struct abs_impl
{ {
value_type operator() (value_type const& val) const value_type operator()(value_type const& val) const { return std::abs(val.to_double()); }
{
return std::abs(val.to_double());
}
}; };
// length // length
struct length_impl struct length_impl
{ {
value_type operator() (value_type const& val) const value_type operator()(value_type const& val) const { return val.to_unicode().length(); }
{
return val.to_unicode().length();
}
}; };
// min // min

View file

@ -42,8 +42,7 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/optional.hpp> #include <boost/optional.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
template<typename T> template<typename T>
bool clip_test(T p, T q, double& tmin, double& tmax) bool clip_test(T p, T q, double& tmin, double& tmax)
{ {
@ -52,15 +51,21 @@ bool clip_test(T p,T q,double& tmin,double& tmax)
if (p < 0.0) if (p < 0.0)
{ {
r = q / p; r = q / p;
if (r>tmax) result=false; if (r > tmax)
else if (r>tmin) tmin=r; result = false;
else if (r > tmin)
tmin = r;
} }
else if (p > 0.0) else if (p > 0.0)
{ {
r = q / p; r = q / p;
if (r<tmin) result=false; if (r < tmin)
else if (r<tmax) tmax=r; result = false;
} else if (q<0.0) result=false; else if (r < tmax)
tmax = r;
}
else if (q < 0.0)
result = false;
return result; return result;
} }
@ -117,9 +122,7 @@ inline bool point_inside_path(double x,double y,Iter start,Iter end)
x1 = std::get<0>(*start); x1 = std::get<0>(*start);
y1 = std::get<1>(*start); y1 = std::get<1>(*start);
if ((((y1 <= y) && (y < y0)) || if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
((y0 <= y) && (y < y1))) &&
( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
inside = !inside; inside = !inside;
x0 = x1; x0 = x1;
y0 = y1; y0 = y1;
@ -153,9 +156,7 @@ inline double distance(double x0, double y0, double x1, double y1)
return std::sqrt(distance2(x0, y0, x1, y1)); return std::sqrt(distance2(x0, y0, x1, y1));
} }
inline double point_to_segment_distance(double x, double y, inline double point_to_segment_distance(double x, double y, double ax, double ay, double bx, double by)
double ax, double ay,
double bx, double by)
{ {
double len2 = distance2(ax, ay, bx, by); double len2 = distance2(ax, ay, bx, by);
@ -211,12 +212,10 @@ struct bounding_box_filter
using value_type = T; using value_type = T;
box2d<value_type> box_; box2d<value_type> box_;
explicit bounding_box_filter(box2d<value_type> const& box) explicit bounding_box_filter(box2d<value_type> const& box)
: box_(box) {} : box_(box)
{}
bool pass(box2d<value_type> const& extent) const bool pass(box2d<value_type> const& extent) const { return extent.intersects(box_); }
{
return extent.intersects(box_);
}
}; };
using filter_in_box = bounding_box_filter<double>; using filter_in_box = bounding_box_filter<double>;
@ -232,10 +231,7 @@ struct at_point_filter
box_.pad(tol); box_.pad(tol);
} }
bool pass(box2d<value_type> const& extent) const bool pass(box2d<value_type> const& extent) const { return extent.intersects(box_); }
{
return extent.intersects(box_);
}
}; };
using filter_at_point = at_point_filter<double>; using filter_at_point = at_point_filter<double>;
@ -250,11 +246,13 @@ double path_length(PathType & path)
double y1 = 0; double y1 = 0;
path.rewind(0); path.rewind(0);
unsigned command = path.vertex(&x0, &y0); unsigned command = path.vertex(&x0, &y0);
if (command == SEG_END) return 0; if (command == SEG_END)
return 0;
double length = 0; double length = 0;
while (SEG_END != (command = path.vertex(&x1, &y1))) while (SEG_END != (command = path.vertex(&x1, &y1)))
{ {
if (command == SEG_CLOSE) continue; if (command == SEG_CLOSE)
continue;
length += distance(x0, y0, x1, y1); length += distance(x0, y0, x1, y1);
x0 = x1; x0 = x1;
y0 = y1; y0 = y1;
@ -291,9 +289,7 @@ bool hit_test_first(PathType & path, double x, double y)
continue; continue;
} }
if ((((y1 <= y) && (y < y0)) || if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
((y0 <= y) && (y < y1))) &&
(x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
inside = !inside; inside = !inside;
x0 = x1; x0 = x1;
@ -314,7 +310,8 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional<doubl
double mid_length = 0.5 * path_length(path); double mid_length = 0.5 * path_length(path);
path.rewind(0); path.rewind(0);
unsigned command = path.vertex(&x0, &y0); unsigned command = path.vertex(&x0, &y0);
if (command == SEG_END) return false; if (command == SEG_END)
return false;
if (std::abs(mid_length) < std::numeric_limits<double>::epsilon()) if (std::abs(mid_length) < std::numeric_limits<double>::epsilon())
{ {
x = x0; x = x0;
@ -324,7 +321,8 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional<doubl
double dist = 0.0; double dist = 0.0;
while (SEG_END != (command = path.vertex(&x1, &y1))) while (SEG_END != (command = path.vertex(&x1, &y1)))
{ {
if (command == SEG_CLOSE) continue; if (command == SEG_CLOSE)
continue;
double seg_length = distance(x0, y0, x1, y1); double seg_length = distance(x0, y0, x1, y1);
if (dist + seg_length >= mid_length) if (dist + seg_length >= mid_length)
@ -352,7 +350,8 @@ bool centroid(PathType & path, double & x, double & y)
path.rewind(0); path.rewind(0);
unsigned command = path.vertex(&p0.x, &p0.y); unsigned command = path.vertex(&p0.x, &p0.y);
if (command == SEG_END) return false; if (command == SEG_END)
return false;
start = move_to = p0; start = move_to = p0;
@ -380,7 +379,6 @@ bool centroid(PathType & path, double & x, double & y)
xtmp += (dx1 + dx0) * ai; xtmp += (dx1 + dx0) * ai;
ytmp += (dy1 + dy0) * ai; ytmp += (dy1 + dy0) * ai;
break; break;
} }
p0 = p1; p0 = p1;
++count; ++count;
@ -514,16 +512,12 @@ bool hit_test(PathType & path, double x, double y, double tol)
} }
switch (geom_type) switch (geom_type)
{ {
case mapnik::geometry::geometry_types::Polygon: case mapnik::geometry::geometry_types::Polygon: {
{ if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
if ((((y1 <= y) && (y < y0)) ||
((y0 <= y) && (y < y1))) &&
(x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
inside = !inside; inside = !inside;
break; break;
} }
case mapnik::geometry::geometry_types::LineString: case mapnik::geometry::geometry_types::LineString: {
{
double distance = point_to_segment_distance(x, y, x0, y0, x1, y1); double distance = point_to_segment_distance(x, y, x0, y0, x1, y1);
if (distance < tol) if (distance < tol)
return true; return true;
@ -544,6 +538,7 @@ bool hit_test(PathType & path, double x, double y, double tol)
return inside; return inside;
} }
}} } // namespace label
} // namespace mapnik
#endif // MAPNIK_GEOM_UTIL_HPP #endif // MAPNIK_GEOM_UTIL_HPP

View file

@ -38,12 +38,14 @@
#include <type_traits> #include <type_traits>
#include <cstddef> #include <cstddef>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<typename T, template<typename...> class Cont = std::vector> template<typename T, template<typename...> class Cont = std::vector>
struct geometry_collection; struct geometry_collection;
struct geometry_empty {}; struct geometry_empty
{};
template<typename T> template<typename T>
using geometry_base = mapnik::util::variant<geometry_empty, using geometry_base = mapnik::util::variant<geometry_empty,
@ -69,18 +71,19 @@ struct geometry : geometry_base<T>
template<typename G> template<typename G>
geometry(G&& geom) geometry(G&& geom)
: geometry_base<T>(std::forward<G>(geom)) {} : geometry_base<T>(std::forward<G>(geom))
{}
#endif #endif
}; };
template<typename T, template<typename...> class Cont> template<typename T, template<typename...> class Cont>
struct geometry_collection : Cont<geometry<T>> struct geometry_collection : Cont<geometry<T>>
{ {
using coordinate_type = T; using coordinate_type = T;
}; };
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_HPP #endif // MAPNIK_GEOMETRY_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP #ifndef MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
#define MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP #define MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
@ -45,7 +44,11 @@ MAPNIK_DISABLE_WARNING_POP
#include <mapnik/geometry/box2d.hpp> #include <mapnik/geometry/box2d.hpp>
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::geometry::point<double>, double, boost::geometry::cs::cartesian, x, y) BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::geometry::point<double>, double, boost::geometry::cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point<std::int64_t>, std::int64_t, boost::geometry::cs::cartesian, x, y) BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::geometry::point<std::int64_t>,
std::int64_t,
boost::geometry::cs::cartesian,
x,
y)
BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(mapnik::geometry::line_string) BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(mapnik::geometry::line_string)
BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(mapnik::geometry::linear_ring) BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(mapnik::geometry::linear_ring)
// needed by box2d<T> // needed by box2d<T>
@ -63,7 +66,8 @@ struct const_interior_rings
using value_type = typename polygon_type::value_type; using value_type = typename polygon_type::value_type;
const_interior_rings(polygon_type const& poly) const_interior_rings(polygon_type const& poly)
: poly_(poly) {} : poly_(poly)
{}
const_iterator begin() const const_iterator begin() const
{ {
@ -74,16 +78,12 @@ struct const_interior_rings
const_iterator end() const { return poly_.cend(); } const_iterator end() const { return poly_.cend(); }
std::size_t size() const std::size_t size() const { return poly_.empty() ? 0 : poly_.size() - 1; }
{
return poly_.empty() ? 0 : poly_.size() - 1;
}
value_type const& back() const { return poly_.back(); } value_type const& back() const { return poly_.back(); }
polygon_type const& poly_; polygon_type const& poly_;
}; };
template<typename CoordinateType> template<typename CoordinateType>
struct interior_rings struct interior_rings
{ {
@ -93,7 +93,8 @@ struct interior_rings
using value_type = typename polygon_type::value_type; using value_type = typename polygon_type::value_type;
interior_rings(polygon_type& poly) interior_rings(polygon_type& poly)
: poly_(poly) {} : poly_(poly)
{}
iterator begin() iterator begin()
{ {
@ -112,20 +113,11 @@ struct interior_rings
const_iterator end() const { return poly_.cend(); } const_iterator end() const { return poly_.cend(); }
void clear() void clear() { poly_.resize(1); }
{
poly_.resize(1);
}
void resize(std::size_t size) void resize(std::size_t size) { poly_.resize(size + 1); }
{
poly_.resize(size + 1);
}
std::size_t size() const std::size_t size() const { return poly_.empty() ? 0 : poly_.size() - 1; }
{
return poly_.empty() ? 0 : poly_.size() - 1;
}
void push_back(value_type const& val) { poly_.push_back(val); } void push_back(value_type const& val) { poly_.push_back(val); }
value_type& back() { return poly_.back(); } value_type& back() { return poly_.back(); }
@ -133,9 +125,11 @@ struct interior_rings
polygon_type& poly_; polygon_type& poly_;
}; };
} // ns mapnik } // namespace mapnik
namespace boost { namespace geometry { namespace traits { namespace boost {
namespace geometry {
namespace traits {
template<typename CoordinateType> template<typename CoordinateType>
struct tag<mapnik::box2d<CoordinateType>> struct tag<mapnik::box2d<CoordinateType>>
@ -143,8 +137,16 @@ struct tag<mapnik::box2d<CoordinateType> >
using type = box_tag; using type = box_tag;
}; };
template<> struct point_type<mapnik::box2d<double> > { using type = mapnik::coord2d; }; template<>
template<> struct point_type<mapnik::box2d<float> > { using type = mapnik::coord2f; }; struct point_type<mapnik::box2d<double>>
{
using type = mapnik::coord2d;
};
template<>
struct point_type<mapnik::box2d<float>>
{
using type = mapnik::coord2f;
};
template<typename CoordinateType> template<typename CoordinateType>
struct indexed_access<mapnik::box2d<CoordinateType>, min_corner, 0> struct indexed_access<mapnik::box2d<CoordinateType>, min_corner, 0>
@ -241,13 +243,15 @@ struct exterior_ring<mapnik::geometry::polygon<CoordinateType> >
using ring_mutable_type = typename ring_mutable_type<mapnik::geometry::polygon<CoordinateType>>::type; using ring_mutable_type = typename ring_mutable_type<mapnik::geometry::polygon<CoordinateType>>::type;
static ring_mutable_type get(mapnik::geometry::polygon<CoordinateType>& p) static ring_mutable_type get(mapnik::geometry::polygon<CoordinateType>& p)
{ {
if (p.empty()) p.resize(1); if (p.empty())
p.resize(1);
return p[0]; return p[0];
} }
static ring_const_type get(mapnik::geometry::polygon<CoordinateType> const& p) static ring_const_type get(mapnik::geometry::polygon<CoordinateType> const& p)
{ {
if (p.empty()) throw std::runtime_error("Exterior ring must be initialized!"); if (p.empty())
throw std::runtime_error("Exterior ring must be initialized!");
return p[0]; return p[0];
} }
}; };
@ -281,10 +285,7 @@ struct resize<mapnik::interior_rings<CoordinateType>>
template<typename CoordinateType> template<typename CoordinateType>
struct clear<mapnik::interior_rings<CoordinateType>> struct clear<mapnik::interior_rings<CoordinateType>>
{ {
static inline void apply(mapnik::interior_rings<CoordinateType> interiors) static inline void apply(mapnik::interior_rings<CoordinateType> interiors) { interiors.clear(); }
{
interiors.clear();
}
}; };
template<typename CoordinateType> template<typename CoordinateType>
@ -297,6 +298,8 @@ struct push_back<mapnik::interior_rings<CoordinateType>>
} }
}; };
}}} } // namespace traits
} // namespace geometry
} // namespace boost
#endif // MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP #endif // MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP

View file

@ -20,45 +20,39 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP #ifndef MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
#define MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP #define MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
namespace boost { using mapbox::util::get; } namespace boost {
using mapbox::util::get;
}
#include <boost/spirit/home/karma/domain.hpp> #include <boost/spirit/home/karma/domain.hpp>
#include <boost/spirit/home/support/attributes.hpp> #include <boost/spirit/home/support/attributes.hpp>
namespace boost { namespace spirit { namespace traits namespace boost {
{ namespace spirit {
namespace traits {
template<> template<>
struct not_is_variant<mapnik::geometry::geometry<double>, karma::domain> struct not_is_variant<mapnik::geometry::geometry<double>, karma::domain> : mpl::false_
: mpl::false_
{}; {};
template<> template<>
struct not_is_variant<mapnik::geometry::geometry<std::int64_t>, karma::domain> struct not_is_variant<mapnik::geometry::geometry<std::int64_t>, karma::domain> : mpl::false_
: mpl::false_
{}; {};
template<> template<>
struct variant_which<mapnik::geometry::geometry<double>> struct variant_which<mapnik::geometry::geometry<double>>
{ {
static int call(mapnik::geometry::geometry<double> const& v) static int call(mapnik::geometry::geometry<double> const& v) { return v.which(); }
{
return v.which();
}
}; };
template<> template<>
struct variant_which<mapnik::geometry::geometry<std::int64_t>> struct variant_which<mapnik::geometry::geometry<std::int64_t>>
{ {
static int call(mapnik::geometry::geometry<std::int64_t> const& v) static int call(mapnik::geometry::geometry<std::int64_t> const& v) { return v.which(); }
{
return v.which();
}
}; };
namespace detail { namespace detail {
@ -67,13 +61,16 @@ template <typename T, typename Tuple>
struct has_type; struct has_type;
template<typename T> template<typename T>
struct has_type<T, std::tuple<>> : std::false_type {}; struct has_type<T, std::tuple<>> : std::false_type
{};
template<typename T, typename U, typename... Types> template<typename T, typename U, typename... Types>
struct has_type<T, std::tuple<U, Types...>> : has_type<T, std::tuple<Types...>> {}; struct has_type<T, std::tuple<U, Types...>> : has_type<T, std::tuple<Types...>>
{};
template<typename T, typename... Types> template<typename T, typename... Types>
struct has_type<T, std::tuple<T, Types...>> : std::true_type {}; struct has_type<T, std::tuple<T, Types...>> : std::true_type
{};
template<typename T, typename Tuple> template<typename T, typename Tuple>
struct index; struct index;
@ -90,7 +87,7 @@ struct index<T, std::tuple<U, Types...>>
static const std::size_t value = 1 + index<T, std::tuple<Types...>>::value; static const std::size_t value = 1 + index<T, std::tuple<Types...>>::value;
}; };
} } // namespace detail
template<typename Expected> template<typename Expected>
struct compute_compatible_component_variant<mapnik::geometry::geometry<double>, Expected> struct compute_compatible_component_variant<mapnik::geometry::geometry<double>, Expected>
@ -114,8 +111,8 @@ struct compute_compatible_component_variant<mapnik::geometry::geometry<std::int6
} }
}; };
}}} } // namespace traits
} // namespace spirit
} // namespace boost
#endif // MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP #endif // MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP

View file

@ -46,11 +46,10 @@ namespace mapnik {
// A spatial envelope (i.e. bounding box) which also defines some basic operators. // A spatial envelope (i.e. bounding box) which also defines some basic operators.
template <typename T> class MAPNIK_DECL box2d template<typename T>
: boost::equality_comparable<box2d<T> , class MAPNIK_DECL box2d : boost::equality_comparable<
boost::addable<box2d<T>, box2d<T>,
boost::dividable2<box2d<T>, T, boost::addable<box2d<T>, boost::dividable2<box2d<T>, T, boost::multipliable2<box2d<T>, T>>>>
boost::multipliable2<box2d<T>, T > > > >
{ {
public: public:
using value_type = T; using value_type = T;
@ -59,6 +58,7 @@ public:
T miny_; T miny_;
T maxx_; T maxx_;
T maxy_; T maxy_;
private: private:
friend inline void swap(box2d_type& lhs, box2d_type& rhs) friend inline void swap(box2d_type& lhs, box2d_type& rhs)
{ {
@ -68,6 +68,7 @@ private:
swap(lhs.maxx_, rhs.maxx_); swap(lhs.maxx_, rhs.maxx_);
swap(lhs.maxy_, rhs.maxy_); swap(lhs.maxy_, rhs.maxy_);
} }
public: public:
box2d(); box2d();
@ -80,10 +81,10 @@ public:
// converting ctor // converting ctor
template<typename T1> template<typename T1>
explicit box2d(box2d<T1> other) explicit box2d(box2d<T1> other)
: minx_(static_cast<value_type>(other.minx())), : minx_(static_cast<value_type>(other.minx()))
miny_(static_cast<value_type>(other.miny())), , miny_(static_cast<value_type>(other.miny()))
maxx_(static_cast<value_type>(other.maxx())), , maxx_(static_cast<value_type>(other.maxx()))
maxy_(static_cast<value_type>(other.maxy())) , maxy_(static_cast<value_type>(other.maxy()))
{} {}
box2d_type& operator=(box2d_type other); box2d_type& operator=(box2d_type other);
T minx() const; T minx() const;
@ -136,13 +137,11 @@ public:
}; };
template<class charT, class traits, class T> template<class charT, class traits, class T>
inline std::basic_ostream<charT,traits>& inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out, const box2d<T>& e)
operator << (std::basic_ostream<charT,traits>& out,
const box2d<T>& e)
{ {
out << e.to_string(); out << e.to_string();
return out; return out;
} }
} } // namespace mapnik
#endif // MAPNIK_BOX2D_HPP #endif // MAPNIK_BOX2D_HPP

View file

@ -41,15 +41,11 @@ MAPNIK_DISABLE_WARNING_POP
// agg // agg
#include "agg_trans_affine.h" #include "agg_trans_affine.h"
BOOST_FUSION_ADAPT_TPL_STRUCT( BOOST_FUSION_ADAPT_TPL_STRUCT((T), (mapnik::box2d)(T), (T, minx_), (T, miny_), (T, maxx_), (T, maxy_))
(T),
(mapnik::box2d)(T),
(T, minx_),
(T, miny_),
(T, maxx_),
(T, maxy_))
namespace mapnik { namespace detail { namespace { namespace mapnik {
namespace detail {
namespace {
template<typename T> template<typename T>
struct assign struct assign
@ -60,15 +56,16 @@ struct assign
_val(ctx) = safe_cast<T>(_attr(ctx)); _val(ctx) = safe_cast<T>(_attr(ctx));
} }
}; };
} // anonymous } // namespace
} // detail } // namespace detail
template<typename T> template<typename T>
box2d<T>::box2d() box2d<T>::box2d()
:minx_( std::numeric_limits<T>::max()), : minx_(std::numeric_limits<T>::max())
miny_( std::numeric_limits<T>::max()), , miny_(std::numeric_limits<T>::max())
maxx_(-std::numeric_limits<T>::max()), , maxx_(-std::numeric_limits<T>::max())
maxy_(-std::numeric_limits<T>::max()) {} , maxy_(-std::numeric_limits<T>::max())
{}
template<typename T> template<typename T>
box2d<T>::box2d(T minx, T miny, T maxx, T maxy) box2d<T>::box2d(T minx, T miny, T maxx, T maxy)
@ -84,17 +81,19 @@ box2d<T>::box2d(coord<T,2> const& c0, coord<T,2> const& c1)
template<typename T> template<typename T>
box2d<T>::box2d(box2d_type const& rhs) box2d<T>::box2d(box2d_type const& rhs)
: minx_(rhs.minx_), : minx_(rhs.minx_)
miny_(rhs.miny_), , miny_(rhs.miny_)
maxx_(rhs.maxx_), , maxx_(rhs.maxx_)
maxy_(rhs.maxy_) {} , maxy_(rhs.maxy_)
{}
template<typename T> template<typename T>
box2d<T>::box2d(box2d_type&& rhs) box2d<T>::box2d(box2d_type&& rhs)
: minx_(std::move(rhs.minx_)), : minx_(std::move(rhs.minx_))
miny_(std::move(rhs.miny_)), , miny_(std::move(rhs.miny_))
maxx_(std::move(rhs.maxx_)), , maxx_(std::move(rhs.maxx_))
maxy_(std::move(rhs.maxy_)) {} , maxy_(std::move(rhs.maxy_))
{}
template<typename T> template<typename T>
box2d<T>& box2d<T>::operator=(box2d_type other) box2d<T>& box2d<T>::operator=(box2d_type other)
@ -114,8 +113,7 @@ box2d<T>::box2d(box2d_type const& rhs, agg::trans_affine const& tr)
tr.transform(&x1, &y1); tr.transform(&x1, &y1);
tr.transform(&x2, &y2); tr.transform(&x2, &y2);
tr.transform(&x3, &y3); tr.transform(&x3, &y3);
init(static_cast<T>(x0), static_cast<T>(y0), init(static_cast<T>(x0), static_cast<T>(y0), static_cast<T>(x2), static_cast<T>(y2));
static_cast<T>(x2), static_cast<T>(y2));
expand_to_include(static_cast<T>(x1), static_cast<T>(y1)); expand_to_include(static_cast<T>(x1), static_cast<T>(y1));
expand_to_include(static_cast<T>(x3), static_cast<T>(y3)); expand_to_include(static_cast<T>(x3), static_cast<T>(y3));
} }
@ -123,10 +121,7 @@ box2d<T>::box2d(box2d_type const& rhs, agg::trans_affine const& tr)
template<typename T> template<typename T>
bool box2d<T>::operator==(box2d<T> const& other) const bool box2d<T>::operator==(box2d<T> const& other) const
{ {
return minx_==other.minx_ && return minx_ == other.minx_ && miny_ == other.miny_ && maxx_ == other.maxx_ && maxy_ == other.maxy_;
miny_==other.miny_ &&
maxx_==other.maxx_ &&
maxy_==other.maxy_;
} }
template<typename T> template<typename T>
@ -208,8 +203,7 @@ void box2d<T>::height(T h)
template<typename T> template<typename T>
coord<T, 2> box2d<T>::center() const coord<T, 2> box2d<T>::center() const
{ {
return coord<T,2>(static_cast<T>(0.5*(minx_+maxx_)), return coord<T, 2>(static_cast<T>(0.5 * (minx_ + maxx_)), static_cast<T>(0.5 * (miny_ + maxy_)));
static_cast<T>(0.5*(miny_+maxy_)));
} }
template<typename T> template<typename T>
@ -221,19 +215,27 @@ void box2d<T>::expand_to_include(coord<T,2> const& c)
template<typename T> template<typename T>
void box2d<T>::expand_to_include(T x, T y) void box2d<T>::expand_to_include(T x, T y)
{ {
if (x<minx_) minx_=x; if (x < minx_)
if (x>maxx_) maxx_=x; minx_ = x;
if (y<miny_) miny_=y; if (x > maxx_)
if (y>maxy_) maxy_=y; maxx_ = x;
if (y < miny_)
miny_ = y;
if (y > maxy_)
maxy_ = y;
} }
template<typename T> template<typename T>
void box2d<T>::expand_to_include(box2d<T> const& other) void box2d<T>::expand_to_include(box2d<T> const& other)
{ {
if (other.minx_<minx_) minx_=other.minx_; if (other.minx_ < minx_)
if (other.maxx_>maxx_) maxx_=other.maxx_; minx_ = other.minx_;
if (other.miny_<miny_) miny_=other.miny_; if (other.maxx_ > maxx_)
if (other.maxy_>maxy_) maxy_=other.maxy_; maxx_ = other.maxx_;
if (other.miny_ < miny_)
miny_ = other.miny_;
if (other.maxy_ > maxy_)
maxy_ = other.maxy_;
} }
template<typename T> template<typename T>
@ -251,10 +253,7 @@ bool box2d<T>::contains(T x,T y) const
template<typename T> template<typename T>
bool box2d<T>::contains(box2d<T> const& other) const bool box2d<T>::contains(box2d<T> const& other) const
{ {
return other.minx_>=minx_ && return other.minx_ >= minx_ && other.maxx_ <= maxx_ && other.miny_ >= miny_ && other.maxy_ <= maxy_;
other.maxx_<=maxx_ &&
other.miny_>=miny_ &&
other.maxy_<=maxy_;
} }
template<typename T> template<typename T>
@ -272,8 +271,7 @@ bool box2d<T>::intersects(T x,T y) const
template<typename T> template<typename T>
bool box2d<T>::intersects(box2d<T> const& other) const bool box2d<T>::intersects(box2d<T> const& other) const
{ {
return !(other.minx_>maxx_ || other.maxx_<minx_ || return !(other.minx_ > maxx_ || other.maxx_ < minx_ || other.miny_ > maxy_ || other.maxy_ < miny_);
other.miny_>maxy_ || other.maxy_<miny_);
} }
template<typename T> template<typename T>
@ -365,12 +363,11 @@ bool box2d<T>::from_string(std::string const& str)
using boost::spirit::x3::lit; using boost::spirit::x3::lit;
boost::spirit::x3::double_type double_; boost::spirit::x3::double_type double_;
boost::spirit::x3::ascii::space_type space; boost::spirit::x3::ascii::space_type space;
bool r = boost::spirit::x3::phrase_parse(str.begin(), bool r = boost::spirit::x3::phrase_parse(
str.begin(),
str.end(), str.end(),
double_[detail::assign<T>()] >> -lit(',') >> double_[detail::assign<T>()] >> -lit(',') >> double_[detail::assign<T>()] >> -lit(',') >>
double_[detail::assign<T>()] >> -lit(',') >> double_[detail::assign<T>()] >> -lit(',') >> double_[detail::assign<T>()],
double_[detail::assign<T>()] >> -lit(',') >>
double_[detail::assign<T>()],
space, space,
*this); *this);
return r; return r;
@ -397,9 +394,8 @@ std::string box2d<T>::to_string() const
std::ostringstream s; std::ostringstream s;
if (valid()) if (valid())
{ {
s << "box2d(" << std::fixed << std::setprecision(16) s << "box2d(" << std::fixed << std::setprecision(16) << minx_ << ',' << miny_ << ',' << maxx_ << ',' << maxy_
<< minx_ << ',' << miny_ << ',' << ')';
<< maxx_ << ',' << maxy_ << ')';
} }
else else
{ {
@ -437,7 +433,6 @@ box2d<T>& box2d<T>::operator+= (T other)
return *this; return *this;
} }
template<typename T> template<typename T>
box2d<T>& box2d<T>::operator*=(T t) box2d<T>& box2d<T>::operator*=(T t)
{ {
@ -507,10 +502,9 @@ box2d<T>& box2d<T>::operator*=(agg::trans_affine const& tr)
tr.transform(&x1, &y1); tr.transform(&x1, &y1);
tr.transform(&x2, &y2); tr.transform(&x2, &y2);
tr.transform(&x3, &y3); tr.transform(&x3, &y3);
init(static_cast<T>(x0), static_cast<T>(y0), init(static_cast<T>(x0), static_cast<T>(y0), static_cast<T>(x2), static_cast<T>(y2));
static_cast<T>(x2), static_cast<T>(y2));
expand_to_include(static_cast<T>(x1), static_cast<T>(y1)); expand_to_include(static_cast<T>(x1), static_cast<T>(y1));
expand_to_include(static_cast<T>(x3), static_cast<T>(y3)); expand_to_include(static_cast<T>(x3), static_cast<T>(y3));
return *this; return *this;
} }
} } // namespace mapnik

View file

@ -29,7 +29,8 @@
#include <mapnik/geometry/is_empty.hpp> #include <mapnik/geometry/is_empty.hpp>
#include <mapnik/geometry/remove_empty.hpp> #include <mapnik/geometry/remove_empty.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
namespace detail { namespace detail {
@ -39,7 +40,8 @@ struct geometry_centroid
using result_type = bool; using result_type = bool;
geometry_centroid(point<T>& pt) geometry_centroid(point<T>& pt)
: pt_(pt) {} : pt_(pt)
{}
template<typename U> template<typename U>
result_type operator()(U const& geom) const result_type operator()(U const& geom) const
@ -47,45 +49,21 @@ struct geometry_centroid
return util::apply_visitor(*this, geom); return util::apply_visitor(*this, geom);
} }
result_type operator() (geometry_empty const&) const result_type operator()(geometry_empty const&) const { return false; }
{
return false;
}
result_type operator() (geometry_collection<T> const&) const result_type operator()(geometry_collection<T> const&) const { return false; }
{
return false;
}
result_type operator() (point<T> const& geom) const result_type operator()(point<T> const& geom) const { return centroid_simple(geom); }
{
return centroid_simple(geom);
}
result_type operator() (line_string<T> const& geom) const result_type operator()(line_string<T> const& geom) const { return centroid_simple(geom); }
{
return centroid_simple(geom);
}
result_type operator() (polygon<T> const& geom) const result_type operator()(polygon<T> const& geom) const { return centroid_simple(geom); }
{
return centroid_simple(geom);
}
result_type operator() (multi_point<T> const& geom) const result_type operator()(multi_point<T> const& geom) const { return centroid_simple(geom); }
{
return centroid_simple(geom);
}
result_type operator() (multi_line_string<T> const& geom) const result_type operator()(multi_line_string<T> const& geom) const { return centroid_multi(geom); }
{
return centroid_multi(geom);
}
result_type operator() (multi_polygon<T> const& geom) const result_type operator()(multi_polygon<T> const& geom) const { return centroid_multi(geom); }
{
return centroid_multi(geom);
}
point<T>& pt_; point<T>& pt_;
@ -97,8 +75,7 @@ private:
{ {
boost::geometry::centroid(geom, pt_); boost::geometry::centroid(geom, pt_);
return true; return true;
} } catch (boost::geometry::centroid_exception const& e)
catch (boost::geometry::centroid_exception const & e)
{ {
return false; return false;
} }
@ -111,7 +88,7 @@ private:
} }
}; };
} } // namespace detail
template<typename T1, typename T2> template<typename T1, typename T2>
inline bool centroid(T1 const& geom, point<T2>& pt) inline bool centroid(T1 const& geom, point<T2>& pt)
@ -119,6 +96,7 @@ inline bool centroid(T1 const& geom, point<T2> & pt)
return detail::geometry_centroid<T2>(pt)(geom); return detail::geometry_centroid<T2>(pt)(geom);
} }
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_CENTROID_HPP #endif // MAPNIK_GEOMETRY_CENTROID_HPP

View file

@ -30,7 +30,8 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/geometry/boost_adapters.hpp> #include <mapnik/geometry/boost_adapters.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
using coordinate_type = double; using coordinate_type = double;
struct closest_point_result struct closest_point_result
@ -44,8 +45,8 @@ using result_type = closest_point_result;
template<typename T1, typename T2> template<typename T1, typename T2>
MAPNIK_DECL result_type closest_point(T1 const& geom, mapnik::geometry::point<T2> const& pt); MAPNIK_DECL result_type closest_point(T1 const& geom, mapnik::geometry::point<T2> const& pt);
}} } // namespace geometry
} // namespace mapnik
#endif // #endif //
#endif // MAPNIK_GEOMETRY_CLOSEST_POINT_HPP #endif // MAPNIK_GEOMETRY_CLOSEST_POINT_HPP

View file

@ -35,7 +35,8 @@ MAPNIK_DISABLE_WARNING_POP
#include <type_traits> #include <type_traits>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
namespace detail { namespace detail {
@ -61,13 +62,15 @@ struct geometry_correct
template<typename T> template<typename T>
result_type operator()(polygon<T>& poly) const result_type operator()(polygon<T>& poly) const
{ {
if (!poly.empty()) boost::geometry::correct(poly); if (!poly.empty())
boost::geometry::correct(poly);
} }
template<typename T> template<typename T>
result_type operator()(multi_polygon<T>& multi_poly) const result_type operator()(multi_polygon<T>& multi_poly) const
{ {
if (!multi_poly.empty()) boost::geometry::correct(multi_poly); if (!multi_poly.empty())
boost::geometry::correct(multi_poly);
} }
template<typename T> template<typename T>
@ -75,10 +78,9 @@ struct geometry_correct
{ {
// no-op // no-op
} }
}; };
} } // namespace detail
template<typename GeomType> template<typename GeomType>
inline void correct(GeomType& geom) inline void correct(GeomType& geom)
@ -87,6 +89,7 @@ inline void correct(GeomType & geom)
detail::geometry_correct()(geom); detail::geometry_correct()(geom);
} }
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_CORRECT_HPP #endif // MAPNIK_GEOMETRY_CORRECT_HPP

View file

@ -32,7 +32,7 @@ namespace geometry {
template<typename T> template<typename T>
MAPNIK_DECL auto envelope(T const& geom) -> box2d<typename T::coordinate_type>; MAPNIK_DECL auto envelope(T const& geom) -> box2d<typename T::coordinate_type>;
} // end ns geometry } // namespace geometry
} // end ns mapnik } // namespace mapnik
#endif // MAPNIK_GEOMETRY_ENVELOPE_HPP #endif // MAPNIK_GEOMETRY_ENVELOPE_HPP

View file

@ -24,7 +24,8 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/geometry/box2d.hpp> #include <mapnik/geometry/box2d.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
namespace detail { namespace detail {
@ -36,7 +37,8 @@ struct geometry_envelope
bbox_type& bbox; bbox_type& bbox;
explicit geometry_envelope(bbox_type& bbox_) explicit geometry_envelope(bbox_type& bbox_)
: bbox(bbox_) {} : bbox(bbox_)
{}
template<typename U> template<typename U>
void operator()(U const& geom) const void operator()(U const& geom) const
@ -55,25 +57,17 @@ struct geometry_envelope
bbox.expand_to_include(pt.x, pt.y); bbox.expand_to_include(pt.x, pt.y);
} }
void operator() (mapnik::geometry::line_string<T> const& line) const void operator()(mapnik::geometry::line_string<T> const& line) const { _envelope_impl(line, bbox); }
{
_envelope_impl(line, bbox);
}
void operator() (mapnik::geometry::linear_ring<T> const& ring) const void operator()(mapnik::geometry::linear_ring<T> const& ring) const { _envelope_impl(ring, bbox); }
{
_envelope_impl(ring, bbox);
}
void operator()(mapnik::geometry::polygon<T> const& poly) const void operator()(mapnik::geometry::polygon<T> const& poly) const
{ {
if (!poly.empty()) _envelope_impl(poly[0], bbox); if (!poly.empty())
_envelope_impl(poly[0], bbox);
} }
void operator() (mapnik::geometry::multi_point<T> const& multi_point) const void operator()(mapnik::geometry::multi_point<T> const& multi_point) const { _envelope_impl(multi_point, bbox); }
{
_envelope_impl(multi_point, bbox);
}
void operator()(mapnik::geometry::multi_line_string<T> const& multi_line) const void operator()(mapnik::geometry::multi_line_string<T> const& multi_line) const
{ {
@ -119,7 +113,7 @@ private:
} }
}; };
} // end ns detail } // namespace detail
template<typename T> template<typename T>
auto envelope(T const& geom) -> box2d<typename T::coordinate_type> auto envelope(T const& geom) -> box2d<typename T::coordinate_type>
@ -131,5 +125,5 @@ auto envelope(T const& geom) -> box2d<typename T::coordinate_type>
return bbox; return bbox;
} }
} // end ns geometry } // namespace geometry
} // end ns mapnik } // namespace mapnik

View file

@ -20,23 +20,14 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP #ifndef MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP
#define MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP #define MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP
#include <mapnik/geometry/polygon.hpp> #include <mapnik/geometry/polygon.hpp>
#include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/adapt_struct.hpp>
BOOST_FUSION_ADAPT_STRUCT( BOOST_FUSION_ADAPT_STRUCT(mapnik::geometry::point<double>, (double, x)(double, y))
mapnik::geometry::point<double>,
(double, x)
(double, y)
)
BOOST_FUSION_ADAPT_STRUCT( BOOST_FUSION_ADAPT_STRUCT(mapnik::geometry::point<std::int64_t>, (std::int64_t, x)(std::int64_t, y))
mapnik::geometry::point<std::int64_t>,
(std::int64_t, x)
(std::int64_t, y)
)
#endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP #endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP

View file

@ -27,7 +27,9 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/geometry/geometry_types.hpp> #include <mapnik/geometry/geometry_types.hpp>
namespace mapnik { namespace geometry { namespace detail { namespace mapnik {
namespace geometry {
namespace detail {
template<typename T> template<typename T>
struct geometry_type struct geometry_type
@ -77,7 +79,7 @@ struct geometry_type
return mapnik::geometry::geometry_types::GeometryCollection; return mapnik::geometry::geometry_types::GeometryCollection;
} }
}; };
} // detail } // namespace detail
template<typename T> template<typename T>
static inline mapnik::geometry::geometry_types geometry_type(T const& geom) static inline mapnik::geometry::geometry_types geometry_type(T const& geom)
@ -86,7 +88,7 @@ static inline mapnik::geometry::geometry_types geometry_type(T const& geom)
return detail::geometry_type<coordinate_type>()(geom); return detail::geometry_type<coordinate_type>()(geom);
} }
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_TYPE_HPP #endif // MAPNIK_GEOMETRY_TYPE_HPP

View file

@ -25,11 +25,11 @@
#include <cstdint> #include <cstdint>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
// OGC compatible types // OGC compatible types
enum geometry_types : std::uint8_t enum geometry_types : std::uint8_t {
{
Unknown = 0, Unknown = 0,
Point = 1, Point = 1,
LineString = 2, LineString = 2,
@ -40,6 +40,7 @@ enum geometry_types : std::uint8_t
GeometryCollection = 7, GeometryCollection = 7,
}; };
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_TYPES_HPP #endif // MAPNIK_GEOMETRY_TYPES_HPP

View file

@ -27,13 +27,13 @@
#include <mapnik/geometry/polygon.hpp> #include <mapnik/geometry/polygon.hpp>
#include <mapnik/geometry/point.hpp> #include <mapnik/geometry/point.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<class T> template<class T>
MAPNIK_DECL bool interior(polygon<T> const& polygon, MAPNIK_DECL bool interior(polygon<T> const& polygon, double scale_factor, point<T>& pt);
double scale_factor,
point<T> & pt);
} } }
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_INTERIOR_HPP #endif // MAPNIK_GEOMETRY_INTERIOR_HPP

View file

@ -25,7 +25,8 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
namespace detail { namespace detail {
@ -36,49 +37,30 @@ struct geometry_is_empty
return mapnik::util::apply_visitor(*this, geom); return mapnik::util::apply_visitor(*this, geom);
} }
bool operator() (mapnik::geometry::point<double> const&) const bool operator()(mapnik::geometry::point<double> const&) const { return false; }
{
return false;
}
bool operator() (mapnik::geometry::line_string<double> const& geom) const bool operator()(mapnik::geometry::line_string<double> const& geom) const { return geom.empty(); }
{
return geom.empty();
}
bool operator()(mapnik::geometry::polygon<double> const& geom) const bool operator()(mapnik::geometry::polygon<double> const& geom) const
{ {
return geom.empty() || geom.front().empty(); return geom.empty() || geom.front().empty();
} }
bool operator() (mapnik::geometry::multi_point<double> const& geom) const bool operator()(mapnik::geometry::multi_point<double> const& geom) const { return geom.empty(); }
{
return geom.empty();
}
bool operator() (mapnik::geometry::multi_line_string<double> const& geom) const bool operator()(mapnik::geometry::multi_line_string<double> const& geom) const { return geom.empty(); }
{
return geom.empty();
}
bool operator() (mapnik::geometry::multi_polygon<double> const& geom) const bool operator()(mapnik::geometry::multi_polygon<double> const& geom) const { return geom.empty(); }
{
return geom.empty();
}
bool operator() (mapnik::geometry::geometry_collection<double> const& geom) const bool operator()(mapnik::geometry::geometry_collection<double> const& geom) const { return geom.empty(); }
{
return geom.empty();
}
template<typename T> template<typename T>
bool operator()(T const&) const bool operator()(T const&) const
{ {
return true; return true;
} }
}; };
} } // namespace detail
// returns true if the geometry is the empty set // returns true if the geometry is the empty set
template<typename GeomType> template<typename GeomType>
@ -87,6 +69,7 @@ inline bool is_empty(GeomType const& geom)
return detail::geometry_is_empty()(geom); return detail::geometry_is_empty()(geom);
} }
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_IS_EMPTY_HPP #endif // MAPNIK_GEOMETRY_IS_EMPTY_HPP

View file

@ -32,7 +32,8 @@
#include <mapnik/geometry/boost_adapters.hpp> #include <mapnik/geometry/boost_adapters.hpp>
#include <boost/geometry/algorithms/is_simple.hpp> #include <boost/geometry/algorithms/is_simple.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
namespace detail { namespace detail {
@ -58,7 +59,8 @@ struct geometry_is_simple
{ {
for (auto const& geom : collection) for (auto const& geom : collection)
{ {
if ( !(*this)(geom)) return false; if (!(*this)(geom))
return false;
} }
return true; return true;
} }
@ -107,7 +109,8 @@ struct geometry_is_simple
} }
for (auto const& line : multi_line) for (auto const& line : multi_line)
{ {
if (!(*this)(line)) return false; if (!(*this)(line))
return false;
} }
return true; return true;
} }
@ -122,14 +125,14 @@ struct geometry_is_simple
} }
for (auto const& poly : multi_poly) for (auto const& poly : multi_poly)
{ {
if (!(*this)(poly)) return false; if (!(*this)(poly))
return false;
} }
return true; return true;
} }
}; };
} } // namespace detail
template<typename T> template<typename T>
inline bool is_simple(T const& geom) inline bool is_simple(T const& geom)
@ -143,7 +146,8 @@ inline bool is_simple(mapnik::geometry::geometry<T> const& geom)
return util::apply_visitor(detail::geometry_is_simple(), geom); return util::apply_visitor(detail::geometry_is_simple(), geom);
} }
}} } // namespace geometry
} // namespace mapnik
#endif // BOOST_VERSION >= 1.56 #endif // BOOST_VERSION >= 1.56
#endif // MAPNIK_GEOMETRY_IS_SIMPLE_HPP #endif // MAPNIK_GEOMETRY_IS_SIMPLE_HPP

View file

@ -33,7 +33,8 @@
#include <boost/geometry/algorithms/is_valid.hpp> #include <boost/geometry/algorithms/is_valid.hpp>
#include <boost/geometry/algorithms/validity_failure_type.hpp> #include <boost/geometry/algorithms/validity_failure_type.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
namespace detail { namespace detail {
@ -47,17 +48,15 @@ struct geometry_is_valid
return mapnik::util::apply_visitor(*this, geom); return mapnik::util::apply_visitor(*this, geom);
} }
result_type operator() (geometry_empty const& ) const result_type operator()(geometry_empty const&) const { return true; }
{
return true;
}
template<typename T> template<typename T>
result_type operator()(geometry_collection<T> const& collection) const result_type operator()(geometry_collection<T> const& collection) const
{ {
for (auto const& geom : collection) for (auto const& geom : collection)
{ {
if ( !(*this)(geom)) return false; if (!(*this)(geom))
return false;
} }
return true; return true;
} }
@ -105,8 +104,9 @@ struct geometry_is_valid_reason
boost::geometry::validity_failure_type& failure_; boost::geometry::validity_failure_type& failure_;
geometry_is_valid_reason(boost::geometry::validity_failure_type & failure): geometry_is_valid_reason(boost::geometry::validity_failure_type& failure)
failure_(failure) {} : failure_(failure)
{}
template<typename T> template<typename T>
result_type operator()(geometry<T> const& geom) const result_type operator()(geometry<T> const& geom) const
@ -125,7 +125,8 @@ struct geometry_is_valid_reason
{ {
for (auto const& geom : collection) for (auto const& geom : collection)
{ {
if ( !(*this)(geom)) return false; if (!(*this)(geom))
return false;
} }
return true; return true;
} }
@ -173,8 +174,9 @@ struct geometry_is_valid_string
std::string& message_; std::string& message_;
geometry_is_valid_string(std::string & message): geometry_is_valid_string(std::string& message)
message_(message) {} : message_(message)
{}
template<typename T> template<typename T>
result_type operator()(geometry<T> const& geom) const result_type operator()(geometry<T> const& geom) const
@ -193,7 +195,8 @@ struct geometry_is_valid_string
{ {
for (auto const& geom : collection) for (auto const& geom : collection)
{ {
if ( !(*this)(geom)) return false; if (!(*this)(geom))
return false;
} }
return true; return true;
} }
@ -235,8 +238,7 @@ struct geometry_is_valid_string
} }
}; };
} // namespace detail
}
template<typename T> template<typename T>
inline bool is_valid(T const& geom) inline bool is_valid(T const& geom)
@ -257,8 +259,7 @@ inline bool is_valid(T const& geom, boost::geometry::validity_failure_type & fai
} }
template<typename T> template<typename T>
inline bool is_valid(mapnik::geometry::geometry<T> const& geom, inline bool is_valid(mapnik::geometry::geometry<T> const& geom, boost::geometry::validity_failure_type& failure)
boost::geometry::validity_failure_type & failure)
{ {
return util::apply_visitor(detail::geometry_is_valid_reason(failure), geom); return util::apply_visitor(detail::geometry_is_valid_reason(failure), geom);
} }
@ -270,13 +271,13 @@ inline bool is_valid(T const& geom, std::string & message)
} }
template<typename T> template<typename T>
inline bool is_valid(mapnik::geometry::geometry<T> const& geom, inline bool is_valid(mapnik::geometry::geometry<T> const& geom, std::string& message)
std::string & message)
{ {
return util::apply_visitor(detail::geometry_is_valid_string(message), geom); return util::apply_visitor(detail::geometry_is_valid_string(message), geom);
} }
}} } // namespace geometry
} // namespace mapnik
#endif // BOOST_VERSION >= 1.58 #endif // BOOST_VERSION >= 1.58
#endif // MAPNIK_GEOMETRY_IS_VALID_HPP #endif // MAPNIK_GEOMETRY_IS_VALID_HPP

View file

@ -26,10 +26,12 @@
// mapnik // mapnik
#include <mapbox/geometry/line_string.hpp> #include <mapbox/geometry/line_string.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<typename T> template<typename T>
using line_string = mapbox::geometry::line_string<T>; using line_string = mapbox::geometry::line_string<T>;
}} }
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_LINE_STRING_HPP #endif // MAPNIK_GEOMETRY_LINE_STRING_HPP

View file

@ -26,11 +26,13 @@
// geometry // geometry
#include <mapbox/geometry/multi_line_string.hpp> #include <mapbox/geometry/multi_line_string.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<typename T> template<typename T>
using multi_line_string = mapbox::geometry::multi_line_string<T>; using multi_line_string = mapbox::geometry::multi_line_string<T>;
}} }
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_MULTI_LINE_STRING_HPP #endif // MAPNIK_GEOMETRY_MULTI_LINE_STRING_HPP

View file

@ -26,11 +26,13 @@
// geometry // geometry
#include <mapbox/geometry/multi_point.hpp> #include <mapbox/geometry/multi_point.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<typename T> template<typename T>
using multi_point = mapbox::geometry::multi_point<T>; using multi_point = mapbox::geometry::multi_point<T>;
}} }
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_MULTI_POINT_HPP #endif // MAPNIK_GEOMETRY_MULTI_POINT_HPP

View file

@ -26,7 +26,8 @@
// geometry // geometry
#include <mapnik/geometry/polygon.hpp> #include <mapnik/geometry/polygon.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<typename T, template<typename...> class Cont = std::vector> template<typename T, template<typename...> class Cont = std::vector>
struct multi_polygon : Cont<polygon<T>> struct multi_polygon : Cont<polygon<T>>
@ -37,7 +38,7 @@ struct multi_polygon : Cont<polygon<T>>
using container_type::container_type; using container_type::container_type;
}; };
} // namespace geometry
}} } // namespace mapnik
#endif // MAPNIK_GEOMETRY_MULTI_POLYGON_HPP #endif // MAPNIK_GEOMETRY_MULTI_POLYGON_HPP

View file

@ -25,11 +25,13 @@
#include <mapbox/geometry/point.hpp> #include <mapbox/geometry/point.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<typename T> template<typename T>
using point = mapbox::geometry::point<T>; using point = mapbox::geometry::point<T>;
}} }
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_POINT_HPP #endif // MAPNIK_GEOMETRY_POINT_HPP

View file

@ -26,7 +26,8 @@
// geometry // geometry
#include <mapbox/geometry/polygon.hpp> #include <mapbox/geometry/polygon.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<typename T> template<typename T>
using linear_ring = mapbox::geometry::linear_ring<T>; using linear_ring = mapbox::geometry::linear_ring<T>;
@ -34,6 +35,7 @@ using linear_ring = mapbox::geometry::linear_ring<T>;
template<typename T> template<typename T>
using polygon = mapbox::geometry::polygon<T>; using polygon = mapbox::geometry::polygon<T>;
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_POLYGON_HPP #endif // MAPNIK_GEOMETRY_POLYGON_HPP

View file

@ -27,7 +27,8 @@
#include <mapnik/geometry/point.hpp> #include <mapnik/geometry/point.hpp>
#include <mapnik/geometry/polygon.hpp> #include <mapnik/geometry/polygon.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<typename T> template<typename T>
struct polygon_vertex_processor struct polygon_vertex_processor
@ -61,6 +62,7 @@ struct polygon_vertex_processor
polygon<T> polygon_; polygon<T> polygon_;
}; };
} } } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_POLYGON_VERTEX_PROCESSOR_HPP #endif // MAPNIK_GEOMETRY_POLYGON_VERTEX_PROCESSOR_HPP

View file

@ -27,17 +27,16 @@
#include <mapnik/geometry/polygon.hpp> #include <mapnik/geometry/polygon.hpp>
#include <mapnik/geometry/point.hpp> #include <mapnik/geometry/point.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
template<class T> template<class T>
MAPNIK_DECL bool polylabel(polygon<T> const& polygon, MAPNIK_DECL bool polylabel(polygon<T> const& polygon, T precision, point<T>& pt);
T precision,
point<T> & pt);
template<class T> template<class T>
MAPNIK_DECL T polylabel_precision(polygon<T> const& polygon, MAPNIK_DECL T polylabel_precision(polygon<T> const& polygon, double scale_factor);
double scale_factor);
} } } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_POLYLABEL_HPP #endif // MAPNIK_GEOMETRY_POLYLABEL_HPP

View file

@ -26,13 +26,15 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/geometry/is_empty.hpp> #include <mapnik/geometry/is_empty.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
namespace detail { namespace detail {
struct geometry_remove_empty struct geometry_remove_empty
{ {
mapnik::geometry::multi_line_string<double> operator() (mapnik::geometry::multi_line_string<double> const& geom) const mapnik::geometry::multi_line_string<double>
operator()(mapnik::geometry::multi_line_string<double> const& geom) const
{ {
return remove_empty(geom); return remove_empty(geom);
} }
@ -64,7 +66,7 @@ private:
} }
}; };
} } // namespace detail
template<typename GeomType> template<typename GeomType>
inline GeomType remove_empty(GeomType const& geom) inline GeomType remove_empty(GeomType const& geom)
@ -72,6 +74,7 @@ inline GeomType remove_empty(GeomType const& geom)
return detail::geometry_remove_empty()(geom); return detail::geometry_remove_empty()(geom);
} }
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_REMOVE_EMPTY_HPP #endif // MAPNIK_GEOMETRY_REMOVE_EMPTY_HPP

View file

@ -27,7 +27,6 @@
#include <mapnik/proj_transform.hpp> #include <mapnik/proj_transform.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
namespace mapnik { namespace mapnik {
namespace geometry { namespace geometry {
@ -46,7 +45,6 @@ MAPNIK_DECL T reproject_copy(T const& geom, proj_transform const& proj_trans, un
template<typename T> template<typename T>
MAPNIK_DECL T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int& n_err); MAPNIK_DECL T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int& n_err);
// No error count is required for a non const reprojection and this will reproject in place. // No error count is required for a non const reprojection and this will reproject in place.
// because the reprojection is done on the same memory it is important to check if it succeeded, // because the reprojection is done on the same memory it is important to check if it succeeded,
// otherwise you could be dealing with a corrupt geometry. // otherwise you could be dealing with a corrupt geometry.
@ -57,8 +55,8 @@ MAPNIK_DECL bool reproject(T & geom, proj_transform const& proj_trans);
template<typename T> template<typename T>
MAPNIK_DECL bool reproject(T& geom, projection const& source, projection const& dest); MAPNIK_DECL bool reproject(T& geom, projection const& source, projection const& dest);
} // end geometry ns } // namespace geometry
} // end mapnik ns } // namespace mapnik
#endif // MAPNIK_GEOMETRY_REPROJECTION_HPP #endif // MAPNIK_GEOMETRY_REPROJECTION_HPP

View file

@ -24,7 +24,9 @@
#include <mapnik/geometry/reprojection.hpp> #include <mapnik/geometry/reprojection.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
namespace mapnik { namespace geometry { namespace detail { namespace mapnik {
namespace geometry {
namespace detail {
// template <typename T> // template <typename T>
geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int&) geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int&)
@ -70,11 +72,12 @@ polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj
n_err += err; n_err += err;
// If there is an error in interior ring drop // If there is an error in interior ring drop
// it from polygon. // it from polygon.
if (!exterior) continue; if (!exterior)
continue;
} }
if (exterior) exterior = false; if (exterior)
exterior = false;
new_poly.push_back(std::move(new_lr)); new_poly.push_back(std::move(new_lr));
} }
return new_poly; return new_poly;
} }
@ -110,7 +113,8 @@ multi_point<T> reproject_internal(multi_point<T> const & mp, proj_transform cons
} }
template<typename T> template<typename T>
multi_line_string<T> reproject_internal(multi_line_string<T> const & mls, proj_transform const& proj_trans, unsigned int & n_err) multi_line_string<T>
reproject_internal(multi_line_string<T> const& mls, proj_transform const& proj_trans, unsigned int& n_err)
{ {
multi_line_string<T> new_mls; multi_line_string<T> new_mls;
new_mls.reserve(mls.size()); new_mls.reserve(mls.size());
@ -126,7 +130,8 @@ multi_line_string<T> reproject_internal(multi_line_string<T> const & mls, proj_t
} }
template<typename T> template<typename T>
multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transform const& proj_trans, unsigned int & n_err) multi_polygon<T>
reproject_internal(multi_polygon<T> const& mpoly, proj_transform const& proj_trans, unsigned int& n_err)
{ {
multi_polygon<T> new_mpoly; multi_polygon<T> new_mpoly;
new_mpoly.reserve(mpoly.size()); new_mpoly.reserve(mpoly.size());
@ -142,13 +147,13 @@ multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transfo
} }
template<typename T> template<typename T>
geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj_transform const& proj_trans, unsigned int & n_err) geometry_collection<T>
reproject_internal(geometry_collection<T> const& c, proj_transform const& proj_trans, unsigned int& n_err)
{ {
geometry_collection<T> new_c; geometry_collection<T> new_c;
new_c.reserve(c.size()); new_c.reserve(c.size());
for (auto const& g : c) for (auto const& g : c)
{ {
geometry<T> new_g = reproject_copy(g, proj_trans, n_err); geometry<T> new_g = reproject_copy(g, proj_trans, n_err);
if (!new_g.template is<geometry_empty>()) if (!new_g.template is<geometry_empty>())
{ {
@ -161,22 +166,20 @@ geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj
template<typename T> template<typename T>
struct geom_reproj_copy_visitor struct geom_reproj_copy_visitor
{ {
geom_reproj_copy_visitor(proj_transform const& proj_trans, unsigned int& n_err) geom_reproj_copy_visitor(proj_transform const& proj_trans, unsigned int& n_err)
: proj_trans_(proj_trans), : proj_trans_(proj_trans)
n_err_(n_err) {} , n_err_(n_err)
{}
geometry<T> operator() (geometry_empty) const geometry<T> operator()(geometry_empty) const { return geometry_empty(); }
{
return geometry_empty();
}
geometry<T> operator()(point<T> const& p) const geometry<T> operator()(point<T> const& p) const
{ {
geometry<T> geom; // default empty geometry<T> geom; // default empty
unsigned int intial_err = n_err_; unsigned int intial_err = n_err_;
point<T> new_p = reproject_internal(p, proj_trans_, n_err_); point<T> new_p = reproject_internal(p, proj_trans_, n_err_);
if (n_err_ > intial_err) return geom; if (n_err_ > intial_err)
return geom;
geom = std::move(new_p); geom = std::move(new_p);
return geom; return geom;
} }
@ -186,7 +189,8 @@ struct geom_reproj_copy_visitor
geometry<T> geom; // default empty geometry<T> geom; // default empty
unsigned int intial_err = n_err_; unsigned int intial_err = n_err_;
line_string<T> new_ls = reproject_internal(ls, proj_trans_, n_err_); line_string<T> new_ls = reproject_internal(ls, proj_trans_, n_err_);
if (n_err_ > intial_err || new_ls.empty()) return geom; if (n_err_ > intial_err || new_ls.empty())
return geom;
geom = std::move(new_ls); geom = std::move(new_ls);
return geom; return geom;
} }
@ -195,7 +199,8 @@ struct geom_reproj_copy_visitor
{ {
geometry<T> geom; // default empty geometry<T> geom; // default empty
polygon<T> new_poly = reproject_internal(poly, proj_trans_, n_err_); polygon<T> new_poly = reproject_internal(poly, proj_trans_, n_err_);
if (new_poly.size() == 0 || new_poly[0].size() == 0) return geom; if (new_poly.size() == 0 || new_poly[0].size() == 0)
return geom;
geom = std::move(new_poly); geom = std::move(new_poly);
return geom; return geom;
} }
@ -204,7 +209,8 @@ struct geom_reproj_copy_visitor
{ {
geometry<T> geom; // default empty geometry<T> geom; // default empty
multi_point<T> new_mp = reproject_internal(mp, proj_trans_, n_err_); multi_point<T> new_mp = reproject_internal(mp, proj_trans_, n_err_);
if (new_mp.empty()) return geom; if (new_mp.empty())
return geom;
geom = std::move(new_mp); geom = std::move(new_mp);
return geom; return geom;
} }
@ -213,7 +219,8 @@ struct geom_reproj_copy_visitor
{ {
geometry<T> geom; // default empty geometry<T> geom; // default empty
multi_line_string<T> new_mls = reproject_internal(mls, proj_trans_, n_err_); multi_line_string<T> new_mls = reproject_internal(mls, proj_trans_, n_err_);
if (new_mls.empty()) return geom; if (new_mls.empty())
return geom;
geom = std::move(new_mls); geom = std::move(new_mls);
return geom; return geom;
} }
@ -222,7 +229,8 @@ struct geom_reproj_copy_visitor
{ {
geometry<T> geom; // default empty geometry<T> geom; // default empty
multi_polygon<T> new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_); multi_polygon<T> new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_);
if (new_mpoly.empty()) return geom; if (new_mpoly.empty())
return geom;
geom = std::move(new_mpoly); geom = std::move(new_mpoly);
return geom; return geom;
} }
@ -231,7 +239,8 @@ struct geom_reproj_copy_visitor
{ {
geometry<T> geom; // default empty geometry<T> geom; // default empty
geometry_collection<T> new_c = reproject_internal(c, proj_trans_, n_err_); geometry_collection<T> new_c = reproject_internal(c, proj_trans_, n_err_);
if (new_c.empty()) return geom; if (new_c.empty())
return geom;
geom = std::move(new_c); geom = std::move(new_c);
return geom; return geom;
} }
@ -239,10 +248,9 @@ struct geom_reproj_copy_visitor
private: private:
proj_transform const& proj_trans_; proj_transform const& proj_trans_;
unsigned int& n_err_; unsigned int& n_err_;
}; };
} // end detail ns } // namespace detail
template<typename T> template<typename T>
geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int& n_err) geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int& n_err)
@ -266,10 +274,11 @@ T reproject_copy(T const& geom, projection const& source, projection const& dest
namespace detail { namespace detail {
struct geom_reproj_visitor { struct geom_reproj_visitor
{
geom_reproj_visitor(proj_transform const& proj_trans) geom_reproj_visitor(proj_transform const& proj_trans)
: proj_trans_(proj_trans) {} : proj_trans_(proj_trans)
{}
template<typename T> template<typename T>
bool operator()(geometry<T>& geom) const bool operator()(geometry<T>& geom) const
@ -364,10 +373,9 @@ struct geom_reproj_visitor {
private: private:
proj_transform const& proj_trans_; proj_transform const& proj_trans_;
}; };
} // end detail ns } // namespace detail
template<typename T> template<typename T>
bool reproject(T& geom, proj_transform const& proj_trans) bool reproject(T& geom, proj_transform const& proj_trans)
@ -384,5 +392,5 @@ bool reproject(T & geom, projection const& source, projection const& dest)
return visit(geom); return visit(geom);
} }
} // end geometry ns } // namespace geometry
} // end mapnik ns } // namespace mapnik

View file

@ -29,24 +29,27 @@
namespace mapnik { namespace mapnik {
namespace geometry { namespace geometry {
namespace helper namespace helper {
{
template<std::size_t... Ts> template<std::size_t... Ts>
struct index {}; struct index
{};
template<std::size_t N, std::size_t... Ts> template<std::size_t N, std::size_t... Ts>
struct gen_seq : gen_seq<N - 1, N - 1, Ts...> {}; struct gen_seq : gen_seq<N - 1, N - 1, Ts...>
{};
template<std::size_t... Ts> template<std::size_t... Ts>
struct gen_seq<0, Ts...> : index<Ts...> {}; struct gen_seq<0, Ts...> : index<Ts...>
} {};
} // namespace helper
// Groups a set of strategies at runtime, the conversion from P1 to P2 will take place on the LAST strategy. // Groups a set of strategies at runtime, the conversion from P1 to P2 will take place on the LAST strategy.
template<typename... Strategies> template<typename... Strategies>
struct strategy_group struct strategy_group
{ {
strategy_group(Strategies const&... ops) strategy_group(Strategies const&... ops)
: ops_(ops ...) {} : ops_(ops...)
{}
template<typename P1, typename P2> template<typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const inline bool apply(P1 const& p1, P2& p2) const
@ -57,7 +60,8 @@ struct strategy_group
} }
template<typename P1, typename P2, typename... Args, std::size_t... Is> template<typename P1, typename P2, typename... Args, std::size_t... Is>
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const inline P2
execute_start(P1 const& p1, bool& status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
{ {
return execute<P1, P2, Args...>(p1, status, std::get<Is>(tup)...); return execute<P1, P2, Args...>(p1, status, std::get<Is>(tup)...);
} }
@ -82,17 +86,16 @@ struct strategy_group
private: private:
std::tuple<Strategies const&...> ops_; std::tuple<Strategies const&...> ops_;
}; };
// The difference between this strategy group and the previous is that the conversion from P1 to P2 happens // The difference between this strategy group and the previous is that the conversion from P1 to P2 happens
// in the first strategy rather then the last strategy. // in the first strategy rather then the last strategy.
template<typename... Strategies> template<typename... Strategies>
struct strategy_group_first struct strategy_group_first
{ {
strategy_group_first(Strategies const&... ops) strategy_group_first(Strategies const&... ops)
: ops_(ops ...) {} : ops_(ops...)
{}
template<typename P1, typename P2> template<typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const inline bool apply(P1 const& p1, P2& p2) const
@ -103,7 +106,8 @@ struct strategy_group_first
} }
template<typename P1, typename P2, typename... Args, std::size_t... Is> template<typename P1, typename P2, typename... Args, std::size_t... Is>
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const inline P2
execute_start(P1 const& p1, bool& status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
{ {
return execute_first<P1, P2, Args...>(p1, status, std::get<Is>(tup)...); return execute_first<P1, P2, Args...>(p1, status, std::get<Is>(tup)...);
} }
@ -140,18 +144,18 @@ struct strategy_group_first
private: private:
std::tuple<Strategies const&...> ops_; std::tuple<Strategies const&...> ops_;
}; };
struct scale_strategy struct scale_strategy
{ {
scale_strategy(double scale, double offset = 0) scale_strategy(double scale, double offset = 0)
: scale_(scale), offset_(offset) {} : scale_(scale)
, offset_(offset)
{}
template<typename P1, typename P2> template<typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const inline bool apply(P1 const& p1, P2& p2) const
{ {
using p2_type = typename boost::geometry::coordinate_type<P2>::type; using p2_type = typename boost::geometry::coordinate_type<P2>::type;
double x = (boost::geometry::get<0>(p1) * scale_) + offset_; double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
double y = (boost::geometry::get<1>(p1) * scale_) + offset_; double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
@ -176,12 +180,13 @@ private:
struct scale_rounding_strategy struct scale_rounding_strategy
{ {
scale_rounding_strategy(double scale, double offset = 0) scale_rounding_strategy(double scale, double offset = 0)
: scale_(scale), offset_(offset) {} : scale_(scale)
, offset_(offset)
{}
template<typename P1, typename P2> template<typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const inline bool apply(P1 const& p1, P2& p2) const
{ {
using p2_type = typename boost::geometry::coordinate_type<P2>::type; using p2_type = typename boost::geometry::coordinate_type<P2>::type;
double x = (boost::geometry::get<0>(p1) * scale_) + offset_; double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
double y = (boost::geometry::get<1>(p1) * scale_) + offset_; double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
@ -203,8 +208,7 @@ private:
double offset_; double offset_;
}; };
} // namespace geometry
} // end geometry ns } // namespace mapnik
} // end mapnik ns
#endif // MAPNIK_GEOMETRY_STRATEGY_HPP #endif // MAPNIK_GEOMETRY_STRATEGY_HPP

View file

@ -26,18 +26,18 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/path.hpp> #include <mapnik/path.hpp>
namespace mapnik { namespace geometry { namespace detail { namespace mapnik {
namespace geometry {
namespace detail {
template<typename T> template<typename T>
struct geometry_to_path struct geometry_to_path
{ {
geometry_to_path(path_type& p) geometry_to_path(path_type& p)
: p_(p) {} : p_(p)
{}
void operator() (geometry<T> const& geom) const void operator()(geometry<T> const& geom) const { mapnik::util::apply_visitor(*this, geom); }
{
mapnik::util::apply_visitor(*this, geom);
}
void operator()(geometry_empty const&) const void operator()(geometry_empty const&) const
{ {
@ -59,8 +59,13 @@ struct geometry_to_path
{ {
// point pt_new; // point pt_new;
// Transformer::apply(pt, pt_new); // Transformer::apply(pt, pt_new);
if (first) { p_.move_to(pt.x, pt.y); first=false;} if (first)
else p_.line_to(pt.x, pt.y); {
p_.move_to(pt.x, pt.y);
first = false;
}
else
p_.line_to(pt.x, pt.y);
} }
} }
@ -125,9 +130,8 @@ struct geometry_to_path
} }
path_type& p_; path_type& p_;
}; };
} // ns detail } // namespace detail
template<typename T> template<typename T>
void to_path(T const& geom, path_type& p) void to_path(T const& geom, path_type& p)
@ -137,6 +141,7 @@ void to_path(T const& geom, path_type & p)
func(geom); func(geom);
} }
}} } // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_TO_PATH_HPP #endif // MAPNIK_GEOMETRY_TO_PATH_HPP

View file

@ -27,7 +27,9 @@
#include <mapnik/geometry/boost_adapters.hpp> #include <mapnik/geometry/boost_adapters.hpp>
#include <boost/geometry/algorithms/transform.hpp> #include <boost/geometry/algorithms/transform.hpp>
namespace mapnik { namespace geometry { namespace detail { namespace mapnik {
namespace geometry {
namespace detail {
template<typename V, typename T, typename Transformer> template<typename V, typename T, typename Transformer>
inline point<V> transform_geometry(point<T> const& geom, Transformer const& transformer) inline point<V> transform_geometry(point<T> const& geom, Transformer const& transformer)
@ -99,14 +101,12 @@ template <typename Transformer, typename V>
struct geometry_transform struct geometry_transform
{ {
geometry_transform(Transformer const& transformer) geometry_transform(Transformer const& transformer)
: transformer_(transformer) {} : transformer_(transformer)
{}
using result_type = geometry<V>; using result_type = geometry<V>;
geometry<V> operator() (geometry_empty const& empty) const geometry<V> operator()(geometry_empty const& empty) const { return geometry_empty(); }
{
return geometry_empty();
}
template<typename T> template<typename T>
geometry<V> operator()(geometry_collection<T> const& collection) const geometry<V> operator()(geometry_collection<T> const& collection) const
@ -164,7 +164,7 @@ struct geometry_transform
Transformer const& transformer_; Transformer const& transformer_;
}; };
} // ns detail } // namespace detail
template<typename T0, typename T1, typename T2> template<typename T0, typename T1, typename T2>
geometry<T0> transform(geometry<T1> const& geom, T2 const& transformer) geometry<T0> transform(geometry<T1> const& geom, T2 const& transformer)
@ -214,7 +214,7 @@ multi_polygon<T0> transform(multi_polygon<T1> const& geom, T2 const& transformer
return detail::transform_geometry<T0>(geom, transformer); return detail::transform_geometry<T0>(geom, transformer);
} }
} // namespace geometry
}} } // namespace mapnik
#endif // MAPNIK_GEOMETRY_TRANSFORM_HPP #endif // MAPNIK_GEOMETRY_TRANSFORM_HPP

View file

@ -28,27 +28,24 @@
#include <cstring> #include <cstring>
#include <cmath> #include <cmath>
namespace mapnik namespace mapnik {
{
#define int2net(A) (int16_t) (((std::uint16_t) ((std::uint8_t) (A)[1])) | \ #define int2net(A) (int16_t)(((std::uint16_t)((std::uint8_t)(A)[1])) | (((std::uint16_t)((std::uint8_t)(A)[0])) << 8))
(((std::uint16_t) ((std::uint8_t) (A)[0])) << 8))
#define int4net(A) (int32_t) (((std::uint32_t) ((std::uint8_t) (A)[3])) | \ #define int4net(A) \
(((std::uint32_t) ((std::uint8_t) (A)[2])) << 8) | \ (int32_t)(((std::uint32_t)((std::uint8_t)(A)[3])) | (((std::uint32_t)((std::uint8_t)(A)[2])) << 8) | \
(((std::uint32_t) ((std::uint8_t) (A)[1])) << 16) | \ (((std::uint32_t)((std::uint8_t)(A)[1])) << 16) | (((std::uint32_t)((std::uint8_t)(A)[0])) << 24))
(((std::uint32_t) ((std::uint8_t) (A)[0])) << 24))
#define int8net(A) (int64_t) (((std::uint64_t) ((std::uint8_t) (A)[7])) | \ #define int8net(A) \
(((std::uint64_t) ((std::uint8_t) (A)[6])) << 8) | \ (int64_t)(((std::uint64_t)((std::uint8_t)(A)[7])) | (((std::uint64_t)((std::uint8_t)(A)[6])) << 8) | \
(((std::uint64_t) ((std::uint8_t) (A)[5])) << 16) | \ (((std::uint64_t)((std::uint8_t)(A)[5])) << 16) | (((std::uint64_t)((std::uint8_t)(A)[4])) << 24) | \
(((std::uint64_t) ((std::uint8_t) (A)[4])) << 24) | \ (((std::uint64_t)((std::uint8_t)(A)[3])) << 32) | (((std::uint64_t)((std::uint8_t)(A)[2])) << 40) | \
(((std::uint64_t) ((std::uint8_t) (A)[3])) << 32) | \ (((std::uint64_t)((std::uint8_t)(A)[1])) << 48) | (((std::uint64_t)((std::uint8_t)(A)[0])) << 56))
(((std::uint64_t) ((std::uint8_t) (A)[2])) << 40) | \
(((std::uint64_t) ((std::uint8_t) (A)[1])) << 48) | \
(((std::uint64_t) ((std::uint8_t) (A)[0])) << 56))
#define float8net(V,M) do { double def_temp; \ #define float8net(V, M) \
do \
{ \
double def_temp; \
((std::uint8_t*)&def_temp)[0] = (M)[7]; \ ((std::uint8_t*)&def_temp)[0] = (M)[7]; \
((std::uint8_t*)&def_temp)[1] = (M)[6]; \ ((std::uint8_t*)&def_temp)[1] = (M)[6]; \
((std::uint8_t*)&def_temp)[2] = (M)[5]; \ ((std::uint8_t*)&def_temp)[2] = (M)[5]; \
@ -57,14 +54,18 @@ namespace mapnik
((std::uint8_t*)&def_temp)[5] = (M)[2]; \ ((std::uint8_t*)&def_temp)[5] = (M)[2]; \
((std::uint8_t*)&def_temp)[6] = (M)[1]; \ ((std::uint8_t*)&def_temp)[6] = (M)[1]; \
((std::uint8_t*)&def_temp)[7] = (M)[0]; \ ((std::uint8_t*)&def_temp)[7] = (M)[0]; \
(V) = def_temp; } while(0) (V) = def_temp; \
#define float4net(V,M) do { float def_temp; \ } while (0)
#define float4net(V, M) \
do \
{ \
float def_temp; \
((std::uint8_t*)&def_temp)[0] = (M)[3]; \ ((std::uint8_t*)&def_temp)[0] = (M)[3]; \
((std::uint8_t*)&def_temp)[1] = (M)[2]; \ ((std::uint8_t*)&def_temp)[1] = (M)[2]; \
((std::uint8_t*)&def_temp)[2] = (M)[1]; \ ((std::uint8_t*)&def_temp)[2] = (M)[1]; \
((std::uint8_t*)&def_temp)[3] = (M)[0]; \ ((std::uint8_t*)&def_temp)[3] = (M)[0]; \
(V)=def_temp; } while(0) (V) = def_temp; \
} while (0)
// read int16_t NDR (little endian) // read int16_t NDR (little endian)
inline void read_int16_ndr(const char* data, std::int16_t& val) inline void read_int16_ndr(const char* data, std::int16_t& val)
@ -99,14 +100,11 @@ inline void read_int32_xdr(const char* data, std::int32_t & val)
// read double XDR (big endian) // read double XDR (big endian)
inline void read_double_xdr(const char* data, double& val) inline void read_double_xdr(const char* data, double& val)
{ {
std::int64_t bits = (static_cast<std::int64_t>(data[7]) & 0xff) | std::int64_t bits =
(static_cast<std::int64_t>(data[6]) & 0xff) << 8 | (static_cast<std::int64_t>(data[7]) & 0xff) | (static_cast<std::int64_t>(data[6]) & 0xff) << 8 |
(static_cast<std::int64_t>(data[5]) & 0xff) << 16 | (static_cast<std::int64_t>(data[5]) & 0xff) << 16 | (static_cast<std::int64_t>(data[4]) & 0xff) << 24 |
(static_cast<std::int64_t>(data[4]) & 0xff) << 24 | (static_cast<std::int64_t>(data[3]) & 0xff) << 32 | (static_cast<std::int64_t>(data[2]) & 0xff) << 40 |
(static_cast<std::int64_t>(data[3]) & 0xff) << 32 | (static_cast<std::int64_t>(data[1]) & 0xff) << 48 | (static_cast<std::int64_t>(data[0]) & 0xff) << 56;
(static_cast<std::int64_t>(data[2]) & 0xff) << 40 |
(static_cast<std::int64_t>(data[1]) & 0xff) << 48 |
(static_cast<std::int64_t>(data[0]) & 0xff) << 56 ;
std::memcpy(&val, &bits, 8); std::memcpy(&val, &bits, 8);
} }
@ -117,6 +115,6 @@ inline double round(double val)
} }
#endif #endif
} } // namespace mapnik
#endif // MAPNIK_GLOBAL_HPP #endif // MAPNIK_GLOBAL_HPP

View file

@ -35,24 +35,18 @@ MAPNIK_DISABLE_WARNING_POP
// stl // stl
#include <vector> #include <vector>
namespace mapnik namespace mapnik {
{
using stop_pair = std::pair<double, mapnik::color>; using stop_pair = std::pair<double, mapnik::color>;
using stop_array = std::vector<stop_pair>; using stop_array = std::vector<stop_pair>;
enum gradient_e enum gradient_e { NO_GRADIENT, LINEAR, RADIAL };
{
NO_GRADIENT,
LINEAR,
RADIAL
};
enum gradient_unit_e enum gradient_unit_e {
{
USER_SPACE_ON_USE, USER_SPACE_ON_USE,
USER_SPACE_ON_USE_BOUNDING_BOX, // used to indicate % age values were specified. This are % of the svg image extent. USER_SPACE_ON_USE_BOUNDING_BOX, // used to indicate % age values were specified. This are % of the svg image extent.
OBJECT_BOUNDING_BOX // (i.e., the abstract coordinate system where (0,0) is at the top/left of the object bounding box and (1,1) is at the bottom/right of the object bounding box) OBJECT_BOUNDING_BOX // (i.e., the abstract coordinate system where (0,0) is at the top/left of the object bounding
// box and (1,1) is at the bottom/right of the object bounding box)
}; };
class MAPNIK_DECL gradient class MAPNIK_DECL gradient
@ -99,6 +93,6 @@ public:
private: private:
void swap(gradient& other) noexcept; void swap(gradient& other) noexcept;
}; };
} } // namespace mapnik
#endif // MAPNIK_GRADIENT_HPP #endif // MAPNIK_GRADIENT_HPP

View file

@ -42,8 +42,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace mapnik namespace mapnik {
{
template<typename T> template<typename T>
class MAPNIK_DECL hit_grid class MAPNIK_DECL hit_grid
@ -79,90 +78,44 @@ public:
void clear(); void clear();
inline void painted(bool is_painted) inline void painted(bool is_painted) { painted_ = is_painted; }
{
painted_ = is_painted;
}
inline bool painted() const inline bool painted() const { return painted_; }
{
return painted_;
}
inline std::string const& key_name() const inline std::string const& key_name() const { return id_name_; }
{
return id_name_;
}
void add_feature(mapnik::feature_impl const& feature); void add_feature(mapnik::feature_impl const& feature);
inline void add_field(std::string const& name) inline void add_field(std::string const& name) { names_.insert(name); }
{
names_.insert(name);
}
inline std::set<std::string> const& get_fields() const inline std::set<std::string> const& get_fields() const { return names_; }
{
return names_;
}
inline feature_type const& get_grid_features() const inline feature_type const& get_grid_features() const { return features_; }
{
return features_;
}
inline feature_key_type const& get_feature_keys() const inline feature_key_type const& get_feature_keys() const { return f_keys_; }
{
return f_keys_;
}
inline std::string const& get_key() const inline std::string const& get_key() const { return key_; }
{
return key_;
}
inline void set_key(std::string const& key) inline void set_key(std::string const& key) { key_ = key; }
{
key_ = key;
}
inline data_type const& data() const inline data_type const& data() const { return data_; }
{
return data_;
}
inline data_type& data() inline data_type& data() { return data_; }
{
return data_;
}
inline value_type const * raw_data() const inline value_type const* raw_data() const { return data_.data(); }
{
return data_.data();
}
inline value_type* raw_data() inline value_type* raw_data() { return data_.data(); }
{
return data_.data();
}
inline value_type const * get_row(std::size_t row) const inline value_type const* get_row(std::size_t row) const { return data_.get_row(row); }
{
return data_.get_row(row);
}
inline mapnik::grid_view get_view(std::size_t x, std::size_t y, std::size_t w, std::size_t h) inline mapnik::grid_view get_view(std::size_t x, std::size_t y, std::size_t w, std::size_t h)
{ {
return mapnik::grid_view(x, y, w, h, return mapnik::grid_view(x, y, w, h, data_, key_, id_name_, names_, f_keys_, features_);
data_, key_, id_name_, names_, f_keys_, features_);
} }
private: private:
inline bool checkBounds(std::size_t x, std::size_t y) const inline bool checkBounds(std::size_t x, std::size_t y) const { return (x < width_ && y < height_); }
{
return (x < width_ && y < height_);
}
hit_grid& operator=(const hit_grid&); hit_grid& operator=(const hit_grid&);
@ -174,15 +127,9 @@ public:
data_(x, y) = feature_id; data_(x, y) = feature_id;
} }
} }
inline std::size_t width() const inline std::size_t width() const { return width_; }
{
return width_;
}
inline std::size_t height() const inline std::size_t height() const { return height_; }
{
return height_;
}
inline void set_rectangle(value_type id, image_rgba8 const& data, std::size_t x0, std::size_t y0) inline void set_rectangle(value_type id, image_rgba8 const& data, std::size_t x0, std::size_t y0)
{ {
@ -219,5 +166,5 @@ public:
using grid = hit_grid<mapnik::value_integer_pixel>; using grid = hit_grid<mapnik::value_integer_pixel>;
} } // namespace mapnik
#endif // MAPNIK_GRID_HPP #endif // MAPNIK_GRID_HPP

View file

@ -25,8 +25,7 @@
#include "agg_basics.h" #include "agg_basics.h"
namespace mapnik namespace mapnik {
{
//==================================================================gray16 //==================================================================gray16
struct gray16 struct gray16
@ -34,12 +33,7 @@ struct gray16
using value_type = agg::int16u; using value_type = agg::int16u;
using calc_type = agg::int32u; using calc_type = agg::int32u;
using long_type = agg::int64; using long_type = agg::int64;
enum base_scale_e enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
using self_type = gray16; using self_type = gray16;
value_type v; value_type v;
@ -49,18 +43,19 @@ struct gray16
gray16() {} gray16() {}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
gray16(unsigned v_, unsigned a_=base_mask) : gray16(unsigned v_, unsigned a_ = base_mask)
v(agg::int16u(v_)), a(agg::int16u(a_)) {} : v(agg::int16u(v_))
, a(agg::int16u(a_))
{}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
gray16(const self_type& c, unsigned a_) : gray16(const self_type& c, unsigned a_)
v(c.v), a(value_type(a_)) {} : v(c.v)
, a(value_type(a_))
{}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void clear() void clear() { v = a = 0; }
{
v = a = 0;
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& transparent() const self_type& transparent()
@ -69,11 +64,11 @@ struct gray16
return *this; return *this;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& premultiply() const self_type& premultiply()
{ {
if(a == base_mask) return *this; if (a == base_mask)
return *this;
if (a == 0) if (a == 0)
{ {
v = 0; v = 0;
@ -86,7 +81,8 @@ struct gray16
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& premultiply(unsigned a_) const self_type& premultiply(unsigned a_)
{ {
if(a == base_mask && a_ >= base_mask) return *this; if (a == base_mask && a_ >= base_mask)
return *this;
if (a == 0 || a_ == 0) if (a == 0 || a_ == 0)
{ {
v = a = 0; v = a = 0;
@ -101,7 +97,8 @@ struct gray16
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& demultiply() const self_type& demultiply()
{ {
if(a == base_mask) return *this; if (a == base_mask)
return *this;
if (a == 0) if (a == 0)
{ {
v = 0; v = 0;
@ -134,8 +131,10 @@ struct gray16
} }
else else
{ {
cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv; cv = v + c.v;
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
ca = a + c.a;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
} }
} }
else else
@ -162,12 +161,7 @@ struct gray32
// in grid_pixfmt.hpp#blend_hiline#l256 // in grid_pixfmt.hpp#blend_hiline#l256
// otherwise code will get invoked that breaks // otherwise code will get invoked that breaks
// with 32 bit or 64 bit ints (blender_gray::blend_pix) // with 32 bit or 64 bit ints (blender_gray::blend_pix)
enum base_scale_e enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
using self_type = gray32; using self_type = gray32;
value_type v; value_type v;
@ -177,18 +171,19 @@ struct gray32
gray32() {} gray32() {}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
gray32(value_type v_, unsigned a_=base_mask) : gray32(value_type v_, unsigned a_ = base_mask)
v(v_), a(value_type(a_)) {} : v(v_)
, a(value_type(a_))
{}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
gray32(const self_type& c, unsigned a_) : gray32(const self_type& c, unsigned a_)
v(c.v), a(value_type(a_)) {} : v(c.v)
, a(value_type(a_))
{}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void clear() void clear() { v = a = 0; }
{
v = a = 0;
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& transparent() const self_type& transparent()
@ -197,11 +192,11 @@ struct gray32
return *this; return *this;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& premultiply() const self_type& premultiply()
{ {
if(a == base_mask) return *this; if (a == base_mask)
return *this;
if (a == 0) if (a == 0)
{ {
v = 0; v = 0;
@ -214,7 +209,8 @@ struct gray32
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& premultiply(unsigned a_) const self_type& premultiply(unsigned a_)
{ {
if(a == base_mask && a_ >= base_mask) return *this; if (a == base_mask && a_ >= base_mask)
return *this;
if (a == 0 || a_ == 0) if (a == 0 || a_ == 0)
{ {
v = a = 0; v = a = 0;
@ -229,7 +225,8 @@ struct gray32
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& demultiply() const self_type& demultiply()
{ {
if(a == base_mask) return *this; if (a == base_mask)
return *this;
if (a == 0) if (a == 0)
{ {
v = 0; v = 0;
@ -262,8 +259,10 @@ struct gray32
} }
else else
{ {
cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv; cv = v + c.v;
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
ca = a + c.a;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
} }
} }
else else
@ -290,12 +289,7 @@ struct gray64
// in grid_pixfmt.hpp#blend_hiline#l256 // in grid_pixfmt.hpp#blend_hiline#l256
// otherwise code will get invoked that breaks // otherwise code will get invoked that breaks
// with 32 bit or 64 bit ints (blender_gray::blend_pix) // with 32 bit or 64 bit ints (blender_gray::blend_pix)
enum base_scale_e enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
using self_type = gray64; using self_type = gray64;
value_type v; value_type v;
@ -305,18 +299,19 @@ struct gray64
gray64() {} gray64() {}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
gray64(value_type v_, unsigned a_=base_mask) : gray64(value_type v_, unsigned a_ = base_mask)
v(v_), a(value_type(a_)) {} : v(v_)
, a(value_type(a_))
{}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
gray64(const self_type& c, unsigned a_) : gray64(const self_type& c, unsigned a_)
v(c.v), a(value_type(a_)) {} : v(c.v)
, a(value_type(a_))
{}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void clear() void clear() { v = a = 0; }
{
v = a = 0;
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& transparent() const self_type& transparent()
@ -325,11 +320,11 @@ struct gray64
return *this; return *this;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& premultiply() const self_type& premultiply()
{ {
if(a == base_mask) return *this; if (a == base_mask)
return *this;
if (a == 0) if (a == 0)
{ {
v = 0; v = 0;
@ -342,7 +337,8 @@ struct gray64
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& premultiply(unsigned a_) const self_type& premultiply(unsigned a_)
{ {
if(a == base_mask && a_ >= base_mask) return *this; if (a == base_mask && a_ >= base_mask)
return *this;
if (a == 0 || a_ == 0) if (a == 0 || a_ == 0)
{ {
v = a = 0; v = a = 0;
@ -357,7 +353,8 @@ struct gray64
//-------------------------------------------------------------------- //--------------------------------------------------------------------
const self_type& demultiply() const self_type& demultiply()
{ {
if(a == base_mask) return *this; if (a == base_mask)
return *this;
if (a == 0) if (a == 0)
{ {
v = 0; v = 0;
@ -390,8 +387,10 @@ struct gray64
} }
else else
{ {
cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv; cv = v + c.v;
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
ca = a + c.a;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
} }
} }
else else
@ -407,6 +406,6 @@ struct gray64
static self_type no_color() { return self_type(0, 0); } static self_type no_color() { return self_type(0, 0); }
}; };
} } // namespace mapnik
#endif #endif

View file

@ -33,64 +33,57 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/grid/grid_pixel.hpp> #include <mapnik/grid/grid_pixel.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
//============================================================blender_gray //============================================================blender_gray
template<typename ColorT> struct blender_gray template<typename ColorT>
struct blender_gray
{ {
using color_type = ColorT; using color_type = ColorT;
using value_type = typename color_type::value_type; using value_type = typename color_type::value_type;
using calc_type = typename color_type::calc_type; using calc_type = typename color_type::calc_type;
enum base_scale_e { base_shift = color_type::base_shift }; enum base_scale_e { base_shift = color_type::base_shift };
static AGG_INLINE void blend_pix(value_type* p, unsigned cv, static AGG_INLINE void blend_pix(value_type* p, unsigned cv, unsigned alpha, unsigned /*cover*/ = 0)
unsigned alpha, unsigned /*cover*/=0)
{ {
*p = (value_type)((((cv - calc_type(*p)) * alpha) + (calc_type(*p) << base_shift)) >> base_shift); *p = (value_type)((((cv - calc_type(*p)) * alpha) + (calc_type(*p) << base_shift)) >> base_shift);
} }
}; };
//=====================================================apply_gamma_dir_gray //=====================================================apply_gamma_dir_gray
template<typename ColorT, class GammaLut> class apply_gamma_dir_gray template<typename ColorT, class GammaLut>
class apply_gamma_dir_gray
{ {
public: public:
using value_type = typename ColorT::value_type; using value_type = typename ColorT::value_type;
apply_gamma_dir_gray(const GammaLut& gamma) : m_gamma(gamma) {} apply_gamma_dir_gray(const GammaLut& gamma)
: m_gamma(gamma)
{}
AGG_INLINE void operator () (value_type* p) AGG_INLINE void operator()(value_type* p) { *p = m_gamma.dir(*p); }
{
*p = m_gamma.dir(*p);
}
private: private:
const GammaLut& m_gamma; const GammaLut& m_gamma;
}; };
//=====================================================apply_gamma_inv_gray //=====================================================apply_gamma_inv_gray
template<typename ColorT, class GammaLut> class apply_gamma_inv_gray template<typename ColorT, class GammaLut>
class apply_gamma_inv_gray
{ {
public: public:
using value_type = typename ColorT::value_type; using value_type = typename ColorT::value_type;
apply_gamma_inv_gray(const GammaLut& gamma) : m_gamma(gamma) {} apply_gamma_inv_gray(const GammaLut& gamma)
: m_gamma(gamma)
{}
AGG_INLINE void operator () (value_type* p) AGG_INLINE void operator()(value_type* p) { *p = m_gamma.inv(*p); }
{
*p = m_gamma.inv(*p);
}
private: private:
const GammaLut& m_gamma; const GammaLut& m_gamma;
}; };
//=================================================pixfmt_alpha_blend_gray //=================================================pixfmt_alpha_blend_gray
template<typename Blender, class RenBuf, unsigned Step = 1, unsigned Offset = 0> template<typename Blender, class RenBuf, unsigned Step = 1, unsigned Offset = 0>
class pixfmt_alpha_blend_gray class pixfmt_alpha_blend_gray
@ -103,8 +96,7 @@ public:
using order_type = int; // A fake one using order_type = int; // A fake one
using value_type = typename color_type::value_type; using value_type = typename color_type::value_type;
using calc_type = typename color_type::calc_type; using calc_type = typename color_type::calc_type;
enum base_scale_e enum base_scale_e {
{
base_shift = color_type::base_shift, base_shift = color_type::base_shift,
base_scale = color_type::base_scale, base_scale = color_type::base_scale,
base_mask = color_type::base_mask, base_mask = color_type::base_mask,
@ -115,9 +107,7 @@ public:
private: private:
//-------------------------------------------------------------------- //--------------------------------------------------------------------
static AGG_INLINE void copy_or_blend_pix(value_type* p, static AGG_INLINE void copy_or_blend_pix(value_type* p, const color_type& c, unsigned cover)
const color_type& c,
unsigned cover)
{ {
if (c.a) if (c.a)
{ {
@ -133,9 +123,7 @@ private:
} }
} }
static AGG_INLINE void copy_or_blend_pix(value_type* p, const color_type& c)
static AGG_INLINE void copy_or_blend_pix(value_type* p,
const color_type& c)
{ {
if (c.a) if (c.a)
{ {
@ -150,11 +138,10 @@ private:
} }
} }
public: public:
//-------------------------------------------------------------------- //--------------------------------------------------------------------
explicit pixfmt_alpha_blend_gray(rbuf_type& rb) : explicit pixfmt_alpha_blend_gray(rbuf_type& rb)
m_rbuf(&rb) : m_rbuf(&rb)
{} {}
void attach(rbuf_type& rb) { m_rbuf = &rb; } void attach(rbuf_type& rb) { m_rbuf = &rb; }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -166,10 +153,7 @@ public:
if (r.clip(agg::rect_i(0, 0, pixf.width() - 1, pixf.height() - 1))) if (r.clip(agg::rect_i(0, 0, pixf.width() - 1, pixf.height() - 1)))
{ {
int stride = pixf.stride(); int stride = pixf.stride();
m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1), m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1), (r.x2 - r.x1) + 1, (r.y2 - r.y1) + 1, stride);
(r.x2 - r.x1) + 1,
(r.y2 - r.y1) + 1,
stride);
return true; return true;
} }
return false; return false;
@ -185,21 +169,12 @@ public:
const agg::int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); } const agg::int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); }
row_data row(int y) const { return m_rbuf->row(y); } row_data row(int y) const { return m_rbuf->row(y); }
const agg::int8u* pix_ptr(int x, int y) const const agg::int8u* pix_ptr(int x, int y) const { return m_rbuf->row_ptr(y) + x * Step + Offset; }
{
return m_rbuf->row_ptr(y) + x * Step + Offset;
}
agg::int8u* pix_ptr(int x, int y) agg::int8u* pix_ptr(int x, int y) { return m_rbuf->row_ptr(y) + x * Step + Offset; }
{
return m_rbuf->row_ptr(y) + x * Step + Offset;
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
AGG_INLINE static void make_pix(agg::int8u* p, const color_type& c) AGG_INLINE static void make_pix(agg::int8u* p, const color_type& c) { *(value_type*)p = c.v; }
{
*(value_type*)p = c.v;
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
AGG_INLINE color_type pixel(int x, int y) const AGG_INLINE color_type pixel(int x, int y) const
@ -217,60 +192,41 @@ public:
//-------------------------------------------------------------------- //--------------------------------------------------------------------
AGG_INLINE void blend_pixel(int x, int y, const color_type& c, agg::int8u cover) AGG_INLINE void blend_pixel(int x, int y, const color_type& c, agg::int8u cover)
{ {
copy_or_blend_pix((value_type*) copy_or_blend_pix((value_type*)m_rbuf->row_ptr(x, y, 1) + x * Step + Offset, c, cover);
m_rbuf->row_ptr(x, y, 1) + x * Step + Offset,
c,
cover);
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
AGG_INLINE void copy_hline(int x, int y, AGG_INLINE void copy_hline(int x, int y, unsigned len, const color_type& c)
unsigned len,
const color_type& c)
{ {
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do do
{ {
*p = c.v; *p = c.v;
p += Step; p += Step;
} while (--len);
} }
while(--len);
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
AGG_INLINE void copy_vline(int x, int y, AGG_INLINE void copy_vline(int x, int y, unsigned len, const color_type& c)
unsigned len,
const color_type& c)
{ {
do do
{ {
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = c.v; *p = c.v;
} while (--len);
} }
while(--len);
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void blend_hline(int x, int y, void blend_hline(int x, int y, unsigned len, const color_type& c, agg::int8u /*cover*/)
unsigned len,
const color_type& c,
agg::int8u /*cover*/)
{ {
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do do
{ {
*p = c.v; *p = c.v;
p += Step; p += Step;
} } while (--len);
while(--len);
// We ignore alpha since grid_renderer is a binary renderer for now // We ignore alpha since grid_renderer is a binary renderer for now
/*if (c.a) /*if (c.a)
{ {
@ -299,12 +255,8 @@ public:
}*/ }*/
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void blend_vline(int x, int y, void blend_vline(int x, int y, unsigned len, const color_type& c, agg::int8u cover)
unsigned len,
const color_type& c,
agg::int8u cover)
{ {
if (c.a) if (c.a)
{ {
@ -314,38 +266,29 @@ public:
{ {
do do
{ {
p = (value_type*) p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = c.v; *p = c.v;
} } while (--len);
while(--len);
} }
else else
{ {
do do
{ {
p = (value_type*) p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
Blender::blend_pix(p, c.v, alpha, cover); Blender::blend_pix(p, c.v, alpha, cover);
} } while (--len);
while(--len);
} }
} }
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void blend_solid_hspan(int x, int y, void blend_solid_hspan(int x, int y, unsigned len, const color_type& c, const agg::int8u* covers)
unsigned len,
const color_type& c,
const agg::int8u* covers)
{ {
if (c.a) if (c.a)
{ {
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do do
{ {
@ -360,17 +303,12 @@ public:
} }
p += Step; p += Step;
++covers; ++covers;
} } while (--len);
while(--len);
} }
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void blend_solid_vspan(int x, int y, void blend_solid_vspan(int x, int y, unsigned len, const color_type& c, const agg::int8u* covers)
unsigned len,
const color_type& c,
const agg::int8u* covers)
{ {
if (c.a) if (c.a)
{ {
@ -378,8 +316,7 @@ public:
{ {
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8; calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
if (alpha == base_mask) if (alpha == base_mask)
{ {
@ -390,55 +327,43 @@ public:
Blender::blend_pix(p, c.v, alpha, *covers); Blender::blend_pix(p, c.v, alpha, *covers);
} }
++covers; ++covers;
} } while (--len);
while(--len);
} }
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void copy_color_hspan(int x, int y, void copy_color_hspan(int x, int y, unsigned len, const color_type* colors)
unsigned len,
const color_type* colors)
{ {
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do do
{ {
*p = colors->v; *p = colors->v;
p += Step; p += Step;
++colors; ++colors;
} while (--len);
} }
while(--len);
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void copy_color_vspan(int x, int y, void copy_color_vspan(int x, int y, unsigned len, const color_type* colors)
unsigned len,
const color_type* colors)
{ {
do do
{ {
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = colors->v; *p = colors->v;
++colors; ++colors;
} while (--len);
} }
while(--len);
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void blend_color_hspan(int x, int y, void blend_color_hspan(int x,
int y,
unsigned len, unsigned len,
const color_type* colors, const color_type* colors,
const agg::int8u* covers, const agg::int8u* covers,
agg::int8u cover) agg::int8u cover)
{ {
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
if (covers) if (covers)
{ {
@ -446,8 +371,7 @@ public:
{ {
copy_or_blend_pix(p, *colors++, *covers++); copy_or_blend_pix(p, *colors++, *covers++);
p += Step; p += Step;
} } while (--len);
while(--len);
} }
else else
{ {
@ -465,8 +389,7 @@ public:
} }
p += Step; p += Step;
++colors; ++colors;
} } while (--len);
while(--len);
} }
else else
{ {
@ -474,16 +397,14 @@ public:
{ {
copy_or_blend_pix(p, *colors++, cover); copy_or_blend_pix(p, *colors++, cover);
p += Step; p += Step;
} } while (--len);
while(--len);
} }
} }
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void blend_color_vspan(int x, int y, void blend_color_vspan(int x,
int y,
unsigned len, unsigned len,
const color_type* colors, const color_type* colors,
const agg::int8u* covers, const agg::int8u* covers,
@ -494,12 +415,10 @@ public:
{ {
do do
{ {
p = (value_type*) p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
copy_or_blend_pix(p, *colors++, *covers++); copy_or_blend_pix(p, *colors++, *covers++);
} } while (--len);
while(--len);
} }
else else
{ {
@ -507,8 +426,7 @@ public:
{ {
do do
{ {
p = (value_type*) p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
if (colors->a == base_mask) if (colors->a == base_mask)
{ {
@ -519,19 +437,16 @@ public:
copy_or_blend_pix(p, *colors); copy_or_blend_pix(p, *colors);
} }
++colors; ++colors;
} } while (--len);
while(--len);
} }
else else
{ {
do do
{ {
p = (value_type*) p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
copy_or_blend_pix(p, *colors++, cover); copy_or_blend_pix(p, *colors++, cover);
} } while (--len);
while(--len);
} }
} }
} }
@ -547,44 +462,39 @@ public:
{ {
unsigned len = r.x2 - r.x1 + 1; unsigned len = r.x2 - r.x1 + 1;
value_type* p = (value_type*) value_type* p = (value_type*)m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset;
m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset;
do do
{ {
f(p); f(p);
p += Step; p += Step;
} } while (--len);
while(--len);
} }
} }
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
template<typename GammaLut> void apply_gamma_dir(const GammaLut& g) template<typename GammaLut>
void apply_gamma_dir(const GammaLut& g)
{ {
for_each_pixel(apply_gamma_dir_gray<color_type, GammaLut>(g)); for_each_pixel(apply_gamma_dir_gray<color_type, GammaLut>(g));
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
template<typename GammaLut> void apply_gamma_inv(const GammaLut& g) template<typename GammaLut>
void apply_gamma_inv(const GammaLut& g)
{ {
for_each_pixel(apply_gamma_inv_gray<color_type, GammaLut>(g)); for_each_pixel(apply_gamma_inv_gray<color_type, GammaLut>(g));
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
template<typename RenBuf2> template<typename RenBuf2>
void copy_from(const RenBuf2& from, void copy_from(const RenBuf2& from, int xdst, int ydst, int xsrc, int ysrc, unsigned len)
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len)
{ {
const agg::int8u* p = from.row_ptr(ysrc); const agg::int8u* p = from.row_ptr(ysrc);
if (p) if (p)
{ {
memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width, memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width, p + xsrc * pix_width, len * pix_width);
p + xsrc * pix_width,
len * pix_width);
} }
} }
@ -592,8 +502,10 @@ public:
template<typename SrcPixelFormatRenderer> template<typename SrcPixelFormatRenderer>
void blend_from_color(const SrcPixelFormatRenderer& from, void blend_from_color(const SrcPixelFormatRenderer& from,
const color_type& color, const color_type& color,
int xdst, int ydst, int xdst,
int /*xsrc*/, int ysrc, int ydst,
int /*xsrc*/,
int ysrc,
unsigned len, unsigned len,
agg::int8u cover) agg::int8u cover)
{ {
@ -601,17 +513,13 @@ public:
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc); const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
if (psrc) if (psrc)
{ {
value_type* pdst = value_type* pdst = (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
(value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
do do
{ {
copy_or_blend_pix(pdst, copy_or_blend_pix(pdst, color, (*psrc * cover + base_mask) >> base_shift);
color,
(*psrc * cover + base_mask) >> base_shift);
++psrc; ++psrc;
++pdst; ++pdst;
} } while (--len);
while(--len);
} }
} }
@ -619,8 +527,10 @@ public:
template<typename SrcPixelFormatRenderer> template<typename SrcPixelFormatRenderer>
void blend_from_lut(const SrcPixelFormatRenderer& from, void blend_from_lut(const SrcPixelFormatRenderer& from,
const color_type* color_lut, const color_type* color_lut,
int xdst, int ydst, int xdst,
int /*xsrc*/, int ysrc, int ydst,
int /*xsrc*/,
int ysrc,
unsigned len, unsigned len,
agg::int8u cover) agg::int8u cover)
{ {
@ -628,15 +538,13 @@ public:
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc); const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
if (psrc) if (psrc)
{ {
value_type* pdst = value_type* pdst = (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
(value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
do do
{ {
copy_or_blend_pix(pdst, color_lut[*psrc], cover); copy_or_blend_pix(pdst, color_lut[*psrc], cover);
++psrc; ++psrc;
++pdst; ++pdst;
} } while (--len);
while(--len);
} }
} }
@ -659,6 +567,6 @@ using blender_gray64 = blender_gray<gray64>;
using pixfmt_gray64 = pixfmt_alpha_blend_gray<blender_gray64, using pixfmt_gray64 = pixfmt_alpha_blend_gray<blender_gray64,
mapnik::grid_rendering_buffer>; //----pixfmt_gray64 mapnik::grid_rendering_buffer>; //----pixfmt_gray64
} } // namespace mapnik
#endif #endif

View file

@ -33,8 +33,10 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
struct grid_rasterizer : agg::rasterizer_scanline_aa<>, util::noncopyable {}; struct grid_rasterizer : agg::rasterizer_scanline_aa<>,
util::noncopyable
{};
} } // namespace mapnik
#endif // MAPNIK_AGG_RASTERIZER_HPP #endif // MAPNIK_AGG_RASTERIZER_HPP

View file

@ -53,10 +53,14 @@ void render_raster_marker(RendererType ren,
double width = src.width(); double width = src.width();
double height = src.height(); double height = src.height();
double p[8]; double p[8];
p[0] = 0; p[1] = 0; p[0] = 0;
p[2] = width; p[3] = 0; p[1] = 0;
p[4] = width; p[5] = height; p[2] = width;
p[6] = 0; p[7] = height; p[3] = 0;
p[4] = width;
p[5] = height;
p[6] = 0;
p[7] = height;
marker_tr.transform(&p[0], &p[1]); marker_tr.transform(&p[0], &p[1]);
marker_tr.transform(&p[2], &p[3]); marker_tr.transform(&p[2], &p[3]);
marker_tr.transform(&p[4], &p[5]); marker_tr.transform(&p[4], &p[5]);
@ -69,6 +73,6 @@ void render_raster_marker(RendererType ren,
agg::render_scanlines(ras, sl, ren); agg::render_scanlines(ras, sl, ren);
} }
} } // namespace mapnik
#endif #endif

View file

@ -40,7 +40,9 @@
#include <memory> #include <memory>
// fwd declaration to avoid depedence on agg headers // fwd declaration to avoid depedence on agg headers
namespace agg { struct trans_affine; } namespace agg {
struct trans_affine;
}
// fwd declarations to speed up compile // fwd declarations to speed up compile
namespace mapnik { namespace mapnik {
@ -53,7 +55,7 @@ namespace mapnik {
class proj_transform; class proj_transform;
struct grid_rasterizer; struct grid_rasterizer;
class request; class request;
} } // namespace mapnik
namespace mapnik { namespace mapnik {
@ -61,12 +63,17 @@ template <typename T>
class MAPNIK_DECL grid_renderer : public feature_style_processor<grid_renderer<T>>, class MAPNIK_DECL grid_renderer : public feature_style_processor<grid_renderer<T>>,
private util::noncopyable private util::noncopyable
{ {
public: public:
using buffer_type = T; using buffer_type = T;
using processor_impl_type = grid_renderer<T>; using processor_impl_type = grid_renderer<T>;
grid_renderer(Map const& m, T& pixmap, double scale_factor = 1.0, unsigned offset_x = 0, unsigned offset_y = 0); grid_renderer(Map const& m, T& pixmap, double scale_factor = 1.0, unsigned offset_x = 0, unsigned offset_y = 0);
grid_renderer(Map const& m, request const& req, attributes const& vars, T & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); grid_renderer(Map const& m,
request const& req,
attributes const& vars,
T& pixmap,
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
~grid_renderer(); ~grid_renderer();
void start_map_processing(Map const& map); void start_map_processing(Map const& map);
void end_map_processing(Map const& map); void end_map_processing(Map const& map);
@ -75,74 +82,39 @@ public:
void start_style_processing(feature_type_style const& /*st*/) {} void start_style_processing(feature_type_style const& /*st*/) {}
void end_style_processing(feature_type_style const& /*st*/) {} void end_style_processing(feature_type_style const& /*st*/) {}
void render_marker(mapnik::feature_impl const& feature, void render_marker(mapnik::feature_impl const& feature,
pixel_position const& pos, marker const& marker, pixel_position const& pos,
agg::trans_affine const& tr, double opacity, composite_mode_e comp_op); marker const& marker,
agg::trans_affine const& tr,
double opacity,
composite_mode_e comp_op);
void process(point_symbolizer const& sym, void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_symbolizer const& sym, void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym, void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym, void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); inline bool
void process(polygon_pattern_symbolizer const& sym, process(rule::symbolizers const& /*syms*/, mapnik::feature_impl& /*feature*/, proj_transform const& /*prj_trans*/)
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(raster_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(shield_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(text_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(markers_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(group_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
inline bool process(rule::symbolizers const& /*syms*/,
mapnik::feature_impl & /*feature*/,
proj_transform const& /*prj_trans*/)
{ {
// grid renderer doesn't support processing of multiple symbolizers. // grid renderer doesn't support processing of multiple symbolizers.
return false; return false;
} }
bool painted() bool painted() { return pixmap_.painted(); }
{
return pixmap_.painted();
}
void painted(bool _painted) void painted(bool _painted) { pixmap_.painted(_painted); }
{
pixmap_.painted(_painted);
}
inline eAttributeCollectionPolicy attribute_collection_policy() const inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
{
return DEFAULT;
}
inline double scale_factor() const inline double scale_factor() const { return common_.scale_factor_; }
{
return common_.scale_factor_;
}
inline attributes const& variables() const inline attributes const& variables() const { return common_.vars_; }
{
return common_.vars_;
}
private: private:
buffer_type& pixmap_; buffer_type& pixmap_;
@ -150,6 +122,6 @@ private:
renderer_common common_; renderer_common common_;
void setup(Map const& m); void setup(Map const& m);
}; };
} } // namespace mapnik
#endif // GRID_RENDERER_HPP #endif // GRID_RENDERER_HPP

View file

@ -39,6 +39,6 @@ using grid_renderer_base_type = agg::renderer_base<mapnik::pixfmt_gray64>;
using grid_renderer_base_type = agg::renderer_base<mapnik::pixfmt_gray32>; using grid_renderer_base_type = agg::renderer_base<mapnik::pixfmt_gray32>;
#endif #endif
} } // namespace mapnik
#endif // MAPNIK_AGG_RASTERIZER_HPP #endif // MAPNIK_AGG_RASTERIZER_HPP

View file

@ -50,51 +50,57 @@ public:
using feature_key_type = std::map<value_type, lookup_type>; using feature_key_type = std::map<value_type, lookup_type>;
using feature_type = std::map<std::string, mapnik::feature_ptr>; using feature_type = std::map<std::string, mapnik::feature_ptr>;
hit_grid_view(unsigned x, unsigned y, hit_grid_view(unsigned x,
unsigned width, unsigned height, unsigned y,
unsigned width,
unsigned height,
T const& _data, T const& _data,
std::string const& key, std::string const& key,
std::string const& id_name, std::string const& id_name,
std::set<std::string> const& names, std::set<std::string> const& names,
feature_key_type const& f_keys, feature_key_type const& f_keys,
feature_type const& features feature_type const& features)
) : x_(x)
: x_(x), , y_(y)
y_(y), , width_(width)
width_(width), , height_(height)
height_(height), , data_(_data)
data_(_data), , key_(key)
key_(key), , id_name_(id_name)
id_name_(id_name), , names_(names)
names_(names), , f_keys_(f_keys)
f_keys_(f_keys), , features_(features)
features_(features)
{ {
if (x_ >= data_.width()) x_=data_.width()-1; if (x_ >= data_.width())
if (y_ >= data_.height()) y_=data_.height()-1; x_ = data_.width() - 1;
if (x_ + width_ > data_.width()) width_= data_.width() - x_; if (y_ >= data_.height())
if (y_ + height_ > data_.height()) height_= data_.height() - y_; y_ = data_.height() - 1;
if (x_ + width_ > data_.width())
width_ = data_.width() - x_;
if (y_ + height_ > data_.height())
height_ = data_.height() - y_;
} }
~hit_grid_view() {} ~hit_grid_view() {}
hit_grid_view(hit_grid_view<T> const& rhs) hit_grid_view(hit_grid_view<T> const& rhs)
: x_(rhs.x_), : x_(rhs.x_)
y_(rhs.y_), , y_(rhs.y_)
width_(rhs.width_), , width_(rhs.width_)
height_(rhs.height_), , height_(rhs.height_)
data_(rhs.data_), , data_(rhs.data_)
key_(rhs.key_), , key_(rhs.key_)
id_name_(rhs.id_name_), , id_name_(rhs.id_name_)
names_(rhs.names_), , names_(rhs.names_)
f_keys_(rhs.f_keys_), , f_keys_(rhs.f_keys_)
features_(rhs.features_) , features_(rhs.features_)
{} {}
hit_grid_view<T>& operator=(hit_grid_view<T> const& rhs) hit_grid_view<T>& operator=(hit_grid_view<T> const& rhs)
{ {
if (&rhs==this) return *this; if (&rhs == this)
return *this;
x_ = rhs.x_; x_ = rhs.x_;
y_ = rhs.y_; y_ = rhs.y_;
width_ = rhs.width_; width_ = rhs.width_;
@ -108,70 +114,31 @@ public:
return *this; return *this;
} }
inline unsigned x() const inline unsigned x() const { return x_; }
{
return x_;
}
inline unsigned y() const inline unsigned y() const { return y_; }
{
return y_;
}
inline unsigned width() const inline unsigned width() const { return width_; }
{
return width_;
}
inline unsigned height() const inline unsigned height() const { return height_; }
{
return height_;
}
inline std::string const& key_name() const inline std::string const& key_name() const { return id_name_; }
{
return id_name_;
}
inline value_type const * get_row(unsigned row) const inline value_type const* get_row(unsigned row) const { return data_.get_row(row + y_) + x_; }
{
return data_.get_row(row + y_) + x_;
}
inline T& data() inline T& data() { return data_; }
{
return data_;
}
inline T const& data() const inline T const& data() const { return data_; }
{
return data_;
}
inline const unsigned char* raw_data() const inline const unsigned char* raw_data() const { return data_.bytes(); }
{
return data_.bytes();
}
inline std::set<std::string> const& get_fields() const inline std::set<std::string> const& get_fields() const { return names_; }
{
return names_;
}
inline feature_type const& get_grid_features() const inline feature_type const& get_grid_features() const { return features_; }
{
return features_;
}
inline feature_key_type const& get_feature_keys() const inline feature_key_type const& get_feature_keys() const { return f_keys_; }
{
return f_keys_;
}
inline lookup_type const& get_key() const inline lookup_type const& get_key() const { return key_; }
{
return key_;
}
private: private:
unsigned x_; unsigned x_;
@ -188,6 +155,6 @@ private:
using grid_view = hit_grid_view<mapnik::image<mapnik::value_integer_pixel>>; using grid_view = hit_grid_view<mapnik::image<mapnik::value_integer_pixel>>;
} } // namespace mapnik
#endif // MAPNIK_GRID_VIEW_HPP #endif // MAPNIK_GRID_VIEW_HPP

Some files were not shown because too many files have changed in this diff Show more