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"
MAPNIK_DISABLE_WARNING_POP
namespace mapnik
{
namespace mapnik {
struct vcgen_smooth_calucate_adaptive
{
@ -57,12 +56,8 @@ struct vcgen_smooth_calucate_adaptive
}
}
return {
{v1.x + s1 * smooth_value * (v2.x - xm1),
v1.y + s1 * smooth_value * (v2.y - ym1)},
{v2.x + s2 * smooth_value * (v1.x - xm2),
v2.y + s2 * smooth_value * (v1.y - ym2)}
};
return {{v1.x + s1 * smooth_value * (v2.x - xm1), v1.y + s1 * smooth_value * (v2.y - ym1)},
{v2.x + s2 * smooth_value * (v1.x - xm2), v2.y + s2 * smooth_value * (v1.y - ym2)}};
}
};
@ -71,7 +66,7 @@ using vcgen_smooth_adaptive = agg::vcgen_smooth<vcgen_smooth_calucate_adaptive>;
template<class VertexSource>
using conv_smooth_adaptive = agg::conv_smooth_curve<VertexSource, vcgen_smooth_adaptive>;
template <typename Geometry>
template<typename Geometry>
class smooth_converter
{
Geometry geom_;
@ -81,9 +76,9 @@ class smooth_converter
using impl_type = util::variant<basic_impl_type, adaptive_impl_type>;
impl_type impl_;
impl_type init_impl(smooth_algorithm_enum algo, Geometry & geom) const
impl_type init_impl(smooth_algorithm_enum algo, Geometry& geom) const
{
switch(algo)
switch (algo)
{
case SMOOTH_ALGORITHM_ADAPTIVE:
return adaptive_impl_type(geom);
@ -94,46 +89,35 @@ class smooth_converter
return basic_impl_type(geom);
}
public:
smooth_converter(Geometry & geom) :
geom_(geom),
impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
public:
smooth_converter(Geometry& geom)
: geom_(geom)
, impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
{}
void algorithm(smooth_algorithm_enum algo)
{
impl_ = init_impl(algo, geom_);
}
void algorithm(smooth_algorithm_enum algo) { impl_ = init_impl(algo, geom_); }
void smooth_value(double v)
{
return util::apply_visitor([=](auto & impl) {
impl.smooth_value(v);
}, impl_);
return util::apply_visitor([=](auto& impl) { impl.smooth_value(v); }, impl_);
}
void rewind(unsigned path_id)
{
return util::apply_visitor([=](auto & impl) {
return impl.rewind(path_id);
}, impl_);
return util::apply_visitor([=](auto& impl) { return impl.rewind(path_id); }, impl_);
}
unsigned vertex(double* x, double* y)
{
return util::apply_visitor([=](auto & impl) {
return impl.vertex(x, y);
}, impl_);
return util::apply_visitor([=](auto& impl) { return impl.vertex(x, y); }, impl_);
}
unsigned type() const
{
return util::apply_visitor([](auto const& impl) {
return impl.type();
}, impl_);
return util::apply_visitor([](auto const& impl) { return impl.type(); }, impl_);
}
};
}
} // namespace mapnik
#endif // MAPNIK_ADAPTIVE_SMOOTH_HPP

View file

@ -69,7 +69,7 @@ struct agg_pattern_base
}
};
template <typename VertexConverter>
template<typename VertexConverter>
struct agg_polygon_pattern : agg_pattern_base
{
using color_type = agg::rgba8;
@ -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 wrap_x_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,
wrap_x_type,
wrap_y_type>;
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre, wrap_x_type, wrap_y_type>;
using span_gen_type = agg::span_pattern_rgba<img_source_type>;
using renderer_base = agg::renderer_base<pixfmt_type>;
using renderer_type = agg::renderer_scanline_aa_alpha<renderer_base,
agg::span_allocator<agg::rgba8>,
span_gen_type>;
using renderer_type =
agg::renderer_scanline_aa_alpha<renderer_base, agg::span_allocator<agg::rgba8>, span_gen_type>;
agg_polygon_pattern(image_rgba8 const& pattern_img,
renderer_common const& common,
symbolizer_base const& sym,
mapnik::feature_impl const& feature,
proj_transform const& prj_trans)
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans},
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
clip_box_(clipping_extent(common)),
tr_(geom_transform()),
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
feature, common.vars_, common.scale_factor_)
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans}
, clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
, clip_box_(clipping_extent(common))
, tr_(geom_transform())
, converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
{
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_);
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>();
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_,
pattern_img_.width(), pattern_img_.height()));
coord<double, 2> offset(
pattern_offset(sym_, feature_, prj_trans_, common_, pattern_img_.width(), pattern_img_.height()));
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);
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
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_);
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
using apply_vertex_converter_type = detail::apply_vertex_converter<
VertexConverter, rasterizer>;
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, rasterizer>;
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
apply_vertex_converter_type apply(converter_, ras);
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
@ -139,5 +137,4 @@ struct agg_polygon_pattern : agg_pattern_base
} // namespace mapnik
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP

View file

@ -34,31 +34,31 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
template <typename T>
void set_gamma_method(T & ras_ptr, double gamma, gamma_method_enum method)
template<typename T>
void set_gamma_method(T& ras_ptr, double gamma, gamma_method_enum method)
{
switch (method)
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(gamma));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, gamma));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(gamma));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(gamma));
break;
default:
ras_ptr->gamma(agg::gamma_power(gamma));
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(gamma));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, gamma));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(gamma));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(gamma));
break;
default:
ras_ptr->gamma(agg::gamma_power(gamma));
}
}
}
} // namespace mapnik
#endif // MAPNIK_AGG_HELPERS_HPP

View file

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

View file

@ -26,7 +26,6 @@
// mapnik
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore_agg.hpp>
@ -35,8 +34,10 @@ MAPNIK_DISABLE_WARNING_POP
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

View file

@ -52,10 +52,14 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
template <typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, RendererBaseType & renb,
box2d<double> const& bbox, agg::trans_affine const& tr,
double opacity, bool snap_to_pixels)
template<typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
void render_vector_marker(SvgRenderer& svg_renderer,
RasterizerType& ras,
RendererBaseType& renb,
box2d<double> const& bbox,
agg::trans_affine const& tr,
double opacity,
bool snap_to_pixels)
{
agg::scanline_u8 sl;
if (snap_to_pixels)
@ -72,23 +76,25 @@ void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, Rend
}
}
template <typename RendererType, typename RasterizerType>
void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 const& src,
agg::trans_affine const& tr, double opacity,
float scale_factor, bool snap_to_pixels)
template<typename RendererType, typename RasterizerType>
void render_raster_marker(RendererType renb,
RasterizerType& ras,
image_rgba8 const& src,
agg::trans_affine const& tr,
double opacity,
float scale_factor,
bool snap_to_pixels)
{
using color_type = agg::rgba8;
using const_rendering_buffer = util::rendering_buffer<image_rgba8>;
using pixfmt_pre = agg::pixfmt_alpha_blend_rgba<agg::blender_rgba32_pre, const_rendering_buffer, agg::pixel32_type>;
agg::scanline_u8 sl;
double width = src.width();
double width = src.width();
double height = src.height();
if (std::fabs(1.0 - scale_factor) < 0.001
&& (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(1.0 - tr.sy) < agg::affine_epsilon))
if (std::fabs(1.0 - scale_factor) < 0.001 && (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(1.0 - tr.sy) < agg::affine_epsilon))
{
const_rendering_buffer src_buffer(src);
pixfmt_pre pixf_mask(src_buffer);
@ -98,32 +104,31 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
0,
static_cast<int>(std::floor(tr.tx + .5)),
static_cast<int>(std::floor(tr.ty + .5)),
unsigned(255*opacity));
unsigned(255 * opacity));
}
else
{
renb.blend_from(pixf_mask,
0,
static_cast<int>(tr.tx),
static_cast<int>(tr.ty),
unsigned(255*opacity));
renb.blend_from(pixf_mask, 0, static_cast<int>(tr.tx), static_cast<int>(tr.ty), unsigned(255 * opacity));
}
}
else
{
using img_accessor_type = agg::image_accessor_clone<pixfmt_pre>;
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 renderer_type = agg::renderer_scanline_aa_alpha<RendererType,
agg::span_allocator<color_type>,
span_gen_type>;
using renderer_type =
agg::renderer_scanline_aa_alpha<RendererType, agg::span_allocator<color_type>, span_gen_type>;
double p[8];
p[0] = 0; p[1] = 0;
p[2] = width; p[3] = 0;
p[4] = width; p[5] = height;
p[6] = 0; p[7] = height;
p[0] = 0;
p[1] = 0;
p[2] = width;
p[3] = 0;
p[4] = width;
p[5] = height;
p[6] = 0;
p[7] = height;
tr.transform(&p[0], &p[1]);
tr.transform(&p[2], &p[3]);
tr.transform(&p[4], &p[5]);
@ -137,20 +142,20 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
agg::trans_affine final_tr(p, 0, 0, width, height);
if (snap_to_pixels)
{
final_tr.tx = std::floor(final_tr.tx+.5);
final_tr.ty = std::floor(final_tr.ty+.5);
final_tr.tx = std::floor(final_tr.tx + .5);
final_tr.ty = std::floor(final_tr.ty + .5);
}
interpolator_type interpolator(final_tr);
span_gen_type sg(ia, interpolator, filter);
renderer_type rp(renb, sa, sg, unsigned(opacity*255));
ras.move_to_d(p[0],p[1]);
ras.line_to_d(p[2],p[3]);
ras.line_to_d(p[4],p[5]);
ras.line_to_d(p[6],p[7]);
renderer_type rp(renb, sa, sg, unsigned(opacity * 255));
ras.move_to_d(p[0], p[1]);
ras.line_to_d(p[2], p[3]);
ras.line_to_d(p[4], p[5]);
ras.line_to_d(p[6], p[7]);
agg::render_scanlines(ras, sl, rp);
}
}
}
} // namespace mapnik
#endif // MAPNIK_AGG_RENDER_MARKER_HPP

View file

@ -24,13 +24,13 @@
#define MAPNIK_AGG_RENDERER_HPP
// mapnik
#include <mapnik/config.hpp> // for MAPNIK_DECL
#include <mapnik/config.hpp> // for MAPNIK_DECL
#include <mapnik/feature_style_processor.hpp>
#include <mapnik/util/noncopyable.hpp> // for noncopyable
#include <mapnik/util/noncopyable.hpp> // for noncopyable
#include <mapnik/rule.hpp> // for rule, symbolizers
#include <mapnik/geometry/box2d.hpp> // for box2d
#include <mapnik/geometry/box2d.hpp> // for box2d
#include <mapnik/view_transform.hpp> // for view_transform
#include <mapnik/image_compositing.hpp> // for composite_mode_e
#include <mapnik/image_compositing.hpp> // for composite_mode_e
#include <mapnik/pixel_position.hpp>
#include <mapnik/request.hpp>
#include <mapnik/symbolizer_enumerations.hpp>
@ -41,38 +41,40 @@
#include <stack>
// fwd declaration to avoid dependence on agg headers
namespace agg { struct trans_affine; }
namespace agg {
struct trans_affine;
}
// fwd declarations to speed up compile
namespace mapnik {
class Map;
class feature_impl;
class feature_type_style;
class label_collision_detector4;
class layer;
class color;
struct marker;
class proj_transform;
struct rasterizer;
struct rgba8_t;
template<typename T> class image;
}
class Map;
class feature_impl;
class feature_type_style;
class label_collision_detector4;
class layer;
class color;
struct marker;
class proj_transform;
struct rasterizer;
struct rgba8_t;
template<typename T>
class image;
} // namespace mapnik
namespace mapnik {
template <typename T>
template<typename T>
class buffer_stack
{
public:
public:
buffer_stack(std::size_t width, std::size_t height)
: width_(width),
height_(height),
buffers_(),
position_(buffers_.begin())
{
}
: width_(width)
, height_(height)
, buffers_()
, position_(buffers_.begin())
{}
T & push()
T& push()
{
if (position_ == buffers_.begin())
{
@ -86,10 +88,7 @@ public:
}
return *position_;
}
bool in_range() const
{
return (position_ != buffers_.end());
}
bool in_range() const { return (position_ != buffers_.end()); }
void pop()
{
@ -98,34 +97,44 @@ public:
++position_;
}
T & top() const
{
return *position_;
}
T& top() const { return *position_; }
private:
private:
const std::size_t width_;
const std::size_t height_;
std::deque<T> buffers_;
typename std::deque<T>::iterator position_;
};
template <typename T0, typename T1=label_collision_detector4>
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0> >,
template<typename T0, typename T1 = label_collision_detector4>
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>>,
private util::noncopyable
{
public:
public:
using buffer_type = T0;
using processor_impl_type = agg_renderer<T0>;
using detector_type = T1;
// 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
agg_renderer(Map const &m, buffer_type & pixmap, std::shared_ptr<detector_type> detector,
double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
agg_renderer(Map const& m,
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
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();
void start_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 end_style_processing(feature_type_style const& st);
void render_marker(pixel_position const& pos, marker const& marker, agg::trans_affine const& tr,
double opacity, composite_mode_e comp_op);
void render_marker(pixel_position const& pos,
marker const& marker,
agg::trans_affine const& tr,
double opacity,
composite_mode_e comp_op);
void process(point_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(line_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(polygon_pattern_symbolizer const& sym,
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);
void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_pattern_symbolizer const& sym, 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&,
mapnik::feature_impl&,
proj_transform const& )
inline bool process(rule::symbolizers const&, mapnik::feature_impl&, proj_transform const&)
{
// agg renderer doesn't support processing of multiple symbolizers.
return false;
@ -189,29 +173,19 @@ public:
void painted(bool painted);
bool painted();
inline eAttributeCollectionPolicy attribute_collection_policy() const
{
return DEFAULT;
}
inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
inline double scale_factor() const
{
return common_.scale_factor_;
}
inline double scale_factor() const { return common_.scale_factor_; }
inline attributes const& variables() const
{
return common_.vars_;
}
protected:
template <typename R>
void debug_draw_box(R& buf, 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);
inline attributes const& variables() const { return common_.vars_; }
private:
protected:
template<typename R>
void debug_draw_box(R& buf, 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);
private:
std::stack<std::reference_wrapper<buffer_type>> buffers_;
buffer_stack<buffer_type> internal_buffers_;
std::unique_ptr<buffer_type> inflated_buffer_;
@ -219,7 +193,7 @@ private:
gamma_method_enum gamma_method_;
double gamma_;
renderer_common common_;
void setup(Map const & m, buffer_type & pixmap);
void setup(Map const& m, buffer_type& pixmap);
};
extern template class MAPNIK_DECL agg_renderer<image<rgba8_t>>;

View file

@ -37,20 +37,21 @@ struct attribute
{
std::string 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
{
return f.get(name_);
}
std::string const& name() const { return name_;}
std::string const& name() const { return name_; }
};
struct geometry_type_attribute
{
template <typename V, typename F>
template<typename V, typename F>
V value(F const& f) const
{
return static_cast<mapnik::value_integer>(util::to_ds_type(f.get_geometry()));
@ -61,10 +62,11 @@ struct global_attribute
{
std::string name;
explicit global_attribute(std::string const& name_)
: name(name_) {}
: name(name_)
{}
template <typename V, typename C>
V const& operator() (C const& ctx)
template<typename V, typename C>
V const& operator()(C const& ctx)
{
return ctx.get(name);
}
@ -72,6 +74,6 @@ struct global_attribute
using attributes = std::unordered_map<std::string, value>;
}
} // namespace mapnik
#endif // MAPNIK_ATTRIBUTE_HPP

View file

@ -28,11 +28,11 @@
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/attribute.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/expression.hpp> // for expression_ptr, etc
#include <mapnik/expression.hpp> // for expression_ptr, etc
#include <mapnik/expression_node.hpp>
#include <mapnik/parse_path.hpp> // for path_processor_type
#include <mapnik/path_expression.hpp> // for path_expression_ptr
#include <mapnik/text/placements/base.hpp> // for text_placements
#include <mapnik/parse_path.hpp> // for path_processor_type
#include <mapnik/path_expression.hpp> // for path_expression_ptr
#include <mapnik/text/placements/base.hpp> // for text_placements
#include <mapnik/image_scaling.hpp>
#include <mapnik/group/group_symbolizer_properties.hpp>
#include <mapnik/group/group_rule.hpp>
@ -51,76 +51,71 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
template <typename Container>
template<typename Container>
struct expression_attributes
{
explicit expression_attributes(Container& names)
: names_(names) {}
: names_(names)
{}
void operator() (attribute const& attr) const
{
names_.emplace(attr.name());
}
void operator()(attribute const& attr) const { names_.emplace(attr.name()); }
template <typename Tag>
void operator() (binary_node<Tag> const& x) const
template<typename Tag>
void operator()(binary_node<Tag> const& x) const
{
util::apply_visitor(*this, x.left);
util::apply_visitor(*this, x.right);
}
template <typename Tag>
void operator() (unary_node<Tag> const& x) const
template<typename Tag>
void operator()(unary_node<Tag> const& x) const
{
util::apply_visitor(*this, x.expr);
}
void operator() (regex_match_node const& x) const
{
util::apply_visitor(*this, x.expr);
}
void operator()(regex_match_node const& x) const { util::apply_visitor(*this, x.expr); }
void operator() (regex_replace_node const& x) const
{
util::apply_visitor(*this, x.expr);
}
void operator()(regex_replace_node const& x) const { util::apply_visitor(*this, x.expr); }
template <typename T>
void operator() (T const&) const {}
template<typename T>
void operator()(T const&) const
{}
private:
private:
Container& names_;
};
class group_attribute_collector : public util::noncopyable
{
private:
private:
std::set<std::string>& names_;
bool expand_index_columns_;
public:
group_attribute_collector(std::set<std::string>& names,
bool expand_index_columns)
: names_(names),
expand_index_columns_(expand_index_columns) {}
void operator() (group_symbolizer const& sym);
public:
group_attribute_collector(std::set<std::string>& names, bool expand_index_columns)
: names_(names)
, expand_index_columns_(expand_index_columns)
{}
void operator()(group_symbolizer const& sym);
};
template <typename Container>
template<typename Container>
struct extract_attribute_names
{
explicit extract_attribute_names(Container& names)
: names_(names),
f_attr_(names) {}
: names_(names)
, f_attr_(names)
{}
void operator() (mapnik::expression_ptr const& expr) const
void operator()(mapnik::expression_ptr const& expr) const
{
if (expr)
{
util::apply_visitor(f_attr_, *expr);
}
}
void operator() (mapnik::transform_type const& expr) const
void operator()(mapnik::transform_type const& expr) const
{
if (expr)
{
@ -128,7 +123,7 @@ struct extract_attribute_names
}
}
void operator() (mapnik::text_placements_ptr const& expr) const
void operator()(mapnik::text_placements_ptr const& expr) const
{
if (expr)
{
@ -136,39 +131,41 @@ struct extract_attribute_names
expression_set expressions;
// TODO - optimize (dane)
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);
}
}
}
void operator() (mapnik::path_expression_ptr const& expr) const
void operator()(mapnik::path_expression_ptr const& expr) const
{
if (expr)
{
path_processor_type::collect_attributes(*expr,names_);
path_processor_type::collect_attributes(*expr, names_);
}
}
template <typename T>
void operator() (T const&) const {}
template<typename T>
void operator()(T const&) const
{}
private:
private:
Container& names_;
expression_attributes<std::set<std::string> > f_attr_;
expression_attributes<std::set<std::string>> f_attr_;
};
struct symbolizer_attributes
{
symbolizer_attributes(std::set<std::string>& names,
double & filter_factor)
: filter_factor_(filter_factor),
f_attrs_(names),
g_attrs_(names, true) {}
symbolizer_attributes(std::set<std::string>& names, double& filter_factor)
: filter_factor_(filter_factor)
, f_attrs_(names)
, g_attrs_(names, true)
{}
template <typename T>
void operator () (T const& sym)
template<typename T>
void operator()(T const& sym)
{
for (auto const& prop : sym.properties)
{
@ -176,7 +173,7 @@ struct symbolizer_attributes
}
}
void operator () (raster_symbolizer const& sym)
void operator()(raster_symbolizer const& sym)
{
boost::optional<double> filter_factor = get_optional<double>(sym, keys::filter_factor);
if (filter_factor)
@ -197,57 +194,51 @@ struct symbolizer_attributes
}
}
void operator () (group_symbolizer const& sym)
{
g_attrs_(sym);
}
void operator()(group_symbolizer const& sym) { g_attrs_(sym); }
private:
double & filter_factor_;
extract_attribute_names<std::set<std::string> > f_attrs_;
private:
double& filter_factor_;
extract_attribute_names<std::set<std::string>> f_attrs_;
group_attribute_collector g_attrs_;
};
class attribute_collector : public util::noncopyable
{
private:
std::set<std::string> & names_;
private:
std::set<std::string>& names_;
double filter_factor_;
expression_attributes<std::set<std::string> > f_attr;
public:
expression_attributes<std::set<std::string>> f_attr;
public:
attribute_collector(std::set<std::string>& names)
: names_(names),
filter_factor_(1.0),
f_attr(names) {}
template <typename RuleType>
void operator() (RuleType const& r)
: names_(names)
, filter_factor_(1.0)
, f_attr(names)
{}
template<typename RuleType>
void operator()(RuleType const& r)
{
typename RuleType::symbolizers const& symbols = r.get_symbolizers();
symbolizer_attributes s_attr(names_,filter_factor_);
symbolizer_attributes s_attr(names_, filter_factor_);
for (auto const& sym : symbols)
{
util::apply_visitor(std::ref(s_attr), sym);
}
expression_ptr const& expr = r.get_filter();
util::apply_visitor(f_attr,*expr);
util::apply_visitor(f_attr, *expr);
}
double get_filter_factor() const
{
return filter_factor_;
}
double get_filter_factor() const { 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
std::set<std::string> group_columns;
attribute_collector column_collector(group_columns);
expression_attributes<std::set<std::string> > rk_attr(group_columns);
expression_attributes<std::set<std::string>> rk_attr(group_columns);
// get columns from symbolizer repeat key
expression_ptr repeat_key = get<mapnik::expression_ptr>(sym, keys::repeat_key);
@ -289,7 +280,7 @@ inline void group_attribute_collector::operator() (group_symbolizer const& sym)
for (value_integer col_idx = start; col_idx < end; ++col_idx)
{
std::string col_idx_str;
if (mapnik::util::to_string(col_idx_str,col_idx))
if (mapnik::util::to_string(col_idx_str, col_idx))
{
std::string col_idx_name = col_name;
boost::replace_all(col_idx_name, "%", col_idx_str);

View file

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

View file

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

View file

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

View file

@ -20,7 +20,6 @@
*
*****************************************************************************/
#ifndef MAPNIK_CAIRO_CONTEXT_HPP
#define MAPNIK_CAIRO_CONTEXT_HPP
@ -57,7 +56,8 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
template <typename T> class box2d;
template<typename T>
class box2d;
using ErrorStatus = cairo_status_t;
@ -67,10 +67,10 @@ inline void throw_exception(ErrorStatus status)
throw std::runtime_error(std::string("cairo: ") + cairo_status_to_string(status));
}
//We inline this because it is called so often.
// We inline this because it is called so often.
inline void check_status_and_throw_exception(ErrorStatus status)
{
if(status != CAIRO_STATUS_SUCCESS)
if (status != CAIRO_STATUS_SUCCESS)
throw_exception(status);
}
@ -82,60 +82,65 @@ void check_object_status_and_throw_exception(T const& object)
class cairo_face : private util::noncopyable
{
public:
public:
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
~cairo_face();
cairo_font_face_t * face() const;
private:
cairo_font_face_t* face() const;
private:
class handle
{
public:
public:
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_;
face_ptr face_;
};
static void destroy(void *data)
static void destroy(void* data)
{
handle *h = static_cast<handle *>(data);
handle* h = static_cast<handle*>(data);
delete h;
}
private:
private:
face_ptr face_;
cairo_font_face_t *c_face_;
cairo_font_face_t* c_face_;
};
using cairo_face_ptr = std::shared_ptr<cairo_face>;
class cairo_face_manager : private util::noncopyable
{
public:
public:
cairo_face_manager(std::shared_ptr<font_library> library);
cairo_face_ptr get_face(face_ptr face);
private:
using cairo_face_cache = std::map<face_ptr,cairo_face_ptr>;
private:
using cairo_face_cache = std::map<face_ptr, cairo_face_ptr>;
std::shared_ptr<font_library> font_library_;
cairo_face_cache cache_;
};
struct cairo_closer
{
void operator() (cairo_t * obj)
void operator()(cairo_t* obj)
{
if (obj) cairo_destroy(obj);
if (obj)
cairo_destroy(obj);
}
};
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);
}
};
@ -144,28 +149,25 @@ using cairo_surface_ptr = std::shared_ptr<cairo_surface_t>;
inline cairo_ptr create_context(cairo_surface_ptr const& surface)
{
return cairo_ptr(cairo_create(&*surface),cairo_closer());
return cairo_ptr(cairo_create(&*surface), cairo_closer());
}
class cairo_pattern : private util::noncopyable
{
public:
public:
explicit cairo_pattern(image_rgba8 const& data, double opacity = 1.0)
{
std::size_t pixels = data.width() * data.height();
const unsigned int *in_ptr = data.data();
const unsigned int *in_end = in_ptr + pixels;
unsigned int *out_ptr;
const unsigned int* in_ptr = data.data();
const unsigned int* in_end = in_ptr + pixels;
unsigned int* out_ptr;
surface_ = cairo_surface_ptr(
cairo_image_surface_create(
CAIRO_FORMAT_ARGB32,
static_cast<int>(data.width()),
static_cast<int>(data.height())),
cairo_surface_closer());
surface_ = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
static_cast<int>(data.width()),
static_cast<int>(data.height())),
cairo_surface_closer());
out_ptr = reinterpret_cast<unsigned int *>(
cairo_image_surface_get_data(surface_.get()));
out_ptr = reinterpret_cast<unsigned int*>(cairo_image_surface_get_data(surface_.get()));
while (in_ptr < in_end)
{
@ -175,9 +177,9 @@ public:
unsigned int b = static_cast<unsigned>(((in >> 16) & 0xff) * opacity);
unsigned int a = static_cast<unsigned>(((in >> 24) & 0xff) * opacity);
//r = r * a / 255;
//g = g * a / 255;
//b = b * a / 255;
// r = r * a / 255;
// g = g * a / 255;
// b = b * a / 255;
*out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b;
}
@ -186,78 +188,65 @@ public:
pattern_ = cairo_pattern_create_for_surface(surface_.get());
}
cairo_pattern(cairo_surface_ptr const& surface) :
surface_(surface),
pattern_(cairo_pattern_create_for_surface(surface_.get()))
{
}
cairo_pattern(cairo_surface_ptr const& surface)
: surface_(surface)
, pattern_(cairo_pattern_create_for_surface(surface_.get()))
{}
~cairo_pattern()
{
if (pattern_) cairo_pattern_destroy(pattern_);
if (pattern_)
cairo_pattern_destroy(pattern_);
}
void set_matrix(cairo_matrix_t const& matrix)
{
cairo_pattern_set_matrix(pattern_, &matrix);
}
void set_matrix(cairo_matrix_t const& matrix) { cairo_pattern_set_matrix(pattern_, &matrix); }
void set_origin(double x, double y)
{
cairo_matrix_t matrix;
cairo_pattern_get_matrix(pattern_,&matrix);
cairo_pattern_get_matrix(pattern_, &matrix);
matrix.x0 = -x;
matrix.y0 = -y;
cairo_pattern_set_matrix(pattern_,&matrix);
cairo_pattern_set_matrix(pattern_, &matrix);
}
void set_extend(cairo_extend_t extend)
{
cairo_pattern_set_extend(pattern_, extend);
}
void set_extend(cairo_extend_t extend) { cairo_pattern_set_extend(pattern_, extend); }
void set_filter(cairo_filter_t filter)
{
cairo_pattern_set_filter(pattern_, filter);
}
void set_filter(cairo_filter_t filter) { cairo_pattern_set_filter(pattern_, filter); }
cairo_pattern_t * pattern() const
{
return pattern_;
}
cairo_pattern_t* pattern() const { return pattern_; }
private:
private:
cairo_surface_ptr surface_;
cairo_pattern_t * pattern_;
cairo_pattern_t* pattern_;
};
class cairo_gradient : private util::noncopyable
{
public:
cairo_gradient(mapnik::gradient const& grad, double opacity=1.0)
public:
cairo_gradient(mapnik::gradient const& grad, double opacity = 1.0)
{
double x1,x2,y1,y2,rad;
grad.get_control_points(x1,y1,x2,y2,rad);
double x1, x2, y1, y2, rad;
grad.get_control_points(x1, y1, x2, y2, rad);
if (grad.get_gradient_type() == LINEAR)
{
pattern_ = cairo_pattern_create_linear(x1, y1, x2, y2);
}
else
{
pattern_ = cairo_pattern_create_radial(x1, y1, 0, x2, y2, rad);
pattern_ = cairo_pattern_create_radial(x1, y1, 0, x2, y2, rad);
}
units_ = grad.get_units();
for ( mapnik::stop_pair const& st : grad.get_stop_array() )
for (mapnik::stop_pair const& st : grad.get_stop_array())
{
mapnik::color const& stop_color = st.second;
double r= static_cast<double> (stop_color.red())/255.0;
double g= static_cast<double> (stop_color.green())/255.0;
double b= static_cast<double> (stop_color.blue())/255.0;
double a= static_cast<double> (stop_color.alpha())/255.0;
cairo_pattern_add_color_stop_rgba(pattern_,st.first, r, g, b, a*opacity);
double r = static_cast<double>(stop_color.red()) / 255.0;
double g = static_cast<double>(stop_color.green()) / 255.0;
double b = static_cast<double>(stop_color.blue()) / 255.0;
double a = static_cast<double>(stop_color.alpha()) / 255.0;
cairo_pattern_add_color_stop_rgba(pattern_, st.first, r, g, b, a * opacity);
}
double m[6];
@ -265,7 +254,7 @@ public:
tr.invert();
tr.store_to(m);
cairo_matrix_t matrix;
cairo_matrix_init(&matrix,m[0],m[1],m[2],m[3],m[4],m[5]);
cairo_matrix_init(&matrix, m[0], m[1], m[2], m[3], m[4], m[5]);
cairo_pattern_set_matrix(pattern_, &matrix);
}
@ -275,43 +264,32 @@ public:
cairo_pattern_destroy(pattern_);
}
cairo_pattern_t* gradient() const { return pattern_; }
cairo_pattern_t * gradient() const
{
return pattern_;
}
gradient_unit_e units() const { return units_; }
gradient_unit_e units() const
{
return units_;
}
private:
cairo_pattern_t * pattern_;
private:
cairo_pattern_t* pattern_;
gradient_unit_e units_;
};
class cairo_context : private util::noncopyable
{
public:
public:
cairo_context(cairo_ptr const& cairo);
inline ErrorStatus get_status() const
{
return cairo_status(cairo_.get());
}
inline ErrorStatus get_status() const { return cairo_status(cairo_.get()); }
void clip();
void show_page();
void set_color(color const &color, double opacity = 1.0);
void set_color(color const& color, double opacity = 1.0);
void set_color(double r, double g, double b, double opacity = 1.0);
void set_operator(composite_mode_e comp_op);
void set_line_join(line_join_e join);
void set_line_cap(line_cap_e cap);
void set_miter_limit(double limit);
void set_line_width(double width);
void set_dash(dash_array const &dashes, double scale_factor);
void set_dash(dash_array const& dashes, double scale_factor);
void set_fill_rule(cairo_fill_rule_t fill_rule);
void move_to(double x, double y);
void curve_to(double ct1_x, double ct1_y, double ct2_x, double ct2_y, double end_x, double end_y);
@ -326,7 +304,7 @@ public:
void set_gradient(cairo_gradient const& pattern, box2d<double> const& bbox);
void add_image(double x, double y, image_rgba8 const& data, double opacity = 1.0);
void add_image(agg::trans_affine const& tr, image_rgba8 const& data, double opacity = 1.0);
void set_font_face(cairo_face_manager & manager, face_ptr face);
void set_font_face(cairo_face_manager& manager, face_ptr face);
void set_font_matrix(cairo_matrix_t const& matrix);
void set_matrix(cairo_matrix_t const& matrix);
void transform(cairo_matrix_t const& matrix);
@ -336,7 +314,7 @@ public:
void show_glyph(unsigned long index, pixel_position const& pos);
void glyph_path(unsigned long index, pixel_position const& pos);
void add_text(glyph_positions const& pos,
cairo_face_manager & manager,
cairo_face_manager& manager,
composite_mode_e comp_op = src_over,
composite_mode_e halo_comp_op = src_over,
double scale_factor = 1.0);
@ -344,7 +322,7 @@ public:
void push_group();
void pop_group();
template <typename T>
template<typename T>
void add_path(T& path, unsigned start_index = 0)
{
double x, y;
@ -366,11 +344,11 @@ public:
}
}
template <typename T>
template<typename T>
void add_agg_path(T& path, unsigned start_index = 0)
{
double x=0;
double y=0;
double x = 0;
double y = 0;
path.rewind(start_index);
@ -384,26 +362,26 @@ public:
{
if (agg::is_curve3(cm))
{
double end_x=0;
double end_y=0;
double end_x = 0;
double end_y = 0;
MAPNIK_LOG_WARN(cairo_renderer) << "Curve 3 not implemented";
path.vertex(&end_x, &end_y);
curve_to(x,y,x,y,end_x,end_y);
curve_to(x, y, x, y, end_x, end_y);
}
else if (agg::is_curve4(cm))
{
double ct2_x=0;
double ct2_y=0;
double end_x=0;
double end_y=0;
double ct2_x = 0;
double ct2_y = 0;
double end_x = 0;
double end_y = 0;
path.vertex(&ct2_x, &ct2_y);
path.vertex(&end_x, &end_y);
curve_to(x,y,ct2_x,ct2_y,end_x,end_y);
curve_to(x, y, ct2_x, ct2_y, end_x, end_y);
}
else if (agg::is_line_to(cm))
{
@ -426,21 +404,22 @@ public:
}
}
private:
private:
cairo_ptr cairo_;
};
template <typename Context>
template<typename Context>
struct line_pattern_rasterizer
{
line_pattern_rasterizer(Context & context, cairo_pattern & pattern, unsigned width, unsigned height)
: context_(context),
pattern_(pattern),
width_(width),
height_(height) {}
line_pattern_rasterizer(Context& context, cairo_pattern& pattern, unsigned width, unsigned height)
: context_(context)
, pattern_(pattern)
, width_(width)
, height_(height)
{}
template <typename T>
void add_path(T & path, unsigned start_index = 0)
template<typename T>
void add_path(T& path, unsigned start_index = 0)
{
double length = 0.0;
double x0 = 0.0;
@ -479,13 +458,12 @@ struct line_pattern_rasterizer
}
}
Context & context_;
cairo_pattern & pattern_;
Context& context_;
cairo_pattern& pattern_;
unsigned width_;
unsigned height_;
};
}
} // namespace mapnik
#endif // MAPNIK_CAIRO_CONTEXT_HPP

View file

@ -20,7 +20,6 @@
*
*****************************************************************************/
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP
@ -33,8 +32,7 @@
namespace mapnik {
static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
cairo_surface_ptr const& surface)
static inline void cairo_image_to_rgba8(mapnik::image_rgba8& data, cairo_surface_ptr const& surface)
{
if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
{
@ -50,7 +48,7 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
int stride = cairo_image_surface_get_stride(&*surface) / 4;
const std::unique_ptr<unsigned int[]> out_row(new unsigned int[data.width()]);
const unsigned int *in_row = (const unsigned int *)cairo_image_surface_get_data(&*surface);
const unsigned int* in_row = (const unsigned int*)cairo_image_surface_get_data(&*surface);
for (unsigned int row = 0; row < data.height(); row++, in_row += stride)
{
@ -62,11 +60,16 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
unsigned int g = (in >> 8) & 0xff;
unsigned int b = (in >> 0) & 0xff;
#define DE_ALPHA(x) do { \
if (a == 0) x = 0; \
else x = x * 255 / a; \
if (x > 255) x = 255; \
} while(0)
#define DE_ALPHA(x) \
do \
{ \
if (a == 0) \
x = 0; \
else \
x = x * 255 / a; \
if (x > 255) \
x = 255; \
} while (0)
DE_ALPHA(r);
DE_ALPHA(g);
@ -78,7 +81,6 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
}
}
}
} // namespace mapnik
#endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP

View file

@ -32,12 +32,14 @@ namespace mapnik {
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,
box2d<double> const& bbox, agg::trans_affine const& tr,
box2d<double> const& bbox,
agg::trans_affine const& tr,
double opacity);
}
} // namespace mapnik
#endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP

View file

@ -53,42 +53,35 @@ class request;
struct pixel_position;
struct cairo_save_restore
{
cairo_save_restore(cairo_context & context)
cairo_save_restore(cairo_context& context)
: context_(context)
{
context_.save();
}
~cairo_save_restore()
{
context_.restore();
}
cairo_context & context_;
~cairo_save_restore() { context_.restore(); }
cairo_context& context_;
};
template <typename T>
class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer<T> >,
template<typename T>
class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer<T>>,
private util::noncopyable
{
public:
public:
using processor_impl_type = cairo_renderer<T>;
cairo_renderer(Map const& m,
T const& obj,
double scale_factor=1.0,
unsigned offset_x=0,
unsigned offset_y=0);
cairo_renderer(Map const& m, T const& obj, double scale_factor = 1.0, unsigned offset_x = 0, unsigned offset_y = 0);
cairo_renderer(Map const& m,
request const& req,
attributes const& vars,
T const& obj,
double scale_factor=1.0,
unsigned offset_x=0,
unsigned offset_y=0);
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
cairo_renderer(Map const& m,
T const& obj,
std::shared_ptr<label_collision_detector4> detector,
double scale_factor=1.0,
unsigned offset_x=0,
unsigned offset_y=0);
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
~cairo_renderer();
void start_map_processing(Map const& map);
@ -97,93 +90,56 @@ public:
void end_layer_processing(layer const& lay);
void start_style_processing(feature_type_style const& st);
void end_style_processing(feature_type_style const& st);
void process(point_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(line_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(polygon_pattern_symbolizer const& sym,
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,
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*/)
void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_pattern_symbolizer const& sym, 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, 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.
return false;
}
bool painted()
{
return true;
}
bool painted() { return true; }
void painted(bool /*painted*/)
{
// nothing to do
}
inline eAttributeCollectionPolicy attribute_collection_policy() const
{
return DEFAULT;
}
inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
inline double scale_factor() const
{
return common_.scale_factor_;
}
inline double scale_factor() const { return common_.scale_factor_; }
inline attributes const& variables() const
{
return common_.vars_;
}
inline attributes const& variables() const { return common_.vars_; }
void render_marker(pixel_position const& pos,
marker const& marker,
agg::trans_affine const& mtx,
double opacity=1.0,
bool recenter=true);
protected:
double opacity = 1.0,
bool recenter = true);
protected:
Map const& m_;
cairo_context context_;
renderer_common common_;
cairo_face_manager face_manager_;
bool style_level_compositing_;
void setup(Map const& m);
};
extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>;
}
} // namespace mapnik
#endif // MAPNIK_CAIRO_RENDERER_HPP

View file

@ -36,36 +36,31 @@ namespace mapnik {
struct cairo_renderer_process_visitor_p
{
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr,
double opacity)
: image_tr_(image_tr),
opacity_(opacity)
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr, double opacity)
: image_tr_(image_tr)
, opacity_(opacity)
{}
cairo_surface_ptr operator()(marker_svg const & marker) const
cairo_surface_ptr operator()(marker_svg const& marker) const
{
box2d<double> bbox(marker.bounding_box());
agg::trans_affine tr(transform(bbox));
double width = std::max(1.0, std::round(bbox.width()));
double height = std::max(1.0, std::round(bbox.height()));
cairo_rectangle_t extent { 0, 0, width, height };
cairo_surface_ptr surface(
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_surface_closer());
cairo_rectangle_t extent{0, 0, width, height};
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_surface_closer());
cairo_ptr cairo = create_context(surface);
cairo_context context(cairo);
svg_storage_type & svg = *marker.get_data();
svg_storage_type& svg = *marker.get_data();
svg_attribute_type const& svg_attributes = svg.attributes();
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(
svg.source());
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(svg.source());
svg::svg_path_adapter svg_path(stl_storage);
render_vector_marker(context, svg_path, svg_attributes,
bbox, tr, opacity_);
render_vector_marker(context, svg_path, svg_attributes, bbox, tr, opacity_);
return surface;
}
@ -75,11 +70,9 @@ struct cairo_renderer_process_visitor_p
box2d<double> bbox(marker.bounding_box());
agg::trans_affine tr(transform(bbox));
cairo_rectangle_t extent { 0, 0, bbox.width(), bbox.height() };
cairo_surface_ptr surface(
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_surface_closer());
cairo_rectangle_t extent{0, 0, bbox.width(), bbox.height()};
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_surface_closer());
cairo_ptr cairo = create_context(surface);
cairo_context context(cairo);
@ -89,25 +82,21 @@ struct cairo_renderer_process_visitor_p
return surface;
}
cairo_surface_ptr operator() (marker_null const&) const
cairo_surface_ptr operator()(marker_null const&) const
{
cairo_surface_ptr surface(
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, nullptr),
cairo_surface_closer());
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, nullptr),
cairo_surface_closer());
cairo_ptr cairo = create_context(surface);
cairo_context context(cairo);
return surface;
}
private:
agg::trans_affine transform(box2d<double> & bbox) const
private:
agg::trans_affine transform(box2d<double>& bbox) const
{
bbox *= image_tr_;
coord<double, 2> c = bbox.center();
agg::trans_affine mtx = agg::trans_affine_translation(
0.5 * bbox.width() - c.x,
0.5 * bbox.height() - c.y);
agg::trans_affine mtx = agg::trans_affine_translation(0.5 * bbox.width() - c.x, 0.5 * bbox.height() - c.y);
return image_tr_ * mtx;
}
@ -135,7 +124,7 @@ struct cairo_pattern_base
}
};
template <typename VertexConverter>
template<typename VertexConverter>
struct cairo_polygon_pattern : cairo_pattern_base
{
cairo_polygon_pattern(mapnik::marker const& marker,
@ -143,22 +132,23 @@ struct cairo_polygon_pattern : cairo_pattern_base
symbolizer_base const& sym,
mapnik::feature_impl const& feature,
proj_transform const& prj_trans)
: cairo_pattern_base{marker, common, sym, feature, prj_trans},
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
clip_box_(clipping_extent(common)),
tr_(geom_transform()),
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
feature, common.vars_, common.scale_factor_)
: cairo_pattern_base{marker, common, sym, feature, prj_trans}
, clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
, clip_box_(clipping_extent(common))
, tr_(geom_transform())
, converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
{
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_);
converter_.template set<affine_transform_tag>();
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
if (smooth > 0.0) converter_.template set<smooth_tag>();
if (simplify_tolerance > 0.0)
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)
{
value_double opacity = get<value_double, keys::opacity>(sym_, feature_, common_.vars_);
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
@ -181,8 +171,12 @@ struct cairo_polygon_pattern : cairo_pattern_base
cairo_rectangle_t pattern_surface_extent;
if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent))
{
offset = pattern_offset(sym_, feature_, prj_trans_, common_,
pattern_surface_extent.width, pattern_surface_extent.height);
offset = pattern_offset(sym_,
feature_,
prj_trans_,
common_,
pattern_surface_extent.width,
pattern_surface_extent.height);
}
cairo_pattern pattern(surface);
@ -193,7 +187,7 @@ struct cairo_polygon_pattern : cairo_pattern_base
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, cairo_context>;
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
apply_vertex_converter_type apply(converter_, context);
mapnik::util::apply_visitor(vertex_processor_type(apply),feature_.get_geometry());
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
// fill polygon
context.set_fill_rule(fill_rule);
context.fill();
@ -207,5 +201,4 @@ struct cairo_polygon_pattern : cairo_pattern_base
} // namespace mapnik
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP

View file

@ -35,15 +35,15 @@ namespace mapnik {
#if defined(HAVE_CAIRO)
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
std::string const& filename,
double scale_factor=1.0,
double scale_denominator=0.0);
double scale_factor = 1.0,
double scale_denominator = 0.0);
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
std::string const& filename,
std::string const& type,
double scale_factor=1.0,
double scale_denominator=0.0);
double scale_factor = 1.0,
double scale_denominator = 0.0);
#endif
} // end ns
} // namespace mapnik
#endif // MAPNIK_CAIRO_IO_HPP

View file

@ -41,7 +41,7 @@ namespace mapnik {
class MAPNIK_DECL color : boost::equality_comparable<color>
{
public:
public:
std::uint8_t red_;
std::uint8_t green_;
std::uint8_t blue_;
@ -50,46 +50,52 @@ public:
// default ctor
color()
: red_(0xff),
green_(0xff),
blue_(0xff),
alpha_(0xff),
premultiplied_(false)
{}
: red_(0xff)
, green_(0xff)
, blue_(0xff)
, alpha_(0xff)
, premultiplied_(false)
{}
color(std::uint8_t _red, std::uint8_t _green, std::uint8_t _blue, std::uint8_t _alpha = 0xff, bool premultiplied = false)
: red_(_red),
green_(_green),
blue_(_blue),
alpha_(_alpha),
premultiplied_(premultiplied)
{}
color(std::uint8_t _red,
std::uint8_t _green,
std::uint8_t _blue,
std::uint8_t _alpha = 0xff,
bool premultiplied = false)
: red_(_red)
, green_(_green)
, blue_(_blue)
, alpha_(_alpha)
, premultiplied_(premultiplied)
{}
color(std::uint32_t _rgba, bool premultiplied = false)
: red_(_rgba & 0xff),
green_((_rgba >> 8) & 0xff),
blue_((_rgba >> 16) & 0xff),
alpha_((_rgba >> 24) & 0xff),
premultiplied_(premultiplied) {}
: red_(_rgba & 0xff)
, green_((_rgba >> 8) & 0xff)
, blue_((_rgba >> 16) & 0xff)
, alpha_((_rgba >> 24) & 0xff)
, premultiplied_(premultiplied)
{}
// copy ctor
color(const color& rhs)
: red_(rhs.red_),
green_(rhs.green_),
blue_(rhs.blue_),
alpha_(rhs.alpha_),
premultiplied_(rhs.premultiplied_)
{}
: red_(rhs.red_)
, green_(rhs.green_)
, blue_(rhs.blue_)
, alpha_(rhs.alpha_)
, premultiplied_(rhs.premultiplied_)
{}
// move ctor
color(color && rhs)
: red_(std::move(rhs.red_)),
green_(std::move(rhs.green_)),
blue_(std::move(rhs.blue_)),
alpha_(std::move(rhs.alpha_)),
premultiplied_(std::move(rhs.premultiplied_)) {}
color(color&& rhs)
: red_(std::move(rhs.red_))
, green_(std::move(rhs.green_))
, blue_(std::move(rhs.blue_))
, alpha_(std::move(rhs.alpha_))
, premultiplied_(std::move(rhs.premultiplied_))
{}
color( std::string const& str, bool premultiplied = false);
color(std::string const& str, bool premultiplied = false);
std::string to_string() const;
std::string to_hex_string() const;
@ -104,78 +110,45 @@ public:
inline bool operator==(color const& rhs) const
{
return (red_== rhs.red_) &&
(green_ == rhs.green_) &&
(blue_ == rhs.blue_) &&
(alpha_ == rhs.alpha_) &&
(premultiplied_ == rhs.premultiplied_);
return (red_ == rhs.red_) && (green_ == rhs.green_) && (blue_ == rhs.blue_) && (alpha_ == rhs.alpha_) &&
(premultiplied_ == rhs.premultiplied_);
}
inline std::uint8_t red() const
{
return red_;
}
inline std::uint8_t red() const { return red_; }
inline std::uint8_t green() const
{
return green_;
}
inline std::uint8_t green() const { return green_; }
inline std::uint8_t blue() const
{
return blue_;
}
inline std::uint8_t blue() const { return blue_; }
inline std::uint8_t alpha() const
{
return alpha_;
}
inline std::uint8_t alpha() const { return alpha_; }
inline void set_red(std::uint8_t _red)
{
red_ = _red;
}
inline void set_red(std::uint8_t _red) { red_ = _red; }
inline void set_green(std::uint8_t _green)
{
green_ = _green;
}
inline void set_green(std::uint8_t _green) { green_ = _green; }
inline void set_blue(std::uint8_t _blue)
{
blue_ = _blue;
}
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 void set_blue(std::uint8_t _blue) { blue_ = _blue; }
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
{
return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_)) ;
return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_));
}
private:
void swap(color & rhs)
private:
void swap(color& rhs)
{
std::swap(red_, rhs.red_);
std::swap(green_,rhs.green_);
std::swap(blue_,rhs.blue_);
std::swap(alpha_,rhs.alpha_);
std::swap(green_, rhs.green_);
std::swap(blue_, rhs.blue_);
std::swap(alpha_, rhs.alpha_);
std::swap(premultiplied_, rhs.premultiplied_);
}
};
template <typename charT, typename traits>
std::basic_ostream<charT, traits> &
operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
template<typename charT, typename traits>
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, mapnik::color const& c)
{
s << c.to_string();
return s;
@ -187,6 +160,6 @@ inline std::size_t hash_value(color const& c)
return c.rgba();
}
}
} // namespace mapnik
#endif // MAPNIK_COLOR_HPP

View file

@ -26,7 +26,7 @@
// mapnik
#include <mapnik/color.hpp>
//stl
// stl
#include <string>
namespace mapnik {

View file

@ -26,28 +26,28 @@
// Windows DLL support
#ifdef _WIN32
# define MAPNIK_EXP __declspec (dllexport)
# define MAPNIK_IMP __declspec (dllimport)
# ifdef MAPNIK_EXPORTS
# define MAPNIK_DECL __declspec (dllexport)
# else
# define MAPNIK_DECL __declspec (dllimport)
# endif
# pragma warning( disable: 4251 )
# pragma warning( disable: 4275 )
# if (_MSC_VER >= 1400) // vc8
# pragma warning(disable : 4996) //_CRT_SECURE_NO_DEPRECATE
# endif
#define MAPNIK_EXP __declspec(dllexport)
#define MAPNIK_IMP __declspec(dllimport)
#ifdef MAPNIK_EXPORTS
#define MAPNIK_DECL __declspec(dllexport)
#else
# if __GNUC__ >= 4
# define MAPNIK_EXP __attribute__ ((visibility ("default")))
# define MAPNIK_DECL __attribute__ ((visibility ("default")))
# define MAPNIK_IMP __attribute__ ((visibility ("default")))
# else
# define MAPNIK_EXP
# define MAPNIK_DECL
# define MAPNIK_IMP
# endif
#define MAPNIK_DECL __declspec(dllimport)
#endif
#pragma warning(disable: 4251)
#pragma warning(disable: 4275)
#if (_MSC_VER >= 1400) // vc8
#pragma warning(disable: 4996) //_CRT_SECURE_NO_DEPRECATE
#endif
#else
#if __GNUC__ >= 4
#define MAPNIK_EXP __attribute__((visibility("default")))
#define MAPNIK_DECL __attribute__((visibility("default")))
#define MAPNIK_IMP __attribute__((visibility("default")))
#else
#define MAPNIK_EXP
#define MAPNIK_DECL
#define MAPNIK_IMP
#endif
#endif
#define PROJ_ENVELOPE_POINTS 20

View file

@ -34,19 +34,17 @@ class xml_node;
class config_error : public std::exception
{
public:
public:
config_error(std::string const& what);
config_error(std::string const& what,
xml_node const& node);
config_error(std::string const& what,
unsigned line_number,
std::string const& filename);
config_error(std::string const& what, xml_node const& node);
config_error(std::string const& what, unsigned line_number, std::string const& filename);
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, xml_node const& node) const;
void append_context(xml_node const& node) const;
protected:
protected:
mutable std::string what_;
mutable unsigned line_number_;
mutable std::string file_;
@ -54,6 +52,6 @@ protected:
mutable std::string msg_;
};
}
} // namespace mapnik
#endif // MAPNIK_CONFIG_ERROR_HPP

View file

@ -30,150 +30,173 @@ MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
template <typename T,int dim>
struct coord {
template<typename T, int dim>
struct coord
{
using type = T;
};
template <typename T>
struct coord<T,2>
: boost::addable<coord<T,2>,
boost::addable2<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 > > > > > >
template<typename T>
struct coord<T, 2>
: boost::addable<
coord<T, 2>,
boost::addable2<
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;
T x;
T y;
public:
public:
coord()
: x(),y() {}
coord(T x_,T y_)
: x(x_),y(y_) {}
: x()
, y()
{}
coord(T x_, T y_)
: x(x_)
, y(y_)
{}
coord(coord<T,2> const& rhs)
: x(rhs.x),
y(rhs.y) {}
coord(coord<T, 2> const& rhs)
: x(rhs.x)
, y(rhs.y)
{}
template <typename T2>
coord (coord<T2,2> const& rhs)
: x(type(rhs.x)),
y(type(rhs.y)) {}
template<typename T2>
coord(coord<T2, 2> const& rhs)
: x(type(rhs.x))
, y(type(rhs.y))
{}
coord(coord<T,2> && rhs) noexcept
: x(std::move(rhs.x)),
y(std::move(rhs.y)) {}
coord(coord<T, 2>&& rhs) noexcept
: x(std::move(rhs.x))
, y(std::move(rhs.y))
{}
coord<T,2>& operator=(coord<T,2> rhs)
coord<T, 2>& operator=(coord<T, 2> rhs)
{
swap(rhs);
return *this;
}
template <typename T2>
coord<T,2>& operator=(const coord<T2,2>& rhs)
template<typename T2>
coord<T, 2>& operator=(const coord<T2, 2>& rhs)
{
coord<T,2> tmp(rhs);
coord<T, 2> tmp(rhs);
swap(rhs);
return *this;
}
template <typename T2>
bool operator==(coord<T2,2> const& rhs)
template<typename T2>
bool operator==(coord<T2, 2> const& rhs)
{
return x == rhs.x && y == rhs.y;
}
coord<T,2>& operator+=(coord<T,2> const& rhs)
coord<T, 2>& operator+=(coord<T, 2> const& rhs)
{
x+=rhs.x;
y+=rhs.y;
x += rhs.x;
y += rhs.y;
return *this;
}
coord<T,2>& operator+=(T rhs)
coord<T, 2>& operator+=(T rhs)
{
x+=rhs;
y+=rhs;
x += rhs;
y += rhs;
return *this;
}
coord<T,2>& operator-=(coord<T,2> const& rhs)
coord<T, 2>& operator-=(coord<T, 2> const& rhs)
{
x-=rhs.x;
y-=rhs.y;
x -= rhs.x;
y -= rhs.y;
return *this;
}
coord<T,2>& operator-=(T rhs)
coord<T, 2>& operator-=(T rhs)
{
x-=rhs;
y-=rhs;
x -= rhs;
y -= rhs;
return *this;
}
coord<T,2>& operator*=(T t)
coord<T, 2>& operator*=(T t)
{
x*=t;
y*=t;
x *= t;
y *= t;
return *this;
}
coord<T,2>& operator/=(T t)
coord<T, 2>& operator/=(T t)
{
x/=t;
y/=t;
x /= t;
y /= t;
return *this;
}
private:
void swap(coord<T,2> & rhs)
private:
void swap(coord<T, 2>& rhs)
{
std::swap(this->x, rhs.x);
std::swap(this->y, rhs.y);
}
};
template <typename T>
struct coord<T,3>
template<typename T>
struct coord<T, 3>
{
using type = T;
T x;
T y;
T z;
public:
public:
coord()
: x(),y(),z() {}
coord(T x_,T y_,T z_)
: x(x_),y(y_),z(z_) {}
: x()
, y()
, z()
{}
coord(T x_, T y_, T z_)
: x(x_)
, y(y_)
, z(z_)
{}
template <typename T2>
coord (coord<T2,3> const& rhs)
: x(type(rhs.x)),
y(type(rhs.y)),
z(type(rhs.z)) {}
template<typename T2>
coord(coord<T2, 3> const& rhs)
: x(type(rhs.x))
, y(type(rhs.y))
, z(type(rhs.z))
{}
coord(coord<T,3> && rhs) noexcept
: x(std::move(rhs.x)),
y(std::move(rhs.y)),
z(std::move(rhs.z)) {}
coord(coord<T, 3>&& rhs) noexcept
: x(std::move(rhs.x))
, y(std::move(rhs.y))
, z(std::move(rhs.z))
{}
coord<T,3> operator=(coord<T,3> rhs)
coord<T, 3> operator=(coord<T, 3> rhs)
{
swap(rhs);
return *this;
}
template <typename T2>
coord<T,3>& operator=(coord<T2,3> const& rhs)
template<typename T2>
coord<T, 3>& operator=(coord<T2, 3> const& rhs)
{
coord<T,3> tmp(rhs);
coord<T, 3> tmp(rhs);
swap(tmp);
return *this;
}
private:
void swap(coord<T,3> & rhs)
private:
void swap(coord<T, 3>& rhs)
{
std::swap(this->x, rhs.x);
std::swap(this->y, rhs.y);
@ -181,10 +204,10 @@ private:
}
};
using coord2d = coord<double,2>;
using coord2f = coord<float,2>;
using coord2i = coord<int,2>;
using coord2d = coord<double, 2>;
using coord2f = coord<float, 2>;
using coord2i = coord<int, 2>;
}
} // namespace mapnik
#endif // MAPNIK_COORD_HPP

View file

@ -31,13 +31,11 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/spirit/home/x3.hpp>
MAPNIK_DISABLE_WARNING_POP
namespace mapnik
{
namespace mapnik {
namespace x3 = boost::spirit::x3;
namespace css_color_grammar
{
namespace css_color_grammar {
struct css_color_class;
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);
}}
} // namespace css_color_grammar
} // namespace mapnik
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP

View file

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

View file

@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
@ -31,8 +31,7 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/spirit/home/x3.hpp>
MAPNIK_DISABLE_WARNING_POP
namespace mapnik
{
namespace mapnik {
using property_value_type = boost::iterator_range<char const*>;
using css_key_value = std::pair<std::string, property_value_type>;
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 css_grammar
{
namespace css_grammar {
class css_tag;
class ident_tag;
@ -58,17 +56,14 @@ css_grammar_type const css_grammar{"css"};
css_skipper_type const css_skipper{"css skipper"};
css_classes_type const css_classes{"css classes"};
BOOST_SPIRIT_DECLARE(ident_grammar_type,
css_classes_type,
css_grammar_type,
css_skipper_type);
BOOST_SPIRIT_DECLARE(ident_grammar_type, css_classes_type, css_grammar_type, css_skipper_type);
}
} // namespace css_grammar
css_grammar::ident_grammar_type const ident_grammar();
css_grammar::css_classes_type const classes();
css_grammar::css_grammar_type const grammar();
css_grammar::css_skipper_type const skipper();
}
} // namespace mapnik
#endif // MAPNIK_CSS_GRAMMAR_X3_HPP

View file

@ -20,7 +20,6 @@
*
*****************************************************************************/
#ifndef 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>
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
+ : 1 or more
@ -148,46 +148,48 @@ namespace x3 = boost::spirit::x3;
namespace css_grammar {
using x3::lit;
using x3::alnum;
using x3::alpha;
using x3::attr;
using x3::char_;
using x3::lexeme;
using x3::lit;
using x3::no_case;
using x3::no_skip;
using x3::lexeme;
using x3::alpha;
using x3::alnum;
using x3::char_;
using x3::raw;
using x3::standard::space;
// 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)))
{
_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));
};
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
x3::rule<class simple_selector_tag, std::string> const simple_selector {"Simple selector"};
x3::rule<class selector_tag, std::vector<std::string>> const selector {"Selector"};
x3::rule<class value_tag, property_value_type> const value {"Value"};
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 simple_selector_tag, std::string> const simple_selector{"Simple selector"};
x3::rule<class selector_tag, std::vector<std::string>> const selector{"Selector"};
x3::rule<class value_tag, property_value_type> const value{"Value"};
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"};
auto const ident_def = alpha >> *(alnum | char_('-'));
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)]
| lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)]
| lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)] |
lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)] |
lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
auto const selector_def = simple_selector % lit(',');
auto const value_def = raw[lexeme[+~char_(";}")]];
@ -202,21 +204,19 @@ auto const css_classes_def = +lexeme[ident];
#include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp>
BOOST_SPIRIT_DEFINE(
ident,
css_classes,
simple_selector,
selector,
value,
key_value,
definition,
css_grammar,
css_skipper
);
BOOST_SPIRIT_DEFINE(ident,
css_classes,
simple_selector,
selector,
value,
key_value,
definition,
css_grammar,
css_skipper);
MAPNIK_DISABLE_WARNING_POP
} //css_grammar
} //mapnik
} // namespace css_grammar
} // 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
#define MAPNIK_CSS_UNIT_VALUE_HPP
@ -36,15 +35,15 @@ struct css_unit_value : x3::symbols<double>
constexpr static double DPI = 96;
css_unit_value()
{
add
("px", 1.0) // pixels
("pt", DPI/72.0) // points
("pc", DPI/6.0) // picas
("mm", DPI/25.4) // milimeters
("Q" , DPI/101.6)// quarter-milimeters
("cm", DPI/2.54) // centimeters
("in", static_cast<double>(DPI)) // inches
;
add //
("px", 1.0) // pixels
("pt", DPI / 72.0) // points
("pc", DPI / 6.0) // picas
("mm", DPI / 25.4) // milimeters
("Q", DPI / 101.6) // quarter-milimeters
("cm", DPI / 2.54) // centimeters
("in", static_cast<double>(DPI)) // inches
;
}
};
@ -53,15 +52,15 @@ struct css_absolute_size : x3::symbols<double>
constexpr static double EM = 10.0; // 1em == 10px
css_absolute_size()
{
add
("xx-small", 0.6 * EM)
("x-small", 0.75 * EM)
("small", 0.88 * EM)
("medium", 1.0 * EM)
("large", 1.2 * EM)
("x-large", 1.5 * EM)
("xx-large", 2.0 * EM)
;
add //
("xx-small", 0.6 * EM) //
("x-small", 0.75 * EM) //
("small", 0.88 * EM) //
("medium", 1.0 * EM) //
("large", 1.2 * EM) //
("x-large", 1.5 * EM) //
("xx-large", 2.0 * EM) //
;
}
};
@ -69,13 +68,12 @@ struct css_relative_size : x3::symbols<double>
{
css_relative_size()
{
add
("larger", 1.2)
("smaller", 0.8)
;
add //
("larger", 1.2) //
("smaller", 0.8);
}
};
} //mapnik
} // namespace mapnik
#endif //MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP

View file

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

View file

@ -29,45 +29,44 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/csv/csv_grammar_x3.hpp>
MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace grammar {
namespace mapnik {
namespace grammar {
namespace x3 = boost::spirit::x3;
namespace standard = boost::spirit::x3::standard;
using x3::lit;
using x3::lexeme;
using standard::char_;
using x3::lexeme;
using x3::lit;
struct unesc_char_ : x3::symbols<char>
{
unesc_char_()
{
add("\\a", '\a')
("\\b", '\b')
("\\f", '\f')
("\\n", '\n')
("\\r", '\r')
("\\t", '\t')
("\\v", '\v')
("\\\\",'\\')
("\\\'", '\'')
("\\\"", '\"')
("\"\"", '\"') // double quote
;
add("\\a", '\a') //
("\\b", '\b') //
("\\f", '\f') //
("\\n", '\n') //
("\\r", '\r') //
("\\t", '\t') //
("\\v", '\v') //
("\\\\", '\\') //
("\\\'", '\'') //
("\\\"", '\"') //
("\"\"", '\"') // double quote
;
}
} unesc_char;
template <typename T>
template<typename T>
struct literal : x3::parser<literal<T>>
{
using attribute_type = x3::unused_type;
using context_tag = T;
static bool const has_attribute = false;
template <typename Iterator, typename Context, typename Attribute>
bool parse(Iterator& first, Iterator const& last,
Context const& context, x3::unused_type, Attribute& ) const
template<typename Iterator, typename Context, typename Attribute>
bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
{
x3::skip_over(first, last, 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 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 text_def = *(unesc_char | (char_ - quote))
;
auto const text_def = *(unesc_char | (char_ - quote));
BOOST_SPIRIT_DEFINE (
line,
column,
quoted_text,
text
);
BOOST_SPIRIT_DEFINE(line, column, quoted_text, text);
} // grammar
} // namespace grammar
} // namespace mapnik
#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_data = std::vector<csv_line>;
}
} // namespace mapnik
#endif // MAPNIK_CSV_TYPES_HPP

View file

@ -28,13 +28,13 @@
namespace mapnik {
namespace detail {
template <bool B, typename T, typename F>
template<bool B, typename T, typename F>
using conditional_t = typename std::conditional<B, T, F>::type;
template <typename T>
template<typename T>
using decay_t = typename std::decay<T>::type;
template <bool B, typename T = void>
template<bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
} // namespace detail

View file

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

View file

@ -41,21 +41,22 @@ class datasource;
class parameters;
class PluginInfo;
class MAPNIK_DECL datasource_cache
: public singleton<datasource_cache, CreateStatic>,
private util::noncopyable
class MAPNIK_DECL datasource_cache : public singleton<datasource_cache, CreateStatic>,
private util::noncopyable
{
friend class CreateStatic<datasource_cache>;
public:
public:
std::vector<std::string> plugin_names();
std::string plugin_directories();
bool register_datasources(std::string const& path, bool recurse = false);
bool register_datasource(std::string const& path);
std::shared_ptr<datasource> create(parameters const& params);
private:
private:
datasource_cache();
~datasource_cache();
std::map<std::string,std::shared_ptr<PluginInfo> > plugins_;
std::map<std::string, std::shared_ptr<PluginInfo>> plugins_;
std::set<std::string> plugin_directories_;
// the singleton has a mutex protecting the instance pointer,
// but the instance also needs its own mutex to protect the
@ -66,6 +67,6 @@ private:
extern template class MAPNIK_DECL singleton<datasource_cache, CreateStatic>;
}
} // namespace mapnik
#endif // MAPNIK_DATASOURCE_CACHE_HPP

View file

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

View file

@ -42,35 +42,21 @@
namespace mapnik {
// Global logger class that holds the configuration of severity, format
// and file/console redirection.
class MAPNIK_DECL logger :
public singleton<logger,CreateStatic>,
private util::noncopyable
class MAPNIK_DECL logger : public singleton<logger, CreateStatic>,
private util::noncopyable
{
public:
enum severity_type
{
debug = 0,
warn = 1,
error = 2,
none = 3
};
public:
enum severity_type { debug = 0, warn = 1, error = 2, none = 3 };
using severity_map = std::unordered_map<std::string, severity_type>;
// global security level
static severity_type get_severity()
{
return severity_level_;
}
static severity_type get_severity() { return severity_level_; }
static void set_severity(severity_type severity_level)
{
severity_level_ = severity_level;
}
static void set_severity(severity_type severity_level) { severity_level_ = severity_level; }
// per object security levels
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,
severity_type const& security_level)
static void set_object_severity(std::string const& object_name, severity_type const& security_level)
{
if (!object_name.empty())
{
@ -111,10 +96,7 @@ public:
}
// format
static std::string const& get_format()
{
return format_;
}
static std::string const& get_format() { return format_; }
static void set_format(std::string const& format)
{
@ -131,7 +113,7 @@ public:
static void use_file(std::string const& filepath);
static void use_console();
private:
private:
static severity_map object_severity_level_;
static std::string format_;
static std::ofstream file_output_;
@ -151,7 +133,6 @@ private:
#endif
};
namespace detail {
// Default sink, it regulates access to clog
@ -159,7 +140,7 @@ namespace detail {
template<class Ch, class Tr, class A>
class clog_sink
{
public:
public:
using stream_buffer = std::basic_ostringstream<Ch, Tr, A>;
void operator()(logger::severity_type const& /*severity*/, stream_buffer const& s)
@ -177,14 +158,14 @@ public:
// This is used for debug/warn reporting that should not output
// anything when not compiling for speed.
template<template <class Ch, class Tr, class A> class OutputPolicy,
template<template<class Ch, class Tr, class A> class OutputPolicy,
logger::severity_type Severity,
class Ch = char,
class Tr = std::char_traits<Ch>,
class A = std::allocator<Ch> >
class A = std::allocator<Ch>>
class base_log : public util::noncopyable
{
public:
public:
using output_policy = OutputPolicy<Ch, Tr, A>;
base_log() {}
@ -198,9 +179,7 @@ public:
}
}
#else
base_log(const char* /*object_name*/)
{
}
base_log(const char* /*object_name*/) {}
#endif
~base_log()
@ -215,45 +194,38 @@ public:
template<class T>
#ifdef MAPNIK_LOG
base_log &operator<<(T const& x)
base_log& operator<<(T const& x)
{
streambuf_ << x;
return *this;
}
#else
base_log &operator<<(T const& /*x*/)
base_log& operator<<(T const& /*x*/)
{
return *this;
}
#endif
private:
private:
#ifdef MAPNIK_LOG
inline bool check_severity()
{
return Severity >= logger::get_object_severity(object_name_);
}
inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
typename output_policy::stream_buffer streambuf_;
std::string object_name_;
#endif
};
// Base log class that always log, regardless of MAPNIK_LOG.
// This is used for error reporting that should always log something
//Base log class that always log, regardless of MAPNIK_LOG.
//This is used for error reporting that should always log something
template<template <class Ch, class Tr, class A> class OutputPolicy,
template<template<class Ch, class Tr, class A> class OutputPolicy,
logger::severity_type Severity,
class Ch = char,
class Tr = std::char_traits<Ch>,
class A = std::allocator<Ch> >
class A = std::allocator<Ch>>
class base_log_always : public util::noncopyable
{
public:
public:
using output_policy = OutputPolicy<Ch, Tr, A>;
base_log_always() {}
@ -275,56 +247,63 @@ public:
}
template<class T>
base_log_always &operator<<(T const& x)
base_log_always& operator<<(T const& x)
{
streambuf_ << x;
return *this;
}
private:
inline bool check_severity()
{
return Severity >= logger::get_object_severity(object_name_);
}
private:
inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
typename output_policy::stream_buffer streambuf_;
std::string object_name_;
};
using base_log_debug = base_log<clog_sink, logger::debug>;
using base_log_warn = base_log<clog_sink, logger::warn>;
using base_log_error = base_log_always<clog_sink, logger::error>;
} // namespace detail
// real interfaces
class MAPNIK_DECL warn : public detail::base_log_warn
{
public:
warn() : detail::base_log_warn() {}
warn(const char* object_name) : detail::base_log_warn(object_name) {}
public:
warn()
: detail::base_log_warn()
{}
warn(const char* object_name)
: detail::base_log_warn(object_name)
{}
};
class MAPNIK_DECL debug : public detail::base_log_debug
{
public:
debug() : detail::base_log_debug() {}
debug(const char* object_name) : detail::base_log_debug(object_name) {}
public:
debug()
: detail::base_log_debug()
{}
debug(const char* object_name)
: detail::base_log_debug(object_name)
{}
};
class MAPNIK_DECL error : public detail::base_log_error
{
public:
error() : detail::base_log_error() {}
error(const char* object_name) : detail::base_log_error(object_name) {}
public:
error()
: detail::base_log_error()
{}
error(const char* object_name)
: detail::base_log_error(object_name)
{}
};
// logging helpers
#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)
}
} // namespace mapnik
#endif // MAPNIK_DEBUG_HPP

View file

@ -38,26 +38,22 @@ namespace mapnik {
class illegal_enum_value : public std::exception
{
public:
illegal_enum_value():
what_() {}
public:
illegal_enum_value()
: what_()
{}
illegal_enum_value( std::string const& _what ) :
what_( _what )
{
}
illegal_enum_value(std::string const& _what)
: what_(_what)
{}
virtual ~illegal_enum_value() {}
virtual const char * what() const noexcept
{
return what_.c_str();
}
virtual const char* what() const noexcept { return what_.c_str(); }
protected:
protected:
std::string what_;
};
/** 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
* type. It supports string conversion through stream operators. This is useful
@ -137,42 +133,34 @@ protected:
* @endcode
*/
template <typename ENUM, int THE_MAX>
class MAPNIK_DECL enumeration {
public:
template<typename ENUM, int THE_MAX>
class MAPNIK_DECL enumeration
{
public:
using native_type = ENUM;
enumeration()
: value_() {}
: value_()
{}
enumeration( ENUM v )
: value_(v) {}
enumeration(ENUM v)
: value_(v)
{}
enumeration( enumeration const& other )
: value_(other.value_) {}
enumeration(enumeration const& other)
: value_(other.value_)
{}
/** Assignment operator for native enum values. */
void operator=(ENUM v)
{
value_ = v;
}
void operator=(ENUM v) { value_ = v; }
/** Assignment operator. */
void operator=(enumeration const& other)
{
value_ = other.value_;
}
void operator=(enumeration const& other) { value_ = other.value_; }
/** Conversion operator for native enum values. */
operator ENUM() const
{
return value_;
}
operator ENUM() const { return value_; }
enum Max
{
MAX = THE_MAX
};
enum Max { MAX = THE_MAX };
/** Converts @p str to an enum.
* @throw illegal_enum_value @p str is not a legal identifier.
@ -190,113 +178,114 @@ public:
}
for (unsigned i = 0; i < THE_MAX; ++i)
{
MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS
MAPNIK_DISABLE_LONG_LONG
MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS
MAPNIK_DISABLE_LONG_LONG
if (str_copy == our_strings_[i])
MAPNIK_DISABLE_WARNING_POP
{
value_ = static_cast<ENUM>(i);
if (deprecated)
MAPNIK_DISABLE_WARNING_POP
{
MAPNIK_LOG_ERROR(enumerations) << "enumeration value (" << str << ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy << "' instead";
value_ = static_cast<ENUM>(i);
if (deprecated)
{
MAPNIK_LOG_ERROR(enumerations)
<< "enumeration value (" << str
<< ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy
<< "' instead";
}
return;
}
return;
}
}
MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS
MAPNIK_DISABLE_LONG_LONG
throw illegal_enum_value(std::string("Illegal enumeration value '") +
str + "' for enum " + our_name_);
MAPNIK_DISABLE_WARNING_POP
MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS
MAPNIK_DISABLE_LONG_LONG
throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_);
MAPNIK_DISABLE_WARNING_POP
}
/** Returns the current value as a string identifier. */
std::string as_string() const
{
MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS
MAPNIK_DISABLE_LONG_LONG
MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS
MAPNIK_DISABLE_LONG_LONG
return our_strings_[value_];
MAPNIK_DISABLE_WARNING_POP
MAPNIK_DISABLE_WARNING_POP
}
/** Static helper function to iterate over valid identifiers. */
static const char * get_string(unsigned i)
{
return our_strings_[i];
}
static const char* get_string(unsigned i) { return our_strings_[i]; }
/** Performs some simple checks and quits the application if
* any error is detected. Tries to print helpful error messages.
*/
static bool verify_mapnik_enum(const char * filename, unsigned line_no)
static bool verify_mapnik_enum(const char* filename, unsigned line_no)
{
for (unsigned i = 0; i < THE_MAX; ++i)
{
if (our_strings_[i] == 0 )
if (our_strings_[i] == 0)
{
std::cerr << "### FATAL: Not enough strings for enum "
<< our_name_ << " defined in file '" << filename
std::cerr << "### FATAL: Not enough strings for enum " << our_name_ << " defined in file '" << filename
<< "' 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_
<< " defined in file '" << filename << "' at line " << line_no
<< " has too many items or is not terminated with an "
std::cerr << "### FATAL: The string array for enum " << our_name_ << " defined in file '" << filename
<< "' at line " << line_no << " has too many items or is not terminated with an "
<< "empty string";
}
return true;
}
private:
private:
ENUM value_;
static const char ** our_strings_ ;
static std::string our_name_ ;
static bool our_verified_flag_;
static const char** our_strings_;
static std::string our_name_;
static bool our_verified_flag_;
};
/** ostream operator for enumeration
* @relates mapnik::enumeration
*/
template <class ENUM, int THE_MAX>
std::ostream &
operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
template<class ENUM, int THE_MAX>
std::ostream& operator<<(std::ostream& os, const mapnik::enumeration<ENUM, THE_MAX>& e)
{
return os << e.as_string();
}
} // end of namespace
} // namespace mapnik
/** Helper macro.
* @relates mapnik::enumeration
*/
#ifdef _MSC_VER
#define DEFINE_ENUM( name, e) \
template enumeration<e, e ## _MAX>; \
using name = enumeration<e, e ## _MAX>;
#define DEFINE_ENUM(name, e) \
template enumeration<e, e##_MAX>; \
using name = enumeration<e, e##_MAX>;
#else
#define DEFINE_ENUM( name, e) \
using name = enumeration<e, e ## _MAX>; \
template <> MAPNIK_DECL const char ** name ::our_strings_; \
template <> MAPNIK_DECL std::string name ::our_name_; \
template <> MAPNIK_DECL bool name ::our_verified_flag_;
#define DEFINE_ENUM(name, e) \
using name = enumeration<e, e##_MAX>; \
template<> \
MAPNIK_DECL const char** name ::our_strings_; \
template<> \
MAPNIK_DECL std::string name ::our_name_; \
template<> \
MAPNIK_DECL bool name ::our_verified_flag_;
#endif
/** Helper macro. Runs the verify_mapnik_enum() method during static initialization.
* @relates mapnik::enumeration
*/
#define IMPLEMENT_ENUM( name, strings ) \
template <> MAPNIK_DECL const char ** name ::our_strings_ = strings; \
template <> MAPNIK_DECL std::string name ::our_name_ = #name; \
template <> MAPNIK_DECL bool name ::our_verified_flag_( name ::verify_mapnik_enum(__FILE__, __LINE__));
#define IMPLEMENT_ENUM(name, strings) \
template<> \
MAPNIK_DECL const char** name ::our_strings_ = strings; \
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

View file

@ -38,93 +38,91 @@ namespace mapnik {
namespace {
template <typename T, typename Attributes>
template<typename T, typename Attributes>
struct evaluate_expression
{
using value_type = T;
explicit evaluate_expression(Attributes const& attrs)
: attrs_(attrs) {}
: attrs_(attrs)
{}
value_type operator() (attribute const&) const
value_type operator()(attribute const&) const
{
throw std::runtime_error("can't evaluate feature attributes in this context");
}
value_type operator() (global_attribute const& attr) const
value_type operator()(global_attribute const& attr) const
{
auto itr = attrs_.find(attr.name);
if (itr != attrs_.end())
{
return itr->second;
}
return value_type();// throw?
return value_type(); // throw?
}
value_type operator() (geometry_type_attribute const&) const
value_type operator()(geometry_type_attribute const&) const
{
throw std::runtime_error("can't evaluate geometry_type attributes in this context");
}
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())
&& (util::apply_visitor(*this, x.right).to_bool());
return (util::apply_visitor(*this, x.left).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())
|| (util::apply_visitor(*this,x.right).to_bool());
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
}
template <typename Tag>
value_type operator() (binary_node<Tag> const& x) const
template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const
{
typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left),
util::apply_visitor(*this, x.right));
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
}
template <typename Tag>
value_type operator() (unary_node<Tag> const& x) const
template<typename Tag>
value_type operator()(unary_node<Tag> const& x) const
{
typename make_op<Tag>::type func;
return func(util::apply_visitor(*this, x.expr));
}
value_type operator() (unary_node<tags::logical_not> const& x) const
value_type operator()(unary_node<tags::logical_not> const& x) const
{
return ! (util::apply_visitor(*this,x.expr).to_bool());
return !(util::apply_visitor(*this, x.expr).to_bool());
}
value_type operator() (regex_match_node const& x) const
value_type operator()(regex_match_node const& x) const
{
value_type v = util::apply_visitor(*this, x.expr);
return x.apply(v);
}
value_type operator() (regex_replace_node const& x) const
value_type operator()(regex_replace_node const& x) const
{
value_type v = util::apply_visitor(*this, x.expr);
return x.apply(v);
}
value_type operator() (unary_function_call const& call) const
value_type operator()(unary_function_call const& call) const
{
value_type arg = util::apply_visitor(*this, call.arg);
return call.fun(arg);
}
value_type operator() (binary_function_call const& call) const
value_type operator()(binary_function_call const& call) const
{
value_type arg1 = util::apply_visitor(*this, call.arg1);
value_type arg2 = util::apply_visitor(*this, call.arg2);
return call.fun(arg1, arg2);
}
template <typename ValueType>
value_type operator() (ValueType const& val) const
template<typename ValueType>
value_type operator()(ValueType const& val) const
{
return value_type(val);
}
@ -132,87 +130,84 @@ struct evaluate_expression
Attributes const& attrs_;
};
template <typename T>
template<typename T>
struct evaluate_expression<T, boost::none_t>
{
using value_type = T;
evaluate_expression(boost::none_t) {}
value_type operator() (attribute const&) const
value_type operator()(attribute const&) const
{
throw std::runtime_error("can't evaluate feature attributes in this context");
}
value_type operator() (global_attribute const&) const
value_type operator()(global_attribute const&) const
{
throw std::runtime_error("can't evaluate feature attributes in this context");
}
value_type operator() (geometry_type_attribute const&) const
value_type operator()(geometry_type_attribute const&) const
{
throw std::runtime_error("can't evaluate geometry_type attributes in this context");
}
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())
&& (util::apply_visitor(*this, x.right).to_bool());
return (util::apply_visitor(*this, x.left).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())
|| (util::apply_visitor(*this,x.right).to_bool());
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
}
template <typename Tag>
value_type operator() (binary_node<Tag> const& x) const
template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const
{
typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left),
util::apply_visitor(*this, x.right));
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
}
template <typename Tag>
value_type operator() (unary_node<Tag> const& x) const
template<typename Tag>
value_type operator()(unary_node<Tag> const& x) const
{
typename make_op<Tag>::type func;
return func(util::apply_visitor(*this, x.expr));
}
value_type operator() (unary_node<tags::logical_not> const& x) const
value_type operator()(unary_node<tags::logical_not> const& x) const
{
return ! (util::apply_visitor(*this,x.expr).to_bool());
return !(util::apply_visitor(*this, x.expr).to_bool());
}
value_type operator() (regex_match_node const& x) const
value_type operator()(regex_match_node const& x) const
{
value_type v = util::apply_visitor(*this, x.expr);
return x.apply(v);
}
value_type operator() (regex_replace_node const& x) const
value_type operator()(regex_replace_node const& x) const
{
value_type v = util::apply_visitor(*this, x.expr);
return x.apply(v);
}
value_type operator() (unary_function_call const& call) const
value_type operator()(unary_function_call const& call) const
{
value_type arg = util::apply_visitor(*this, call.arg);
return call.fun(arg);
}
value_type operator() (binary_function_call const& call) const
value_type operator()(binary_function_call const& call) const
{
value_type arg1 = util::apply_visitor(*this, call.arg1);
value_type arg2 = util::apply_visitor(*this, call.arg2);
return call.fun(arg1, arg2);
}
template <typename ValueType>
value_type operator() (ValueType const& val) const
template<typename ValueType>
value_type operator()(ValueType const& val) const
{
return value_type(val);
}
@ -221,90 +216,98 @@ struct evaluate_expression<T, boost::none_t>
struct assign_value
{
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)
{
case property_types::target_color:
{
// evaluate expression as a string then parse as css color
std::string str = util::apply_visitor(mapnik::evaluate_expression<mapnik::value,
Attributes>(attrs),*expr).to_string();
try { val = parse_color(str); }
catch (...) { val = color(0,0,0);}
break;
}
case property_types::target_double:
{
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_double();
break;
}
case property_types::target_integer:
{
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_int();
break;
}
case property_types::target_bool:
{
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_bool();
break;
}
default: // no-op
break;
case property_types::target_color: {
// evaluate expression as a string then parse as css color
std::string str =
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_string();
try
{
val = parse_color(str);
} catch (...)
{
val = color(0, 0, 0);
}
break;
}
case property_types::target_double: {
val =
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_double();
break;
}
case property_types::target_integer: {
val =
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_int();
break;
}
case property_types::target_bool: {
val =
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_bool();
break;
}
default: // no-op
break;
}
}
};
}
} // namespace
template <typename T>
std::tuple<T,bool> pre_evaluate_expression (expression_ptr const& expr)
template<typename T>
std::tuple<T, bool> pre_evaluate_expression(expression_ptr const& expr)
{
try
{
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none),*expr), true);
}
catch (...)
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none), *expr),
true);
} catch (...)
{
return std::make_tuple(T(),false);
return std::make_tuple(T(), false);
}
}
struct evaluate_global_attributes : util::noncopyable
{
template <typename Attributes>
template<typename Attributes>
struct evaluator
{
evaluator(symbolizer_base::cont_type::value_type & prop, Attributes const& attrs)
: prop_(prop),
attrs_(attrs) {}
evaluator(symbolizer_base::cont_type::value_type& prop, Attributes const& attrs)
: prop_(prop)
, attrs_(attrs)
{}
void operator() (expression_ptr const& expr) const
void operator()(expression_ptr const& expr) const
{
auto const& meta = get_meta(prop_.first);
assign_value::apply(prop_.second, expr, attrs_, std::get<2>(meta));
}
template <typename T>
void operator() (T const&) const
template<typename T>
void operator()(T const&) const
{
// no-op
}
symbolizer_base::cont_type::value_type & prop_;
symbolizer_base::cont_type::value_type& prop_;
Attributes const& attrs_;
};
template <typename Attributes>
template<typename Attributes>
struct extract_symbolizer
{
extract_symbolizer(Attributes const& attrs)
: attrs_(attrs) {}
: attrs_(attrs)
{}
template <typename Symbolizer>
void operator() (Symbolizer & sym) const
template<typename Symbolizer>
void operator()(Symbolizer& sym) const
{
for (auto & prop : sym.properties)
for (auto& prop : sym.properties)
{
util::apply_visitor(evaluator<Attributes>(prop, attrs_), prop.second);
}
@ -312,14 +315,14 @@ struct evaluate_global_attributes : util::noncopyable
Attributes const& attrs_;
};
template <typename Attributes>
static void apply(Map & m, Attributes const& attrs)
template<typename Attributes>
static void apply(Map& m, Attributes const& attrs)
{
for ( auto & val : m.styles() )
for (auto& val : m.styles())
{
for (auto & rule : val.second.get_rules_nonconst())
for (auto& rule : val.second.get_rules_nonconst())
{
for (auto & sym : rule)
for (auto& sym : rule)
{
util::apply_visitor(extract_symbolizer<Attributes>(attrs), sym);
}
@ -328,6 +331,6 @@ struct evaluate_global_attributes : util::noncopyable
}
};
}
} // namespace mapnik
#endif // MAPNIK_EVALUATE_GLOBAL_ATTRIBUTES_HPP

View file

@ -34,14 +34,13 @@
#include <string>
#include <set>
namespace mapnik
{
namespace mapnik {
// fwd declare to reduce compile time
using expression_ptr = std::shared_ptr<expr_node>;
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

View file

@ -31,10 +31,9 @@
#include <mapnik/util/variant.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
{
using feature_type = T0;
@ -42,105 +41,85 @@ struct evaluate
using variable_type = T2;
using result_type = T1; // we need this because automatic result_type deduction fails
explicit evaluate(feature_type const& f, variable_type const& v)
: feature_(f),
vars_(v) {}
: feature_(f)
, vars_(v)
{}
value_type operator() (value_integer val) const
{
return val;
}
value_type operator()(value_integer val) const { return val; }
value_type operator() (value_double val) const
{
return val;
}
value_type operator()(value_double val) const { return val; }
value_type operator() (value_bool val) const
{
return val;
}
value_type operator()(value_bool val) const { return val; }
value_type operator() (value_null val) const
{
return val;
}
value_type operator()(value_null val) const { return val; }
value_type operator() (value_unicode_string const& str) const
{
return str;
}
value_type operator()(value_unicode_string const& str) const { return str; }
value_type operator() (attribute const& attr) const
{
return attr.value<value_type,feature_type>(feature_);
}
value_type operator()(attribute const& attr) const { return attr.value<value_type, feature_type>(feature_); }
value_type operator() (global_attribute const& attr) const
value_type operator()(global_attribute const& attr) const
{
auto itr = vars_.find(attr.name);
if (itr != vars_.end())
{
return itr->second;
}
return value_type();// throw?
return value_type(); // throw?
}
value_type operator() (geometry_type_attribute const& geom) const
value_type operator()(geometry_type_attribute const& geom) const
{
return geom.value<value_type,feature_type>(feature_);
return geom.value<value_type, feature_type>(feature_);
}
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())
&& (util::apply_visitor(*this, x.right).to_bool());
return (util::apply_visitor(*this, x.left).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())
|| (util::apply_visitor(*this, x.right).to_bool());
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
}
template <typename Tag>
value_type operator() (binary_node<Tag> const& x) const
template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const
{
typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left),
util::apply_visitor(*this, x.right));
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
}
template <typename Tag>
value_type operator() (unary_node<Tag> const& x) const
template<typename Tag>
value_type operator()(unary_node<Tag> const& x) const
{
typename make_op<Tag>::type func;
return func(util::apply_visitor(*this, x.expr));
}
value_type operator() (unary_node<tags::logical_not> const& x) const
value_type operator()(unary_node<tags::logical_not> const& x) const
{
return ! (util::apply_visitor(*this,x.expr).to_bool());
return !(util::apply_visitor(*this, x.expr).to_bool());
}
value_type operator() (regex_match_node const& x) const
value_type operator()(regex_match_node const& x) const
{
value_type v = util::apply_visitor(*this, x.expr);
return x.apply(v);
}
value_type operator() (regex_replace_node const& x) const
value_type operator()(regex_replace_node const& x) const
{
value_type v = util::apply_visitor(*this, x.expr);
return x.apply(v);
}
value_type operator() (unary_function_call const& call) const
value_type operator()(unary_function_call const& call) const
{
value_type arg = util::apply_visitor(*this, call.arg);
return call.fun(arg);
}
value_type operator() (binary_function_call const& call) const
value_type operator()(binary_function_call const& call) const
{
value_type arg1 = util::apply_visitor(*this, call.arg1);
value_type arg2 = util::apply_visitor(*this, call.arg2);
@ -151,6 +130,6 @@ struct evaluate
variable_type const& vars_;
};
}
} // namespace mapnik
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP

View file

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

View file

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

View file

@ -24,299 +24,272 @@
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
#include <mapnik/expression_grammar_x3.hpp>
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
#include <mapnik/expression_node.hpp>
#include <mapnik/function_call.hpp>
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/warning.hpp>
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/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
BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call,
(mapnik::unary_function_impl, fun)
(mapnik::unary_function_call::argument_type, arg))
(mapnik::unary_function_impl, fun)(mapnik::unary_function_call::argument_type, arg))
BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call,
(mapnik::binary_function_impl, fun)
(mapnik::binary_function_call::argument_type, arg1)
(mapnik::binary_function_call::argument_type, arg2))
(mapnik::binary_function_impl, fun)(mapnik::binary_function_call::argument_type,
arg1)(mapnik::binary_function_call::argument_type, arg2))
namespace mapnik {
namespace grammar {
namespace mapnik { namespace grammar {
namespace x3 = boost::spirit::x3;
namespace ascii = boost::spirit::x3::ascii;
using ascii::char_;
using ascii::string;
using x3::_attr;
using x3::_val;
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{};
namespace x3 = boost::spirit::x3;
namespace ascii = boost::spirit::x3::ascii;
using ascii::char_;
using ascii::string;
using x3::lit;
using x3::double_;
using x3::int_;
using x3::bool_;
using x3::_attr;
using x3::_val;
using x3::no_skip;
using x3::lexeme;
using x3::no_case;
using x3::alpha;
using x3::alnum;
x3::uint_parser<char, 16, 2, 2> const hex2 {};
namespace {
auto const& escaped_unicode = json::grammar::escaped_unicode;
}
namespace {
auto const& escaped_unicode = json::grammar::escaped_unicode;
template<typename Context>
inline mapnik::transcoder const& extract_transcoder(Context const& ctx)
{
return x3::get<transcoder_tag>(ctx);
}
auto append = [](auto const& ctx) {
_val(ctx) += _attr(ctx);
};
auto do_assign = [](auto const& ctx) {
_val(ctx) = std::move(_attr(ctx));
};
auto do_negate = [](auto const& ctx) {
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx)));
};
auto do_attribute = [](auto const& ctx) {
auto const& attr = _attr(ctx);
if (attr == "mapnik::geometry_type")
{
_val(ctx) = std::move(geometry_type_attribute());
}
template <typename Context>
inline mapnik::transcoder const& extract_transcoder(Context const& ctx)
else
{
return x3::get<transcoder_tag>(ctx);
_val(ctx) = std::move(attribute(attr));
}
};
auto append = [](auto const& ctx)
{
_val(ctx) += _attr(ctx);
};
auto do_global_attribute = [](auto const& ctx) {
_val(ctx) = std::move(global_attribute(_attr(ctx)));
};
auto do_assign = [] (auto const& ctx)
{
_val(ctx) = std::move(_attr(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))));
};
auto do_negate = [] (auto const& ctx)
{
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(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))));
};
auto do_attribute = [] (auto const& ctx)
{
auto const& attr = _attr(ctx);
if (attr == "mapnik::geometry_type")
{
_val(ctx) = std::move(geometry_type_attribute());
}
else
{
_val(ctx) = std::move(attribute(attr));
}
};
auto do_mult = [](auto const& ctx) {
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
};
auto do_global_attribute = [] (auto const& ctx)
{
_val(ctx) = std::move(global_attribute(_attr(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))));
};
auto do_add = [] (auto const& ctx)
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(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))));
};
auto do_subt = [] (auto const& ctx)
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx))));
};
auto do_unicode = [](auto const& ctx) {
auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
};
auto do_mult = [] (auto const& ctx)
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
};
auto do_null = [](auto const& ctx) {
_val(ctx) = std::move(mapnik::value_null());
};
auto do_div = [] (auto const& ctx)
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx))));
};
auto do_not = [](auto const& ctx) {
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
_val(ctx) = std::move(node);
};
auto do_mod = [] (auto const& ctx)
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(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))));
};
auto do_unicode = [] (auto const& ctx)
{
auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
};
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))));
};
auto do_null = [] (auto const& ctx)
{
_val(ctx) = std::move(mapnik::value_null());
};
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))));
};
auto do_not = [] (auto const& ctx)
{
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
_val(ctx) = std::move(node);
};
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))));
};
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))));
};
auto do_less = [](auto const& ctx) {
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(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))));
};
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))));
};
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))));
};
auto do_greater = [](auto const& ctx) {
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(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))));
};
auto do_less = [] (auto const& 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)
{
_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)
{
_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)
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
};
auto do_greater_equal = [](auto const& ctx) {
_val(ctx) =
std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
};
// regex
auto do_regex_match = [] (auto const& ctx)
{
auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)) , std::move(_attr(ctx))));
};
auto do_regex_match = [](auto const& ctx) {
auto const& tr = extract_transcoder(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 const& tr = extract_transcoder(ctx);
auto const& pair = _attr(ctx);
auto const& pattern = std::get<0>(pair);
auto const& format = std::get<1>(pair);
_val(ctx) = mapnik::regex_replace_node(tr, _val(ctx) , pattern, format);
};
auto do_regex_replace = [](auto const& ctx) {
auto const& tr = extract_transcoder(ctx);
auto const& pair = _attr(ctx);
auto const& pattern = std::get<0>(pair);
auto const& format = std::get<1>(pair);
_val(ctx) = mapnik::regex_replace_node(tr, _val(ctx), pattern, format);
};
// mapnik::value_integer
auto const mapnik_int = x3::int_parser<value_integer,10,1,-1>();
auto const mapnik_int = x3::int_parser<value_integer, 10, 1, -1>();
// mapnik::value_double
auto const mapnik_double = x3::real_parser<value_double, x3::strict_real_policies<value_double>>();
auto const mapnik_double = x3::real_parser<value_double, x3::strict_real_policies<value_double>>();
// mapnik::value_bool
struct boolean_ : x3::symbols<mapnik::value_bool>
struct boolean_ : x3::symbols<mapnik::value_bool>
{
boolean_()
{
boolean_()
{
add
("true", true)
("false", false)
;
}
} boolean;
add("true", true) //
("false", false) //
;
}
} boolean;
struct floating_point_constants : x3::symbols<mapnik::value_double>
struct floating_point_constants : x3::symbols<mapnik::value_double>
{
floating_point_constants()
{
floating_point_constants()
{
add
("pi", 3.1415926535897932384626433832795)
("deg_to_rad",0.017453292519943295769236907684886)
("rad_to_deg",57.295779513082320876798154814105)
;
}
} float_const;
add("pi", 3.1415926535897932384626433832795) //
("deg_to_rad", 0.017453292519943295769236907684886) //
("rad_to_deg", 57.295779513082320876798154814105) //
;
}
} float_const;
// unary functions
struct unary_function_types_ : x3::symbols<unary_function_impl>
struct unary_function_types_ : x3::symbols<unary_function_impl>
{
unary_function_types_()
{
unary_function_types_()
{
add
("sin", sin_impl())
("cos", cos_impl())
("tan", tan_impl())
("atan", atan_impl())
("exp", exp_impl())
("log", log_impl())
("abs", abs_impl())
("length",length_impl())
;
}
} unary_func_types ;
add("sin", sin_impl()) //
("cos", cos_impl()) //
("tan", tan_impl()) //
("atan", atan_impl()) //
("exp", exp_impl()) //
("log", log_impl()) //
("abs", abs_impl()) //
("length", length_impl()) //
;
}
} unary_func_types;
// 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
("min", binary_function_impl(min_impl))
("max", binary_function_impl(max_impl))
("pow", binary_function_impl(pow_impl))
;
}
} binary_func_types;
add("min", binary_function_impl(min_impl)) //
("max", binary_function_impl(max_impl)) //
("pow", binary_function_impl(pow_impl)) //
;
}
} binary_func_types;
// geometry types
struct geometry_types_ : x3::symbols<mapnik::value_integer>
struct geometry_types_ : x3::symbols<mapnik::value_integer>
{
geometry_types_()
{
geometry_types_()
{
add
("point", 1)
("linestring", 2)
("polygon",3)
("collection",4)
;
}
} geometry_type;
add("point", 1) //
("linestring", 2) //
("polygon", 3) //
("collection", 4) //
;
}
} geometry_type;
struct unesc_chars_ : x3::symbols<char>
struct unesc_chars_ : x3::symbols<char>
{
unesc_chars_()
{
unesc_chars_()
{
add
("\\a", '\a')
("\\b", '\b')
("\\f", '\f')
("\\n", '\n')
("\\r", '\r')
("\\t", '\t')
("\\v", '\v')
("\\\\", '\\')
("\\\'", '\'')
("\\\"", '\"')
;
}
} unesc_char;
// rules
x3::rule<class logical_expression, mapnik::expr_node> const logical_expression("logical expression");
x3::rule<class not_expression, mapnik::expr_node> const not_expression("not expression");
x3::rule<class conditional_expression, mapnik::expr_node> const conditional_expression("conditional 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 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 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 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_replace_expression, std::pair<std::string,std::string> > const regex_replace_expression("regex replace expression");
add("\\a", '\a') //
("\\b", '\b') //
("\\f", '\f') //
("\\n", '\n') //
("\\r", '\r') //
("\\t", '\t') //
("\\v", '\v') //
("\\\\", '\\') //
("\\\'", '\'') //
("\\\"", '\"') //
;
}
} unesc_char;
// rules
x3::rule<class logical_expression, mapnik::expr_node> const logical_expression("logical expression");
x3::rule<class not_expression, mapnik::expr_node> const not_expression("not expression");
x3::rule<class conditional_expression, mapnik::expr_node> const conditional_expression("conditional 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 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 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 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_replace_expression, std::pair<std::string, std::string>> const
regex_replace_expression("regex replace expression");
// clang-format off
// strings
auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'')
>> no_skip[*(unesc_char[append]
@ -431,24 +404,23 @@ namespace mapnik { namespace grammar {
unquoted_ustring[do_unicode]
// ^ https://github.com/mapnik/mapnik/pull/3389
;
// clang-format on
BOOST_SPIRIT_DEFINE(expression,
logical_expression,
not_expression,
conditional_expression,
equality_expression,
relational_expression,
additive_expression,
regex_match_expression,
regex_replace_expression,
multiplicative_expression,
unary_func_expression,
binary_func_expression,
unary_expression,
primary_expression);
BOOST_SPIRIT_DEFINE (
expression,
logical_expression,
not_expression,
conditional_expression,
equality_expression,
relational_expression,
additive_expression,
regex_match_expression,
regex_replace_expression,
multiplicative_expression,
unary_func_expression,
binary_func_expression,
unary_expression,
primary_expression
);
} // namespace grammar
} // namespace mapnik
}}
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP

View file

@ -34,61 +34,119 @@
// stl
#include <memory>
namespace mapnik
{
namespace mapnik {
using value_type = mapnik::value;
template <typename Tag> struct make_op;
template <> struct make_op<mapnik::tags::negate> { using type = std::negate<value_type>;};
template <> struct make_op<mapnik::tags::plus> { using type = std::plus<value_type>;};
template <> struct make_op<mapnik::tags::minus> { 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>
struct make_op;
template<>
struct make_op<mapnik::tags::negate>
{
using type = std::negate<value_type>;
};
template<>
struct make_op<mapnik::tags::plus>
{
using type = std::plus<value_type>;
};
template<>
struct make_op<mapnik::tags::minus>
{
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
{
unary_node (expr_node && a)
: expr(std::move(a)) {}
unary_node(expr_node&& a)
: expr(std::move(a))
{}
unary_node (expr_node const& a)
: expr(a) {}
unary_node(expr_node const& a)
: expr(a)
{}
static const char* type()
{
return Tag::str();
}
static const char* type() { return Tag::str(); }
expr_node expr;
};
template <typename Tag>
template<typename Tag>
struct binary_node
{
binary_node(expr_node && a, expr_node && b)
: left(std::move(a)),
right(std::move(b)) {}
binary_node(expr_node&& a, expr_node&& b)
: left(std::move(a))
, right(std::move(b))
{}
binary_node(expr_node const& a, expr_node const& b)
: left(a),
right(b) {}
: left(a)
, right(b)
{}
static const char* type()
{
return Tag::str();
}
expr_node left,right;
static const char* type() { return Tag::str(); }
expr_node left, right;
};
struct unary_function_call
@ -96,7 +154,9 @@ struct unary_function_call
using argument_type = expr_node;
unary_function_call() = default;
unary_function_call(unary_function_impl _fun, argument_type const& _arg)
: fun(_fun), arg(_arg) {}
: fun(_fun)
, arg(_arg)
{}
unary_function_impl fun;
argument_type arg;
@ -107,7 +167,10 @@ struct binary_function_call
using argument_type = expr_node;
binary_function_call() = default;
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;
argument_type arg1;
argument_type arg2;
@ -137,7 +200,6 @@ struct MAPNIK_DECL regex_replace_node
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/util/variant.hpp>
namespace mapnik
{
namespace mapnik {
namespace tags {
namespace tags {
struct negate
{
static const char* str()
{
return "-";
}
static const char* str() { return "-"; }
};
struct plus
{
static const char* str()
{
return "+";
}
static const char* str() { return "+"; }
};
struct minus
{
static const char* str()
{
return "-";
}
static const char* str() { return "-"; }
};
struct mult
{
static const char* str()
{
return "*";
}
static const char* str() { return "*"; }
};
struct div
{
static const char* str()
{
return "/";
}
static const char* str() { return "/"; }
};
struct mod
struct mod
{
static const char* str()
{
return "%";
}
static const char* str() { return "%"; }
};
struct less
{
static const char* str()
{
return "<";
}
static const char* str() { return "<"; }
};
struct less_equal
{
static const char* str()
{
return "<=";
}
static const char* str() { return "<="; }
};
struct greater
{
static const char* str()
{
return ">";
}
static const char* str() { return ">"; }
};
struct greater_equal
{
static const char* str()
{
return ">=";
}
static const char* str() { return ">="; }
};
struct equal_to
{
static const char* str()
{
return "=";
}
static const char* str() { return "="; }
};
struct not_equal_to
{
static const char* str()
{
return "!=";
}
static const char* str() { return "!="; }
};
struct logical_not
{
static const char* str()
{
return "not ";
}
static const char* str() { return "not "; }
};
struct logical_and
{
static const char* str()
{
return " and ";
}
static const char* str() { return " and "; }
};
struct logical_or
{
static const char* str()
{
return " or ";
}
static const char* str() { return " or "; }
};
} // end operation tags
} // namespace tags
template <typename Tag> struct binary_node;
template <typename Tag> struct unary_node;
template<typename Tag>
struct binary_node;
template<typename Tag>
struct unary_node;
struct regex_match_node;
struct regex_replace_node;
struct attribute;
@ -166,37 +120,34 @@ struct geometry_type_attribute;
struct unary_function_call;
struct binary_function_call;
using expr_node = util::variant<
value_null,
value_bool,
value_integer,
value_double,
value_unicode_string,
attribute,
global_attribute,
geometry_type_attribute,
util::recursive_wrapper<unary_node<mapnik::tags::negate> >,
util::recursive_wrapper<binary_node<mapnik::tags::plus> >,
util::recursive_wrapper<binary_node<mapnik::tags::minus> >,
util::recursive_wrapper<binary_node<mapnik::tags::mult> >,
util::recursive_wrapper<binary_node<mapnik::tags::div> >,
util::recursive_wrapper<binary_node<mapnik::tags::mod> >,
util::recursive_wrapper<binary_node<mapnik::tags::less> >,
util::recursive_wrapper<binary_node<mapnik::tags::less_equal> >,
util::recursive_wrapper<binary_node<mapnik::tags::greater> >,
util::recursive_wrapper<binary_node<mapnik::tags::greater_equal> >,
util::recursive_wrapper<binary_node<mapnik::tags::equal_to> >,
util::recursive_wrapper<binary_node<mapnik::tags::not_equal_to> >,
util::recursive_wrapper<unary_node<mapnik::tags::logical_not> >,
util::recursive_wrapper<binary_node<mapnik::tags::logical_and> >,
util::recursive_wrapper<binary_node<mapnik::tags::logical_or> >,
util::recursive_wrapper<regex_match_node>,
util::recursive_wrapper<regex_replace_node>,
util::recursive_wrapper<unary_function_call>,
util::recursive_wrapper<binary_function_call>
>;
}
using expr_node = util::variant<value_null,
value_bool,
value_integer,
value_double,
value_unicode_string,
attribute,
global_attribute,
geometry_type_attribute,
util::recursive_wrapper<unary_node<mapnik::tags::negate>>,
util::recursive_wrapper<binary_node<mapnik::tags::plus>>,
util::recursive_wrapper<binary_node<mapnik::tags::minus>>,
util::recursive_wrapper<binary_node<mapnik::tags::mult>>,
util::recursive_wrapper<binary_node<mapnik::tags::div>>,
util::recursive_wrapper<binary_node<mapnik::tags::mod>>,
util::recursive_wrapper<binary_node<mapnik::tags::less>>,
util::recursive_wrapper<binary_node<mapnik::tags::less_equal>>,
util::recursive_wrapper<binary_node<mapnik::tags::greater>>,
util::recursive_wrapper<binary_node<mapnik::tags::greater_equal>>,
util::recursive_wrapper<binary_node<mapnik::tags::equal_to>>,
util::recursive_wrapper<binary_node<mapnik::tags::not_equal_to>>,
util::recursive_wrapper<unary_node<mapnik::tags::logical_not>>,
util::recursive_wrapper<binary_node<mapnik::tags::logical_and>>,
util::recursive_wrapper<binary_node<mapnik::tags::logical_or>>,
util::recursive_wrapper<regex_match_node>,
util::recursive_wrapper<regex_replace_node>,
util::recursive_wrapper<unary_function_call>,
util::recursive_wrapper<binary_function_call>>;
} // namespace mapnik
#endif // MAPNIK_EXPRESSION_NODE_HPP

View file

@ -35,8 +35,7 @@
#include <string>
#include <stdexcept>
namespace mapnik
{
namespace mapnik {
MAPNIK_DECL std::string to_expression_string(expr_node const& node);
/*
@ -48,7 +47,7 @@ implicit pointer-to-bool conversion, thus any non-null pointer
would yield "true".
*/
template <typename T>
template<typename T>
std::string to_expression_string(T const* expr_node_ptr)
{
throw std::logic_error("to_expression_string() called with pointer argument");
@ -56,13 +55,13 @@ std::string to_expression_string(T const* expr_node_ptr)
return expr_node_ptr; // to_expression_string() called with pointer argument
}
template <typename T>
template<typename T>
std::string to_expression_string(std::shared_ptr<T> const& expr_node_ptr)
{
throw std::logic_error("to_expression_string() called with pointer argument");
// compile error intended here; comment on the next line shows in clang output
return expr_node_ptr; // to_expression_string() called with pointer argument
}
}
} // namespace mapnik
#endif // MAPNIK_EXPRESSION_STRING_HPP

View file

@ -38,108 +38,122 @@ MAPNIK_DISABLE_WARNING_POP
// stl
#include <cmath>
namespace mapnik
{
namespace mapnik {
namespace detail
{
namespace detail {
namespace msm = boost::msm;
namespace mpl = boost::mpl;
using namespace msm::front;
template <typename T>
T extend(T const & v1, T const & v2, double length)
template<typename T>
T extend(T const& v1, T const& v2, double length)
{
double dx = v2.x - v1.x;
double dy = v2.y - v1.y;
double l12 = std::sqrt(dx * dx + dy * dy);
double coef = 1.0 + length / l12;
return vertex2d(v1.x + dx * coef,
v1.y + dy * coef, v2.cmd);
return vertex2d(v1.x + dx * coef, v1.y + dy * coef, v2.cmd);
}
namespace events
namespace events {
struct vertex_event
{
struct vertex_event
{
vertex_event(vertex2d const & vertex) : vertex(vertex) { }
vertex2d const & vertex;
};
vertex_event(vertex2d const& vertex)
: vertex(vertex)
{}
vertex2d const& vertex;
};
struct move_to : vertex_event { 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 actions
struct move_to : vertex_event
{
struct store
{
template <class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
{
m.v2 = m.v1;
m.v1 = e.vertex;
m.output = boost::none;
}
};
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
struct output
namespace actions {
struct store
{
template<class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
{
template <class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
{
m.output = e.vertex;
}
};
m.v2 = m.v1;
m.v1 = e.vertex;
m.output = boost::none;
}
};
struct store_and_output
struct output
{
template<class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
{
template <class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
{
m.v2 = m.v1;
m.v1 = e.vertex;
m.output = m.v2;
}
};
m.output = e.vertex;
}
};
struct output_begin
struct store_and_output
{
template<class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
{
template <class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
{
m.v2 = m.v1;
m.v1 = e.vertex;
m.output = extend(m.v1, m.v2, m.extend_length);
}
};
m.v2 = m.v1;
m.v1 = e.vertex;
m.output = m.v2;
}
};
struct output_end
struct output_begin
{
template<class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
{
template <class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
{
m.output = extend(m.v2, m.v1, m.extend_length);
m.v1 = e.vertex;
}
};
}
m.v2 = m.v1;
m.v1 = e.vertex;
m.output = extend(m.v1, m.v2, m.extend_length);
}
};
struct output_end
{
template<class FSM, class EVT, class SourceState, class TargetState>
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
{
m.output = extend(m.v2, m.v1, m.extend_length);
m.v1 = e.vertex;
}
};
} // namespace actions
struct extender_def : public msm::front::state_machine_def<extender_def>
{
using no_exception_thrown = int;
using no_message_queue = int;
struct initial : public msm::front::state<> { };
struct vertex_one : public msm::front::state<> { };
struct vertex_two : public msm::front::state<> { };
struct end : 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 end : public msm::front::state<>
{};
using initial_state = initial;
// clang-format off
struct transition_table : mpl::vector<
// 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 < end , events::end , end , actions::output >
> {};
// clang-format on
extender_def(double extend_length)
: extend_length(extend_length)
{
}
{}
boost::optional<vertex2d> output;
vertex2d v1, v2;
@ -170,25 +184,23 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
using extender = msm::back::state_machine<extender_def>;
}
} // namespace detail
template <typename Geometry>
template<typename Geometry>
struct extend_converter
{
extend_converter(Geometry & geom)
extend_converter(Geometry& geom)
: extend_converter(geom, 0)
{}
extend_converter(Geometry & geom, double extend)
: geom_(geom), extender_(extend)
extend_converter(Geometry& geom, double extend)
: geom_(geom)
, extender_(extend)
{}
void set_extend(double extend)
{
extender_.extend_length = extend;
}
void set_extend(double extend) { extender_.extend_length = extend; }
unsigned vertex(double * x, double * y)
unsigned vertex(double* x, double* y)
{
using namespace detail;
vertex2d v;
@ -210,9 +222,9 @@ struct extend_converter
extender_.process_event(events::end(v));
break;
}
} while(!extender_.output);
} while (!extender_.output);
vertex2d const & output = *extender_.output;
vertex2d const& output = *extender_.output;
*x = output.x;
*y = output.y;
return output.cmd;
@ -224,11 +236,11 @@ struct extend_converter
extender_.start();
}
private:
Geometry & geom_;
private:
Geometry& geom_;
detail::extender extender_;
};
}
} // namespace mapnik
#endif // MAPNIK_EXTEND_CONVERTER_HPP

View file

@ -32,41 +32,33 @@
namespace mapnik {
template
<
typename product_type,
typename key_type,
typename ...Args >
class factory : public singleton<factory <product_type,
key_type,
Args...> >
template<typename product_type, typename key_type, typename... Args>
class factory : public singleton<factory<product_type, key_type, Args...>>
{
private:
using product_creator = product_type* (*) (Args...);
using product_map = std::map<key_type,product_creator>;
private:
using product_creator = product_type* (*)(Args...);
using product_map = std::map<key_type, product_creator>;
product_map map_;
public:
public:
bool register_product(key_type const& key, product_creator creator)
{
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)
{
return map_.erase(key)==1;
}
bool unregister_product(const key_type& key) { 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)
{
typename product_map::const_iterator pos=map_.find(key);
if (pos!=map_.end())
typename product_map::const_iterator pos = map_.find(key);
if (pos != map_.end())
{
return (pos->second)(args...);
}
return 0;
}
};
}
} // namespace mapnik
#endif // MAPNIK_FACTORY_HPP

View file

@ -38,9 +38,9 @@
#include <memory>
#include <vector>
#include <map>
#include <ostream> // for basic_ostream, operator<<, etc
#include <sstream> // for basic_stringstream
#include <stdexcept> // for out_of_range
#include <ostream> // for basic_ostream, operator<<, etc
#include <sstream> // for basic_stringstream
#include <stdexcept> // for out_of_range
#include <iostream>
namespace mapnik {
@ -50,12 +50,13 @@ class feature_impl;
using raster_ptr = std::shared_ptr<raster>;
template <typename T>
template<typename T>
class context : private util::noncopyable
{
friend class feature_impl;
public:
public:
using map_type = T;
using value_type = typename map_type::value_type;
using key_type = typename map_type::key_type;
@ -65,7 +66,8 @@ public:
using const_iterator = typename map_type::const_iterator;
context()
: mapping_() {}
: mapping_()
{}
inline size_type push(key_type const& name)
{
@ -74,20 +76,17 @@ public:
return index;
}
inline void add(key_type const& name, size_type index)
{
mapping_.emplace(name, index);
}
inline void add(key_type const& name, size_type index) { mapping_.emplace(name, index); }
inline size_type size() const { return mapping_.size(); }
inline const_iterator begin() const { return mapping_.begin();}
inline const_iterator end() const { return mapping_.end();}
inline const_iterator begin() const { return mapping_.begin(); }
inline const_iterator end() const { return mapping_.end(); }
private:
private:
map_type mapping_;
};
using context_type = context<std::map<std::string,std::size_t> >;
using context_type = context<std::map<std::string, std::size_t>>;
using context_ptr = std::shared_ptr<context_type>;
static const value default_feature_value{};
@ -95,38 +94,39 @@ static const value default_feature_value{};
class MAPNIK_DECL feature_impl : private util::noncopyable
{
friend class feature_kv_iterator;
public:
public:
using value_type = mapnik::value;
using cont_type = std::vector<value_type>;
using iterator = feature_kv_iterator;
feature_impl(context_ptr const& ctx, mapnik::value_integer _id)
: id_(_id),
ctx_(ctx),
data_(ctx_->mapping_.size()),
geom_(geometry::geometry_empty()),
raster_() {}
: id_(_id)
, ctx_(ctx)
, data_(ctx_->mapping_.size())
, geom_(geometry::geometry_empty())
, raster_()
{}
inline mapnik::value_integer id() const { return id_;}
inline void set_id(mapnik::value_integer _id) { id_ = _id;}
template <typename T>
inline mapnik::value_integer id() const { return id_; }
inline void set_id(mapnik::value_integer _id) { id_ = _id; }
template<typename T>
inline void put(context_type::key_type const& key, T const& val)
{
put(key, value(val));
}
template <typename T>
template<typename T>
inline void put_new(context_type::key_type const& key, T const& val)
{
put_new(key, value(val));
}
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);
if (itr != ctx_->mapping_.end()
&& itr->second < data_.size())
if (itr != ctx_->mapping_.end() && itr->second < data_.size())
{
data_[itr->second] = std::move(val);
}
@ -136,11 +136,10 @@ 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);
if (itr != ctx_->mapping_.end()
&& itr->second < data_.size())
if (itr != ctx_->mapping_.end() && itr->second < data_.size())
{
data_[itr->second] = std::move(val);
}
@ -152,10 +151,7 @@ public:
}
}
inline bool has_key(context_type::key_type const& key) const
{
return (ctx_->mapping_.count(key) == 1);
}
inline bool has_key(context_type::key_type const& key) const { return (ctx_->mapping_.count(key) == 1); }
inline value_type const& get(context_type::key_type const& key) const
{
@ -173,70 +169,31 @@ public:
return default_feature_value;
}
inline std::size_t size() const
{
return data_.size();
}
inline std::size_t size() const { return data_.size(); }
inline cont_type const& get_data() const
{
return data_;
}
inline cont_type const& get_data() const { return data_; }
inline void set_data(cont_type const& data)
{
data_ = data;
}
inline void set_data(cont_type const& data) { data_ = data; }
inline context_ptr context() const
{
return ctx_;
}
inline context_ptr context() const { return ctx_; }
inline void set_geometry(geometry::geometry<double> && geom)
{
geom_ = std::move(geom);
}
inline void set_geometry(geometry::geometry<double>&& geom) { geom_ = std::move(geom); }
inline void set_geometry_copy(geometry::geometry<double> const& geom)
{
geom_ = geom;
}
inline void set_geometry_copy(geometry::geometry<double> const& geom) { geom_ = geom; }
inline geometry::geometry<double> const& get_geometry() const
{
return geom_;
}
inline geometry::geometry<double> const& get_geometry() const { return geom_; }
inline geometry::geometry<double> & get_geometry()
{
return geom_;
}
inline geometry::geometry<double>& get_geometry() { return geom_; }
inline box2d<double> envelope() const
{
return mapnik::geometry::envelope(geom_);
}
inline box2d<double> envelope() const { return mapnik::geometry::envelope(geom_); }
inline raster_ptr const& get_raster() const
{
return raster_;
}
inline raster_ptr const& get_raster() const { return raster_; }
inline void set_raster(raster_ptr const& raster)
{
raster_ = raster;
}
inline void set_raster(raster_ptr const& raster) { raster_ = raster; }
inline feature_kv_iterator begin() const
{
return feature_kv_iterator(*this,true);
}
inline feature_kv_iterator begin() const { return feature_kv_iterator(*this, true); }
inline feature_kv_iterator end() const
{
return feature_kv_iterator(*this);
}
inline feature_kv_iterator end() const { return feature_kv_iterator(*this); }
std::string to_string() const
{
@ -249,11 +206,11 @@ public:
{
if (data_[kv.second] == mapnik::value_null())
{
ss << " " << kv.first << ":null" << std::endl;
ss << " " << kv.first << ":null" << std::endl;
}
else
{
ss << " " << kv.first << ":" << data_[kv.second] << std::endl;
ss << " " << kv.first << ":" << data_[kv.second] << std::endl;
}
}
}
@ -261,7 +218,7 @@ public:
return ss.str();
}
private:
private:
mapnik::value_integer id_;
context_ptr ctx_;
cont_type data_;
@ -269,8 +226,7 @@ private:
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();
return out;
@ -278,6 +234,6 @@ inline std::ostream& operator<< (std::ostream & out,feature_impl const& f)
using feature_ptr = std::shared_ptr<feature_impl>;
}
} // namespace mapnik
#endif // MAPNIK_FEATURE_HPP

View file

@ -30,17 +30,16 @@
// boost
//#include <boost/pool/pool_alloc.hpp>
namespace mapnik
{
namespace mapnik {
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)
{
//return boost::allocate_shared<feature_impl>(boost::pool_allocator<feature_impl>(),fid);
//return boost::allocate_shared<feature_impl>(boost::fast_pool_allocator<feature_impl>(),fid);
return std::make_shared<feature_impl>(ctx,fid);
// return boost::allocate_shared<feature_impl>(boost::pool_allocator<feature_impl>(),fid);
// return boost::allocate_shared<feature_impl>(boost::fast_pool_allocator<feature_impl>(),fid);
return std::make_shared<feature_impl>(ctx, fid);
}
};
}
} // namespace mapnik
#endif // MAPNIK_FEATURE_FACTORY_HPP

View file

@ -45,32 +45,31 @@ namespace mapnik {
class feature_impl;
class MAPNIK_DECL feature_kv_iterator :
public boost::iterator_facade<feature_kv_iterator,
std::tuple<std::string, value> const,
boost::forward_traversal_tag>
class MAPNIK_DECL feature_kv_iterator : public boost::iterator_facade<feature_kv_iterator,
std::tuple<std::string, value> const,
boost::forward_traversal_tag>
{
public:
using value_type = std::tuple<std::string,value>;
feature_kv_iterator (feature_impl const& f, bool begin = false);
private:
public:
using value_type = std::tuple<std::string, value>;
feature_kv_iterator(feature_impl const& f, bool begin = false);
private:
friend class boost::iterator_core_access;
void increment();
void decrement();
void advance(boost::iterator_difference<feature_kv_iterator>::type);
bool equal( feature_kv_iterator const& other) const;
bool equal(feature_kv_iterator const& other) const;
value_type const& dereference() const;
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_;
};
struct value_not_null
{
bool operator() (feature_kv_iterator::value_type const& kv) const
bool operator()(feature_kv_iterator::value_type const& kv) const
{
return !util::apply_visitor(mapnik::detail::is_null_visitor(), std::get<1>(kv));
}
@ -78,6 +77,6 @@ struct value_not_null
using feature_kv_iterator2 = boost::filter_iterator<value_not_null, feature_kv_iterator>;
}
} // namespace mapnik
#endif // MAPNIK_FEATURE_KV_ITERATOR_HPP

View file

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

View file

@ -34,8 +34,7 @@
#include <set>
#include <string>
namespace mapnik
{
namespace mapnik {
class Map;
class layer;
@ -45,36 +44,29 @@ class feature_type_style;
class rule_cache;
struct layer_rendering_material;
enum eAttributeCollectionPolicy
{
DEFAULT = 0,
COLLECT_ALL = 1
};
enum eAttributeCollectionPolicy { DEFAULT = 0, COLLECT_ALL = 1 };
template <typename Processor>
template<typename Processor>
class feature_style_processor
{
public:
explicit feature_style_processor(Map const& m,
double scale_factor = 1.0);
public:
explicit feature_style_processor(Map const& m, double scale_factor = 1.0);
/*!
* \brief apply renderer to all map layers.
*/
void apply(double scale_denom_override=0.0);
void apply(double scale_denom_override = 0.0);
/*!
* \brief apply renderer to a single layer, providing pre-populated set of query attribute names.
*/
void apply(mapnik::layer const& lyr,
std::set<std::string>& names,
double scale_denom_override=0.0);
void apply(mapnik::layer const& lyr, std::set<std::string>& names, double scale_denom_override = 0.0);
/*!
* \brief render a layer given a projection and scale.
*/
void apply_to_layer(layer const& lay,
Processor & p,
Processor& p,
projection const& proj0,
double scale,
double scale_denom,
@ -84,28 +76,28 @@ public:
int buffer_size,
std::set<std::string>& names);
private:
private:
/*!
* \brief renders a featureset with the given styles.
*/
void render_style(Processor & p,
void render_style(Processor& p,
feature_type_style const* style,
rule_cache const& rules,
featureset_ptr features,
proj_transform const& prj_trans);
void prepare_layers(layer_rendering_material & parent_mat,
std::vector<layer> const & layers,
feature_style_context_map & ctx_map,
Processor & p,
void prepare_layers(layer_rendering_material& parent_mat,
std::vector<layer> const& layers,
feature_style_context_map& ctx_map,
Processor& p,
double scale_denom);
/*!
* \brief prepare features for rendering asynchronously.
*/
void prepare_layer(layer_rendering_material & mat,
feature_style_context_map & ctx_map,
Processor & p,
void prepare_layer(layer_rendering_material& mat,
feature_style_context_map& ctx_map,
Processor& p,
double scale,
double scale_denom,
unsigned width,
@ -117,11 +109,11 @@ private:
/*!
* \brief render features list queued when they are available.
*/
void render_material(layer_rendering_material const & mat, Processor & p );
void render_submaterials(layer_rendering_material const & mat, Processor & p);
void render_material(layer_rendering_material const& mat, Processor& p);
void render_submaterials(layer_rendering_material const& mat, Processor& p);
Map const& m_;
};
}
} // namespace mapnik
#endif // MAPNIK_FEATURE_STYLE_PROCESSOR_HPP

View file

@ -30,15 +30,15 @@
namespace mapnik {
class IProcessorContext {
public:
class IProcessorContext
{
public:
virtual ~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

View file

@ -50,8 +50,7 @@
#include <vector>
#include <stdexcept>
namespace mapnik
{
namespace mapnik {
// Store material for layer rendering in a two step process
struct layer_rendering_material
@ -66,14 +65,15 @@ struct layer_rendering_material
std::vector<layer_rendering_material> materials_;
layer_rendering_material(layer const& lay, projection const& dest)
: lay_(lay),
proj0_(dest),
proj1_(lay.srs(), true) {}
: lay_(lay)
, proj0_(dest)
, proj1_(lay.srs(), true)
{}
layer_rendering_material(layer_rendering_material && rhs) = default;
layer_rendering_material(layer_rendering_material&& rhs) = default;
};
template <typename Processor>
template<typename Processor>
feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor)
: m_(m)
{
@ -84,11 +84,11 @@ feature_style_processor<Processor>::feature_style_processor(Map const& m, double
}
}
template <typename Processor>
void feature_style_processor<Processor>::prepare_layers(layer_rendering_material & parent_mat,
std::vector<layer> const & layers,
feature_style_context_map & ctx_map,
Processor & p,
template<typename Processor>
void feature_style_processor<Processor>::prepare_layers(layer_rendering_material& parent_mat,
std::vector<layer> const& layers,
feature_style_context_map& ctx_map,
Processor& p,
double scale_denom)
{
for (layer const& lyr : layers)
@ -119,15 +119,15 @@ void feature_style_processor<Processor>::prepare_layers(layer_rendering_material
}
}
template <typename Processor>
template<typename Processor>
void feature_style_processor<Processor>::apply(double scale_denom)
{
Processor & p = static_cast<Processor&>(*this);
Processor& p = static_cast<Processor&>(*this);
p.start_map_processing(m_);
projection proj(m_.srs(),true);
projection proj(m_.srs(), true);
if (scale_denom <= 0.0)
scale_denom = mapnik::scale_denominator(m_.scale(),proj.is_geographic());
scale_denom = mapnik::scale_denominator(m_.scale(), proj.is_geographic());
scale_denom *= p.scale_factor(); // FIXME - we might want to comment this out
// Asynchronous query supports:
@ -151,16 +151,16 @@ void feature_style_processor<Processor>::apply(double scale_denom)
p.end_map_processing(m_);
}
template <typename Processor>
template<typename Processor>
void feature_style_processor<Processor>::apply(mapnik::layer const& lyr,
std::set<std::string>& names,
double scale_denom)
{
Processor & p = static_cast<Processor&>(*this);
Processor& p = static_cast<Processor&>(*this);
p.start_map_processing(m_);
projection proj(m_.srs(),true);
projection proj(m_.srs(), true);
if (scale_denom <= 0.0)
scale_denom = mapnik::scale_denominator(m_.scale(),proj.is_geographic());
scale_denom = mapnik::scale_denominator(m_.scale(), proj.is_geographic());
scale_denom *= p.scale_factor();
if (lyr.visible(scale_denom))
@ -182,9 +182,9 @@ void feature_style_processor<Processor>::apply(mapnik::layer const& lyr,
/*!
* \brief render a layer given a projection and scale.
*/
template <typename Processor>
template<typename Processor>
void feature_style_processor<Processor>::apply_to_layer(layer const& lay,
Processor & p,
Processor& p,
projection const& proj0,
double scale,
double scale_denom,
@ -195,18 +195,9 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay,
std::set<std::string>& names)
{
feature_style_context_map ctx_map;
layer_rendering_material mat(lay, proj0);
layer_rendering_material mat(lay, proj0);
prepare_layer(mat,
ctx_map,
p,
scale,
scale_denom,
width,
height,
extent,
buffer_size,
names);
prepare_layer(mat, ctx_map, p, scale, scale_denom, width, height, extent, buffer_size, names);
prepare_layers(mat, lay.layers(), ctx_map, p, scale_denom);
@ -214,17 +205,17 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay,
{
p.start_layer_processing(mat.lay_, mat.layer_ext2_);
render_material(mat,p);
render_material(mat, p);
render_submaterials(mat, p);
p.end_layer_processing(mat.lay_);
}
}
template <typename Processor>
void feature_style_processor<Processor>::prepare_layer(layer_rendering_material & mat,
feature_style_context_map & ctx_map,
Processor & p,
template<typename Processor>
void feature_style_processor<Processor>::prepare_layer(layer_rendering_material& mat,
feature_style_context_map& ctx_map,
Processor& p,
double scale,
double scale_denom,
unsigned width,
@ -240,23 +231,21 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
std::size_t num_styles = style_names.size();
if (num_styles == 0)
{
MAPNIK_LOG_DEBUG(feature_style_processor)
<< "feature_style_processor: No style for layer=" << lay.name();
MAPNIK_LOG_DEBUG(feature_style_processor) << "feature_style_processor: No style for layer=" << lay.name();
return;
}
mapnik::datasource_ptr ds = lay.datasource();
if (!ds)
{
MAPNIK_LOG_DEBUG(feature_style_processor)
<< "feature_style_processor: No datasource for layer=" << lay.name();
MAPNIK_LOG_DEBUG(feature_style_processor) << "feature_style_processor: No datasource for layer=" << lay.name();
return;
}
processor_context_ptr current_ctx = ds->get_context(ctx_map);
proj_transform const* proj_trans_ptr = proj_transform_cache::get(mat.proj0_.params(), mat.proj1_.params());
box2d<double> query_ext = extent; // unbuffered
box2d<double> buffered_query_ext(query_ext); // buffered
box2d<double> query_ext = extent; // unbuffered
box2d<double> buffered_query_ext(query_ext); // buffered
double buffer_padding = 2.0 * scale * p.scale_factor();
boost::optional<int> layer_buffer_size = lay.buffer_size();
@ -272,7 +261,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
buffered_query_ext.height(query_ext.height() + buffer_padding);
// clip buffered extent by maximum extent, if supplied
boost::optional<box2d<double> > const& maximum_extent = m_.maximum_extent();
boost::optional<box2d<double>> const& maximum_extent = m_.maximum_extent();
if (maximum_extent)
{
buffered_query_ext.clip(*maximum_extent);
@ -295,16 +284,16 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
early_return = true;
}
// 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);
// 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)
<< "feature_style_processor: Layer=" << lay.name()
<< " extent=" << layer_ext << " in map projection "
<< " did not reproject properly back to layer projection";
<< "feature_style_processor: Layer=" << lay.name() << " extent=" << layer_ext << " in map projection "
<< " did not reproject properly back to layer projection";
}
}
else
@ -313,7 +302,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
early_return = true;
}
std::vector<feature_type_style const*> & active_styles = mat.active_styles_;
std::vector<feature_type_style const*>& active_styles = mat.active_styles_;
if (early_return)
{
@ -321,7 +310,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
// https://github.com/mapnik/mapnik/issues/1477
for (std::string const& style_name : style_names)
{
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)
{
continue;
@ -346,7 +335,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
query_ext.clip(*maximum_extent);
}
box2d<double> & layer_ext2 = mat.layer_ext2_;
box2d<double>& layer_ext2 = mat.layer_ext2_;
layer_ext2 = lay.envelope();
if (fw_success)
@ -365,18 +354,17 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
}
}
std::vector<rule_cache> & rule_caches = mat.rule_caches_;
std::vector<rule_cache>& rule_caches = mat.rule_caches_;
attribute_collector collector(names);
// iterate through all named styles collecting active styles and attribute names
for (std::string const& style_name : style_names)
{
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)
{
MAPNIK_LOG_ERROR(feature_style_processor)
<< "feature_style_processor: Style=" << style_name
<< " required for layer=" << lay.name() << " does not exist.";
MAPNIK_LOG_ERROR(feature_style_processor) << "feature_style_processor: Style=" << style_name
<< " required for layer=" << lay.name() << " does not exist.";
continue;
}
@ -384,7 +372,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
std::vector<rule> const& style_rules = style->get_rules();
bool active_rules = false;
rule_cache rc;
for(rule const& r : style_rules)
for (rule const& r : style_rules)
{
if (r.active(scale_denom))
{
@ -406,12 +394,11 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
return;
}
double qw = query_ext.width()>0 ? query_ext.width() : 1;
double qh = query_ext.height()>0 ? query_ext.height() : 1;
query::resolution_type res(width/qw,
height/qh);
double qw = query_ext.width() > 0 ? query_ext.width() : 1;
double qh = query_ext.height() > 0 ? query_ext.height() : 1;
query::resolution_type res(width / qw, height / qh);
query q(layer_ext,res,scale_denom,extent);
query q(layer_ext, res, scale_denom, extent);
q.set_variables(p.variables());
if (p.attribute_collection_policy() == COLLECT_ALL)
@ -440,25 +427,24 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
bool cache_features = lay.cache_features() && active_styles.size() > 1;
std::vector<featureset_ptr> & featureset_ptr_list = mat.featureset_ptr_list_;
std::vector<featureset_ptr>& featureset_ptr_list = mat.featureset_ptr_list_;
if (!group_by.empty() || cache_features)
{
featureset_ptr_list.push_back(ds->features_with_context(q,current_ctx));
featureset_ptr_list.push_back(ds->features_with_context(q, current_ctx));
}
else
{
for(std::size_t i = 0; i < active_styles.size(); ++i)
for (std::size_t i = 0; i < active_styles.size(); ++i)
{
featureset_ptr_list.push_back(ds->features_with_context(q,current_ctx));
featureset_ptr_list.push_back(ds->features_with_context(q, current_ctx));
}
}
}
template <typename Processor>
void feature_style_processor<Processor>::render_submaterials(layer_rendering_material const & parent_mat,
Processor & p)
template<typename Processor>
void feature_style_processor<Processor>::render_submaterials(layer_rendering_material const& parent_mat, Processor& p)
{
for (layer_rendering_material const & mat : parent_mat.materials_)
for (layer_rendering_material const& mat : parent_mat.materials_)
{
if (!mat.active_styles_.empty())
{
@ -472,12 +458,11 @@ void feature_style_processor<Processor>::render_submaterials(layer_rendering_mat
}
}
template <typename Processor>
void feature_style_processor<Processor>::render_material(layer_rendering_material const & mat,
Processor & p)
template<typename Processor>
void feature_style_processor<Processor>::render_material(layer_rendering_material const& mat, Processor& p)
{
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<feature_type_style const*> const& active_styles = mat.active_styles_;
std::vector<featureset_ptr> const& featureset_ptr_list = mat.featureset_ptr_list_;
if (featureset_ptr_list.empty())
{
// The datasource wasn't queried because of early return
@ -492,7 +477,7 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
layer const& lay = mat.lay_;
std::vector<rule_cache> const & rule_caches = mat.rule_caches_;
std::vector<rule_cache> const& rule_caches = mat.rule_caches_;
proj_transform const* proj_trans_ptr = proj_transform_cache::get(mat.proj0_.params(), mat.proj1_.params());
bool cache_features = lay.cache_features() && active_styles.size() > 1;
@ -518,12 +503,8 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
std::size_t i = 0;
for (feature_type_style const* style : active_styles)
{
cache->prepare();
render_style(p, style,
rule_caches[i++],
cache,
*proj_trans_ptr);
render_style(p, style, rule_caches[i++], cache, *proj_trans_ptr);
}
cache->clear();
}
@ -550,7 +531,6 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
feature_ptr feature;
while ((feature = features->next()))
{
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)
{
cache->prepare();
render_style(p, style,
rule_caches[i++],
cache, *proj_trans_ptr);
render_style(p, style, rule_caches[i++], cache, *proj_trans_ptr);
}
}
// We only have a single style and no grouping.
@ -571,21 +549,17 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
for (feature_type_style const* style : active_styles)
{
featureset_ptr features = *featuresets++;
render_style(p, style,
rule_caches[i++],
features,
*proj_trans_ptr);
render_style(p, style, rule_caches[i++], features, *proj_trans_ptr);
}
}
}
template <typename Processor>
void feature_style_processor<Processor>::render_style(
Processor & p,
feature_type_style const* style,
rule_cache const& rc,
featureset_ptr features,
proj_transform const& prj_trans)
template<typename Processor>
void feature_style_processor<Processor>::render_style(Processor& p,
feature_type_style const* style,
rule_cache const& rc,
featureset_ptr features,
proj_transform const& prj_trans)
{
p.start_style_processing(*style);
if (!features)
@ -600,57 +574,58 @@ void feature_style_processor<Processor>::render_style(
{
bool do_else = true;
bool do_also = false;
for (rule const* r : rc.get_if_rules() )
for (rule const* r : rc.get_if_rules())
{
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())
{
was_painted = true;
do_else=false;
do_also=true;
do_else = false;
do_also = true;
rule::symbolizers const& symbols = r->get_symbolizers();
if(!p.process(symbols,*feature,prj_trans))
if (!p.process(symbols, *feature, prj_trans))
{
for (symbolizer const& sym : symbols)
{
util::apply_visitor(symbolizer_dispatch<Processor>(p,*feature,prj_trans),sym);
util::apply_visitor(symbolizer_dispatch<Processor>(p, *feature, prj_trans), sym);
}
}
if (style->get_filter_mode() == FILTER_FIRST)
{
// Stop iterating over rules and proceed with next feature.
do_also=false;
do_also = false;
break;
}
}
}
if (do_else)
{
for( rule const* r : rc.get_else_rules() )
for (rule const* r : rc.get_else_rules())
{
was_painted = true;
rule::symbolizers const& symbols = r->get_symbolizers();
if(!p.process(symbols,*feature,prj_trans))
if (!p.process(symbols, *feature, prj_trans))
{
for (symbolizer const& sym : symbols)
{
util::apply_visitor(symbolizer_dispatch<Processor>(p,*feature,prj_trans),sym);
util::apply_visitor(symbolizer_dispatch<Processor>(p, *feature, prj_trans), sym);
}
}
}
}
if (do_also)
{
for( rule const* r : rc.get_also_rules() )
for (rule const* r : rc.get_also_rules())
{
was_painted = true;
rule::symbolizers const& symbols = r->get_symbolizers();
if(!p.process(symbols,*feature,prj_trans))
if (!p.process(symbols, *feature, prj_trans))
{
for (symbolizer const& sym : symbols)
{
util::apply_visitor(symbolizer_dispatch<Processor>(p,*feature,prj_trans),sym);
util::apply_visitor(symbolizer_dispatch<Processor>(p, *feature, prj_trans), sym);
}
}
}
@ -660,4 +635,4 @@ void feature_style_processor<Processor>::render_style(
p.end_style_processing(*style);
}
}
} // namespace mapnik

View file

@ -39,24 +39,19 @@ MAPNIK_DISABLE_WARNING_POP
#include <vector>
#include <cstddef>
namespace mapnik
{
namespace mapnik {
class rule;
enum filter_mode_enum {
FILTER_ALL,
FILTER_FIRST,
filter_mode_enum_MAX
};
enum filter_mode_enum { FILTER_ALL, FILTER_FIRST, filter_mode_enum_MAX };
DEFINE_ENUM( filter_mode_e, filter_mode_enum );
DEFINE_ENUM(filter_mode_e, filter_mode_enum);
using rules = std::vector<rule>;
class MAPNIK_DECL feature_type_style
{
private:
private:
rules rules_;
filter_mode_e filter_mode_;
// image_filters
@ -66,18 +61,19 @@ private:
boost::optional<composite_mode_e> comp_op_;
float opacity_;
bool image_filters_inflate_;
friend void swap(feature_type_style& lhs, feature_type_style & rhs);
public:
friend void swap(feature_type_style& lhs, feature_type_style& rhs);
public:
// ctor
feature_type_style();
feature_type_style(feature_type_style const& rhs);
feature_type_style(feature_type_style && rhs);
feature_type_style(feature_type_style&& rhs);
feature_type_style& operator=(feature_type_style rhs);
// comparison
bool operator==(feature_type_style const& rhs) const;
void add_rule(rule && rule);
void add_rule(rule&& rule);
rules const& get_rules() const;
rules& get_rules_nonconst();
@ -88,9 +84,9 @@ public:
// filters
std::vector<filter::filter_type> const& image_filters() const;
std::vector<filter::filter_type> & image_filters();
std::vector<filter::filter_type>& image_filters();
std::vector<filter::filter_type> const& direct_image_filters() const;
std::vector<filter::filter_type> & direct_image_filters();
std::vector<filter::filter_type>& direct_image_filters();
// compositing
void set_comp_op(composite_mode_e comp_op);
boost::optional<composite_mode_e> comp_op() const;
@ -98,14 +94,10 @@ public:
float get_opacity() const;
void set_image_filters_inflate(bool inflate);
bool image_filters_inflate() const;
inline void reserve(std::size_t size)
{
rules_.reserve(size);
}
inline void reserve(std::size_t size) { rules_.reserve(size); }
~feature_type_style() {}
};
}
} // namespace mapnik
#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
{
feature_ptr next()
{
return feature_ptr();
}
feature_ptr next() { return feature_ptr(); }
~invalid_featureset() {}
};
@ -62,6 +59,6 @@ inline bool is_valid(featureset_ptr const& ptr)
return (dynamic_cast<invalid_featureset*>(ptr.get()) == nullptr) ? true : false;
}
}
} // namespace mapnik
#endif // MAPNIK_FEATURESET_HPP

View file

@ -29,14 +29,16 @@
namespace mapnik {
template <typename T>
template<typename T>
class filter_featureset : public Featureset
{
using filter_type = T;
public:
filter_featureset(featureset_ptr const& fs, filter_type && filter)
: fs_(fs), filter_(std::move(filter)) {}
public:
filter_featureset(featureset_ptr const& fs, filter_type&& filter)
: fs_(fs)
, filter_(std::move(filter))
{}
feature_ptr next()
{
@ -48,10 +50,10 @@ public:
return feature;
}
private:
private:
featureset_ptr fs_;
filter_type filter_;
};
}
} // namespace mapnik
#endif // MAPNIK_FILTER_FEATURESET_HPP

View file

@ -36,10 +36,12 @@
#include <utility> // pair
#include <vector>
namespace boost { template <class T> class optional; }
namespace boost {
template<class T>
class optional;
}
namespace mapnik
{
namespace mapnik {
class stroker;
using stroker_ptr = std::shared_ptr<stroker>;
@ -53,8 +55,9 @@ class MAPNIK_DECL freetype_engine : public singleton<freetype_engine, CreateUsin
{
friend class CreateUsingNew<freetype_engine>;
friend class Map;
public:
using font_file_mapping_type = std::map<std::string,std::pair<int,std::string>>;
public:
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>>;
static bool is_font_file(std::string const& file_name);
@ -62,44 +65,44 @@ public:
static bool register_fonts(std::string const& dir, bool recurse = false);
static std::vector<std::string> face_names();
static font_file_mapping_type const& get_mapping();
static font_memory_cache_type & get_cache();
static font_memory_cache_type& get_cache();
static bool can_open(std::string const& face_name,
font_library & library,
font_library& library,
font_file_mapping_type const& font_file_mapping,
font_file_mapping_type const& global_font_file_mapping);
static face_ptr create_face(std::string const& face_name,
font_library & library,
font_library& library,
font_file_mapping_type const& font_file_mapping,
freetype_engine::font_memory_cache_type const& font_cache,
font_file_mapping_type const& global_font_file_mapping,
freetype_engine::font_memory_cache_type & global_memory_fonts);
private:
freetype_engine::font_memory_cache_type& global_memory_fonts);
private:
bool is_font_file_impl(std::string const& file_name);
std::vector<std::string> face_names_impl();
font_file_mapping_type const& get_mapping_impl();
font_memory_cache_type& get_cache_impl();
bool can_open_impl(std::string const& face_name,
font_library & library,
font_file_mapping_type const& font_file_mapping,
font_file_mapping_type const& global_font_file_mapping);
font_library& library,
font_file_mapping_type const& font_file_mapping,
font_file_mapping_type const& global_font_file_mapping);
face_ptr create_face_impl(std::string const& face_name,
font_library & library,
font_library& library,
font_file_mapping_type const& font_file_mapping,
freetype_engine::font_memory_cache_type const& font_cache,
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);
bool register_font_impl(std::string const& file_name);
bool register_fonts_impl(std::string const& dir, bool recurse);
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_font_impl(std::string const& file_name,
font_library & libary,
font_file_mapping_type & font_file_mapping);
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_font_impl(std::string const& file_name, font_library& libary, font_file_mapping_type& font_file_mapping);
bool register_fonts_impl(std::string const& dir,
font_library & libary,
font_file_mapping_type & font_file_mapping,
font_library& libary,
font_file_mapping_type& font_file_mapping,
bool recurse = false);
font_file_mapping_type global_font_file_mapping_;
font_memory_cache_type global_memory_fonts_;
@ -107,8 +110,8 @@ private:
class MAPNIK_DECL face_manager
{
public:
face_manager(font_library & library,
public:
face_manager(font_library& library,
freetype_engine::font_file_mapping_type const& font_file_mapping,
freetype_engine::font_memory_cache_type const& font_cache);
face_ptr get_face(std::string const& name);
@ -117,12 +120,12 @@ public:
face_set_ptr get_face_set(std::string const& name, boost::optional<font_set> fset);
stroker_ptr get_stroker() const { return stroker_; }
private:
private:
using face_cache = std::map<std::string, face_ptr>;
using face_cache_ptr = std::shared_ptr<face_cache>;
face_cache_ptr face_cache_;
font_library & library_;
font_library& library_;
freetype_engine::font_file_mapping_type const& font_file_mapping_;
freetype_engine::font_memory_cache_type const& font_memory_cache_;
stroker_ptr stroker_;
@ -130,6 +133,6 @@ private:
using face_manager_freetype = face_manager;
extern template class MAPNIK_DECL singleton<freetype_engine, CreateUsingNew>;
}
} // namespace mapnik
#endif // MAPNIK_FONT_ENGINE_FREETYPE_HPP

View file

@ -30,15 +30,14 @@
#include <string>
#include <vector>
namespace mapnik
{
namespace mapnik {
class MAPNIK_DECL font_set
{
public:
public:
// ctor/copy/move/dtor
font_set(std::string const& name);
font_set(font_set const& rhs);
font_set(font_set &&);
font_set(font_set&&);
font_set& operator=(font_set rhs);
~font_set();
// comparison
@ -49,11 +48,11 @@ public:
void add_face_name(std::string const& face_name);
std::vector<std::string> const& get_face_names() const;
private:
friend void swap(font_set & lhs, font_set & rhs);
private:
friend void swap(font_set& lhs, font_set& rhs);
std::string name_;
std::vector<std::string> face_names_;
};
}
} // namespace mapnik
#endif // MAPNIK_FONT_SET_HPP

View file

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

View file

@ -42,52 +42,57 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/optional.hpp>
MAPNIK_DISABLE_WARNING_POP
namespace mapnik
{
template <typename T>
bool clip_test(T p,T q,double& tmin,double& tmax)
namespace mapnik {
template<typename T>
bool clip_test(T p, T q, double& tmin, double& tmax)
{
double r = 0;
bool result=true;
if (p<0.0)
bool result = true;
if (p < 0.0)
{
r=q/p;
if (r>tmax) result=false;
else if (r>tmin) tmin=r;
r = q / p;
if (r > tmax)
result = false;
else if (r > tmin)
tmin = r;
}
else if (p>0.0)
else if (p > 0.0)
{
r=q/p;
if (r<tmin) result=false;
else if (r<tmax) tmax=r;
} else if (q<0.0) result=false;
r = q / p;
if (r < tmin)
result = false;
else if (r < tmax)
tmax = r;
}
else if (q < 0.0)
result = false;
return result;
}
template <typename T,typename Image>
bool clip_line(T& x0,T& y0,T& x1,T& y1,box2d<T> const& box)
template<typename T, typename Image>
bool clip_line(T& x0, T& y0, T& x1, T& y1, box2d<T> const& box)
{
double tmin=0.0;
double tmax=1.0;
double dx=x1-x0;
if (clip_test<double>(-dx,x0,tmin,tmax))
double tmin = 0.0;
double tmax = 1.0;
double dx = x1 - x0;
if (clip_test<double>(-dx, x0, tmin, tmax))
{
if (clip_test<double>(dx,box.width()-x0,tmin,tmax))
if (clip_test<double>(dx, box.width() - x0, tmin, tmax))
{
double dy=y1-y0;
if (clip_test<double>(-dy,y0,tmin,tmax))
double dy = y1 - y0;
if (clip_test<double>(-dy, y0, tmin, tmax))
{
if (clip_test<double>(dy,box.height()-y0,tmin,tmax))
if (clip_test<double>(dy, box.height() - y0, tmin, tmax))
{
if (tmax<1.0)
if (tmax < 1.0)
{
x1=static_cast<T>(x0+tmax*dx);
y1=static_cast<T>(y0+tmax*dy);
x1 = static_cast<T>(x0 + tmax * dx);
y1 = static_cast<T>(y0 + tmax * dy);
}
if (tmin>0.0)
if (tmin > 0.0)
{
x0+=static_cast<T>(tmin*dx);
y0+=static_cast<T>(tmin*dy);
x0 += static_cast<T>(tmin * dx);
y0 += static_cast<T>(tmin * dy);
}
return true;
}
@ -97,37 +102,35 @@ bool clip_line(T& x0,T& y0,T& x1,T& y1,box2d<T> const& box)
return false;
}
template <typename Iter>
inline bool point_inside_path(double x,double y,Iter start,Iter end)
template<typename Iter>
inline bool point_inside_path(double x, double y, Iter start, Iter end)
{
bool inside=false;
double x0=std::get<0>(*start);
double y0=std::get<1>(*start);
bool inside = false;
double x0 = std::get<0>(*start);
double y0 = std::get<1>(*start);
double x1 = 0;
double y1 = 0;
while (++start!=end)
while (++start != end)
{
if ( std::get<2>(*start) == SEG_MOVETO)
if (std::get<2>(*start) == SEG_MOVETO)
{
x0 = std::get<0>(*start);
y0 = std::get<1>(*start);
continue;
}
x1=std::get<0>(*start);
y1=std::get<1>(*start);
x1 = std::get<0>(*start);
y1 = std::get<1>(*start);
if ((((y1 <= y) && (y < y0)) ||
((y0 <= y) && (y < y1))) &&
( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
inside=!inside;
x0=x1;
y0=y1;
if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
inside = !inside;
x0 = x1;
y0 = y1;
}
return inside;
}
inline bool point_in_circle(double x,double y,double cx,double cy,double r)
inline bool point_in_circle(double x, double y, double cx, double cy, double r)
{
double dx = x - cx;
double dy = y - cy;
@ -135,7 +138,7 @@ inline bool point_in_circle(double x,double y,double cx,double cy,double r)
return (d2 <= r * r);
}
template <typename T>
template<typename T>
inline T sqr(T x)
{
return x * x;
@ -153,9 +156,7 @@ inline double distance(double x0, double y0, double x1, double y1)
return std::sqrt(distance2(x0, y0, x1, y1));
}
inline double point_to_segment_distance(double x, double y,
double ax, double ay,
double bx, double by)
inline double point_to_segment_distance(double x, double y, double ax, double ay, double bx, double by)
{
double len2 = distance2(ax, ay, bx, by);
@ -177,7 +178,7 @@ inline double point_to_segment_distance(double x, double y,
return std::fabs(s) * std::sqrt(len2);
}
template <typename Iter>
template<typename Iter>
inline bool point_on_path(double x, double y, Iter start, Iter end, double tol)
{
double x0 = std::get<0>(*start);
@ -205,23 +206,21 @@ inline bool point_on_path(double x, double y, Iter start, Iter end, double tol)
}
// filters
template <typename T>
template<typename T>
struct bounding_box_filter
{
using value_type = T;
box2d<value_type> box_;
explicit bounding_box_filter(box2d<value_type> const& box)
: box_(box) {}
: box_(box)
{}
bool pass(box2d<value_type> const& extent) const
{
return extent.intersects(box_);
}
bool pass(box2d<value_type> const& extent) const { return extent.intersects(box_); }
};
using filter_in_box = bounding_box_filter<double>;
template <typename T>
template<typename T>
struct at_point_filter
{
using value_type = T;
@ -232,40 +231,39 @@ struct at_point_filter
box_.pad(tol);
}
bool pass(box2d<value_type> const& extent) const
{
return extent.intersects(box_);
}
bool pass(box2d<value_type> const& extent) const { return extent.intersects(box_); }
};
using filter_at_point = at_point_filter<double>;
////////////////////////////////////////////////////////////////////////////
template <typename PathType>
double path_length(PathType & path)
template<typename PathType>
double path_length(PathType& path)
{
double x0 = 0;
double y0 = 0;
double x1 = 0;
double y1 = 0;
path.rewind(0);
unsigned command = path.vertex(&x0,&y0);
if (command == SEG_END) return 0;
unsigned command = path.vertex(&x0, &y0);
if (command == SEG_END)
return 0;
double length = 0;
while (SEG_END != (command = path.vertex(&x1, &y1)))
{
if (command == SEG_CLOSE) continue;
length += distance(x0,y0,x1,y1);
if (command == SEG_CLOSE)
continue;
length += distance(x0, y0, x1, y1);
x0 = x1;
y0 = y1;
}
return length;
}
template <typename PathType>
bool hit_test_first(PathType & path, double x, double y)
template<typename PathType>
bool hit_test_first(PathType& path, double x, double y)
{
bool inside=false;
bool inside = false;
double x0 = 0;
double y0 = 0;
double x1 = 0;
@ -291,10 +289,8 @@ bool hit_test_first(PathType & path, double x, double y)
continue;
}
if ((((y1 <= y) && (y < y0)) ||
((y0 <= y) && (y < y1))) &&
(x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
inside=!inside;
if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
inside = !inside;
x0 = x1;
y0 = y1;
@ -304,8 +300,8 @@ bool hit_test_first(PathType & path, double x, double y)
namespace label {
template <typename PathType>
bool middle_point(PathType & path, double & x, double & y, boost::optional<double&> angle = boost::none)
template<typename PathType>
bool middle_point(PathType& path, double& x, double& y, boost::optional<double&> angle = boost::none)
{
double x0 = 0;
double y0 = 0;
@ -313,8 +309,9 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional<doubl
double y1 = 0;
double mid_length = 0.5 * path_length(path);
path.rewind(0);
unsigned command = path.vertex(&x0,&y0);
if (command == SEG_END) return false;
unsigned command = path.vertex(&x0, &y0);
if (command == SEG_END)
return false;
if (std::abs(mid_length) < std::numeric_limits<double>::epsilon())
{
x = x0;
@ -324,12 +321,13 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional<doubl
double dist = 0.0;
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);
if ( dist + seg_length >= mid_length)
if (dist + seg_length >= mid_length)
{
double r = (mid_length - dist)/seg_length;
double r = (mid_length - dist) / seg_length;
x = x0 + (x1 - x0) * r;
y = y0 + (y1 - y0) * r;
if (angle)
@ -345,14 +343,15 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional<doubl
return true;
}
template <typename PathType>
bool centroid(PathType & path, double & x, double & y)
template<typename PathType>
bool centroid(PathType& path, double& x, double& y)
{
geometry::point<double> p0, p1, move_to, start;
path.rewind(0);
unsigned command = path.vertex(&p0.x, &p0.y);
if (command == SEG_END) return false;
if (command == SEG_END)
return false;
start = move_to = p0;
@ -380,7 +379,6 @@ bool centroid(PathType & path, double & x, double & y)
xtmp += (dx1 + dx0) * ai;
ytmp += (dy1 + dy0) * ai;
break;
}
p0 = p1;
++count;
@ -478,10 +476,10 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y)
#endif
template <typename PathType>
bool hit_test(PathType & path, double x, double y, double tol)
template<typename PathType>
bool hit_test(PathType& path, double x, double y, double tol)
{
bool inside=false;
bool inside = false;
double x0 = 0;
double y0 = 0;
double x1 = 0;
@ -512,25 +510,21 @@ bool hit_test(PathType & path, double x, double y, double tol)
x1 = start_x;
y1 = start_y;
}
switch(geom_type)
switch (geom_type)
{
case mapnik::geometry::geometry_types::Polygon:
{
if ((((y1 <= y) && (y < y0)) ||
((y0 <= y) && (y < y1))) &&
(x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
inside=!inside;
break;
}
case mapnik::geometry::geometry_types::LineString:
{
double distance = point_to_segment_distance(x,y,x0,y0,x1,y1);
if (distance < tol)
return true;
break;
}
default:
break;
case mapnik::geometry::geometry_types::Polygon: {
if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
inside = !inside;
break;
}
case mapnik::geometry::geometry_types::LineString: {
double distance = point_to_segment_distance(x, y, x0, y0, x1, y1);
if (distance < tol)
return true;
break;
}
default:
break;
}
x0 = x1;
y0 = y1;
@ -544,6 +538,7 @@ bool hit_test(PathType & path, double x, double y, double tol)
return inside;
}
}}
} // namespace label
} // namespace mapnik
#endif // MAPNIK_GEOM_UTIL_HPP

View file

@ -38,14 +38,16 @@
#include <type_traits>
#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_empty {};
struct geometry_empty
{};
template <typename T>
template<typename T>
using geometry_base = mapnik::util::variant<geometry_empty,
point<T>,
line_string<T>,
@ -53,13 +55,13 @@ using geometry_base = mapnik::util::variant<geometry_empty,
multi_point<T>,
multi_line_string<T>,
multi_polygon<T>,
geometry_collection<T> >;
template <typename T>
geometry_collection<T>>;
template<typename T>
struct geometry : geometry_base<T>
{
using coordinate_type = T;
#if __cpp_inheriting_constructors >= 200802 && !defined (_MSC_VER)
#if __cpp_inheriting_constructors >= 200802 && !defined(_MSC_VER)
using geometry_base<T>::geometry_base;
@ -67,20 +69,21 @@ struct geometry : geometry_base<T>
geometry() = default;
template <typename G>
geometry(G && geom)
: geometry_base<T>(std::forward<G>(geom)) {}
template<typename G>
geometry(G&& geom)
: geometry_base<T>(std::forward<G>(geom))
{}
#endif
};
template <typename T, template <typename...> class Cont>
template<typename T, template<typename...> class Cont>
struct geometry_collection : Cont<geometry<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
#define MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
@ -45,16 +44,20 @@ MAPNIK_DISABLE_WARNING_POP
#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<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_RING_TEMPLATED(mapnik::geometry::linear_ring)
// needed by box2d<T>
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::coord2d, double, boost::geometry::cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::coord2f, float, boost::geometry::cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::coord2f, float, boost::geometry::cs::cartesian, x, y)
namespace mapnik {
template <typename CoordinateType>
template<typename CoordinateType>
struct const_interior_rings
{
using polygon_type = mapnik::geometry::polygon<CoordinateType> const;
@ -63,7 +66,8 @@ struct const_interior_rings
using value_type = typename polygon_type::value_type;
const_interior_rings(polygon_type const& poly)
: poly_(poly) {}
: poly_(poly)
{}
const_iterator begin() const
{
@ -72,19 +76,15 @@ struct const_interior_rings
return itr;
}
const_iterator end() const { return poly_.cend();}
const_iterator end() const { return poly_.cend(); }
std::size_t size() const
{
return poly_.empty() ? 0 : poly_.size() - 1;
}
std::size_t size() const { 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_;
};
template <typename CoordinateType>
template<typename CoordinateType>
struct interior_rings
{
using polygon_type = mapnik::geometry::polygon<CoordinateType>;
@ -92,8 +92,9 @@ struct interior_rings
using const_iterator = typename polygon_type::const_iterator;
using value_type = typename polygon_type::value_type;
interior_rings(polygon_type & poly)
: poly_(poly) {}
interior_rings(polygon_type& poly)
: poly_(poly)
{}
iterator begin()
{
@ -102,7 +103,7 @@ struct interior_rings
return itr;
}
iterator end() { return poly_.end();}
iterator end() { return poly_.end(); }
const_iterator begin() const
{
auto itr = poly_.cbegin();
@ -110,153 +111,156 @@ struct interior_rings
return itr;
}
const_iterator end() const { return poly_.cend();}
const_iterator end() const { return poly_.cend(); }
void clear()
{
poly_.resize(1);
}
void clear() { poly_.resize(1); }
void resize(std::size_t size)
{
poly_.resize(size + 1);
}
void resize(std::size_t size) { poly_.resize(size + 1); }
std::size_t size() const
{
return poly_.empty() ? 0 : poly_.size() - 1;
}
std::size_t size() const { return poly_.empty() ? 0 : poly_.size() - 1; }
void push_back(value_type const& val) { poly_.push_back(val); }
value_type& back() { return poly_.back(); }
value_type const& back() const { return poly_.back(); }
polygon_type & poly_;
value_type const& back() const { return poly_.back(); }
polygon_type& poly_;
};
} // ns mapnik
} // namespace mapnik
namespace boost { namespace geometry { namespace traits {
namespace boost {
namespace geometry {
namespace traits {
template <typename CoordinateType>
struct tag<mapnik::box2d<CoordinateType> >
template<typename CoordinateType>
struct tag<mapnik::box2d<CoordinateType>>
{
using type = box_tag;
};
template<> struct point_type<mapnik::box2d<double> > { using type = mapnik::coord2d; };
template<> struct point_type<mapnik::box2d<float> > { using type = mapnik::coord2f; };
template <typename CoordinateType>
struct indexed_access<mapnik::box2d<CoordinateType>, min_corner, 0>
template<>
struct point_type<mapnik::box2d<double>>
{
using ct = CoordinateType;
static inline ct get(mapnik::box2d<CoordinateType> const& b) { return b.minx();}
static inline void set(mapnik::box2d<CoordinateType> &b, ct const& value) { b.set_minx(value); }
using type = mapnik::coord2d;
};
template <typename CoordinateType>
struct indexed_access<mapnik::box2d<CoordinateType>, min_corner, 1>
template<>
struct point_type<mapnik::box2d<float>>
{
using ct = CoordinateType;
static inline ct get(mapnik::box2d<CoordinateType> const& b) { return b.miny();}
static inline void set(mapnik::box2d<CoordinateType> &b, ct const& value) { b.set_miny(value); }
};
template <typename CoordinateType>
struct indexed_access<mapnik::box2d<CoordinateType>, max_corner, 0>
{
using ct = CoordinateType;
static inline ct get(mapnik::box2d<CoordinateType> const& b) { return b.maxx();}
static inline void set(mapnik::box2d<CoordinateType> &b, ct const& value) { b.set_maxx(value); }
};
template <typename CoordinateType>
struct indexed_access<mapnik::box2d<CoordinateType>, max_corner, 1>
{
using ct = CoordinateType;
static inline ct get(mapnik::box2d<CoordinateType> const& b) { return b.maxy();}
static inline void set(mapnik::box2d<CoordinateType> &b , ct const& value) { b.set_maxy(value); }
using type = mapnik::coord2f;
};
template<typename CoordinateType>
struct tag<mapnik::geometry::polygon<CoordinateType> >
struct indexed_access<mapnik::box2d<CoordinateType>, min_corner, 0>
{
using ct = CoordinateType;
static inline ct get(mapnik::box2d<CoordinateType> const& b) { return b.minx(); }
static inline void set(mapnik::box2d<CoordinateType>& b, ct const& value) { b.set_minx(value); }
};
template<typename CoordinateType>
struct indexed_access<mapnik::box2d<CoordinateType>, min_corner, 1>
{
using ct = CoordinateType;
static inline ct get(mapnik::box2d<CoordinateType> const& b) { return b.miny(); }
static inline void set(mapnik::box2d<CoordinateType>& b, ct const& value) { b.set_miny(value); }
};
template<typename CoordinateType>
struct indexed_access<mapnik::box2d<CoordinateType>, max_corner, 0>
{
using ct = CoordinateType;
static inline ct get(mapnik::box2d<CoordinateType> const& b) { return b.maxx(); }
static inline void set(mapnik::box2d<CoordinateType>& b, ct const& value) { b.set_maxx(value); }
};
template<typename CoordinateType>
struct indexed_access<mapnik::box2d<CoordinateType>, max_corner, 1>
{
using ct = CoordinateType;
static inline ct get(mapnik::box2d<CoordinateType> const& b) { return b.maxy(); }
static inline void set(mapnik::box2d<CoordinateType>& b, ct const& value) { b.set_maxy(value); }
};
template<typename CoordinateType>
struct tag<mapnik::geometry::polygon<CoordinateType>>
{
using type = polygon_tag;
};
template <typename CoordinateType>
struct point_order<mapnik::geometry::linear_ring<CoordinateType> >
template<typename CoordinateType>
struct point_order<mapnik::geometry::linear_ring<CoordinateType>>
{
static const order_selector value = counterclockwise;
};
template<typename CoordinateType>
struct tag<mapnik::geometry::multi_point<CoordinateType> >
struct tag<mapnik::geometry::multi_point<CoordinateType>>
{
using type = multi_point_tag;
};
template<typename CoordinateType>
struct tag<mapnik::geometry::multi_line_string<CoordinateType> >
struct tag<mapnik::geometry::multi_line_string<CoordinateType>>
{
using type = multi_linestring_tag;
};
template<typename CoordinateType>
struct tag<mapnik::geometry::multi_polygon<CoordinateType> >
struct tag<mapnik::geometry::multi_polygon<CoordinateType>>
{
using type = multi_polygon_tag;
};
// ring
template <typename CoordinateType>
struct ring_const_type<mapnik::geometry::polygon<CoordinateType> >
template<typename CoordinateType>
struct ring_const_type<mapnik::geometry::polygon<CoordinateType>>
{
using type = typename mapnik::geometry::linear_ring<CoordinateType> const&;
};
template <typename CoordinateType>
struct ring_mutable_type<mapnik::geometry::polygon<CoordinateType> >
template<typename CoordinateType>
struct ring_mutable_type<mapnik::geometry::polygon<CoordinateType>>
{
using type = typename mapnik::geometry::linear_ring<CoordinateType>&;
};
// interior
template <typename CoordinateType>
template<typename CoordinateType>
struct interior_const_type<mapnik::geometry::polygon<CoordinateType>>
{
using type = typename mapnik::const_interior_rings<CoordinateType> const;
};
template <typename CoordinateType>
struct interior_mutable_type<mapnik::geometry::polygon<CoordinateType> >
template<typename CoordinateType>
struct interior_mutable_type<mapnik::geometry::polygon<CoordinateType>>
{
using type = typename mapnik::interior_rings<CoordinateType> ;
using type = typename mapnik::interior_rings<CoordinateType>;
};
template <typename CoordinateType>
struct exterior_ring<mapnik::geometry::polygon<CoordinateType> >
template<typename CoordinateType>
struct exterior_ring<mapnik::geometry::polygon<CoordinateType>>
{
using ring_const_type = typename ring_const_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)
using ring_const_type = typename ring_const_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)
{
if (p.empty()) p.resize(1);
if (p.empty())
p.resize(1);
return p[0];
}
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];
}
};
template <typename CoordinateType>
struct interior_rings<mapnik::geometry::polygon<CoordinateType> >
template<typename CoordinateType>
struct interior_rings<mapnik::geometry::polygon<CoordinateType>>
{
using interior_const_type = typename interior_const_type<mapnik::geometry::polygon<CoordinateType> >::type;
using interior_mutable_type = typename interior_mutable_type<mapnik::geometry::polygon<CoordinateType> >::type;
using interior_const_type = typename interior_const_type<mapnik::geometry::polygon<CoordinateType>>::type;
using interior_mutable_type = typename interior_mutable_type<mapnik::geometry::polygon<CoordinateType>>::type;
static interior_const_type get(mapnik::geometry::polygon<CoordinateType> const& p)
{
@ -269,7 +273,7 @@ struct interior_rings<mapnik::geometry::polygon<CoordinateType> >
}
};
template <typename CoordinateType>
template<typename CoordinateType>
struct resize<mapnik::interior_rings<CoordinateType>>
{
static inline void apply(mapnik::interior_rings<CoordinateType> interiors, std::size_t new_size)
@ -278,25 +282,24 @@ struct resize<mapnik::interior_rings<CoordinateType>>
}
};
template <typename CoordinateType>
template<typename CoordinateType>
struct clear<mapnik::interior_rings<CoordinateType>>
{
static inline void apply(mapnik::interior_rings<CoordinateType> interiors)
{
interiors.clear();
}
static inline void apply(mapnik::interior_rings<CoordinateType> interiors) { interiors.clear(); }
};
template <typename CoordinateType>
template<typename CoordinateType>
struct push_back<mapnik::interior_rings<CoordinateType>>
{
template <typename Ring>
template<typename Ring>
static inline void apply(mapnik::interior_rings<CoordinateType> interiors, Ring const& ring)
{
interiors.push_back(ring);
}
};
}}}
} // namespace traits
} // namespace geometry
} // namespace boost
#endif //MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
#endif // MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP

View file

@ -20,81 +20,78 @@
*
*****************************************************************************/
#ifndef MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
#define MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_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/support/attributes.hpp>
namespace boost { namespace spirit { namespace traits
{
template <>
struct not_is_variant<mapnik::geometry::geometry<double>, karma::domain>
: mpl::false_
namespace boost {
namespace spirit {
namespace traits {
template<>
struct not_is_variant<mapnik::geometry::geometry<double>, karma::domain> : mpl::false_
{};
template <>
struct not_is_variant<mapnik::geometry::geometry<std::int64_t>, karma::domain>
: mpl::false_
template<>
struct not_is_variant<mapnik::geometry::geometry<std::int64_t>, karma::domain> : mpl::false_
{};
template <>
struct variant_which< mapnik::geometry::geometry<double> >
template<>
struct variant_which<mapnik::geometry::geometry<double>>
{
static int call(mapnik::geometry::geometry<double> const& v)
{
return v.which();
}
static int call(mapnik::geometry::geometry<double> const& v) { return v.which(); }
};
template <>
struct variant_which< mapnik::geometry::geometry<std::int64_t> >
template<>
struct variant_which<mapnik::geometry::geometry<std::int64_t>>
{
static int call(mapnik::geometry::geometry<std::int64_t> const& v)
{
return v.which();
}
static int call(mapnik::geometry::geometry<std::int64_t> const& v) { return v.which(); }
};
namespace detail {
template <typename T, typename Tuple>
template<typename T, typename Tuple>
struct has_type;
template <typename T>
struct has_type<T, std::tuple<>> : std::false_type {};
template<typename T>
struct has_type<T, std::tuple<>> : std::false_type
{};
template <typename T, typename U, typename... Types>
struct has_type<T, std::tuple<U, Types...>> : has_type<T, std::tuple<Types...>> {};
template<typename T, typename U, typename... Types>
struct has_type<T, std::tuple<U, Types...>> : has_type<T, std::tuple<Types...>>
{};
template <typename T, typename... Types>
struct has_type<T, std::tuple<T, Types...>> : std::true_type {};
template<typename T, typename... Types>
struct has_type<T, std::tuple<T, Types...>> : std::true_type
{};
template <typename T, typename Tuple>
template<typename T, typename Tuple>
struct index;
template <typename T, typename... Types>
template<typename T, typename... Types>
struct index<T, std::tuple<T, Types...>>
{
static const std::size_t value = 0;
};
template <typename T, typename U, typename... Types>
template<typename T, typename U, typename... Types>
struct index<T, std::tuple<U, Types...>>
{
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>
: detail::has_type<Expected, mapnik::geometry::geometry<double>::types>
: detail::has_type<Expected, mapnik::geometry::geometry<double>::types>
{
using compatible_type = Expected;
static bool is_compatible(int index)
@ -103,9 +100,9 @@ struct compute_compatible_component_variant<mapnik::geometry::geometry<double>,
}
};
template <typename Expected>
template<typename Expected>
struct compute_compatible_component_variant<mapnik::geometry::geometry<std::int64_t>, Expected>
: detail::has_type<Expected, mapnik::geometry::geometry<std::int64_t>::types>
: detail::has_type<Expected, mapnik::geometry::geometry<std::int64_t>::types>
{
using compatible_type = Expected;
static bool is_compatible(int index)
@ -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,21 +46,21 @@ namespace mapnik {
// A spatial envelope (i.e. bounding box) which also defines some basic operators.
template <typename T> class MAPNIK_DECL box2d
: boost::equality_comparable<box2d<T> ,
boost::addable<box2d<T>,
boost::dividable2<box2d<T>, T,
boost::multipliable2<box2d<T>, T > > > >
template<typename T>
class MAPNIK_DECL box2d : boost::equality_comparable<
box2d<T>,
boost::addable<box2d<T>, boost::dividable2<box2d<T>, T, boost::multipliable2<box2d<T>, T>>>>
{
public:
public:
using value_type = T;
using box2d_type = box2d<value_type>;
T minx_;
T miny_;
T maxx_;
T maxy_;
private:
friend inline void swap(box2d_type & lhs, box2d_type & rhs)
private:
friend inline void swap(box2d_type& lhs, box2d_type& rhs)
{
using std::swap;
swap(lhs.minx_, rhs.minx_);
@ -68,23 +68,24 @@ private:
swap(lhs.maxx_, rhs.maxx_);
swap(lhs.maxy_, rhs.maxy_);
}
public:
public:
box2d();
box2d(T minx,T miny,T maxx,T maxy);
box2d(coord<T,2> const& c0, coord<T,2> const& c1);
box2d(T minx, T miny, T maxx, T maxy);
box2d(coord<T, 2> const& c0, coord<T, 2> const& c1);
box2d(box2d_type const& rhs);
box2d(box2d_type const& rhs, agg::trans_affine const& tr);
// move
box2d(box2d_type&& rhs);
// converting ctor
template <typename T1>
template<typename T1>
explicit box2d(box2d<T1> other)
: minx_(static_cast<value_type>(other.minx())),
miny_(static_cast<value_type>(other.miny())),
maxx_(static_cast<value_type>(other.maxx())),
maxy_(static_cast<value_type>(other.maxy()))
{}
: minx_(static_cast<value_type>(other.minx()))
, miny_(static_cast<value_type>(other.miny()))
, maxx_(static_cast<value_type>(other.maxx()))
, maxy_(static_cast<value_type>(other.maxy()))
{}
box2d_type& operator=(box2d_type other);
T minx() const;
T miny() const;
@ -98,21 +99,21 @@ public:
T height() const;
void width(T w);
void height(T h);
coord<T,2> center() const;
void expand_to_include(T x,T y);
void expand_to_include(coord<T,2> const& c);
coord<T, 2> center() const;
void expand_to_include(T x, T y);
void expand_to_include(coord<T, 2> const& c);
void expand_to_include(box2d_type const& other);
bool contains(coord<T,2> const& c) const;
bool contains(T x,T y) const;
bool contains(coord<T, 2> const& c) const;
bool contains(T x, T y) const;
bool contains(box2d_type const& other) const;
bool intersects(coord<T,2> const& c) const;
bool intersects(T x,T y) const;
bool intersects(coord<T, 2> const& c) const;
bool intersects(T x, T y) const;
bool intersects(box2d_type const& other) const;
box2d_type intersect(box2d_type const& other) const;
bool operator==(box2d_type const& other) const;
void re_center(T cx,T cy);
void re_center(coord<T,2> const& c);
void init(T x0,T y0,T x1,T y1);
void re_center(T cx, T cy);
void re_center(coord<T, 2> const& c);
void init(T x0, T y0, T x1, T y1);
void init(T x, T y);
void clip(box2d_type const& other);
void pad(T padding);
@ -127,22 +128,20 @@ public:
box2d_type& operator*=(T);
box2d_type& operator/=(T);
T operator[](int index) const;
box2d_type operator +(T other) const; //enlarge box by given amount
box2d_type& operator +=(T other); //enlarge box by given amount
box2d_type operator+(T other) const; // enlarge box by given amount
box2d_type& operator+=(T other); // enlarge box by given amount
// compute the bounding box of this one transformed
box2d_type operator* (agg::trans_affine const& tr) const;
box2d_type operator*(agg::trans_affine const& tr) const;
box2d_type& operator*=(agg::trans_affine const& tr);
};
template <class charT,class traits,class T>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
const box2d<T>& e)
template<class charT, class traits, class T>
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out, const box2d<T>& e)
{
out << e.to_string();
return out;
}
}
} // namespace mapnik
#endif // MAPNIK_BOX2D_HPP

View file

@ -41,69 +41,68 @@ MAPNIK_DISABLE_WARNING_POP
// agg
#include "agg_trans_affine.h"
BOOST_FUSION_ADAPT_TPL_STRUCT(
(T),
(mapnik::box2d)(T),
(T, minx_),
(T, miny_),
(T, maxx_),
(T, maxy_))
BOOST_FUSION_ADAPT_TPL_STRUCT((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
{
template <typename Context>
void operator() (Context & ctx) const
template<typename Context>
void operator()(Context& ctx) const
{
_val(ctx) = safe_cast<T>(_attr(ctx));
}
};
} // anonymous
} // detail
} // namespace
} // namespace detail
template <typename T>
template<typename T>
box2d<T>::box2d()
:minx_( std::numeric_limits<T>::max()),
miny_( std::numeric_limits<T>::max()),
maxx_(-std::numeric_limits<T>::max()),
maxy_(-std::numeric_limits<T>::max()) {}
: minx_(std::numeric_limits<T>::max())
, miny_(std::numeric_limits<T>::max())
, maxx_(-std::numeric_limits<T>::max())
, maxy_(-std::numeric_limits<T>::max())
{}
template <typename T>
box2d<T>::box2d(T minx,T miny,T maxx,T maxy)
template<typename T>
box2d<T>::box2d(T minx, T miny, T maxx, T maxy)
{
init(minx, miny, maxx, maxy);
}
template <typename T>
box2d<T>::box2d(coord<T,2> const& c0, coord<T,2> const& c1)
template<typename T>
box2d<T>::box2d(coord<T, 2> const& c0, coord<T, 2> const& c1)
{
init(c0.x, c0.y, c1.x, c1.y);
}
template <typename T>
template<typename T>
box2d<T>::box2d(box2d_type const& rhs)
: minx_(rhs.minx_),
miny_(rhs.miny_),
maxx_(rhs.maxx_),
maxy_(rhs.maxy_) {}
: minx_(rhs.minx_)
, miny_(rhs.miny_)
, maxx_(rhs.maxx_)
, maxy_(rhs.maxy_)
{}
template <typename T>
box2d<T>::box2d(box2d_type && rhs)
: minx_(std::move(rhs.minx_)),
miny_(std::move(rhs.miny_)),
maxx_(std::move(rhs.maxx_)),
maxy_(std::move(rhs.maxy_)) {}
template<typename T>
box2d<T>::box2d(box2d_type&& rhs)
: minx_(std::move(rhs.minx_))
, miny_(std::move(rhs.miny_))
, maxx_(std::move(rhs.maxx_))
, maxy_(std::move(rhs.maxy_))
{}
template <typename T>
template<typename T>
box2d<T>& box2d<T>::operator=(box2d_type other)
{
swap(*this, other);
return *this;
}
template <typename T>
template<typename T>
box2d<T>::box2d(box2d_type const& rhs, agg::trans_affine const& tr)
{
double x0 = rhs.minx_, y0 = rhs.miny_;
@ -114,40 +113,36 @@ box2d<T>::box2d(box2d_type const& rhs, agg::trans_affine const& tr)
tr.transform(&x1, &y1);
tr.transform(&x2, &y2);
tr.transform(&x3, &y3);
init(static_cast<T>(x0), static_cast<T>(y0),
static_cast<T>(x2), static_cast<T>(y2));
init(static_cast<T>(x0), static_cast<T>(y0), 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>(x3), static_cast<T>(y3));
}
template <typename T>
template<typename T>
bool box2d<T>::operator==(box2d<T> const& other) const
{
return minx_==other.minx_ &&
miny_==other.miny_ &&
maxx_==other.maxx_ &&
maxy_==other.maxy_;
return minx_ == other.minx_ && miny_ == other.miny_ && maxx_ == other.maxx_ && maxy_ == other.maxy_;
}
template <typename T>
template<typename T>
T box2d<T>::minx() const
{
return minx_;
}
template <typename T>
template<typename T>
T box2d<T>::maxx() const
{
return maxx_;
}
template <typename T>
template<typename T>
T box2d<T>::miny() const
{
return miny_;
}
template <typename T>
template<typename T>
T box2d<T>::maxy() const
{
return maxy_;
@ -177,115 +172,118 @@ void box2d<T>::set_maxy(T v)
maxy_ = v;
}
template <typename T>
template<typename T>
T box2d<T>::width() const
{
return maxx_-minx_;
return maxx_ - minx_;
}
template <typename T>
template<typename T>
T box2d<T>::height() const
{
return maxy_-miny_;
return maxy_ - miny_;
}
template <typename T>
template<typename T>
void box2d<T>::width(T w)
{
T cx=center().x;
minx_=static_cast<T>(cx-w*0.5);
maxx_=static_cast<T>(cx+w*0.5);
T cx = center().x;
minx_ = static_cast<T>(cx - w * 0.5);
maxx_ = static_cast<T>(cx + w * 0.5);
}
template <typename T>
template<typename T>
void box2d<T>::height(T h)
{
T cy=center().y;
miny_=static_cast<T>(cy-h*0.5);
maxy_=static_cast<T>(cy+h*0.5);
T cy = center().y;
miny_ = static_cast<T>(cy - h * 0.5);
maxy_ = static_cast<T>(cy + h * 0.5);
}
template <typename T>
coord<T,2> box2d<T>::center() const
template<typename T>
coord<T, 2> box2d<T>::center() const
{
return coord<T,2>(static_cast<T>(0.5*(minx_+maxx_)),
static_cast<T>(0.5*(miny_+maxy_)));
return coord<T, 2>(static_cast<T>(0.5 * (minx_ + maxx_)), static_cast<T>(0.5 * (miny_ + maxy_)));
}
template <typename T>
void box2d<T>::expand_to_include(coord<T,2> const& c)
template<typename T>
void box2d<T>::expand_to_include(coord<T, 2> const& c)
{
expand_to_include(c.x,c.y);
expand_to_include(c.x, c.y);
}
template <typename T>
void box2d<T>::expand_to_include(T x,T y)
template<typename T>
void box2d<T>::expand_to_include(T x, T y)
{
if (x<minx_) minx_=x;
if (x>maxx_) maxx_=x;
if (y<miny_) miny_=y;
if (y>maxy_) maxy_=y;
if (x < minx_)
minx_ = x;
if (x > maxx_)
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)
{
if (other.minx_<minx_) minx_=other.minx_;
if (other.maxx_>maxx_) maxx_=other.maxx_;
if (other.miny_<miny_) miny_=other.miny_;
if (other.maxy_>maxy_) maxy_=other.maxy_;
if (other.minx_ < minx_)
minx_ = other.minx_;
if (other.maxx_ > maxx_)
maxx_ = other.maxx_;
if (other.miny_ < miny_)
miny_ = other.miny_;
if (other.maxy_ > maxy_)
maxy_ = other.maxy_;
}
template <typename T>
bool box2d<T>::contains(coord<T,2> const& c) const
template<typename T>
bool box2d<T>::contains(coord<T, 2> const& c) const
{
return contains(c.x,c.y);
return contains(c.x, c.y);
}
template <typename T>
bool box2d<T>::contains(T x,T y) const
template<typename T>
bool box2d<T>::contains(T x, T y) const
{
return x>=minx_ && x<=maxx_ && y>=miny_ && y<=maxy_;
return x >= minx_ && x <= maxx_ && y >= miny_ && y <= maxy_;
}
template <typename T>
template<typename T>
bool box2d<T>::contains(box2d<T> const& other) const
{
return other.minx_>=minx_ &&
other.maxx_<=maxx_ &&
other.miny_>=miny_ &&
other.maxy_<=maxy_;
return other.minx_ >= minx_ && other.maxx_ <= maxx_ && other.miny_ >= miny_ && other.maxy_ <= maxy_;
}
template <typename T>
bool box2d<T>::intersects(coord<T,2> const& c) const
template<typename T>
bool box2d<T>::intersects(coord<T, 2> const& c) const
{
return intersects(c.x,c.y);
return intersects(c.x, c.y);
}
template <typename T>
bool box2d<T>::intersects(T x,T y) const
template<typename T>
bool box2d<T>::intersects(T x, T y) const
{
return !(x>maxx_ || x<minx_ || y>maxy_ || y<miny_);
return !(x > maxx_ || x < minx_ || y > maxy_ || y < miny_);
}
template <typename T>
template<typename T>
bool box2d<T>::intersects(box2d<T> const& other) const
{
return !(other.minx_>maxx_ || other.maxx_<minx_ ||
other.miny_>maxy_ || other.maxy_<miny_);
return !(other.minx_ > maxx_ || other.maxx_ < minx_ || other.miny_ > maxy_ || other.maxy_ < miny_);
}
template <typename T>
template<typename T>
box2d<T> box2d<T>::intersect(box2d_type const& other) const
{
if (intersects(other))
{
T x0=std::max(minx_,other.minx_);
T y0=std::max(miny_,other.miny_);
T x1=std::min(maxx_,other.maxx_);
T y1=std::min(maxy_,other.maxy_);
return box2d<T>(x0,y0,x1,y1);
T x0 = std::max(minx_, other.minx_);
T y0 = std::max(miny_, other.miny_);
T x1 = std::min(maxx_, other.maxx_);
T y1 = std::min(maxy_, other.maxy_);
return box2d<T>(x0, y0, x1, y1);
}
else
{
@ -293,24 +291,24 @@ box2d<T> box2d<T>::intersect(box2d_type const& other) const
}
}
template <typename T>
void box2d<T>::re_center(T cx,T cy)
template<typename T>
void box2d<T>::re_center(T cx, T cy)
{
T dx=cx-center().x;
T dy=cy-center().y;
minx_+=dx;
miny_+=dy;
maxx_+=dx;
maxy_+=dy;
T dx = cx - center().x;
T dy = cy - center().y;
minx_ += dx;
miny_ += dy;
maxx_ += dx;
maxy_ += dy;
}
template <typename T>
void box2d<T>::re_center(coord<T,2> const& c)
template<typename T>
void box2d<T>::re_center(coord<T, 2> const& c)
{
re_center(c.x,c.y);
re_center(c.x, c.y);
}
template <typename T>
template<typename T>
void box2d<T>::init(T x0, T y0, T x1, T y1)
{
if (x0 < x1)
@ -335,13 +333,13 @@ void box2d<T>::init(T x0, T y0, T x1, T y1)
}
}
template <typename T>
template<typename T>
void box2d<T>::init(T x, T y)
{
init(x, y, x, y);
}
template <typename T>
template<typename T>
void box2d<T>::clip(box2d_type const& other)
{
minx_ = std::max(minx_, other.minx());
@ -350,7 +348,7 @@ void box2d<T>::clip(box2d_type const& other)
maxy_ = std::min(maxy_, other.maxy());
}
template <typename T>
template<typename T>
void box2d<T>::pad(T padding)
{
minx_ -= padding;
@ -359,30 +357,29 @@ void box2d<T>::pad(T padding)
maxy_ += padding;
}
template <typename T>
template<typename T>
bool box2d<T>::from_string(std::string const& str)
{
using boost::spirit::x3::lit;
boost::spirit::x3::double_type double_;
boost::spirit::x3::ascii::space_type space;
bool r = boost::spirit::x3::phrase_parse(str.begin(),
str.end(),
double_[detail::assign<T>()] >> -lit(',') >>
double_[detail::assign<T>()] >> -lit(',') >>
double_[detail::assign<T>()] >> -lit(',') >>
double_[detail::assign<T>()],
space,
*this);
bool r = boost::spirit::x3::phrase_parse(
str.begin(),
str.end(),
double_[detail::assign<T>()] >> -lit(',') >> double_[detail::assign<T>()] >> -lit(',') >>
double_[detail::assign<T>()] >> -lit(',') >> double_[detail::assign<T>()],
space,
*this);
return r;
}
template <typename T>
template<typename T>
bool box2d<T>::valid() const
{
return (minx_ <= maxx_ && miny_ <= maxy_) ;
return (minx_ <= maxx_ && miny_ <= maxy_);
}
template <typename T>
template<typename T>
void box2d<T>::move(T x, T y)
{
minx_ += x;
@ -391,15 +388,14 @@ void box2d<T>::move(T x, T y)
maxy_ += y;
}
template <typename T>
template<typename T>
std::string box2d<T>::to_string() const
{
std::ostringstream s;
if (valid())
{
s << "box2d(" << std::fixed << std::setprecision(16)
<< minx_ << ',' << miny_ << ','
<< maxx_ << ',' << maxy_ << ')';
s << "box2d(" << std::fixed << std::setprecision(16) << minx_ << ',' << miny_ << ',' << maxx_ << ',' << maxy_
<< ')';
}
else
{
@ -408,27 +404,27 @@ std::string box2d<T>::to_string() const
return s.str();
}
template <typename T>
T box2d<T>::area() const
template<typename T>
T box2d<T>::area() const
{
return width() * height();
}
template <typename T>
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
template<typename T>
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
{
expand_to_include(other);
return *this;
}
template <typename T>
box2d<T> box2d<T>::operator+ (T other) const
template<typename T>
box2d<T> box2d<T>::operator+(T other) const
{
return box2d<T>(minx_ - other, miny_ - other, maxx_ + other, maxy_ + other);
}
template <typename T>
box2d<T>& box2d<T>::operator+= (T other)
template<typename T>
box2d<T>& box2d<T>::operator+=(T other)
{
minx_ -= other;
miny_ -= other;
@ -437,12 +433,11 @@ box2d<T>& box2d<T>::operator+= (T other)
return *this;
}
template <typename T>
template<typename T>
box2d<T>& box2d<T>::operator*=(T t)
{
coord<T,2> c = center();
T sx = static_cast<T>(0.5 * width() * t);
coord<T, 2> c = center();
T sx = static_cast<T>(0.5 * width() * t);
T sy = static_cast<T>(0.5 * height() * t);
minx_ = c.x - sx;
maxx_ = c.x + sx;
@ -451,10 +446,10 @@ box2d<T>& box2d<T>::operator*=(T t)
return *this;
}
template <typename T>
template<typename T>
box2d<T>& box2d<T>::operator/=(T t)
{
coord<T,2> c = center();
coord<T, 2> c = center();
T sx = static_cast<T>(0.5 * width() / t);
T sy = static_cast<T>(0.5 * height() / t);
minx_ = c.x - sx;
@ -464,39 +459,39 @@ box2d<T>& box2d<T>::operator/=(T t)
return *this;
}
template <typename T>
T box2d<T>::operator[] (int index) const
template<typename T>
T box2d<T>::operator[](int index) const
{
switch(index)
switch (index)
{
case 0:
return minx_;
case 1:
return miny_;
case 2:
return maxx_;
case 3:
return maxy_;
case -4:
return minx_;
case -3:
return miny_;
case -2:
return maxx_;
case -1:
return maxy_;
default:
throw std::out_of_range("index out of range, max value is 3, min value is -4 ");
case 0:
return minx_;
case 1:
return miny_;
case 2:
return maxx_;
case 3:
return maxy_;
case -4:
return minx_;
case -3:
return miny_;
case -2:
return maxx_;
case -1:
return maxy_;
default:
throw std::out_of_range("index out of range, max value is 3, min value is -4 ");
}
}
template <typename T>
template<typename T>
box2d<T> box2d<T>::operator*(agg::trans_affine const& tr) const
{
return box2d<T>(*this, tr);
}
template <typename T>
template<typename T>
box2d<T>& box2d<T>::operator*=(agg::trans_affine const& tr)
{
double x0 = minx_, y0 = miny_;
@ -507,10 +502,9 @@ box2d<T>& box2d<T>::operator*=(agg::trans_affine const& tr)
tr.transform(&x1, &y1);
tr.transform(&x2, &y2);
tr.transform(&x3, &y3);
init(static_cast<T>(x0), static_cast<T>(y0),
static_cast<T>(x2), static_cast<T>(y2));
init(static_cast<T>(x0), static_cast<T>(y0), 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>(x3), static_cast<T>(y3));
return *this;
}
}
} // namespace mapnik

View file

@ -29,96 +29,74 @@
#include <mapnik/geometry/is_empty.hpp>
#include <mapnik/geometry/remove_empty.hpp>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
namespace detail {
template <typename T>
template<typename T>
struct geometry_centroid
{
using result_type = bool;
geometry_centroid(point<T> & pt)
: pt_(pt) {}
geometry_centroid(point<T>& pt)
: pt_(pt)
{}
template <typename U>
result_type operator() (U const& geom) const
template<typename U>
result_type operator()(U const& geom) const
{
return util::apply_visitor(*this, geom);
}
result_type operator() (geometry_empty const&) const
{
return false;
}
result_type operator()(geometry_empty const&) const { return false; }
result_type operator() (geometry_collection<T> const&) const
{
return false;
}
result_type operator()(geometry_collection<T> const&) const { return false; }
result_type operator() (point<T> const& geom) const
{
return centroid_simple(geom);
}
result_type operator()(point<T> const& geom) const { return centroid_simple(geom); }
result_type operator() (line_string<T> const& geom) const
{
return centroid_simple(geom);
}
result_type operator()(line_string<T> const& geom) const { return centroid_simple(geom); }
result_type operator() (polygon<T> const& geom) const
{
return centroid_simple(geom);
}
result_type operator()(polygon<T> const& geom) const { return centroid_simple(geom); }
result_type operator() (multi_point<T> const& geom) const
{
return centroid_simple(geom);
}
result_type operator()(multi_point<T> const& geom) const { return centroid_simple(geom); }
result_type operator() (multi_line_string<T> const& geom) const
{
return centroid_multi(geom);
}
result_type operator()(multi_line_string<T> const& geom) const { return centroid_multi(geom); }
result_type operator() (multi_polygon<T> const& geom) const
{
return centroid_multi(geom);
}
result_type operator()(multi_polygon<T> const& geom) const { return centroid_multi(geom); }
point<T> & pt_;
point<T>& pt_;
private:
template <typename Geom>
result_type centroid_simple(Geom const & geom) const
private:
template<typename Geom>
result_type centroid_simple(Geom const& geom) const
{
try
{
boost::geometry::centroid(geom, pt_);
return true;
}
catch (boost::geometry::centroid_exception const & e)
} catch (boost::geometry::centroid_exception const& e)
{
return false;
}
}
template <typename Geom>
result_type centroid_multi(Geom const & multi_geom) const
template<typename Geom>
result_type centroid_multi(Geom const& multi_geom) const
{
return centroid_simple(multi_geom);
}
};
}
} // namespace detail
template <typename T1, typename T2>
inline bool centroid(T1 const& geom, point<T2> & pt)
template<typename T1, typename T2>
inline bool centroid(T1 const& geom, point<T2>& pt)
{
return detail::geometry_centroid<T2>(pt)(geom);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_CENTROID_HPP

View file

@ -30,7 +30,8 @@
#include <mapnik/geometry.hpp>
#include <mapnik/geometry/boost_adapters.hpp>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
using coordinate_type = double;
struct closest_point_result
@ -41,11 +42,11 @@ struct closest_point_result
};
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);
}}
} // namespace geometry
} // namespace mapnik
#endif //
#endif // MAPNIK_GEOMETRY_CLOSEST_POINT_HPP

View file

@ -35,7 +35,8 @@ MAPNIK_DISABLE_WARNING_POP
#include <type_traits>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
namespace detail {
@ -43,50 +44,52 @@ struct geometry_correct
{
using result_type = void;
template <typename T>
result_type operator() (geometry<T> & geom) const
template<typename T>
result_type operator()(geometry<T>& geom) const
{
mapnik::util::apply_visitor(*this, geom);
}
template <typename T>
result_type operator() (geometry_collection<T> & collection) const
template<typename T>
result_type operator()(geometry_collection<T>& collection) const
{
for (auto & geom : collection)
for (auto& geom : collection)
{
(*this)(geom);
}
}
template <typename T>
result_type operator() (polygon<T> & poly) const
template<typename T>
result_type operator()(polygon<T>& poly) const
{
if (!poly.empty()) boost::geometry::correct(poly);
if (!poly.empty())
boost::geometry::correct(poly);
}
template <typename T>
result_type operator() (multi_polygon<T> & multi_poly) const
template<typename T>
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>
result_type operator() (T &) const
template<typename T>
result_type operator()(T&) const
{
//no-op
// no-op
}
};
}
} // namespace detail
template <typename GeomType>
inline void correct(GeomType & geom)
template<typename GeomType>
inline void correct(GeomType& geom)
{
static_assert(!std::is_const<GeomType>::value,"mapnik::geometry::correct on const& is invalid");
static_assert(!std::is_const<GeomType>::value, "mapnik::geometry::correct on const& is invalid");
detail::geometry_correct()(geom);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_CORRECT_HPP

View file

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

View file

@ -24,29 +24,31 @@
#include <mapnik/geometry.hpp>
#include <mapnik/geometry/box2d.hpp>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
namespace detail {
template <typename T>
template<typename T>
struct geometry_envelope
{
using coordinate_type = T;
using bbox_type = box2d<coordinate_type>;
bbox_type & bbox;
bbox_type& bbox;
explicit geometry_envelope(bbox_type & bbox_)
: bbox(bbox_) {}
explicit geometry_envelope(bbox_type& bbox_)
: bbox(bbox_)
{}
template <typename U>
void operator() (U const& geom) const
template<typename U>
void operator()(U const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
void operator() (mapnik::geometry::geometry_empty const&) const {}
void operator()(mapnik::geometry::geometry_empty const&) const {}
void operator() (mapnik::geometry::point<T> const& pt) const
void operator()(mapnik::geometry::point<T> const& pt) const
{
if (!bbox.valid())
{
@ -55,27 +57,19 @@ struct geometry_envelope
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); }
void operator()(mapnik::geometry::linear_ring<T> const& ring) const { _envelope_impl(ring, bbox); }
void operator()(mapnik::geometry::polygon<T> const& poly) const
{
_envelope_impl(line, bbox);
if (!poly.empty())
_envelope_impl(poly[0], bbox);
}
void operator() (mapnik::geometry::linear_ring<T> const& ring) const
{
_envelope_impl(ring, bbox);
}
void operator()(mapnik::geometry::multi_point<T> const& multi_point) const { _envelope_impl(multi_point, bbox); }
void operator() (mapnik::geometry::polygon<T> const& poly) const
{
if (!poly.empty()) _envelope_impl(poly[0], bbox);
}
void operator() (mapnik::geometry::multi_point<T> const& multi_point) const
{
_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
{
for (auto const& line : multi_line)
{
@ -83,7 +77,7 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::multi_polygon<T> const& multi_poly) const
void operator()(mapnik::geometry::multi_polygon<T> const& multi_poly) const
{
for (auto const& poly : multi_poly)
{
@ -91,7 +85,7 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::geometry_collection<T> const& collection) const
void operator()(mapnik::geometry::geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{
@ -99,9 +93,9 @@ struct geometry_envelope
}
}
private:
template <typename Points>
void _envelope_impl(Points const& points, bbox_type & b) const
private:
template<typename Points>
void _envelope_impl(Points const& points, bbox_type& b) const
{
bool first = true;
for (auto const& pt : points)
@ -119,9 +113,9 @@ private:
}
};
} // end ns detail
} // namespace detail
template <typename T>
template<typename T>
auto envelope(T const& geom) -> box2d<typename T::coordinate_type>
{
using coordinate_type = typename T::coordinate_type;
@ -131,5 +125,5 @@ auto envelope(T const& geom) -> box2d<typename T::coordinate_type>
return bbox;
}
} // end ns geometry
} // end ns mapnik
} // namespace geometry
} // namespace mapnik

View file

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

View file

@ -27,66 +27,68 @@
#include <mapnik/geometry.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
{
mapnik::geometry::geometry_types operator () (mapnik::geometry::geometry<T> const& geom) const
mapnik::geometry::geometry_types operator()(mapnik::geometry::geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
mapnik::geometry::geometry_types operator() (geometry_empty const& ) const
mapnik::geometry::geometry_types operator()(geometry_empty const&) const
{
return mapnik::geometry::geometry_types::Unknown;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::point<T> const&) const
mapnik::geometry::geometry_types operator()(mapnik::geometry::point<T> const&) const
{
return mapnik::geometry::geometry_types::Point;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::line_string<T> const&) const
mapnik::geometry::geometry_types operator()(mapnik::geometry::line_string<T> const&) const
{
return mapnik::geometry::geometry_types::LineString;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::polygon<T> const&) const
mapnik::geometry::geometry_types operator()(mapnik::geometry::polygon<T> const&) const
{
return mapnik::geometry::geometry_types::Polygon;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_point<T> const&) const
mapnik::geometry::geometry_types operator()(mapnik::geometry::multi_point<T> const&) const
{
return mapnik::geometry::geometry_types::MultiPoint;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_line_string<T> const&) const
mapnik::geometry::geometry_types operator()(mapnik::geometry::multi_line_string<T> const&) const
{
return mapnik::geometry::geometry_types::MultiLineString;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_polygon<T> const&) const
mapnik::geometry::geometry_types operator()(mapnik::geometry::multi_polygon<T> const&) const
{
return mapnik::geometry::geometry_types::MultiPolygon;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::geometry_collection<T> const&) const
mapnik::geometry::geometry_types operator()(mapnik::geometry::geometry_collection<T> const&) const
{
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)
{
using coordinate_type = typename T::coordinate_type;
return detail::geometry_type<coordinate_type>()(geom);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_TYPE_HPP

View file

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

View file

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

View file

@ -25,68 +25,51 @@
#include <mapnik/geometry.hpp>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
namespace detail {
struct geometry_is_empty
{
bool operator() (mapnik::geometry::geometry<double> const& geom) const
bool operator()(mapnik::geometry::geometry<double> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
bool operator() (mapnik::geometry::point<double> const&) const
{
return false;
}
bool operator()(mapnik::geometry::point<double> const&) const { return false; }
bool operator() (mapnik::geometry::line_string<double> const& geom) const
{
return geom.empty();
}
bool operator()(mapnik::geometry::line_string<double> const& geom) const { 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();
}
bool operator() (mapnik::geometry::multi_point<double> const& geom) const
{
return geom.empty();
}
bool operator()(mapnik::geometry::multi_point<double> const& geom) const { return geom.empty(); }
bool operator() (mapnik::geometry::multi_line_string<double> const& geom) const
{
return geom.empty();
}
bool operator()(mapnik::geometry::multi_line_string<double> const& geom) const { return geom.empty(); }
bool operator() (mapnik::geometry::multi_polygon<double> const& geom) const
{
return geom.empty();
}
bool operator()(mapnik::geometry::multi_polygon<double> const& geom) const { return geom.empty(); }
bool operator() (mapnik::geometry::geometry_collection<double> const& geom) const
{
return geom.empty();
}
bool operator()(mapnik::geometry::geometry_collection<double> const& geom) const { return geom.empty(); }
template <typename T>
bool operator() (T const&) const
template<typename T>
bool operator()(T const&) const
{
return true;
}
};
}
} // namespace detail
// returns true if the geometry is the empty set
template <typename GeomType>
template<typename GeomType>
inline bool is_empty(GeomType const& geom)
{
return detail::geometry_is_empty()(geom);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_IS_EMPTY_HPP

View file

@ -32,7 +32,8 @@
#include <mapnik/geometry/boost_adapters.hpp>
#include <boost/geometry/algorithms/is_simple.hpp>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
namespace detail {
@ -40,36 +41,37 @@ struct geometry_is_simple
{
using result_type = bool;
template <typename T>
result_type operator() (geometry<T> const& geom) const
template<typename T>
result_type operator()(geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
result_type operator() (geometry_empty const& ) const
result_type operator()(geometry_empty const&) const
{
// An empty geometry has no anomalous geometric points, such as self intersection or self tangency.
// Therefore, we will return true
return true;
}
template <typename T>
result_type operator() (geometry_collection<T> const& collection) const
template<typename T>
result_type operator()(geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{
if ( !(*this)(geom)) return false;
if (!(*this)(geom))
return false;
}
return true;
}
template <typename T>
result_type operator() (point<T> const& pt) const
template<typename T>
result_type operator()(point<T> const& pt) const
{
return boost::geometry::is_simple(pt);
}
template <typename T>
result_type operator() (line_string<T> const& line) const
template<typename T>
result_type operator()(line_string<T> const& line) const
{
if (line.empty())
{
@ -80,13 +82,13 @@ struct geometry_is_simple
}
return boost::geometry::is_simple(line);
}
template <typename T>
result_type operator() (polygon<T> const& poly) const
template<typename T>
result_type operator()(polygon<T> const& poly) const
{
return boost::geometry::is_simple(poly);
}
template <typename T>
result_type operator() (multi_point<T> const& multi_pt) const
template<typename T>
result_type operator()(multi_point<T> const& multi_pt) const
{
if (multi_pt.empty())
{
@ -96,8 +98,8 @@ struct geometry_is_simple
}
return boost::geometry::is_simple(multi_pt);
}
template <typename T>
result_type operator() (multi_line_string<T> const& multi_line) const
template<typename T>
result_type operator()(multi_line_string<T> const& multi_line) const
{
if (multi_line.empty())
{
@ -107,12 +109,13 @@ struct geometry_is_simple
}
for (auto const& line : multi_line)
{
if (!(*this)(line)) return false;
if (!(*this)(line))
return false;
}
return true;
}
template <typename T>
result_type operator() (multi_polygon<T> const& multi_poly) const
template<typename T>
result_type operator()(multi_polygon<T> const& multi_poly) const
{
if (multi_poly.empty())
{
@ -122,28 +125,29 @@ struct geometry_is_simple
}
for (auto const& poly : multi_poly)
{
if (!(*this)(poly)) return false;
if (!(*this)(poly))
return false;
}
return true;
}
};
}
} // namespace detail
template <typename T>
template<typename T>
inline bool is_simple(T const& geom)
{
return detail::geometry_is_simple() (geom);
return detail::geometry_is_simple()(geom);
}
template <typename T>
template<typename T>
inline bool is_simple(mapnik::geometry::geometry<T> const& geom)
{
return util::apply_visitor(detail::geometry_is_simple(), geom);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // BOOST_VERSION >= 1.56
#endif // MAPNIK_GEOMETRY_IS_SIMPLE_HPP

View file

@ -33,7 +33,8 @@
#include <boost/geometry/algorithms/is_valid.hpp>
#include <boost/geometry/algorithms/validity_failure_type.hpp>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
namespace detail {
@ -41,59 +42,57 @@ struct geometry_is_valid
{
using result_type = bool;
template <typename T>
result_type operator() (geometry<T> const& geom) const
template<typename T>
result_type operator()(geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
result_type operator() (geometry_empty const& ) const
{
return true;
}
result_type operator()(geometry_empty const&) const { return true; }
template <typename T>
result_type operator() (geometry_collection<T> const& collection) const
template<typename T>
result_type operator()(geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{
if ( !(*this)(geom)) return false;
if (!(*this)(geom))
return false;
}
return true;
}
template <typename T>
result_type operator() (point<T> const& pt) const
template<typename T>
result_type operator()(point<T> const& pt) const
{
return boost::geometry::is_valid(pt);
}
template <typename T>
result_type operator() (line_string<T> const& line) const
template<typename T>
result_type operator()(line_string<T> const& line) const
{
return boost::geometry::is_valid(line);
}
template <typename T>
result_type operator() (polygon<T> const& poly) const
template<typename T>
result_type operator()(polygon<T> const& poly) const
{
return boost::geometry::is_valid(poly);
}
template <typename T>
result_type operator() (multi_point<T> const& multi_pt) const
template<typename T>
result_type operator()(multi_point<T> const& multi_pt) const
{
return boost::geometry::is_valid(multi_pt);
}
template <typename T>
result_type operator() (multi_line_string<T> const& multi_line) const
template<typename T>
result_type operator()(multi_line_string<T> const& multi_line) const
{
return boost::geometry::is_valid(multi_line);
}
template <typename T>
result_type operator() (multi_polygon<T> const& multi_poly) const
template<typename T>
result_type operator()(multi_polygon<T> const& multi_poly) const
{
return boost::geometry::is_valid(multi_poly);
}
@ -103,65 +102,67 @@ struct geometry_is_valid_reason
{
using result_type = bool;
boost::geometry::validity_failure_type & failure_;
boost::geometry::validity_failure_type& failure_;
geometry_is_valid_reason(boost::geometry::validity_failure_type & failure):
failure_(failure) {}
geometry_is_valid_reason(boost::geometry::validity_failure_type& failure)
: failure_(failure)
{}
template <typename T>
result_type operator() (geometry<T> const& geom) const
template<typename T>
result_type operator()(geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
result_type operator() (geometry_empty const& ) const
result_type operator()(geometry_empty const&) const
{
failure_ = boost::geometry::no_failure;
return true;
}
template <typename T>
result_type operator() (geometry_collection<T> const& collection) const
template<typename T>
result_type operator()(geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{
if ( !(*this)(geom)) return false;
if (!(*this)(geom))
return false;
}
return true;
}
template <typename T>
result_type operator() (point<T> const& pt) const
template<typename T>
result_type operator()(point<T> const& pt) const
{
return boost::geometry::is_valid(pt, failure_);
}
template <typename T>
result_type operator() (line_string<T> const& line) const
template<typename T>
result_type operator()(line_string<T> const& line) const
{
return boost::geometry::is_valid(line, failure_);
}
template <typename T>
result_type operator() (polygon<T> const& poly) const
template<typename T>
result_type operator()(polygon<T> const& poly) const
{
return boost::geometry::is_valid(poly, failure_);
}
template <typename T>
result_type operator() (multi_point<T> const& multi_pt) const
template<typename T>
result_type operator()(multi_point<T> const& multi_pt) const
{
return boost::geometry::is_valid(multi_pt, failure_);
}
template <typename T>
result_type operator() (multi_line_string<T> const& multi_line) const
template<typename T>
result_type operator()(multi_line_string<T> const& multi_line) const
{
return boost::geometry::is_valid(multi_line, failure_);
}
template <typename T>
result_type operator() (multi_polygon<T> const& multi_poly) const
template<typename T>
result_type operator()(multi_polygon<T> const& multi_poly) const
{
return boost::geometry::is_valid(multi_poly, failure_);
}
@ -171,112 +172,112 @@ struct geometry_is_valid_string
{
using result_type = bool;
std::string & message_;
std::string& message_;
geometry_is_valid_string(std::string & message):
message_(message) {}
geometry_is_valid_string(std::string& message)
: message_(message)
{}
template <typename T>
result_type operator() (geometry<T> const& geom) const
template<typename T>
result_type operator()(geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
result_type operator() (geometry_empty const& ) const
result_type operator()(geometry_empty const&) const
{
message_ = "Geometry is valid";
return true;
}
template <typename T>
result_type operator() (geometry_collection<T> const& collection) const
template<typename T>
result_type operator()(geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{
if ( !(*this)(geom)) return false;
if (!(*this)(geom))
return false;
}
return true;
}
template <typename T>
result_type operator() (point<T> const& pt) const
template<typename T>
result_type operator()(point<T> const& pt) const
{
return boost::geometry::is_valid(pt, message_);
}
template <typename T>
result_type operator() (line_string<T> const& line) const
template<typename T>
result_type operator()(line_string<T> const& line) const
{
return boost::geometry::is_valid(line, message_);
}
template <typename T>
result_type operator() (polygon<T> const& poly) const
template<typename T>
result_type operator()(polygon<T> const& poly) const
{
return boost::geometry::is_valid(poly, message_);
}
template <typename T>
result_type operator() (multi_point<T> const& multi_pt) const
template<typename T>
result_type operator()(multi_point<T> const& multi_pt) const
{
return boost::geometry::is_valid(multi_pt, message_);
}
template <typename T>
result_type operator() (multi_line_string<T> const& multi_line) const
template<typename T>
result_type operator()(multi_line_string<T> const& multi_line) const
{
return boost::geometry::is_valid(multi_line, message_);
}
template <typename T>
result_type operator() (multi_polygon<T> const& multi_poly) const
template<typename T>
result_type operator()(multi_polygon<T> const& multi_poly) const
{
return boost::geometry::is_valid(multi_poly, message_);
}
};
} // namespace detail
}
template <typename T>
template<typename T>
inline bool is_valid(T const& geom)
{
return detail::geometry_is_valid() (geom);
return detail::geometry_is_valid()(geom);
}
template <typename T>
template<typename T>
inline bool is_valid(mapnik::geometry::geometry<T> const& geom)
{
return util::apply_visitor(detail::geometry_is_valid(), geom);
}
template <typename T>
inline bool is_valid(T const& geom, boost::geometry::validity_failure_type & failure)
template<typename T>
inline bool is_valid(T const& geom, boost::geometry::validity_failure_type& failure)
{
return detail::geometry_is_valid_reason(failure) (geom);
return detail::geometry_is_valid_reason(failure)(geom);
}
template <typename T>
inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
boost::geometry::validity_failure_type & failure)
template<typename T>
inline bool is_valid(mapnik::geometry::geometry<T> const& geom, boost::geometry::validity_failure_type& failure)
{
return util::apply_visitor(detail::geometry_is_valid_reason(failure), geom);
}
template <typename T>
inline bool is_valid(T const& geom, std::string & message)
template<typename T>
inline bool is_valid(T const& geom, std::string& message)
{
return detail::geometry_is_valid_string(message) (geom);
return detail::geometry_is_valid_string(message)(geom);
}
template <typename T>
inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
std::string & message)
template<typename T>
inline bool is_valid(mapnik::geometry::geometry<T> const& geom, std::string& message)
{
return util::apply_visitor(detail::geometry_is_valid_string(message), geom);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // BOOST_VERSION >= 1.58
#endif // MAPNIK_GEOMETRY_IS_VALID_HPP

View file

@ -26,10 +26,12 @@
// mapnik
#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>;
}}
}
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_LINE_STRING_HPP

View file

@ -26,11 +26,13 @@
// geometry
#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>;
}}
}
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_MULTI_LINE_STRING_HPP

View file

@ -26,11 +26,13 @@
// geometry
#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>;
}}
}
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_MULTI_POINT_HPP

View file

@ -26,9 +26,10 @@
// geometry
#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>>
{
using coordinate_type = T;
@ -37,7 +38,7 @@ struct multi_polygon : Cont<polygon<T>>
using container_type::container_type;
};
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_MULTI_POLYGON_HPP

View file

@ -25,11 +25,13 @@
#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>;
}}
}
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_POINT_HPP

View file

@ -26,14 +26,16 @@
// geometry
#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>;
template <typename T>
template<typename T>
using polygon = mapbox::geometry::polygon<T>;
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_POLYGON_HPP

View file

@ -27,13 +27,14 @@
#include <mapnik/geometry/point.hpp>
#include <mapnik/geometry/polygon.hpp>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
template <typename T>
template<typename T>
struct polygon_vertex_processor
{
template <typename Path>
void add_path(Path & path)
template<typename Path>
void add_path(Path& path)
{
point<T> p;
unsigned cmd;
@ -61,6 +62,7 @@ struct polygon_vertex_processor
polygon<T> polygon_;
};
} }
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_POLYGON_VERTEX_PROCESSOR_HPP

View file

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

View file

@ -26,34 +26,36 @@
#include <mapnik/geometry.hpp>
#include <mapnik/geometry/is_empty.hpp>
namespace mapnik { namespace geometry {
namespace mapnik {
namespace geometry {
namespace detail {
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);
}
mapnik::geometry::multi_polygon<double> operator() (mapnik::geometry::multi_polygon<double> const& geom) const
mapnik::geometry::multi_polygon<double> operator()(mapnik::geometry::multi_polygon<double> const& geom) const
{
return remove_empty(geom);
}
template <typename T>
T operator() (T const& geom) const
template<typename T>
T operator()(T const& geom) const
{
return geom;
}
private:
template <typename T>
private:
template<typename T>
T remove_empty(T const& geom) const
{
T new_geom;
for (auto const & g : geom)
for (auto const& g : geom)
{
if (!g.empty())
{
@ -64,14 +66,15 @@ private:
}
};
}
} // namespace detail
template <typename GeomType>
template<typename GeomType>
inline GeomType remove_empty(GeomType const& geom)
{
return detail::geometry_remove_empty()(geom);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_REMOVE_EMPTY_HPP

View file

@ -27,7 +27,6 @@
#include <mapnik/proj_transform.hpp>
#include <mapnik/geometry.hpp>
namespace mapnik {
namespace geometry {
@ -37,28 +36,27 @@ namespace geometry {
// This is done this way so that large geometry collections that only have a few failing points or polygon parts could
// still be return with out the few failing projections.
template <typename T>
MAPNIK_DECL geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template<typename T>
MAPNIK_DECL geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int& n_err);
template <typename T>
MAPNIK_DECL T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template <typename T>
MAPNIK_DECL T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template<typename T>
MAPNIK_DECL T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int& n_err);
template<typename T>
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.
// 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.
template <typename T>
MAPNIK_DECL bool reproject(T & geom, proj_transform const& proj_trans);
template<typename T>
MAPNIK_DECL bool reproject(T& geom, proj_transform const& proj_trans);
template <typename T>
MAPNIK_DECL bool reproject(T & geom, projection const& source, projection const& dest);
template<typename T>
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

View file

@ -24,16 +24,18 @@
#include <mapnik/geometry/reprojection.hpp>
#include <mapnik/geometry.hpp>
namespace mapnik { namespace geometry { namespace detail {
namespace mapnik {
namespace geometry {
namespace detail {
//template <typename T>
geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int &)
// template <typename T>
geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int&)
{
return geometry_empty();
}
template <typename T>
point<T> reproject_internal(point<T> const& p, proj_transform const& proj_trans, unsigned int & n_err)
template<typename T>
point<T> reproject_internal(point<T> const& p, proj_transform const& proj_trans, unsigned int& n_err)
{
point<T> new_p(p);
if (!proj_trans.forward(new_p))
@ -43,8 +45,8 @@ point<T> reproject_internal(point<T> const& p, proj_transform const& proj_trans,
return new_p;
}
template <typename T>
line_string<T> reproject_internal(line_string<T> const& ls, proj_transform const& proj_trans, unsigned int & n_err)
template<typename T>
line_string<T> reproject_internal(line_string<T> const& ls, proj_transform const& proj_trans, unsigned int& n_err)
{
line_string<T> new_ls(ls);
unsigned int err = proj_trans.forward(new_ls);
@ -55,8 +57,8 @@ line_string<T> reproject_internal(line_string<T> const& ls, proj_transform const
return new_ls;
}
template <typename T>
polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj_trans, unsigned int & n_err)
template<typename T>
polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj_trans, unsigned int& n_err)
{
polygon<T> new_poly;
new_poly.reserve(poly.size());
@ -70,17 +72,18 @@ polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj
n_err += err;
// If there is an error in interior ring drop
// 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));
}
return new_poly;
}
template <typename T>
multi_point<T> reproject_internal(multi_point<T> const & mp, proj_transform const& proj_trans, unsigned int & n_err)
template<typename T>
multi_point<T> reproject_internal(multi_point<T> const& mp, proj_transform const& proj_trans, unsigned int& n_err)
{
multi_point<T> new_mp;
if (proj_trans.is_known())
@ -109,8 +112,9 @@ multi_point<T> reproject_internal(multi_point<T> const & mp, proj_transform cons
return new_mp;
}
template <typename T>
multi_line_string<T> reproject_internal(multi_line_string<T> const & mls, proj_transform const& proj_trans, unsigned int & n_err)
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> new_mls;
new_mls.reserve(mls.size());
@ -125,8 +129,9 @@ multi_line_string<T> reproject_internal(multi_line_string<T> const & mls, proj_t
return new_mls;
}
template <typename T>
multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transform const& proj_trans, unsigned int & n_err)
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> new_mpoly;
new_mpoly.reserve(mpoly.size());
@ -141,14 +146,14 @@ multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transfo
return new_mpoly;
}
template <typename T>
geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj_transform const& proj_trans, unsigned int & n_err)
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> new_c;
new_c.reserve(c.size());
for (auto const& g : c)
{
geometry<T> new_g = reproject_copy(g, proj_trans, n_err);
if (!new_g.template is<geometry_empty>())
{
@ -158,107 +163,110 @@ geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj
return new_c;
}
template <typename T>
template<typename T>
struct geom_reproj_copy_visitor
{
geom_reproj_copy_visitor(proj_transform const& proj_trans, unsigned int& n_err)
: proj_trans_(proj_trans)
, n_err_(n_err)
{}
geom_reproj_copy_visitor(proj_transform const & proj_trans, unsigned int & n_err)
: proj_trans_(proj_trans),
n_err_(n_err) {}
geometry<T> operator()(geometry_empty) const { return geometry_empty(); }
geometry<T> operator() (geometry_empty) const
{
return geometry_empty();
}
geometry<T> operator() (point<T> const& p) const
geometry<T> operator()(point<T> const& p) const
{
geometry<T> geom; // default empty
unsigned int intial_err = 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);
return geom;
}
geometry<T> operator() (line_string<T> const& ls) const
geometry<T> operator()(line_string<T> const& ls) const
{
geometry<T> geom; // default empty
unsigned int intial_err = 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);
return geom;
}
geometry<T> operator() (polygon<T> const& poly) const
geometry<T> operator()(polygon<T> const& poly) const
{
geometry<T> geom; // default empty
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);
return geom;
}
geometry<T> operator() (multi_point<T> const& mp) const
geometry<T> operator()(multi_point<T> const& mp) const
{
geometry<T> geom; // default empty
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);
return geom;
}
geometry<T> operator() (multi_line_string<T> const& mls) const
geometry<T> operator()(multi_line_string<T> const& mls) const
{
geometry<T> geom; // default empty
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);
return geom;
}
geometry<T> operator() (multi_polygon<T> const& mpoly) const
geometry<T> operator()(multi_polygon<T> const& mpoly) const
{
geometry<T> geom; // default empty
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);
return geom;
}
geometry<T> operator() (geometry_collection<T> const& c) const
geometry<T> operator()(geometry_collection<T> const& c) const
{
geometry<T> geom; // default empty
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);
return geom;
}
private:
private:
proj_transform const& proj_trans_;
unsigned int & n_err_;
unsigned int& n_err_;
};
} // end detail ns
} // namespace detail
template <typename T>
geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int & n_err)
template<typename T>
geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int& n_err)
{
detail::geom_reproj_copy_visitor<T> visit(proj_trans, n_err);
return mapnik::util::apply_visitor(visit, geom);
}
template <typename T>
T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err)
template<typename T>
T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int& n_err)
{
return detail::reproject_internal(geom, proj_trans, n_err);
}
template <typename T>
T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int & n_err)
template<typename T>
T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int& n_err)
{
proj_transform proj_trans(source, dest);
return reproject_copy(geom, proj_trans, n_err);
@ -266,22 +274,23 @@ T reproject_copy(T const& geom, projection const& source, projection const& dest
namespace detail {
struct geom_reproj_visitor {
struct geom_reproj_visitor
{
geom_reproj_visitor(proj_transform const& proj_trans)
: proj_trans_(proj_trans)
{}
geom_reproj_visitor(proj_transform const & proj_trans)
: proj_trans_(proj_trans) {}
template <typename T>
bool operator() (geometry<T> & geom) const
template<typename T>
bool operator()(geometry<T>& geom) const
{
return mapnik::util::apply_visitor((*this), geom);
}
//template <typename T>
bool operator() (geometry_empty &) const { return true; }
// template <typename T>
bool operator()(geometry_empty&) const { return true; }
template <typename T>
bool operator() (point<T> & p) const
template<typename T>
bool operator()(point<T>& p) const
{
if (!proj_trans_.forward(p))
{
@ -290,8 +299,8 @@ struct geom_reproj_visitor {
return true;
}
template <typename T>
bool operator() (line_string<T> & ls) const
template<typename T>
bool operator()(line_string<T>& ls) const
{
if (proj_trans_.forward(ls) > 0)
{
@ -300,10 +309,10 @@ struct geom_reproj_visitor {
return true;
}
template <typename T>
bool operator() (polygon<T> & poly) const
template<typename T>
bool operator()(polygon<T>& poly) const
{
for (auto & lr : poly)
for (auto& lr : poly)
{
if (proj_trans_.forward(lr) > 0)
{
@ -313,8 +322,8 @@ struct geom_reproj_visitor {
return true;
}
template <typename T>
bool operator() (multi_point<T> & mp) const
template<typename T>
bool operator()(multi_point<T>& mp) const
{
if (proj_trans_.forward(mp) > 0)
{
@ -323,12 +332,12 @@ struct geom_reproj_visitor {
return true;
}
template <typename T>
bool operator() (multi_line_string<T> & mls) const
template<typename T>
bool operator()(multi_line_string<T>& mls) const
{
for (auto & ls : mls)
for (auto& ls : mls)
{
if (! (*this) (ls))
if (!(*this)(ls))
{
return false;
}
@ -336,12 +345,12 @@ struct geom_reproj_visitor {
return true;
}
template <typename T>
bool operator() (multi_polygon<T> & mpoly) const
template<typename T>
bool operator()(multi_polygon<T>& mpoly) const
{
for (auto & poly : mpoly)
for (auto& poly : mpoly)
{
if(! (*this)(poly))
if (!(*this)(poly))
{
return false;
}
@ -349,12 +358,12 @@ struct geom_reproj_visitor {
return true;
}
template <typename T>
bool operator() (geometry_collection<T> & c) const
template<typename T>
bool operator()(geometry_collection<T>& c) const
{
for (auto & g : c)
for (auto& g : c)
{
if (! (*this)(g) )
if (!(*this)(g))
{
return false;
}
@ -362,27 +371,26 @@ struct geom_reproj_visitor {
return true;
}
private:
private:
proj_transform const& proj_trans_;
};
} // end detail ns
} // namespace detail
template <typename T>
bool reproject(T & geom, proj_transform const& proj_trans)
template<typename T>
bool reproject(T& geom, proj_transform const& proj_trans)
{
detail::geom_reproj_visitor visit(proj_trans);
return visit(geom);
}
template <typename T>
bool reproject(T & geom, projection const& source, projection const& dest)
template<typename T>
bool reproject(T& geom, projection const& source, projection const& dest)
{
proj_transform proj_trans(source, dest);
detail::geom_reproj_visitor visit(proj_trans);
return visit(geom);
}
} // end geometry ns
} // end mapnik ns
} // namespace geometry
} // namespace mapnik

View file

@ -29,129 +29,133 @@
namespace mapnik {
namespace geometry {
namespace helper
{
template <std::size_t... Ts>
struct index {};
namespace helper {
template<std::size_t... Ts>
struct index
{};
template <std::size_t N, std::size_t... Ts>
struct gen_seq : gen_seq<N - 1, N - 1, Ts...> {};
template<std::size_t N, std::size_t... Ts>
struct gen_seq : gen_seq<N - 1, N - 1, Ts...>
{};
template <std::size_t... Ts>
struct gen_seq<0, Ts...> : index<Ts...> {};
}
template<std::size_t... 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.
template <typename... Strategies>
template<typename... Strategies>
struct strategy_group
{
strategy_group(Strategies const& ... ops)
: ops_(ops ...) {}
strategy_group(Strategies const&... ops)
: ops_(ops...)
{}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
template<typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const
{
bool status = true;
p2 = execute_start<P1,P2>(p1, status, ops_);
p2 = execute_start<P1, P2>(p1, status, ops_);
return status;
}
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
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
{
return execute<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
return execute<P1, P2, Args...>(p1, status, std::get<Is>(tup)...);
}
template <typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
template<typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool& status, std::tuple<Strategies const&...> const& tup) const
{
return execute_start<P1,P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)> {} );
return execute_start<P1, P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)>{});
}
template <typename P1, typename P2, typename T, typename ...Args>
inline P2 execute(P1 const& p, bool & status, T const& strat, Args const& ... args) const
template<typename P1, typename P2, typename T, typename... Args>
inline P2 execute(P1 const& p, bool& status, T const& strat, Args const&... args) const
{
return execute<P1,P2>(strat.template execute<P1,P1>(p, status), status, args...);
return execute<P1, P2>(strat.template execute<P1, P1>(p, status), status, args...);
}
template <typename P1, typename P2, typename T>
inline P2 execute(P1 const& p, bool & status, T const& strat) const
template<typename P1, typename P2, typename T>
inline P2 execute(P1 const& p, bool& status, T const& strat) const
{
return strat.template execute<P1,P2>(p, status);
return strat.template execute<P1, P2>(p, status);
}
private:
std::tuple<Strategies const& ...> ops_;
private:
std::tuple<Strategies const&...> ops_;
};
// 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.
template <typename... Strategies>
template<typename... Strategies>
struct strategy_group_first
{
strategy_group_first(Strategies const& ... ops)
: ops_(ops ...) {}
strategy_group_first(Strategies const&... ops)
: ops_(ops...)
{}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
template<typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const
{
bool status = true;
p2 = execute_start<P1,P2>(p1, status, ops_);
p2 = execute_start<P1, P2>(p1, status, ops_);
return status;
}
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
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
{
return execute_first<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
return execute_first<P1, P2, Args...>(p1, status, std::get<Is>(tup)...);
}
template <typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
template<typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool& status, std::tuple<Strategies const&...> const& tup) const
{
return execute_start<P1,P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)> {} );
return execute_start<P1, P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)>{});
}
template <typename P1, typename P2, typename T, typename ...Args>
inline P2 execute_first(P1 const& p, bool & status, T const& strat, Args const& ... args) const
template<typename P1, typename P2, typename T, typename... Args>
inline P2 execute_first(P1 const& p, bool& status, T const& strat, Args const&... args) const
{
return execute<P2>(strat.template execute<P1,P2>(p, status), status, args...);
return execute<P2>(strat.template execute<P1, P2>(p, status), status, args...);
}
template <typename P2, typename T, typename ...Args>
inline P2 execute(P2 const& p, bool & status, T const& strat, Args const& ... args) const
template<typename P2, typename T, typename... Args>
inline P2 execute(P2 const& p, bool& status, T const& strat, Args const&... args) const
{
return execute<P2>(strat.template execute<P2,P2>(p, status), status, args...);
return execute<P2>(strat.template execute<P2, P2>(p, status), status, args...);
}
template <typename P2, typename T>
inline P2 execute(P2 const& p, bool & status, T const& strat) const
template<typename P2, typename T>
inline P2 execute(P2 const& p, bool& status, T const& strat) const
{
return strat.template execute<P2,P2>(p, status);
return strat.template execute<P2, P2>(p, status);
}
template <typename P2>
inline P2 execute(P2 const& p, bool & status) const
template<typename P2>
inline P2 execute(P2 const& p, bool& status) const
{
return p;
}
private:
std::tuple<Strategies const& ...> ops_;
private:
std::tuple<Strategies const&...> ops_;
};
struct scale_strategy
{
scale_strategy(double scale, double offset = 0)
: scale_(scale), offset_(offset) {}
: scale_(scale)
, offset_(offset)
{}
template <typename P1, typename P2>
inline bool apply(P1 const & p1, P2 & p2) const
template<typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const
{
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
@ -160,15 +164,15 @@ struct scale_strategy
return true;
}
template <typename P1, typename P2>
inline P2 execute(P1 const& p1, bool & status) const
template<typename P1, typename P2>
inline P2 execute(P1 const& p1, bool& status) const
{
P2 p2;
status = apply(p1, p2);
return p2;
}
private:
private:
double scale_;
double offset_;
};
@ -176,12 +180,13 @@ private:
struct scale_rounding_strategy
{
scale_rounding_strategy(double scale, double offset = 0)
: scale_(scale), offset_(offset) {}
: scale_(scale)
, offset_(offset)
{}
template <typename P1, typename P2>
inline bool apply(P1 const & p1, P2 & p2) const
template<typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const
{
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
@ -190,21 +195,20 @@ struct scale_rounding_strategy
return true;
}
template <typename P1, typename P2>
inline P2 execute(P1 const& p1, bool & status) const
template<typename P1, typename P2>
inline P2 execute(P1 const& p1, bool& status) const
{
P2 p2;
status = apply(p1, p2);
return p2;
}
private:
private:
double scale_;
double offset_;
};
} // namespace geometry
} // namespace mapnik
} // end geometry ns
} // end mapnik ns
#endif //MAPNIK_GEOMETRY_STRATEGY_HPP
#endif // MAPNIK_GEOMETRY_STRATEGY_HPP

View file

@ -26,46 +26,51 @@
#include <mapnik/geometry.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
{
geometry_to_path(path_type & p)
: p_(p) {}
geometry_to_path(path_type& p)
: p_(p)
{}
void operator() (geometry<T> const& geom) const
{
mapnik::util::apply_visitor(*this, geom);
}
void operator()(geometry<T> const& geom) const { mapnik::util::apply_visitor(*this, geom); }
void operator() (geometry_empty const&) const
void operator()(geometry_empty const&) const
{
// no-op
}
// point
void operator() (point<T> const& pt) const
void operator()(point<T> const& pt) const
{
//point pt_new;
//Transformer::apply(pt, pt_new);
// point pt_new;
// Transformer::apply(pt, pt_new);
p_.move_to(pt.x, pt.y);
}
// line_string
void operator() (line_string<T> const& line) const
void operator()(line_string<T> const& line) const
{
bool first = true;
for (auto const& pt : line)
{
//point pt_new;
//Transformer::apply(pt, pt_new);
if (first) { p_.move_to(pt.x, pt.y); first=false;}
else p_.line_to(pt.x, pt.y);
// point pt_new;
// Transformer::apply(pt, pt_new);
if (first)
{
p_.move_to(pt.x, pt.y);
first = false;
}
else
p_.line_to(pt.x, pt.y);
}
}
// polygon
void operator() (polygon<T> const& poly) const
void operator()(polygon<T> const& poly) const
{
// rings: exterior *interior
for (auto const& ring : poly)
@ -76,7 +81,7 @@ struct geometry_to_path
if (first)
{
p_.move_to(pt.x, pt.y);
first=false;
first = false;
}
else
{
@ -91,7 +96,7 @@ struct geometry_to_path
}
// multi point
void operator() (multi_point<T> const& multi_pt) const
void operator()(multi_point<T> const& multi_pt) const
{
for (auto const& pt : multi_pt)
{
@ -99,7 +104,7 @@ struct geometry_to_path
}
}
// multi_line_string
void operator() (multi_line_string<T> const& multi_line) const
void operator()(multi_line_string<T> const& multi_line) const
{
for (auto const& line : multi_line)
{
@ -108,7 +113,7 @@ struct geometry_to_path
}
// multi_polygon
void operator() (multi_polygon<T> const& multi_poly) const
void operator()(multi_polygon<T> const& multi_poly) const
{
for (auto const& poly : multi_poly)
{
@ -116,27 +121,27 @@ struct geometry_to_path
}
}
// geometry_collection
void operator() (geometry_collection<T> const& collection) const
void operator()(geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
for (auto const& geom : collection)
{
(*this)(geom);
}
}
path_type & p_;
path_type& p_;
};
} // ns detail
} // namespace detail
template <typename T>
void to_path(T const& geom, path_type & p)
template<typename T>
void to_path(T const& geom, path_type& p)
{
using coordinate_type = typename T::coordinate_type;
detail::geometry_to_path<coordinate_type> func(p);
func(geom);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_TO_PATH_HPP

View file

@ -27,9 +27,11 @@
#include <mapnik/geometry/boost_adapters.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)
{
point<V> geom_transformed;
@ -40,7 +42,7 @@ inline point<V> transform_geometry(point<T> const& geom, Transformer const& tran
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
template<typename V, typename T, typename Transformer>
inline multi_point<V> transform_geometry(multi_point<T> const& geom, Transformer const& transformer)
{
multi_point<V> geom_transformed;
@ -51,7 +53,7 @@ inline multi_point<V> transform_geometry(multi_point<T> const& geom, Transformer
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
template<typename V, typename T, typename Transformer>
inline line_string<V> transform_geometry(line_string<T> const& geom, Transformer const& transformer)
{
line_string<V> geom_transformed;
@ -62,7 +64,7 @@ inline line_string<V> transform_geometry(line_string<T> const& geom, Transformer
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
template<typename V, typename T, typename Transformer>
inline multi_line_string<V> transform_geometry(multi_line_string<T> const& geom, Transformer const& transformer)
{
multi_line_string<V> geom_transformed;
@ -73,7 +75,7 @@ inline multi_line_string<V> transform_geometry(multi_line_string<T> const& geom,
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
template<typename V, typename T, typename Transformer>
inline polygon<V> transform_geometry(polygon<T> const& geom, Transformer const& transformer)
{
polygon<V> geom_transformed;
@ -84,7 +86,7 @@ inline polygon<V> transform_geometry(polygon<T> const& geom, Transformer const&
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
template<typename V, typename T, typename Transformer>
inline multi_polygon<V> transform_geometry(multi_polygon<T> const& geom, Transformer const& transformer)
{
multi_polygon<V> geom_transformed;
@ -95,68 +97,66 @@ inline multi_polygon<V> transform_geometry(multi_polygon<T> const& geom, Transfo
return geom_transformed;
}
template <typename Transformer, typename V>
template<typename Transformer, typename V>
struct geometry_transform
{
geometry_transform(Transformer const& transformer)
: transformer_(transformer) {}
: transformer_(transformer)
{}
using result_type = geometry<V>;
geometry<V> operator() (geometry_empty const& empty) const
{
return geometry_empty();
}
geometry<V> operator()(geometry_empty const& empty) const { return geometry_empty(); }
template <typename T>
geometry<V> operator() (geometry_collection<T> const& collection) const
template<typename T>
geometry<V> operator()(geometry_collection<T> const& collection) const
{
geometry_collection<V> collection_out;
for (auto const& geom : collection)
for (auto const& geom : collection)
{
collection_out.push_back((*this)(geom));
}
return collection_out;
}
template <typename T>
geometry<V> operator() (geometry<T> const& geom) const
template<typename T>
geometry<V> operator()(geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
template <typename T>
geometry<V> operator() (point<T> const& geom) const
template<typename T>
geometry<V> operator()(point<T> const& geom) const
{
return transform_geometry<V>(geom, transformer_);
}
template <typename T>
geometry<V> operator() (line_string<T> const& geom) const
template<typename T>
geometry<V> operator()(line_string<T> const& geom) const
{
return transform_geometry<V>(geom, transformer_);
}
template <typename T>
geometry<V> operator() (polygon<T> const& geom) const
template<typename T>
geometry<V> operator()(polygon<T> const& geom) const
{
return transform_geometry<V>(geom, transformer_);
}
template <typename T>
geometry<V> operator() (multi_point<T> const& geom) const
template<typename T>
geometry<V> operator()(multi_point<T> const& geom) const
{
return transform_geometry<V>(geom, transformer_);
}
template <typename T>
geometry<V> operator() (multi_line_string<T> const& geom) const
template<typename T>
geometry<V> operator()(multi_line_string<T> const& geom) const
{
return transform_geometry<V>(geom, transformer_);
}
template <typename T>
geometry<V> operator() (multi_polygon<T> const& geom) const
template<typename T>
geometry<V> operator()(multi_polygon<T> const& geom) const
{
return transform_geometry<V>(geom, transformer_);
}
@ -164,57 +164,57 @@ struct geometry_transform
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)
{
return detail::geometry_transform<T2, T0>(transformer)(geom);
}
template <typename T0, typename T1, typename T2>
template<typename T0, typename T1, typename T2>
geometry<T0> transform(geometry_collection<T1> const& geom, T2 const& transformer)
{
return detail::geometry_transform<T2, T0>(transformer)(geom);
}
template <typename T0, typename T1, typename T2>
template<typename T0, typename T1, typename T2>
point<T0> transform(point<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
template<typename T0, typename T1, typename T2>
multi_point<T0> transform(multi_point<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
template<typename T0, typename T1, typename T2>
line_string<T0> transform(line_string<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
template<typename T0, typename T1, typename T2>
multi_line_string<T0> transform(multi_line_string<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
template<typename T0, typename T1, typename T2>
polygon<T0> transform(polygon<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
template<typename T0, typename T1, typename T2>
multi_polygon<T0> transform(multi_polygon<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
}}
} // namespace geometry
} // namespace mapnik
#endif // MAPNIK_GEOMETRY_TRANSFORM_HPP

View file

@ -28,86 +28,84 @@
#include <cstring>
#include <cmath>
namespace mapnik
{
namespace mapnik {
#define int2net(A) (int16_t) (((std::uint16_t) ((std::uint8_t) (A)[1])) | \
(((std::uint16_t) ((std::uint8_t) (A)[0])) << 8))
#define int2net(A) (int16_t)(((std::uint16_t)((std::uint8_t)(A)[1])) | (((std::uint16_t)((std::uint8_t)(A)[0])) << 8))
#define int4net(A) (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)[0])) << 24))
#define int4net(A) \
(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)[0])) << 24))
#define int8net(A) (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)[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)[1])) << 48) | \
(((std::uint64_t) ((std::uint8_t) (A)[0])) << 56))
#define float8net(V,M) do { double def_temp; \
((std::uint8_t*) &def_temp)[0]=(M)[7]; \
((std::uint8_t*) &def_temp)[1]=(M)[6]; \
((std::uint8_t*) &def_temp)[2]=(M)[5]; \
((std::uint8_t*) &def_temp)[3]=(M)[4]; \
((std::uint8_t*) &def_temp)[4]=(M)[3]; \
((std::uint8_t*) &def_temp)[5]=(M)[2]; \
((std::uint8_t*) &def_temp)[6]=(M)[1]; \
((std::uint8_t*) &def_temp)[7]=(M)[0]; \
(V) = 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)[1]=(M)[2]; \
((std::uint8_t*) &def_temp)[2]=(M)[1]; \
((std::uint8_t*) &def_temp)[3]=(M)[0]; \
(V)=def_temp; } while(0)
#define int8net(A) \
(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)[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)[1])) << 48) | (((std::uint64_t)((std::uint8_t)(A)[0])) << 56))
#define float8net(V, M) \
do \
{ \
double def_temp; \
((std::uint8_t*)&def_temp)[0] = (M)[7]; \
((std::uint8_t*)&def_temp)[1] = (M)[6]; \
((std::uint8_t*)&def_temp)[2] = (M)[5]; \
((std::uint8_t*)&def_temp)[3] = (M)[4]; \
((std::uint8_t*)&def_temp)[4] = (M)[3]; \
((std::uint8_t*)&def_temp)[5] = (M)[2]; \
((std::uint8_t*)&def_temp)[6] = (M)[1]; \
((std::uint8_t*)&def_temp)[7] = (M)[0]; \
(V) = 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)[1] = (M)[2]; \
((std::uint8_t*)&def_temp)[2] = (M)[1]; \
((std::uint8_t*)&def_temp)[3] = (M)[0]; \
(V) = def_temp; \
} while (0)
// 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)
{
std::memcpy(&val,data,2);
std::memcpy(&val, data, 2);
}
// read int32_t NDR (little endian)
inline void read_int32_ndr(const char* data, std::int32_t & val)
inline void read_int32_ndr(const char* data, std::int32_t& val)
{
std::memcpy(&val,data,4);
std::memcpy(&val, data, 4);
}
// read double NDR (little endian)
inline void read_double_ndr(const char* data, double & val)
inline void read_double_ndr(const char* data, double& val)
{
std::memcpy(&val,&data[0],8);
std::memcpy(&val, &data[0], 8);
}
// read int16_t XDR (big endian)
inline void read_int16_xdr(const char* data, std::int16_t & val)
inline void read_int16_xdr(const char* data, std::int16_t& val)
{
val = static_cast<std::int16_t>((data[3]&0xff) | ((data[2]&0xff)<<8));
val = static_cast<std::int16_t>((data[3] & 0xff) | ((data[2] & 0xff) << 8));
}
// read int32_t XDR (big endian)
inline void read_int32_xdr(const char* data, std::int32_t & val)
inline void read_int32_xdr(const char* data, std::int32_t& val)
{
val = (data[3]&0xff) | ((data[2]&0xff)<<8) | ((data[1]&0xff)<<16) | ((data[0]&0xff)<<24);
val = (data[3] & 0xff) | ((data[2] & 0xff) << 8) | ((data[1] & 0xff) << 16) | ((data[0] & 0xff) << 24);
}
// 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) |
(static_cast<std::int64_t>(data[6]) & 0xff) << 8 |
(static_cast<std::int64_t>(data[5]) & 0xff) << 16 |
(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[1]) & 0xff) << 48 |
(static_cast<std::int64_t>(data[0]) & 0xff) << 56 ;
std::memcpy(&val,&bits,8);
std::int64_t bits =
(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[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[1]) & 0xff) << 48 | (static_cast<std::int64_t>(data[0]) & 0xff) << 56;
std::memcpy(&val, &bits, 8);
}
#if defined(_MSC_VER) && _MSC_VER < 1800
@ -117,6 +115,6 @@ inline double round(double val)
}
#endif
}
} // namespace mapnik
#endif // MAPNIK_GLOBAL_HPP

View file

@ -35,24 +35,18 @@ MAPNIK_DISABLE_WARNING_POP
// stl
#include <vector>
namespace mapnik
{
namespace mapnik {
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
{
NO_GRADIENT,
LINEAR,
RADIAL
};
enum gradient_e { NO_GRADIENT, LINEAR, RADIAL };
enum gradient_unit_e
{
enum gradient_unit_e {
USER_SPACE_ON_USE,
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
@ -72,17 +66,17 @@ class MAPNIK_DECL gradient
gradient_unit_e units_;
gradient_e gradient_type_;
public:
public:
gradient();
gradient(gradient const& other);
gradient(gradient && other);
gradient(gradient&& other);
gradient& operator=(gradient rhs);
bool operator==(gradient const& other) const;
void set_gradient_type(gradient_e grad);
gradient_e get_gradient_type() const;
void set_transform(agg::trans_affine const& transform);
agg::trans_affine const& get_transform() const;
agg::trans_affine const& get_transform() const;
void set_units(gradient_unit_e units);
gradient_unit_e get_units() const;
@ -92,13 +86,13 @@ public:
stop_array const& get_stop_array() const;
void set_control_points(double x1, double y1, double x2, double y2, double r=0);
void get_control_points(double &x1, double &y1, double &x2, double &y2, double &r) const;
void get_control_points(double &x1, double &y1, double &x2, double &y2) const;
void set_control_points(double x1, double y1, double x2, double y2, double r = 0);
void get_control_points(double& x1, double& y1, double& x2, double& y2, double& r) const;
void get_control_points(double& x1, double& y1, double& x2, double& y2) const;
private:
private:
void swap(gradient& other) noexcept;
};
}
} // namespace mapnik
#endif // MAPNIK_GRADIENT_HPP

View file

@ -42,13 +42,12 @@
#include <string>
#include <vector>
namespace mapnik
{
namespace mapnik {
template <typename T>
template<typename T>
class MAPNIK_DECL hit_grid
{
public:
public:
using value_type = typename T::type;
using data_type = mapnik::image<T>;
using lookup_type = std::string;
@ -57,7 +56,7 @@ public:
using feature_type = std::map<lookup_type, mapnik::feature_ptr>;
static const value_type base_mask;
private:
private:
std::size_t width_;
std::size_t height_;
std::string key_;
@ -69,7 +68,7 @@ private:
feature_type features_;
mapnik::context_ptr ctx_;
public:
public:
hit_grid(std::size_t width, std::size_t height, std::string const& key);
@ -79,94 +78,48 @@ public:
void clear();
inline void painted(bool is_painted)
{
painted_ = is_painted;
}
inline void painted(bool is_painted) { painted_ = is_painted; }
inline bool painted() const
{
return painted_;
}
inline bool painted() const { return painted_; }
inline std::string const& key_name() const
{
return id_name_;
}
inline std::string const& key_name() const { return id_name_; }
void add_feature(mapnik::feature_impl const& feature);
inline void add_field(std::string const& name)
{
names_.insert(name);
}
inline void add_field(std::string const& name) { names_.insert(name); }
inline std::set<std::string> const& get_fields() const
{
return names_;
}
inline std::set<std::string> const& get_fields() const { return names_; }
inline feature_type const& get_grid_features() const
{
return features_;
}
inline feature_type const& get_grid_features() const { return features_; }
inline feature_key_type const& get_feature_keys() const
{
return f_keys_;
}
inline feature_key_type const& get_feature_keys() const { return f_keys_; }
inline std::string const& get_key() const
{
return key_;
}
inline std::string const& get_key() const { return key_; }
inline void set_key(std::string const& key)
{
key_ = key;
}
inline void set_key(std::string const& key) { key_ = key; }
inline data_type const& data() const
{
return data_;
}
inline data_type const& data() const { return data_; }
inline data_type& data()
{
return data_;
}
inline data_type& data() { return data_; }
inline value_type const * raw_data() const
{
return data_.data();
}
inline value_type const* raw_data() const { return data_.data(); }
inline value_type* raw_data()
{
return data_.data();
}
inline value_type* raw_data() { return data_.data(); }
inline value_type const * get_row(std::size_t row) const
{
return data_.get_row(row);
}
inline value_type const* get_row(std::size_t row) const { 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)
{
return mapnik::grid_view(x, y, w, h,
data_, key_, id_name_, names_, f_keys_, features_);
return mapnik::grid_view(x, y, w, h, data_, key_, id_name_, names_, f_keys_, features_);
}
private:
private:
inline bool checkBounds(std::size_t x, std::size_t y) const
{
return (x < width_ && y < height_);
}
inline bool checkBounds(std::size_t x, std::size_t y) const { return (x < width_ && y < height_); }
hit_grid& operator=(const hit_grid&);
public:
public:
inline void setPixel(std::size_t x, std::size_t y, value_type feature_id)
{
if (checkBounds(x, y))
@ -174,15 +127,9 @@ public:
data_(x, y) = feature_id;
}
}
inline std::size_t width() const
{
return width_;
}
inline std::size_t width() const { return width_; }
inline std::size_t height() const
{
return height_;
}
inline std::size_t height() const { return height_; }
inline void set_rectangle(value_type id, image_rgba8 const& data, std::size_t x0, std::size_t y0)
{
@ -198,8 +145,8 @@ public:
std::size_t maxx = safe_cast<std::size_t>(box.maxx());
for (std::size_t y = miny; y < maxy; ++y)
{
value_type* row_to = data_.get_row(y);
image_rgba8::pixel_type const * row_from = data.get_row(y - y0);
value_type* row_to = data_.get_row(y);
image_rgba8::pixel_type const* row_from = data.get_row(y - y0);
for (std::size_t x = minx; x < maxx; ++x)
{
@ -219,5 +166,5 @@ public:
using grid = hit_grid<mapnik::value_integer_pixel>;
}
#endif //MAPNIK_GRID_HPP
} // namespace mapnik
#endif // MAPNIK_GRID_HPP

View file

@ -25,21 +25,15 @@
#include "agg_basics.h"
namespace mapnik
{
namespace mapnik {
//==================================================================gray16
struct gray16
{
using value_type = agg::int16u;
using calc_type = agg::int32u;
using long_type = agg::int64 ;
enum base_scale_e
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
using long_type = agg::int64;
enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
using self_type = gray16;
value_type v;
@ -49,18 +43,19 @@ struct gray16
gray16() {}
//--------------------------------------------------------------------
gray16(unsigned v_, unsigned a_=base_mask) :
v(agg::int16u(v_)), a(agg::int16u(a_)) {}
gray16(unsigned v_, unsigned a_ = base_mask)
: v(agg::int16u(v_))
, a(agg::int16u(a_))
{}
//--------------------------------------------------------------------
gray16(const self_type& c, unsigned a_) :
v(c.v), a(value_type(a_)) {}
gray16(const self_type& c, unsigned a_)
: v(c.v)
, a(value_type(a_))
{}
//--------------------------------------------------------------------
void clear()
{
v = a = 0;
}
void clear() { v = a = 0; }
//--------------------------------------------------------------------
const self_type& transparent()
@ -69,12 +64,12 @@ struct gray16
return *this;
}
//--------------------------------------------------------------------
const self_type& premultiply()
{
if(a == base_mask) return *this;
if(a == 0)
if (a == base_mask)
return *this;
if (a == 0)
{
v = 0;
return *this;
@ -86,8 +81,9 @@ struct gray16
//--------------------------------------------------------------------
const self_type& premultiply(unsigned a_)
{
if(a == base_mask && a_ >= base_mask) return *this;
if(a == 0 || a_ == 0)
if (a == base_mask && a_ >= base_mask)
return *this;
if (a == 0 || a_ == 0)
{
v = a = 0;
return *this;
@ -101,8 +97,9 @@ struct gray16
//--------------------------------------------------------------------
const self_type& demultiply()
{
if(a == base_mask) return *this;
if(a == 0)
if (a == base_mask)
return *this;
if (a == 0)
{
v = 0;
return *this;
@ -126,29 +123,31 @@ struct gray16
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cv, ca;
if(cover == agg::cover_mask)
if (cover == agg::cover_mask)
{
if(c.a == base_mask)
if (c.a == base_mask)
{
*this = c;
}
else
{
cv = v + c.v; 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;
cv = v + c.v;
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
{
cv = v + ((c.v * cover + agg::cover_mask/2) >> agg::cover_shift);
ca = a + ((c.a * cover + agg::cover_mask/2) >> agg::cover_shift);
cv = v + ((c.v * cover + agg::cover_mask / 2) >> agg::cover_shift);
ca = a + ((c.a * cover + agg::cover_mask / 2) >> agg::cover_shift);
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0); }
static self_type no_color() { return self_type(0, 0); }
};
//==================================================================gray32
@ -156,18 +155,13 @@ struct gray32
{
using value_type = agg::int32;
using calc_type = agg::int64u;
using long_type = agg::int64 ;
using long_type = agg::int64;
// NOTE: don't touch this enum since enums cannot be
// 64 bit and we need to ensure that alpha = base_mask
// in grid_pixfmt.hpp#blend_hiline#l256
// otherwise code will get invoked that breaks
// with 32 bit or 64 bit ints (blender_gray::blend_pix)
enum base_scale_e
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
using self_type = gray32;
value_type v;
@ -177,18 +171,19 @@ struct gray32
gray32() {}
//--------------------------------------------------------------------
gray32(value_type v_, unsigned a_=base_mask) :
v(v_), a(value_type(a_)) {}
gray32(value_type v_, unsigned a_ = base_mask)
: v(v_)
, a(value_type(a_))
{}
//--------------------------------------------------------------------
gray32(const self_type& c, unsigned a_) :
v(c.v), a(value_type(a_)) {}
gray32(const self_type& c, unsigned a_)
: v(c.v)
, a(value_type(a_))
{}
//--------------------------------------------------------------------
void clear()
{
v = a = 0;
}
void clear() { v = a = 0; }
//--------------------------------------------------------------------
const self_type& transparent()
@ -197,12 +192,12 @@ struct gray32
return *this;
}
//--------------------------------------------------------------------
const self_type& premultiply()
{
if(a == base_mask) return *this;
if(a == 0)
if (a == base_mask)
return *this;
if (a == 0)
{
v = 0;
return *this;
@ -214,8 +209,9 @@ struct gray32
//--------------------------------------------------------------------
const self_type& premultiply(unsigned a_)
{
if(a == base_mask && a_ >= base_mask) return *this;
if(a == 0 || a_ == 0)
if (a == base_mask && a_ >= base_mask)
return *this;
if (a == 0 || a_ == 0)
{
v = a = 0;
return *this;
@ -229,8 +225,9 @@ struct gray32
//--------------------------------------------------------------------
const self_type& demultiply()
{
if(a == base_mask) return *this;
if(a == 0)
if (a == base_mask)
return *this;
if (a == 0)
{
v = 0;
return *this;
@ -254,29 +251,31 @@ struct gray32
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cv, ca;
if(cover == agg::cover_mask)
if (cover == agg::cover_mask)
{
if(c.a == base_mask)
if (c.a == base_mask)
{
*this = c;
}
else
{
cv = v + c.v; 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;
cv = v + c.v;
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
{
cv = v + ((c.v * cover + agg::cover_mask/2) >> agg::cover_shift);
ca = a + ((c.a * cover + agg::cover_mask/2) >> agg::cover_shift);
cv = v + ((c.v * cover + agg::cover_mask / 2) >> agg::cover_shift);
ca = a + ((c.a * cover + agg::cover_mask / 2) >> agg::cover_shift);
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0); }
static self_type no_color() { return self_type(0, 0); }
};
//==================================================================gray64
@ -284,18 +283,13 @@ struct gray64
{
using value_type = agg::int64;
using calc_type = agg::int64u;
using long_type = agg::int64 ;
using long_type = agg::int64;
// NOTE: don't touch this enum since enums cannot be
// 64 bit and we need to ensure that alpha = base_mask
// in grid_pixfmt.hpp#blend_hiline#l256
// otherwise code will get invoked that breaks
// with 32 bit or 64 bit ints (blender_gray::blend_pix)
enum base_scale_e
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
using self_type = gray64;
value_type v;
@ -305,18 +299,19 @@ struct gray64
gray64() {}
//--------------------------------------------------------------------
gray64(value_type v_, unsigned a_=base_mask) :
v(v_), a(value_type(a_)) {}
gray64(value_type v_, unsigned a_ = base_mask)
: v(v_)
, a(value_type(a_))
{}
//--------------------------------------------------------------------
gray64(const self_type& c, unsigned a_) :
v(c.v), a(value_type(a_)) {}
gray64(const self_type& c, unsigned a_)
: v(c.v)
, a(value_type(a_))
{}
//--------------------------------------------------------------------
void clear()
{
v = a = 0;
}
void clear() { v = a = 0; }
//--------------------------------------------------------------------
const self_type& transparent()
@ -325,12 +320,12 @@ struct gray64
return *this;
}
//--------------------------------------------------------------------
const self_type& premultiply()
{
if(a == base_mask) return *this;
if(a == 0)
if (a == base_mask)
return *this;
if (a == 0)
{
v = 0;
return *this;
@ -342,8 +337,9 @@ struct gray64
//--------------------------------------------------------------------
const self_type& premultiply(unsigned a_)
{
if(a == base_mask && a_ >= base_mask) return *this;
if(a == 0 || a_ == 0)
if (a == base_mask && a_ >= base_mask)
return *this;
if (a == 0 || a_ == 0)
{
v = a = 0;
return *this;
@ -357,8 +353,9 @@ struct gray64
//--------------------------------------------------------------------
const self_type& demultiply()
{
if(a == base_mask) return *this;
if(a == 0)
if (a == base_mask)
return *this;
if (a == 0)
{
v = 0;
return *this;
@ -382,31 +379,33 @@ struct gray64
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cv, ca;
if(cover == agg::cover_mask)
if (cover == agg::cover_mask)
{
if(c.a == base_mask)
if (c.a == base_mask)
{
*this = c;
}
else
{
cv = v + c.v; 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;
cv = v + c.v;
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
{
cv = v + ((c.v * cover + agg::cover_mask/2) >> agg::cover_shift);
ca = a + ((c.a * cover + agg::cover_mask/2) >> agg::cover_shift);
cv = v + ((c.v * cover + agg::cover_mask / 2) >> agg::cover_shift);
ca = a + ((c.a * cover + agg::cover_mask / 2) >> agg::cover_shift);
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0); }
static self_type no_color() { return self_type(0, 0); }
};
}
} // namespace mapnik
#endif

View file

@ -33,96 +33,86 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/grid/grid_pixel.hpp>
MAPNIK_DISABLE_WARNING_POP
namespace mapnik
{
namespace mapnik {
//============================================================blender_gray
template<typename ColorT> struct blender_gray
template<typename ColorT>
struct blender_gray
{
using color_type = ColorT;
using value_type = typename color_type::value_type;
using calc_type = typename color_type::calc_type;
enum base_scale_e { base_shift = color_type::base_shift };
static AGG_INLINE void blend_pix(value_type* p, unsigned cv,
unsigned alpha, unsigned /*cover*/=0)
static AGG_INLINE void blend_pix(value_type* p, unsigned cv, unsigned alpha, unsigned /*cover*/ = 0)
{
*p = (value_type)((((cv - calc_type(*p)) * alpha) + (calc_type(*p) << base_shift)) >> base_shift);
}
};
//=====================================================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;
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)
{
*p = m_gamma.dir(*p);
}
AGG_INLINE void operator()(value_type* p) { *p = m_gamma.dir(*p); }
private:
private:
const GammaLut& m_gamma;
};
//=====================================================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;
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)
{
*p = m_gamma.inv(*p);
}
AGG_INLINE void operator()(value_type* p) { *p = m_gamma.inv(*p); }
private:
private:
const GammaLut& m_gamma;
};
//=================================================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
{
public:
using rbuf_type = RenBuf ;
public:
using rbuf_type = RenBuf;
using row_data = typename rbuf_type::row_data;
using blender_type = Blender ;
using blender_type = Blender;
using color_type = typename blender_type::color_type;
using order_type = int ; // A fake one
using value_type = typename color_type::value_type ;
using calc_type = typename color_type::calc_type ;
enum base_scale_e
{
using order_type = int; // A fake one
using value_type = typename color_type::value_type;
using calc_type = typename color_type::calc_type;
enum base_scale_e {
base_shift = color_type::base_shift,
base_scale = color_type::base_scale,
base_mask = color_type::base_mask,
pix_width = sizeof(value_type),
pix_step = Step,
base_mask = color_type::base_mask,
pix_width = sizeof(value_type),
pix_step = Step,
pix_offset = Offset
};
private:
private:
//--------------------------------------------------------------------
static AGG_INLINE void copy_or_blend_pix(value_type* p,
const color_type& c,
unsigned cover)
static AGG_INLINE void copy_or_blend_pix(value_type* p, const color_type& c, unsigned cover)
{
if (c.a)
{
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
if(alpha == base_mask)
if (alpha == base_mask)
{
*p = c.v;
}
@ -133,13 +123,11 @@ 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 == base_mask)
if (c.a == base_mask)
{
*p = c.v;
}
@ -150,11 +138,10 @@ private:
}
}
public:
public:
//--------------------------------------------------------------------
explicit pixfmt_alpha_blend_gray(rbuf_type& rb) :
m_rbuf(&rb)
explicit pixfmt_alpha_blend_gray(rbuf_type& rb)
: m_rbuf(&rb)
{}
void attach(rbuf_type& rb) { m_rbuf = &rb; }
//--------------------------------------------------------------------
@ -163,43 +150,31 @@ public:
bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2)
{
agg::rect_i r(x1, y1, x2, y2);
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();
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);
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);
return true;
}
return false;
}
//--------------------------------------------------------------------
AGG_INLINE unsigned width() const { return m_rbuf->width(); }
AGG_INLINE unsigned width() const { return m_rbuf->width(); }
AGG_INLINE unsigned height() const { return m_rbuf->height(); }
AGG_INLINE int stride() const { return m_rbuf->stride(); }
AGG_INLINE int stride() const { return m_rbuf->stride(); }
//--------------------------------------------------------------------
agg::int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); }
agg::int8u* row_ptr(int y) { 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
{
return m_rbuf->row_ptr(y) + x * Step + Offset;
}
const agg::int8u* pix_ptr(int x, int y) const { return m_rbuf->row_ptr(y) + x * Step + Offset; }
agg::int8u* pix_ptr(int x, int y)
{
return m_rbuf->row_ptr(y) + x * Step + Offset;
}
agg::int8u* pix_ptr(int x, int y) { return m_rbuf->row_ptr(y) + x * Step + Offset; }
//--------------------------------------------------------------------
AGG_INLINE static void make_pix(agg::int8u* p, const color_type& c)
{
*(value_type*)p = c.v;
}
AGG_INLINE static void make_pix(agg::int8u* p, const color_type& c) { *(value_type*)p = c.v; }
//--------------------------------------------------------------------
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)
{
copy_or_blend_pix((value_type*)
m_rbuf->row_ptr(x, y, 1) + x * Step + Offset,
c,
cover);
copy_or_blend_pix((value_type*)m_rbuf->row_ptr(x, y, 1) + x * Step + Offset, c, cover);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_hline(int x, int y,
unsigned len,
const color_type& c)
AGG_INLINE void copy_hline(int x, int y, unsigned len, const color_type& c)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do
{
*p = c.v;
p += Step;
}
while(--len);
} while (--len);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_vline(int x, int y,
unsigned len,
const color_type& c)
AGG_INLINE void copy_vline(int x, int y, unsigned len, const color_type& c)
{
do
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = c.v;
}
while(--len);
} while (--len);
}
//--------------------------------------------------------------------
void blend_hline(int x, int y,
unsigned len,
const color_type& c,
agg::int8u /*cover*/)
void blend_hline(int x, int y, unsigned len, const color_type& c, agg::int8u /*cover*/)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do
{
*p = c.v;
p += Step;
}
while(--len);
} while (--len);
// We ignore alpha since grid_renderer is a binary renderer for now
/*if (c.a)
{
@ -299,58 +255,45 @@ public:
}*/
}
//--------------------------------------------------------------------
void blend_vline(int x, int y,
unsigned len,
const color_type& c,
agg::int8u cover)
void blend_vline(int x, int y, unsigned len, const color_type& c, agg::int8u cover)
{
if (c.a)
{
value_type* p;
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
if(alpha == base_mask)
if (alpha == base_mask)
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = c.v;
}
while(--len);
} while (--len);
}
else
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
Blender::blend_pix(p, c.v, alpha, cover);
}
while(--len);
} while (--len);
}
}
}
//--------------------------------------------------------------------
void blend_solid_hspan(int x, int y,
unsigned len,
const color_type& c,
const agg::int8u* covers)
void blend_solid_hspan(int x, int y, unsigned len, const color_type& c, const agg::int8u* covers)
{
if (c.a)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do
{
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
if(alpha == base_mask)
if (alpha == base_mask)
{
*p = c.v;
}
@ -360,17 +303,12 @@ public:
}
p += Step;
++covers;
}
while(--len);
} while (--len);
}
}
//--------------------------------------------------------------------
void blend_solid_vspan(int x, int y,
unsigned len,
const color_type& c,
const agg::int8u* covers)
void blend_solid_vspan(int x, int y, unsigned len, const color_type& c, const agg::int8u* covers)
{
if (c.a)
{
@ -378,10 +316,9 @@ public:
{
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
if(alpha == base_mask)
if (alpha == base_mask)
{
*p = c.v;
}
@ -390,72 +327,59 @@ public:
Blender::blend_pix(p, c.v, alpha, *covers);
}
++covers;
}
while(--len);
} while (--len);
}
}
//--------------------------------------------------------------------
void copy_color_hspan(int x, int y,
unsigned len,
const color_type* colors)
void copy_color_hspan(int x, int y, unsigned len, const color_type* colors)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do
{
*p = colors->v;
p += Step;
++colors;
}
while(--len);
} while (--len);
}
//--------------------------------------------------------------------
void copy_color_vspan(int x, int y,
unsigned len,
const color_type* colors)
void copy_color_vspan(int x, int y, unsigned len, const color_type* colors)
{
do
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = colors->v;
++colors;
}
while(--len);
} while (--len);
}
//--------------------------------------------------------------------
void blend_color_hspan(int x, int y,
void blend_color_hspan(int x,
int y,
unsigned len,
const color_type* colors,
const agg::int8u* covers,
agg::int8u cover)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
if(covers)
if (covers)
{
do
{
copy_or_blend_pix(p, *colors++, *covers++);
p += Step;
}
while(--len);
} while (--len);
}
else
{
if(cover == 255)
if (cover == 255)
{
do
{
if(colors->a == base_mask)
if (colors->a == base_mask)
{
*p = colors->v;
}
@ -465,8 +389,7 @@ public:
}
p += Step;
++colors;
}
while(--len);
} while (--len);
}
else
{
@ -474,43 +397,38 @@ public:
{
copy_or_blend_pix(p, *colors++, cover);
p += Step;
}
while(--len);
} while (--len);
}
}
}
//--------------------------------------------------------------------
void blend_color_vspan(int x, int y,
void blend_color_vspan(int x,
int y,
unsigned len,
const color_type* colors,
const agg::int8u* covers,
agg::int8u cover)
{
value_type* p;
if(covers)
if (covers)
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
copy_or_blend_pix(p, *colors++, *covers++);
}
while(--len);
} while (--len);
}
else
{
if(cover == 255)
if (cover == 255)
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
if(colors->a == base_mask)
if (colors->a == base_mask)
{
*p = colors->v;
}
@ -519,72 +437,64 @@ public:
copy_or_blend_pix(p, *colors);
}
++colors;
}
while(--len);
} while (--len);
}
else
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
copy_or_blend_pix(p, *colors++, cover);
}
while(--len);
} while (--len);
}
}
}
//--------------------------------------------------------------------
template <typename Function>
template<typename Function>
void for_each_pixel(Function f)
{
for(unsigned y = 0; y < height(); ++y)
for (unsigned y = 0; y < height(); ++y)
{
row_data r = m_rbuf->row(y);
if(r.ptr)
if (r.ptr)
{
unsigned len = r.x2 - r.x1 + 1;
value_type* p = (value_type*)
m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset;
value_type* p = (value_type*)m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset;
do
{
f(p);
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));
}
//--------------------------------------------------------------------
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));
}
//--------------------------------------------------------------------
template<typename RenBuf2>
void copy_from(const RenBuf2& from,
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len)
void copy_from(const RenBuf2& from, int xdst, int ydst, int xsrc, int ysrc, unsigned len)
{
const agg::int8u* p = from.row_ptr(ysrc);
if(p)
if (p)
{
memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width,
p + xsrc * pix_width,
len * pix_width);
memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width, p + xsrc * pix_width, len * pix_width);
}
}
@ -592,26 +502,24 @@ public:
template<typename SrcPixelFormatRenderer>
void blend_from_color(const SrcPixelFormatRenderer& from,
const color_type& color,
int xdst, int ydst,
int /*xsrc*/, int ysrc,
int xdst,
int ydst,
int /*xsrc*/,
int ysrc,
unsigned len,
agg::int8u cover)
{
using src_value_type = typename SrcPixelFormatRenderer::value_type;
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
if(psrc)
if (psrc)
{
value_type* pdst =
(value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
value_type* pdst = (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
do
{
copy_or_blend_pix(pdst,
color,
(*psrc * cover + base_mask) >> base_shift);
copy_or_blend_pix(pdst, color, (*psrc * cover + base_mask) >> base_shift);
++psrc;
++pdst;
}
while(--len);
} while (--len);
}
}
@ -619,46 +527,46 @@ public:
template<typename SrcPixelFormatRenderer>
void blend_from_lut(const SrcPixelFormatRenderer& from,
const color_type* color_lut,
int xdst, int ydst,
int /*xsrc*/, int ysrc,
int xdst,
int ydst,
int /*xsrc*/,
int ysrc,
unsigned len,
agg::int8u cover)
{
using src_value_type = typename SrcPixelFormatRenderer::value_type;
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
if(psrc)
if (psrc)
{
value_type* pdst =
(value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
value_type* pdst = (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
do
{
copy_or_blend_pix(pdst, color_lut[*psrc], cover);
++psrc;
++pdst;
}
while(--len);
} while (--len);
}
}
private:
private:
rbuf_type* m_rbuf;
};
using blender_gray16 = blender_gray<gray16>;
using pixfmt_gray16 = pixfmt_alpha_blend_gray<blender_gray16,
mapnik::grid_rendering_buffer>; //----pixfmt_gray16
using pixfmt_gray16 = pixfmt_alpha_blend_gray<blender_gray16,
mapnik::grid_rendering_buffer>; //----pixfmt_gray16
using blender_gray32 = blender_gray<gray32>;
using pixfmt_gray32 = pixfmt_alpha_blend_gray<blender_gray32,
mapnik::grid_rendering_buffer>; //----pixfmt_gray32
using pixfmt_gray32 = pixfmt_alpha_blend_gray<blender_gray32,
mapnik::grid_rendering_buffer>; //----pixfmt_gray32
using blender_gray64 = blender_gray<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

View file

@ -33,8 +33,10 @@ MAPNIK_DISABLE_WARNING_POP
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

@ -40,9 +40,9 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
template <typename RendererType, typename RasterizerType>
template<typename RendererType, typename RasterizerType>
void render_raster_marker(RendererType ren,
RasterizerType & ras,
RasterizerType& ras,
image_rgba8 const& src,
mapnik::feature_impl const& feature,
agg::trans_affine const& marker_tr,
@ -50,25 +50,29 @@ void render_raster_marker(RendererType ren,
{
using color_type = typename RendererType::color_type;
agg::scanline_bin sl;
double width = src.width();
double width = src.width();
double height = src.height();
double p[8];
p[0] = 0; p[1] = 0;
p[2] = width; p[3] = 0;
p[4] = width; p[5] = height;
p[6] = 0; p[7] = height;
p[0] = 0;
p[1] = 0;
p[2] = width;
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[2], &p[3]);
marker_tr.transform(&p[4], &p[5]);
marker_tr.transform(&p[6], &p[7]);
ras.move_to_d(p[0],p[1]);
ras.line_to_d(p[2],p[3]);
ras.line_to_d(p[4],p[5]);
ras.line_to_d(p[6],p[7]);
ras.move_to_d(p[0], p[1]);
ras.line_to_d(p[2], p[3]);
ras.line_to_d(p[4], p[5]);
ras.line_to_d(p[6], p[7]);
ren.color(color_type(feature.id()));
agg::render_scanlines(ras, sl, ren);
}
}
} // namespace mapnik
#endif

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