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:
parent
6fe46f61e2
commit
e7c3d04309
648 changed files with 25217 additions and 26024 deletions
|
@ -9,8 +9,7 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include "agg_conv_smooth_poly1.h"
|
#include "agg_conv_smooth_poly1.h"
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
struct vcgen_smooth_calucate_adaptive
|
struct vcgen_smooth_calucate_adaptive
|
||||||
{
|
{
|
||||||
|
@ -57,12 +56,8 @@ struct vcgen_smooth_calucate_adaptive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {{v1.x + s1 * smooth_value * (v2.x - xm1), v1.y + s1 * smooth_value * (v2.y - ym1)},
|
||||||
{v1.x + s1 * smooth_value * (v2.x - xm1),
|
{v2.x + s2 * smooth_value * (v1.x - xm2), v2.y + s2 * smooth_value * (v1.y - ym2)}};
|
||||||
v1.y + s1 * smooth_value * (v2.y - ym1)},
|
|
||||||
{v2.x + s2 * smooth_value * (v1.x - xm2),
|
|
||||||
v2.y + s2 * smooth_value * (v1.y - ym2)}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,7 +66,7 @@ using vcgen_smooth_adaptive = agg::vcgen_smooth<vcgen_smooth_calucate_adaptive>;
|
||||||
template<class VertexSource>
|
template<class VertexSource>
|
||||||
using conv_smooth_adaptive = agg::conv_smooth_curve<VertexSource, vcgen_smooth_adaptive>;
|
using conv_smooth_adaptive = agg::conv_smooth_curve<VertexSource, vcgen_smooth_adaptive>;
|
||||||
|
|
||||||
template <typename Geometry>
|
template<typename Geometry>
|
||||||
class smooth_converter
|
class smooth_converter
|
||||||
{
|
{
|
||||||
Geometry geom_;
|
Geometry geom_;
|
||||||
|
@ -81,9 +76,9 @@ class smooth_converter
|
||||||
using impl_type = util::variant<basic_impl_type, adaptive_impl_type>;
|
using impl_type = util::variant<basic_impl_type, adaptive_impl_type>;
|
||||||
impl_type impl_;
|
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:
|
case SMOOTH_ALGORITHM_ADAPTIVE:
|
||||||
return adaptive_impl_type(geom);
|
return adaptive_impl_type(geom);
|
||||||
|
@ -94,46 +89,35 @@ class smooth_converter
|
||||||
return basic_impl_type(geom);
|
return basic_impl_type(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
smooth_converter(Geometry & geom) :
|
smooth_converter(Geometry& geom)
|
||||||
geom_(geom),
|
: geom_(geom)
|
||||||
impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
|
, impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void algorithm(smooth_algorithm_enum algo)
|
void algorithm(smooth_algorithm_enum algo) { impl_ = init_impl(algo, geom_); }
|
||||||
{
|
|
||||||
impl_ = init_impl(algo, geom_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void smooth_value(double v)
|
void smooth_value(double v)
|
||||||
{
|
{
|
||||||
return util::apply_visitor([=](auto & impl) {
|
return util::apply_visitor([=](auto& impl) { impl.smooth_value(v); }, impl_);
|
||||||
impl.smooth_value(v);
|
|
||||||
}, impl_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewind(unsigned path_id)
|
void rewind(unsigned path_id)
|
||||||
{
|
{
|
||||||
return util::apply_visitor([=](auto & impl) {
|
return util::apply_visitor([=](auto& impl) { return impl.rewind(path_id); }, impl_);
|
||||||
return impl.rewind(path_id);
|
|
||||||
}, impl_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned vertex(double* x, double* y)
|
unsigned vertex(double* x, double* y)
|
||||||
{
|
{
|
||||||
return util::apply_visitor([=](auto & impl) {
|
return util::apply_visitor([=](auto& impl) { return impl.vertex(x, y); }, impl_);
|
||||||
return impl.vertex(x, y);
|
|
||||||
}, impl_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type() const
|
unsigned type() const
|
||||||
{
|
{
|
||||||
return util::apply_visitor([](auto const& impl) {
|
return util::apply_visitor([](auto const& impl) { return impl.type(); }, impl_);
|
||||||
return impl.type();
|
|
||||||
}, impl_);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_ADAPTIVE_SMOOTH_HPP
|
#endif // MAPNIK_ADAPTIVE_SMOOTH_HPP
|
||||||
|
|
|
@ -69,7 +69,7 @@ struct agg_pattern_base
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename VertexConverter>
|
template<typename VertexConverter>
|
||||||
struct agg_polygon_pattern : agg_pattern_base
|
struct agg_polygon_pattern : agg_pattern_base
|
||||||
{
|
{
|
||||||
using color_type = agg::rgba8;
|
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 pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
|
||||||
using wrap_x_type = agg::wrap_mode_repeat;
|
using wrap_x_type = agg::wrap_mode_repeat;
|
||||||
using wrap_y_type = agg::wrap_mode_repeat;
|
using wrap_y_type = agg::wrap_mode_repeat;
|
||||||
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre,
|
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre, wrap_x_type, wrap_y_type>;
|
||||||
wrap_x_type,
|
|
||||||
wrap_y_type>;
|
|
||||||
using span_gen_type = agg::span_pattern_rgba<img_source_type>;
|
using span_gen_type = agg::span_pattern_rgba<img_source_type>;
|
||||||
using renderer_base = agg::renderer_base<pixfmt_type>;
|
using renderer_base = agg::renderer_base<pixfmt_type>;
|
||||||
using renderer_type = agg::renderer_scanline_aa_alpha<renderer_base,
|
using renderer_type =
|
||||||
agg::span_allocator<agg::rgba8>,
|
agg::renderer_scanline_aa_alpha<renderer_base, agg::span_allocator<agg::rgba8>, span_gen_type>;
|
||||||
span_gen_type>;
|
|
||||||
|
|
||||||
agg_polygon_pattern(image_rgba8 const& pattern_img,
|
agg_polygon_pattern(image_rgba8 const& pattern_img,
|
||||||
renderer_common const& common,
|
renderer_common const& common,
|
||||||
symbolizer_base const& sym,
|
symbolizer_base const& sym,
|
||||||
mapnik::feature_impl const& feature,
|
mapnik::feature_impl const& feature,
|
||||||
proj_transform const& prj_trans)
|
proj_transform const& prj_trans)
|
||||||
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans},
|
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans}
|
||||||
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
|
, clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
|
||||||
clip_box_(clipping_extent(common)),
|
, clip_box_(clipping_extent(common))
|
||||||
tr_(geom_transform()),
|
, tr_(geom_transform())
|
||||||
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
|
, converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
|
||||||
feature, common.vars_, common.scale_factor_)
|
|
||||||
{
|
{
|
||||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
|
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
|
||||||
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
|
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
|
||||||
|
|
||||||
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
|
if (simplify_tolerance > 0.0)
|
||||||
|
converter_.template set<simplify_tag>();
|
||||||
converter_.template set<affine_transform_tag>();
|
converter_.template set<affine_transform_tag>();
|
||||||
if (smooth > 0.0) converter_.template set<smooth_tag>();
|
if (smooth > 0.0)
|
||||||
|
converter_.template set<smooth_tag>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(renderer_base & ren_base, rasterizer & ras)
|
void render(renderer_base& ren_base, rasterizer& ras)
|
||||||
{
|
{
|
||||||
coord<double, 2> offset(pattern_offset(sym_, feature_, prj_trans_, common_,
|
coord<double, 2> offset(
|
||||||
pattern_img_.width(), pattern_img_.height()));
|
pattern_offset(sym_, feature_, prj_trans_, common_, pattern_img_.width(), pattern_img_.height()));
|
||||||
agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(),
|
agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(),
|
||||||
pattern_img_.width(), pattern_img_.height(),
|
pattern_img_.width(),
|
||||||
|
pattern_img_.height(),
|
||||||
pattern_img_.width() * 4);
|
pattern_img_.width() * 4);
|
||||||
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
|
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
|
||||||
img_source_type img_src(pixf_pattern);
|
img_source_type img_src(pixf_pattern);
|
||||||
|
@ -122,8 +121,7 @@ struct agg_polygon_pattern : agg_pattern_base
|
||||||
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
|
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||||
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
|
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
|
||||||
|
|
||||||
using apply_vertex_converter_type = detail::apply_vertex_converter<
|
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, rasterizer>;
|
||||||
VertexConverter, rasterizer>;
|
|
||||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||||
apply_vertex_converter_type apply(converter_, ras);
|
apply_vertex_converter_type apply(converter_, ras);
|
||||||
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
||||||
|
@ -139,5 +137,4 @@ struct agg_polygon_pattern : agg_pattern_base
|
||||||
|
|
||||||
} // namespace mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP
|
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP
|
||||||
|
|
|
@ -34,8 +34,8 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void set_gamma_method(T & ras_ptr, double gamma, gamma_method_enum method)
|
void set_gamma_method(T& ras_ptr, double gamma, gamma_method_enum method)
|
||||||
{
|
{
|
||||||
switch (method)
|
switch (method)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +59,6 @@ void set_gamma_method(T & ras_ptr, double gamma, gamma_method_enum method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_AGG_HELPERS_HPP
|
#endif // MAPNIK_AGG_HELPERS_HPP
|
||||||
|
|
|
@ -33,36 +33,31 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include "agg_color_rgba.h"
|
#include "agg_color_rgba.h"
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class pattern_source : private util::noncopyable
|
class pattern_source : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
pattern_source(image_rgba8 const& pattern, double opacity = 1.0)
|
pattern_source(image_rgba8 const& pattern, double opacity = 1.0)
|
||||||
: pattern_(pattern),
|
: pattern_(pattern)
|
||||||
opacity_(opacity) {}
|
, opacity_(opacity)
|
||||||
|
{}
|
||||||
|
|
||||||
unsigned int width() const
|
unsigned int width() const { return pattern_.width(); }
|
||||||
{
|
unsigned int height() const { return pattern_.height(); }
|
||||||
return pattern_.width();
|
|
||||||
}
|
|
||||||
unsigned int height() const
|
|
||||||
{
|
|
||||||
return pattern_.height();
|
|
||||||
}
|
|
||||||
agg::rgba8 pixel(int x, int y) const
|
agg::rgba8 pixel(int x, int y) const
|
||||||
{
|
{
|
||||||
unsigned c = pattern_(x,y);
|
unsigned c = pattern_(x, y);
|
||||||
return agg::rgba8(static_cast<unsigned>((c & 0xff) * opacity_),
|
return agg::rgba8(static_cast<unsigned>((c & 0xff) * opacity_),
|
||||||
static_cast<unsigned>(((c >> 8) & 0xff) * opacity_),
|
static_cast<unsigned>(((c >> 8) & 0xff) * opacity_),
|
||||||
static_cast<unsigned>(((c >> 16) & 0xff) * opacity_),
|
static_cast<unsigned>(((c >> 16) & 0xff) * opacity_),
|
||||||
static_cast<unsigned>(((c >> 24) & 0xff) * opacity_));
|
static_cast<unsigned>(((c >> 24) & 0xff) * opacity_));
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
|
private:
|
||||||
image_rgba8 const& pattern_;
|
image_rgba8 const& pattern_;
|
||||||
double opacity_;
|
double opacity_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP
|
#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/util/noncopyable.hpp>
|
#include <mapnik/util/noncopyable.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include <mapnik/warning.hpp>
|
#include <mapnik/warning.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/warning_ignore_agg.hpp>
|
#include <mapnik/warning_ignore_agg.hpp>
|
||||||
|
@ -35,8 +34,10 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
struct rasterizer : agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_int_sat>, util::noncopyable {};
|
struct rasterizer : agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_int_sat>,
|
||||||
|
util::noncopyable
|
||||||
|
{};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_AGG_RASTERIZER_HPP
|
#endif // MAPNIK_AGG_RASTERIZER_HPP
|
||||||
|
|
|
@ -52,10 +52,14 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
|
template<typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
|
||||||
void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, RendererBaseType & renb,
|
void render_vector_marker(SvgRenderer& svg_renderer,
|
||||||
box2d<double> const& bbox, agg::trans_affine const& tr,
|
RasterizerType& ras,
|
||||||
double opacity, bool snap_to_pixels)
|
RendererBaseType& renb,
|
||||||
|
box2d<double> const& bbox,
|
||||||
|
agg::trans_affine const& tr,
|
||||||
|
double opacity,
|
||||||
|
bool snap_to_pixels)
|
||||||
{
|
{
|
||||||
agg::scanline_u8 sl;
|
agg::scanline_u8 sl;
|
||||||
if (snap_to_pixels)
|
if (snap_to_pixels)
|
||||||
|
@ -72,10 +76,14 @@ void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, Rend
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename RendererType, typename RasterizerType>
|
template<typename RendererType, typename RasterizerType>
|
||||||
void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 const& src,
|
void render_raster_marker(RendererType renb,
|
||||||
agg::trans_affine const& tr, double opacity,
|
RasterizerType& ras,
|
||||||
float scale_factor, bool snap_to_pixels)
|
image_rgba8 const& src,
|
||||||
|
agg::trans_affine const& tr,
|
||||||
|
double opacity,
|
||||||
|
float scale_factor,
|
||||||
|
bool snap_to_pixels)
|
||||||
{
|
{
|
||||||
using color_type = agg::rgba8;
|
using color_type = agg::rgba8;
|
||||||
using const_rendering_buffer = util::rendering_buffer<image_rgba8>;
|
using const_rendering_buffer = util::rendering_buffer<image_rgba8>;
|
||||||
|
@ -84,11 +92,9 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
|
||||||
agg::scanline_u8 sl;
|
agg::scanline_u8 sl;
|
||||||
double width = src.width();
|
double width = src.width();
|
||||||
double height = src.height();
|
double height = src.height();
|
||||||
if (std::fabs(1.0 - scale_factor) < 0.001
|
if (std::fabs(1.0 - scale_factor) < 0.001 && (std::fabs(1.0 - tr.sx) < agg::affine_epsilon) &&
|
||||||
&& (std::fabs(1.0 - tr.sx) < agg::affine_epsilon)
|
(std::fabs(0.0 - tr.shy) < agg::affine_epsilon) && (std::fabs(0.0 - tr.shx) < agg::affine_epsilon) &&
|
||||||
&& (std::fabs(0.0 - tr.shy) < agg::affine_epsilon)
|
(std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
|
||||||
&& (std::fabs(0.0 - tr.shx) < agg::affine_epsilon)
|
|
||||||
&& (std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
|
|
||||||
{
|
{
|
||||||
const_rendering_buffer src_buffer(src);
|
const_rendering_buffer src_buffer(src);
|
||||||
pixfmt_pre pixf_mask(src_buffer);
|
pixfmt_pre pixf_mask(src_buffer);
|
||||||
|
@ -98,32 +104,31 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
|
||||||
0,
|
0,
|
||||||
static_cast<int>(std::floor(tr.tx + .5)),
|
static_cast<int>(std::floor(tr.tx + .5)),
|
||||||
static_cast<int>(std::floor(tr.ty + .5)),
|
static_cast<int>(std::floor(tr.ty + .5)),
|
||||||
unsigned(255*opacity));
|
unsigned(255 * opacity));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
renb.blend_from(pixf_mask,
|
renb.blend_from(pixf_mask, 0, static_cast<int>(tr.tx), static_cast<int>(tr.ty), unsigned(255 * opacity));
|
||||||
0,
|
|
||||||
static_cast<int>(tr.tx),
|
|
||||||
static_cast<int>(tr.ty),
|
|
||||||
unsigned(255*opacity));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using img_accessor_type = agg::image_accessor_clone<pixfmt_pre>;
|
using img_accessor_type = agg::image_accessor_clone<pixfmt_pre>;
|
||||||
using interpolator_type = agg::span_interpolator_linear<>;
|
using interpolator_type = agg::span_interpolator_linear<>;
|
||||||
//using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>;
|
// using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>;
|
||||||
using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>;
|
using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>;
|
||||||
using renderer_type = agg::renderer_scanline_aa_alpha<RendererType,
|
using renderer_type =
|
||||||
agg::span_allocator<color_type>,
|
agg::renderer_scanline_aa_alpha<RendererType, agg::span_allocator<color_type>, span_gen_type>;
|
||||||
span_gen_type>;
|
|
||||||
|
|
||||||
double p[8];
|
double p[8];
|
||||||
p[0] = 0; p[1] = 0;
|
p[0] = 0;
|
||||||
p[2] = width; p[3] = 0;
|
p[1] = 0;
|
||||||
p[4] = width; p[5] = height;
|
p[2] = width;
|
||||||
p[6] = 0; p[7] = height;
|
p[3] = 0;
|
||||||
|
p[4] = width;
|
||||||
|
p[5] = height;
|
||||||
|
p[6] = 0;
|
||||||
|
p[7] = height;
|
||||||
tr.transform(&p[0], &p[1]);
|
tr.transform(&p[0], &p[1]);
|
||||||
tr.transform(&p[2], &p[3]);
|
tr.transform(&p[2], &p[3]);
|
||||||
tr.transform(&p[4], &p[5]);
|
tr.transform(&p[4], &p[5]);
|
||||||
|
@ -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);
|
agg::trans_affine final_tr(p, 0, 0, width, height);
|
||||||
if (snap_to_pixels)
|
if (snap_to_pixels)
|
||||||
{
|
{
|
||||||
final_tr.tx = std::floor(final_tr.tx+.5);
|
final_tr.tx = std::floor(final_tr.tx + .5);
|
||||||
final_tr.ty = std::floor(final_tr.ty+.5);
|
final_tr.ty = std::floor(final_tr.ty + .5);
|
||||||
}
|
}
|
||||||
interpolator_type interpolator(final_tr);
|
interpolator_type interpolator(final_tr);
|
||||||
span_gen_type sg(ia, interpolator, filter);
|
span_gen_type sg(ia, interpolator, filter);
|
||||||
renderer_type rp(renb, sa, sg, unsigned(opacity*255));
|
renderer_type rp(renb, sa, sg, unsigned(opacity * 255));
|
||||||
ras.move_to_d(p[0],p[1]);
|
ras.move_to_d(p[0], p[1]);
|
||||||
ras.line_to_d(p[2],p[3]);
|
ras.line_to_d(p[2], p[3]);
|
||||||
ras.line_to_d(p[4],p[5]);
|
ras.line_to_d(p[4], p[5]);
|
||||||
ras.line_to_d(p[6],p[7]);
|
ras.line_to_d(p[6], p[7]);
|
||||||
agg::render_scanlines(ras, sl, rp);
|
agg::render_scanlines(ras, sl, rp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_AGG_RENDER_MARKER_HPP
|
#endif // MAPNIK_AGG_RENDER_MARKER_HPP
|
||||||
|
|
|
@ -41,38 +41,40 @@
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
// fwd declaration to avoid dependence on agg headers
|
// fwd declaration to avoid dependence on agg headers
|
||||||
namespace agg { struct trans_affine; }
|
namespace agg {
|
||||||
|
struct trans_affine;
|
||||||
|
}
|
||||||
|
|
||||||
// fwd declarations to speed up compile
|
// fwd declarations to speed up compile
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
class Map;
|
class Map;
|
||||||
class feature_impl;
|
class feature_impl;
|
||||||
class feature_type_style;
|
class feature_type_style;
|
||||||
class label_collision_detector4;
|
class label_collision_detector4;
|
||||||
class layer;
|
class layer;
|
||||||
class color;
|
class color;
|
||||||
struct marker;
|
struct marker;
|
||||||
class proj_transform;
|
class proj_transform;
|
||||||
struct rasterizer;
|
struct rasterizer;
|
||||||
struct rgba8_t;
|
struct rgba8_t;
|
||||||
template<typename T> class image;
|
template<typename T>
|
||||||
}
|
class image;
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class buffer_stack
|
class buffer_stack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
buffer_stack(std::size_t width, std::size_t height)
|
buffer_stack(std::size_t width, std::size_t height)
|
||||||
: width_(width),
|
: width_(width)
|
||||||
height_(height),
|
, height_(height)
|
||||||
buffers_(),
|
, buffers_()
|
||||||
position_(buffers_.begin())
|
, position_(buffers_.begin())
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
T & push()
|
T& push()
|
||||||
{
|
{
|
||||||
if (position_ == buffers_.begin())
|
if (position_ == buffers_.begin())
|
||||||
{
|
{
|
||||||
|
@ -86,10 +88,7 @@ public:
|
||||||
}
|
}
|
||||||
return *position_;
|
return *position_;
|
||||||
}
|
}
|
||||||
bool in_range() const
|
bool in_range() const { return (position_ != buffers_.end()); }
|
||||||
{
|
|
||||||
return (position_ != buffers_.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
void pop()
|
void pop()
|
||||||
{
|
{
|
||||||
|
@ -98,34 +97,44 @@ public:
|
||||||
++position_;
|
++position_;
|
||||||
}
|
}
|
||||||
|
|
||||||
T & top() const
|
T& top() const { return *position_; }
|
||||||
{
|
|
||||||
return *position_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::size_t width_;
|
const std::size_t width_;
|
||||||
const std::size_t height_;
|
const std::size_t height_;
|
||||||
std::deque<T> buffers_;
|
std::deque<T> buffers_;
|
||||||
typename std::deque<T>::iterator position_;
|
typename std::deque<T>::iterator position_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T0, typename T1=label_collision_detector4>
|
template<typename T0, typename T1 = label_collision_detector4>
|
||||||
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0> >,
|
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>>,
|
||||||
private util::noncopyable
|
private util::noncopyable
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
public:
|
|
||||||
using buffer_type = T0;
|
using buffer_type = T0;
|
||||||
using processor_impl_type = agg_renderer<T0>;
|
using processor_impl_type = agg_renderer<T0>;
|
||||||
using detector_type = T1;
|
using detector_type = T1;
|
||||||
// create with default, empty placement detector
|
// create with default, empty placement detector
|
||||||
agg_renderer(Map const& m, buffer_type & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
agg_renderer(Map const& m,
|
||||||
|
buffer_type& pixmap,
|
||||||
|
double scale_factor = 1.0,
|
||||||
|
unsigned offset_x = 0,
|
||||||
|
unsigned offset_y = 0);
|
||||||
// create with external placement detector, possibly non-empty
|
// create with external placement detector, possibly non-empty
|
||||||
agg_renderer(Map const &m, buffer_type & pixmap, std::shared_ptr<detector_type> detector,
|
agg_renderer(Map const& m,
|
||||||
double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
buffer_type& pixmap,
|
||||||
|
std::shared_ptr<detector_type> detector,
|
||||||
|
double scale_factor = 1.0,
|
||||||
|
unsigned offset_x = 0,
|
||||||
|
unsigned offset_y = 0);
|
||||||
// pass in mapnik::request object to provide the mutable things per render
|
// pass in mapnik::request object to provide the mutable things per render
|
||||||
agg_renderer(Map const& m, request const& req, attributes const& vars, buffer_type & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
agg_renderer(Map const& m,
|
||||||
|
request const& req,
|
||||||
|
attributes const& vars,
|
||||||
|
buffer_type& pixmap,
|
||||||
|
double scale_factor = 1.0,
|
||||||
|
unsigned offset_x = 0,
|
||||||
|
unsigned offset_y = 0);
|
||||||
~agg_renderer();
|
~agg_renderer();
|
||||||
void start_map_processing(Map const& map);
|
void start_map_processing(Map const& map);
|
||||||
void end_map_processing(Map const& map);
|
void end_map_processing(Map const& map);
|
||||||
|
@ -135,52 +144,27 @@ public:
|
||||||
void start_style_processing(feature_type_style const& st);
|
void start_style_processing(feature_type_style const& st);
|
||||||
void end_style_processing(feature_type_style const& st);
|
void end_style_processing(feature_type_style const& st);
|
||||||
|
|
||||||
void render_marker(pixel_position const& pos, marker const& marker, agg::trans_affine const& tr,
|
void render_marker(pixel_position const& pos,
|
||||||
double opacity, composite_mode_e comp_op);
|
marker const& marker,
|
||||||
|
agg::trans_affine const& tr,
|
||||||
|
double opacity,
|
||||||
|
composite_mode_e comp_op);
|
||||||
|
|
||||||
void process(point_symbolizer const& sym,
|
void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(line_symbolizer const& sym,
|
void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(line_pattern_symbolizer const& sym,
|
void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(polygon_symbolizer const& sym,
|
void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(debug_symbolizer const& sym, feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(polygon_pattern_symbolizer const& sym,
|
void process(dot_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(raster_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(shield_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(text_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(building_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(markers_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(group_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(debug_symbolizer const& sym,
|
|
||||||
feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(dot_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
|
|
||||||
inline bool process(rule::symbolizers const&,
|
inline bool process(rule::symbolizers const&, mapnik::feature_impl&, proj_transform const&)
|
||||||
mapnik::feature_impl&,
|
|
||||||
proj_transform const& )
|
|
||||||
{
|
{
|
||||||
// agg renderer doesn't support processing of multiple symbolizers.
|
// agg renderer doesn't support processing of multiple symbolizers.
|
||||||
return false;
|
return false;
|
||||||
|
@ -189,29 +173,19 @@ public:
|
||||||
void painted(bool painted);
|
void painted(bool painted);
|
||||||
bool painted();
|
bool painted();
|
||||||
|
|
||||||
inline eAttributeCollectionPolicy attribute_collection_policy() const
|
inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
|
||||||
{
|
|
||||||
return DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline double scale_factor() const
|
inline double scale_factor() const { return common_.scale_factor_; }
|
||||||
{
|
|
||||||
return common_.scale_factor_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline attributes const& variables() const
|
inline attributes const& variables() const { return common_.vars_; }
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
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_;
|
std::stack<std::reference_wrapper<buffer_type>> buffers_;
|
||||||
buffer_stack<buffer_type> internal_buffers_;
|
buffer_stack<buffer_type> internal_buffers_;
|
||||||
std::unique_ptr<buffer_type> inflated_buffer_;
|
std::unique_ptr<buffer_type> inflated_buffer_;
|
||||||
|
@ -219,7 +193,7 @@ private:
|
||||||
gamma_method_enum gamma_method_;
|
gamma_method_enum gamma_method_;
|
||||||
double gamma_;
|
double gamma_;
|
||||||
renderer_common common_;
|
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>>;
|
extern template class MAPNIK_DECL agg_renderer<image<rgba8_t>>;
|
||||||
|
|
|
@ -37,20 +37,21 @@ struct attribute
|
||||||
{
|
{
|
||||||
std::string name_;
|
std::string name_;
|
||||||
explicit attribute(std::string const& _name)
|
explicit attribute(std::string const& _name)
|
||||||
: name_(_name) {}
|
: name_(_name)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename V ,typename F>
|
template<typename V, typename F>
|
||||||
V const& value(F const& f) const
|
V const& value(F const& f) const
|
||||||
{
|
{
|
||||||
return f.get(name_);
|
return f.get(name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& name() const { return name_;}
|
std::string const& name() const { return name_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct geometry_type_attribute
|
struct geometry_type_attribute
|
||||||
{
|
{
|
||||||
template <typename V, typename F>
|
template<typename V, typename F>
|
||||||
V value(F const& f) const
|
V value(F const& f) const
|
||||||
{
|
{
|
||||||
return static_cast<mapnik::value_integer>(util::to_ds_type(f.get_geometry()));
|
return static_cast<mapnik::value_integer>(util::to_ds_type(f.get_geometry()));
|
||||||
|
@ -61,10 +62,11 @@ struct global_attribute
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
explicit global_attribute(std::string const& name_)
|
explicit global_attribute(std::string const& name_)
|
||||||
: name(name_) {}
|
: name(name_)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename V, typename C>
|
template<typename V, typename C>
|
||||||
V const& operator() (C const& ctx)
|
V const& operator()(C const& ctx)
|
||||||
{
|
{
|
||||||
return ctx.get(name);
|
return ctx.get(name);
|
||||||
}
|
}
|
||||||
|
@ -72,6 +74,6 @@ struct global_attribute
|
||||||
|
|
||||||
using attributes = std::unordered_map<std::string, value>;
|
using attributes = std::unordered_map<std::string, value>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_ATTRIBUTE_HPP
|
#endif // MAPNIK_ATTRIBUTE_HPP
|
||||||
|
|
|
@ -51,76 +51,71 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename Container>
|
template<typename Container>
|
||||||
struct expression_attributes
|
struct expression_attributes
|
||||||
{
|
{
|
||||||
explicit expression_attributes(Container& names)
|
explicit expression_attributes(Container& names)
|
||||||
: names_(names) {}
|
: names_(names)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator() (attribute const& attr) const
|
void operator()(attribute const& attr) const { names_.emplace(attr.name()); }
|
||||||
{
|
|
||||||
names_.emplace(attr.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
void operator() (binary_node<Tag> const& x) const
|
void operator()(binary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
util::apply_visitor(*this, x.left);
|
util::apply_visitor(*this, x.left);
|
||||||
util::apply_visitor(*this, x.right);
|
util::apply_visitor(*this, x.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
void operator() (unary_node<Tag> const& x) const
|
void operator()(unary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
util::apply_visitor(*this, x.expr);
|
util::apply_visitor(*this, x.expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator() (regex_match_node const& x) const
|
void operator()(regex_match_node const& x) const { util::apply_visitor(*this, x.expr); }
|
||||||
{
|
|
||||||
util::apply_visitor(*this, x.expr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator() (regex_replace_node const& x) const
|
void operator()(regex_replace_node const& x) const { util::apply_visitor(*this, x.expr); }
|
||||||
{
|
|
||||||
util::apply_visitor(*this, x.expr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void operator() (T const&) const {}
|
void operator()(T const&) const
|
||||||
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Container& names_;
|
Container& names_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class group_attribute_collector : public util::noncopyable
|
class group_attribute_collector : public util::noncopyable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::set<std::string>& names_;
|
std::set<std::string>& names_;
|
||||||
bool expand_index_columns_;
|
bool expand_index_columns_;
|
||||||
public:
|
|
||||||
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
|
struct extract_attribute_names
|
||||||
{
|
{
|
||||||
explicit extract_attribute_names(Container& names)
|
explicit extract_attribute_names(Container& names)
|
||||||
: names_(names),
|
: names_(names)
|
||||||
f_attr_(names) {}
|
, f_attr_(names)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator() (mapnik::expression_ptr const& expr) const
|
void operator()(mapnik::expression_ptr const& expr) const
|
||||||
{
|
{
|
||||||
if (expr)
|
if (expr)
|
||||||
{
|
{
|
||||||
util::apply_visitor(f_attr_, *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)
|
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)
|
if (expr)
|
||||||
{
|
{
|
||||||
|
@ -136,39 +131,41 @@ struct extract_attribute_names
|
||||||
expression_set expressions;
|
expression_set expressions;
|
||||||
// TODO - optimize (dane)
|
// TODO - optimize (dane)
|
||||||
expr->add_expressions(expressions);
|
expr->add_expressions(expressions);
|
||||||
for (it=expressions.begin(); it != expressions.end(); ++it)
|
for (it = expressions.begin(); it != expressions.end(); ++it)
|
||||||
{
|
{
|
||||||
if (*it) util::apply_visitor(f_attr_, **it);
|
if (*it)
|
||||||
|
util::apply_visitor(f_attr_, **it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator() (mapnik::path_expression_ptr const& expr) const
|
void operator()(mapnik::path_expression_ptr const& expr) const
|
||||||
{
|
{
|
||||||
if (expr)
|
if (expr)
|
||||||
{
|
{
|
||||||
path_processor_type::collect_attributes(*expr,names_);
|
path_processor_type::collect_attributes(*expr, names_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void operator() (T const&) const {}
|
void operator()(T const&) const
|
||||||
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Container& names_;
|
Container& names_;
|
||||||
expression_attributes<std::set<std::string> > f_attr_;
|
expression_attributes<std::set<std::string>> f_attr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct symbolizer_attributes
|
struct symbolizer_attributes
|
||||||
{
|
{
|
||||||
symbolizer_attributes(std::set<std::string>& names,
|
symbolizer_attributes(std::set<std::string>& names, double& filter_factor)
|
||||||
double & filter_factor)
|
: filter_factor_(filter_factor)
|
||||||
: filter_factor_(filter_factor),
|
, f_attrs_(names)
|
||||||
f_attrs_(names),
|
, g_attrs_(names, true)
|
||||||
g_attrs_(names, true) {}
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void operator () (T const& sym)
|
void operator()(T const& sym)
|
||||||
{
|
{
|
||||||
for (auto const& prop : sym.properties)
|
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);
|
boost::optional<double> filter_factor = get_optional<double>(sym, keys::filter_factor);
|
||||||
if (filter_factor)
|
if (filter_factor)
|
||||||
|
@ -197,57 +194,51 @@ struct symbolizer_attributes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator () (group_symbolizer const& sym)
|
void operator()(group_symbolizer const& sym) { g_attrs_(sym); }
|
||||||
{
|
|
||||||
g_attrs_(sym);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double & filter_factor_;
|
double& filter_factor_;
|
||||||
extract_attribute_names<std::set<std::string> > f_attrs_;
|
extract_attribute_names<std::set<std::string>> f_attrs_;
|
||||||
group_attribute_collector g_attrs_;
|
group_attribute_collector g_attrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class attribute_collector : public util::noncopyable
|
class attribute_collector : public util::noncopyable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::set<std::string> & names_;
|
std::set<std::string>& names_;
|
||||||
double filter_factor_;
|
double filter_factor_;
|
||||||
expression_attributes<std::set<std::string> > f_attr;
|
expression_attributes<std::set<std::string>> f_attr;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
|
|
||||||
attribute_collector(std::set<std::string>& names)
|
attribute_collector(std::set<std::string>& names)
|
||||||
: names_(names),
|
: names_(names)
|
||||||
filter_factor_(1.0),
|
, filter_factor_(1.0)
|
||||||
f_attr(names) {}
|
, f_attr(names)
|
||||||
template <typename RuleType>
|
{}
|
||||||
void operator() (RuleType const& r)
|
template<typename RuleType>
|
||||||
|
void operator()(RuleType const& r)
|
||||||
{
|
{
|
||||||
typename RuleType::symbolizers const& symbols = r.get_symbolizers();
|
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)
|
for (auto const& sym : symbols)
|
||||||
{
|
{
|
||||||
util::apply_visitor(std::ref(s_attr), sym);
|
util::apply_visitor(std::ref(s_attr), sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
expression_ptr const& expr = r.get_filter();
|
expression_ptr const& expr = r.get_filter();
|
||||||
util::apply_visitor(f_attr,*expr);
|
util::apply_visitor(f_attr, *expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
double get_filter_factor() const
|
double get_filter_factor() const { return filter_factor_; }
|
||||||
{
|
|
||||||
return filter_factor_;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline void group_attribute_collector::operator()(group_symbolizer const& sym)
|
||||||
inline void group_attribute_collector::operator() (group_symbolizer const& sym)
|
|
||||||
{
|
{
|
||||||
// find all column names referenced in the group symbolizer
|
// find all column names referenced in the group symbolizer
|
||||||
std::set<std::string> group_columns;
|
std::set<std::string> group_columns;
|
||||||
attribute_collector column_collector(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
|
// get columns from symbolizer repeat key
|
||||||
expression_ptr repeat_key = get<mapnik::expression_ptr>(sym, keys::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)
|
for (value_integer col_idx = start; col_idx < end; ++col_idx)
|
||||||
{
|
{
|
||||||
std::string col_idx_str;
|
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;
|
std::string col_idx_name = col_name;
|
||||||
boost::replace_all(col_idx_name, "%", col_idx_str);
|
boost::replace_all(col_idx_name, "%", col_idx_str);
|
||||||
|
|
|
@ -27,35 +27,30 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
enum eAttributeType {
|
enum eAttributeType { Integer = 1, Float = 2, Double = 3, String = 4, Boolean = 5, Geometry = 6, Object = 7 };
|
||||||
Integer=1,
|
|
||||||
Float =2,
|
|
||||||
Double =3,
|
|
||||||
String =4,
|
|
||||||
Boolean =5,
|
|
||||||
Geometry=6,
|
|
||||||
Object=7
|
|
||||||
};
|
|
||||||
|
|
||||||
class attribute_descriptor
|
class attribute_descriptor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
attribute_descriptor(std::string const& name,unsigned type,
|
attribute_descriptor(std::string const& name,
|
||||||
bool primary_key=false,
|
unsigned type,
|
||||||
int size=-1,
|
bool primary_key = false,
|
||||||
int precision=-1)
|
int size = -1,
|
||||||
: name_(name),
|
int precision = -1)
|
||||||
type_(type),
|
: name_(name)
|
||||||
size_(size),
|
, type_(type)
|
||||||
precision_(precision),
|
, size_(size)
|
||||||
primary_key_(primary_key) {}
|
, precision_(precision)
|
||||||
|
, primary_key_(primary_key)
|
||||||
|
{}
|
||||||
|
|
||||||
attribute_descriptor(attribute_descriptor const& other)
|
attribute_descriptor(attribute_descriptor const& other)
|
||||||
: name_(other.name_),
|
: name_(other.name_)
|
||||||
type_(other.type_),
|
, type_(other.type_)
|
||||||
size_(other.size_),
|
, size_(other.size_)
|
||||||
precision_(other.precision_),
|
, precision_(other.precision_)
|
||||||
primary_key_(other.primary_key_) {}
|
, primary_key_(other.primary_key_)
|
||||||
|
{}
|
||||||
|
|
||||||
attribute_descriptor& operator=(attribute_descriptor rhs)
|
attribute_descriptor& operator=(attribute_descriptor rhs)
|
||||||
{
|
{
|
||||||
|
@ -68,32 +63,17 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& get_name() const
|
std::string const& get_name() const { return name_; }
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int get_type() const
|
unsigned int get_type() const { return type_; }
|
||||||
{
|
|
||||||
return type_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_primary_key() const
|
bool is_primary_key() const { return primary_key_; }
|
||||||
{
|
|
||||||
return primary_key_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_size() const
|
int get_size() const { return size_; }
|
||||||
{
|
|
||||||
return size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_precision() const
|
int get_precision() const { return precision_; }
|
||||||
{
|
|
||||||
return precision_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
unsigned int type_;
|
unsigned int type_;
|
||||||
int size_;
|
int size_;
|
||||||
|
@ -101,6 +81,6 @@ private:
|
||||||
bool primary_key_;
|
bool primary_key_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP
|
#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP
|
||||||
|
|
|
@ -30,25 +30,24 @@
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class MAPNIK_DECL boolean_type
|
class MAPNIK_DECL boolean_type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
boolean_type()
|
boolean_type()
|
||||||
: b_(false) {}
|
: b_(false)
|
||||||
|
{}
|
||||||
boolean_type(bool b)
|
boolean_type(bool b)
|
||||||
: b_(b) {}
|
: b_(b)
|
||||||
|
{}
|
||||||
boolean_type(boolean_type const& b)
|
boolean_type(boolean_type const& b)
|
||||||
: b_(b.b_) {}
|
: b_(b.b_)
|
||||||
|
{}
|
||||||
|
|
||||||
operator bool() const
|
operator bool() const { return b_; }
|
||||||
{
|
|
||||||
return b_;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean_type & operator =(boolean_type const& other)
|
boolean_type& operator=(boolean_type const& other)
|
||||||
{
|
{
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -56,33 +55,32 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool b_;
|
bool b_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Special stream input operator for boolean_type values
|
// Special stream input operator for boolean_type values
|
||||||
template <typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
std::basic_istream<charT, traits> &
|
std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& s, boolean_type& b)
|
||||||
operator >> ( std::basic_istream<charT, traits> & s, boolean_type & b )
|
|
||||||
{
|
{
|
||||||
if ( s )
|
if (s)
|
||||||
{
|
{
|
||||||
std::string word;
|
std::string word;
|
||||||
s >> word;
|
s >> word;
|
||||||
bool result;
|
bool result;
|
||||||
if (util::string2bool(word,result)) b = result;
|
if (util::string2bool(word, result))
|
||||||
|
b = result;
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
std::basic_ostream<charT, traits> &
|
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, boolean_type const& b)
|
||||||
operator << ( std::basic_ostream<charT, traits> & s, boolean_type const& b )
|
|
||||||
{
|
{
|
||||||
s << ( b ? "true" : "false" );
|
s << (b ? "true" : "false");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_BOOLEAN_HPP
|
#endif // MAPNIK_BOOLEAN_HPP
|
||||||
|
|
|
@ -23,17 +23,21 @@
|
||||||
#ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
#ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
||||||
#define MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
#define MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
||||||
|
|
||||||
namespace boost { namespace spirit { namespace x3
|
namespace boost {
|
||||||
{
|
namespace spirit {
|
||||||
|
namespace x3 {
|
||||||
// helper macro
|
// helper macro
|
||||||
#define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \
|
#define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \
|
||||||
template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \
|
template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \
|
||||||
rule_type rule_ \
|
rule_type rule_, \
|
||||||
, Iterator& first, Iterator const& last \
|
Iterator & first, \
|
||||||
, Context const& context, boost::spirit::x3::unused_type const& ); \
|
Iterator const& last, \
|
||||||
|
Context const& context, \
|
||||||
|
boost::spirit::x3::unused_type const&); \
|
||||||
/***/
|
/***/
|
||||||
|
|
||||||
}}}
|
} // namespace x3
|
||||||
|
} // namespace spirit
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
#endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
#endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_CAIRO_CONTEXT_HPP
|
#ifndef MAPNIK_CAIRO_CONTEXT_HPP
|
||||||
#define MAPNIK_CAIRO_CONTEXT_HPP
|
#define MAPNIK_CAIRO_CONTEXT_HPP
|
||||||
|
|
||||||
|
@ -57,7 +56,8 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename T> class box2d;
|
template<typename T>
|
||||||
|
class box2d;
|
||||||
|
|
||||||
using ErrorStatus = cairo_status_t;
|
using ErrorStatus = cairo_status_t;
|
||||||
|
|
||||||
|
@ -67,10 +67,10 @@ inline void throw_exception(ErrorStatus status)
|
||||||
throw std::runtime_error(std::string("cairo: ") + cairo_status_to_string(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)
|
inline void check_status_and_throw_exception(ErrorStatus status)
|
||||||
{
|
{
|
||||||
if(status != CAIRO_STATUS_SUCCESS)
|
if (status != CAIRO_STATUS_SUCCESS)
|
||||||
throw_exception(status);
|
throw_exception(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,60 +82,65 @@ void check_object_status_and_throw_exception(T const& object)
|
||||||
|
|
||||||
class cairo_face : private util::noncopyable
|
class cairo_face : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
|
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
|
||||||
~cairo_face();
|
~cairo_face();
|
||||||
cairo_font_face_t * face() const;
|
cairo_font_face_t* face() const;
|
||||||
private:
|
|
||||||
|
private:
|
||||||
class handle
|
class handle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
handle(std::shared_ptr<font_library> const& library, face_ptr const& face)
|
handle(std::shared_ptr<font_library> const& library, face_ptr const& face)
|
||||||
: library_(library), face_(face) {}
|
: library_(library)
|
||||||
|
, face_(face)
|
||||||
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<font_library> library_;
|
std::shared_ptr<font_library> library_;
|
||||||
face_ptr face_;
|
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;
|
delete h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
face_ptr face_;
|
face_ptr face_;
|
||||||
cairo_font_face_t *c_face_;
|
cairo_font_face_t* c_face_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using cairo_face_ptr = std::shared_ptr<cairo_face>;
|
using cairo_face_ptr = std::shared_ptr<cairo_face>;
|
||||||
|
|
||||||
class cairo_face_manager : private util::noncopyable
|
class cairo_face_manager : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cairo_face_manager(std::shared_ptr<font_library> library);
|
cairo_face_manager(std::shared_ptr<font_library> library);
|
||||||
cairo_face_ptr get_face(face_ptr face);
|
cairo_face_ptr get_face(face_ptr face);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using cairo_face_cache = std::map<face_ptr,cairo_face_ptr>;
|
using cairo_face_cache = std::map<face_ptr, cairo_face_ptr>;
|
||||||
std::shared_ptr<font_library> font_library_;
|
std::shared_ptr<font_library> font_library_;
|
||||||
cairo_face_cache cache_;
|
cairo_face_cache cache_;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cairo_closer
|
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
|
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)
|
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
|
class cairo_pattern : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit cairo_pattern(image_rgba8 const& data, double opacity = 1.0)
|
explicit cairo_pattern(image_rgba8 const& data, double opacity = 1.0)
|
||||||
{
|
{
|
||||||
std::size_t pixels = data.width() * data.height();
|
std::size_t pixels = data.width() * data.height();
|
||||||
const unsigned int *in_ptr = data.data();
|
const unsigned int* in_ptr = data.data();
|
||||||
const unsigned int *in_end = in_ptr + pixels;
|
const unsigned int* in_end = in_ptr + pixels;
|
||||||
unsigned int *out_ptr;
|
unsigned int* out_ptr;
|
||||||
|
|
||||||
surface_ = cairo_surface_ptr(
|
surface_ = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
||||||
cairo_image_surface_create(
|
|
||||||
CAIRO_FORMAT_ARGB32,
|
|
||||||
static_cast<int>(data.width()),
|
static_cast<int>(data.width()),
|
||||||
static_cast<int>(data.height())),
|
static_cast<int>(data.height())),
|
||||||
cairo_surface_closer());
|
cairo_surface_closer());
|
||||||
|
|
||||||
out_ptr = reinterpret_cast<unsigned int *>(
|
out_ptr = reinterpret_cast<unsigned int*>(cairo_image_surface_get_data(surface_.get()));
|
||||||
cairo_image_surface_get_data(surface_.get()));
|
|
||||||
|
|
||||||
while (in_ptr < in_end)
|
while (in_ptr < in_end)
|
||||||
{
|
{
|
||||||
|
@ -175,9 +177,9 @@ public:
|
||||||
unsigned int b = static_cast<unsigned>(((in >> 16) & 0xff) * opacity);
|
unsigned int b = static_cast<unsigned>(((in >> 16) & 0xff) * opacity);
|
||||||
unsigned int a = static_cast<unsigned>(((in >> 24) & 0xff) * opacity);
|
unsigned int a = static_cast<unsigned>(((in >> 24) & 0xff) * opacity);
|
||||||
|
|
||||||
//r = r * a / 255;
|
// r = r * a / 255;
|
||||||
//g = g * a / 255;
|
// g = g * a / 255;
|
||||||
//b = b * a / 255;
|
// b = b * a / 255;
|
||||||
|
|
||||||
*out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b;
|
*out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
|
@ -186,59 +188,46 @@ public:
|
||||||
pattern_ = cairo_pattern_create_for_surface(surface_.get());
|
pattern_ = cairo_pattern_create_for_surface(surface_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_pattern(cairo_surface_ptr const& surface) :
|
cairo_pattern(cairo_surface_ptr const& surface)
|
||||||
surface_(surface),
|
: surface_(surface)
|
||||||
pattern_(cairo_pattern_create_for_surface(surface_.get()))
|
, pattern_(cairo_pattern_create_for_surface(surface_.get()))
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
~cairo_pattern()
|
~cairo_pattern()
|
||||||
{
|
{
|
||||||
if (pattern_) cairo_pattern_destroy(pattern_);
|
if (pattern_)
|
||||||
|
cairo_pattern_destroy(pattern_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_matrix(cairo_matrix_t const& matrix)
|
void set_matrix(cairo_matrix_t const& matrix) { cairo_pattern_set_matrix(pattern_, &matrix); }
|
||||||
{
|
|
||||||
cairo_pattern_set_matrix(pattern_, &matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_origin(double x, double y)
|
void set_origin(double x, double y)
|
||||||
{
|
{
|
||||||
cairo_matrix_t matrix;
|
cairo_matrix_t matrix;
|
||||||
cairo_pattern_get_matrix(pattern_,&matrix);
|
cairo_pattern_get_matrix(pattern_, &matrix);
|
||||||
matrix.x0 = -x;
|
matrix.x0 = -x;
|
||||||
matrix.y0 = -y;
|
matrix.y0 = -y;
|
||||||
cairo_pattern_set_matrix(pattern_,&matrix);
|
cairo_pattern_set_matrix(pattern_, &matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_extend(cairo_extend_t extend)
|
void set_extend(cairo_extend_t extend) { cairo_pattern_set_extend(pattern_, extend); }
|
||||||
{
|
|
||||||
cairo_pattern_set_extend(pattern_, extend);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_filter(cairo_filter_t filter)
|
void set_filter(cairo_filter_t filter) { cairo_pattern_set_filter(pattern_, filter); }
|
||||||
{
|
|
||||||
cairo_pattern_set_filter(pattern_, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
cairo_pattern_t * pattern() const
|
cairo_pattern_t* pattern() const { return pattern_; }
|
||||||
{
|
|
||||||
return pattern_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cairo_surface_ptr surface_;
|
cairo_surface_ptr surface_;
|
||||||
cairo_pattern_t * pattern_;
|
cairo_pattern_t* pattern_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class cairo_gradient : private util::noncopyable
|
class cairo_gradient : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cairo_gradient(mapnik::gradient const& grad, double opacity=1.0)
|
cairo_gradient(mapnik::gradient const& grad, double opacity = 1.0)
|
||||||
{
|
{
|
||||||
double x1,x2,y1,y2,rad;
|
double x1, x2, y1, y2, rad;
|
||||||
grad.get_control_points(x1,y1,x2,y2,rad);
|
grad.get_control_points(x1, y1, x2, y2, rad);
|
||||||
if (grad.get_gradient_type() == LINEAR)
|
if (grad.get_gradient_type() == LINEAR)
|
||||||
{
|
{
|
||||||
pattern_ = cairo_pattern_create_linear(x1, y1, x2, y2);
|
pattern_ = cairo_pattern_create_linear(x1, y1, x2, y2);
|
||||||
|
@ -250,14 +239,14 @@ public:
|
||||||
|
|
||||||
units_ = grad.get_units();
|
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;
|
mapnik::color const& stop_color = st.second;
|
||||||
double r= static_cast<double> (stop_color.red())/255.0;
|
double r = static_cast<double>(stop_color.red()) / 255.0;
|
||||||
double g= static_cast<double> (stop_color.green())/255.0;
|
double g = static_cast<double>(stop_color.green()) / 255.0;
|
||||||
double b= static_cast<double> (stop_color.blue())/255.0;
|
double b = static_cast<double>(stop_color.blue()) / 255.0;
|
||||||
double a= static_cast<double> (stop_color.alpha())/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);
|
cairo_pattern_add_color_stop_rgba(pattern_, st.first, r, g, b, a * opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
double m[6];
|
double m[6];
|
||||||
|
@ -265,7 +254,7 @@ public:
|
||||||
tr.invert();
|
tr.invert();
|
||||||
tr.store_to(m);
|
tr.store_to(m);
|
||||||
cairo_matrix_t matrix;
|
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);
|
cairo_pattern_set_matrix(pattern_, &matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,43 +264,32 @@ public:
|
||||||
cairo_pattern_destroy(pattern_);
|
cairo_pattern_destroy(pattern_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cairo_pattern_t* gradient() const { return pattern_; }
|
||||||
|
|
||||||
cairo_pattern_t * gradient() const
|
gradient_unit_e units() const { return units_; }
|
||||||
{
|
|
||||||
return pattern_;
|
|
||||||
}
|
|
||||||
|
|
||||||
gradient_unit_e units() const
|
private:
|
||||||
{
|
cairo_pattern_t* pattern_;
|
||||||
return units_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
cairo_pattern_t * pattern_;
|
|
||||||
gradient_unit_e units_;
|
gradient_unit_e units_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class cairo_context : private util::noncopyable
|
class cairo_context : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cairo_context(cairo_ptr const& cairo);
|
cairo_context(cairo_ptr const& cairo);
|
||||||
|
|
||||||
inline ErrorStatus get_status() const
|
inline ErrorStatus get_status() const { return cairo_status(cairo_.get()); }
|
||||||
{
|
|
||||||
return cairo_status(cairo_.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
void clip();
|
void clip();
|
||||||
void show_page();
|
void show_page();
|
||||||
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_color(double r, double g, double b, double opacity = 1.0);
|
||||||
void set_operator(composite_mode_e comp_op);
|
void set_operator(composite_mode_e comp_op);
|
||||||
void set_line_join(line_join_e join);
|
void set_line_join(line_join_e join);
|
||||||
void set_line_cap(line_cap_e cap);
|
void set_line_cap(line_cap_e cap);
|
||||||
void set_miter_limit(double limit);
|
void set_miter_limit(double limit);
|
||||||
void set_line_width(double width);
|
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 set_fill_rule(cairo_fill_rule_t fill_rule);
|
||||||
void move_to(double x, double y);
|
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);
|
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 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(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 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_font_matrix(cairo_matrix_t const& matrix);
|
||||||
void set_matrix(cairo_matrix_t const& matrix);
|
void set_matrix(cairo_matrix_t const& matrix);
|
||||||
void transform(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 show_glyph(unsigned long index, pixel_position const& pos);
|
||||||
void glyph_path(unsigned long index, pixel_position const& pos);
|
void glyph_path(unsigned long index, pixel_position const& pos);
|
||||||
void add_text(glyph_positions 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 comp_op = src_over,
|
||||||
composite_mode_e halo_comp_op = src_over,
|
composite_mode_e halo_comp_op = src_over,
|
||||||
double scale_factor = 1.0);
|
double scale_factor = 1.0);
|
||||||
|
@ -344,7 +322,7 @@ public:
|
||||||
void push_group();
|
void push_group();
|
||||||
void pop_group();
|
void pop_group();
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void add_path(T& path, unsigned start_index = 0)
|
void add_path(T& path, unsigned start_index = 0)
|
||||||
{
|
{
|
||||||
double x, y;
|
double x, y;
|
||||||
|
@ -366,11 +344,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void add_agg_path(T& path, unsigned start_index = 0)
|
void add_agg_path(T& path, unsigned start_index = 0)
|
||||||
{
|
{
|
||||||
double x=0;
|
double x = 0;
|
||||||
double y=0;
|
double y = 0;
|
||||||
|
|
||||||
path.rewind(start_index);
|
path.rewind(start_index);
|
||||||
|
|
||||||
|
@ -384,26 +362,26 @@ public:
|
||||||
{
|
{
|
||||||
if (agg::is_curve3(cm))
|
if (agg::is_curve3(cm))
|
||||||
{
|
{
|
||||||
double end_x=0;
|
double end_x = 0;
|
||||||
double end_y=0;
|
double end_y = 0;
|
||||||
|
|
||||||
MAPNIK_LOG_WARN(cairo_renderer) << "Curve 3 not implemented";
|
MAPNIK_LOG_WARN(cairo_renderer) << "Curve 3 not implemented";
|
||||||
|
|
||||||
path.vertex(&end_x, &end_y);
|
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))
|
else if (agg::is_curve4(cm))
|
||||||
{
|
{
|
||||||
double ct2_x=0;
|
double ct2_x = 0;
|
||||||
double ct2_y=0;
|
double ct2_y = 0;
|
||||||
double end_x=0;
|
double end_x = 0;
|
||||||
double end_y=0;
|
double end_y = 0;
|
||||||
|
|
||||||
path.vertex(&ct2_x, &ct2_y);
|
path.vertex(&ct2_x, &ct2_y);
|
||||||
path.vertex(&end_x, &end_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))
|
else if (agg::is_line_to(cm))
|
||||||
{
|
{
|
||||||
|
@ -426,21 +404,22 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cairo_ptr cairo_;
|
cairo_ptr cairo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template<typename Context>
|
||||||
struct line_pattern_rasterizer
|
struct line_pattern_rasterizer
|
||||||
{
|
{
|
||||||
line_pattern_rasterizer(Context & context, cairo_pattern & pattern, unsigned width, unsigned height)
|
line_pattern_rasterizer(Context& context, cairo_pattern& pattern, unsigned width, unsigned height)
|
||||||
: context_(context),
|
: context_(context)
|
||||||
pattern_(pattern),
|
, pattern_(pattern)
|
||||||
width_(width),
|
, width_(width)
|
||||||
height_(height) {}
|
, height_(height)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void add_path(T & path, unsigned start_index = 0)
|
void add_path(T& path, unsigned start_index = 0)
|
||||||
{
|
{
|
||||||
double length = 0.0;
|
double length = 0.0;
|
||||||
double x0 = 0.0;
|
double x0 = 0.0;
|
||||||
|
@ -479,13 +458,12 @@ struct line_pattern_rasterizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context & context_;
|
Context& context_;
|
||||||
cairo_pattern & pattern_;
|
cairo_pattern& pattern_;
|
||||||
unsigned width_;
|
unsigned width_;
|
||||||
unsigned height_;
|
unsigned height_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_CONTEXT_HPP
|
#endif // MAPNIK_CAIRO_CONTEXT_HPP
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||||
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||||
|
|
||||||
|
@ -33,8 +32,7 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
|
static inline void cairo_image_to_rgba8(mapnik::image_rgba8& data, cairo_surface_ptr const& surface)
|
||||||
cairo_surface_ptr const& surface)
|
|
||||||
{
|
{
|
||||||
if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
|
if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +48,7 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
|
||||||
int stride = cairo_image_surface_get_stride(&*surface) / 4;
|
int stride = cairo_image_surface_get_stride(&*surface) / 4;
|
||||||
|
|
||||||
const std::unique_ptr<unsigned int[]> out_row(new unsigned int[data.width()]);
|
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)
|
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 g = (in >> 8) & 0xff;
|
||||||
unsigned int b = (in >> 0) & 0xff;
|
unsigned int b = (in >> 0) & 0xff;
|
||||||
|
|
||||||
#define DE_ALPHA(x) do { \
|
#define DE_ALPHA(x) \
|
||||||
if (a == 0) x = 0; \
|
do \
|
||||||
else x = x * 255 / a; \
|
{ \
|
||||||
if (x > 255) x = 255; \
|
if (a == 0) \
|
||||||
} while(0)
|
x = 0; \
|
||||||
|
else \
|
||||||
|
x = x * 255 / a; \
|
||||||
|
if (x > 255) \
|
||||||
|
x = 255; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
DE_ALPHA(r);
|
DE_ALPHA(r);
|
||||||
DE_ALPHA(g);
|
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
|
#endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||||
|
|
|
@ -32,12 +32,14 @@ namespace mapnik {
|
||||||
|
|
||||||
class cairo_context;
|
class cairo_context;
|
||||||
|
|
||||||
void render_vector_marker(cairo_context & context, svg_path_adapter & svg_path,
|
void render_vector_marker(cairo_context& context,
|
||||||
|
svg_path_adapter& svg_path,
|
||||||
svg_attribute_type const& attributes,
|
svg_attribute_type const& attributes,
|
||||||
box2d<double> const& bbox, agg::trans_affine const& tr,
|
box2d<double> const& bbox,
|
||||||
|
agg::trans_affine const& tr,
|
||||||
double opacity);
|
double opacity);
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP
|
#endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP
|
||||||
|
|
||||||
|
|
|
@ -53,42 +53,35 @@ class request;
|
||||||
struct pixel_position;
|
struct pixel_position;
|
||||||
struct cairo_save_restore
|
struct cairo_save_restore
|
||||||
{
|
{
|
||||||
cairo_save_restore(cairo_context & context)
|
cairo_save_restore(cairo_context& context)
|
||||||
: context_(context)
|
: context_(context)
|
||||||
{
|
{
|
||||||
context_.save();
|
context_.save();
|
||||||
}
|
}
|
||||||
~cairo_save_restore()
|
~cairo_save_restore() { context_.restore(); }
|
||||||
{
|
cairo_context& context_;
|
||||||
context_.restore();
|
|
||||||
}
|
|
||||||
cairo_context & context_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer<T> >,
|
class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer<T>>,
|
||||||
private util::noncopyable
|
private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using processor_impl_type = cairo_renderer<T>;
|
using processor_impl_type = cairo_renderer<T>;
|
||||||
cairo_renderer(Map const& m,
|
cairo_renderer(Map const& m, T const& obj, double scale_factor = 1.0, unsigned offset_x = 0, unsigned offset_y = 0);
|
||||||
T const& obj,
|
|
||||||
double scale_factor=1.0,
|
|
||||||
unsigned offset_x=0,
|
|
||||||
unsigned offset_y=0);
|
|
||||||
cairo_renderer(Map const& m,
|
cairo_renderer(Map const& m,
|
||||||
request const& req,
|
request const& req,
|
||||||
attributes const& vars,
|
attributes const& vars,
|
||||||
T const& obj,
|
T const& obj,
|
||||||
double scale_factor=1.0,
|
double scale_factor = 1.0,
|
||||||
unsigned offset_x=0,
|
unsigned offset_x = 0,
|
||||||
unsigned offset_y=0);
|
unsigned offset_y = 0);
|
||||||
cairo_renderer(Map const& m,
|
cairo_renderer(Map const& m,
|
||||||
T const& obj,
|
T const& obj,
|
||||||
std::shared_ptr<label_collision_detector4> detector,
|
std::shared_ptr<label_collision_detector4> detector,
|
||||||
double scale_factor=1.0,
|
double scale_factor = 1.0,
|
||||||
unsigned offset_x=0,
|
unsigned offset_x = 0,
|
||||||
unsigned offset_y=0);
|
unsigned offset_y = 0);
|
||||||
|
|
||||||
~cairo_renderer();
|
~cairo_renderer();
|
||||||
void start_map_processing(Map const& map);
|
void start_map_processing(Map const& map);
|
||||||
|
@ -97,93 +90,56 @@ public:
|
||||||
void end_layer_processing(layer const& lay);
|
void end_layer_processing(layer const& lay);
|
||||||
void start_style_processing(feature_type_style const& st);
|
void start_style_processing(feature_type_style const& st);
|
||||||
void end_style_processing(feature_type_style const& st);
|
void end_style_processing(feature_type_style const& st);
|
||||||
void process(point_symbolizer const& sym,
|
void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(line_symbolizer const& sym,
|
void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(line_pattern_symbolizer const& sym,
|
void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(polygon_symbolizer const& sym,
|
void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(debug_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(polygon_pattern_symbolizer const& sym,
|
inline bool
|
||||||
mapnik::feature_impl & feature,
|
process(rule::symbolizers const& /*syms*/, mapnik::feature_impl& /*feature*/, proj_transform const& /*prj_trans*/)
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(raster_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(shield_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(text_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(building_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(markers_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(group_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
void process(debug_symbolizer const& sym,
|
|
||||||
mapnik::feature_impl & feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
inline bool process(rule::symbolizers const& /*syms*/,
|
|
||||||
mapnik::feature_impl & /*feature*/,
|
|
||||||
proj_transform const& /*prj_trans*/)
|
|
||||||
{
|
{
|
||||||
// cairo renderer doesn't support processing of multiple symbolizers.
|
// cairo renderer doesn't support processing of multiple symbolizers.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool painted()
|
bool painted() { return true; }
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void painted(bool /*painted*/)
|
void painted(bool /*painted*/)
|
||||||
{
|
{
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
inline eAttributeCollectionPolicy attribute_collection_policy() const
|
inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
|
||||||
{
|
|
||||||
return DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline double scale_factor() const
|
inline double scale_factor() const { return common_.scale_factor_; }
|
||||||
{
|
|
||||||
return common_.scale_factor_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline attributes const& variables() const
|
inline attributes const& variables() const { return common_.vars_; }
|
||||||
{
|
|
||||||
return common_.vars_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void render_marker(pixel_position const& pos,
|
void render_marker(pixel_position const& pos,
|
||||||
marker const& marker,
|
marker const& marker,
|
||||||
agg::trans_affine const& mtx,
|
agg::trans_affine const& mtx,
|
||||||
double opacity=1.0,
|
double opacity = 1.0,
|
||||||
bool recenter=true);
|
bool recenter = true);
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
Map const& m_;
|
Map const& m_;
|
||||||
cairo_context context_;
|
cairo_context context_;
|
||||||
renderer_common common_;
|
renderer_common common_;
|
||||||
cairo_face_manager face_manager_;
|
cairo_face_manager face_manager_;
|
||||||
bool style_level_compositing_;
|
bool style_level_compositing_;
|
||||||
void setup(Map const& m);
|
void setup(Map const& m);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>;
|
extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_RENDERER_HPP
|
#endif // MAPNIK_CAIRO_RENDERER_HPP
|
||||||
|
|
||||||
|
|
|
@ -36,36 +36,31 @@ namespace mapnik {
|
||||||
|
|
||||||
struct cairo_renderer_process_visitor_p
|
struct cairo_renderer_process_visitor_p
|
||||||
{
|
{
|
||||||
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr,
|
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr, double opacity)
|
||||||
double opacity)
|
: image_tr_(image_tr)
|
||||||
: image_tr_(image_tr),
|
, opacity_(opacity)
|
||||||
opacity_(opacity)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
cairo_surface_ptr operator()(marker_svg const & marker) const
|
cairo_surface_ptr operator()(marker_svg const& marker) const
|
||||||
{
|
{
|
||||||
box2d<double> bbox(marker.bounding_box());
|
box2d<double> bbox(marker.bounding_box());
|
||||||
agg::trans_affine tr(transform(bbox));
|
agg::trans_affine tr(transform(bbox));
|
||||||
|
|
||||||
double width = std::max(1.0, std::round(bbox.width()));
|
double width = std::max(1.0, std::round(bbox.width()));
|
||||||
double height = std::max(1.0, std::round(bbox.height()));
|
double height = std::max(1.0, std::round(bbox.height()));
|
||||||
cairo_rectangle_t extent { 0, 0, width, height };
|
cairo_rectangle_t extent{0, 0, width, height};
|
||||||
cairo_surface_ptr surface(
|
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
||||||
cairo_recording_surface_create(
|
|
||||||
CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
|
||||||
cairo_surface_closer());
|
cairo_surface_closer());
|
||||||
|
|
||||||
cairo_ptr cairo = create_context(surface);
|
cairo_ptr cairo = create_context(surface);
|
||||||
cairo_context context(cairo);
|
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_attribute_type const& svg_attributes = svg.attributes();
|
||||||
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(
|
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(svg.source());
|
||||||
svg.source());
|
|
||||||
svg::svg_path_adapter svg_path(stl_storage);
|
svg::svg_path_adapter svg_path(stl_storage);
|
||||||
|
|
||||||
render_vector_marker(context, svg_path, svg_attributes,
|
render_vector_marker(context, svg_path, svg_attributes, bbox, tr, opacity_);
|
||||||
bbox, tr, opacity_);
|
|
||||||
|
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
@ -75,10 +70,8 @@ struct cairo_renderer_process_visitor_p
|
||||||
box2d<double> bbox(marker.bounding_box());
|
box2d<double> bbox(marker.bounding_box());
|
||||||
agg::trans_affine tr(transform(bbox));
|
agg::trans_affine tr(transform(bbox));
|
||||||
|
|
||||||
cairo_rectangle_t extent { 0, 0, bbox.width(), bbox.height() };
|
cairo_rectangle_t extent{0, 0, bbox.width(), bbox.height()};
|
||||||
cairo_surface_ptr surface(
|
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
||||||
cairo_recording_surface_create(
|
|
||||||
CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
|
||||||
cairo_surface_closer());
|
cairo_surface_closer());
|
||||||
|
|
||||||
cairo_ptr cairo = create_context(surface);
|
cairo_ptr cairo = create_context(surface);
|
||||||
|
@ -89,25 +82,21 @@ struct cairo_renderer_process_visitor_p
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_surface_ptr operator() (marker_null const&) const
|
cairo_surface_ptr operator()(marker_null const&) const
|
||||||
{
|
{
|
||||||
cairo_surface_ptr surface(
|
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, nullptr),
|
||||||
cairo_recording_surface_create(
|
|
||||||
CAIRO_CONTENT_COLOR_ALPHA, nullptr),
|
|
||||||
cairo_surface_closer());
|
cairo_surface_closer());
|
||||||
cairo_ptr cairo = create_context(surface);
|
cairo_ptr cairo = create_context(surface);
|
||||||
cairo_context context(cairo);
|
cairo_context context(cairo);
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
agg::trans_affine transform(box2d<double> & bbox) const
|
agg::trans_affine transform(box2d<double>& bbox) const
|
||||||
{
|
{
|
||||||
bbox *= image_tr_;
|
bbox *= image_tr_;
|
||||||
coord<double, 2> c = bbox.center();
|
coord<double, 2> c = bbox.center();
|
||||||
agg::trans_affine mtx = agg::trans_affine_translation(
|
agg::trans_affine mtx = agg::trans_affine_translation(0.5 * bbox.width() - c.x, 0.5 * bbox.height() - c.y);
|
||||||
0.5 * bbox.width() - c.x,
|
|
||||||
0.5 * bbox.height() - c.y);
|
|
||||||
return image_tr_ * mtx;
|
return image_tr_ * mtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +124,7 @@ struct cairo_pattern_base
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename VertexConverter>
|
template<typename VertexConverter>
|
||||||
struct cairo_polygon_pattern : cairo_pattern_base
|
struct cairo_polygon_pattern : cairo_pattern_base
|
||||||
{
|
{
|
||||||
cairo_polygon_pattern(mapnik::marker const& marker,
|
cairo_polygon_pattern(mapnik::marker const& marker,
|
||||||
|
@ -143,22 +132,23 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
||||||
symbolizer_base const& sym,
|
symbolizer_base const& sym,
|
||||||
mapnik::feature_impl const& feature,
|
mapnik::feature_impl const& feature,
|
||||||
proj_transform const& prj_trans)
|
proj_transform const& prj_trans)
|
||||||
: cairo_pattern_base{marker, common, sym, feature, prj_trans},
|
: cairo_pattern_base{marker, common, sym, feature, prj_trans}
|
||||||
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
|
, clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
|
||||||
clip_box_(clipping_extent(common)),
|
, clip_box_(clipping_extent(common))
|
||||||
tr_(geom_transform()),
|
, tr_(geom_transform())
|
||||||
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
|
, converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
|
||||||
feature, common.vars_, common.scale_factor_)
|
|
||||||
{
|
{
|
||||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_);
|
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_);
|
||||||
value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_);
|
value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_);
|
||||||
|
|
||||||
converter_.template set<affine_transform_tag>();
|
converter_.template set<affine_transform_tag>();
|
||||||
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
|
if (simplify_tolerance > 0.0)
|
||||||
if (smooth > 0.0) converter_.template set<smooth_tag>();
|
converter_.template set<simplify_tag>();
|
||||||
|
if (smooth > 0.0)
|
||||||
|
converter_.template set<smooth_tag>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(cairo_fill_rule_t fill_rule, cairo_context & context)
|
void render(cairo_fill_rule_t fill_rule, cairo_context& context)
|
||||||
{
|
{
|
||||||
value_double opacity = get<value_double, keys::opacity>(sym_, feature_, common_.vars_);
|
value_double opacity = get<value_double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||||
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
|
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;
|
cairo_rectangle_t pattern_surface_extent;
|
||||||
if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent))
|
if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent))
|
||||||
{
|
{
|
||||||
offset = pattern_offset(sym_, feature_, prj_trans_, common_,
|
offset = pattern_offset(sym_,
|
||||||
pattern_surface_extent.width, pattern_surface_extent.height);
|
feature_,
|
||||||
|
prj_trans_,
|
||||||
|
common_,
|
||||||
|
pattern_surface_extent.width,
|
||||||
|
pattern_surface_extent.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_pattern pattern(surface);
|
cairo_pattern pattern(surface);
|
||||||
|
@ -193,7 +187,7 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
||||||
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, cairo_context>;
|
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, cairo_context>;
|
||||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||||
apply_vertex_converter_type apply(converter_, context);
|
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
|
// fill polygon
|
||||||
context.set_fill_rule(fill_rule);
|
context.set_fill_rule(fill_rule);
|
||||||
context.fill();
|
context.fill();
|
||||||
|
@ -207,5 +201,4 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
||||||
|
|
||||||
} // namespace mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP
|
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP
|
||||||
|
|
|
@ -35,15 +35,15 @@ namespace mapnik {
|
||||||
#if defined(HAVE_CAIRO)
|
#if defined(HAVE_CAIRO)
|
||||||
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
||||||
std::string const& filename,
|
std::string const& filename,
|
||||||
double scale_factor=1.0,
|
double scale_factor = 1.0,
|
||||||
double scale_denominator=0.0);
|
double scale_denominator = 0.0);
|
||||||
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
||||||
std::string const& filename,
|
std::string const& filename,
|
||||||
std::string const& type,
|
std::string const& type,
|
||||||
double scale_factor=1.0,
|
double scale_factor = 1.0,
|
||||||
double scale_denominator=0.0);
|
double scale_denominator = 0.0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // end ns
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_IO_HPP
|
#endif // MAPNIK_CAIRO_IO_HPP
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace mapnik {
|
||||||
|
|
||||||
class MAPNIK_DECL color : boost::equality_comparable<color>
|
class MAPNIK_DECL color : boost::equality_comparable<color>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::uint8_t red_;
|
std::uint8_t red_;
|
||||||
std::uint8_t green_;
|
std::uint8_t green_;
|
||||||
std::uint8_t blue_;
|
std::uint8_t blue_;
|
||||||
|
@ -50,46 +50,52 @@ public:
|
||||||
|
|
||||||
// default ctor
|
// default ctor
|
||||||
color()
|
color()
|
||||||
: red_(0xff),
|
: red_(0xff)
|
||||||
green_(0xff),
|
, green_(0xff)
|
||||||
blue_(0xff),
|
, blue_(0xff)
|
||||||
alpha_(0xff),
|
, alpha_(0xff)
|
||||||
premultiplied_(false)
|
, premultiplied_(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
color(std::uint8_t _red, std::uint8_t _green, std::uint8_t _blue, std::uint8_t _alpha = 0xff, bool premultiplied = false)
|
color(std::uint8_t _red,
|
||||||
: red_(_red),
|
std::uint8_t _green,
|
||||||
green_(_green),
|
std::uint8_t _blue,
|
||||||
blue_(_blue),
|
std::uint8_t _alpha = 0xff,
|
||||||
alpha_(_alpha),
|
bool premultiplied = false)
|
||||||
premultiplied_(premultiplied)
|
: red_(_red)
|
||||||
|
, green_(_green)
|
||||||
|
, blue_(_blue)
|
||||||
|
, alpha_(_alpha)
|
||||||
|
, premultiplied_(premultiplied)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
color(std::uint32_t _rgba, bool premultiplied = false)
|
color(std::uint32_t _rgba, bool premultiplied = false)
|
||||||
: red_(_rgba & 0xff),
|
: red_(_rgba & 0xff)
|
||||||
green_((_rgba >> 8) & 0xff),
|
, green_((_rgba >> 8) & 0xff)
|
||||||
blue_((_rgba >> 16) & 0xff),
|
, blue_((_rgba >> 16) & 0xff)
|
||||||
alpha_((_rgba >> 24) & 0xff),
|
, alpha_((_rgba >> 24) & 0xff)
|
||||||
premultiplied_(premultiplied) {}
|
, premultiplied_(premultiplied)
|
||||||
|
{}
|
||||||
|
|
||||||
// copy ctor
|
// copy ctor
|
||||||
color(const color& rhs)
|
color(const color& rhs)
|
||||||
: red_(rhs.red_),
|
: red_(rhs.red_)
|
||||||
green_(rhs.green_),
|
, green_(rhs.green_)
|
||||||
blue_(rhs.blue_),
|
, blue_(rhs.blue_)
|
||||||
alpha_(rhs.alpha_),
|
, alpha_(rhs.alpha_)
|
||||||
premultiplied_(rhs.premultiplied_)
|
, premultiplied_(rhs.premultiplied_)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// move ctor
|
// move ctor
|
||||||
color(color && rhs)
|
color(color&& rhs)
|
||||||
: red_(std::move(rhs.red_)),
|
: red_(std::move(rhs.red_))
|
||||||
green_(std::move(rhs.green_)),
|
, green_(std::move(rhs.green_))
|
||||||
blue_(std::move(rhs.blue_)),
|
, blue_(std::move(rhs.blue_))
|
||||||
alpha_(std::move(rhs.alpha_)),
|
, alpha_(std::move(rhs.alpha_))
|
||||||
premultiplied_(std::move(rhs.premultiplied_)) {}
|
, premultiplied_(std::move(rhs.premultiplied_))
|
||||||
|
{}
|
||||||
|
|
||||||
color( std::string const& str, bool premultiplied = false);
|
color(std::string const& str, bool premultiplied = false);
|
||||||
|
|
||||||
std::string to_string() const;
|
std::string to_string() const;
|
||||||
std::string to_hex_string() const;
|
std::string to_hex_string() const;
|
||||||
|
@ -104,78 +110,45 @@ public:
|
||||||
|
|
||||||
inline bool operator==(color const& rhs) const
|
inline bool operator==(color const& rhs) const
|
||||||
{
|
{
|
||||||
return (red_== rhs.red_) &&
|
return (red_ == rhs.red_) && (green_ == rhs.green_) && (blue_ == rhs.blue_) && (alpha_ == rhs.alpha_) &&
|
||||||
(green_ == rhs.green_) &&
|
|
||||||
(blue_ == rhs.blue_) &&
|
|
||||||
(alpha_ == rhs.alpha_) &&
|
|
||||||
(premultiplied_ == rhs.premultiplied_);
|
(premultiplied_ == rhs.premultiplied_);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::uint8_t red() const
|
inline std::uint8_t red() const { return red_; }
|
||||||
{
|
|
||||||
return red_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::uint8_t green() const
|
inline std::uint8_t green() const { return green_; }
|
||||||
{
|
|
||||||
return green_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::uint8_t blue() const
|
inline std::uint8_t blue() const { return blue_; }
|
||||||
{
|
|
||||||
return blue_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::uint8_t alpha() const
|
inline std::uint8_t alpha() const { return alpha_; }
|
||||||
{
|
|
||||||
return alpha_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_red(std::uint8_t _red)
|
inline void set_red(std::uint8_t _red) { red_ = _red; }
|
||||||
{
|
|
||||||
red_ = _red;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_green(std::uint8_t _green)
|
inline void set_green(std::uint8_t _green) { green_ = _green; }
|
||||||
{
|
|
||||||
green_ = _green;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_blue(std::uint8_t _blue)
|
inline void set_blue(std::uint8_t _blue) { blue_ = _blue; }
|
||||||
{
|
inline void set_alpha(std::uint8_t _alpha) { alpha_ = _alpha; }
|
||||||
blue_ = _blue;
|
inline bool get_premultiplied() const { return premultiplied_; }
|
||||||
}
|
inline void set_premultiplied(bool val) { premultiplied_ = val; }
|
||||||
inline void set_alpha(std::uint8_t _alpha)
|
|
||||||
{
|
|
||||||
alpha_ = _alpha;
|
|
||||||
}
|
|
||||||
inline bool get_premultiplied() const
|
|
||||||
{
|
|
||||||
return premultiplied_;
|
|
||||||
}
|
|
||||||
inline void set_premultiplied(bool val)
|
|
||||||
{
|
|
||||||
premultiplied_ = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline unsigned rgba() const
|
inline unsigned rgba() const
|
||||||
{
|
{
|
||||||
return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_)) ;
|
return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_));
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
void swap(color & rhs)
|
private:
|
||||||
|
void swap(color& rhs)
|
||||||
{
|
{
|
||||||
std::swap(red_, rhs.red_);
|
std::swap(red_, rhs.red_);
|
||||||
std::swap(green_,rhs.green_);
|
std::swap(green_, rhs.green_);
|
||||||
std::swap(blue_,rhs.blue_);
|
std::swap(blue_, rhs.blue_);
|
||||||
std::swap(alpha_,rhs.alpha_);
|
std::swap(alpha_, rhs.alpha_);
|
||||||
std::swap(premultiplied_, rhs.premultiplied_);
|
std::swap(premultiplied_, rhs.premultiplied_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
std::basic_ostream<charT, traits> &
|
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, mapnik::color const& c)
|
||||||
operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
|
|
||||||
{
|
{
|
||||||
s << c.to_string();
|
s << c.to_string();
|
||||||
return s;
|
return s;
|
||||||
|
@ -187,6 +160,6 @@ inline std::size_t hash_value(color const& c)
|
||||||
return c.rgba();
|
return c.rgba();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_COLOR_HPP
|
#endif // MAPNIK_COLOR_HPP
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/color.hpp>
|
#include <mapnik/color.hpp>
|
||||||
|
|
||||||
//stl
|
// stl
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
|
@ -26,28 +26,28 @@
|
||||||
// Windows DLL support
|
// Windows DLL support
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# define MAPNIK_EXP __declspec (dllexport)
|
#define MAPNIK_EXP __declspec(dllexport)
|
||||||
# define MAPNIK_IMP __declspec (dllimport)
|
#define MAPNIK_IMP __declspec(dllimport)
|
||||||
# ifdef MAPNIK_EXPORTS
|
#ifdef MAPNIK_EXPORTS
|
||||||
# define MAPNIK_DECL __declspec (dllexport)
|
#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
|
|
||||||
#else
|
#else
|
||||||
# if __GNUC__ >= 4
|
#define MAPNIK_DECL __declspec(dllimport)
|
||||||
# define MAPNIK_EXP __attribute__ ((visibility ("default")))
|
#endif
|
||||||
# define MAPNIK_DECL __attribute__ ((visibility ("default")))
|
#pragma warning(disable: 4251)
|
||||||
# define MAPNIK_IMP __attribute__ ((visibility ("default")))
|
#pragma warning(disable: 4275)
|
||||||
# else
|
#if (_MSC_VER >= 1400) // vc8
|
||||||
# define MAPNIK_EXP
|
#pragma warning(disable: 4996) //_CRT_SECURE_NO_DEPRECATE
|
||||||
# define MAPNIK_DECL
|
#endif
|
||||||
# define MAPNIK_IMP
|
#else
|
||||||
# endif
|
#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
|
#endif
|
||||||
|
|
||||||
#define PROJ_ENVELOPE_POINTS 20
|
#define PROJ_ENVELOPE_POINTS 20
|
||||||
|
|
|
@ -34,19 +34,17 @@ class xml_node;
|
||||||
|
|
||||||
class config_error : public std::exception
|
class config_error : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
config_error(std::string const& what);
|
config_error(std::string const& what);
|
||||||
config_error(std::string const& what,
|
config_error(std::string const& what, xml_node const& node);
|
||||||
xml_node const& node);
|
config_error(std::string const& what, unsigned line_number, std::string const& filename);
|
||||||
config_error(std::string const& what,
|
|
||||||
unsigned line_number,
|
|
||||||
std::string const& filename);
|
|
||||||
virtual ~config_error() {}
|
virtual ~config_error() {}
|
||||||
virtual const char * what() const noexcept;
|
virtual const char* what() const noexcept;
|
||||||
void append_context(std::string const& ctx) const;
|
void append_context(std::string const& ctx) const;
|
||||||
void append_context(std::string const& ctx, xml_node const& node) const;
|
void append_context(std::string const& ctx, xml_node const& node) const;
|
||||||
void append_context(xml_node const& node) const;
|
void append_context(xml_node const& node) const;
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
mutable std::string what_;
|
mutable std::string what_;
|
||||||
mutable unsigned line_number_;
|
mutable unsigned line_number_;
|
||||||
mutable std::string file_;
|
mutable std::string file_;
|
||||||
|
@ -54,6 +52,6 @@ protected:
|
||||||
mutable std::string msg_;
|
mutable std::string msg_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CONFIG_ERROR_HPP
|
#endif // MAPNIK_CONFIG_ERROR_HPP
|
||||||
|
|
|
@ -30,150 +30,173 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
template <typename T,int dim>
|
template<typename T, int dim>
|
||||||
struct coord {
|
struct coord
|
||||||
|
{
|
||||||
using type = T;
|
using type = T;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct coord<T,2>
|
struct coord<T, 2>
|
||||||
: boost::addable<coord<T,2>,
|
: boost::addable<
|
||||||
boost::addable2<coord<T,2>,T,
|
coord<T, 2>,
|
||||||
boost::subtractable<coord<T,2>,
|
boost::addable2<
|
||||||
boost::subtractable2<coord<T,2>,T,
|
coord<T, 2>,
|
||||||
boost::dividable2<coord<T,2>, T,
|
T,
|
||||||
boost::multipliable2<coord<T,2>, T > > > > > >
|
boost::subtractable<
|
||||||
|
coord<T, 2>,
|
||||||
|
boost::
|
||||||
|
subtractable2<coord<T, 2>, T, boost::dividable2<coord<T, 2>, T, boost::multipliable2<coord<T, 2>, T>>>>>>
|
||||||
|
|
||||||
{
|
{
|
||||||
using type = T;
|
using type = T;
|
||||||
T x;
|
T x;
|
||||||
T y;
|
T y;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
coord()
|
coord()
|
||||||
: x(),y() {}
|
: x()
|
||||||
coord(T x_,T y_)
|
, y()
|
||||||
: x(x_),y(y_) {}
|
{}
|
||||||
|
coord(T x_, T y_)
|
||||||
|
: x(x_)
|
||||||
|
, y(y_)
|
||||||
|
{}
|
||||||
|
|
||||||
coord(coord<T,2> const& rhs)
|
coord(coord<T, 2> const& rhs)
|
||||||
: x(rhs.x),
|
: x(rhs.x)
|
||||||
y(rhs.y) {}
|
, y(rhs.y)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
coord (coord<T2,2> const& rhs)
|
coord(coord<T2, 2> const& rhs)
|
||||||
: x(type(rhs.x)),
|
: x(type(rhs.x))
|
||||||
y(type(rhs.y)) {}
|
, y(type(rhs.y))
|
||||||
|
{}
|
||||||
|
|
||||||
coord(coord<T,2> && rhs) noexcept
|
coord(coord<T, 2>&& rhs) noexcept
|
||||||
: x(std::move(rhs.x)),
|
: x(std::move(rhs.x))
|
||||||
y(std::move(rhs.y)) {}
|
, y(std::move(rhs.y))
|
||||||
|
{}
|
||||||
|
|
||||||
coord<T,2>& operator=(coord<T,2> rhs)
|
coord<T, 2>& operator=(coord<T, 2> rhs)
|
||||||
{
|
{
|
||||||
swap(rhs);
|
swap(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
coord<T,2>& operator=(const coord<T2,2>& rhs)
|
coord<T, 2>& operator=(const coord<T2, 2>& rhs)
|
||||||
{
|
{
|
||||||
coord<T,2> tmp(rhs);
|
coord<T, 2> tmp(rhs);
|
||||||
swap(rhs);
|
swap(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
bool operator==(coord<T2,2> const& rhs)
|
bool operator==(coord<T2, 2> const& rhs)
|
||||||
{
|
{
|
||||||
return x == rhs.x && y == rhs.y;
|
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;
|
x += rhs.x;
|
||||||
y+=rhs.y;
|
y += rhs.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
coord<T,2>& operator+=(T rhs)
|
coord<T, 2>& operator+=(T rhs)
|
||||||
{
|
{
|
||||||
x+=rhs;
|
x += rhs;
|
||||||
y+=rhs;
|
y += rhs;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
coord<T,2>& operator-=(coord<T,2> const& rhs)
|
coord<T, 2>& operator-=(coord<T, 2> const& rhs)
|
||||||
{
|
{
|
||||||
x-=rhs.x;
|
x -= rhs.x;
|
||||||
y-=rhs.y;
|
y -= rhs.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
coord<T,2>& operator-=(T rhs)
|
coord<T, 2>& operator-=(T rhs)
|
||||||
{
|
{
|
||||||
x-=rhs;
|
x -= rhs;
|
||||||
y-=rhs;
|
y -= rhs;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
coord<T,2>& operator*=(T t)
|
coord<T, 2>& operator*=(T t)
|
||||||
{
|
{
|
||||||
x*=t;
|
x *= t;
|
||||||
y*=t;
|
y *= t;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
coord<T,2>& operator/=(T t)
|
coord<T, 2>& operator/=(T t)
|
||||||
{
|
{
|
||||||
x/=t;
|
x /= t;
|
||||||
y/=t;
|
y /= t;
|
||||||
return *this;
|
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->x, rhs.x);
|
||||||
std::swap(this->y, rhs.y);
|
std::swap(this->y, rhs.y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct coord<T,3>
|
struct coord<T, 3>
|
||||||
{
|
{
|
||||||
using type = T;
|
using type = T;
|
||||||
T x;
|
T x;
|
||||||
T y;
|
T y;
|
||||||
T z;
|
T z;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
coord()
|
coord()
|
||||||
: x(),y(),z() {}
|
: x()
|
||||||
coord(T x_,T y_,T z_)
|
, y()
|
||||||
: x(x_),y(y_),z(z_) {}
|
, z()
|
||||||
|
{}
|
||||||
|
coord(T x_, T y_, T z_)
|
||||||
|
: x(x_)
|
||||||
|
, y(y_)
|
||||||
|
, z(z_)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
coord (coord<T2,3> const& rhs)
|
coord(coord<T2, 3> const& rhs)
|
||||||
: x(type(rhs.x)),
|
: x(type(rhs.x))
|
||||||
y(type(rhs.y)),
|
, y(type(rhs.y))
|
||||||
z(type(rhs.z)) {}
|
, z(type(rhs.z))
|
||||||
|
{}
|
||||||
|
|
||||||
coord(coord<T,3> && rhs) noexcept
|
coord(coord<T, 3>&& rhs) noexcept
|
||||||
: x(std::move(rhs.x)),
|
: x(std::move(rhs.x))
|
||||||
y(std::move(rhs.y)),
|
, y(std::move(rhs.y))
|
||||||
z(std::move(rhs.z)) {}
|
, z(std::move(rhs.z))
|
||||||
|
{}
|
||||||
|
|
||||||
coord<T,3> operator=(coord<T,3> rhs)
|
coord<T, 3> operator=(coord<T, 3> rhs)
|
||||||
{
|
{
|
||||||
swap(rhs);
|
swap(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
coord<T,3>& operator=(coord<T2,3> const& rhs)
|
coord<T, 3>& operator=(coord<T2, 3> const& rhs)
|
||||||
{
|
{
|
||||||
coord<T,3> tmp(rhs);
|
coord<T, 3> tmp(rhs);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
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->x, rhs.x);
|
||||||
std::swap(this->y, rhs.y);
|
std::swap(this->y, rhs.y);
|
||||||
|
@ -181,10 +204,10 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using coord2d = coord<double,2>;
|
using coord2d = coord<double, 2>;
|
||||||
using coord2f = coord<float,2>;
|
using coord2f = coord<float, 2>;
|
||||||
using coord2i = coord<int,2>;
|
using coord2i = coord<int, 2>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_COORD_HPP
|
#endif // MAPNIK_COORD_HPP
|
||||||
|
|
|
@ -31,13 +31,11 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/spirit/home/x3.hpp>
|
#include <boost/spirit/home/x3.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
|
|
||||||
namespace css_color_grammar
|
namespace css_color_grammar {
|
||||||
{
|
|
||||||
|
|
||||||
struct css_color_class;
|
struct css_color_class;
|
||||||
using css_color_grammar_type = x3::rule<css_color_class, mapnik::color>;
|
using css_color_grammar_type = x3::rule<css_color_class, mapnik::color>;
|
||||||
|
@ -46,6 +44,7 @@ css_color_grammar_type const css_color = "css_color";
|
||||||
|
|
||||||
BOOST_SPIRIT_DECLARE(css_color_grammar_type);
|
BOOST_SPIRIT_DECLARE(css_color_grammar_type);
|
||||||
|
|
||||||
}}
|
} // namespace css_color_grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP
|
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP
|
||||||
|
|
|
@ -37,13 +37,8 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/fusion/adapted/std_tuple.hpp>
|
#include <boost/fusion/adapted/std_tuple.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT (
|
BOOST_FUSION_ADAPT_STRUCT(mapnik::color,
|
||||||
mapnik::color,
|
(std::uint8_t, red_)(std::uint8_t, green_)(std::uint8_t, blue_)(std::uint8_t, alpha_))
|
||||||
(std::uint8_t, red_)
|
|
||||||
(std::uint8_t, green_)
|
|
||||||
(std::uint8_t, blue_)
|
|
||||||
(std::uint8_t, alpha_)
|
|
||||||
)
|
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
|
@ -51,20 +46,21 @@ namespace x3 = boost::spirit::x3;
|
||||||
|
|
||||||
namespace css_color_grammar {
|
namespace css_color_grammar {
|
||||||
|
|
||||||
using x3::lit;
|
|
||||||
using x3::uint_parser;
|
|
||||||
using x3::hex;
|
|
||||||
using x3::symbols;
|
|
||||||
using x3::omit;
|
|
||||||
using x3::attr;
|
using x3::attr;
|
||||||
using x3::double_;
|
using x3::double_;
|
||||||
|
using x3::hex;
|
||||||
|
using x3::lit;
|
||||||
using x3::no_case;
|
using x3::no_case;
|
||||||
using x3::no_skip;
|
using x3::no_skip;
|
||||||
|
using x3::omit;
|
||||||
|
using x3::symbols;
|
||||||
|
using x3::uint_parser;
|
||||||
|
|
||||||
struct named_colors_ : x3::symbols<color>
|
struct named_colors_ : x3::symbols<color>
|
||||||
{
|
{
|
||||||
named_colors_()
|
named_colors_()
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
add
|
add
|
||||||
("aliceblue", color(240, 248, 255))
|
("aliceblue", color(240, 248, 255))
|
||||||
("antiquewhite", color(250, 235, 215))
|
("antiquewhite", color(250, 235, 215))
|
||||||
|
@ -216,6 +212,7 @@ struct named_colors_ : x3::symbols<color>
|
||||||
("yellowgreen", color(154, 205, 50))
|
("yellowgreen", color(154, 205, 50))
|
||||||
("transparent", color(0, 0, 0, 0))
|
("transparent", color(0, 0, 0, 0))
|
||||||
;
|
;
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
} named_colors;
|
} named_colors;
|
||||||
|
|
||||||
|
@ -235,97 +232,80 @@ struct clip_opacity
|
||||||
{
|
{
|
||||||
static double call(double val)
|
static double call(double val)
|
||||||
{
|
{
|
||||||
if (val > 1.0) return 1.0;
|
if (val > 1.0)
|
||||||
if (val < 0.0) return 0.0;
|
return 1.0;
|
||||||
|
if (val < 0.0)
|
||||||
|
return 0.0;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct percent_converter
|
struct percent_converter
|
||||||
{
|
{
|
||||||
static std::uint8_t call(double val)
|
static std::uint8_t call(double val) { return safe_cast<std::uint8_t>(std::lround((255.0 * val) / 100.0)); }
|
||||||
{
|
|
||||||
return safe_cast<std::uint8_t>(std::lround((255.0 * val)/100.0));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto dec_red = [](auto& ctx)
|
auto dec_red = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).red_ = _attr(ctx);
|
_val(ctx).red_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto dec_green = [](auto& ctx)
|
auto dec_green = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).green_ = _attr(ctx);
|
_val(ctx).green_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto dec_blue = [](auto& ctx)
|
auto dec_blue = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).blue_ = _attr(ctx);
|
_val(ctx).blue_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto opacity = [](auto& ctx)
|
auto opacity = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).alpha_ = uint8_t((255.0 * clip_opacity::call(_attr(ctx))) + 0.5);
|
_val(ctx).alpha_ = uint8_t((255.0 * clip_opacity::call(_attr(ctx))) + 0.5);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto percent_red = [] (auto & ctx)
|
auto percent_red = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).red_ = percent_converter::call(_attr(ctx));
|
_val(ctx).red_ = percent_converter::call(_attr(ctx));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto percent_green = [] (auto & ctx)
|
auto percent_green = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).green_ = percent_converter::call(_attr(ctx));
|
_val(ctx).green_ = percent_converter::call(_attr(ctx));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto percent_blue = [] (auto & ctx)
|
auto percent_blue = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).blue_ = percent_converter::call(_attr(ctx));
|
_val(ctx).blue_ = percent_converter::call(_attr(ctx));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex1_red = [](auto& ctx)
|
auto hex1_red = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).red_ = _attr(ctx) | _attr(ctx) << 4;
|
_val(ctx).red_ = _attr(ctx) | _attr(ctx) << 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex1_green = [](auto& ctx)
|
auto hex1_green = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).green_ = _attr(ctx) | _attr(ctx) << 4;
|
_val(ctx).green_ = _attr(ctx) | _attr(ctx) << 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex1_blue = [](auto& ctx)
|
auto hex1_blue = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).blue_ = _attr(ctx) | _attr(ctx) << 4;
|
_val(ctx).blue_ = _attr(ctx) | _attr(ctx) << 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex1_opacity = [](auto& ctx)
|
auto hex1_opacity = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4;
|
_val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex2_red = [](auto& ctx)
|
auto hex2_red = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).red_ = _attr(ctx);
|
_val(ctx).red_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex2_green = [](auto& ctx)
|
auto hex2_green = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).green_ = _attr(ctx);
|
_val(ctx).green_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex2_blue = [](auto& ctx)
|
auto hex2_blue = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).blue_ = _attr(ctx);
|
_val(ctx).blue_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex2_opacity = [](auto& ctx)
|
auto hex2_opacity = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).alpha_ = _attr(ctx);
|
_val(ctx).alpha_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hsl_to_rgba = [] (auto& ctx)
|
auto hsl_to_rgba = [](auto& ctx) {
|
||||||
{
|
|
||||||
double h = std::get<0>(_attr(ctx));
|
double h = std::get<0>(_attr(ctx));
|
||||||
double s = std::get<1>(_attr(ctx));
|
double s = std::get<1>(_attr(ctx));
|
||||||
double l = std::get<2>(_attr(ctx));
|
double l = std::get<2>(_attr(ctx));
|
||||||
|
@ -341,20 +321,20 @@ auto hsl_to_rgba = [] (auto& ctx)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m2 = l + s - l*s;
|
m2 = l + s - l * s;
|
||||||
}
|
}
|
||||||
m1 = l * 2 - m2;
|
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 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);
|
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)),
|
_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 * g)),
|
||||||
safe_cast<uint8_t>(std::lround(255.0 * b)),
|
safe_cast<uint8_t>(std::lround(255.0 * b)),
|
||||||
alpha);
|
alpha);
|
||||||
};
|
};
|
||||||
|
// clang-format off
|
||||||
auto const hex2_color_def = no_skip[lit('#')
|
auto const hex2_color_def = no_skip[lit('#')
|
||||||
>> hex2[hex2_red]
|
>> hex2[hex2_red]
|
||||||
>> hex2[hex2_green]
|
>> hex2[hex2_green]
|
||||||
|
@ -429,21 +409,13 @@ auto const css_color_def =
|
||||||
|
|
|
|
||||||
hsla_color
|
hsla_color
|
||||||
;
|
;
|
||||||
|
// clang-format on
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/warning_ignore.hpp>
|
#include <mapnik/warning_ignore.hpp>
|
||||||
BOOST_SPIRIT_DEFINE(
|
BOOST_SPIRIT_DEFINE(css_color, hex2_color, hex1_color, rgb_color, rgba_color, rgb_color_percent, rgba_color_percent);
|
||||||
css_color,
|
|
||||||
hex2_color,
|
|
||||||
hex1_color,
|
|
||||||
rgb_color,
|
|
||||||
rgba_color,
|
|
||||||
rgb_color_percent,
|
|
||||||
rgba_color_percent
|
|
||||||
);
|
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
} // ns
|
} // namespace css_color_grammar
|
||||||
} //ns mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif //MAPNIK_CSS_COLOR_GRAMMAR_X3_DEF_HPP
|
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* This file is part of Mapnik (c++ mapping toolkit)
|
* This file is part of Mapnik (c++ mapping toolkit)
|
||||||
*
|
*
|
||||||
|
@ -31,8 +31,7 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/spirit/home/x3.hpp>
|
#include <boost/spirit/home/x3.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
using property_value_type = boost::iterator_range<char const*>;
|
using property_value_type = boost::iterator_range<char const*>;
|
||||||
using css_key_value = std::pair<std::string, property_value_type>;
|
using css_key_value = std::pair<std::string, property_value_type>;
|
||||||
using definition_type = std::vector<css_key_value>;
|
using definition_type = std::vector<css_key_value>;
|
||||||
|
@ -40,8 +39,7 @@ using css_data = std::unordered_multimap<std::string, definition_type>;
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
|
|
||||||
namespace css_grammar
|
namespace css_grammar {
|
||||||
{
|
|
||||||
|
|
||||||
class css_tag;
|
class css_tag;
|
||||||
class ident_tag;
|
class ident_tag;
|
||||||
|
@ -58,17 +56,14 @@ css_grammar_type const css_grammar{"css"};
|
||||||
css_skipper_type const css_skipper{"css skipper"};
|
css_skipper_type const css_skipper{"css skipper"};
|
||||||
css_classes_type const css_classes{"css classes"};
|
css_classes_type const css_classes{"css classes"};
|
||||||
|
|
||||||
BOOST_SPIRIT_DECLARE(ident_grammar_type,
|
BOOST_SPIRIT_DECLARE(ident_grammar_type, css_classes_type, css_grammar_type, css_skipper_type);
|
||||||
css_classes_type,
|
|
||||||
css_grammar_type,
|
|
||||||
css_skipper_type);
|
|
||||||
|
|
||||||
}
|
} // namespace css_grammar
|
||||||
|
|
||||||
css_grammar::ident_grammar_type const ident_grammar();
|
css_grammar::ident_grammar_type const ident_grammar();
|
||||||
css_grammar::css_classes_type const classes();
|
css_grammar::css_classes_type const classes();
|
||||||
css_grammar::css_grammar_type const grammar();
|
css_grammar::css_grammar_type const grammar();
|
||||||
css_grammar::css_skipper_type const skipper();
|
css_grammar::css_skipper_type const skipper();
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CSS_GRAMMAR_X3_HPP
|
#endif // MAPNIK_CSS_GRAMMAR_X3_HPP
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
#ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||||
#define MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
#define MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
||||||
|
@ -33,9 +32,10 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/fusion/adapted/std_pair.hpp>
|
#include <boost/fusion/adapted/std_pair.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing conventions, only the CSS1 syntax). The format of the productions is optimized for human consumption and some shorthand notation beyond yacc [15] is used:
|
The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing
|
||||||
|
conventions, only the CSS1 syntax). The format of the productions is optimized for human consumption and some shorthand
|
||||||
|
notation beyond yacc [15] is used:
|
||||||
|
|
||||||
* : 0 or more
|
* : 0 or more
|
||||||
+ : 1 or more
|
+ : 1 or more
|
||||||
|
@ -148,46 +148,48 @@ namespace x3 = boost::spirit::x3;
|
||||||
|
|
||||||
namespace css_grammar {
|
namespace css_grammar {
|
||||||
|
|
||||||
using x3::lit;
|
using x3::alnum;
|
||||||
|
using x3::alpha;
|
||||||
using x3::attr;
|
using x3::attr;
|
||||||
|
using x3::char_;
|
||||||
|
using x3::lexeme;
|
||||||
|
using x3::lit;
|
||||||
using x3::no_case;
|
using x3::no_case;
|
||||||
using x3::no_skip;
|
using x3::no_skip;
|
||||||
using x3::lexeme;
|
|
||||||
using x3::alpha;
|
|
||||||
using x3::alnum;
|
|
||||||
using x3::char_;
|
|
||||||
using x3::raw;
|
using x3::raw;
|
||||||
using x3::standard::space;
|
using x3::standard::space;
|
||||||
|
|
||||||
// import unicode string rule
|
// import unicode string rule
|
||||||
namespace { auto const& css_string = mapnik::json::grammar::unicode_string; }
|
namespace {
|
||||||
|
auto const& css_string = mapnik::json::grammar::unicode_string;
|
||||||
|
}
|
||||||
|
|
||||||
auto assign_def = [] (auto const& ctx)
|
auto assign_def = [](auto const& ctx) {
|
||||||
{
|
|
||||||
for (auto const& k : std::get<0>(_attr(ctx)))
|
for (auto const& k : std::get<0>(_attr(ctx)))
|
||||||
{
|
{
|
||||||
_val(ctx).emplace(k, std::get<1>(_attr(ctx)));
|
_val(ctx).emplace(k, std::get<1>(_attr(ctx)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto assign_key = [] (auto const& ctx)
|
auto assign_key = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).first = std::move(_attr(ctx));
|
_val(ctx).first = std::move(_attr(ctx));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto assign_value = [] (auto const& ctx) {_val(ctx).second = std::move(_attr(ctx));};
|
auto assign_value = [](auto const& ctx) {
|
||||||
|
_val(ctx).second = std::move(_attr(ctx));
|
||||||
|
};
|
||||||
|
|
||||||
// rules
|
// rules
|
||||||
x3::rule<class simple_selector_tag, std::string> const simple_selector {"Simple selector"};
|
x3::rule<class simple_selector_tag, std::string> const simple_selector{"Simple selector"};
|
||||||
x3::rule<class selector_tag, std::vector<std::string>> const selector {"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 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 key_value_tag, css_key_value> const key_value{"CSS Key/Value"};
|
||||||
x3::rule<class definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition {"CSS Definition"};
|
x3::rule<class definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition{"CSS Definition"};
|
||||||
|
|
||||||
auto const ident_def = alpha >> *(alnum | char_('-'));
|
auto const ident_def = alpha >> *(alnum | char_('-'));
|
||||||
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)]
|
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)] |
|
||||||
| lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)]
|
lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)] |
|
||||||
| lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
|
lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
|
||||||
|
|
||||||
auto const selector_def = simple_selector % lit(',');
|
auto const selector_def = simple_selector % lit(',');
|
||||||
auto const value_def = raw[lexeme[+~char_(";}")]];
|
auto const value_def = raw[lexeme[+~char_(";}")]];
|
||||||
|
@ -202,8 +204,7 @@ auto const css_classes_def = +lexeme[ident];
|
||||||
#include <mapnik/warning.hpp>
|
#include <mapnik/warning.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/warning_ignore.hpp>
|
#include <mapnik/warning_ignore.hpp>
|
||||||
BOOST_SPIRIT_DEFINE(
|
BOOST_SPIRIT_DEFINE(ident,
|
||||||
ident,
|
|
||||||
css_classes,
|
css_classes,
|
||||||
simple_selector,
|
simple_selector,
|
||||||
selector,
|
selector,
|
||||||
|
@ -211,12 +212,11 @@ BOOST_SPIRIT_DEFINE(
|
||||||
key_value,
|
key_value,
|
||||||
definition,
|
definition,
|
||||||
css_grammar,
|
css_grammar,
|
||||||
css_skipper
|
css_skipper);
|
||||||
);
|
|
||||||
|
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
} //css_grammar
|
} // namespace css_grammar
|
||||||
} //mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif //MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_CSS_UNIT_VALUE_HPP
|
#ifndef MAPNIK_CSS_UNIT_VALUE_HPP
|
||||||
#define MAPNIK_CSS_UNIT_VALUE_HPP
|
#define MAPNIK_CSS_UNIT_VALUE_HPP
|
||||||
|
|
||||||
|
@ -36,13 +35,13 @@ struct css_unit_value : x3::symbols<double>
|
||||||
constexpr static double DPI = 96;
|
constexpr static double DPI = 96;
|
||||||
css_unit_value()
|
css_unit_value()
|
||||||
{
|
{
|
||||||
add
|
add //
|
||||||
("px", 1.0) // pixels
|
("px", 1.0) // pixels
|
||||||
("pt", DPI/72.0) // points
|
("pt", DPI / 72.0) // points
|
||||||
("pc", DPI/6.0) // picas
|
("pc", DPI / 6.0) // picas
|
||||||
("mm", DPI/25.4) // milimeters
|
("mm", DPI / 25.4) // milimeters
|
||||||
("Q" , DPI/101.6)// quarter-milimeters
|
("Q", DPI / 101.6) // quarter-milimeters
|
||||||
("cm", DPI/2.54) // centimeters
|
("cm", DPI / 2.54) // centimeters
|
||||||
("in", static_cast<double>(DPI)) // inches
|
("in", static_cast<double>(DPI)) // inches
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -53,14 +52,14 @@ struct css_absolute_size : x3::symbols<double>
|
||||||
constexpr static double EM = 10.0; // 1em == 10px
|
constexpr static double EM = 10.0; // 1em == 10px
|
||||||
css_absolute_size()
|
css_absolute_size()
|
||||||
{
|
{
|
||||||
add
|
add //
|
||||||
("xx-small", 0.6 * EM)
|
("xx-small", 0.6 * EM) //
|
||||||
("x-small", 0.75 * EM)
|
("x-small", 0.75 * EM) //
|
||||||
("small", 0.88 * EM)
|
("small", 0.88 * EM) //
|
||||||
("medium", 1.0 * EM)
|
("medium", 1.0 * EM) //
|
||||||
("large", 1.2 * EM)
|
("large", 1.2 * EM) //
|
||||||
("x-large", 1.5 * EM)
|
("x-large", 1.5 * EM) //
|
||||||
("xx-large", 2.0 * EM)
|
("xx-large", 2.0 * EM) //
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -69,13 +68,12 @@ struct css_relative_size : x3::symbols<double>
|
||||||
{
|
{
|
||||||
css_relative_size()
|
css_relative_size()
|
||||||
{
|
{
|
||||||
add
|
add //
|
||||||
("larger", 1.2)
|
("larger", 1.2) //
|
||||||
("smaller", 0.8)
|
("smaller", 0.8);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} //mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif //MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
|
@ -35,9 +35,8 @@ struct csv_white_space_skipper : x3::parser<csv_white_space_skipper>
|
||||||
using attribute_type = x3::unused_type;
|
using attribute_type = x3::unused_type;
|
||||||
static bool const has_attribute = false;
|
static bool const has_attribute = false;
|
||||||
|
|
||||||
template <typename Iterator, typename Context, typename Attribute>
|
template<typename Iterator, typename Context, typename Attribute>
|
||||||
bool parse(Iterator& first, Iterator const& last,
|
bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
|
||||||
Context const& context, x3::unused_type, Attribute& ) const
|
|
||||||
{
|
{
|
||||||
x3::skip_over(first, last, context);
|
x3::skip_over(first, last, context);
|
||||||
if (first != last && *first == ' ')
|
if (first != last && *first == ' ')
|
||||||
|
@ -64,6 +63,7 @@ csv_line_grammar_type const line = "csv-line";
|
||||||
|
|
||||||
BOOST_SPIRIT_DECLARE(csv_line_grammar_type);
|
BOOST_SPIRIT_DECLARE(csv_line_grammar_type);
|
||||||
|
|
||||||
}}
|
} // namespace grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CSV_GRAMMAR_X3_HPP
|
#endif // MAPNIK_CSV_GRAMMAR_X3_HPP
|
||||||
|
|
|
@ -29,45 +29,44 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/csv/csv_grammar_x3.hpp>
|
#include <mapnik/csv/csv_grammar_x3.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
|
namespace mapnik {
|
||||||
namespace mapnik { namespace grammar {
|
namespace grammar {
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
namespace standard = boost::spirit::x3::standard;
|
namespace standard = boost::spirit::x3::standard;
|
||||||
|
|
||||||
using x3::lit;
|
|
||||||
using x3::lexeme;
|
|
||||||
using standard::char_;
|
using standard::char_;
|
||||||
|
using x3::lexeme;
|
||||||
|
using x3::lit;
|
||||||
|
|
||||||
struct unesc_char_ : x3::symbols<char>
|
struct unesc_char_ : x3::symbols<char>
|
||||||
{
|
{
|
||||||
unesc_char_()
|
unesc_char_()
|
||||||
{
|
{
|
||||||
add("\\a", '\a')
|
add("\\a", '\a') //
|
||||||
("\\b", '\b')
|
("\\b", '\b') //
|
||||||
("\\f", '\f')
|
("\\f", '\f') //
|
||||||
("\\n", '\n')
|
("\\n", '\n') //
|
||||||
("\\r", '\r')
|
("\\r", '\r') //
|
||||||
("\\t", '\t')
|
("\\t", '\t') //
|
||||||
("\\v", '\v')
|
("\\v", '\v') //
|
||||||
("\\\\",'\\')
|
("\\\\", '\\') //
|
||||||
("\\\'", '\'')
|
("\\\'", '\'') //
|
||||||
("\\\"", '\"')
|
("\\\"", '\"') //
|
||||||
("\"\"", '\"') // double quote
|
("\"\"", '\"') // double quote
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} unesc_char;
|
} unesc_char;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct literal : x3::parser<literal<T>>
|
struct literal : x3::parser<literal<T>>
|
||||||
{
|
{
|
||||||
using attribute_type = x3::unused_type;
|
using attribute_type = x3::unused_type;
|
||||||
using context_tag = T;
|
using context_tag = T;
|
||||||
static bool const has_attribute = false;
|
static bool const has_attribute = false;
|
||||||
|
|
||||||
template <typename Iterator, typename Context, typename Attribute>
|
template<typename Iterator, typename Context, typename Attribute>
|
||||||
bool parse(Iterator& first, Iterator const& last,
|
bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
|
||||||
Context const& context, x3::unused_type, Attribute& ) const
|
|
||||||
{
|
{
|
||||||
x3::skip_over(first, last, context);
|
x3::skip_over(first, last, context);
|
||||||
if (first != last && *first == x3::get<context_tag>(context))
|
if (first != last && *first == x3::get<context_tag>(context))
|
||||||
|
@ -87,27 +86,18 @@ x3::rule<class csv_column, csv_value> const column("csv-column");
|
||||||
x3::rule<class csv_text, csv_value> const text("csv-text");
|
x3::rule<class csv_text, csv_value> const text("csv-text");
|
||||||
x3::rule<class csc_quoted_text, csv_value> const quoted_text("csv-quoted-text");
|
x3::rule<class csc_quoted_text, csv_value> const quoted_text("csv-quoted-text");
|
||||||
|
|
||||||
auto const line_def = -lit('\r') > -lit('\n') > lexeme[column] % separator
|
auto const line_def = -lit('\r') > -lit('\n') > lexeme[column] % separator;
|
||||||
;
|
|
||||||
|
|
||||||
auto const column_def = quoted_text | *(char_ - separator)
|
auto const column_def = quoted_text | *(char_ - separator);
|
||||||
;
|
|
||||||
|
|
||||||
auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??)
|
auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??)
|
||||||
;
|
;
|
||||||
|
|
||||||
auto const text_def = *(unesc_char | (char_ - quote))
|
auto const text_def = *(unesc_char | (char_ - quote));
|
||||||
;
|
|
||||||
|
|
||||||
BOOST_SPIRIT_DEFINE (
|
BOOST_SPIRIT_DEFINE(line, column, quoted_text, text);
|
||||||
line,
|
|
||||||
column,
|
|
||||||
quoted_text,
|
|
||||||
text
|
|
||||||
);
|
|
||||||
|
|
||||||
} // grammar
|
} // namespace grammar
|
||||||
} // namespace mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_CSV_GRAMMAR_X3_DEF_HPP
|
#endif // MAPNIK_CSV_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
|
@ -32,6 +32,6 @@ using csv_value = std::string;
|
||||||
using csv_line = std::vector<csv_value>;
|
using csv_line = std::vector<csv_value>;
|
||||||
using csv_data = std::vector<csv_line>;
|
using csv_data = std::vector<csv_line>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CSV_TYPES_HPP
|
#endif // MAPNIK_CSV_TYPES_HPP
|
||||||
|
|
|
@ -28,13 +28,13 @@
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
namespace detail {
|
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;
|
using conditional_t = typename std::conditional<B, T, F>::type;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using decay_t = typename std::decay<T>::type;
|
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;
|
using enable_if_t = typename std::enable_if<B, T>::type;
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
|
@ -43,31 +43,27 @@ namespace mapnik {
|
||||||
|
|
||||||
class MAPNIK_DECL datasource_exception : public std::exception
|
class MAPNIK_DECL datasource_exception : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
datasource_exception(std::string const& message)
|
datasource_exception(std::string const& message)
|
||||||
: message_(message)
|
: message_(message)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~datasource_exception() {}
|
~datasource_exception() {}
|
||||||
|
|
||||||
virtual const char* what() const noexcept
|
virtual const char* what() const noexcept { return message_.c_str(); }
|
||||||
{
|
|
||||||
return message_.c_str();
|
private:
|
||||||
}
|
|
||||||
private:
|
|
||||||
std::string message_;
|
std::string message_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MAPNIK_DECL datasource : private util::noncopyable
|
class MAPNIK_DECL datasource : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum datasource_t : std::uint8_t {
|
enum datasource_t : std::uint8_t { Vector, Raster };
|
||||||
Vector,
|
|
||||||
Raster
|
|
||||||
};
|
|
||||||
|
|
||||||
datasource (parameters const& _params)
|
datasource(parameters const& _params)
|
||||||
: params_(_params) {}
|
: params_(_params)
|
||||||
|
{}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Get the configuration parameters of the data source.
|
* @brief Get the configuration parameters of the data source.
|
||||||
|
@ -76,25 +72,13 @@ public:
|
||||||
*
|
*
|
||||||
* @return The configuration parameters of the data source.
|
* @return The configuration parameters of the data source.
|
||||||
*/
|
*/
|
||||||
parameters const& params() const
|
parameters const& params() const { return params_; }
|
||||||
{
|
|
||||||
return params_;
|
|
||||||
}
|
|
||||||
|
|
||||||
parameters & params()
|
parameters& params() { return params_; }
|
||||||
{
|
|
||||||
return params_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(datasource const& rhs) const
|
bool operator==(datasource const& rhs) const { return params_ == rhs.params(); }
|
||||||
{
|
|
||||||
return params_ == rhs.params();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(datasource const& rhs) const
|
bool operator!=(datasource const& rhs) const { return !(*this == rhs); }
|
||||||
{
|
|
||||||
return !(*this == rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Get the type of the datasource
|
* @brief Get the type of the datasource
|
||||||
|
@ -113,43 +97,32 @@ public:
|
||||||
virtual box2d<double> envelope() const = 0;
|
virtual box2d<double> envelope() const = 0;
|
||||||
virtual layer_descriptor get_descriptor() const = 0;
|
virtual layer_descriptor get_descriptor() const = 0;
|
||||||
virtual ~datasource() {}
|
virtual ~datasource() {}
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
parameters params_;
|
parameters params_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using datasource_name = const char* (*)();
|
using datasource_name = const char* (*)();
|
||||||
using create_ds = datasource* (*) (parameters const&);
|
using create_ds = datasource* (*)(parameters const&);
|
||||||
using destroy_ds = void (*) (datasource *);
|
using destroy_ds = void (*)(datasource*);
|
||||||
|
|
||||||
class datasource_deleter
|
class datasource_deleter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void operator() (datasource* ds)
|
void operator()(datasource* ds) { delete ds; }
|
||||||
{
|
|
||||||
delete ds;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using datasource_ptr = std::shared_ptr<datasource>;
|
using datasource_ptr = std::shared_ptr<datasource>;
|
||||||
|
|
||||||
#ifdef MAPNIK_STATIC_PLUGINS
|
#ifdef MAPNIK_STATIC_PLUGINS
|
||||||
#define DATASOURCE_PLUGIN(classname)
|
#define DATASOURCE_PLUGIN(classname)
|
||||||
#else
|
#else
|
||||||
#define DATASOURCE_PLUGIN(classname) \
|
#define DATASOURCE_PLUGIN(classname) \
|
||||||
extern "C" MAPNIK_EXP const char * datasource_name() \
|
extern "C" MAPNIK_EXP const char* datasource_name() { return classname::name(); } \
|
||||||
{ \
|
extern "C" MAPNIK_EXP datasource* create(parameters const& params) { return new classname(params); } \
|
||||||
return classname::name(); \
|
extern "C" MAPNIK_EXP void destroy(datasource* ds) { delete ds; }
|
||||||
} \
|
|
||||||
extern "C" MAPNIK_EXP datasource* create(parameters const& params) \
|
|
||||||
{ \
|
|
||||||
return new classname(params); \
|
|
||||||
} \
|
|
||||||
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
|
|
||||||
{ \
|
|
||||||
delete ds; \
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_DATASOURCE_HPP
|
#endif // MAPNIK_DATASOURCE_HPP
|
||||||
|
|
|
@ -41,21 +41,22 @@ class datasource;
|
||||||
class parameters;
|
class parameters;
|
||||||
class PluginInfo;
|
class PluginInfo;
|
||||||
|
|
||||||
class MAPNIK_DECL datasource_cache
|
class MAPNIK_DECL datasource_cache : public singleton<datasource_cache, CreateStatic>,
|
||||||
: public singleton<datasource_cache, CreateStatic>,
|
|
||||||
private util::noncopyable
|
private util::noncopyable
|
||||||
{
|
{
|
||||||
friend class CreateStatic<datasource_cache>;
|
friend class CreateStatic<datasource_cache>;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
std::vector<std::string> plugin_names();
|
std::vector<std::string> plugin_names();
|
||||||
std::string plugin_directories();
|
std::string plugin_directories();
|
||||||
bool register_datasources(std::string const& path, bool recurse = false);
|
bool register_datasources(std::string const& path, bool recurse = false);
|
||||||
bool register_datasource(std::string const& path);
|
bool register_datasource(std::string const& path);
|
||||||
std::shared_ptr<datasource> create(parameters const& params);
|
std::shared_ptr<datasource> create(parameters const& params);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
datasource_cache();
|
datasource_cache();
|
||||||
~datasource_cache();
|
~datasource_cache();
|
||||||
std::map<std::string,std::shared_ptr<PluginInfo> > plugins_;
|
std::map<std::string, std::shared_ptr<PluginInfo>> plugins_;
|
||||||
std::set<std::string> plugin_directories_;
|
std::set<std::string> plugin_directories_;
|
||||||
// the singleton has a mutex protecting the instance pointer,
|
// the singleton has a mutex protecting the instance pointer,
|
||||||
// but the instance also needs its own mutex to protect the
|
// 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>;
|
extern template class MAPNIK_DECL singleton<datasource_cache, CreateStatic>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_DATASOURCE_CACHE_HPP
|
#endif // MAPNIK_DATASOURCE_CACHE_HPP
|
||||||
|
|
|
@ -27,15 +27,8 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
enum datasource_geometry_t : std::uint8_t {
|
enum datasource_geometry_t : std::uint8_t { Unknown = 0, Point = 1, LineString = 2, Polygon = 3, Collection = 4 };
|
||||||
Unknown = 0,
|
|
||||||
Point = 1,
|
|
||||||
LineString = 2,
|
|
||||||
Polygon = 3,
|
|
||||||
Collection = 4
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP
|
#endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP
|
||||||
|
|
|
@ -42,35 +42,21 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
|
|
||||||
// Global logger class that holds the configuration of severity, format
|
// Global logger class that holds the configuration of severity, format
|
||||||
// and file/console redirection.
|
// and file/console redirection.
|
||||||
|
|
||||||
class MAPNIK_DECL logger :
|
class MAPNIK_DECL logger : public singleton<logger, CreateStatic>,
|
||||||
public singleton<logger,CreateStatic>,
|
|
||||||
private util::noncopyable
|
private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum severity_type
|
enum severity_type { debug = 0, warn = 1, error = 2, none = 3 };
|
||||||
{
|
|
||||||
debug = 0,
|
|
||||||
warn = 1,
|
|
||||||
error = 2,
|
|
||||||
none = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
using severity_map = std::unordered_map<std::string, severity_type>;
|
using severity_map = std::unordered_map<std::string, severity_type>;
|
||||||
|
|
||||||
// global security level
|
// global security level
|
||||||
static severity_type get_severity()
|
static severity_type get_severity() { return severity_level_; }
|
||||||
{
|
|
||||||
return severity_level_;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_severity(severity_type severity_level)
|
static void set_severity(severity_type severity_level) { severity_level_ = severity_level; }
|
||||||
{
|
|
||||||
severity_level_ = severity_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
// per object security levels
|
// per object security levels
|
||||||
static severity_type get_object_severity(std::string const& object_name)
|
static severity_type get_object_severity(std::string const& object_name)
|
||||||
|
@ -89,8 +75,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_object_severity(std::string const& object_name,
|
static void set_object_severity(std::string const& object_name, severity_type const& security_level)
|
||||||
severity_type const& security_level)
|
|
||||||
{
|
{
|
||||||
if (!object_name.empty())
|
if (!object_name.empty())
|
||||||
{
|
{
|
||||||
|
@ -111,10 +96,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// format
|
// format
|
||||||
static std::string const& get_format()
|
static std::string const& get_format() { return format_; }
|
||||||
{
|
|
||||||
return format_;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_format(std::string const& format)
|
static void set_format(std::string const& format)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +113,7 @@ public:
|
||||||
static void use_file(std::string const& filepath);
|
static void use_file(std::string const& filepath);
|
||||||
static void use_console();
|
static void use_console();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static severity_map object_severity_level_;
|
static severity_map object_severity_level_;
|
||||||
static std::string format_;
|
static std::string format_;
|
||||||
static std::ofstream file_output_;
|
static std::ofstream file_output_;
|
||||||
|
@ -151,7 +133,6 @@ private:
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
// Default sink, it regulates access to clog
|
// Default sink, it regulates access to clog
|
||||||
|
@ -159,7 +140,7 @@ namespace detail {
|
||||||
template<class Ch, class Tr, class A>
|
template<class Ch, class Tr, class A>
|
||||||
class clog_sink
|
class clog_sink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using stream_buffer = std::basic_ostringstream<Ch, Tr, A>;
|
using stream_buffer = std::basic_ostringstream<Ch, Tr, A>;
|
||||||
|
|
||||||
void operator()(logger::severity_type const& /*severity*/, stream_buffer const& s)
|
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
|
// This is used for debug/warn reporting that should not output
|
||||||
// anything when not compiling for speed.
|
// 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,
|
logger::severity_type Severity,
|
||||||
class Ch = char,
|
class Ch = char,
|
||||||
class Tr = std::char_traits<Ch>,
|
class Tr = std::char_traits<Ch>,
|
||||||
class A = std::allocator<Ch> >
|
class A = std::allocator<Ch>>
|
||||||
class base_log : public util::noncopyable
|
class base_log : public util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using output_policy = OutputPolicy<Ch, Tr, A>;
|
using output_policy = OutputPolicy<Ch, Tr, A>;
|
||||||
|
|
||||||
base_log() {}
|
base_log() {}
|
||||||
|
@ -198,9 +179,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
base_log(const char* /*object_name*/)
|
base_log(const char* /*object_name*/) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
~base_log()
|
~base_log()
|
||||||
|
@ -215,45 +194,38 @@ public:
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
#ifdef MAPNIK_LOG
|
#ifdef MAPNIK_LOG
|
||||||
base_log &operator<<(T const& x)
|
base_log& operator<<(T const& x)
|
||||||
{
|
{
|
||||||
|
|
||||||
streambuf_ << x;
|
streambuf_ << x;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
base_log &operator<<(T const& /*x*/)
|
base_log& operator<<(T const& /*x*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef MAPNIK_LOG
|
#ifdef MAPNIK_LOG
|
||||||
inline bool check_severity()
|
inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
|
||||||
{
|
|
||||||
return Severity >= logger::get_object_severity(object_name_);
|
|
||||||
}
|
|
||||||
|
|
||||||
typename output_policy::stream_buffer streambuf_;
|
typename output_policy::stream_buffer streambuf_;
|
||||||
std::string object_name_;
|
std::string object_name_;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Base log class that always log, regardless of MAPNIK_LOG.
|
||||||
|
// This is used for error reporting that should always log something
|
||||||
|
|
||||||
|
template<template<class Ch, class Tr, class A> class OutputPolicy,
|
||||||
//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,
|
|
||||||
logger::severity_type Severity,
|
logger::severity_type Severity,
|
||||||
class Ch = char,
|
class Ch = char,
|
||||||
class Tr = std::char_traits<Ch>,
|
class Tr = std::char_traits<Ch>,
|
||||||
class A = std::allocator<Ch> >
|
class A = std::allocator<Ch>>
|
||||||
class base_log_always : public util::noncopyable
|
class base_log_always : public util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using output_policy = OutputPolicy<Ch, Tr, A>;
|
using output_policy = OutputPolicy<Ch, Tr, A>;
|
||||||
|
|
||||||
base_log_always() {}
|
base_log_always() {}
|
||||||
|
@ -275,56 +247,63 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
base_log_always &operator<<(T const& x)
|
base_log_always& operator<<(T const& x)
|
||||||
{
|
{
|
||||||
streambuf_ << x;
|
streambuf_ << x;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline bool check_severity()
|
inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
|
||||||
{
|
|
||||||
return Severity >= logger::get_object_severity(object_name_);
|
|
||||||
}
|
|
||||||
|
|
||||||
typename output_policy::stream_buffer streambuf_;
|
typename output_policy::stream_buffer streambuf_;
|
||||||
std::string object_name_;
|
std::string object_name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using base_log_debug = base_log<clog_sink, logger::debug>;
|
using base_log_debug = base_log<clog_sink, logger::debug>;
|
||||||
using base_log_warn = base_log<clog_sink, logger::warn>;
|
using base_log_warn = base_log<clog_sink, logger::warn>;
|
||||||
using base_log_error = base_log_always<clog_sink, logger::error>;
|
using base_log_error = base_log_always<clog_sink, logger::error>;
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
|
||||||
// real interfaces
|
// real interfaces
|
||||||
class MAPNIK_DECL warn : public detail::base_log_warn
|
class MAPNIK_DECL warn : public detail::base_log_warn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
warn() : detail::base_log_warn() {}
|
warn()
|
||||||
warn(const char* object_name) : detail::base_log_warn(object_name) {}
|
: detail::base_log_warn()
|
||||||
|
{}
|
||||||
|
warn(const char* object_name)
|
||||||
|
: detail::base_log_warn(object_name)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MAPNIK_DECL debug : public detail::base_log_debug
|
class MAPNIK_DECL debug : public detail::base_log_debug
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
debug() : detail::base_log_debug() {}
|
debug()
|
||||||
debug(const char* object_name) : detail::base_log_debug(object_name) {}
|
: detail::base_log_debug()
|
||||||
|
{}
|
||||||
|
debug(const char* object_name)
|
||||||
|
: detail::base_log_debug(object_name)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MAPNIK_DECL error : public detail::base_log_error
|
class MAPNIK_DECL error : public detail::base_log_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
error() : detail::base_log_error() {}
|
error()
|
||||||
error(const char* object_name) : detail::base_log_error(object_name) {}
|
: detail::base_log_error()
|
||||||
|
{}
|
||||||
|
error(const char* object_name)
|
||||||
|
: detail::base_log_error(object_name)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
// logging helpers
|
// logging helpers
|
||||||
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)
|
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)
|
||||||
#define MAPNIK_LOG_WARN(s) mapnik::warn(#s)
|
#define MAPNIK_LOG_WARN(s) mapnik::warn(#s)
|
||||||
#define MAPNIK_LOG_ERROR(s) mapnik::error(#s)
|
#define MAPNIK_LOG_ERROR(s) mapnik::error(#s)
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_DEBUG_HPP
|
#endif // MAPNIK_DEBUG_HPP
|
||||||
|
|
|
@ -38,26 +38,22 @@ namespace mapnik {
|
||||||
|
|
||||||
class illegal_enum_value : public std::exception
|
class illegal_enum_value : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
illegal_enum_value():
|
illegal_enum_value()
|
||||||
what_() {}
|
: what_()
|
||||||
|
{}
|
||||||
|
|
||||||
illegal_enum_value( std::string const& _what ) :
|
illegal_enum_value(std::string const& _what)
|
||||||
what_( _what )
|
: what_(_what)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
virtual ~illegal_enum_value() {}
|
virtual ~illegal_enum_value() {}
|
||||||
|
|
||||||
virtual const char * what() const noexcept
|
virtual const char* what() const noexcept { return what_.c_str(); }
|
||||||
{
|
|
||||||
return what_.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string what_;
|
std::string what_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Slim wrapper for enumerations. It creates a new type from a native enum and
|
/** Slim wrapper for enumerations. It creates a new type from a native enum and
|
||||||
* a char pointer array. It almost exactly behaves like a native enumeration
|
* a char pointer array. It almost exactly behaves like a native enumeration
|
||||||
* type. It supports string conversion through stream operators. This is useful
|
* type. It supports string conversion through stream operators. This is useful
|
||||||
|
@ -137,42 +133,34 @@ protected:
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <typename ENUM, int THE_MAX>
|
template<typename ENUM, int THE_MAX>
|
||||||
class MAPNIK_DECL enumeration {
|
class MAPNIK_DECL enumeration
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
using native_type = ENUM;
|
using native_type = ENUM;
|
||||||
|
|
||||||
enumeration()
|
enumeration()
|
||||||
: value_() {}
|
: value_()
|
||||||
|
{}
|
||||||
|
|
||||||
enumeration( ENUM v )
|
enumeration(ENUM v)
|
||||||
: value_(v) {}
|
: value_(v)
|
||||||
|
{}
|
||||||
|
|
||||||
enumeration( enumeration const& other )
|
enumeration(enumeration const& other)
|
||||||
: value_(other.value_) {}
|
: value_(other.value_)
|
||||||
|
{}
|
||||||
|
|
||||||
/** Assignment operator for native enum values. */
|
/** Assignment operator for native enum values. */
|
||||||
void operator=(ENUM v)
|
void operator=(ENUM v) { value_ = v; }
|
||||||
{
|
|
||||||
value_ = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Assignment operator. */
|
/** Assignment operator. */
|
||||||
void operator=(enumeration const& other)
|
void operator=(enumeration const& other) { value_ = other.value_; }
|
||||||
{
|
|
||||||
value_ = other.value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Conversion operator for native enum values. */
|
/** Conversion operator for native enum values. */
|
||||||
operator ENUM() const
|
operator ENUM() const { return value_; }
|
||||||
{
|
|
||||||
return value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Max
|
enum Max { MAX = THE_MAX };
|
||||||
{
|
|
||||||
MAX = THE_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Converts @p str to an enum.
|
/** Converts @p str to an enum.
|
||||||
* @throw illegal_enum_value @p str is not a legal identifier.
|
* @throw illegal_enum_value @p str is not a legal identifier.
|
||||||
|
@ -190,113 +178,114 @@ public:
|
||||||
}
|
}
|
||||||
for (unsigned i = 0; i < THE_MAX; ++i)
|
for (unsigned i = 0; i < THE_MAX; ++i)
|
||||||
{
|
{
|
||||||
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
MAPNIK_DISABLE_LONG_LONG
|
||||||
MAPNIK_DISABLE_LONG_LONG
|
|
||||||
if (str_copy == our_strings_[i])
|
if (str_copy == our_strings_[i])
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
{
|
{
|
||||||
value_ = static_cast<ENUM>(i);
|
value_ = static_cast<ENUM>(i);
|
||||||
if (deprecated)
|
if (deprecated)
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_ERROR(enumerations) << "enumeration value (" << str << ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy << "' instead";
|
MAPNIK_LOG_ERROR(enumerations)
|
||||||
|
<< "enumeration value (" << str
|
||||||
|
<< ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy
|
||||||
|
<< "' instead";
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||||
MAPNIK_DISABLE_LONG_LONG
|
MAPNIK_DISABLE_LONG_LONG
|
||||||
throw illegal_enum_value(std::string("Illegal enumeration value '") +
|
throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_);
|
||||||
str + "' for enum " + our_name_);
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the current value as a string identifier. */
|
/** Returns the current value as a string identifier. */
|
||||||
std::string as_string() const
|
std::string as_string() const
|
||||||
{
|
{
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||||
MAPNIK_DISABLE_LONG_LONG
|
MAPNIK_DISABLE_LONG_LONG
|
||||||
return our_strings_[value_];
|
return our_strings_[value_];
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Static helper function to iterate over valid identifiers. */
|
/** Static helper function to iterate over valid identifiers. */
|
||||||
static const char * get_string(unsigned i)
|
static const char* get_string(unsigned i) { return our_strings_[i]; }
|
||||||
{
|
|
||||||
return our_strings_[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Performs some simple checks and quits the application if
|
/** Performs some simple checks and quits the application if
|
||||||
* any error is detected. Tries to print helpful error messages.
|
* any error is detected. Tries to print helpful error messages.
|
||||||
*/
|
*/
|
||||||
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)
|
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 "
|
std::cerr << "### FATAL: Not enough strings for enum " << our_name_ << " defined in file '" << filename
|
||||||
<< our_name_ << " defined in file '" << filename
|
|
||||||
<< "' at line " << line_no;
|
<< "' at line " << line_no;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( std::string("") != our_strings_[THE_MAX])
|
if (std::string("") != our_strings_[THE_MAX])
|
||||||
{
|
{
|
||||||
std::cerr << "### FATAL: The string array for enum " << our_name_
|
std::cerr << "### FATAL: The string array for enum " << our_name_ << " defined in file '" << filename
|
||||||
<< " defined in file '" << filename << "' at line " << line_no
|
<< "' at line " << line_no << " has too many items or is not terminated with an "
|
||||||
<< " has too many items or is not terminated with an "
|
|
||||||
<< "empty string";
|
<< "empty string";
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ENUM value_;
|
ENUM value_;
|
||||||
static const char ** our_strings_ ;
|
static const char** our_strings_;
|
||||||
static std::string our_name_ ;
|
static std::string our_name_;
|
||||||
static bool our_verified_flag_;
|
static bool our_verified_flag_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** ostream operator for enumeration
|
/** ostream operator for enumeration
|
||||||
* @relates mapnik::enumeration
|
* @relates mapnik::enumeration
|
||||||
*/
|
*/
|
||||||
template <class ENUM, int THE_MAX>
|
template<class ENUM, int THE_MAX>
|
||||||
std::ostream &
|
std::ostream& operator<<(std::ostream& os, const mapnik::enumeration<ENUM, THE_MAX>& e)
|
||||||
operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
|
|
||||||
{
|
{
|
||||||
return os << e.as_string();
|
return os << e.as_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of namespace
|
} // namespace mapnik
|
||||||
|
|
||||||
/** Helper macro.
|
/** Helper macro.
|
||||||
* @relates mapnik::enumeration
|
* @relates mapnik::enumeration
|
||||||
*/
|
*/
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define DEFINE_ENUM( name, e) \
|
#define DEFINE_ENUM(name, e) \
|
||||||
template enumeration<e, e ## _MAX>; \
|
template enumeration<e, e##_MAX>; \
|
||||||
using name = enumeration<e, e ## _MAX>;
|
using name = enumeration<e, e##_MAX>;
|
||||||
#else
|
#else
|
||||||
#define DEFINE_ENUM( name, e) \
|
#define DEFINE_ENUM(name, e) \
|
||||||
using name = enumeration<e, e ## _MAX>; \
|
using name = enumeration<e, e##_MAX>; \
|
||||||
template <> MAPNIK_DECL const char ** name ::our_strings_; \
|
template<> \
|
||||||
template <> MAPNIK_DECL std::string name ::our_name_; \
|
MAPNIK_DECL const char** name ::our_strings_; \
|
||||||
template <> MAPNIK_DECL bool name ::our_verified_flag_;
|
template<> \
|
||||||
|
MAPNIK_DECL std::string name ::our_name_; \
|
||||||
|
template<> \
|
||||||
|
MAPNIK_DECL bool name ::our_verified_flag_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Helper macro. Runs the verify_mapnik_enum() method during static initialization.
|
/** Helper macro. Runs the verify_mapnik_enum() method during static initialization.
|
||||||
* @relates mapnik::enumeration
|
* @relates mapnik::enumeration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define IMPLEMENT_ENUM( name, strings ) \
|
#define IMPLEMENT_ENUM(name, strings) \
|
||||||
template <> MAPNIK_DECL const char ** name ::our_strings_ = strings; \
|
template<> \
|
||||||
template <> MAPNIK_DECL std::string name ::our_name_ = #name; \
|
MAPNIK_DECL const char** name ::our_strings_ = strings; \
|
||||||
template <> MAPNIK_DECL bool name ::our_verified_flag_( name ::verify_mapnik_enum(__FILE__, __LINE__));
|
template<> \
|
||||||
|
MAPNIK_DECL std::string name ::our_name_ = #name; \
|
||||||
|
template<> \
|
||||||
|
MAPNIK_DECL bool name ::our_verified_flag_(name ::verify_mapnik_enum(__FILE__, __LINE__));
|
||||||
|
|
||||||
#endif // MAPNIK_ENUMERATION_HPP
|
#endif // MAPNIK_ENUMERATION_HPP
|
||||||
|
|
|
@ -38,93 +38,91 @@ namespace mapnik {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template <typename T, typename Attributes>
|
template<typename T, typename Attributes>
|
||||||
struct evaluate_expression
|
struct evaluate_expression
|
||||||
{
|
{
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
explicit evaluate_expression(Attributes const& attrs)
|
explicit evaluate_expression(Attributes const& attrs)
|
||||||
: attrs_(attrs) {}
|
: attrs_(attrs)
|
||||||
|
{}
|
||||||
|
|
||||||
value_type operator() (attribute const&) const
|
value_type operator()(attribute const&) const
|
||||||
{
|
{
|
||||||
throw std::runtime_error("can't evaluate feature attributes in this context");
|
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);
|
auto itr = attrs_.find(attr.name);
|
||||||
if (itr != attrs_.end())
|
if (itr != attrs_.end())
|
||||||
{
|
{
|
||||||
return itr->second;
|
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");
|
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())
|
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
|
||||||
&& (util::apply_visitor(*this, x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
value_type operator() (binary_node<tags::logical_or> const & x) const
|
value_type operator()(binary_node<tags::logical_or> const& x) const
|
||||||
{
|
{
|
||||||
return (util::apply_visitor(*this,x.left).to_bool())
|
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||||
|| (util::apply_visitor(*this,x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (binary_node<Tag> const& x) const
|
value_type operator()(binary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type operation;
|
typename make_op<Tag>::type operation;
|
||||||
return operation(util::apply_visitor(*this, x.left),
|
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||||
util::apply_visitor(*this, x.right));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (unary_node<Tag> const& x) const
|
value_type operator()(unary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type func;
|
typename make_op<Tag>::type func;
|
||||||
return func(util::apply_visitor(*this, x.expr));
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type arg = util::apply_visitor(*this, call.arg);
|
||||||
return call.fun(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 arg1 = util::apply_visitor(*this, call.arg1);
|
||||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||||
return call.fun(arg1, arg2);
|
return call.fun(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ValueType>
|
template<typename ValueType>
|
||||||
value_type operator() (ValueType const& val) const
|
value_type operator()(ValueType const& val) const
|
||||||
{
|
{
|
||||||
return value_type(val);
|
return value_type(val);
|
||||||
}
|
}
|
||||||
|
@ -132,87 +130,84 @@ struct evaluate_expression
|
||||||
Attributes const& attrs_;
|
Attributes const& attrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct evaluate_expression<T, boost::none_t>
|
struct evaluate_expression<T, boost::none_t>
|
||||||
{
|
{
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
evaluate_expression(boost::none_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");
|
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");
|
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");
|
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())
|
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
|
||||||
&& (util::apply_visitor(*this, x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
value_type operator() (binary_node<tags::logical_or> const & x) const
|
value_type operator()(binary_node<tags::logical_or> const& x) const
|
||||||
{
|
{
|
||||||
return (util::apply_visitor(*this,x.left).to_bool())
|
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||||
|| (util::apply_visitor(*this,x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (binary_node<Tag> const& x) const
|
value_type operator()(binary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type operation;
|
typename make_op<Tag>::type operation;
|
||||||
return operation(util::apply_visitor(*this, x.left),
|
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||||
util::apply_visitor(*this, x.right));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (unary_node<Tag> const& x) const
|
value_type operator()(unary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type func;
|
typename make_op<Tag>::type func;
|
||||||
return func(util::apply_visitor(*this, x.expr));
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type arg = util::apply_visitor(*this, call.arg);
|
||||||
return call.fun(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 arg1 = util::apply_visitor(*this, call.arg1);
|
||||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||||
return call.fun(arg1, arg2);
|
return call.fun(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ValueType>
|
template<typename ValueType>
|
||||||
value_type operator() (ValueType const& val) const
|
value_type operator()(ValueType const& val) const
|
||||||
{
|
{
|
||||||
return value_type(val);
|
return value_type(val);
|
||||||
}
|
}
|
||||||
|
@ -221,33 +216,39 @@ struct evaluate_expression<T, boost::none_t>
|
||||||
struct assign_value
|
struct assign_value
|
||||||
{
|
{
|
||||||
template<typename Attributes>
|
template<typename Attributes>
|
||||||
static void apply(symbolizer_base::value_type & val, expression_ptr const& expr, Attributes const& attrs, property_types target )
|
static void apply(symbolizer_base::value_type& val,
|
||||||
|
expression_ptr const& expr,
|
||||||
|
Attributes const& attrs,
|
||||||
|
property_types target)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (target)
|
switch (target)
|
||||||
{
|
{
|
||||||
case property_types::target_color:
|
case property_types::target_color: {
|
||||||
{
|
|
||||||
// evaluate expression as a string then parse as css color
|
// evaluate expression as a string then parse as css color
|
||||||
std::string str = util::apply_visitor(mapnik::evaluate_expression<mapnik::value,
|
std::string str =
|
||||||
Attributes>(attrs),*expr).to_string();
|
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_string();
|
||||||
try { val = parse_color(str); }
|
try
|
||||||
catch (...) { val = color(0,0,0);}
|
{
|
||||||
|
val = parse_color(str);
|
||||||
|
} catch (...)
|
||||||
|
{
|
||||||
|
val = color(0, 0, 0);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case property_types::target_double:
|
case property_types::target_double: {
|
||||||
{
|
val =
|
||||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_double();
|
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_double();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case property_types::target_integer:
|
case property_types::target_integer: {
|
||||||
{
|
val =
|
||||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_int();
|
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_int();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case property_types::target_bool:
|
case property_types::target_bool: {
|
||||||
{
|
val =
|
||||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_bool();
|
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_bool();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: // no-op
|
default: // no-op
|
||||||
|
@ -256,55 +257,57 @@ struct assign_value
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
std::tuple<T,bool> pre_evaluate_expression (expression_ptr const& expr)
|
std::tuple<T, bool> pre_evaluate_expression(expression_ptr const& expr)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none),*expr), true);
|
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none), *expr),
|
||||||
}
|
true);
|
||||||
catch (...)
|
} catch (...)
|
||||||
{
|
{
|
||||||
return std::make_tuple(T(),false);
|
return std::make_tuple(T(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct evaluate_global_attributes : util::noncopyable
|
struct evaluate_global_attributes : util::noncopyable
|
||||||
{
|
{
|
||||||
template <typename Attributes>
|
template<typename Attributes>
|
||||||
struct evaluator
|
struct evaluator
|
||||||
{
|
{
|
||||||
evaluator(symbolizer_base::cont_type::value_type & prop, Attributes const& attrs)
|
evaluator(symbolizer_base::cont_type::value_type& prop, Attributes const& attrs)
|
||||||
: prop_(prop),
|
: prop_(prop)
|
||||||
attrs_(attrs) {}
|
, attrs_(attrs)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator() (expression_ptr const& expr) const
|
void operator()(expression_ptr const& expr) const
|
||||||
{
|
{
|
||||||
auto const& meta = get_meta(prop_.first);
|
auto const& meta = get_meta(prop_.first);
|
||||||
assign_value::apply(prop_.second, expr, attrs_, std::get<2>(meta));
|
assign_value::apply(prop_.second, expr, attrs_, std::get<2>(meta));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void operator() (T const&) const
|
void operator()(T const&) const
|
||||||
{
|
{
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
symbolizer_base::cont_type::value_type & prop_;
|
symbolizer_base::cont_type::value_type& prop_;
|
||||||
Attributes const& attrs_;
|
Attributes const& attrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Attributes>
|
template<typename Attributes>
|
||||||
struct extract_symbolizer
|
struct extract_symbolizer
|
||||||
{
|
{
|
||||||
extract_symbolizer(Attributes const& attrs)
|
extract_symbolizer(Attributes const& attrs)
|
||||||
: attrs_(attrs) {}
|
: attrs_(attrs)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename Symbolizer>
|
template<typename Symbolizer>
|
||||||
void operator() (Symbolizer & sym) const
|
void operator()(Symbolizer& sym) const
|
||||||
{
|
{
|
||||||
for (auto & prop : sym.properties)
|
for (auto& prop : sym.properties)
|
||||||
{
|
{
|
||||||
util::apply_visitor(evaluator<Attributes>(prop, attrs_), prop.second);
|
util::apply_visitor(evaluator<Attributes>(prop, attrs_), prop.second);
|
||||||
}
|
}
|
||||||
|
@ -312,14 +315,14 @@ struct evaluate_global_attributes : util::noncopyable
|
||||||
Attributes const& attrs_;
|
Attributes const& attrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Attributes>
|
template<typename Attributes>
|
||||||
static void apply(Map & m, Attributes const& attrs)
|
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);
|
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
|
#endif // MAPNIK_EVALUATE_GLOBAL_ATTRIBUTES_HPP
|
||||||
|
|
|
@ -34,14 +34,13 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
// fwd declare to reduce compile time
|
// fwd declare to reduce compile time
|
||||||
using expression_ptr = std::shared_ptr<expr_node>;
|
using expression_ptr = std::shared_ptr<expr_node>;
|
||||||
using expression_set = std::set<expression_ptr>;
|
using expression_set = std::set<expression_ptr>;
|
||||||
|
|
||||||
MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt);
|
MAPNIK_DECL expression_ptr parse_expression(std::string const& wkt);
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSION_HPP
|
#endif // MAPNIK_EXPRESSION_HPP
|
||||||
|
|
|
@ -31,10 +31,9 @@
|
||||||
#include <mapnik/util/variant.hpp>
|
#include <mapnik/util/variant.hpp>
|
||||||
#include <mapnik/feature.hpp>
|
#include <mapnik/feature.hpp>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
template <typename T0, typename T1, typename T2>
|
template<typename T0, typename T1, typename T2>
|
||||||
struct evaluate
|
struct evaluate
|
||||||
{
|
{
|
||||||
using feature_type = T0;
|
using feature_type = T0;
|
||||||
|
@ -42,105 +41,85 @@ struct evaluate
|
||||||
using variable_type = T2;
|
using variable_type = T2;
|
||||||
using result_type = T1; // we need this because automatic result_type deduction fails
|
using result_type = T1; // we need this because automatic result_type deduction fails
|
||||||
explicit evaluate(feature_type const& f, variable_type const& v)
|
explicit evaluate(feature_type const& f, variable_type const& v)
|
||||||
: feature_(f),
|
: feature_(f)
|
||||||
vars_(v) {}
|
, vars_(v)
|
||||||
|
{}
|
||||||
|
|
||||||
value_type operator() (value_integer val) const
|
value_type operator()(value_integer val) const { return val; }
|
||||||
{
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (value_double val) const
|
value_type operator()(value_double val) const { return val; }
|
||||||
{
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (value_bool val) const
|
value_type operator()(value_bool val) const { return val; }
|
||||||
{
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (value_null val) const
|
value_type operator()(value_null val) const { return val; }
|
||||||
{
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (value_unicode_string const& str) const
|
value_type operator()(value_unicode_string const& str) const { return str; }
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (attribute const& attr) const
|
value_type operator()(attribute const& attr) const { return attr.value<value_type, feature_type>(feature_); }
|
||||||
{
|
|
||||||
return attr.value<value_type,feature_type>(feature_);
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (global_attribute const& attr) const
|
value_type operator()(global_attribute const& attr) const
|
||||||
{
|
{
|
||||||
auto itr = vars_.find(attr.name);
|
auto itr = vars_.find(attr.name);
|
||||||
if (itr != vars_.end())
|
if (itr != vars_.end())
|
||||||
{
|
{
|
||||||
return itr->second;
|
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())
|
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
|
||||||
&& (util::apply_visitor(*this, x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
value_type operator() (binary_node<tags::logical_or> const& x) const
|
value_type operator()(binary_node<tags::logical_or> const& x) const
|
||||||
{
|
{
|
||||||
return (util::apply_visitor(*this, x.left).to_bool())
|
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||||
|| (util::apply_visitor(*this, x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (binary_node<Tag> const& x) const
|
value_type operator()(binary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type operation;
|
typename make_op<Tag>::type operation;
|
||||||
return operation(util::apply_visitor(*this, x.left),
|
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||||
util::apply_visitor(*this, x.right));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (unary_node<Tag> const& x) const
|
value_type operator()(unary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type func;
|
typename make_op<Tag>::type func;
|
||||||
return func(util::apply_visitor(*this, x.expr));
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type arg = util::apply_visitor(*this, call.arg);
|
||||||
return call.fun(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 arg1 = util::apply_visitor(*this, call.arg1);
|
||||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||||
|
@ -151,6 +130,6 @@ struct evaluate
|
||||||
variable_type const& vars_;
|
variable_type const& vars_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP
|
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP
|
||||||
|
|
|
@ -31,7 +31,8 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/spirit/home/x3.hpp>
|
#include <boost/spirit/home/x3.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik { namespace grammar {
|
namespace mapnik {
|
||||||
|
namespace grammar {
|
||||||
|
|
||||||
#if BOOST_VERSION >= 106700
|
#if BOOST_VERSION >= 106700
|
||||||
using transcoder_type = mapnik::transcoder;
|
using transcoder_type = mapnik::transcoder;
|
||||||
|
@ -39,7 +40,6 @@ using transcoder_type = mapnik::transcoder;
|
||||||
using transcoder_type = std::reference_wrapper<mapnik::transcoder const>;
|
using transcoder_type = std::reference_wrapper<mapnik::transcoder const>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
struct transcoder_tag;
|
struct transcoder_tag;
|
||||||
struct expression_class; // top-most ID
|
struct expression_class; // top-most ID
|
||||||
|
@ -49,6 +49,7 @@ expression_grammar_type const expression("expression");
|
||||||
|
|
||||||
BOOST_SPIRIT_DECLARE(expression_grammar_type);
|
BOOST_SPIRIT_DECLARE(expression_grammar_type);
|
||||||
|
|
||||||
}}
|
} // namespace grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP
|
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP
|
||||||
|
|
|
@ -26,16 +26,16 @@
|
||||||
#include <mapnik/expression_grammar_x3.hpp>
|
#include <mapnik/expression_grammar_x3.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mapnik { namespace grammar {
|
namespace mapnik {
|
||||||
|
namespace grammar {
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
using iterator_type = std::string::const_iterator;
|
using iterator_type = std::string::const_iterator;
|
||||||
using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;
|
using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;
|
||||||
// define combined context
|
// define combined context
|
||||||
using context_type = x3::context<transcoder_tag,
|
using context_type = x3::context<transcoder_tag, transcoder_type const, phrase_context_type>;
|
||||||
transcoder_type const,
|
|
||||||
phrase_context_type>;
|
|
||||||
|
|
||||||
}}
|
} // namespace grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP
|
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP
|
||||||
|
|
|
@ -24,76 +24,70 @@
|
||||||
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
||||||
#include <mapnik/expression_grammar_x3.hpp>
|
#include <mapnik/expression_grammar_x3.hpp>
|
||||||
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
|
|
||||||
#include <mapnik/expression_node.hpp>
|
#include <mapnik/expression_node.hpp>
|
||||||
#include <mapnik/function_call.hpp>
|
#include <mapnik/function_call.hpp>
|
||||||
|
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
|
||||||
#include <mapnik/unicode.hpp>
|
#include <mapnik/unicode.hpp>
|
||||||
|
|
||||||
#include <mapnik/warning.hpp>
|
#include <mapnik/warning.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/warning_ignore.hpp>
|
|
||||||
#include <boost/spirit/home/x3.hpp>
|
|
||||||
#include <boost/spirit/home/x3/support/ast/variant.hpp>
|
|
||||||
#include <boost/fusion/include/adapt_struct.hpp>
|
#include <boost/fusion/include/adapt_struct.hpp>
|
||||||
#include <boost/fusion/include/std_pair.hpp>
|
#include <boost/fusion/include/std_pair.hpp>
|
||||||
|
#include <boost/spirit/home/x3.hpp>
|
||||||
|
#include <boost/spirit/home/x3/support/ast/variant.hpp>
|
||||||
|
#include <mapnik/warning_ignore.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call,
|
BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call,
|
||||||
(mapnik::unary_function_impl, fun)
|
(mapnik::unary_function_impl, fun)(mapnik::unary_function_call::argument_type, arg))
|
||||||
(mapnik::unary_function_call::argument_type, arg))
|
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call,
|
BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call,
|
||||||
(mapnik::binary_function_impl, fun)
|
(mapnik::binary_function_impl, fun)(mapnik::binary_function_call::argument_type,
|
||||||
(mapnik::binary_function_call::argument_type, arg1)
|
arg1)(mapnik::binary_function_call::argument_type, arg2))
|
||||||
(mapnik::binary_function_call::argument_type, arg2))
|
|
||||||
|
|
||||||
|
namespace mapnik {
|
||||||
|
namespace 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 {
|
||||||
namespace ascii = boost::spirit::x3::ascii;
|
auto const& escaped_unicode = json::grammar::escaped_unicode;
|
||||||
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 {
|
template<typename Context>
|
||||||
auto const& escaped_unicode = json::grammar::escaped_unicode;
|
inline mapnik::transcoder const& extract_transcoder(Context const& ctx)
|
||||||
}
|
{
|
||||||
|
|
||||||
template <typename Context>
|
|
||||||
inline mapnik::transcoder const& extract_transcoder(Context const& ctx)
|
|
||||||
{
|
|
||||||
return x3::get<transcoder_tag>(ctx);
|
return x3::get<transcoder_tag>(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto append = [](auto const& ctx)
|
auto append = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) += _attr(ctx);
|
_val(ctx) += _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_assign = [] (auto const& ctx)
|
auto do_assign = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(_attr(ctx));
|
_val(ctx) = std::move(_attr(ctx));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_negate = [] (auto const& ctx)
|
auto do_negate = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx)));
|
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx)));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_attribute = [] (auto const& ctx)
|
auto do_attribute = [](auto const& ctx) {
|
||||||
{
|
|
||||||
auto const& attr = _attr(ctx);
|
auto const& attr = _attr(ctx);
|
||||||
if (attr == "mapnik::geometry_type")
|
if (attr == "mapnik::geometry_type")
|
||||||
{
|
{
|
||||||
|
@ -103,220 +97,199 @@ namespace mapnik { namespace grammar {
|
||||||
{
|
{
|
||||||
_val(ctx) = std::move(attribute(attr));
|
_val(ctx) = std::move(attribute(attr));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_global_attribute = [] (auto const& ctx)
|
auto do_global_attribute = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(global_attribute(_attr(ctx)));
|
_val(ctx) = std::move(global_attribute(_attr(ctx)));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_add = [] (auto const& ctx)
|
auto do_add = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_subt = [] (auto const& ctx)
|
auto do_subt = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_mult = [] (auto const& ctx)
|
auto do_mult = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_div = [] (auto const& ctx)
|
auto do_div = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_mod = [] (auto const& ctx)
|
auto do_mod = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_unicode = [] (auto const& ctx)
|
auto do_unicode = [](auto const& ctx) {
|
||||||
{
|
|
||||||
auto const& tr = extract_transcoder(ctx);
|
auto const& tr = extract_transcoder(ctx);
|
||||||
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
|
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_null = [] (auto const& ctx)
|
auto do_null = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::value_null());
|
_val(ctx) = std::move(mapnik::value_null());
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_not = [] (auto const& ctx)
|
auto do_not = [](auto const& ctx) {
|
||||||
{
|
|
||||||
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
|
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
|
||||||
_val(ctx) = std::move(node);
|
_val(ctx) = std::move(node);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_and = [] (auto const& ctx)
|
auto do_and = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_or = [] (auto const& ctx)
|
auto do_or = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_equal = [] (auto const& ctx)
|
auto do_equal = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_not_equal = [] (auto const& ctx)
|
auto do_not_equal = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_less = [] (auto const& ctx)
|
auto do_less = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_less_equal = [] (auto const& ctx)
|
auto do_less_equal = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_greater = [] (auto const& ctx)
|
auto do_greater = [](auto const& ctx) {
|
||||||
{
|
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_greater_equal = [] (auto const& ctx)
|
auto do_greater_equal = [](auto const& ctx) {
|
||||||
{
|
_val(ctx) =
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
// regex
|
// regex
|
||||||
auto do_regex_match = [] (auto const& ctx)
|
auto do_regex_match = [](auto const& ctx) {
|
||||||
{
|
|
||||||
auto const& tr = extract_transcoder(ctx);
|
auto const& tr = extract_transcoder(ctx);
|
||||||
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)) , std::move(_attr(ctx))));
|
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_regex_replace = [] (auto const& ctx)
|
auto do_regex_replace = [](auto const& ctx) {
|
||||||
{
|
|
||||||
auto const& tr = extract_transcoder(ctx);
|
auto const& tr = extract_transcoder(ctx);
|
||||||
auto const& pair = _attr(ctx);
|
auto const& pair = _attr(ctx);
|
||||||
auto const& pattern = std::get<0>(pair);
|
auto const& pattern = std::get<0>(pair);
|
||||||
auto const& format = std::get<1>(pair);
|
auto const& format = std::get<1>(pair);
|
||||||
_val(ctx) = mapnik::regex_replace_node(tr, _val(ctx) , pattern, format);
|
_val(ctx) = mapnik::regex_replace_node(tr, _val(ctx), pattern, format);
|
||||||
};
|
};
|
||||||
|
|
||||||
// mapnik::value_integer
|
// 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
|
// 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
|
// mapnik::value_bool
|
||||||
struct boolean_ : x3::symbols<mapnik::value_bool>
|
struct boolean_ : x3::symbols<mapnik::value_bool>
|
||||||
{
|
{
|
||||||
boolean_()
|
boolean_()
|
||||||
{
|
{
|
||||||
add
|
add("true", true) //
|
||||||
("true", true)
|
("false", false) //
|
||||||
("false", false)
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} boolean;
|
} 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
|
add("pi", 3.1415926535897932384626433832795) //
|
||||||
("pi", 3.1415926535897932384626433832795)
|
("deg_to_rad", 0.017453292519943295769236907684886) //
|
||||||
("deg_to_rad",0.017453292519943295769236907684886)
|
("rad_to_deg", 57.295779513082320876798154814105) //
|
||||||
("rad_to_deg",57.295779513082320876798154814105)
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} float_const;
|
} float_const;
|
||||||
|
|
||||||
// unary functions
|
// 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
|
add("sin", sin_impl()) //
|
||||||
("sin", sin_impl())
|
("cos", cos_impl()) //
|
||||||
("cos", cos_impl())
|
("tan", tan_impl()) //
|
||||||
("tan", tan_impl())
|
("atan", atan_impl()) //
|
||||||
("atan", atan_impl())
|
("exp", exp_impl()) //
|
||||||
("exp", exp_impl())
|
("log", log_impl()) //
|
||||||
("log", log_impl())
|
("abs", abs_impl()) //
|
||||||
("abs", abs_impl())
|
("length", length_impl()) //
|
||||||
("length",length_impl())
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} unary_func_types ;
|
} unary_func_types;
|
||||||
|
|
||||||
|
|
||||||
// binary functions
|
// binary functions
|
||||||
|
|
||||||
struct binary_function_types_ : x3::symbols<binary_function_impl>
|
struct binary_function_types_ : x3::symbols<binary_function_impl>
|
||||||
{
|
{
|
||||||
binary_function_types_()
|
binary_function_types_()
|
||||||
{
|
{
|
||||||
add
|
add("min", binary_function_impl(min_impl)) //
|
||||||
("min", binary_function_impl(min_impl))
|
("max", binary_function_impl(max_impl)) //
|
||||||
("max", binary_function_impl(max_impl))
|
("pow", binary_function_impl(pow_impl)) //
|
||||||
("pow", binary_function_impl(pow_impl))
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} binary_func_types;
|
} binary_func_types;
|
||||||
|
|
||||||
// geometry types
|
// geometry types
|
||||||
struct geometry_types_ : x3::symbols<mapnik::value_integer>
|
struct geometry_types_ : x3::symbols<mapnik::value_integer>
|
||||||
{
|
{
|
||||||
geometry_types_()
|
geometry_types_()
|
||||||
{
|
{
|
||||||
add
|
add("point", 1) //
|
||||||
("point", 1)
|
("linestring", 2) //
|
||||||
("linestring", 2)
|
("polygon", 3) //
|
||||||
("polygon",3)
|
("collection", 4) //
|
||||||
("collection",4)
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} geometry_type;
|
} geometry_type;
|
||||||
|
|
||||||
struct unesc_chars_ : x3::symbols<char>
|
struct unesc_chars_ : x3::symbols<char>
|
||||||
{
|
{
|
||||||
unesc_chars_()
|
unesc_chars_()
|
||||||
{
|
{
|
||||||
add
|
add("\\a", '\a') //
|
||||||
("\\a", '\a')
|
("\\b", '\b') //
|
||||||
("\\b", '\b')
|
("\\f", '\f') //
|
||||||
("\\f", '\f')
|
("\\n", '\n') //
|
||||||
("\\n", '\n')
|
("\\r", '\r') //
|
||||||
("\\r", '\r')
|
("\\t", '\t') //
|
||||||
("\\t", '\t')
|
("\\v", '\v') //
|
||||||
("\\v", '\v')
|
("\\\\", '\\') //
|
||||||
("\\\\", '\\')
|
("\\\'", '\'') //
|
||||||
("\\\'", '\'')
|
("\\\"", '\"') //
|
||||||
("\\\"", '\"')
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} unesc_char;
|
} unesc_char;
|
||||||
|
|
||||||
// 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");
|
|
||||||
|
|
||||||
|
// 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
|
// strings
|
||||||
auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'')
|
auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'')
|
||||||
>> no_skip[*(unesc_char[append]
|
>> no_skip[*(unesc_char[append]
|
||||||
|
@ -431,9 +404,8 @@ namespace mapnik { namespace grammar {
|
||||||
unquoted_ustring[do_unicode]
|
unquoted_ustring[do_unicode]
|
||||||
// ^ https://github.com/mapnik/mapnik/pull/3389
|
// ^ https://github.com/mapnik/mapnik/pull/3389
|
||||||
;
|
;
|
||||||
|
// clang-format on
|
||||||
BOOST_SPIRIT_DEFINE (
|
BOOST_SPIRIT_DEFINE(expression,
|
||||||
expression,
|
|
||||||
logical_expression,
|
logical_expression,
|
||||||
not_expression,
|
not_expression,
|
||||||
conditional_expression,
|
conditional_expression,
|
||||||
|
@ -446,9 +418,9 @@ namespace mapnik { namespace grammar {
|
||||||
unary_func_expression,
|
unary_func_expression,
|
||||||
binary_func_expression,
|
binary_func_expression,
|
||||||
unary_expression,
|
unary_expression,
|
||||||
primary_expression
|
primary_expression);
|
||||||
);
|
|
||||||
|
|
||||||
}}
|
} // namespace grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
|
@ -34,61 +34,119 @@
|
||||||
// stl
|
// stl
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
using value_type = mapnik::value;
|
using value_type = mapnik::value;
|
||||||
|
|
||||||
template <typename Tag> struct make_op;
|
template<typename Tag>
|
||||||
template <> struct make_op<mapnik::tags::negate> { using type = std::negate<value_type>;};
|
struct make_op;
|
||||||
template <> struct make_op<mapnik::tags::plus> { using type = std::plus<value_type>;};
|
template<>
|
||||||
template <> struct make_op<mapnik::tags::minus> { using type = std::minus<value_type>;};
|
struct make_op<mapnik::tags::negate>
|
||||||
template <> struct make_op<mapnik::tags::mult> { using type = std::multiplies<value_type>;};
|
{
|
||||||
template <> struct make_op<mapnik::tags::div> { using type = std::divides<value_type>;};
|
using type = std::negate<value_type>;
|
||||||
template <> struct make_op<mapnik::tags::mod> { using type = std::modulus<value_type>;};
|
};
|
||||||
template <> struct make_op<mapnik::tags::less> { using type = std::less<value_type>;};
|
template<>
|
||||||
template <> struct make_op<mapnik::tags::less_equal> { using type = std::less_equal<value_type>;};
|
struct make_op<mapnik::tags::plus>
|
||||||
template <> struct make_op<mapnik::tags::greater> { using type = std::greater<value_type>;};
|
{
|
||||||
template <> struct make_op<mapnik::tags::greater_equal> { using type = std::greater_equal<value_type>;};
|
using type = std::plus<value_type>;
|
||||||
template <> struct make_op<mapnik::tags::equal_to> { using type = std::equal_to<value_type>;};
|
};
|
||||||
template <> struct make_op<mapnik::tags::not_equal_to> { using type = std::not_equal_to<value_type>;};
|
template<>
|
||||||
template <> struct make_op<mapnik::tags::logical_not> { using type = std::logical_not<value_type>;};
|
struct make_op<mapnik::tags::minus>
|
||||||
template <> struct make_op<mapnik::tags::logical_and> { using type = std::logical_and<value_type>;};
|
{
|
||||||
template <> struct make_op<mapnik::tags::logical_or> { using type = std::logical_or<value_type>;};
|
using type = std::minus<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::mult>
|
||||||
|
{
|
||||||
|
using type = std::multiplies<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::div>
|
||||||
|
{
|
||||||
|
using type = std::divides<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::mod>
|
||||||
|
{
|
||||||
|
using type = std::modulus<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::less>
|
||||||
|
{
|
||||||
|
using type = std::less<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::less_equal>
|
||||||
|
{
|
||||||
|
using type = std::less_equal<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::greater>
|
||||||
|
{
|
||||||
|
using type = std::greater<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::greater_equal>
|
||||||
|
{
|
||||||
|
using type = std::greater_equal<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::equal_to>
|
||||||
|
{
|
||||||
|
using type = std::equal_to<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::not_equal_to>
|
||||||
|
{
|
||||||
|
using type = std::not_equal_to<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::logical_not>
|
||||||
|
{
|
||||||
|
using type = std::logical_not<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::logical_and>
|
||||||
|
{
|
||||||
|
using type = std::logical_and<value_type>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct make_op<mapnik::tags::logical_or>
|
||||||
|
{
|
||||||
|
using type = std::logical_or<value_type>;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
struct unary_node
|
struct unary_node
|
||||||
{
|
{
|
||||||
unary_node (expr_node && a)
|
unary_node(expr_node&& a)
|
||||||
: expr(std::move(a)) {}
|
: expr(std::move(a))
|
||||||
|
{}
|
||||||
|
|
||||||
unary_node (expr_node const& a)
|
unary_node(expr_node const& a)
|
||||||
: expr(a) {}
|
: expr(a)
|
||||||
|
{}
|
||||||
|
|
||||||
static const char* type()
|
static const char* type() { return Tag::str(); }
|
||||||
{
|
|
||||||
return Tag::str();
|
|
||||||
}
|
|
||||||
|
|
||||||
expr_node expr;
|
expr_node expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
struct binary_node
|
struct binary_node
|
||||||
{
|
{
|
||||||
binary_node(expr_node && a, expr_node && b)
|
binary_node(expr_node&& a, expr_node&& b)
|
||||||
: left(std::move(a)),
|
: left(std::move(a))
|
||||||
right(std::move(b)) {}
|
, right(std::move(b))
|
||||||
|
{}
|
||||||
|
|
||||||
binary_node(expr_node const& a, expr_node const& b)
|
binary_node(expr_node const& a, expr_node const& b)
|
||||||
: left(a),
|
: left(a)
|
||||||
right(b) {}
|
, right(b)
|
||||||
|
{}
|
||||||
|
|
||||||
static const char* type()
|
static const char* type() { return Tag::str(); }
|
||||||
{
|
expr_node left, right;
|
||||||
return Tag::str();
|
|
||||||
}
|
|
||||||
expr_node left,right;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct unary_function_call
|
struct unary_function_call
|
||||||
|
@ -96,7 +154,9 @@ struct unary_function_call
|
||||||
using argument_type = expr_node;
|
using argument_type = expr_node;
|
||||||
unary_function_call() = default;
|
unary_function_call() = default;
|
||||||
unary_function_call(unary_function_impl _fun, argument_type const& _arg)
|
unary_function_call(unary_function_impl _fun, argument_type const& _arg)
|
||||||
: fun(_fun), arg(_arg) {}
|
: fun(_fun)
|
||||||
|
, arg(_arg)
|
||||||
|
{}
|
||||||
|
|
||||||
unary_function_impl fun;
|
unary_function_impl fun;
|
||||||
argument_type arg;
|
argument_type arg;
|
||||||
|
@ -107,7 +167,10 @@ struct binary_function_call
|
||||||
using argument_type = expr_node;
|
using argument_type = expr_node;
|
||||||
binary_function_call() = default;
|
binary_function_call() = default;
|
||||||
binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2)
|
binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2)
|
||||||
: fun(_fun), arg1(_arg1), arg2(_arg2) {}
|
: fun(_fun)
|
||||||
|
, arg1(_arg1)
|
||||||
|
, arg2(_arg2)
|
||||||
|
{}
|
||||||
binary_function_impl fun;
|
binary_function_impl fun;
|
||||||
argument_type arg1;
|
argument_type arg1;
|
||||||
argument_type arg2;
|
argument_type arg2;
|
||||||
|
@ -137,7 +200,6 @@ struct MAPNIK_DECL regex_replace_node
|
||||||
std::shared_ptr<_regex_replace_impl> impl_;
|
std::shared_ptr<_regex_replace_impl> impl_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
|
#endif // MAPNIK_EXPRESSION_NODE_HPP
|
||||||
#endif //MAPNIK_EXPRESSION_NODE_HPP
|
|
||||||
|
|
|
@ -28,136 +28,90 @@
|
||||||
#include <mapnik/value/types.hpp>
|
#include <mapnik/value/types.hpp>
|
||||||
#include <mapnik/util/variant.hpp>
|
#include <mapnik/util/variant.hpp>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
namespace tags {
|
namespace tags {
|
||||||
struct negate
|
struct negate
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "-"; }
|
||||||
{
|
|
||||||
return "-";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct plus
|
struct plus
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "+"; }
|
||||||
{
|
|
||||||
return "+";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct minus
|
struct minus
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "-"; }
|
||||||
{
|
|
||||||
return "-";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mult
|
struct mult
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "*"; }
|
||||||
{
|
|
||||||
return "*";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct div
|
struct div
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "/"; }
|
||||||
{
|
|
||||||
return "/";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct mod
|
struct mod
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "%"; }
|
||||||
{
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct less
|
struct less
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "<"; }
|
||||||
{
|
|
||||||
return "<";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct less_equal
|
struct less_equal
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "<="; }
|
||||||
{
|
|
||||||
return "<=";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct greater
|
struct greater
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return ">"; }
|
||||||
{
|
|
||||||
return ">";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct greater_equal
|
struct greater_equal
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return ">="; }
|
||||||
{
|
|
||||||
return ">=";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct equal_to
|
struct equal_to
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "="; }
|
||||||
{
|
|
||||||
return "=";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct not_equal_to
|
struct not_equal_to
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "!="; }
|
||||||
{
|
|
||||||
return "!=";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct logical_not
|
struct logical_not
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "not "; }
|
||||||
{
|
|
||||||
return "not ";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct logical_and
|
struct logical_and
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return " and "; }
|
||||||
{
|
|
||||||
return " and ";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct logical_or
|
struct logical_or
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return " or "; }
|
||||||
{
|
|
||||||
return " or ";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end operation tags
|
} // namespace tags
|
||||||
|
|
||||||
|
template<typename Tag>
|
||||||
template <typename Tag> struct binary_node;
|
struct binary_node;
|
||||||
template <typename Tag> struct unary_node;
|
template<typename Tag>
|
||||||
|
struct unary_node;
|
||||||
struct regex_match_node;
|
struct regex_match_node;
|
||||||
struct regex_replace_node;
|
struct regex_replace_node;
|
||||||
struct attribute;
|
struct attribute;
|
||||||
|
@ -166,37 +120,34 @@ struct geometry_type_attribute;
|
||||||
struct unary_function_call;
|
struct unary_function_call;
|
||||||
struct binary_function_call;
|
struct binary_function_call;
|
||||||
|
|
||||||
using expr_node = util::variant<
|
using expr_node = util::variant<value_null,
|
||||||
value_null,
|
value_bool,
|
||||||
value_bool,
|
value_integer,
|
||||||
value_integer,
|
value_double,
|
||||||
value_double,
|
value_unicode_string,
|
||||||
value_unicode_string,
|
attribute,
|
||||||
attribute,
|
global_attribute,
|
||||||
global_attribute,
|
geometry_type_attribute,
|
||||||
geometry_type_attribute,
|
util::recursive_wrapper<unary_node<mapnik::tags::negate>>,
|
||||||
util::recursive_wrapper<unary_node<mapnik::tags::negate> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::plus>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::plus> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::minus>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::minus> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::mult>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::mult> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::div>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::div> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::mod>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::mod> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::less>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::less> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::less_equal>>,
|
||||||
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> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::greater_equal>>,
|
||||||
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::equal_to> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::not_equal_to>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::not_equal_to> >,
|
util::recursive_wrapper<unary_node<mapnik::tags::logical_not>>,
|
||||||
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_and> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::logical_or>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::logical_or> >,
|
util::recursive_wrapper<regex_match_node>,
|
||||||
util::recursive_wrapper<regex_match_node>,
|
util::recursive_wrapper<regex_replace_node>,
|
||||||
util::recursive_wrapper<regex_replace_node>,
|
util::recursive_wrapper<unary_function_call>,
|
||||||
util::recursive_wrapper<unary_function_call>,
|
util::recursive_wrapper<binary_function_call>>;
|
||||||
util::recursive_wrapper<binary_function_call>
|
|
||||||
>;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSION_NODE_HPP
|
#endif // MAPNIK_EXPRESSION_NODE_HPP
|
||||||
|
|
|
@ -35,8 +35,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
MAPNIK_DECL std::string to_expression_string(expr_node const& node);
|
MAPNIK_DECL std::string to_expression_string(expr_node const& node);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -48,7 +47,7 @@ implicit pointer-to-bool conversion, thus any non-null pointer
|
||||||
would yield "true".
|
would yield "true".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
std::string to_expression_string(T const* expr_node_ptr)
|
std::string to_expression_string(T const* expr_node_ptr)
|
||||||
{
|
{
|
||||||
throw std::logic_error("to_expression_string() called with pointer argument");
|
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
|
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)
|
std::string to_expression_string(std::shared_ptr<T> const& expr_node_ptr)
|
||||||
{
|
{
|
||||||
throw std::logic_error("to_expression_string() called with pointer argument");
|
throw std::logic_error("to_expression_string() called with pointer argument");
|
||||||
// compile error intended here; comment on the next line shows in clang output
|
// compile error intended here; comment on the next line shows in clang output
|
||||||
return expr_node_ptr; // to_expression_string() called with pointer argument
|
return expr_node_ptr; // to_expression_string() called with pointer argument
|
||||||
}
|
}
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSION_STRING_HPP
|
#endif // MAPNIK_EXPRESSION_STRING_HPP
|
||||||
|
|
|
@ -38,108 +38,122 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
// stl
|
// stl
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
namespace msm = boost::msm;
|
namespace msm = boost::msm;
|
||||||
namespace mpl = boost::mpl;
|
namespace mpl = boost::mpl;
|
||||||
using namespace msm::front;
|
using namespace msm::front;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T extend(T const & v1, T const & v2, double length)
|
T extend(T const& v1, T const& v2, double length)
|
||||||
{
|
{
|
||||||
double dx = v2.x - v1.x;
|
double dx = v2.x - v1.x;
|
||||||
double dy = v2.y - v1.y;
|
double dy = v2.y - v1.y;
|
||||||
double l12 = std::sqrt(dx * dx + dy * dy);
|
double l12 = std::sqrt(dx * dx + dy * dy);
|
||||||
double coef = 1.0 + length / l12;
|
double coef = 1.0 + length / l12;
|
||||||
return vertex2d(v1.x + dx * coef,
|
return vertex2d(v1.x + dx * coef, v1.y + dy * coef, v2.cmd);
|
||||||
v1.y + dy * coef, v2.cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace events
|
namespace events {
|
||||||
|
struct vertex_event
|
||||||
{
|
{
|
||||||
struct vertex_event
|
vertex_event(vertex2d const& vertex)
|
||||||
{
|
: vertex(vertex)
|
||||||
vertex_event(vertex2d const & vertex) : vertex(vertex) { }
|
{}
|
||||||
vertex2d const & vertex;
|
vertex2d const& vertex;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct move_to : vertex_event { using vertex_event::vertex_event; };
|
struct move_to : vertex_event
|
||||||
struct line_to : vertex_event { using vertex_event::vertex_event; };
|
|
||||||
struct close : vertex_event { using vertex_event::vertex_event; };
|
|
||||||
struct end : vertex_event { using vertex_event::vertex_event; };
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace actions
|
|
||||||
{
|
{
|
||||||
struct store
|
using vertex_event::vertex_event;
|
||||||
{
|
};
|
||||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
struct line_to : vertex_event
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
{
|
||||||
|
using vertex_event::vertex_event;
|
||||||
|
};
|
||||||
|
struct close : vertex_event
|
||||||
|
{
|
||||||
|
using vertex_event::vertex_event;
|
||||||
|
};
|
||||||
|
struct end : vertex_event
|
||||||
|
{
|
||||||
|
using vertex_event::vertex_event;
|
||||||
|
};
|
||||||
|
} // namespace events
|
||||||
|
|
||||||
|
namespace actions {
|
||||||
|
struct store
|
||||||
|
{
|
||||||
|
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||||
|
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||||
{
|
{
|
||||||
m.v2 = m.v1;
|
m.v2 = m.v1;
|
||||||
m.v1 = e.vertex;
|
m.v1 = e.vertex;
|
||||||
m.output = boost::none;
|
m.output = boost::none;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct output
|
struct output
|
||||||
{
|
{
|
||||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||||
{
|
{
|
||||||
m.output = e.vertex;
|
m.output = e.vertex;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct store_and_output
|
struct store_and_output
|
||||||
{
|
{
|
||||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||||
{
|
{
|
||||||
m.v2 = m.v1;
|
m.v2 = m.v1;
|
||||||
m.v1 = e.vertex;
|
m.v1 = e.vertex;
|
||||||
m.output = m.v2;
|
m.output = m.v2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct output_begin
|
struct output_begin
|
||||||
{
|
{
|
||||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||||
{
|
{
|
||||||
m.v2 = m.v1;
|
m.v2 = m.v1;
|
||||||
m.v1 = e.vertex;
|
m.v1 = e.vertex;
|
||||||
m.output = extend(m.v1, m.v2, m.extend_length);
|
m.output = extend(m.v1, m.v2, m.extend_length);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct output_end
|
struct output_end
|
||||||
{
|
{
|
||||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||||
{
|
{
|
||||||
m.output = extend(m.v2, m.v1, m.extend_length);
|
m.output = extend(m.v2, m.v1, m.extend_length);
|
||||||
m.v1 = e.vertex;
|
m.v1 = e.vertex;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace actions
|
||||||
|
|
||||||
struct extender_def : public msm::front::state_machine_def<extender_def>
|
struct extender_def : public msm::front::state_machine_def<extender_def>
|
||||||
{
|
{
|
||||||
using no_exception_thrown = int;
|
using no_exception_thrown = int;
|
||||||
using no_message_queue = int;
|
using no_message_queue = int;
|
||||||
|
|
||||||
struct initial : public msm::front::state<> { };
|
struct initial : public msm::front::state<>
|
||||||
struct vertex_one : public msm::front::state<> { };
|
{};
|
||||||
struct vertex_two : public msm::front::state<> { };
|
struct vertex_one : public msm::front::state<>
|
||||||
struct end : public msm::front::state<> { };
|
{};
|
||||||
|
struct vertex_two : public msm::front::state<>
|
||||||
|
{};
|
||||||
|
struct end : public msm::front::state<>
|
||||||
|
{};
|
||||||
|
|
||||||
using initial_state = initial;
|
using initial_state = initial;
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
struct transition_table : mpl::vector<
|
struct transition_table : mpl::vector<
|
||||||
// Start Event Next Action Guard
|
// Start Event Next Action Guard
|
||||||
// +------------+-----------------+------------+--------------------+------+
|
// +------------+-----------------+------------+--------------------+------+
|
||||||
|
@ -157,11 +171,11 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
|
||||||
Row < vertex_two , events::end , end , actions::output_end >,
|
Row < vertex_two , events::end , end , actions::output_end >,
|
||||||
Row < end , events::end , end , actions::output >
|
Row < end , events::end , end , actions::output >
|
||||||
> {};
|
> {};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
extender_def(double extend_length)
|
extender_def(double extend_length)
|
||||||
: extend_length(extend_length)
|
: extend_length(extend_length)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
boost::optional<vertex2d> output;
|
boost::optional<vertex2d> output;
|
||||||
vertex2d v1, v2;
|
vertex2d v1, v2;
|
||||||
|
@ -170,25 +184,23 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
|
||||||
|
|
||||||
using extender = msm::back::state_machine<extender_def>;
|
using extender = msm::back::state_machine<extender_def>;
|
||||||
|
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template <typename Geometry>
|
template<typename Geometry>
|
||||||
struct extend_converter
|
struct extend_converter
|
||||||
{
|
{
|
||||||
extend_converter(Geometry & geom)
|
extend_converter(Geometry& geom)
|
||||||
: extend_converter(geom, 0)
|
: extend_converter(geom, 0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
extend_converter(Geometry & geom, double extend)
|
extend_converter(Geometry& geom, double extend)
|
||||||
: geom_(geom), extender_(extend)
|
: geom_(geom)
|
||||||
|
, extender_(extend)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void set_extend(double extend)
|
void set_extend(double extend) { extender_.extend_length = extend; }
|
||||||
{
|
|
||||||
extender_.extend_length = extend;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned vertex(double * x, double * y)
|
unsigned vertex(double* x, double* y)
|
||||||
{
|
{
|
||||||
using namespace detail;
|
using namespace detail;
|
||||||
vertex2d v;
|
vertex2d v;
|
||||||
|
@ -210,9 +222,9 @@ struct extend_converter
|
||||||
extender_.process_event(events::end(v));
|
extender_.process_event(events::end(v));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while(!extender_.output);
|
} while (!extender_.output);
|
||||||
|
|
||||||
vertex2d const & output = *extender_.output;
|
vertex2d const& output = *extender_.output;
|
||||||
*x = output.x;
|
*x = output.x;
|
||||||
*y = output.y;
|
*y = output.y;
|
||||||
return output.cmd;
|
return output.cmd;
|
||||||
|
@ -224,11 +236,11 @@ struct extend_converter
|
||||||
extender_.start();
|
extender_.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Geometry & geom_;
|
Geometry& geom_;
|
||||||
detail::extender extender_;
|
detail::extender extender_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXTEND_CONVERTER_HPP
|
#endif // MAPNIK_EXTEND_CONVERTER_HPP
|
||||||
|
|
|
@ -32,41 +32,33 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template
|
template<typename product_type, typename key_type, typename... Args>
|
||||||
<
|
class factory : public singleton<factory<product_type, key_type, Args...>>
|
||||||
typename product_type,
|
|
||||||
typename key_type,
|
|
||||||
typename ...Args >
|
|
||||||
class factory : public singleton<factory <product_type,
|
|
||||||
key_type,
|
|
||||||
Args...> >
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
using product_creator = product_type* (*) (Args...);
|
using product_creator = product_type* (*)(Args...);
|
||||||
using product_map = std::map<key_type,product_creator>;
|
using product_map = std::map<key_type, product_creator>;
|
||||||
product_map map_;
|
product_map map_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
|
|
||||||
bool register_product(key_type const& key, product_creator creator)
|
bool register_product(key_type const& key, product_creator creator)
|
||||||
{
|
{
|
||||||
return map_.insert(typename product_map::value_type(key,creator)).second;
|
return map_.insert(typename product_map::value_type(key, creator)).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool unregister_product(const key_type& key)
|
bool unregister_product(const key_type& key) { return map_.erase(key) == 1; }
|
||||||
{
|
|
||||||
return map_.erase(key)==1;
|
|
||||||
}
|
|
||||||
|
|
||||||
product_type* create_object(key_type const& key, Args...args)
|
product_type* create_object(key_type const& key, Args... args)
|
||||||
{
|
{
|
||||||
typename product_map::const_iterator pos=map_.find(key);
|
typename product_map::const_iterator pos = map_.find(key);
|
||||||
if (pos!=map_.end())
|
if (pos != map_.end())
|
||||||
{
|
{
|
||||||
return (pos->second)(args...);
|
return (pos->second)(args...);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FACTORY_HPP
|
#endif // MAPNIK_FACTORY_HPP
|
||||||
|
|
|
@ -50,12 +50,13 @@ class feature_impl;
|
||||||
|
|
||||||
using raster_ptr = std::shared_ptr<raster>;
|
using raster_ptr = std::shared_ptr<raster>;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class context : private util::noncopyable
|
class context : private util::noncopyable
|
||||||
|
|
||||||
{
|
{
|
||||||
friend class feature_impl;
|
friend class feature_impl;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
using map_type = T;
|
using map_type = T;
|
||||||
using value_type = typename map_type::value_type;
|
using value_type = typename map_type::value_type;
|
||||||
using key_type = typename map_type::key_type;
|
using key_type = typename map_type::key_type;
|
||||||
|
@ -65,7 +66,8 @@ public:
|
||||||
using const_iterator = typename map_type::const_iterator;
|
using const_iterator = typename map_type::const_iterator;
|
||||||
|
|
||||||
context()
|
context()
|
||||||
: mapping_() {}
|
: mapping_()
|
||||||
|
{}
|
||||||
|
|
||||||
inline size_type push(key_type const& name)
|
inline size_type push(key_type const& name)
|
||||||
{
|
{
|
||||||
|
@ -74,20 +76,17 @@ public:
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void add(key_type const& name, size_type index)
|
inline void add(key_type const& name, size_type index) { mapping_.emplace(name, index); }
|
||||||
{
|
|
||||||
mapping_.emplace(name, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline size_type size() const { return mapping_.size(); }
|
inline size_type size() const { return mapping_.size(); }
|
||||||
inline const_iterator begin() const { return mapping_.begin();}
|
inline const_iterator begin() const { return mapping_.begin(); }
|
||||||
inline const_iterator end() const { return mapping_.end();}
|
inline const_iterator end() const { return mapping_.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
map_type mapping_;
|
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>;
|
using context_ptr = std::shared_ptr<context_type>;
|
||||||
|
|
||||||
static const value default_feature_value{};
|
static const value default_feature_value{};
|
||||||
|
@ -95,38 +94,39 @@ static const value default_feature_value{};
|
||||||
class MAPNIK_DECL feature_impl : private util::noncopyable
|
class MAPNIK_DECL feature_impl : private util::noncopyable
|
||||||
{
|
{
|
||||||
friend class feature_kv_iterator;
|
friend class feature_kv_iterator;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
|
|
||||||
using value_type = mapnik::value;
|
using value_type = mapnik::value;
|
||||||
using cont_type = std::vector<value_type>;
|
using cont_type = std::vector<value_type>;
|
||||||
using iterator = feature_kv_iterator;
|
using iterator = feature_kv_iterator;
|
||||||
|
|
||||||
feature_impl(context_ptr const& ctx, mapnik::value_integer _id)
|
feature_impl(context_ptr const& ctx, mapnik::value_integer _id)
|
||||||
: id_(_id),
|
: id_(_id)
|
||||||
ctx_(ctx),
|
, ctx_(ctx)
|
||||||
data_(ctx_->mapping_.size()),
|
, data_(ctx_->mapping_.size())
|
||||||
geom_(geometry::geometry_empty()),
|
, geom_(geometry::geometry_empty())
|
||||||
raster_() {}
|
, raster_()
|
||||||
|
{}
|
||||||
|
|
||||||
inline mapnik::value_integer id() const { return id_;}
|
inline mapnik::value_integer id() const { return id_; }
|
||||||
inline void set_id(mapnik::value_integer _id) { id_ = _id;}
|
inline void set_id(mapnik::value_integer _id) { id_ = _id; }
|
||||||
template <typename T>
|
template<typename T>
|
||||||
inline void put(context_type::key_type const& key, T const& val)
|
inline void put(context_type::key_type const& key, T const& val)
|
||||||
{
|
{
|
||||||
put(key, value(val));
|
put(key, value(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
inline void put_new(context_type::key_type const& key, T const& val)
|
inline void put_new(context_type::key_type const& key, T const& val)
|
||||||
{
|
{
|
||||||
put_new(key, value(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);
|
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
|
||||||
if (itr != ctx_->mapping_.end()
|
if (itr != ctx_->mapping_.end() && itr->second < data_.size())
|
||||||
&& itr->second < data_.size())
|
|
||||||
{
|
{
|
||||||
data_[itr->second] = std::move(val);
|
data_[itr->second] = std::move(val);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
|
||||||
if (itr != ctx_->mapping_.end()
|
if (itr != ctx_->mapping_.end() && itr->second < data_.size())
|
||||||
&& itr->second < data_.size())
|
|
||||||
{
|
{
|
||||||
data_[itr->second] = std::move(val);
|
data_[itr->second] = std::move(val);
|
||||||
}
|
}
|
||||||
|
@ -152,10 +151,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool has_key(context_type::key_type const& key) const
|
inline bool has_key(context_type::key_type const& key) const { return (ctx_->mapping_.count(key) == 1); }
|
||||||
{
|
|
||||||
return (ctx_->mapping_.count(key) == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline value_type const& get(context_type::key_type const& key) const
|
inline value_type const& get(context_type::key_type const& key) const
|
||||||
{
|
{
|
||||||
|
@ -173,70 +169,31 @@ public:
|
||||||
return default_feature_value;
|
return default_feature_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t size() const
|
inline std::size_t size() const { return data_.size(); }
|
||||||
{
|
|
||||||
return data_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline cont_type const& get_data() const
|
inline cont_type const& get_data() const { return data_; }
|
||||||
{
|
|
||||||
return data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_data(cont_type const& data)
|
inline void set_data(cont_type const& data) { data_ = data; }
|
||||||
{
|
|
||||||
data_ = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline context_ptr context() const
|
inline context_ptr context() const { return ctx_; }
|
||||||
{
|
|
||||||
return ctx_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_geometry(geometry::geometry<double> && geom)
|
inline void set_geometry(geometry::geometry<double>&& geom) { geom_ = std::move(geom); }
|
||||||
{
|
|
||||||
geom_ = std::move(geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_geometry_copy(geometry::geometry<double> const& geom)
|
inline void set_geometry_copy(geometry::geometry<double> const& geom) { geom_ = geom; }
|
||||||
{
|
|
||||||
geom_ = geom;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline geometry::geometry<double> const& get_geometry() const
|
inline geometry::geometry<double> const& get_geometry() const { return geom_; }
|
||||||
{
|
|
||||||
return geom_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline geometry::geometry<double> & get_geometry()
|
inline geometry::geometry<double>& get_geometry() { return geom_; }
|
||||||
{
|
|
||||||
return geom_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline box2d<double> envelope() const
|
inline box2d<double> envelope() const { return mapnik::geometry::envelope(geom_); }
|
||||||
{
|
|
||||||
return mapnik::geometry::envelope(geom_);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline raster_ptr const& get_raster() const
|
inline raster_ptr const& get_raster() const { return raster_; }
|
||||||
{
|
|
||||||
return raster_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_raster(raster_ptr const& raster)
|
inline void set_raster(raster_ptr const& raster) { raster_ = raster; }
|
||||||
{
|
|
||||||
raster_ = raster;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline feature_kv_iterator begin() const
|
inline feature_kv_iterator begin() const { return feature_kv_iterator(*this, true); }
|
||||||
{
|
|
||||||
return feature_kv_iterator(*this,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline feature_kv_iterator end() const
|
inline feature_kv_iterator end() const { return feature_kv_iterator(*this); }
|
||||||
{
|
|
||||||
return feature_kv_iterator(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
|
@ -261,7 +218,7 @@ public:
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mapnik::value_integer id_;
|
mapnik::value_integer id_;
|
||||||
context_ptr ctx_;
|
context_ptr ctx_;
|
||||||
cont_type data_;
|
cont_type data_;
|
||||||
|
@ -269,8 +226,7 @@ private:
|
||||||
raster_ptr raster_;
|
raster_ptr raster_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& out, feature_impl const& f)
|
||||||
inline std::ostream& operator<< (std::ostream & out,feature_impl const& f)
|
|
||||||
{
|
{
|
||||||
out << f.to_string();
|
out << f.to_string();
|
||||||
return out;
|
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>;
|
using feature_ptr = std::shared_ptr<feature_impl>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_HPP
|
#endif // MAPNIK_FEATURE_HPP
|
||||||
|
|
|
@ -30,17 +30,16 @@
|
||||||
// boost
|
// boost
|
||||||
//#include <boost/pool/pool_alloc.hpp>
|
//#include <boost/pool/pool_alloc.hpp>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
struct feature_factory
|
struct feature_factory
|
||||||
{
|
{
|
||||||
static std::shared_ptr<feature_impl> create (context_ptr const& ctx, mapnik::value_integer fid)
|
static std::shared_ptr<feature_impl> create(context_ptr const& ctx, mapnik::value_integer fid)
|
||||||
{
|
{
|
||||||
//return boost::allocate_shared<feature_impl>(boost::pool_allocator<feature_impl>(),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 boost::allocate_shared<feature_impl>(boost::fast_pool_allocator<feature_impl>(),fid);
|
||||||
return std::make_shared<feature_impl>(ctx,fid);
|
return std::make_shared<feature_impl>(ctx, fid);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_FACTORY_HPP
|
#endif // MAPNIK_FEATURE_FACTORY_HPP
|
||||||
|
|
|
@ -45,32 +45,31 @@ namespace mapnik {
|
||||||
|
|
||||||
class feature_impl;
|
class feature_impl;
|
||||||
|
|
||||||
class MAPNIK_DECL feature_kv_iterator :
|
class MAPNIK_DECL feature_kv_iterator : public boost::iterator_facade<feature_kv_iterator,
|
||||||
public boost::iterator_facade<feature_kv_iterator,
|
|
||||||
std::tuple<std::string, value> const,
|
std::tuple<std::string, value> const,
|
||||||
boost::forward_traversal_tag>
|
boost::forward_traversal_tag>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using value_type = std::tuple<std::string,value>;
|
using value_type = std::tuple<std::string, value>;
|
||||||
feature_kv_iterator (feature_impl const& f, bool begin = false);
|
feature_kv_iterator(feature_impl const& f, bool begin = false);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
friend class boost::iterator_core_access;
|
friend class boost::iterator_core_access;
|
||||||
void increment();
|
void increment();
|
||||||
void decrement();
|
void decrement();
|
||||||
void advance(boost::iterator_difference<feature_kv_iterator>::type);
|
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;
|
value_type const& dereference() const;
|
||||||
|
|
||||||
feature_impl const& f_;
|
feature_impl const& f_;
|
||||||
std::map<std::string,std::size_t>::const_iterator itr_;
|
std::map<std::string, std::size_t>::const_iterator itr_;
|
||||||
mutable value_type kv_;
|
mutable value_type kv_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct value_not_null
|
struct value_not_null
|
||||||
{
|
{
|
||||||
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));
|
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>;
|
using feature_kv_iterator2 = boost::filter_iterator<value_not_null, feature_kv_iterator>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_KV_ITERATOR_HPP
|
#endif // MAPNIK_FEATURE_KV_ITERATOR_HPP
|
||||||
|
|
|
@ -32,90 +32,65 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class layer_descriptor
|
class layer_descriptor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
layer_descriptor(std::string const& name, std::string const& encoding)
|
layer_descriptor(std::string const& name, std::string const& encoding)
|
||||||
: name_(name),
|
: name_(name)
|
||||||
encoding_(encoding),
|
, encoding_(encoding)
|
||||||
descriptors_(),
|
, descriptors_()
|
||||||
extra_params_() {}
|
, extra_params_()
|
||||||
|
{}
|
||||||
|
|
||||||
layer_descriptor(layer_descriptor const& other)
|
layer_descriptor(layer_descriptor const& other)
|
||||||
: name_(other.name_),
|
: name_(other.name_)
|
||||||
encoding_(other.encoding_),
|
, encoding_(other.encoding_)
|
||||||
descriptors_(other.descriptors_),
|
, descriptors_(other.descriptors_)
|
||||||
extra_params_(other.extra_params_) {}
|
, extra_params_(other.extra_params_)
|
||||||
|
{}
|
||||||
|
|
||||||
void set_name(std::string const& name)
|
void set_name(std::string const& name) { name_ = name; }
|
||||||
{
|
|
||||||
name_ = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string const& get_name() const
|
std::string const& get_name() const { return name_; }
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_encoding(std::string const& encoding)
|
void set_encoding(std::string const& encoding) { encoding_ = encoding; }
|
||||||
{
|
|
||||||
encoding_ = encoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string const& get_encoding() const
|
std::string const& get_encoding() const { return encoding_; }
|
||||||
{
|
|
||||||
return encoding_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_descriptor(attribute_descriptor const& desc)
|
void add_descriptor(attribute_descriptor const& desc) { descriptors_.push_back(desc); }
|
||||||
{
|
|
||||||
descriptors_.push_back(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<attribute_descriptor> const& get_descriptors() const
|
std::vector<attribute_descriptor> const& get_descriptors() const { return descriptors_; }
|
||||||
{
|
|
||||||
return descriptors_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<attribute_descriptor>& get_descriptors()
|
std::vector<attribute_descriptor>& get_descriptors() { return descriptors_; }
|
||||||
{
|
|
||||||
return descriptors_;
|
|
||||||
}
|
|
||||||
|
|
||||||
parameters const& get_extra_parameters() const
|
parameters const& get_extra_parameters() const { return extra_params_; }
|
||||||
{
|
|
||||||
return extra_params_;
|
|
||||||
}
|
|
||||||
|
|
||||||
parameters& get_extra_parameters()
|
parameters& get_extra_parameters() { return extra_params_; }
|
||||||
{
|
|
||||||
return extra_params_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool has_name(std::string const& name) const
|
bool has_name(std::string const& name) const
|
||||||
{
|
{
|
||||||
auto result = std::find_if(std::begin(descriptors_), std::end(descriptors_),
|
auto result = std::find_if(std::begin(descriptors_),
|
||||||
[&name](attribute_descriptor const& desc) { return name == desc.get_name();});
|
std::end(descriptors_),
|
||||||
|
[&name](attribute_descriptor const& desc) { return name == desc.get_name(); });
|
||||||
return result != std::end(descriptors_);
|
return result != std::end(descriptors_);
|
||||||
}
|
}
|
||||||
void order_by_name()
|
void order_by_name()
|
||||||
{
|
{
|
||||||
std::sort(std::begin(descriptors_), std::end(descriptors_),
|
std::sort(
|
||||||
[](attribute_descriptor const& d0, attribute_descriptor const& d1)
|
std::begin(descriptors_),
|
||||||
{
|
std::end(descriptors_),
|
||||||
return d0.get_name() < d1.get_name();
|
[](attribute_descriptor const& d0, attribute_descriptor const& d1) { return d0.get_name() < d1.get_name(); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::string encoding_;
|
std::string encoding_;
|
||||||
std::vector<attribute_descriptor> descriptors_;
|
std::vector<attribute_descriptor> descriptors_;
|
||||||
parameters extra_params_;
|
parameters extra_params_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_LAYER_DESC_HPP
|
#endif // MAPNIK_FEATURE_LAYER_DESC_HPP
|
||||||
|
|
|
@ -34,8 +34,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class Map;
|
class Map;
|
||||||
class layer;
|
class layer;
|
||||||
|
@ -45,36 +44,29 @@ class feature_type_style;
|
||||||
class rule_cache;
|
class rule_cache;
|
||||||
struct layer_rendering_material;
|
struct layer_rendering_material;
|
||||||
|
|
||||||
enum eAttributeCollectionPolicy
|
enum eAttributeCollectionPolicy { DEFAULT = 0, COLLECT_ALL = 1 };
|
||||||
{
|
|
||||||
DEFAULT = 0,
|
|
||||||
COLLECT_ALL = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Processor>
|
template<typename Processor>
|
||||||
class feature_style_processor
|
class feature_style_processor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit feature_style_processor(Map const& m,
|
explicit feature_style_processor(Map const& m, double scale_factor = 1.0);
|
||||||
double scale_factor = 1.0);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief apply renderer to all map layers.
|
* \brief apply renderer to all map layers.
|
||||||
*/
|
*/
|
||||||
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.
|
* \brief apply renderer to a single layer, providing pre-populated set of query attribute names.
|
||||||
*/
|
*/
|
||||||
void apply(mapnik::layer const& lyr,
|
void apply(mapnik::layer const& lyr, std::set<std::string>& names, double scale_denom_override = 0.0);
|
||||||
std::set<std::string>& names,
|
|
||||||
double scale_denom_override=0.0);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief render a layer given a projection and scale.
|
* \brief render a layer given a projection and scale.
|
||||||
*/
|
*/
|
||||||
void apply_to_layer(layer const& lay,
|
void apply_to_layer(layer const& lay,
|
||||||
Processor & p,
|
Processor& p,
|
||||||
projection const& proj0,
|
projection const& proj0,
|
||||||
double scale,
|
double scale,
|
||||||
double scale_denom,
|
double scale_denom,
|
||||||
|
@ -84,28 +76,28 @@ public:
|
||||||
int buffer_size,
|
int buffer_size,
|
||||||
std::set<std::string>& names);
|
std::set<std::string>& names);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*!
|
/*!
|
||||||
* \brief renders a featureset with the given styles.
|
* \brief renders a featureset with the given styles.
|
||||||
*/
|
*/
|
||||||
void render_style(Processor & p,
|
void render_style(Processor& p,
|
||||||
feature_type_style const* style,
|
feature_type_style const* style,
|
||||||
rule_cache const& rules,
|
rule_cache const& rules,
|
||||||
featureset_ptr features,
|
featureset_ptr features,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
void prepare_layers(layer_rendering_material & parent_mat,
|
void prepare_layers(layer_rendering_material& parent_mat,
|
||||||
std::vector<layer> const & layers,
|
std::vector<layer> const& layers,
|
||||||
feature_style_context_map & ctx_map,
|
feature_style_context_map& ctx_map,
|
||||||
Processor & p,
|
Processor& p,
|
||||||
double scale_denom);
|
double scale_denom);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief prepare features for rendering asynchronously.
|
* \brief prepare features for rendering asynchronously.
|
||||||
*/
|
*/
|
||||||
void prepare_layer(layer_rendering_material & mat,
|
void prepare_layer(layer_rendering_material& mat,
|
||||||
feature_style_context_map & ctx_map,
|
feature_style_context_map& ctx_map,
|
||||||
Processor & p,
|
Processor& p,
|
||||||
double scale,
|
double scale,
|
||||||
double scale_denom,
|
double scale_denom,
|
||||||
unsigned width,
|
unsigned width,
|
||||||
|
@ -117,11 +109,11 @@ private:
|
||||||
/*!
|
/*!
|
||||||
* \brief render features list queued when they are available.
|
* \brief render features list queued when they are available.
|
||||||
*/
|
*/
|
||||||
void render_material(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);
|
void render_submaterials(layer_rendering_material const& mat, Processor& p);
|
||||||
|
|
||||||
Map const& m_;
|
Map const& m_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_STYLE_PROCESSOR_HPP
|
#endif // MAPNIK_FEATURE_STYLE_PROCESSOR_HPP
|
||||||
|
|
|
@ -30,15 +30,15 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
|
class IProcessorContext
|
||||||
class IProcessorContext {
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IProcessorContext() {}
|
virtual ~IProcessorContext() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
using processor_context_ptr = std::shared_ptr<IProcessorContext>;
|
using processor_context_ptr = std::shared_ptr<IProcessorContext>;
|
||||||
using feature_style_context_map = std::map<std::string, processor_context_ptr >;
|
using feature_style_context_map = std::map<std::string, processor_context_ptr>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // FEATURE_STYLE_PROCESSOR_CONTEXT_HPP
|
#endif // FEATURE_STYLE_PROCESSOR_CONTEXT_HPP
|
||||||
|
|
|
@ -50,8 +50,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
// Store material for layer rendering in a two step process
|
// Store material for layer rendering in a two step process
|
||||||
struct layer_rendering_material
|
struct layer_rendering_material
|
||||||
|
@ -66,14 +65,15 @@ struct layer_rendering_material
|
||||||
std::vector<layer_rendering_material> materials_;
|
std::vector<layer_rendering_material> materials_;
|
||||||
|
|
||||||
layer_rendering_material(layer const& lay, projection const& dest)
|
layer_rendering_material(layer const& lay, projection const& dest)
|
||||||
: lay_(lay),
|
: lay_(lay)
|
||||||
proj0_(dest),
|
, proj0_(dest)
|
||||||
proj1_(lay.srs(), true) {}
|
, proj1_(lay.srs(), true)
|
||||||
|
{}
|
||||||
|
|
||||||
layer_rendering_material(layer_rendering_material && rhs) = default;
|
layer_rendering_material(layer_rendering_material&& rhs) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Processor>
|
template<typename Processor>
|
||||||
feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor)
|
feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor)
|
||||||
: m_(m)
|
: m_(m)
|
||||||
{
|
{
|
||||||
|
@ -84,11 +84,11 @@ feature_style_processor<Processor>::feature_style_processor(Map const& m, double
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Processor>
|
template<typename Processor>
|
||||||
void feature_style_processor<Processor>::prepare_layers(layer_rendering_material & parent_mat,
|
void feature_style_processor<Processor>::prepare_layers(layer_rendering_material& parent_mat,
|
||||||
std::vector<layer> const & layers,
|
std::vector<layer> const& layers,
|
||||||
feature_style_context_map & ctx_map,
|
feature_style_context_map& ctx_map,
|
||||||
Processor & p,
|
Processor& p,
|
||||||
double scale_denom)
|
double scale_denom)
|
||||||
{
|
{
|
||||||
for (layer const& lyr : layers)
|
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)
|
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_);
|
p.start_map_processing(m_);
|
||||||
|
|
||||||
projection proj(m_.srs(),true);
|
projection proj(m_.srs(), true);
|
||||||
if (scale_denom <= 0.0)
|
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
|
scale_denom *= p.scale_factor(); // FIXME - we might want to comment this out
|
||||||
|
|
||||||
// Asynchronous query supports:
|
// Asynchronous query supports:
|
||||||
|
@ -151,16 +151,16 @@ void feature_style_processor<Processor>::apply(double scale_denom)
|
||||||
p.end_map_processing(m_);
|
p.end_map_processing(m_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Processor>
|
template<typename Processor>
|
||||||
void feature_style_processor<Processor>::apply(mapnik::layer const& lyr,
|
void feature_style_processor<Processor>::apply(mapnik::layer const& lyr,
|
||||||
std::set<std::string>& names,
|
std::set<std::string>& names,
|
||||||
double scale_denom)
|
double scale_denom)
|
||||||
{
|
{
|
||||||
Processor & p = static_cast<Processor&>(*this);
|
Processor& p = static_cast<Processor&>(*this);
|
||||||
p.start_map_processing(m_);
|
p.start_map_processing(m_);
|
||||||
projection proj(m_.srs(),true);
|
projection proj(m_.srs(), true);
|
||||||
if (scale_denom <= 0.0)
|
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();
|
scale_denom *= p.scale_factor();
|
||||||
|
|
||||||
if (lyr.visible(scale_denom))
|
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.
|
* \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,
|
void feature_style_processor<Processor>::apply_to_layer(layer const& lay,
|
||||||
Processor & p,
|
Processor& p,
|
||||||
projection const& proj0,
|
projection const& proj0,
|
||||||
double scale,
|
double scale,
|
||||||
double scale_denom,
|
double scale_denom,
|
||||||
|
@ -197,16 +197,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay,
|
||||||
feature_style_context_map ctx_map;
|
feature_style_context_map ctx_map;
|
||||||
layer_rendering_material mat(lay, proj0);
|
layer_rendering_material mat(lay, proj0);
|
||||||
|
|
||||||
prepare_layer(mat,
|
prepare_layer(mat, ctx_map, p, scale, scale_denom, width, height, extent, buffer_size, names);
|
||||||
ctx_map,
|
|
||||||
p,
|
|
||||||
scale,
|
|
||||||
scale_denom,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
extent,
|
|
||||||
buffer_size,
|
|
||||||
names);
|
|
||||||
|
|
||||||
prepare_layers(mat, lay.layers(), ctx_map, p, scale_denom);
|
prepare_layers(mat, lay.layers(), ctx_map, p, scale_denom);
|
||||||
|
|
||||||
|
@ -214,17 +205,17 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay,
|
||||||
{
|
{
|
||||||
p.start_layer_processing(mat.lay_, mat.layer_ext2_);
|
p.start_layer_processing(mat.lay_, mat.layer_ext2_);
|
||||||
|
|
||||||
render_material(mat,p);
|
render_material(mat, p);
|
||||||
render_submaterials(mat, p);
|
render_submaterials(mat, p);
|
||||||
|
|
||||||
p.end_layer_processing(mat.lay_);
|
p.end_layer_processing(mat.lay_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Processor>
|
template<typename Processor>
|
||||||
void feature_style_processor<Processor>::prepare_layer(layer_rendering_material & mat,
|
void feature_style_processor<Processor>::prepare_layer(layer_rendering_material& mat,
|
||||||
feature_style_context_map & ctx_map,
|
feature_style_context_map& ctx_map,
|
||||||
Processor & p,
|
Processor& p,
|
||||||
double scale,
|
double scale,
|
||||||
double scale_denom,
|
double scale_denom,
|
||||||
unsigned width,
|
unsigned width,
|
||||||
|
@ -240,16 +231,14 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
std::size_t num_styles = style_names.size();
|
std::size_t num_styles = style_names.size();
|
||||||
if (num_styles == 0)
|
if (num_styles == 0)
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_DEBUG(feature_style_processor)
|
MAPNIK_LOG_DEBUG(feature_style_processor) << "feature_style_processor: No style for layer=" << lay.name();
|
||||||
<< "feature_style_processor: No style for layer=" << lay.name();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapnik::datasource_ptr ds = lay.datasource();
|
mapnik::datasource_ptr ds = lay.datasource();
|
||||||
if (!ds)
|
if (!ds)
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_DEBUG(feature_style_processor)
|
MAPNIK_LOG_DEBUG(feature_style_processor) << "feature_style_processor: No datasource for layer=" << lay.name();
|
||||||
<< "feature_style_processor: No datasource for layer=" << lay.name();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +261,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
buffered_query_ext.height(query_ext.height() + buffer_padding);
|
buffered_query_ext.height(query_ext.height() + buffer_padding);
|
||||||
|
|
||||||
// clip buffered extent by maximum extent, if supplied
|
// 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)
|
if (maximum_extent)
|
||||||
{
|
{
|
||||||
buffered_query_ext.clip(*maximum_extent);
|
buffered_query_ext.clip(*maximum_extent);
|
||||||
|
@ -295,15 +284,15 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
early_return = true;
|
early_return = true;
|
||||||
}
|
}
|
||||||
// next try intersection of layer extent back projected into map srs
|
// next try intersection of layer extent back projected into map srs
|
||||||
else if (proj_trans_ptr->backward(layer_ext, PROJ_ENVELOPE_POINTS) && buffered_query_ext_map_srs.intersects(layer_ext))
|
else if (proj_trans_ptr->backward(layer_ext, PROJ_ENVELOPE_POINTS) &&
|
||||||
|
buffered_query_ext_map_srs.intersects(layer_ext))
|
||||||
{
|
{
|
||||||
layer_ext.clip(buffered_query_ext_map_srs);
|
layer_ext.clip(buffered_query_ext_map_srs);
|
||||||
// forward project layer extent back into native projection
|
// forward project layer extent back into native projection
|
||||||
if (! proj_trans_ptr->forward(layer_ext, PROJ_ENVELOPE_POINTS))
|
if (!proj_trans_ptr->forward(layer_ext, PROJ_ENVELOPE_POINTS))
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_ERROR(feature_style_processor)
|
MAPNIK_LOG_ERROR(feature_style_processor)
|
||||||
<< "feature_style_processor: Layer=" << lay.name()
|
<< "feature_style_processor: Layer=" << lay.name() << " extent=" << layer_ext << " in map projection "
|
||||||
<< " extent=" << layer_ext << " in map projection "
|
|
||||||
<< " did not reproject properly back to layer projection";
|
<< " did not reproject properly back to layer projection";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,7 +302,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
early_return = true;
|
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)
|
if (early_return)
|
||||||
{
|
{
|
||||||
|
@ -321,7 +310,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
// https://github.com/mapnik/mapnik/issues/1477
|
// https://github.com/mapnik/mapnik/issues/1477
|
||||||
for (std::string const& style_name : style_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)
|
if (!style)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -346,7 +335,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
query_ext.clip(*maximum_extent);
|
query_ext.clip(*maximum_extent);
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> & layer_ext2 = mat.layer_ext2_;
|
box2d<double>& layer_ext2 = mat.layer_ext2_;
|
||||||
|
|
||||||
layer_ext2 = lay.envelope();
|
layer_ext2 = lay.envelope();
|
||||||
if (fw_success)
|
if (fw_success)
|
||||||
|
@ -365,17 +354,16 @@ 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);
|
attribute_collector collector(names);
|
||||||
|
|
||||||
// iterate through all named styles collecting active styles and attribute names
|
// iterate through all named styles collecting active styles and attribute names
|
||||||
for (std::string const& style_name : style_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)
|
if (!style)
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_ERROR(feature_style_processor)
|
MAPNIK_LOG_ERROR(feature_style_processor) << "feature_style_processor: Style=" << style_name
|
||||||
<< "feature_style_processor: Style=" << style_name
|
|
||||||
<< " required for layer=" << lay.name() << " does not exist.";
|
<< " required for layer=" << lay.name() << " does not exist.";
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -384,7 +372,7 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
std::vector<rule> const& style_rules = style->get_rules();
|
std::vector<rule> const& style_rules = style->get_rules();
|
||||||
bool active_rules = false;
|
bool active_rules = false;
|
||||||
rule_cache rc;
|
rule_cache rc;
|
||||||
for(rule const& r : style_rules)
|
for (rule const& r : style_rules)
|
||||||
{
|
{
|
||||||
if (r.active(scale_denom))
|
if (r.active(scale_denom))
|
||||||
{
|
{
|
||||||
|
@ -406,12 +394,11 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double qw = query_ext.width()>0 ? query_ext.width() : 1;
|
double qw = query_ext.width() > 0 ? query_ext.width() : 1;
|
||||||
double qh = query_ext.height()>0 ? query_ext.height() : 1;
|
double qh = query_ext.height() > 0 ? query_ext.height() : 1;
|
||||||
query::resolution_type res(width/qw,
|
query::resolution_type res(width / qw, height / qh);
|
||||||
height/qh);
|
|
||||||
|
|
||||||
query q(layer_ext,res,scale_denom,extent);
|
query q(layer_ext, res, scale_denom, extent);
|
||||||
q.set_variables(p.variables());
|
q.set_variables(p.variables());
|
||||||
|
|
||||||
if (p.attribute_collection_policy() == COLLECT_ALL)
|
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;
|
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)
|
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
|
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>
|
template<typename Processor>
|
||||||
void feature_style_processor<Processor>::render_submaterials(layer_rendering_material const & parent_mat,
|
void feature_style_processor<Processor>::render_submaterials(layer_rendering_material const& parent_mat, Processor& p)
|
||||||
Processor & p)
|
|
||||||
{
|
{
|
||||||
for (layer_rendering_material const & mat : parent_mat.materials_)
|
for (layer_rendering_material const& mat : parent_mat.materials_)
|
||||||
{
|
{
|
||||||
if (!mat.active_styles_.empty())
|
if (!mat.active_styles_.empty())
|
||||||
{
|
{
|
||||||
|
@ -472,12 +458,11 @@ void feature_style_processor<Processor>::render_submaterials(layer_rendering_mat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Processor>
|
template<typename Processor>
|
||||||
void feature_style_processor<Processor>::render_material(layer_rendering_material const & mat,
|
void feature_style_processor<Processor>::render_material(layer_rendering_material const& mat, Processor& p)
|
||||||
Processor & p)
|
|
||||||
{
|
{
|
||||||
std::vector<feature_type_style const*> const & active_styles = mat.active_styles_;
|
std::vector<feature_type_style const*> const& active_styles = mat.active_styles_;
|
||||||
std::vector<featureset_ptr> const & featureset_ptr_list = mat.featureset_ptr_list_;
|
std::vector<featureset_ptr> const& featureset_ptr_list = mat.featureset_ptr_list_;
|
||||||
if (featureset_ptr_list.empty())
|
if (featureset_ptr_list.empty())
|
||||||
{
|
{
|
||||||
// The datasource wasn't queried because of early return
|
// 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_;
|
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());
|
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;
|
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;
|
std::size_t i = 0;
|
||||||
for (feature_type_style const* style : active_styles)
|
for (feature_type_style const* style : active_styles)
|
||||||
{
|
{
|
||||||
|
|
||||||
cache->prepare();
|
cache->prepare();
|
||||||
render_style(p, style,
|
render_style(p, style, rule_caches[i++], cache, *proj_trans_ptr);
|
||||||
rule_caches[i++],
|
|
||||||
cache,
|
|
||||||
*proj_trans_ptr);
|
|
||||||
}
|
}
|
||||||
cache->clear();
|
cache->clear();
|
||||||
}
|
}
|
||||||
|
@ -550,7 +531,6 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
|
||||||
feature_ptr feature;
|
feature_ptr feature;
|
||||||
while ((feature = features->next()))
|
while ((feature = features->next()))
|
||||||
{
|
{
|
||||||
|
|
||||||
cache->push(feature);
|
cache->push(feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -558,9 +538,7 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
|
||||||
for (feature_type_style const* style : active_styles)
|
for (feature_type_style const* style : active_styles)
|
||||||
{
|
{
|
||||||
cache->prepare();
|
cache->prepare();
|
||||||
render_style(p, style,
|
render_style(p, style, rule_caches[i++], cache, *proj_trans_ptr);
|
||||||
rule_caches[i++],
|
|
||||||
cache, *proj_trans_ptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We only have a single style and no grouping.
|
// We only have a single style and no grouping.
|
||||||
|
@ -571,17 +549,13 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
|
||||||
for (feature_type_style const* style : active_styles)
|
for (feature_type_style const* style : active_styles)
|
||||||
{
|
{
|
||||||
featureset_ptr features = *featuresets++;
|
featureset_ptr features = *featuresets++;
|
||||||
render_style(p, style,
|
render_style(p, style, rule_caches[i++], features, *proj_trans_ptr);
|
||||||
rule_caches[i++],
|
|
||||||
features,
|
|
||||||
*proj_trans_ptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Processor>
|
template<typename Processor>
|
||||||
void feature_style_processor<Processor>::render_style(
|
void feature_style_processor<Processor>::render_style(Processor& p,
|
||||||
Processor & p,
|
|
||||||
feature_type_style const* style,
|
feature_type_style const* style,
|
||||||
rule_cache const& rc,
|
rule_cache const& rc,
|
||||||
featureset_ptr features,
|
featureset_ptr features,
|
||||||
|
@ -600,57 +574,58 @@ void feature_style_processor<Processor>::render_style(
|
||||||
{
|
{
|
||||||
bool do_else = true;
|
bool do_else = true;
|
||||||
bool do_also = false;
|
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();
|
expression_ptr const& expr = r->get_filter();
|
||||||
value_type result = util::apply_visitor(evaluate<feature_impl,value_type,attributes>(*feature,vars),*expr);
|
value_type result =
|
||||||
|
util::apply_visitor(evaluate<feature_impl, value_type, attributes>(*feature, vars), *expr);
|
||||||
if (result.to_bool())
|
if (result.to_bool())
|
||||||
{
|
{
|
||||||
was_painted = true;
|
was_painted = true;
|
||||||
do_else=false;
|
do_else = false;
|
||||||
do_also=true;
|
do_also = true;
|
||||||
rule::symbolizers const& symbols = r->get_symbolizers();
|
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)
|
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)
|
if (style->get_filter_mode() == FILTER_FIRST)
|
||||||
{
|
{
|
||||||
// Stop iterating over rules and proceed with next feature.
|
// Stop iterating over rules and proceed with next feature.
|
||||||
do_also=false;
|
do_also = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (do_else)
|
if (do_else)
|
||||||
{
|
{
|
||||||
for( rule const* r : rc.get_else_rules() )
|
for (rule const* r : rc.get_else_rules())
|
||||||
{
|
{
|
||||||
was_painted = true;
|
was_painted = true;
|
||||||
rule::symbolizers const& symbols = r->get_symbolizers();
|
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)
|
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)
|
if (do_also)
|
||||||
{
|
{
|
||||||
for( rule const* r : rc.get_also_rules() )
|
for (rule const* r : rc.get_also_rules())
|
||||||
{
|
{
|
||||||
was_painted = true;
|
was_painted = true;
|
||||||
rule::symbolizers const& symbols = r->get_symbolizers();
|
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)
|
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);
|
p.end_style_processing(*style);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
|
@ -39,24 +39,19 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class rule;
|
class rule;
|
||||||
|
|
||||||
enum filter_mode_enum {
|
enum filter_mode_enum { FILTER_ALL, FILTER_FIRST, filter_mode_enum_MAX };
|
||||||
FILTER_ALL,
|
|
||||||
FILTER_FIRST,
|
|
||||||
filter_mode_enum_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
DEFINE_ENUM( filter_mode_e, filter_mode_enum );
|
DEFINE_ENUM(filter_mode_e, filter_mode_enum);
|
||||||
|
|
||||||
using rules = std::vector<rule>;
|
using rules = std::vector<rule>;
|
||||||
|
|
||||||
class MAPNIK_DECL feature_type_style
|
class MAPNIK_DECL feature_type_style
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
rules rules_;
|
rules rules_;
|
||||||
filter_mode_e filter_mode_;
|
filter_mode_e filter_mode_;
|
||||||
// image_filters
|
// image_filters
|
||||||
|
@ -66,18 +61,19 @@ private:
|
||||||
boost::optional<composite_mode_e> comp_op_;
|
boost::optional<composite_mode_e> comp_op_;
|
||||||
float opacity_;
|
float opacity_;
|
||||||
bool image_filters_inflate_;
|
bool image_filters_inflate_;
|
||||||
friend void swap(feature_type_style& lhs, feature_type_style & rhs);
|
friend void swap(feature_type_style& lhs, feature_type_style& rhs);
|
||||||
public:
|
|
||||||
|
public:
|
||||||
// ctor
|
// ctor
|
||||||
feature_type_style();
|
feature_type_style();
|
||||||
feature_type_style(feature_type_style const& rhs);
|
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);
|
feature_type_style& operator=(feature_type_style rhs);
|
||||||
|
|
||||||
// comparison
|
// comparison
|
||||||
bool operator==(feature_type_style const& rhs) const;
|
bool operator==(feature_type_style const& rhs) const;
|
||||||
|
|
||||||
void add_rule(rule && rule);
|
void add_rule(rule&& rule);
|
||||||
rules const& get_rules() const;
|
rules const& get_rules() const;
|
||||||
rules& get_rules_nonconst();
|
rules& get_rules_nonconst();
|
||||||
|
|
||||||
|
@ -88,9 +84,9 @@ public:
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
std::vector<filter::filter_type> const& image_filters() const;
|
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> const& direct_image_filters() const;
|
||||||
std::vector<filter::filter_type> & direct_image_filters();
|
std::vector<filter::filter_type>& direct_image_filters();
|
||||||
// compositing
|
// compositing
|
||||||
void set_comp_op(composite_mode_e comp_op);
|
void set_comp_op(composite_mode_e comp_op);
|
||||||
boost::optional<composite_mode_e> comp_op() const;
|
boost::optional<composite_mode_e> comp_op() const;
|
||||||
|
@ -98,14 +94,10 @@ public:
|
||||||
float get_opacity() const;
|
float get_opacity() const;
|
||||||
void set_image_filters_inflate(bool inflate);
|
void set_image_filters_inflate(bool inflate);
|
||||||
bool image_filters_inflate() const;
|
bool image_filters_inflate() const;
|
||||||
inline void reserve(std::size_t size)
|
inline void reserve(std::size_t size) { rules_.reserve(size); }
|
||||||
{
|
|
||||||
rules_.reserve(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
~feature_type_style() {}
|
~feature_type_style() {}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_TYPE_STYLE_HPP
|
#endif // MAPNIK_FEATURE_TYPE_STYLE_HPP
|
||||||
|
|
|
@ -43,10 +43,7 @@ struct MAPNIK_DECL Featureset : private util::noncopyable
|
||||||
|
|
||||||
struct MAPNIK_DECL invalid_featureset final : Featureset
|
struct MAPNIK_DECL invalid_featureset final : Featureset
|
||||||
{
|
{
|
||||||
feature_ptr next()
|
feature_ptr next() { return feature_ptr(); }
|
||||||
{
|
|
||||||
return feature_ptr();
|
|
||||||
}
|
|
||||||
~invalid_featureset() {}
|
~invalid_featureset() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -62,6 +59,6 @@ inline bool is_valid(featureset_ptr const& ptr)
|
||||||
return (dynamic_cast<invalid_featureset*>(ptr.get()) == nullptr) ? true : false;
|
return (dynamic_cast<invalid_featureset*>(ptr.get()) == nullptr) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURESET_HPP
|
#endif // MAPNIK_FEATURESET_HPP
|
||||||
|
|
|
@ -29,14 +29,16 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class filter_featureset : public Featureset
|
class filter_featureset : public Featureset
|
||||||
{
|
{
|
||||||
using filter_type = T;
|
using filter_type = T;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
filter_featureset(featureset_ptr const& fs, filter_type && filter)
|
filter_featureset(featureset_ptr const& fs, filter_type&& filter)
|
||||||
: fs_(fs), filter_(std::move(filter)) {}
|
: fs_(fs)
|
||||||
|
, filter_(std::move(filter))
|
||||||
|
{}
|
||||||
|
|
||||||
feature_ptr next()
|
feature_ptr next()
|
||||||
{
|
{
|
||||||
|
@ -48,10 +50,10 @@ public:
|
||||||
return feature;
|
return feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
featureset_ptr fs_;
|
featureset_ptr fs_;
|
||||||
filter_type filter_;
|
filter_type filter_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FILTER_FEATURESET_HPP
|
#endif // MAPNIK_FILTER_FEATURESET_HPP
|
||||||
|
|
|
@ -36,10 +36,12 @@
|
||||||
#include <utility> // pair
|
#include <utility> // pair
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace boost { template <class T> class optional; }
|
namespace boost {
|
||||||
|
template<class T>
|
||||||
|
class optional;
|
||||||
|
}
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class stroker;
|
class stroker;
|
||||||
using stroker_ptr = std::shared_ptr<stroker>;
|
using stroker_ptr = std::shared_ptr<stroker>;
|
||||||
|
@ -53,8 +55,9 @@ class MAPNIK_DECL freetype_engine : public singleton<freetype_engine, CreateUsin
|
||||||
{
|
{
|
||||||
friend class CreateUsingNew<freetype_engine>;
|
friend class CreateUsingNew<freetype_engine>;
|
||||||
friend class Map;
|
friend class Map;
|
||||||
public:
|
|
||||||
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>>;
|
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);
|
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 bool register_fonts(std::string const& dir, bool recurse = false);
|
||||||
static std::vector<std::string> face_names();
|
static std::vector<std::string> face_names();
|
||||||
static font_file_mapping_type const& get_mapping();
|
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,
|
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& font_file_mapping,
|
||||||
font_file_mapping_type const& global_font_file_mapping);
|
font_file_mapping_type const& global_font_file_mapping);
|
||||||
|
|
||||||
static face_ptr create_face(std::string const& face_name,
|
static face_ptr create_face(std::string const& face_name,
|
||||||
font_library & library,
|
font_library& library,
|
||||||
font_file_mapping_type const& font_file_mapping,
|
font_file_mapping_type const& font_file_mapping,
|
||||||
freetype_engine::font_memory_cache_type const& font_cache,
|
freetype_engine::font_memory_cache_type const& font_cache,
|
||||||
font_file_mapping_type const& global_font_file_mapping,
|
font_file_mapping_type const& global_font_file_mapping,
|
||||||
freetype_engine::font_memory_cache_type & global_memory_fonts);
|
freetype_engine::font_memory_cache_type& global_memory_fonts);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
bool is_font_file_impl(std::string const& file_name);
|
bool is_font_file_impl(std::string const& file_name);
|
||||||
std::vector<std::string> face_names_impl();
|
std::vector<std::string> face_names_impl();
|
||||||
font_file_mapping_type const& get_mapping_impl();
|
font_file_mapping_type const& get_mapping_impl();
|
||||||
font_memory_cache_type& get_cache_impl();
|
font_memory_cache_type& get_cache_impl();
|
||||||
bool can_open_impl(std::string const& face_name,
|
bool can_open_impl(std::string const& face_name,
|
||||||
font_library & library,
|
font_library& library,
|
||||||
font_file_mapping_type const& font_file_mapping,
|
font_file_mapping_type const& font_file_mapping,
|
||||||
font_file_mapping_type const& global_font_file_mapping);
|
font_file_mapping_type const& global_font_file_mapping);
|
||||||
|
|
||||||
face_ptr create_face_impl(std::string const& face_name,
|
face_ptr create_face_impl(std::string const& face_name,
|
||||||
font_library & library,
|
font_library& library,
|
||||||
font_file_mapping_type const& font_file_mapping,
|
font_file_mapping_type const& font_file_mapping,
|
||||||
freetype_engine::font_memory_cache_type const& font_cache,
|
freetype_engine::font_memory_cache_type const& font_cache,
|
||||||
font_file_mapping_type const& global_font_file_mapping,
|
font_file_mapping_type const& global_font_file_mapping,
|
||||||
freetype_engine::font_memory_cache_type & global_memory_fonts);
|
freetype_engine::font_memory_cache_type& global_memory_fonts);
|
||||||
bool register_font_impl(std::string const& file_name);
|
bool register_font_impl(std::string const& file_name);
|
||||||
bool register_fonts_impl(std::string const& dir, bool recurse);
|
bool register_fonts_impl(std::string const& dir, bool recurse);
|
||||||
bool register_font_impl(std::string const& file_name, FT_LibraryRec_ * library);
|
bool register_font_impl(std::string const& file_name, FT_LibraryRec_* library);
|
||||||
bool register_fonts_impl(std::string const& dir, FT_LibraryRec_ * library, bool recurse = false);
|
bool register_fonts_impl(std::string const& dir, FT_LibraryRec_* library, bool recurse = false);
|
||||||
bool register_font_impl(std::string const& file_name,
|
bool
|
||||||
font_library & libary,
|
register_font_impl(std::string const& file_name, font_library& libary, font_file_mapping_type& font_file_mapping);
|
||||||
font_file_mapping_type & font_file_mapping);
|
|
||||||
bool register_fonts_impl(std::string const& dir,
|
bool register_fonts_impl(std::string const& dir,
|
||||||
font_library & libary,
|
font_library& libary,
|
||||||
font_file_mapping_type & font_file_mapping,
|
font_file_mapping_type& font_file_mapping,
|
||||||
bool recurse = false);
|
bool recurse = false);
|
||||||
font_file_mapping_type global_font_file_mapping_;
|
font_file_mapping_type global_font_file_mapping_;
|
||||||
font_memory_cache_type global_memory_fonts_;
|
font_memory_cache_type global_memory_fonts_;
|
||||||
|
@ -107,8 +110,8 @@ private:
|
||||||
|
|
||||||
class MAPNIK_DECL face_manager
|
class MAPNIK_DECL face_manager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
face_manager(font_library & library,
|
face_manager(font_library& library,
|
||||||
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
||||||
freetype_engine::font_memory_cache_type const& font_cache);
|
freetype_engine::font_memory_cache_type const& font_cache);
|
||||||
face_ptr get_face(std::string const& name);
|
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);
|
face_set_ptr get_face_set(std::string const& name, boost::optional<font_set> fset);
|
||||||
stroker_ptr get_stroker() const { return stroker_; }
|
stroker_ptr get_stroker() const { return stroker_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using face_cache = std::map<std::string, face_ptr>;
|
using face_cache = std::map<std::string, face_ptr>;
|
||||||
using face_cache_ptr = std::shared_ptr<face_cache>;
|
using face_cache_ptr = std::shared_ptr<face_cache>;
|
||||||
|
|
||||||
face_cache_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_file_mapping_type const& font_file_mapping_;
|
||||||
freetype_engine::font_memory_cache_type const& font_memory_cache_;
|
freetype_engine::font_memory_cache_type const& font_memory_cache_;
|
||||||
stroker_ptr stroker_;
|
stroker_ptr stroker_;
|
||||||
|
@ -130,6 +133,6 @@ private:
|
||||||
|
|
||||||
using face_manager_freetype = face_manager;
|
using face_manager_freetype = face_manager;
|
||||||
extern template class MAPNIK_DECL singleton<freetype_engine, CreateUsingNew>;
|
extern template class MAPNIK_DECL singleton<freetype_engine, CreateUsingNew>;
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FONT_ENGINE_FREETYPE_HPP
|
#endif // MAPNIK_FONT_ENGINE_FREETYPE_HPP
|
||||||
|
|
|
@ -30,15 +30,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
class MAPNIK_DECL font_set
|
class MAPNIK_DECL font_set
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor/copy/move/dtor
|
// ctor/copy/move/dtor
|
||||||
font_set(std::string const& name);
|
font_set(std::string const& name);
|
||||||
font_set(font_set const& rhs);
|
font_set(font_set const& rhs);
|
||||||
font_set(font_set &&);
|
font_set(font_set&&);
|
||||||
font_set& operator=(font_set rhs);
|
font_set& operator=(font_set rhs);
|
||||||
~font_set();
|
~font_set();
|
||||||
// comparison
|
// comparison
|
||||||
|
@ -49,11 +48,11 @@ public:
|
||||||
void add_face_name(std::string const& face_name);
|
void add_face_name(std::string const& face_name);
|
||||||
std::vector<std::string> const& get_face_names() const;
|
std::vector<std::string> const& get_face_names() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend void swap(font_set & lhs, font_set & rhs);
|
friend void swap(font_set& lhs, font_set& rhs);
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::vector<std::string> face_names_;
|
std::vector<std::string> face_names_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FONT_SET_HPP
|
#endif // MAPNIK_FONT_SET_HPP
|
||||||
|
|
|
@ -42,75 +42,51 @@ char const* binary_function_name(binary_function_impl const& fun);
|
||||||
// exp
|
// exp
|
||||||
struct exp_impl
|
struct exp_impl
|
||||||
{
|
{
|
||||||
//using type = T;
|
// using type = T;
|
||||||
value_type operator() (value_type const& val) const
|
value_type operator()(value_type const& val) const { return std::exp(val.to_double()); }
|
||||||
{
|
|
||||||
return std::exp(val.to_double());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// log
|
// log
|
||||||
struct log_impl
|
struct log_impl
|
||||||
{
|
{
|
||||||
//using type = T;
|
// using type = T;
|
||||||
value_type operator() (value_type const& val) const
|
value_type operator()(value_type const& val) const { return std::log(val.to_double()); }
|
||||||
{
|
|
||||||
return std::log(val.to_double());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// sin
|
// sin
|
||||||
struct sin_impl
|
struct sin_impl
|
||||||
{
|
{
|
||||||
value_type operator() (value_type const& val) const
|
value_type operator()(value_type const& val) const { return std::sin(val.to_double()); }
|
||||||
{
|
|
||||||
return std::sin(val.to_double());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// cos
|
// cos
|
||||||
struct cos_impl
|
struct cos_impl
|
||||||
{
|
{
|
||||||
value_type operator() (value_type const& val) const
|
value_type operator()(value_type const& val) const { return std::cos(val.to_double()); }
|
||||||
{
|
|
||||||
return std::cos(val.to_double());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// tan
|
// tan
|
||||||
struct tan_impl
|
struct tan_impl
|
||||||
{
|
{
|
||||||
value_type operator() (value_type const& val) const
|
value_type operator()(value_type const& val) const { return std::tan(val.to_double()); }
|
||||||
{
|
|
||||||
return std::tan(val.to_double());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// atan
|
// atan
|
||||||
struct atan_impl
|
struct atan_impl
|
||||||
{
|
{
|
||||||
value_type operator()(value_type const& val) const
|
value_type operator()(value_type const& val) const { return std::atan(val.to_double()); }
|
||||||
{
|
|
||||||
return std::atan(val.to_double());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// abs
|
// abs
|
||||||
struct abs_impl
|
struct abs_impl
|
||||||
{
|
{
|
||||||
value_type operator() (value_type const& val) const
|
value_type operator()(value_type const& val) const { return std::abs(val.to_double()); }
|
||||||
{
|
|
||||||
return std::abs(val.to_double());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// length
|
// length
|
||||||
struct length_impl
|
struct length_impl
|
||||||
{
|
{
|
||||||
value_type operator() (value_type const& val) const
|
value_type operator()(value_type const& val) const { return val.to_unicode().length(); }
|
||||||
{
|
|
||||||
return val.to_unicode().length();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// min
|
// min
|
||||||
|
|
|
@ -42,52 +42,57 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
template<typename T>
|
||||||
template <typename T>
|
bool clip_test(T p, T q, double& tmin, double& tmax)
|
||||||
bool clip_test(T p,T q,double& tmin,double& tmax)
|
|
||||||
{
|
{
|
||||||
double r = 0;
|
double r = 0;
|
||||||
bool result=true;
|
bool result = true;
|
||||||
if (p<0.0)
|
if (p < 0.0)
|
||||||
{
|
{
|
||||||
r=q/p;
|
r = q / p;
|
||||||
if (r>tmax) result=false;
|
if (r > tmax)
|
||||||
else if (r>tmin) tmin=r;
|
result = false;
|
||||||
|
else if (r > tmin)
|
||||||
|
tmin = r;
|
||||||
}
|
}
|
||||||
else if (p>0.0)
|
else if (p > 0.0)
|
||||||
{
|
{
|
||||||
r=q/p;
|
r = q / p;
|
||||||
if (r<tmin) result=false;
|
if (r < tmin)
|
||||||
else if (r<tmax) tmax=r;
|
result = false;
|
||||||
} else if (q<0.0) result=false;
|
else if (r < tmax)
|
||||||
|
tmax = r;
|
||||||
|
}
|
||||||
|
else if (q < 0.0)
|
||||||
|
result = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T,typename Image>
|
template<typename T, typename Image>
|
||||||
bool clip_line(T& x0,T& y0,T& x1,T& y1,box2d<T> const& box)
|
bool clip_line(T& x0, T& y0, T& x1, T& y1, box2d<T> const& box)
|
||||||
{
|
{
|
||||||
double tmin=0.0;
|
double tmin = 0.0;
|
||||||
double tmax=1.0;
|
double tmax = 1.0;
|
||||||
double dx=x1-x0;
|
double dx = x1 - x0;
|
||||||
if (clip_test<double>(-dx,x0,tmin,tmax))
|
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;
|
double dy = y1 - y0;
|
||||||
if (clip_test<double>(-dy,y0,tmin,tmax))
|
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);
|
x1 = static_cast<T>(x0 + tmax * dx);
|
||||||
y1=static_cast<T>(y0+tmax*dy);
|
y1 = static_cast<T>(y0 + tmax * dy);
|
||||||
}
|
}
|
||||||
if (tmin>0.0)
|
if (tmin > 0.0)
|
||||||
{
|
{
|
||||||
x0+=static_cast<T>(tmin*dx);
|
x0 += static_cast<T>(tmin * dx);
|
||||||
y0+=static_cast<T>(tmin*dy);
|
y0 += static_cast<T>(tmin * dy);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -97,37 +102,35 @@ bool clip_line(T& x0,T& y0,T& x1,T& y1,box2d<T> const& box)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Iter>
|
template<typename Iter>
|
||||||
inline bool point_inside_path(double x,double y,Iter start,Iter end)
|
inline bool point_inside_path(double x, double y, Iter start, Iter end)
|
||||||
{
|
{
|
||||||
bool inside=false;
|
bool inside = false;
|
||||||
double x0=std::get<0>(*start);
|
double x0 = std::get<0>(*start);
|
||||||
double y0=std::get<1>(*start);
|
double y0 = std::get<1>(*start);
|
||||||
|
|
||||||
double x1 = 0;
|
double x1 = 0;
|
||||||
double y1 = 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);
|
x0 = std::get<0>(*start);
|
||||||
y0 = std::get<1>(*start);
|
y0 = std::get<1>(*start);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
x1=std::get<0>(*start);
|
x1 = std::get<0>(*start);
|
||||||
y1=std::get<1>(*start);
|
y1 = std::get<1>(*start);
|
||||||
|
|
||||||
if ((((y1 <= y) && (y < y0)) ||
|
if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
|
||||||
((y0 <= y) && (y < y1))) &&
|
inside = !inside;
|
||||||
( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
|
x0 = x1;
|
||||||
inside=!inside;
|
y0 = y1;
|
||||||
x0=x1;
|
|
||||||
y0=y1;
|
|
||||||
}
|
}
|
||||||
return inside;
|
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 dx = x - cx;
|
||||||
double dy = y - cy;
|
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);
|
return (d2 <= r * r);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
inline T sqr(T x)
|
inline T sqr(T x)
|
||||||
{
|
{
|
||||||
return x * 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));
|
return std::sqrt(distance2(x0, y0, x1, y1));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double point_to_segment_distance(double x, double y,
|
inline double point_to_segment_distance(double x, double y, double ax, double ay, double bx, double by)
|
||||||
double ax, double ay,
|
|
||||||
double bx, double by)
|
|
||||||
{
|
{
|
||||||
double len2 = distance2(ax, ay, bx, by);
|
double len2 = distance2(ax, ay, bx, by);
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ inline double point_to_segment_distance(double x, double y,
|
||||||
return std::fabs(s) * std::sqrt(len2);
|
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)
|
inline bool point_on_path(double x, double y, Iter start, Iter end, double tol)
|
||||||
{
|
{
|
||||||
double x0 = std::get<0>(*start);
|
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
|
// filters
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct bounding_box_filter
|
struct bounding_box_filter
|
||||||
{
|
{
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
box2d<value_type> box_;
|
box2d<value_type> box_;
|
||||||
explicit bounding_box_filter(box2d<value_type> const& box)
|
explicit bounding_box_filter(box2d<value_type> const& box)
|
||||||
: box_(box) {}
|
: box_(box)
|
||||||
|
{}
|
||||||
|
|
||||||
bool pass(box2d<value_type> const& extent) const
|
bool pass(box2d<value_type> const& extent) const { return extent.intersects(box_); }
|
||||||
{
|
|
||||||
return extent.intersects(box_);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using filter_in_box = bounding_box_filter<double>;
|
using filter_in_box = bounding_box_filter<double>;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct at_point_filter
|
struct at_point_filter
|
||||||
{
|
{
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
@ -232,40 +231,39 @@ struct at_point_filter
|
||||||
box_.pad(tol);
|
box_.pad(tol);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pass(box2d<value_type> const& extent) const
|
bool pass(box2d<value_type> const& extent) const { return extent.intersects(box_); }
|
||||||
{
|
|
||||||
return extent.intersects(box_);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using filter_at_point = at_point_filter<double>;
|
using filter_at_point = at_point_filter<double>;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
template <typename PathType>
|
template<typename PathType>
|
||||||
double path_length(PathType & path)
|
double path_length(PathType& path)
|
||||||
{
|
{
|
||||||
double x0 = 0;
|
double x0 = 0;
|
||||||
double y0 = 0;
|
double y0 = 0;
|
||||||
double x1 = 0;
|
double x1 = 0;
|
||||||
double y1 = 0;
|
double y1 = 0;
|
||||||
path.rewind(0);
|
path.rewind(0);
|
||||||
unsigned command = path.vertex(&x0,&y0);
|
unsigned command = path.vertex(&x0, &y0);
|
||||||
if (command == SEG_END) return 0;
|
if (command == SEG_END)
|
||||||
|
return 0;
|
||||||
double length = 0;
|
double length = 0;
|
||||||
while (SEG_END != (command = path.vertex(&x1, &y1)))
|
while (SEG_END != (command = path.vertex(&x1, &y1)))
|
||||||
{
|
{
|
||||||
if (command == SEG_CLOSE) continue;
|
if (command == SEG_CLOSE)
|
||||||
length += distance(x0,y0,x1,y1);
|
continue;
|
||||||
|
length += distance(x0, y0, x1, y1);
|
||||||
x0 = x1;
|
x0 = x1;
|
||||||
y0 = y1;
|
y0 = y1;
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename PathType>
|
template<typename PathType>
|
||||||
bool hit_test_first(PathType & path, double x, double y)
|
bool hit_test_first(PathType& path, double x, double y)
|
||||||
{
|
{
|
||||||
bool inside=false;
|
bool inside = false;
|
||||||
double x0 = 0;
|
double x0 = 0;
|
||||||
double y0 = 0;
|
double y0 = 0;
|
||||||
double x1 = 0;
|
double x1 = 0;
|
||||||
|
@ -291,10 +289,8 @@ bool hit_test_first(PathType & path, double x, double y)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((((y1 <= y) && (y < y0)) ||
|
if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
|
||||||
((y0 <= y) && (y < y1))) &&
|
inside = !inside;
|
||||||
(x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
|
|
||||||
inside=!inside;
|
|
||||||
|
|
||||||
x0 = x1;
|
x0 = x1;
|
||||||
y0 = y1;
|
y0 = y1;
|
||||||
|
@ -304,8 +300,8 @@ bool hit_test_first(PathType & path, double x, double y)
|
||||||
|
|
||||||
namespace label {
|
namespace label {
|
||||||
|
|
||||||
template <typename PathType>
|
template<typename PathType>
|
||||||
bool middle_point(PathType & path, double & x, double & y, boost::optional<double&> angle = boost::none)
|
bool middle_point(PathType& path, double& x, double& y, boost::optional<double&> angle = boost::none)
|
||||||
{
|
{
|
||||||
double x0 = 0;
|
double x0 = 0;
|
||||||
double y0 = 0;
|
double y0 = 0;
|
||||||
|
@ -313,8 +309,9 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional<doubl
|
||||||
double y1 = 0;
|
double y1 = 0;
|
||||||
double mid_length = 0.5 * path_length(path);
|
double mid_length = 0.5 * path_length(path);
|
||||||
path.rewind(0);
|
path.rewind(0);
|
||||||
unsigned command = path.vertex(&x0,&y0);
|
unsigned command = path.vertex(&x0, &y0);
|
||||||
if (command == SEG_END) return false;
|
if (command == SEG_END)
|
||||||
|
return false;
|
||||||
if (std::abs(mid_length) < std::numeric_limits<double>::epsilon())
|
if (std::abs(mid_length) < std::numeric_limits<double>::epsilon())
|
||||||
{
|
{
|
||||||
x = x0;
|
x = x0;
|
||||||
|
@ -324,12 +321,13 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional<doubl
|
||||||
double dist = 0.0;
|
double dist = 0.0;
|
||||||
while (SEG_END != (command = path.vertex(&x1, &y1)))
|
while (SEG_END != (command = path.vertex(&x1, &y1)))
|
||||||
{
|
{
|
||||||
if (command == SEG_CLOSE) continue;
|
if (command == SEG_CLOSE)
|
||||||
|
continue;
|
||||||
double seg_length = distance(x0, y0, x1, y1);
|
double seg_length = distance(x0, y0, x1, y1);
|
||||||
|
|
||||||
if ( dist + seg_length >= mid_length)
|
if (dist + seg_length >= mid_length)
|
||||||
{
|
{
|
||||||
double r = (mid_length - dist)/seg_length;
|
double r = (mid_length - dist) / seg_length;
|
||||||
x = x0 + (x1 - x0) * r;
|
x = x0 + (x1 - x0) * r;
|
||||||
y = y0 + (y1 - y0) * r;
|
y = y0 + (y1 - y0) * r;
|
||||||
if (angle)
|
if (angle)
|
||||||
|
@ -345,14 +343,15 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional<doubl
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename PathType>
|
template<typename PathType>
|
||||||
bool centroid(PathType & path, double & x, double & y)
|
bool centroid(PathType& path, double& x, double& y)
|
||||||
{
|
{
|
||||||
geometry::point<double> p0, p1, move_to, start;
|
geometry::point<double> p0, p1, move_to, start;
|
||||||
|
|
||||||
path.rewind(0);
|
path.rewind(0);
|
||||||
unsigned command = path.vertex(&p0.x, &p0.y);
|
unsigned command = path.vertex(&p0.x, &p0.y);
|
||||||
if (command == SEG_END) return false;
|
if (command == SEG_END)
|
||||||
|
return false;
|
||||||
|
|
||||||
start = move_to = p0;
|
start = move_to = p0;
|
||||||
|
|
||||||
|
@ -380,7 +379,6 @@ bool centroid(PathType & path, double & x, double & y)
|
||||||
xtmp += (dx1 + dx0) * ai;
|
xtmp += (dx1 + dx0) * ai;
|
||||||
ytmp += (dy1 + dy0) * ai;
|
ytmp += (dy1 + dy0) * ai;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
p0 = p1;
|
p0 = p1;
|
||||||
++count;
|
++count;
|
||||||
|
@ -478,10 +476,10 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename PathType>
|
template<typename PathType>
|
||||||
bool hit_test(PathType & path, double x, double y, double tol)
|
bool hit_test(PathType& path, double x, double y, double tol)
|
||||||
{
|
{
|
||||||
bool inside=false;
|
bool inside = false;
|
||||||
double x0 = 0;
|
double x0 = 0;
|
||||||
double y0 = 0;
|
double y0 = 0;
|
||||||
double x1 = 0;
|
double x1 = 0;
|
||||||
|
@ -512,19 +510,15 @@ bool hit_test(PathType & path, double x, double y, double tol)
|
||||||
x1 = start_x;
|
x1 = start_x;
|
||||||
y1 = start_y;
|
y1 = start_y;
|
||||||
}
|
}
|
||||||
switch(geom_type)
|
switch (geom_type)
|
||||||
{
|
{
|
||||||
case mapnik::geometry::geometry_types::Polygon:
|
case mapnik::geometry::geometry_types::Polygon: {
|
||||||
{
|
if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1))
|
||||||
if ((((y1 <= y) && (y < y0)) ||
|
inside = !inside;
|
||||||
((y0 <= y) && (y < y1))) &&
|
|
||||||
(x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
|
|
||||||
inside=!inside;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case mapnik::geometry::geometry_types::LineString:
|
case mapnik::geometry::geometry_types::LineString: {
|
||||||
{
|
double distance = point_to_segment_distance(x, y, x0, y0, x1, y1);
|
||||||
double distance = point_to_segment_distance(x,y,x0,y0,x1,y1);
|
|
||||||
if (distance < tol)
|
if (distance < tol)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
@ -544,6 +538,7 @@ bool hit_test(PathType & path, double x, double y, double tol)
|
||||||
return inside;
|
return inside;
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace label
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOM_UTIL_HPP
|
#endif // MAPNIK_GEOM_UTIL_HPP
|
||||||
|
|
|
@ -38,14 +38,16 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T, template <typename...> class Cont = std::vector>
|
template<typename T, template<typename...> class Cont = std::vector>
|
||||||
struct geometry_collection;
|
struct geometry_collection;
|
||||||
|
|
||||||
struct geometry_empty {};
|
struct geometry_empty
|
||||||
|
{};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using geometry_base = mapnik::util::variant<geometry_empty,
|
using geometry_base = mapnik::util::variant<geometry_empty,
|
||||||
point<T>,
|
point<T>,
|
||||||
line_string<T>,
|
line_string<T>,
|
||||||
|
@ -53,13 +55,13 @@ using geometry_base = mapnik::util::variant<geometry_empty,
|
||||||
multi_point<T>,
|
multi_point<T>,
|
||||||
multi_line_string<T>,
|
multi_line_string<T>,
|
||||||
multi_polygon<T>,
|
multi_polygon<T>,
|
||||||
geometry_collection<T> >;
|
geometry_collection<T>>;
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct geometry : geometry_base<T>
|
struct geometry : geometry_base<T>
|
||||||
{
|
{
|
||||||
using coordinate_type = 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;
|
using geometry_base<T>::geometry_base;
|
||||||
|
|
||||||
|
@ -67,20 +69,21 @@ struct geometry : geometry_base<T>
|
||||||
|
|
||||||
geometry() = default;
|
geometry() = default;
|
||||||
|
|
||||||
template <typename G>
|
template<typename G>
|
||||||
geometry(G && geom)
|
geometry(G&& geom)
|
||||||
: geometry_base<T>(std::forward<G>(geom)) {}
|
: geometry_base<T>(std::forward<G>(geom))
|
||||||
|
{}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T, template<typename...> class Cont>
|
||||||
template <typename T, template <typename...> class Cont>
|
|
||||||
struct geometry_collection : Cont<geometry<T>>
|
struct geometry_collection : Cont<geometry<T>>
|
||||||
{
|
{
|
||||||
using coordinate_type = T;
|
using coordinate_type = T;
|
||||||
};
|
};
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif //MAPNIK_GEOMETRY_HPP
|
#endif // MAPNIK_GEOMETRY_HPP
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
|
#ifndef MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
|
||||||
#define MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
|
#define MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
|
||||||
|
|
||||||
|
@ -45,7 +44,11 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
#include <mapnik/geometry/box2d.hpp>
|
#include <mapnik/geometry/box2d.hpp>
|
||||||
|
|
||||||
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::geometry::point<double>, double, boost::geometry::cs::cartesian, x, y)
|
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::geometry::point<double>, double, boost::geometry::cs::cartesian, x, y)
|
||||||
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point<std::int64_t>, std::int64_t, boost::geometry::cs::cartesian, x, y)
|
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::geometry::point<std::int64_t>,
|
||||||
|
std::int64_t,
|
||||||
|
boost::geometry::cs::cartesian,
|
||||||
|
x,
|
||||||
|
y)
|
||||||
BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(mapnik::geometry::line_string)
|
BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(mapnik::geometry::line_string)
|
||||||
BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(mapnik::geometry::linear_ring)
|
BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(mapnik::geometry::linear_ring)
|
||||||
// needed by box2d<T>
|
// needed by box2d<T>
|
||||||
|
@ -54,7 +57,7 @@ BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::coord2f, float, boost::geometry::cs::c
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct const_interior_rings
|
struct const_interior_rings
|
||||||
{
|
{
|
||||||
using polygon_type = mapnik::geometry::polygon<CoordinateType> const;
|
using polygon_type = mapnik::geometry::polygon<CoordinateType> const;
|
||||||
|
@ -63,7 +66,8 @@ struct const_interior_rings
|
||||||
using value_type = typename polygon_type::value_type;
|
using value_type = typename polygon_type::value_type;
|
||||||
|
|
||||||
const_interior_rings(polygon_type const& poly)
|
const_interior_rings(polygon_type const& poly)
|
||||||
: poly_(poly) {}
|
: poly_(poly)
|
||||||
|
{}
|
||||||
|
|
||||||
const_iterator begin() const
|
const_iterator begin() const
|
||||||
{
|
{
|
||||||
|
@ -72,19 +76,15 @@ struct const_interior_rings
|
||||||
return itr;
|
return itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const_iterator end() const { return poly_.cend();}
|
const_iterator end() const { return poly_.cend(); }
|
||||||
|
|
||||||
std::size_t size() const
|
std::size_t size() const { return poly_.empty() ? 0 : poly_.size() - 1; }
|
||||||
{
|
|
||||||
return poly_.empty() ? 0 : poly_.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type const& back() const { return poly_.back(); }
|
value_type const& back() const { return poly_.back(); }
|
||||||
polygon_type const& poly_;
|
polygon_type const& poly_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename CoordinateType>
|
||||||
template <typename CoordinateType>
|
|
||||||
struct interior_rings
|
struct interior_rings
|
||||||
{
|
{
|
||||||
using polygon_type = mapnik::geometry::polygon<CoordinateType>;
|
using polygon_type = mapnik::geometry::polygon<CoordinateType>;
|
||||||
|
@ -92,8 +92,9 @@ struct interior_rings
|
||||||
using const_iterator = typename polygon_type::const_iterator;
|
using const_iterator = typename polygon_type::const_iterator;
|
||||||
using value_type = typename polygon_type::value_type;
|
using value_type = typename polygon_type::value_type;
|
||||||
|
|
||||||
interior_rings(polygon_type & poly)
|
interior_rings(polygon_type& poly)
|
||||||
: poly_(poly) {}
|
: poly_(poly)
|
||||||
|
{}
|
||||||
|
|
||||||
iterator begin()
|
iterator begin()
|
||||||
{
|
{
|
||||||
|
@ -102,7 +103,7 @@ struct interior_rings
|
||||||
return itr;
|
return itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator end() { return poly_.end();}
|
iterator end() { return poly_.end(); }
|
||||||
const_iterator begin() const
|
const_iterator begin() const
|
||||||
{
|
{
|
||||||
auto itr = poly_.cbegin();
|
auto itr = poly_.cbegin();
|
||||||
|
@ -110,153 +111,156 @@ struct interior_rings
|
||||||
return itr;
|
return itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const_iterator end() const { return poly_.cend();}
|
const_iterator end() const { return poly_.cend(); }
|
||||||
|
|
||||||
void clear()
|
void clear() { poly_.resize(1); }
|
||||||
{
|
|
||||||
poly_.resize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void resize(std::size_t size)
|
void resize(std::size_t size) { poly_.resize(size + 1); }
|
||||||
{
|
|
||||||
poly_.resize(size + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t size() const
|
std::size_t size() const { return poly_.empty() ? 0 : poly_.size() - 1; }
|
||||||
{
|
|
||||||
return poly_.empty() ? 0 : poly_.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void push_back(value_type const& val) { poly_.push_back(val); }
|
void push_back(value_type const& val) { poly_.push_back(val); }
|
||||||
value_type& back() { return poly_.back(); }
|
value_type& back() { return poly_.back(); }
|
||||||
value_type const& back() const { return poly_.back(); }
|
value_type const& back() const { return poly_.back(); }
|
||||||
polygon_type & poly_;
|
polygon_type& poly_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ns mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
namespace boost { namespace geometry { namespace traits {
|
namespace boost {
|
||||||
|
namespace geometry {
|
||||||
|
namespace traits {
|
||||||
|
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct tag<mapnik::box2d<CoordinateType> >
|
struct tag<mapnik::box2d<CoordinateType>>
|
||||||
{
|
{
|
||||||
using type = box_tag;
|
using type = box_tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct point_type<mapnik::box2d<double> > { using type = mapnik::coord2d; };
|
template<>
|
||||||
template<> struct point_type<mapnik::box2d<float> > { using type = mapnik::coord2f; };
|
struct point_type<mapnik::box2d<double>>
|
||||||
|
|
||||||
template <typename CoordinateType>
|
|
||||||
struct indexed_access<mapnik::box2d<CoordinateType>, min_corner, 0>
|
|
||||||
{
|
{
|
||||||
using ct = CoordinateType;
|
using type = mapnik::coord2d;
|
||||||
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<>
|
||||||
template <typename CoordinateType>
|
struct point_type<mapnik::box2d<float>>
|
||||||
struct indexed_access<mapnik::box2d<CoordinateType>, min_corner, 1>
|
|
||||||
{
|
{
|
||||||
using ct = CoordinateType;
|
using type = mapnik::coord2f;
|
||||||
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>
|
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;
|
using type = polygon_tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct point_order<mapnik::geometry::linear_ring<CoordinateType> >
|
struct point_order<mapnik::geometry::linear_ring<CoordinateType>>
|
||||||
{
|
{
|
||||||
static const order_selector value = counterclockwise;
|
static const order_selector value = counterclockwise;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct tag<mapnik::geometry::multi_point<CoordinateType> >
|
struct tag<mapnik::geometry::multi_point<CoordinateType>>
|
||||||
{
|
{
|
||||||
using type = multi_point_tag;
|
using type = multi_point_tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct tag<mapnik::geometry::multi_line_string<CoordinateType> >
|
struct tag<mapnik::geometry::multi_line_string<CoordinateType>>
|
||||||
{
|
{
|
||||||
using type = multi_linestring_tag;
|
using type = multi_linestring_tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct tag<mapnik::geometry::multi_polygon<CoordinateType> >
|
struct tag<mapnik::geometry::multi_polygon<CoordinateType>>
|
||||||
{
|
{
|
||||||
using type = multi_polygon_tag;
|
using type = multi_polygon_tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ring
|
// ring
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct ring_const_type<mapnik::geometry::polygon<CoordinateType> >
|
struct ring_const_type<mapnik::geometry::polygon<CoordinateType>>
|
||||||
{
|
{
|
||||||
using type = typename mapnik::geometry::linear_ring<CoordinateType> const&;
|
using type = typename mapnik::geometry::linear_ring<CoordinateType> const&;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct ring_mutable_type<mapnik::geometry::polygon<CoordinateType> >
|
struct ring_mutable_type<mapnik::geometry::polygon<CoordinateType>>
|
||||||
{
|
{
|
||||||
using type = typename mapnik::geometry::linear_ring<CoordinateType>&;
|
using type = typename mapnik::geometry::linear_ring<CoordinateType>&;
|
||||||
};
|
};
|
||||||
|
|
||||||
// interior
|
// interior
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct interior_const_type<mapnik::geometry::polygon<CoordinateType>>
|
struct interior_const_type<mapnik::geometry::polygon<CoordinateType>>
|
||||||
{
|
{
|
||||||
using type = typename mapnik::const_interior_rings<CoordinateType> const;
|
using type = typename mapnik::const_interior_rings<CoordinateType> const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct interior_mutable_type<mapnik::geometry::polygon<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>
|
template<typename CoordinateType>
|
||||||
struct exterior_ring<mapnik::geometry::polygon<CoordinateType> >
|
struct exterior_ring<mapnik::geometry::polygon<CoordinateType>>
|
||||||
{
|
{
|
||||||
using ring_const_type = typename ring_const_type<mapnik::geometry::polygon<CoordinateType> >::type;
|
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;
|
using ring_mutable_type = typename ring_mutable_type<mapnik::geometry::polygon<CoordinateType>>::type;
|
||||||
static ring_mutable_type get(mapnik::geometry::polygon<CoordinateType> & p)
|
static ring_mutable_type get(mapnik::geometry::polygon<CoordinateType>& p)
|
||||||
{
|
{
|
||||||
if (p.empty()) p.resize(1);
|
if (p.empty())
|
||||||
|
p.resize(1);
|
||||||
return p[0];
|
return p[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static ring_const_type get(mapnik::geometry::polygon<CoordinateType> const& p)
|
static ring_const_type get(mapnik::geometry::polygon<CoordinateType> const& p)
|
||||||
{
|
{
|
||||||
if (p.empty()) throw std::runtime_error("Exterior ring must be initialized!");
|
if (p.empty())
|
||||||
|
throw std::runtime_error("Exterior ring must be initialized!");
|
||||||
return p[0];
|
return p[0];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct interior_rings<mapnik::geometry::polygon<CoordinateType> >
|
struct interior_rings<mapnik::geometry::polygon<CoordinateType>>
|
||||||
{
|
{
|
||||||
using interior_const_type = typename interior_const_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;
|
using interior_mutable_type = typename interior_mutable_type<mapnik::geometry::polygon<CoordinateType>>::type;
|
||||||
|
|
||||||
static interior_const_type get(mapnik::geometry::polygon<CoordinateType> const& p)
|
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>>
|
struct resize<mapnik::interior_rings<CoordinateType>>
|
||||||
{
|
{
|
||||||
static inline void apply(mapnik::interior_rings<CoordinateType> interiors, std::size_t new_size)
|
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>>
|
struct clear<mapnik::interior_rings<CoordinateType>>
|
||||||
{
|
{
|
||||||
static inline void apply(mapnik::interior_rings<CoordinateType> interiors)
|
static inline void apply(mapnik::interior_rings<CoordinateType> interiors) { interiors.clear(); }
|
||||||
{
|
|
||||||
interiors.clear();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename CoordinateType>
|
template<typename CoordinateType>
|
||||||
struct push_back<mapnik::interior_rings<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)
|
static inline void apply(mapnik::interior_rings<CoordinateType> interiors, Ring const& ring)
|
||||||
{
|
{
|
||||||
interiors.push_back(ring);
|
interiors.push_back(ring);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}}}
|
} // namespace traits
|
||||||
|
} // namespace geometry
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
#endif //MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
|
#endif // MAPNIK_BOOST_GEOMETRY_ADAPTERS_HPP
|
||||||
|
|
|
@ -20,79 +20,76 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
|
#ifndef MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
|
||||||
#define MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
|
#define MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
|
||||||
|
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
|
|
||||||
namespace boost { using mapbox::util::get; }
|
namespace boost {
|
||||||
|
using mapbox::util::get;
|
||||||
|
}
|
||||||
|
|
||||||
#include <boost/spirit/home/karma/domain.hpp>
|
#include <boost/spirit/home/karma/domain.hpp>
|
||||||
#include <boost/spirit/home/support/attributes.hpp>
|
#include <boost/spirit/home/support/attributes.hpp>
|
||||||
|
|
||||||
namespace boost { namespace spirit { namespace traits
|
namespace boost {
|
||||||
{
|
namespace spirit {
|
||||||
template <>
|
namespace traits {
|
||||||
struct not_is_variant<mapnik::geometry::geometry<double>, karma::domain>
|
template<>
|
||||||
: mpl::false_
|
struct not_is_variant<mapnik::geometry::geometry<double>, karma::domain> : mpl::false_
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template <>
|
template<>
|
||||||
struct not_is_variant<mapnik::geometry::geometry<std::int64_t>, karma::domain>
|
struct not_is_variant<mapnik::geometry::geometry<std::int64_t>, karma::domain> : mpl::false_
|
||||||
: mpl::false_
|
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template <>
|
template<>
|
||||||
struct variant_which< mapnik::geometry::geometry<double> >
|
struct variant_which<mapnik::geometry::geometry<double>>
|
||||||
{
|
{
|
||||||
static int call(mapnik::geometry::geometry<double> const& v)
|
static int call(mapnik::geometry::geometry<double> const& v) { return v.which(); }
|
||||||
{
|
|
||||||
return v.which();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template<>
|
||||||
struct variant_which< mapnik::geometry::geometry<std::int64_t> >
|
struct variant_which<mapnik::geometry::geometry<std::int64_t>>
|
||||||
{
|
{
|
||||||
static int call(mapnik::geometry::geometry<std::int64_t> const& v)
|
static int call(mapnik::geometry::geometry<std::int64_t> const& v) { return v.which(); }
|
||||||
{
|
|
||||||
return v.which();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template <typename T, typename Tuple>
|
template<typename T, typename Tuple>
|
||||||
struct has_type;
|
struct has_type;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct has_type<T, std::tuple<>> : std::false_type {};
|
struct has_type<T, std::tuple<>> : std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
template <typename T, typename U, typename... Types>
|
template<typename T, typename U, typename... Types>
|
||||||
struct has_type<T, std::tuple<U, Types...>> : has_type<T, std::tuple<Types...>> {};
|
struct has_type<T, std::tuple<U, Types...>> : has_type<T, std::tuple<Types...>>
|
||||||
|
{};
|
||||||
|
|
||||||
template <typename T, typename... Types>
|
template<typename T, typename... Types>
|
||||||
struct has_type<T, std::tuple<T, Types...>> : std::true_type {};
|
struct has_type<T, std::tuple<T, Types...>> : std::true_type
|
||||||
|
{};
|
||||||
|
|
||||||
template <typename T, typename Tuple>
|
template<typename T, typename Tuple>
|
||||||
struct index;
|
struct index;
|
||||||
|
|
||||||
template <typename T, typename... Types>
|
template<typename T, typename... Types>
|
||||||
struct index<T, std::tuple<T, Types...>>
|
struct index<T, std::tuple<T, Types...>>
|
||||||
{
|
{
|
||||||
static const std::size_t value = 0;
|
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...>>
|
struct index<T, std::tuple<U, Types...>>
|
||||||
{
|
{
|
||||||
static const std::size_t value = 1 + index<T, std::tuple<Types...>>::value;
|
static const std::size_t value = 1 + index<T, std::tuple<Types...>>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template <typename Expected>
|
template<typename Expected>
|
||||||
struct compute_compatible_component_variant<mapnik::geometry::geometry<double>, Expected>
|
struct compute_compatible_component_variant<mapnik::geometry::geometry<double>, Expected>
|
||||||
: detail::has_type<Expected, mapnik::geometry::geometry<double>::types>
|
: detail::has_type<Expected, mapnik::geometry::geometry<double>::types>
|
||||||
{
|
{
|
||||||
|
@ -103,7 +100,7 @@ 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>
|
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>
|
||||||
{
|
{
|
||||||
|
@ -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
|
|
||||||
|
|
|
@ -46,21 +46,21 @@ namespace mapnik {
|
||||||
|
|
||||||
// A spatial envelope (i.e. bounding box) which also defines some basic operators.
|
// A spatial envelope (i.e. bounding box) which also defines some basic operators.
|
||||||
|
|
||||||
template <typename T> class MAPNIK_DECL box2d
|
template<typename T>
|
||||||
: boost::equality_comparable<box2d<T> ,
|
class MAPNIK_DECL box2d : boost::equality_comparable<
|
||||||
boost::addable<box2d<T>,
|
box2d<T>,
|
||||||
boost::dividable2<box2d<T>, T,
|
boost::addable<box2d<T>, boost::dividable2<box2d<T>, T, boost::multipliable2<box2d<T>, T>>>>
|
||||||
boost::multipliable2<box2d<T>, T > > > >
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
using box2d_type = box2d<value_type>;
|
using box2d_type = box2d<value_type>;
|
||||||
T minx_;
|
T minx_;
|
||||||
T miny_;
|
T miny_;
|
||||||
T maxx_;
|
T maxx_;
|
||||||
T maxy_;
|
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;
|
using std::swap;
|
||||||
swap(lhs.minx_, rhs.minx_);
|
swap(lhs.minx_, rhs.minx_);
|
||||||
|
@ -68,22 +68,23 @@ private:
|
||||||
swap(lhs.maxx_, rhs.maxx_);
|
swap(lhs.maxx_, rhs.maxx_);
|
||||||
swap(lhs.maxy_, rhs.maxy_);
|
swap(lhs.maxy_, rhs.maxy_);
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
|
public:
|
||||||
|
|
||||||
box2d();
|
box2d();
|
||||||
box2d(T minx,T miny,T maxx,T maxy);
|
box2d(T minx, T miny, T maxx, T maxy);
|
||||||
box2d(coord<T,2> const& c0, coord<T,2> const& c1);
|
box2d(coord<T, 2> const& c0, coord<T, 2> const& c1);
|
||||||
box2d(box2d_type const& rhs);
|
box2d(box2d_type const& rhs);
|
||||||
box2d(box2d_type const& rhs, agg::trans_affine const& tr);
|
box2d(box2d_type const& rhs, agg::trans_affine const& tr);
|
||||||
// move
|
// move
|
||||||
box2d(box2d_type&& rhs);
|
box2d(box2d_type&& rhs);
|
||||||
// converting ctor
|
// converting ctor
|
||||||
template <typename T1>
|
template<typename T1>
|
||||||
explicit box2d(box2d<T1> other)
|
explicit box2d(box2d<T1> other)
|
||||||
: minx_(static_cast<value_type>(other.minx())),
|
: minx_(static_cast<value_type>(other.minx()))
|
||||||
miny_(static_cast<value_type>(other.miny())),
|
, miny_(static_cast<value_type>(other.miny()))
|
||||||
maxx_(static_cast<value_type>(other.maxx())),
|
, maxx_(static_cast<value_type>(other.maxx()))
|
||||||
maxy_(static_cast<value_type>(other.maxy()))
|
, maxy_(static_cast<value_type>(other.maxy()))
|
||||||
{}
|
{}
|
||||||
box2d_type& operator=(box2d_type other);
|
box2d_type& operator=(box2d_type other);
|
||||||
T minx() const;
|
T minx() const;
|
||||||
|
@ -98,21 +99,21 @@ public:
|
||||||
T height() const;
|
T height() const;
|
||||||
void width(T w);
|
void width(T w);
|
||||||
void height(T h);
|
void height(T h);
|
||||||
coord<T,2> center() const;
|
coord<T, 2> center() const;
|
||||||
void expand_to_include(T x,T y);
|
void expand_to_include(T x, T y);
|
||||||
void expand_to_include(coord<T,2> const& c);
|
void expand_to_include(coord<T, 2> const& c);
|
||||||
void expand_to_include(box2d_type const& other);
|
void expand_to_include(box2d_type const& other);
|
||||||
bool contains(coord<T,2> const& c) const;
|
bool contains(coord<T, 2> const& c) const;
|
||||||
bool contains(T x,T y) const;
|
bool contains(T x, T y) const;
|
||||||
bool contains(box2d_type const& other) const;
|
bool contains(box2d_type const& other) const;
|
||||||
bool intersects(coord<T,2> const& c) const;
|
bool intersects(coord<T, 2> const& c) const;
|
||||||
bool intersects(T x,T y) const;
|
bool intersects(T x, T y) const;
|
||||||
bool intersects(box2d_type const& other) const;
|
bool intersects(box2d_type const& other) const;
|
||||||
box2d_type intersect(box2d_type const& other) const;
|
box2d_type intersect(box2d_type const& other) const;
|
||||||
bool operator==(box2d_type const& other) const;
|
bool operator==(box2d_type const& other) const;
|
||||||
void re_center(T cx,T cy);
|
void re_center(T cx, T cy);
|
||||||
void re_center(coord<T,2> const& c);
|
void re_center(coord<T, 2> const& c);
|
||||||
void init(T x0,T y0,T x1,T y1);
|
void init(T x0, T y0, T x1, T y1);
|
||||||
void init(T x, T y);
|
void init(T x, T y);
|
||||||
void clip(box2d_type const& other);
|
void clip(box2d_type const& other);
|
||||||
void pad(T padding);
|
void pad(T padding);
|
||||||
|
@ -127,22 +128,20 @@ public:
|
||||||
box2d_type& operator*=(T);
|
box2d_type& operator*=(T);
|
||||||
box2d_type& operator/=(T);
|
box2d_type& operator/=(T);
|
||||||
T operator[](int index) const;
|
T operator[](int index) const;
|
||||||
box2d_type operator +(T other) const; //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
|
box2d_type& operator+=(T other); // enlarge box by given amount
|
||||||
|
|
||||||
// compute the bounding box of this one transformed
|
// 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);
|
box2d_type& operator*=(agg::trans_affine const& tr);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class charT,class traits,class T>
|
template<class charT, class traits, class T>
|
||||||
inline std::basic_ostream<charT,traits>&
|
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out, const box2d<T>& e)
|
||||||
operator << (std::basic_ostream<charT,traits>& out,
|
|
||||||
const box2d<T>& e)
|
|
||||||
{
|
{
|
||||||
out << e.to_string();
|
out << e.to_string();
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_BOX2D_HPP
|
#endif // MAPNIK_BOX2D_HPP
|
||||||
|
|
|
@ -41,69 +41,68 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
// agg
|
// agg
|
||||||
#include "agg_trans_affine.h"
|
#include "agg_trans_affine.h"
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_TPL_STRUCT(
|
BOOST_FUSION_ADAPT_TPL_STRUCT((T), (mapnik::box2d)(T), (T, minx_), (T, miny_), (T, maxx_), (T, maxy_))
|
||||||
(T),
|
|
||||||
(mapnik::box2d)(T),
|
|
||||||
(T, minx_),
|
|
||||||
(T, miny_),
|
|
||||||
(T, maxx_),
|
|
||||||
(T, maxy_))
|
|
||||||
|
|
||||||
namespace mapnik { namespace detail { namespace {
|
namespace mapnik {
|
||||||
|
namespace detail {
|
||||||
|
namespace {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct assign
|
struct assign
|
||||||
{
|
{
|
||||||
template <typename Context>
|
template<typename Context>
|
||||||
void operator() (Context & ctx) const
|
void operator()(Context& ctx) const
|
||||||
{
|
{
|
||||||
_val(ctx) = safe_cast<T>(_attr(ctx));
|
_val(ctx) = safe_cast<T>(_attr(ctx));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // anonymous
|
} // namespace
|
||||||
} // detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>::box2d()
|
box2d<T>::box2d()
|
||||||
:minx_( std::numeric_limits<T>::max()),
|
: minx_(std::numeric_limits<T>::max())
|
||||||
miny_( std::numeric_limits<T>::max()),
|
, miny_(std::numeric_limits<T>::max())
|
||||||
maxx_(-std::numeric_limits<T>::max()),
|
, maxx_(-std::numeric_limits<T>::max())
|
||||||
maxy_(-std::numeric_limits<T>::max()) {}
|
, maxy_(-std::numeric_limits<T>::max())
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>::box2d(T minx,T miny,T maxx,T maxy)
|
box2d<T>::box2d(T minx, T miny, T maxx, T maxy)
|
||||||
{
|
{
|
||||||
init(minx, miny, maxx, maxy);
|
init(minx, miny, maxx, maxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>::box2d(coord<T,2> const& c0, coord<T,2> const& c1)
|
box2d<T>::box2d(coord<T, 2> const& c0, coord<T, 2> const& c1)
|
||||||
{
|
{
|
||||||
init(c0.x, c0.y, c1.x, c1.y);
|
init(c0.x, c0.y, c1.x, c1.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>::box2d(box2d_type const& rhs)
|
box2d<T>::box2d(box2d_type const& rhs)
|
||||||
: minx_(rhs.minx_),
|
: minx_(rhs.minx_)
|
||||||
miny_(rhs.miny_),
|
, miny_(rhs.miny_)
|
||||||
maxx_(rhs.maxx_),
|
, maxx_(rhs.maxx_)
|
||||||
maxy_(rhs.maxy_) {}
|
, maxy_(rhs.maxy_)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>::box2d(box2d_type && rhs)
|
box2d<T>::box2d(box2d_type&& rhs)
|
||||||
: minx_(std::move(rhs.minx_)),
|
: minx_(std::move(rhs.minx_))
|
||||||
miny_(std::move(rhs.miny_)),
|
, miny_(std::move(rhs.miny_))
|
||||||
maxx_(std::move(rhs.maxx_)),
|
, maxx_(std::move(rhs.maxx_))
|
||||||
maxy_(std::move(rhs.maxy_)) {}
|
, maxy_(std::move(rhs.maxy_))
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>& box2d<T>::operator=(box2d_type other)
|
box2d<T>& box2d<T>::operator=(box2d_type other)
|
||||||
{
|
{
|
||||||
swap(*this, other);
|
swap(*this, other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>::box2d(box2d_type const& rhs, agg::trans_affine const& tr)
|
box2d<T>::box2d(box2d_type const& rhs, agg::trans_affine const& tr)
|
||||||
{
|
{
|
||||||
double x0 = rhs.minx_, y0 = rhs.miny_;
|
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(&x1, &y1);
|
||||||
tr.transform(&x2, &y2);
|
tr.transform(&x2, &y2);
|
||||||
tr.transform(&x3, &y3);
|
tr.transform(&x3, &y3);
|
||||||
init(static_cast<T>(x0), static_cast<T>(y0),
|
init(static_cast<T>(x0), static_cast<T>(y0), static_cast<T>(x2), static_cast<T>(y2));
|
||||||
static_cast<T>(x2), static_cast<T>(y2));
|
|
||||||
expand_to_include(static_cast<T>(x1), static_cast<T>(y1));
|
expand_to_include(static_cast<T>(x1), static_cast<T>(y1));
|
||||||
expand_to_include(static_cast<T>(x3), static_cast<T>(y3));
|
expand_to_include(static_cast<T>(x3), static_cast<T>(y3));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool box2d<T>::operator==(box2d<T> const& other) const
|
bool box2d<T>::operator==(box2d<T> const& other) const
|
||||||
{
|
{
|
||||||
return minx_==other.minx_ &&
|
return minx_ == other.minx_ && miny_ == other.miny_ && maxx_ == other.maxx_ && maxy_ == other.maxy_;
|
||||||
miny_==other.miny_ &&
|
|
||||||
maxx_==other.maxx_ &&
|
|
||||||
maxy_==other.maxy_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T box2d<T>::minx() const
|
T box2d<T>::minx() const
|
||||||
{
|
{
|
||||||
return minx_;
|
return minx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T box2d<T>::maxx() const
|
T box2d<T>::maxx() const
|
||||||
{
|
{
|
||||||
return maxx_;
|
return maxx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T box2d<T>::miny() const
|
T box2d<T>::miny() const
|
||||||
{
|
{
|
||||||
return miny_;
|
return miny_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T box2d<T>::maxy() const
|
T box2d<T>::maxy() const
|
||||||
{
|
{
|
||||||
return maxy_;
|
return maxy_;
|
||||||
|
@ -177,115 +172,118 @@ void box2d<T>::set_maxy(T v)
|
||||||
maxy_ = v;
|
maxy_ = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T box2d<T>::width() const
|
T box2d<T>::width() const
|
||||||
{
|
{
|
||||||
return maxx_-minx_;
|
return maxx_ - minx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T box2d<T>::height() const
|
T box2d<T>::height() const
|
||||||
{
|
{
|
||||||
return maxy_-miny_;
|
return maxy_ - miny_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void box2d<T>::width(T w)
|
void box2d<T>::width(T w)
|
||||||
{
|
{
|
||||||
T cx=center().x;
|
T cx = center().x;
|
||||||
minx_=static_cast<T>(cx-w*0.5);
|
minx_ = static_cast<T>(cx - w * 0.5);
|
||||||
maxx_=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)
|
void box2d<T>::height(T h)
|
||||||
{
|
{
|
||||||
T cy=center().y;
|
T cy = center().y;
|
||||||
miny_=static_cast<T>(cy-h*0.5);
|
miny_ = static_cast<T>(cy - h * 0.5);
|
||||||
maxy_=static_cast<T>(cy+h*0.5);
|
maxy_ = static_cast<T>(cy + h * 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
coord<T,2> box2d<T>::center() const
|
coord<T, 2> box2d<T>::center() const
|
||||||
{
|
{
|
||||||
return coord<T,2>(static_cast<T>(0.5*(minx_+maxx_)),
|
return coord<T, 2>(static_cast<T>(0.5 * (minx_ + maxx_)), static_cast<T>(0.5 * (miny_ + maxy_)));
|
||||||
static_cast<T>(0.5*(miny_+maxy_)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void box2d<T>::expand_to_include(coord<T,2> const& c)
|
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>
|
template<typename T>
|
||||||
void box2d<T>::expand_to_include(T x,T y)
|
void box2d<T>::expand_to_include(T x, T y)
|
||||||
{
|
{
|
||||||
if (x<minx_) minx_=x;
|
if (x < minx_)
|
||||||
if (x>maxx_) maxx_=x;
|
minx_ = x;
|
||||||
if (y<miny_) miny_=y;
|
if (x > maxx_)
|
||||||
if (y>maxy_) maxy_=y;
|
maxx_ = x;
|
||||||
|
if (y < miny_)
|
||||||
|
miny_ = y;
|
||||||
|
if (y > maxy_)
|
||||||
|
maxy_ = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void box2d<T>::expand_to_include(box2d<T> const& other)
|
void box2d<T>::expand_to_include(box2d<T> const& other)
|
||||||
{
|
{
|
||||||
if (other.minx_<minx_) minx_=other.minx_;
|
if (other.minx_ < minx_)
|
||||||
if (other.maxx_>maxx_) maxx_=other.maxx_;
|
minx_ = other.minx_;
|
||||||
if (other.miny_<miny_) miny_=other.miny_;
|
if (other.maxx_ > maxx_)
|
||||||
if (other.maxy_>maxy_) maxy_=other.maxy_;
|
maxx_ = other.maxx_;
|
||||||
|
if (other.miny_ < miny_)
|
||||||
|
miny_ = other.miny_;
|
||||||
|
if (other.maxy_ > maxy_)
|
||||||
|
maxy_ = other.maxy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool box2d<T>::contains(coord<T,2> const& c) const
|
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>
|
template<typename T>
|
||||||
bool box2d<T>::contains(T x,T y) const
|
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
|
bool box2d<T>::contains(box2d<T> const& other) const
|
||||||
{
|
{
|
||||||
return other.minx_>=minx_ &&
|
return other.minx_ >= minx_ && other.maxx_ <= maxx_ && other.miny_ >= miny_ && other.maxy_ <= maxy_;
|
||||||
other.maxx_<=maxx_ &&
|
|
||||||
other.miny_>=miny_ &&
|
|
||||||
other.maxy_<=maxy_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool box2d<T>::intersects(coord<T,2> const& c) const
|
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>
|
template<typename T>
|
||||||
bool box2d<T>::intersects(T x,T y) const
|
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
|
bool box2d<T>::intersects(box2d<T> const& other) const
|
||||||
{
|
{
|
||||||
return !(other.minx_>maxx_ || other.maxx_<minx_ ||
|
return !(other.minx_ > maxx_ || other.maxx_ < minx_ || other.miny_ > maxy_ || other.maxy_ < miny_);
|
||||||
other.miny_>maxy_ || other.maxy_<miny_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T> box2d<T>::intersect(box2d_type const& other) const
|
box2d<T> box2d<T>::intersect(box2d_type const& other) const
|
||||||
{
|
{
|
||||||
if (intersects(other))
|
if (intersects(other))
|
||||||
{
|
{
|
||||||
T x0=std::max(minx_,other.minx_);
|
T x0 = std::max(minx_, other.minx_);
|
||||||
T y0=std::max(miny_,other.miny_);
|
T y0 = std::max(miny_, other.miny_);
|
||||||
T x1=std::min(maxx_,other.maxx_);
|
T x1 = std::min(maxx_, other.maxx_);
|
||||||
T y1=std::min(maxy_,other.maxy_);
|
T y1 = std::min(maxy_, other.maxy_);
|
||||||
return box2d<T>(x0,y0,x1,y1);
|
return box2d<T>(x0, y0, x1, y1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -293,24 +291,24 @@ box2d<T> box2d<T>::intersect(box2d_type const& other) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void box2d<T>::re_center(T cx,T cy)
|
void box2d<T>::re_center(T cx, T cy)
|
||||||
{
|
{
|
||||||
T dx=cx-center().x;
|
T dx = cx - center().x;
|
||||||
T dy=cy-center().y;
|
T dy = cy - center().y;
|
||||||
minx_+=dx;
|
minx_ += dx;
|
||||||
miny_+=dy;
|
miny_ += dy;
|
||||||
maxx_+=dx;
|
maxx_ += dx;
|
||||||
maxy_+=dy;
|
maxy_ += dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void box2d<T>::re_center(coord<T,2> const& c)
|
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)
|
void box2d<T>::init(T x0, T y0, T x1, T y1)
|
||||||
{
|
{
|
||||||
if (x0 < x1)
|
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)
|
void box2d<T>::init(T x, T y)
|
||||||
{
|
{
|
||||||
init(x, y, x, y);
|
init(x, y, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void box2d<T>::clip(box2d_type const& other)
|
void box2d<T>::clip(box2d_type const& other)
|
||||||
{
|
{
|
||||||
minx_ = std::max(minx_, other.minx());
|
minx_ = std::max(minx_, other.minx());
|
||||||
|
@ -350,7 +348,7 @@ void box2d<T>::clip(box2d_type const& other)
|
||||||
maxy_ = std::min(maxy_, other.maxy());
|
maxy_ = std::min(maxy_, other.maxy());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void box2d<T>::pad(T padding)
|
void box2d<T>::pad(T padding)
|
||||||
{
|
{
|
||||||
minx_ -= padding;
|
minx_ -= padding;
|
||||||
|
@ -359,30 +357,29 @@ void box2d<T>::pad(T padding)
|
||||||
maxy_ += padding;
|
maxy_ += padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool box2d<T>::from_string(std::string const& str)
|
bool box2d<T>::from_string(std::string const& str)
|
||||||
{
|
{
|
||||||
using boost::spirit::x3::lit;
|
using boost::spirit::x3::lit;
|
||||||
boost::spirit::x3::double_type double_;
|
boost::spirit::x3::double_type double_;
|
||||||
boost::spirit::x3::ascii::space_type space;
|
boost::spirit::x3::ascii::space_type space;
|
||||||
bool r = boost::spirit::x3::phrase_parse(str.begin(),
|
bool r = boost::spirit::x3::phrase_parse(
|
||||||
|
str.begin(),
|
||||||
str.end(),
|
str.end(),
|
||||||
double_[detail::assign<T>()] >> -lit(',') >>
|
double_[detail::assign<T>()] >> -lit(',') >> double_[detail::assign<T>()] >> -lit(',') >>
|
||||||
double_[detail::assign<T>()] >> -lit(',') >>
|
double_[detail::assign<T>()] >> -lit(',') >> double_[detail::assign<T>()],
|
||||||
double_[detail::assign<T>()] >> -lit(',') >>
|
|
||||||
double_[detail::assign<T>()],
|
|
||||||
space,
|
space,
|
||||||
*this);
|
*this);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool box2d<T>::valid() const
|
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)
|
void box2d<T>::move(T x, T y)
|
||||||
{
|
{
|
||||||
minx_ += x;
|
minx_ += x;
|
||||||
|
@ -391,15 +388,14 @@ void box2d<T>::move(T x, T y)
|
||||||
maxy_ += y;
|
maxy_ += y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
std::string box2d<T>::to_string() const
|
std::string box2d<T>::to_string() const
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
if (valid())
|
if (valid())
|
||||||
{
|
{
|
||||||
s << "box2d(" << std::fixed << std::setprecision(16)
|
s << "box2d(" << std::fixed << std::setprecision(16) << minx_ << ',' << miny_ << ',' << maxx_ << ',' << maxy_
|
||||||
<< minx_ << ',' << miny_ << ','
|
<< ')';
|
||||||
<< maxx_ << ',' << maxy_ << ')';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -408,27 +404,27 @@ std::string box2d<T>::to_string() const
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T box2d<T>::area() const
|
T box2d<T>::area() const
|
||||||
{
|
{
|
||||||
return width() * height();
|
return width() * height();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
|
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
|
||||||
{
|
{
|
||||||
expand_to_include(other);
|
expand_to_include(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T> box2d<T>::operator+ (T other) const
|
box2d<T> box2d<T>::operator+(T other) const
|
||||||
{
|
{
|
||||||
return box2d<T>(minx_ - other, miny_ - other, maxx_ + other, maxy_ + other);
|
return box2d<T>(minx_ - other, miny_ - other, maxx_ + other, maxy_ + other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>& box2d<T>::operator+= (T other)
|
box2d<T>& box2d<T>::operator+=(T other)
|
||||||
{
|
{
|
||||||
minx_ -= other;
|
minx_ -= other;
|
||||||
miny_ -= other;
|
miny_ -= other;
|
||||||
|
@ -437,11 +433,10 @@ box2d<T>& box2d<T>::operator+= (T other)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
template <typename T>
|
|
||||||
box2d<T>& box2d<T>::operator*=(T t)
|
box2d<T>& box2d<T>::operator*=(T t)
|
||||||
{
|
{
|
||||||
coord<T,2> c = center();
|
coord<T, 2> c = center();
|
||||||
T sx = static_cast<T>(0.5 * width() * t);
|
T sx = static_cast<T>(0.5 * width() * t);
|
||||||
T sy = static_cast<T>(0.5 * height() * t);
|
T sy = static_cast<T>(0.5 * height() * t);
|
||||||
minx_ = c.x - sx;
|
minx_ = c.x - sx;
|
||||||
|
@ -451,10 +446,10 @@ box2d<T>& box2d<T>::operator*=(T t)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>& box2d<T>::operator/=(T 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 sx = static_cast<T>(0.5 * width() / t);
|
||||||
T sy = static_cast<T>(0.5 * height() / t);
|
T sy = static_cast<T>(0.5 * height() / t);
|
||||||
minx_ = c.x - sx;
|
minx_ = c.x - sx;
|
||||||
|
@ -464,10 +459,10 @@ box2d<T>& box2d<T>::operator/=(T t)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T box2d<T>::operator[] (int index) const
|
T box2d<T>::operator[](int index) const
|
||||||
{
|
{
|
||||||
switch(index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return minx_;
|
return minx_;
|
||||||
|
@ -490,13 +485,13 @@ T box2d<T>::operator[] (int index) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T> box2d<T>::operator*(agg::trans_affine const& tr) const
|
box2d<T> box2d<T>::operator*(agg::trans_affine const& tr) const
|
||||||
{
|
{
|
||||||
return box2d<T>(*this, tr);
|
return box2d<T>(*this, tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
box2d<T>& box2d<T>::operator*=(agg::trans_affine const& tr)
|
box2d<T>& box2d<T>::operator*=(agg::trans_affine const& tr)
|
||||||
{
|
{
|
||||||
double x0 = minx_, y0 = miny_;
|
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(&x1, &y1);
|
||||||
tr.transform(&x2, &y2);
|
tr.transform(&x2, &y2);
|
||||||
tr.transform(&x3, &y3);
|
tr.transform(&x3, &y3);
|
||||||
init(static_cast<T>(x0), static_cast<T>(y0),
|
init(static_cast<T>(x0), static_cast<T>(y0), static_cast<T>(x2), static_cast<T>(y2));
|
||||||
static_cast<T>(x2), static_cast<T>(y2));
|
|
||||||
expand_to_include(static_cast<T>(x1), static_cast<T>(y1));
|
expand_to_include(static_cast<T>(x1), static_cast<T>(y1));
|
||||||
expand_to_include(static_cast<T>(x3), static_cast<T>(y3));
|
expand_to_include(static_cast<T>(x3), static_cast<T>(y3));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
|
@ -29,96 +29,74 @@
|
||||||
#include <mapnik/geometry/is_empty.hpp>
|
#include <mapnik/geometry/is_empty.hpp>
|
||||||
#include <mapnik/geometry/remove_empty.hpp>
|
#include <mapnik/geometry/remove_empty.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct geometry_centroid
|
struct geometry_centroid
|
||||||
{
|
{
|
||||||
using result_type = bool;
|
using result_type = bool;
|
||||||
|
|
||||||
geometry_centroid(point<T> & pt)
|
geometry_centroid(point<T>& pt)
|
||||||
: pt_(pt) {}
|
: pt_(pt)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename U>
|
template<typename U>
|
||||||
result_type operator() (U const& geom) const
|
result_type operator()(U const& geom) const
|
||||||
{
|
{
|
||||||
return util::apply_visitor(*this, geom);
|
return util::apply_visitor(*this, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
result_type operator() (geometry_empty const&) const
|
result_type operator()(geometry_empty const&) const { return false; }
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
result_type operator() (geometry_collection<T> const&) const
|
result_type operator()(geometry_collection<T> const&) const { return false; }
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
result_type operator() (point<T> const& geom) const
|
result_type operator()(point<T> const& geom) const { return centroid_simple(geom); }
|
||||||
{
|
|
||||||
return centroid_simple(geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
result_type operator() (line_string<T> const& geom) const
|
result_type operator()(line_string<T> const& geom) const { return centroid_simple(geom); }
|
||||||
{
|
|
||||||
return centroid_simple(geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
result_type operator() (polygon<T> const& geom) const
|
result_type operator()(polygon<T> const& geom) const { return centroid_simple(geom); }
|
||||||
{
|
|
||||||
return centroid_simple(geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
result_type operator() (multi_point<T> const& geom) const
|
result_type operator()(multi_point<T> const& geom) const { return centroid_simple(geom); }
|
||||||
{
|
|
||||||
return centroid_simple(geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
result_type operator() (multi_line_string<T> const& geom) const
|
result_type operator()(multi_line_string<T> const& geom) const { return centroid_multi(geom); }
|
||||||
{
|
|
||||||
return centroid_multi(geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
result_type operator() (multi_polygon<T> const& geom) const
|
result_type operator()(multi_polygon<T> const& geom) const { return centroid_multi(geom); }
|
||||||
{
|
|
||||||
return centroid_multi(geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
point<T> & pt_;
|
point<T>& pt_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename Geom>
|
template<typename Geom>
|
||||||
result_type centroid_simple(Geom const & geom) const
|
result_type centroid_simple(Geom const& geom) const
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::geometry::centroid(geom, pt_);
|
boost::geometry::centroid(geom, pt_);
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (boost::geometry::centroid_exception const& e)
|
||||||
catch (boost::geometry::centroid_exception const & e)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Geom>
|
template<typename Geom>
|
||||||
result_type centroid_multi(Geom const & multi_geom) const
|
result_type centroid_multi(Geom const& multi_geom) const
|
||||||
{
|
{
|
||||||
return centroid_simple(multi_geom);
|
return centroid_simple(multi_geom);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
inline bool centroid(T1 const& geom, point<T2> & pt)
|
inline bool centroid(T1 const& geom, point<T2>& pt)
|
||||||
{
|
{
|
||||||
return detail::geometry_centroid<T2>(pt)(geom);
|
return detail::geometry_centroid<T2>(pt)(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_CENTROID_HPP
|
#endif // MAPNIK_GEOMETRY_CENTROID_HPP
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
#include <mapnik/geometry/boost_adapters.hpp>
|
#include <mapnik/geometry/boost_adapters.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
using coordinate_type = double;
|
using coordinate_type = double;
|
||||||
|
|
||||||
struct closest_point_result
|
struct closest_point_result
|
||||||
|
@ -41,11 +42,11 @@ struct closest_point_result
|
||||||
};
|
};
|
||||||
|
|
||||||
using result_type = 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);
|
MAPNIK_DECL result_type closest_point(T1 const& geom, mapnik::geometry::point<T2> const& pt);
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif //
|
#endif //
|
||||||
#endif // MAPNIK_GEOMETRY_CLOSEST_POINT_HPP
|
#endif // MAPNIK_GEOMETRY_CLOSEST_POINT_HPP
|
||||||
|
|
|
@ -35,7 +35,8 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
@ -43,50 +44,52 @@ struct geometry_correct
|
||||||
{
|
{
|
||||||
using result_type = void;
|
using result_type = void;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry<T> & geom) const
|
result_type operator()(geometry<T>& geom) const
|
||||||
{
|
{
|
||||||
mapnik::util::apply_visitor(*this, geom);
|
mapnik::util::apply_visitor(*this, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry_collection<T> & collection) const
|
result_type operator()(geometry_collection<T>& collection) const
|
||||||
{
|
{
|
||||||
for (auto & geom : collection)
|
for (auto& geom : collection)
|
||||||
{
|
{
|
||||||
(*this)(geom);
|
(*this)(geom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (polygon<T> & poly) const
|
result_type operator()(polygon<T>& poly) const
|
||||||
{
|
{
|
||||||
if (!poly.empty()) boost::geometry::correct(poly);
|
if (!poly.empty())
|
||||||
|
boost::geometry::correct(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_polygon<T> & multi_poly) const
|
result_type operator()(multi_polygon<T>& multi_poly) const
|
||||||
{
|
{
|
||||||
if (!multi_poly.empty()) boost::geometry::correct(multi_poly);
|
if (!multi_poly.empty())
|
||||||
|
boost::geometry::correct(multi_poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (T &) const
|
result_type operator()(T&) const
|
||||||
{
|
{
|
||||||
//no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template <typename GeomType>
|
template<typename GeomType>
|
||||||
inline void correct(GeomType & geom)
|
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);
|
detail::geometry_correct()(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_CORRECT_HPP
|
#endif // MAPNIK_GEOMETRY_CORRECT_HPP
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
namespace geometry {
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
MAPNIK_DECL auto envelope(T const& geom) -> box2d<typename T::coordinate_type>;
|
MAPNIK_DECL auto envelope(T const& geom) -> box2d<typename T::coordinate_type>;
|
||||||
|
|
||||||
} // end ns geometry
|
} // namespace geometry
|
||||||
} // end ns mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_ENVELOPE_HPP
|
#endif // MAPNIK_GEOMETRY_ENVELOPE_HPP
|
||||||
|
|
|
@ -24,29 +24,31 @@
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
#include <mapnik/geometry/box2d.hpp>
|
#include <mapnik/geometry/box2d.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct geometry_envelope
|
struct geometry_envelope
|
||||||
{
|
{
|
||||||
using coordinate_type = T;
|
using coordinate_type = T;
|
||||||
using bbox_type = box2d<coordinate_type>;
|
using bbox_type = box2d<coordinate_type>;
|
||||||
bbox_type & bbox;
|
bbox_type& bbox;
|
||||||
|
|
||||||
explicit geometry_envelope(bbox_type & bbox_)
|
explicit geometry_envelope(bbox_type& bbox_)
|
||||||
: bbox(bbox_) {}
|
: bbox(bbox_)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename U>
|
template<typename U>
|
||||||
void operator() (U const& geom) const
|
void operator()(U const& geom) const
|
||||||
{
|
{
|
||||||
return mapnik::util::apply_visitor(*this, geom);
|
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())
|
if (!bbox.valid())
|
||||||
{
|
{
|
||||||
|
@ -55,27 +57,19 @@ struct geometry_envelope
|
||||||
bbox.expand_to_include(pt.x, pt.y);
|
bbox.expand_to_include(pt.x, pt.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator() (mapnik::geometry::line_string<T> const& line) const
|
void operator()(mapnik::geometry::line_string<T> const& line) const { _envelope_impl(line, bbox); }
|
||||||
|
|
||||||
|
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
|
void operator()(mapnik::geometry::multi_point<T> const& multi_point) const { _envelope_impl(multi_point, bbox); }
|
||||||
{
|
|
||||||
_envelope_impl(ring, bbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator() (mapnik::geometry::polygon<T> const& poly) const
|
void operator()(mapnik::geometry::multi_line_string<T> const& multi_line) 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
|
|
||||||
{
|
{
|
||||||
for (auto const& line : multi_line)
|
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)
|
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)
|
for (auto const& geom : collection)
|
||||||
{
|
{
|
||||||
|
@ -99,9 +93,9 @@ struct geometry_envelope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename Points>
|
template<typename Points>
|
||||||
void _envelope_impl(Points const& points, bbox_type & b) const
|
void _envelope_impl(Points const& points, bbox_type& b) const
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto const& pt : points)
|
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>
|
auto envelope(T const& geom) -> box2d<typename T::coordinate_type>
|
||||||
{
|
{
|
||||||
using coordinate_type = 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;
|
return bbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end ns geometry
|
} // namespace geometry
|
||||||
} // end ns mapnik
|
} // namespace mapnik
|
||||||
|
|
|
@ -20,23 +20,14 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP
|
#ifndef MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP
|
||||||
#define MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP
|
#define MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP
|
||||||
|
|
||||||
#include <mapnik/geometry/polygon.hpp>
|
#include <mapnik/geometry/polygon.hpp>
|
||||||
#include <boost/fusion/include/adapt_struct.hpp>
|
#include <boost/fusion/include/adapt_struct.hpp>
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT(
|
BOOST_FUSION_ADAPT_STRUCT(mapnik::geometry::point<double>, (double, x)(double, y))
|
||||||
mapnik::geometry::point<double>,
|
|
||||||
(double, x)
|
|
||||||
(double, y)
|
|
||||||
)
|
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT(
|
BOOST_FUSION_ADAPT_STRUCT(mapnik::geometry::point<std::int64_t>, (std::int64_t, x)(std::int64_t, y))
|
||||||
mapnik::geometry::point<std::int64_t>,
|
|
||||||
(std::int64_t, x)
|
|
||||||
(std::int64_t, y)
|
|
||||||
)
|
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP
|
#endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP
|
||||||
|
|
|
@ -27,66 +27,68 @@
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
#include <mapnik/geometry/geometry_types.hpp>
|
#include <mapnik/geometry/geometry_types.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry { namespace detail {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct geometry_type
|
struct geometry_type
|
||||||
{
|
{
|
||||||
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);
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
return mapnik::geometry::geometry_types::GeometryCollection;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
static inline mapnik::geometry::geometry_types geometry_type(T const& geom)
|
static inline mapnik::geometry::geometry_types geometry_type(T const& geom)
|
||||||
{
|
{
|
||||||
using coordinate_type = typename T::coordinate_type;
|
using coordinate_type = typename T::coordinate_type;
|
||||||
return detail::geometry_type<coordinate_type>()(geom);
|
return detail::geometry_type<coordinate_type>()(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_TYPE_HPP
|
#endif // MAPNIK_GEOMETRY_TYPE_HPP
|
||||||
|
|
|
@ -25,11 +25,11 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
// OGC compatible types
|
// OGC compatible types
|
||||||
enum geometry_types : std::uint8_t
|
enum geometry_types : std::uint8_t {
|
||||||
{
|
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
Point = 1,
|
Point = 1,
|
||||||
LineString = 2,
|
LineString = 2,
|
||||||
|
@ -40,6 +40,7 @@ enum geometry_types : std::uint8_t
|
||||||
GeometryCollection = 7,
|
GeometryCollection = 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_TYPES_HPP
|
#endif // MAPNIK_GEOMETRY_TYPES_HPP
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
#include <mapnik/geometry/polygon.hpp>
|
#include <mapnik/geometry/polygon.hpp>
|
||||||
#include <mapnik/geometry/point.hpp>
|
#include <mapnik/geometry/point.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <class T>
|
template<class T>
|
||||||
MAPNIK_DECL bool interior(polygon<T> const& polygon,
|
MAPNIK_DECL bool interior(polygon<T> const& polygon, double scale_factor, point<T>& pt);
|
||||||
double scale_factor,
|
|
||||||
point<T> & pt);
|
|
||||||
|
|
||||||
} }
|
}
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_INTERIOR_HPP
|
#endif // MAPNIK_GEOMETRY_INTERIOR_HPP
|
||||||
|
|
|
@ -25,68 +25,51 @@
|
||||||
|
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
struct geometry_is_empty
|
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);
|
return mapnik::util::apply_visitor(*this, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator() (mapnik::geometry::point<double> const&) const
|
bool operator()(mapnik::geometry::point<double> const&) const { return false; }
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator() (mapnik::geometry::line_string<double> const& geom) const
|
bool operator()(mapnik::geometry::line_string<double> const& geom) const { return geom.empty(); }
|
||||||
{
|
|
||||||
return geom.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator() (mapnik::geometry::polygon<double> const& geom) const
|
bool operator()(mapnik::geometry::polygon<double> const& geom) const
|
||||||
{
|
{
|
||||||
return geom.empty() || geom.front().empty();
|
return geom.empty() || geom.front().empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator() (mapnik::geometry::multi_point<double> const& geom) const
|
bool operator()(mapnik::geometry::multi_point<double> const& geom) const { return geom.empty(); }
|
||||||
{
|
|
||||||
return geom.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator() (mapnik::geometry::multi_line_string<double> const& geom) const
|
bool operator()(mapnik::geometry::multi_line_string<double> const& geom) const { return geom.empty(); }
|
||||||
{
|
|
||||||
return geom.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator() (mapnik::geometry::multi_polygon<double> const& geom) const
|
bool operator()(mapnik::geometry::multi_polygon<double> const& geom) const { return geom.empty(); }
|
||||||
{
|
|
||||||
return geom.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator() (mapnik::geometry::geometry_collection<double> const& geom) const
|
bool operator()(mapnik::geometry::geometry_collection<double> const& geom) const { return geom.empty(); }
|
||||||
{
|
|
||||||
return geom.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool operator() (T const&) const
|
bool operator()(T const&) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
// returns true if the geometry is the empty set
|
// returns true if the geometry is the empty set
|
||||||
template <typename GeomType>
|
template<typename GeomType>
|
||||||
inline bool is_empty(GeomType const& geom)
|
inline bool is_empty(GeomType const& geom)
|
||||||
{
|
{
|
||||||
return detail::geometry_is_empty()(geom);
|
return detail::geometry_is_empty()(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_IS_EMPTY_HPP
|
#endif // MAPNIK_GEOMETRY_IS_EMPTY_HPP
|
||||||
|
|
|
@ -32,7 +32,8 @@
|
||||||
#include <mapnik/geometry/boost_adapters.hpp>
|
#include <mapnik/geometry/boost_adapters.hpp>
|
||||||
#include <boost/geometry/algorithms/is_simple.hpp>
|
#include <boost/geometry/algorithms/is_simple.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
@ -40,36 +41,37 @@ struct geometry_is_simple
|
||||||
{
|
{
|
||||||
using result_type = bool;
|
using result_type = bool;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry<T> const& geom) const
|
result_type operator()(geometry<T> const& geom) const
|
||||||
{
|
{
|
||||||
return mapnik::util::apply_visitor(*this, geom);
|
return mapnik::util::apply_visitor(*this, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
result_type operator() (geometry_empty const& ) const
|
result_type operator()(geometry_empty const&) const
|
||||||
{
|
{
|
||||||
// An empty geometry has no anomalous geometric points, such as self intersection or self tangency.
|
// An empty geometry has no anomalous geometric points, such as self intersection or self tangency.
|
||||||
// Therefore, we will return true
|
// Therefore, we will return true
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry_collection<T> const& collection) const
|
result_type operator()(geometry_collection<T> const& collection) const
|
||||||
{
|
{
|
||||||
for (auto const& geom : collection)
|
for (auto const& geom : collection)
|
||||||
{
|
{
|
||||||
if ( !(*this)(geom)) return false;
|
if (!(*this)(geom))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (point<T> const& pt) const
|
result_type operator()(point<T> const& pt) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_simple(pt);
|
return boost::geometry::is_simple(pt);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (line_string<T> const& line) const
|
result_type operator()(line_string<T> const& line) const
|
||||||
{
|
{
|
||||||
if (line.empty())
|
if (line.empty())
|
||||||
{
|
{
|
||||||
|
@ -80,13 +82,13 @@ struct geometry_is_simple
|
||||||
}
|
}
|
||||||
return boost::geometry::is_simple(line);
|
return boost::geometry::is_simple(line);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (polygon<T> const& poly) const
|
result_type operator()(polygon<T> const& poly) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_simple(poly);
|
return boost::geometry::is_simple(poly);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_point<T> const& multi_pt) const
|
result_type operator()(multi_point<T> const& multi_pt) const
|
||||||
{
|
{
|
||||||
if (multi_pt.empty())
|
if (multi_pt.empty())
|
||||||
{
|
{
|
||||||
|
@ -96,8 +98,8 @@ struct geometry_is_simple
|
||||||
}
|
}
|
||||||
return boost::geometry::is_simple(multi_pt);
|
return boost::geometry::is_simple(multi_pt);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_line_string<T> const& multi_line) const
|
result_type operator()(multi_line_string<T> const& multi_line) const
|
||||||
{
|
{
|
||||||
if (multi_line.empty())
|
if (multi_line.empty())
|
||||||
{
|
{
|
||||||
|
@ -107,12 +109,13 @@ struct geometry_is_simple
|
||||||
}
|
}
|
||||||
for (auto const& line : multi_line)
|
for (auto const& line : multi_line)
|
||||||
{
|
{
|
||||||
if (!(*this)(line)) return false;
|
if (!(*this)(line))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_polygon<T> const& multi_poly) const
|
result_type operator()(multi_polygon<T> const& multi_poly) const
|
||||||
{
|
{
|
||||||
if (multi_poly.empty())
|
if (multi_poly.empty())
|
||||||
{
|
{
|
||||||
|
@ -122,28 +125,29 @@ struct geometry_is_simple
|
||||||
}
|
}
|
||||||
for (auto const& poly : multi_poly)
|
for (auto const& poly : multi_poly)
|
||||||
{
|
{
|
||||||
if (!(*this)(poly)) return false;
|
if (!(*this)(poly))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
inline bool is_simple(T const& geom)
|
inline bool is_simple(T const& geom)
|
||||||
{
|
{
|
||||||
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)
|
inline bool is_simple(mapnik::geometry::geometry<T> const& geom)
|
||||||
{
|
{
|
||||||
return util::apply_visitor(detail::geometry_is_simple(), geom);
|
return util::apply_visitor(detail::geometry_is_simple(), geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // BOOST_VERSION >= 1.56
|
#endif // BOOST_VERSION >= 1.56
|
||||||
#endif // MAPNIK_GEOMETRY_IS_SIMPLE_HPP
|
#endif // MAPNIK_GEOMETRY_IS_SIMPLE_HPP
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
#include <boost/geometry/algorithms/is_valid.hpp>
|
#include <boost/geometry/algorithms/is_valid.hpp>
|
||||||
#include <boost/geometry/algorithms/validity_failure_type.hpp>
|
#include <boost/geometry/algorithms/validity_failure_type.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
@ -41,59 +42,57 @@ struct geometry_is_valid
|
||||||
{
|
{
|
||||||
using result_type = bool;
|
using result_type = bool;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry<T> const& geom) const
|
result_type operator()(geometry<T> const& geom) const
|
||||||
{
|
{
|
||||||
return mapnik::util::apply_visitor(*this, geom);
|
return mapnik::util::apply_visitor(*this, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
result_type operator() (geometry_empty const& ) const
|
result_type operator()(geometry_empty const&) const { return true; }
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry_collection<T> const& collection) const
|
result_type operator()(geometry_collection<T> const& collection) const
|
||||||
{
|
{
|
||||||
for (auto const& geom : collection)
|
for (auto const& geom : collection)
|
||||||
{
|
{
|
||||||
if ( !(*this)(geom)) return false;
|
if (!(*this)(geom))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (point<T> const& pt) const
|
result_type operator()(point<T> const& pt) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(pt);
|
return boost::geometry::is_valid(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (line_string<T> const& line) const
|
result_type operator()(line_string<T> const& line) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(line);
|
return boost::geometry::is_valid(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (polygon<T> const& poly) const
|
result_type operator()(polygon<T> const& poly) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(poly);
|
return boost::geometry::is_valid(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_point<T> const& multi_pt) const
|
result_type operator()(multi_point<T> const& multi_pt) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_pt);
|
return boost::geometry::is_valid(multi_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_line_string<T> const& multi_line) const
|
result_type operator()(multi_line_string<T> const& multi_line) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_line);
|
return boost::geometry::is_valid(multi_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_polygon<T> const& multi_poly) const
|
result_type operator()(multi_polygon<T> const& multi_poly) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_poly);
|
return boost::geometry::is_valid(multi_poly);
|
||||||
}
|
}
|
||||||
|
@ -103,65 +102,67 @@ struct geometry_is_valid_reason
|
||||||
{
|
{
|
||||||
using result_type = bool;
|
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):
|
geometry_is_valid_reason(boost::geometry::validity_failure_type& failure)
|
||||||
failure_(failure) {}
|
: failure_(failure)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry<T> const& geom) const
|
result_type operator()(geometry<T> const& geom) const
|
||||||
{
|
{
|
||||||
return mapnik::util::apply_visitor(*this, geom);
|
return mapnik::util::apply_visitor(*this, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
result_type operator() (geometry_empty const& ) const
|
result_type operator()(geometry_empty const&) const
|
||||||
{
|
{
|
||||||
failure_ = boost::geometry::no_failure;
|
failure_ = boost::geometry::no_failure;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry_collection<T> const& collection) const
|
result_type operator()(geometry_collection<T> const& collection) const
|
||||||
{
|
{
|
||||||
for (auto const& geom : collection)
|
for (auto const& geom : collection)
|
||||||
{
|
{
|
||||||
if ( !(*this)(geom)) return false;
|
if (!(*this)(geom))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (point<T> const& pt) const
|
result_type operator()(point<T> const& pt) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(pt, failure_);
|
return boost::geometry::is_valid(pt, failure_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (line_string<T> const& line) const
|
result_type operator()(line_string<T> const& line) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(line, failure_);
|
return boost::geometry::is_valid(line, failure_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (polygon<T> const& poly) const
|
result_type operator()(polygon<T> const& poly) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(poly, failure_);
|
return boost::geometry::is_valid(poly, failure_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_point<T> const& multi_pt) const
|
result_type operator()(multi_point<T> const& multi_pt) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_pt, failure_);
|
return boost::geometry::is_valid(multi_pt, failure_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_line_string<T> const& multi_line) const
|
result_type operator()(multi_line_string<T> const& multi_line) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_line, failure_);
|
return boost::geometry::is_valid(multi_line, failure_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_polygon<T> const& multi_poly) const
|
result_type operator()(multi_polygon<T> const& multi_poly) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_poly, failure_);
|
return boost::geometry::is_valid(multi_poly, failure_);
|
||||||
}
|
}
|
||||||
|
@ -171,112 +172,112 @@ struct geometry_is_valid_string
|
||||||
{
|
{
|
||||||
using result_type = bool;
|
using result_type = bool;
|
||||||
|
|
||||||
std::string & message_;
|
std::string& message_;
|
||||||
|
|
||||||
geometry_is_valid_string(std::string & message):
|
geometry_is_valid_string(std::string& message)
|
||||||
message_(message) {}
|
: message_(message)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry<T> const& geom) const
|
result_type operator()(geometry<T> const& geom) const
|
||||||
{
|
{
|
||||||
return mapnik::util::apply_visitor(*this, geom);
|
return mapnik::util::apply_visitor(*this, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
result_type operator() (geometry_empty const& ) const
|
result_type operator()(geometry_empty const&) const
|
||||||
{
|
{
|
||||||
message_ = "Geometry is valid";
|
message_ = "Geometry is valid";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (geometry_collection<T> const& collection) const
|
result_type operator()(geometry_collection<T> const& collection) const
|
||||||
{
|
{
|
||||||
for (auto const& geom : collection)
|
for (auto const& geom : collection)
|
||||||
{
|
{
|
||||||
if ( !(*this)(geom)) return false;
|
if (!(*this)(geom))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (point<T> const& pt) const
|
result_type operator()(point<T> const& pt) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(pt, message_);
|
return boost::geometry::is_valid(pt, message_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (line_string<T> const& line) const
|
result_type operator()(line_string<T> const& line) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(line, message_);
|
return boost::geometry::is_valid(line, message_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (polygon<T> const& poly) const
|
result_type operator()(polygon<T> const& poly) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(poly, message_);
|
return boost::geometry::is_valid(poly, message_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_point<T> const& multi_pt) const
|
result_type operator()(multi_point<T> const& multi_pt) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_pt, message_);
|
return boost::geometry::is_valid(multi_pt, message_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_line_string<T> const& multi_line) const
|
result_type operator()(multi_line_string<T> const& multi_line) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_line, message_);
|
return boost::geometry::is_valid(multi_line, message_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
result_type operator() (multi_polygon<T> const& multi_poly) const
|
result_type operator()(multi_polygon<T> const& multi_poly) const
|
||||||
{
|
{
|
||||||
return boost::geometry::is_valid(multi_poly, message_);
|
return boost::geometry::is_valid(multi_poly, message_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
}
|
template<typename T>
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline bool is_valid(T const& geom)
|
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)
|
inline bool is_valid(mapnik::geometry::geometry<T> const& geom)
|
||||||
{
|
{
|
||||||
return util::apply_visitor(detail::geometry_is_valid(), geom);
|
return util::apply_visitor(detail::geometry_is_valid(), geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
inline bool is_valid(T const& geom, boost::geometry::validity_failure_type & failure)
|
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>
|
template<typename T>
|
||||||
inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
|
inline bool is_valid(mapnik::geometry::geometry<T> const& geom, boost::geometry::validity_failure_type& failure)
|
||||||
boost::geometry::validity_failure_type & failure)
|
|
||||||
{
|
{
|
||||||
return util::apply_visitor(detail::geometry_is_valid_reason(failure), geom);
|
return util::apply_visitor(detail::geometry_is_valid_reason(failure), geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
inline bool is_valid(T const& geom, std::string & message)
|
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>
|
template<typename T>
|
||||||
inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
|
inline bool is_valid(mapnik::geometry::geometry<T> const& geom, std::string& message)
|
||||||
std::string & message)
|
|
||||||
{
|
{
|
||||||
return util::apply_visitor(detail::geometry_is_valid_string(message), geom);
|
return util::apply_visitor(detail::geometry_is_valid_string(message), geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // BOOST_VERSION >= 1.58
|
#endif // BOOST_VERSION >= 1.58
|
||||||
#endif // MAPNIK_GEOMETRY_IS_VALID_HPP
|
#endif // MAPNIK_GEOMETRY_IS_VALID_HPP
|
||||||
|
|
|
@ -26,10 +26,12 @@
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapbox/geometry/line_string.hpp>
|
#include <mapbox/geometry/line_string.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using line_string = mapbox::geometry::line_string<T>;
|
using line_string = mapbox::geometry::line_string<T>;
|
||||||
}}
|
}
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_LINE_STRING_HPP
|
#endif // MAPNIK_GEOMETRY_LINE_STRING_HPP
|
||||||
|
|
|
@ -26,11 +26,13 @@
|
||||||
// geometry
|
// geometry
|
||||||
#include <mapbox/geometry/multi_line_string.hpp>
|
#include <mapbox/geometry/multi_line_string.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using multi_line_string = mapbox::geometry::multi_line_string<T>;
|
using multi_line_string = mapbox::geometry::multi_line_string<T>;
|
||||||
|
|
||||||
}}
|
}
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_MULTI_LINE_STRING_HPP
|
#endif // MAPNIK_GEOMETRY_MULTI_LINE_STRING_HPP
|
||||||
|
|
|
@ -26,11 +26,13 @@
|
||||||
// geometry
|
// geometry
|
||||||
#include <mapbox/geometry/multi_point.hpp>
|
#include <mapbox/geometry/multi_point.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using multi_point = mapbox::geometry::multi_point<T>;
|
using multi_point = mapbox::geometry::multi_point<T>;
|
||||||
|
|
||||||
}}
|
}
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_MULTI_POINT_HPP
|
#endif // MAPNIK_GEOMETRY_MULTI_POINT_HPP
|
||||||
|
|
|
@ -26,9 +26,10 @@
|
||||||
// geometry
|
// geometry
|
||||||
#include <mapnik/geometry/polygon.hpp>
|
#include <mapnik/geometry/polygon.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T, template <typename...> class Cont = std::vector>
|
template<typename T, template<typename...> class Cont = std::vector>
|
||||||
struct multi_polygon : Cont<polygon<T>>
|
struct multi_polygon : Cont<polygon<T>>
|
||||||
{
|
{
|
||||||
using coordinate_type = T;
|
using coordinate_type = T;
|
||||||
|
@ -37,7 +38,7 @@ struct multi_polygon : Cont<polygon<T>>
|
||||||
using container_type::container_type;
|
using container_type::container_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace geometry
|
||||||
}}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_MULTI_POLYGON_HPP
|
#endif // MAPNIK_GEOMETRY_MULTI_POLYGON_HPP
|
||||||
|
|
|
@ -25,11 +25,13 @@
|
||||||
|
|
||||||
#include <mapbox/geometry/point.hpp>
|
#include <mapbox/geometry/point.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using point = mapbox::geometry::point<T>;
|
using point = mapbox::geometry::point<T>;
|
||||||
|
|
||||||
}}
|
}
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_POINT_HPP
|
#endif // MAPNIK_GEOMETRY_POINT_HPP
|
||||||
|
|
|
@ -26,14 +26,16 @@
|
||||||
// geometry
|
// geometry
|
||||||
#include <mapbox/geometry/polygon.hpp>
|
#include <mapbox/geometry/polygon.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using linear_ring = mapbox::geometry::linear_ring<T>;
|
using linear_ring = mapbox::geometry::linear_ring<T>;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using polygon = mapbox::geometry::polygon<T>;
|
using polygon = mapbox::geometry::polygon<T>;
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_POLYGON_HPP
|
#endif // MAPNIK_GEOMETRY_POLYGON_HPP
|
||||||
|
|
|
@ -27,13 +27,14 @@
|
||||||
#include <mapnik/geometry/point.hpp>
|
#include <mapnik/geometry/point.hpp>
|
||||||
#include <mapnik/geometry/polygon.hpp>
|
#include <mapnik/geometry/polygon.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct polygon_vertex_processor
|
struct polygon_vertex_processor
|
||||||
{
|
{
|
||||||
template <typename Path>
|
template<typename Path>
|
||||||
void add_path(Path & path)
|
void add_path(Path& path)
|
||||||
{
|
{
|
||||||
point<T> p;
|
point<T> p;
|
||||||
unsigned cmd;
|
unsigned cmd;
|
||||||
|
@ -61,6 +62,7 @@ struct polygon_vertex_processor
|
||||||
polygon<T> polygon_;
|
polygon<T> polygon_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} }
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_POLYGON_VERTEX_PROCESSOR_HPP
|
#endif // MAPNIK_GEOMETRY_POLYGON_VERTEX_PROCESSOR_HPP
|
||||||
|
|
|
@ -27,17 +27,16 @@
|
||||||
#include <mapnik/geometry/polygon.hpp>
|
#include <mapnik/geometry/polygon.hpp>
|
||||||
#include <mapnik/geometry/point.hpp>
|
#include <mapnik/geometry/point.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
template <class T>
|
template<class T>
|
||||||
MAPNIK_DECL bool polylabel(polygon<T> const& polygon,
|
MAPNIK_DECL bool polylabel(polygon<T> const& polygon, T precision, point<T>& pt);
|
||||||
T precision,
|
|
||||||
point<T> & pt);
|
|
||||||
|
|
||||||
template <class T>
|
template<class T>
|
||||||
MAPNIK_DECL T polylabel_precision(polygon<T> const& polygon,
|
MAPNIK_DECL T polylabel_precision(polygon<T> const& polygon, double scale_factor);
|
||||||
double scale_factor);
|
|
||||||
|
|
||||||
} }
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_POLYLABEL_HPP
|
#endif // MAPNIK_GEOMETRY_POLYLABEL_HPP
|
||||||
|
|
|
@ -26,34 +26,36 @@
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
#include <mapnik/geometry/is_empty.hpp>
|
#include <mapnik/geometry/is_empty.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
struct geometry_remove_empty
|
struct geometry_remove_empty
|
||||||
{
|
{
|
||||||
mapnik::geometry::multi_line_string<double> operator() (mapnik::geometry::multi_line_string<double> const& geom) const
|
mapnik::geometry::multi_line_string<double>
|
||||||
|
operator()(mapnik::geometry::multi_line_string<double> const& geom) const
|
||||||
{
|
{
|
||||||
return remove_empty(geom);
|
return remove_empty(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
return remove_empty(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T operator() (T const& geom) const
|
T operator()(T const& geom) const
|
||||||
{
|
{
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T remove_empty(T const& geom) const
|
T remove_empty(T const& geom) const
|
||||||
{
|
{
|
||||||
T new_geom;
|
T new_geom;
|
||||||
for (auto const & g : geom)
|
for (auto const& g : geom)
|
||||||
{
|
{
|
||||||
if (!g.empty())
|
if (!g.empty())
|
||||||
{
|
{
|
||||||
|
@ -64,14 +66,15 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template <typename GeomType>
|
template<typename GeomType>
|
||||||
inline GeomType remove_empty(GeomType const& geom)
|
inline GeomType remove_empty(GeomType const& geom)
|
||||||
{
|
{
|
||||||
return detail::geometry_remove_empty()(geom);
|
return detail::geometry_remove_empty()(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_REMOVE_EMPTY_HPP
|
#endif // MAPNIK_GEOMETRY_REMOVE_EMPTY_HPP
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include <mapnik/proj_transform.hpp>
|
#include <mapnik/proj_transform.hpp>
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
namespace geometry {
|
namespace geometry {
|
||||||
|
@ -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
|
// 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.
|
// still be return with out the few failing projections.
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
MAPNIK_DECL geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
|
MAPNIK_DECL geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int& n_err);
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
MAPNIK_DECL T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err);
|
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, projection const& source, projection const& dest, unsigned int& n_err);
|
||||||
|
|
||||||
// No error count is required for a non const reprojection and this will reproject in place.
|
// No error count is required for a non const reprojection and this will reproject in place.
|
||||||
// because the reprojection is done on the same memory it is important to check if it succeeded,
|
// because the reprojection is done on the same memory it is important to check if it succeeded,
|
||||||
// otherwise you could be dealing with a corrupt geometry.
|
// otherwise you could be dealing with a corrupt geometry.
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
MAPNIK_DECL bool reproject(T & geom, proj_transform const& proj_trans);
|
MAPNIK_DECL bool reproject(T& geom, proj_transform const& proj_trans);
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
MAPNIK_DECL bool reproject(T & geom, projection const& source, projection const& dest);
|
MAPNIK_DECL bool reproject(T& geom, projection const& source, projection const& dest);
|
||||||
|
|
||||||
} // end geometry ns
|
} // namespace geometry
|
||||||
|
|
||||||
} // end mapnik ns
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_REPROJECTION_HPP
|
#endif // MAPNIK_GEOMETRY_REPROJECTION_HPP
|
||||||
|
|
|
@ -24,16 +24,18 @@
|
||||||
#include <mapnik/geometry/reprojection.hpp>
|
#include <mapnik/geometry/reprojection.hpp>
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry { namespace detail {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
//template <typename T>
|
// template <typename T>
|
||||||
geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int &)
|
geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int&)
|
||||||
{
|
{
|
||||||
return geometry_empty();
|
return geometry_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
point<T> reproject_internal(point<T> const& p, proj_transform const& proj_trans, unsigned int & n_err)
|
point<T> reproject_internal(point<T> const& p, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
point<T> new_p(p);
|
point<T> new_p(p);
|
||||||
if (!proj_trans.forward(new_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;
|
return new_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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> reproject_internal(line_string<T> const& ls, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
line_string<T> new_ls(ls);
|
line_string<T> new_ls(ls);
|
||||||
unsigned int err = proj_trans.forward(new_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;
|
return new_ls;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj_trans, unsigned int & n_err)
|
polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
polygon<T> new_poly;
|
polygon<T> new_poly;
|
||||||
new_poly.reserve(poly.size());
|
new_poly.reserve(poly.size());
|
||||||
|
@ -70,17 +72,18 @@ polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj
|
||||||
n_err += err;
|
n_err += err;
|
||||||
// If there is an error in interior ring drop
|
// If there is an error in interior ring drop
|
||||||
// it from polygon.
|
// it from polygon.
|
||||||
if (!exterior) continue;
|
if (!exterior)
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (exterior) exterior = false;
|
if (exterior)
|
||||||
|
exterior = false;
|
||||||
new_poly.push_back(std::move(new_lr));
|
new_poly.push_back(std::move(new_lr));
|
||||||
|
|
||||||
}
|
}
|
||||||
return new_poly;
|
return new_poly;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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> reproject_internal(multi_point<T> const& mp, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
multi_point<T> new_mp;
|
multi_point<T> new_mp;
|
||||||
if (proj_trans.is_known())
|
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;
|
return new_mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
multi_line_string<T> reproject_internal(multi_line_string<T> const & mls, proj_transform const& proj_trans, unsigned int & n_err)
|
multi_line_string<T>
|
||||||
|
reproject_internal(multi_line_string<T> const& mls, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
multi_line_string<T> new_mls;
|
multi_line_string<T> new_mls;
|
||||||
new_mls.reserve(mls.size());
|
new_mls.reserve(mls.size());
|
||||||
|
@ -125,8 +129,9 @@ multi_line_string<T> reproject_internal(multi_line_string<T> const & mls, proj_t
|
||||||
return new_mls;
|
return new_mls;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transform const& proj_trans, unsigned int & n_err)
|
multi_polygon<T>
|
||||||
|
reproject_internal(multi_polygon<T> const& mpoly, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
multi_polygon<T> new_mpoly;
|
multi_polygon<T> new_mpoly;
|
||||||
new_mpoly.reserve(mpoly.size());
|
new_mpoly.reserve(mpoly.size());
|
||||||
|
@ -141,14 +146,14 @@ multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transfo
|
||||||
return new_mpoly;
|
return new_mpoly;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj_transform const& proj_trans, unsigned int & n_err)
|
geometry_collection<T>
|
||||||
|
reproject_internal(geometry_collection<T> const& c, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
geometry_collection<T> new_c;
|
geometry_collection<T> new_c;
|
||||||
new_c.reserve(c.size());
|
new_c.reserve(c.size());
|
||||||
for (auto const& g : c)
|
for (auto const& g : c)
|
||||||
{
|
{
|
||||||
|
|
||||||
geometry<T> new_g = reproject_copy(g, proj_trans, n_err);
|
geometry<T> new_g = reproject_copy(g, proj_trans, n_err);
|
||||||
if (!new_g.template is<geometry_empty>())
|
if (!new_g.template is<geometry_empty>())
|
||||||
{
|
{
|
||||||
|
@ -158,107 +163,110 @@ geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj
|
||||||
return new_c;
|
return new_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct geom_reproj_copy_visitor
|
struct geom_reproj_copy_visitor
|
||||||
{
|
{
|
||||||
|
geom_reproj_copy_visitor(proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
|
: proj_trans_(proj_trans)
|
||||||
|
, n_err_(n_err)
|
||||||
|
{}
|
||||||
|
|
||||||
geom_reproj_copy_visitor(proj_transform const & proj_trans, unsigned int & n_err)
|
geometry<T> operator()(geometry_empty) const { return geometry_empty(); }
|
||||||
: proj_trans_(proj_trans),
|
|
||||||
n_err_(n_err) {}
|
|
||||||
|
|
||||||
geometry<T> operator() (geometry_empty) const
|
geometry<T> operator()(point<T> const& p) const
|
||||||
{
|
|
||||||
return geometry_empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
geometry<T> operator() (point<T> const& p) const
|
|
||||||
{
|
{
|
||||||
geometry<T> geom; // default empty
|
geometry<T> geom; // default empty
|
||||||
unsigned int intial_err = n_err_;
|
unsigned int intial_err = n_err_;
|
||||||
point<T> new_p = reproject_internal(p, proj_trans_, n_err_);
|
point<T> new_p = reproject_internal(p, proj_trans_, n_err_);
|
||||||
if (n_err_ > intial_err) return geom;
|
if (n_err_ > intial_err)
|
||||||
|
return geom;
|
||||||
geom = std::move(new_p);
|
geom = std::move(new_p);
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry<T> operator() (line_string<T> const& ls) const
|
geometry<T> operator()(line_string<T> const& ls) const
|
||||||
{
|
{
|
||||||
geometry<T> geom; // default empty
|
geometry<T> geom; // default empty
|
||||||
unsigned int intial_err = n_err_;
|
unsigned int intial_err = n_err_;
|
||||||
line_string<T> new_ls = reproject_internal(ls, proj_trans_, n_err_);
|
line_string<T> new_ls = reproject_internal(ls, proj_trans_, n_err_);
|
||||||
if (n_err_ > intial_err || new_ls.empty()) return geom;
|
if (n_err_ > intial_err || new_ls.empty())
|
||||||
|
return geom;
|
||||||
geom = std::move(new_ls);
|
geom = std::move(new_ls);
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry<T> operator() (polygon<T> const& poly) const
|
geometry<T> operator()(polygon<T> const& poly) const
|
||||||
{
|
{
|
||||||
geometry<T> geom; // default empty
|
geometry<T> geom; // default empty
|
||||||
polygon<T> new_poly = reproject_internal(poly, proj_trans_, n_err_);
|
polygon<T> new_poly = reproject_internal(poly, proj_trans_, n_err_);
|
||||||
if (new_poly.size() == 0 || new_poly[0].size() == 0) return geom;
|
if (new_poly.size() == 0 || new_poly[0].size() == 0)
|
||||||
|
return geom;
|
||||||
geom = std::move(new_poly);
|
geom = std::move(new_poly);
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry<T> operator() (multi_point<T> const& mp) const
|
geometry<T> operator()(multi_point<T> const& mp) const
|
||||||
{
|
{
|
||||||
geometry<T> geom; // default empty
|
geometry<T> geom; // default empty
|
||||||
multi_point<T> new_mp = reproject_internal(mp, proj_trans_, n_err_);
|
multi_point<T> new_mp = reproject_internal(mp, proj_trans_, n_err_);
|
||||||
if (new_mp.empty()) return geom;
|
if (new_mp.empty())
|
||||||
|
return geom;
|
||||||
geom = std::move(new_mp);
|
geom = std::move(new_mp);
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
geometry<T> geom; // default empty
|
||||||
multi_line_string<T> new_mls = reproject_internal(mls, proj_trans_, n_err_);
|
multi_line_string<T> new_mls = reproject_internal(mls, proj_trans_, n_err_);
|
||||||
if (new_mls.empty()) return geom;
|
if (new_mls.empty())
|
||||||
|
return geom;
|
||||||
geom = std::move(new_mls);
|
geom = std::move(new_mls);
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry<T> operator() (multi_polygon<T> const& mpoly) const
|
geometry<T> operator()(multi_polygon<T> const& mpoly) const
|
||||||
{
|
{
|
||||||
geometry<T> geom; // default empty
|
geometry<T> geom; // default empty
|
||||||
multi_polygon<T> new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_);
|
multi_polygon<T> new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_);
|
||||||
if (new_mpoly.empty()) return geom;
|
if (new_mpoly.empty())
|
||||||
|
return geom;
|
||||||
geom = std::move(new_mpoly);
|
geom = std::move(new_mpoly);
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry<T> operator() (geometry_collection<T> const& c) const
|
geometry<T> operator()(geometry_collection<T> const& c) const
|
||||||
{
|
{
|
||||||
geometry<T> geom; // default empty
|
geometry<T> geom; // default empty
|
||||||
geometry_collection<T> new_c = reproject_internal(c, proj_trans_, n_err_);
|
geometry_collection<T> new_c = reproject_internal(c, proj_trans_, n_err_);
|
||||||
if (new_c.empty()) return geom;
|
if (new_c.empty())
|
||||||
|
return geom;
|
||||||
geom = std::move(new_c);
|
geom = std::move(new_c);
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
proj_transform const& proj_trans_;
|
proj_transform const& proj_trans_;
|
||||||
unsigned int & n_err_;
|
unsigned int& n_err_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end detail ns
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int & n_err)
|
geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
detail::geom_reproj_copy_visitor<T> visit(proj_trans, n_err);
|
detail::geom_reproj_copy_visitor<T> visit(proj_trans, n_err);
|
||||||
return mapnik::util::apply_visitor(visit, geom);
|
return mapnik::util::apply_visitor(visit, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err)
|
T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
return detail::reproject_internal(geom, proj_trans, n_err);
|
return detail::reproject_internal(geom, proj_trans, n_err);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int & n_err)
|
T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int& n_err)
|
||||||
{
|
{
|
||||||
proj_transform proj_trans(source, dest);
|
proj_transform proj_trans(source, dest);
|
||||||
return reproject_copy(geom, proj_trans, n_err);
|
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 {
|
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)
|
template<typename T>
|
||||||
: proj_trans_(proj_trans) {}
|
bool operator()(geometry<T>& geom) const
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
bool operator() (geometry<T> & geom) const
|
|
||||||
{
|
{
|
||||||
return mapnik::util::apply_visitor((*this), geom);
|
return mapnik::util::apply_visitor((*this), geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
//template <typename T>
|
// template <typename T>
|
||||||
bool operator() (geometry_empty &) const { return true; }
|
bool operator()(geometry_empty&) const { return true; }
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool operator() (point<T> & p) const
|
bool operator()(point<T>& p) const
|
||||||
{
|
{
|
||||||
if (!proj_trans_.forward(p))
|
if (!proj_trans_.forward(p))
|
||||||
{
|
{
|
||||||
|
@ -290,8 +299,8 @@ struct geom_reproj_visitor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool operator() (line_string<T> & ls) const
|
bool operator()(line_string<T>& ls) const
|
||||||
{
|
{
|
||||||
if (proj_trans_.forward(ls) > 0)
|
if (proj_trans_.forward(ls) > 0)
|
||||||
{
|
{
|
||||||
|
@ -300,10 +309,10 @@ struct geom_reproj_visitor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool operator() (polygon<T> & poly) const
|
bool operator()(polygon<T>& poly) const
|
||||||
{
|
{
|
||||||
for (auto & lr : poly)
|
for (auto& lr : poly)
|
||||||
{
|
{
|
||||||
if (proj_trans_.forward(lr) > 0)
|
if (proj_trans_.forward(lr) > 0)
|
||||||
{
|
{
|
||||||
|
@ -313,8 +322,8 @@ struct geom_reproj_visitor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool operator() (multi_point<T> & mp) const
|
bool operator()(multi_point<T>& mp) const
|
||||||
{
|
{
|
||||||
if (proj_trans_.forward(mp) > 0)
|
if (proj_trans_.forward(mp) > 0)
|
||||||
{
|
{
|
||||||
|
@ -323,12 +332,12 @@ struct geom_reproj_visitor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool operator() (multi_line_string<T> & mls) const
|
bool operator()(multi_line_string<T>& mls) const
|
||||||
{
|
{
|
||||||
for (auto & ls : mls)
|
for (auto& ls : mls)
|
||||||
{
|
{
|
||||||
if (! (*this) (ls))
|
if (!(*this)(ls))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -336,12 +345,12 @@ struct geom_reproj_visitor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool operator() (multi_polygon<T> & mpoly) const
|
bool operator()(multi_polygon<T>& mpoly) const
|
||||||
{
|
{
|
||||||
for (auto & poly : mpoly)
|
for (auto& poly : mpoly)
|
||||||
{
|
{
|
||||||
if(! (*this)(poly))
|
if (!(*this)(poly))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -349,12 +358,12 @@ struct geom_reproj_visitor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool operator() (geometry_collection<T> & c) const
|
bool operator()(geometry_collection<T>& c) const
|
||||||
{
|
{
|
||||||
for (auto & g : c)
|
for (auto& g : c)
|
||||||
{
|
{
|
||||||
if (! (*this)(g) )
|
if (!(*this)(g))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -362,27 +371,26 @@ struct geom_reproj_visitor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
proj_transform const& proj_trans_;
|
proj_transform const& proj_trans_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end detail ns
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool reproject(T & geom, proj_transform const& proj_trans)
|
bool reproject(T& geom, proj_transform const& proj_trans)
|
||||||
{
|
{
|
||||||
detail::geom_reproj_visitor visit(proj_trans);
|
detail::geom_reproj_visitor visit(proj_trans);
|
||||||
return visit(geom);
|
return visit(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool reproject(T & geom, projection const& source, projection const& dest)
|
bool reproject(T& geom, projection const& source, projection const& dest)
|
||||||
{
|
{
|
||||||
proj_transform proj_trans(source, dest);
|
proj_transform proj_trans(source, dest);
|
||||||
detail::geom_reproj_visitor visit(proj_trans);
|
detail::geom_reproj_visitor visit(proj_trans);
|
||||||
return visit(geom);
|
return visit(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end geometry ns
|
} // namespace geometry
|
||||||
} // end mapnik ns
|
} // namespace mapnik
|
||||||
|
|
|
@ -29,129 +29,133 @@
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
namespace geometry {
|
namespace geometry {
|
||||||
|
|
||||||
namespace helper
|
namespace helper {
|
||||||
{
|
template<std::size_t... Ts>
|
||||||
template <std::size_t... Ts>
|
struct index
|
||||||
struct index {};
|
{};
|
||||||
|
|
||||||
template <std::size_t N, std::size_t... Ts>
|
template<std::size_t N, std::size_t... Ts>
|
||||||
struct gen_seq : gen_seq<N - 1, N - 1, Ts...> {};
|
struct gen_seq : gen_seq<N - 1, N - 1, Ts...>
|
||||||
|
{};
|
||||||
|
|
||||||
template <std::size_t... Ts>
|
template<std::size_t... Ts>
|
||||||
struct gen_seq<0, Ts...> : index<Ts...> {};
|
struct gen_seq<0, Ts...> : index<Ts...>
|
||||||
}
|
{};
|
||||||
|
} // namespace helper
|
||||||
|
|
||||||
// Groups a set of strategies at runtime, the conversion from P1 to P2 will take place on the LAST strategy.
|
// Groups a set of strategies at runtime, the conversion from P1 to P2 will take place on the LAST strategy.
|
||||||
template <typename... Strategies>
|
template<typename... Strategies>
|
||||||
struct strategy_group
|
struct strategy_group
|
||||||
{
|
{
|
||||||
strategy_group(Strategies const& ... ops)
|
strategy_group(Strategies const&... ops)
|
||||||
: ops_(ops ...) {}
|
: ops_(ops...)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
inline bool apply(P1 const& p1, P2 & p2) const
|
inline bool apply(P1 const& p1, P2& p2) const
|
||||||
{
|
{
|
||||||
bool status = true;
|
bool status = true;
|
||||||
p2 = execute_start<P1,P2>(p1, status, ops_);
|
p2 = execute_start<P1, P2>(p1, status, ops_);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2, typename... Args, std::size_t... Is>
|
template<typename P1, typename P2, typename... Args, std::size_t... Is>
|
||||||
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
|
inline P2
|
||||||
|
execute_start(P1 const& p1, bool& status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
|
||||||
{
|
{
|
||||||
return execute<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
|
return execute<P1, P2, Args...>(p1, status, std::get<Is>(tup)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
|
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>
|
template<typename P1, typename P2, typename T, typename... Args>
|
||||||
inline P2 execute(P1 const& p, bool & status, T const& strat, Args const& ... args) const
|
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>
|
template<typename P1, typename P2, typename T>
|
||||||
inline P2 execute(P1 const& p, bool & status, T const& strat) const
|
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:
|
private:
|
||||||
std::tuple<Strategies const& ...> ops_;
|
std::tuple<Strategies const&...> ops_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// The difference between this strategy group and the previous is that the conversion from P1 to P2 happens
|
// The difference between this strategy group and the previous is that the conversion from P1 to P2 happens
|
||||||
// in the first strategy rather then the last strategy.
|
// in the first strategy rather then the last strategy.
|
||||||
template <typename... Strategies>
|
template<typename... Strategies>
|
||||||
struct strategy_group_first
|
struct strategy_group_first
|
||||||
{
|
{
|
||||||
strategy_group_first(Strategies const& ... ops)
|
strategy_group_first(Strategies const&... ops)
|
||||||
: ops_(ops ...) {}
|
: ops_(ops...)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
inline bool apply(P1 const& p1, P2 & p2) const
|
inline bool apply(P1 const& p1, P2& p2) const
|
||||||
{
|
{
|
||||||
bool status = true;
|
bool status = true;
|
||||||
p2 = execute_start<P1,P2>(p1, status, ops_);
|
p2 = execute_start<P1, P2>(p1, status, ops_);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2, typename... Args, std::size_t... Is>
|
template<typename P1, typename P2, typename... Args, std::size_t... Is>
|
||||||
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
|
inline P2
|
||||||
|
execute_start(P1 const& p1, bool& status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
|
||||||
{
|
{
|
||||||
return execute_first<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
|
return execute_first<P1, P2, Args...>(p1, status, std::get<Is>(tup)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
|
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>
|
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
|
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>
|
template<typename P2, typename T, typename... Args>
|
||||||
inline P2 execute(P2 const& p, bool & status, T const& strat, Args const& ... args) const
|
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>
|
template<typename P2, typename T>
|
||||||
inline P2 execute(P2 const& p, bool & status, T const& strat) const
|
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>
|
template<typename P2>
|
||||||
inline P2 execute(P2 const& p, bool & status) const
|
inline P2 execute(P2 const& p, bool& status) const
|
||||||
{
|
{
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::tuple<Strategies const& ...> ops_;
|
std::tuple<Strategies const&...> ops_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct scale_strategy
|
struct scale_strategy
|
||||||
{
|
{
|
||||||
scale_strategy(double scale, double offset = 0)
|
scale_strategy(double scale, double offset = 0)
|
||||||
: scale_(scale), offset_(offset) {}
|
: scale_(scale)
|
||||||
|
, offset_(offset)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
inline bool apply(P1 const & p1, P2 & p2) const
|
inline bool apply(P1 const& p1, P2& p2) const
|
||||||
{
|
{
|
||||||
|
|
||||||
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
|
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
|
||||||
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
|
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
|
||||||
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
|
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
|
||||||
|
@ -160,15 +164,15 @@ struct scale_strategy
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
inline P2 execute(P1 const& p1, bool & status) const
|
inline P2 execute(P1 const& p1, bool& status) const
|
||||||
{
|
{
|
||||||
P2 p2;
|
P2 p2;
|
||||||
status = apply(p1, p2);
|
status = apply(p1, p2);
|
||||||
return p2;
|
return p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double scale_;
|
double scale_;
|
||||||
double offset_;
|
double offset_;
|
||||||
};
|
};
|
||||||
|
@ -176,12 +180,13 @@ private:
|
||||||
struct scale_rounding_strategy
|
struct scale_rounding_strategy
|
||||||
{
|
{
|
||||||
scale_rounding_strategy(double scale, double offset = 0)
|
scale_rounding_strategy(double scale, double offset = 0)
|
||||||
: scale_(scale), offset_(offset) {}
|
: scale_(scale)
|
||||||
|
, offset_(offset)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
inline bool apply(P1 const & p1, P2 & p2) const
|
inline bool apply(P1 const& p1, P2& p2) const
|
||||||
{
|
{
|
||||||
|
|
||||||
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
|
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
|
||||||
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
|
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
|
||||||
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
|
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
|
||||||
|
@ -190,21 +195,20 @@ struct scale_rounding_strategy
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
inline P2 execute(P1 const& p1, bool & status) const
|
inline P2 execute(P1 const& p1, bool& status) const
|
||||||
{
|
{
|
||||||
P2 p2;
|
P2 p2;
|
||||||
status = apply(p1, p2);
|
status = apply(p1, p2);
|
||||||
return p2;
|
return p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double scale_;
|
double scale_;
|
||||||
double offset_;
|
double offset_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
} // end geometry ns
|
#endif // MAPNIK_GEOMETRY_STRATEGY_HPP
|
||||||
} // end mapnik ns
|
|
||||||
|
|
||||||
#endif //MAPNIK_GEOMETRY_STRATEGY_HPP
|
|
||||||
|
|
|
@ -26,46 +26,51 @@
|
||||||
#include <mapnik/geometry.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
#include <mapnik/path.hpp>
|
#include <mapnik/path.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry { namespace detail {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct geometry_to_path
|
struct geometry_to_path
|
||||||
{
|
{
|
||||||
geometry_to_path(path_type & p)
|
geometry_to_path(path_type& p)
|
||||||
: p_(p) {}
|
: p_(p)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator() (geometry<T> const& geom) const
|
void operator()(geometry<T> const& geom) const { mapnik::util::apply_visitor(*this, geom); }
|
||||||
{
|
|
||||||
mapnik::util::apply_visitor(*this, geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator() (geometry_empty const&) const
|
void operator()(geometry_empty const&) const
|
||||||
{
|
{
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
// point
|
// point
|
||||||
void operator() (point<T> const& pt) const
|
void operator()(point<T> const& pt) const
|
||||||
{
|
{
|
||||||
//point pt_new;
|
// point pt_new;
|
||||||
//Transformer::apply(pt, pt_new);
|
// Transformer::apply(pt, pt_new);
|
||||||
p_.move_to(pt.x, pt.y);
|
p_.move_to(pt.x, pt.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// line_string
|
// line_string
|
||||||
void operator() (line_string<T> const& line) const
|
void operator()(line_string<T> const& line) const
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto const& pt : line)
|
for (auto const& pt : line)
|
||||||
{
|
{
|
||||||
//point pt_new;
|
// point pt_new;
|
||||||
//Transformer::apply(pt, pt_new);
|
// Transformer::apply(pt, pt_new);
|
||||||
if (first) { p_.move_to(pt.x, pt.y); first=false;}
|
if (first)
|
||||||
else p_.line_to(pt.x, pt.y);
|
{
|
||||||
|
p_.move_to(pt.x, pt.y);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
p_.line_to(pt.x, pt.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// polygon
|
// polygon
|
||||||
void operator() (polygon<T> const& poly) const
|
void operator()(polygon<T> const& poly) const
|
||||||
{
|
{
|
||||||
// rings: exterior *interior
|
// rings: exterior *interior
|
||||||
for (auto const& ring : poly)
|
for (auto const& ring : poly)
|
||||||
|
@ -76,7 +81,7 @@ struct geometry_to_path
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
p_.move_to(pt.x, pt.y);
|
p_.move_to(pt.x, pt.y);
|
||||||
first=false;
|
first = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -91,7 +96,7 @@ struct geometry_to_path
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi point
|
// 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)
|
for (auto const& pt : multi_pt)
|
||||||
{
|
{
|
||||||
|
@ -99,7 +104,7 @@ struct geometry_to_path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// multi_line_string
|
// 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)
|
for (auto const& line : multi_line)
|
||||||
{
|
{
|
||||||
|
@ -108,7 +113,7 @@ struct geometry_to_path
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi_polygon
|
// 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)
|
for (auto const& poly : multi_poly)
|
||||||
{
|
{
|
||||||
|
@ -116,7 +121,7 @@ struct geometry_to_path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// geometry_collection
|
// 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)
|
||||||
{
|
{
|
||||||
|
@ -124,19 +129,19 @@ struct geometry_to_path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
path_type & p_;
|
path_type& p_;
|
||||||
|
|
||||||
};
|
};
|
||||||
} // ns detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void to_path(T const& geom, path_type & p)
|
void to_path(T const& geom, path_type& p)
|
||||||
{
|
{
|
||||||
using coordinate_type = typename T::coordinate_type;
|
using coordinate_type = typename T::coordinate_type;
|
||||||
detail::geometry_to_path<coordinate_type> func(p);
|
detail::geometry_to_path<coordinate_type> func(p);
|
||||||
func(geom);
|
func(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
} // namespace geometry
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_TO_PATH_HPP
|
#endif // MAPNIK_GEOMETRY_TO_PATH_HPP
|
||||||
|
|
|
@ -27,9 +27,11 @@
|
||||||
#include <mapnik/geometry/boost_adapters.hpp>
|
#include <mapnik/geometry/boost_adapters.hpp>
|
||||||
#include <boost/geometry/algorithms/transform.hpp>
|
#include <boost/geometry/algorithms/transform.hpp>
|
||||||
|
|
||||||
namespace mapnik { namespace geometry { namespace detail {
|
namespace mapnik {
|
||||||
|
namespace geometry {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
template <typename V, typename T, typename Transformer>
|
template<typename V, typename T, typename Transformer>
|
||||||
inline point<V> transform_geometry(point<T> const& geom, Transformer const& transformer)
|
inline point<V> transform_geometry(point<T> const& geom, Transformer const& transformer)
|
||||||
{
|
{
|
||||||
point<V> geom_transformed;
|
point<V> geom_transformed;
|
||||||
|
@ -40,7 +42,7 @@ inline point<V> transform_geometry(point<T> const& geom, Transformer const& tran
|
||||||
return geom_transformed;
|
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)
|
inline multi_point<V> transform_geometry(multi_point<T> const& geom, Transformer const& transformer)
|
||||||
{
|
{
|
||||||
multi_point<V> geom_transformed;
|
multi_point<V> geom_transformed;
|
||||||
|
@ -51,7 +53,7 @@ inline multi_point<V> transform_geometry(multi_point<T> const& geom, Transformer
|
||||||
return geom_transformed;
|
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)
|
inline line_string<V> transform_geometry(line_string<T> const& geom, Transformer const& transformer)
|
||||||
{
|
{
|
||||||
line_string<V> geom_transformed;
|
line_string<V> geom_transformed;
|
||||||
|
@ -62,7 +64,7 @@ inline line_string<V> transform_geometry(line_string<T> const& geom, Transformer
|
||||||
return geom_transformed;
|
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)
|
inline multi_line_string<V> transform_geometry(multi_line_string<T> const& geom, Transformer const& transformer)
|
||||||
{
|
{
|
||||||
multi_line_string<V> geom_transformed;
|
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;
|
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)
|
inline polygon<V> transform_geometry(polygon<T> const& geom, Transformer const& transformer)
|
||||||
{
|
{
|
||||||
polygon<V> geom_transformed;
|
polygon<V> geom_transformed;
|
||||||
|
@ -84,7 +86,7 @@ inline polygon<V> transform_geometry(polygon<T> const& geom, Transformer const&
|
||||||
return geom_transformed;
|
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)
|
inline multi_polygon<V> transform_geometry(multi_polygon<T> const& geom, Transformer const& transformer)
|
||||||
{
|
{
|
||||||
multi_polygon<V> geom_transformed;
|
multi_polygon<V> geom_transformed;
|
||||||
|
@ -95,21 +97,19 @@ inline multi_polygon<V> transform_geometry(multi_polygon<T> const& geom, Transfo
|
||||||
return geom_transformed;
|
return geom_transformed;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Transformer, typename V>
|
template<typename Transformer, typename V>
|
||||||
struct geometry_transform
|
struct geometry_transform
|
||||||
{
|
{
|
||||||
geometry_transform(Transformer const& transformer)
|
geometry_transform(Transformer const& transformer)
|
||||||
: transformer_(transformer) {}
|
: transformer_(transformer)
|
||||||
|
{}
|
||||||
|
|
||||||
using result_type = geometry<V>;
|
using result_type = geometry<V>;
|
||||||
|
|
||||||
geometry<V> operator() (geometry_empty const& empty) const
|
geometry<V> operator()(geometry_empty const& empty) const { return geometry_empty(); }
|
||||||
{
|
|
||||||
return geometry_empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<V> operator() (geometry_collection<T> const& collection) const
|
geometry<V> operator()(geometry_collection<T> const& collection) const
|
||||||
{
|
{
|
||||||
geometry_collection<V> collection_out;
|
geometry_collection<V> collection_out;
|
||||||
for (auto const& geom : collection)
|
for (auto const& geom : collection)
|
||||||
|
@ -119,44 +119,44 @@ struct geometry_transform
|
||||||
return collection_out;
|
return collection_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<V> operator() (geometry<T> const& geom) const
|
geometry<V> operator()(geometry<T> const& geom) const
|
||||||
{
|
{
|
||||||
return mapnik::util::apply_visitor(*this, geom);
|
return mapnik::util::apply_visitor(*this, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<V> operator() (point<T> const& geom) const
|
geometry<V> operator()(point<T> const& geom) const
|
||||||
{
|
{
|
||||||
return transform_geometry<V>(geom, transformer_);
|
return transform_geometry<V>(geom, transformer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<V> operator() (line_string<T> const& geom) const
|
geometry<V> operator()(line_string<T> const& geom) const
|
||||||
{
|
{
|
||||||
return transform_geometry<V>(geom, transformer_);
|
return transform_geometry<V>(geom, transformer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<V> operator() (polygon<T> const& geom) const
|
geometry<V> operator()(polygon<T> const& geom) const
|
||||||
{
|
{
|
||||||
return transform_geometry<V>(geom, transformer_);
|
return transform_geometry<V>(geom, transformer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<V> operator() (multi_point<T> const& geom) const
|
geometry<V> operator()(multi_point<T> const& geom) const
|
||||||
{
|
{
|
||||||
return transform_geometry<V>(geom, transformer_);
|
return transform_geometry<V>(geom, transformer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<V> operator() (multi_line_string<T> const& geom) const
|
geometry<V> operator()(multi_line_string<T> const& geom) const
|
||||||
{
|
{
|
||||||
return transform_geometry<V>(geom, transformer_);
|
return transform_geometry<V>(geom, transformer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
geometry<V> operator() (multi_polygon<T> const& geom) const
|
geometry<V> operator()(multi_polygon<T> const& geom) const
|
||||||
{
|
{
|
||||||
return transform_geometry<V>(geom, transformer_);
|
return transform_geometry<V>(geom, transformer_);
|
||||||
}
|
}
|
||||||
|
@ -164,57 +164,57 @@ struct geometry_transform
|
||||||
Transformer const& transformer_;
|
Transformer const& transformer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ns detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T0, typename T1, typename T2>
|
template<typename T0, typename T1, typename T2>
|
||||||
geometry<T0> transform(geometry<T1> const& geom, T2 const& transformer)
|
geometry<T0> transform(geometry<T1> const& geom, T2 const& transformer)
|
||||||
{
|
{
|
||||||
return detail::geometry_transform<T2, T0>(transformer)(geom);
|
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)
|
geometry<T0> transform(geometry_collection<T1> const& geom, T2 const& transformer)
|
||||||
{
|
{
|
||||||
return detail::geometry_transform<T2, T0>(transformer)(geom);
|
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)
|
point<T0> transform(point<T1> const& geom, T2 const& transformer)
|
||||||
{
|
{
|
||||||
return detail::transform_geometry<T0>(geom, 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)
|
multi_point<T0> transform(multi_point<T1> const& geom, T2 const& transformer)
|
||||||
{
|
{
|
||||||
return detail::transform_geometry<T0>(geom, 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)
|
line_string<T0> transform(line_string<T1> const& geom, T2 const& transformer)
|
||||||
{
|
{
|
||||||
return detail::transform_geometry<T0>(geom, 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)
|
multi_line_string<T0> transform(multi_line_string<T1> const& geom, T2 const& transformer)
|
||||||
{
|
{
|
||||||
return detail::transform_geometry<T0>(geom, 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)
|
polygon<T0> transform(polygon<T1> const& geom, T2 const& transformer)
|
||||||
{
|
{
|
||||||
return detail::transform_geometry<T0>(geom, 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)
|
multi_polygon<T0> transform(multi_polygon<T1> const& geom, T2 const& transformer)
|
||||||
{
|
{
|
||||||
return detail::transform_geometry<T0>(geom, transformer);
|
return detail::transform_geometry<T0>(geom, transformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace geometry
|
||||||
}}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GEOMETRY_TRANSFORM_HPP
|
#endif // MAPNIK_GEOMETRY_TRANSFORM_HPP
|
||||||
|
|
|
@ -28,86 +28,84 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
#define int2net(A) (int16_t) (((std::uint16_t) ((std::uint8_t) (A)[1])) | \
|
#define int2net(A) (int16_t)(((std::uint16_t)((std::uint8_t)(A)[1])) | (((std::uint16_t)((std::uint8_t)(A)[0])) << 8))
|
||||||
(((std::uint16_t) ((std::uint8_t) (A)[0])) << 8))
|
|
||||||
|
|
||||||
#define int4net(A) (int32_t) (((std::uint32_t) ((std::uint8_t) (A)[3])) | \
|
#define int4net(A) \
|
||||||
(((std::uint32_t) ((std::uint8_t) (A)[2])) << 8) | \
|
(int32_t)(((std::uint32_t)((std::uint8_t)(A)[3])) | (((std::uint32_t)((std::uint8_t)(A)[2])) << 8) | \
|
||||||
(((std::uint32_t) ((std::uint8_t) (A)[1])) << 16) | \
|
(((std::uint32_t)((std::uint8_t)(A)[1])) << 16) | (((std::uint32_t)((std::uint8_t)(A)[0])) << 24))
|
||||||
(((std::uint32_t) ((std::uint8_t) (A)[0])) << 24))
|
|
||||||
|
|
||||||
#define int8net(A) (int64_t) (((std::uint64_t) ((std::uint8_t) (A)[7])) | \
|
#define int8net(A) \
|
||||||
(((std::uint64_t) ((std::uint8_t) (A)[6])) << 8) | \
|
(int64_t)(((std::uint64_t)((std::uint8_t)(A)[7])) | (((std::uint64_t)((std::uint8_t)(A)[6])) << 8) | \
|
||||||
(((std::uint64_t) ((std::uint8_t) (A)[5])) << 16) | \
|
(((std::uint64_t)((std::uint8_t)(A)[5])) << 16) | (((std::uint64_t)((std::uint8_t)(A)[4])) << 24) | \
|
||||||
(((std::uint64_t) ((std::uint8_t) (A)[4])) << 24) | \
|
(((std::uint64_t)((std::uint8_t)(A)[3])) << 32) | (((std::uint64_t)((std::uint8_t)(A)[2])) << 40) | \
|
||||||
(((std::uint64_t) ((std::uint8_t) (A)[3])) << 32) | \
|
(((std::uint64_t)((std::uint8_t)(A)[1])) << 48) | (((std::uint64_t)((std::uint8_t)(A)[0])) << 56))
|
||||||
(((std::uint64_t) ((std::uint8_t) (A)[2])) << 40) | \
|
|
||||||
(((std::uint64_t) ((std::uint8_t) (A)[1])) << 48) | \
|
|
||||||
(((std::uint64_t) ((std::uint8_t) (A)[0])) << 56))
|
|
||||||
|
|
||||||
#define float8net(V,M) do { double def_temp; \
|
|
||||||
((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 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)
|
// 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)
|
// 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)
|
// 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)
|
// 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)
|
// 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)
|
// read double XDR (big endian)
|
||||||
inline void read_double_xdr(const char* data, double & val)
|
inline void read_double_xdr(const char* data, double& val)
|
||||||
{
|
{
|
||||||
std::int64_t bits = (static_cast<std::int64_t>(data[7]) & 0xff) |
|
std::int64_t bits =
|
||||||
(static_cast<std::int64_t>(data[6]) & 0xff) << 8 |
|
(static_cast<std::int64_t>(data[7]) & 0xff) | (static_cast<std::int64_t>(data[6]) & 0xff) << 8 |
|
||||||
(static_cast<std::int64_t>(data[5]) & 0xff) << 16 |
|
(static_cast<std::int64_t>(data[5]) & 0xff) << 16 | (static_cast<std::int64_t>(data[4]) & 0xff) << 24 |
|
||||||
(static_cast<std::int64_t>(data[4]) & 0xff) << 24 |
|
(static_cast<std::int64_t>(data[3]) & 0xff) << 32 | (static_cast<std::int64_t>(data[2]) & 0xff) << 40 |
|
||||||
(static_cast<std::int64_t>(data[3]) & 0xff) << 32 |
|
(static_cast<std::int64_t>(data[1]) & 0xff) << 48 | (static_cast<std::int64_t>(data[0]) & 0xff) << 56;
|
||||||
(static_cast<std::int64_t>(data[2]) & 0xff) << 40 |
|
std::memcpy(&val, &bits, 8);
|
||||||
(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
|
#if defined(_MSC_VER) && _MSC_VER < 1800
|
||||||
|
@ -117,6 +115,6 @@ inline double round(double val)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GLOBAL_HPP
|
#endif // MAPNIK_GLOBAL_HPP
|
||||||
|
|
|
@ -35,24 +35,18 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
// stl
|
// stl
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
using stop_pair = std::pair<double, mapnik::color>;
|
using stop_pair = std::pair<double, mapnik::color>;
|
||||||
using stop_array = std::vector<stop_pair >;
|
using stop_array = std::vector<stop_pair>;
|
||||||
|
|
||||||
enum gradient_e
|
enum gradient_e { NO_GRADIENT, LINEAR, RADIAL };
|
||||||
{
|
|
||||||
NO_GRADIENT,
|
|
||||||
LINEAR,
|
|
||||||
RADIAL
|
|
||||||
};
|
|
||||||
|
|
||||||
enum gradient_unit_e
|
enum gradient_unit_e {
|
||||||
{
|
|
||||||
USER_SPACE_ON_USE,
|
USER_SPACE_ON_USE,
|
||||||
USER_SPACE_ON_USE_BOUNDING_BOX, // used to indicate % age values were specified. This are % of the svg image extent.
|
USER_SPACE_ON_USE_BOUNDING_BOX, // used to indicate % age values were specified. This are % of the svg image extent.
|
||||||
OBJECT_BOUNDING_BOX // (i.e., the abstract coordinate system where (0,0) is at the top/left of the object bounding box and (1,1) is at the bottom/right of the object bounding box)
|
OBJECT_BOUNDING_BOX // (i.e., the abstract coordinate system where (0,0) is at the top/left of the object bounding
|
||||||
|
// box and (1,1) is at the bottom/right of the object bounding box)
|
||||||
};
|
};
|
||||||
|
|
||||||
class MAPNIK_DECL gradient
|
class MAPNIK_DECL gradient
|
||||||
|
@ -72,10 +66,10 @@ class MAPNIK_DECL gradient
|
||||||
gradient_unit_e units_;
|
gradient_unit_e units_;
|
||||||
gradient_e gradient_type_;
|
gradient_e gradient_type_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
gradient();
|
gradient();
|
||||||
gradient(gradient const& other);
|
gradient(gradient const& other);
|
||||||
gradient(gradient && other);
|
gradient(gradient&& other);
|
||||||
gradient& operator=(gradient rhs);
|
gradient& operator=(gradient rhs);
|
||||||
bool operator==(gradient const& other) const;
|
bool operator==(gradient const& other) const;
|
||||||
void set_gradient_type(gradient_e grad);
|
void set_gradient_type(gradient_e grad);
|
||||||
|
@ -92,13 +86,13 @@ public:
|
||||||
|
|
||||||
stop_array const& get_stop_array() const;
|
stop_array const& get_stop_array() const;
|
||||||
|
|
||||||
void set_control_points(double x1, double y1, double x2, double y2, double r=0);
|
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, double& r) const;
|
||||||
void get_control_points(double &x1, double &y1, double &x2, double &y2) const;
|
void get_control_points(double& x1, double& y1, double& x2, double& y2) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void swap(gradient& other) noexcept;
|
void swap(gradient& other) noexcept;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_GRADIENT_HPP
|
#endif // MAPNIK_GRADIENT_HPP
|
||||||
|
|
|
@ -42,13 +42,12 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class MAPNIK_DECL hit_grid
|
class MAPNIK_DECL hit_grid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using value_type = typename T::type;
|
using value_type = typename T::type;
|
||||||
using data_type = mapnik::image<T>;
|
using data_type = mapnik::image<T>;
|
||||||
using lookup_type = std::string;
|
using lookup_type = std::string;
|
||||||
|
@ -57,7 +56,7 @@ public:
|
||||||
using feature_type = std::map<lookup_type, mapnik::feature_ptr>;
|
using feature_type = std::map<lookup_type, mapnik::feature_ptr>;
|
||||||
static const value_type base_mask;
|
static const value_type base_mask;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t width_;
|
std::size_t width_;
|
||||||
std::size_t height_;
|
std::size_t height_;
|
||||||
std::string key_;
|
std::string key_;
|
||||||
|
@ -69,7 +68,7 @@ private:
|
||||||
feature_type features_;
|
feature_type features_;
|
||||||
mapnik::context_ptr ctx_;
|
mapnik::context_ptr ctx_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
hit_grid(std::size_t width, std::size_t height, std::string const& key);
|
hit_grid(std::size_t width, std::size_t height, std::string const& key);
|
||||||
|
|
||||||
|
@ -79,94 +78,48 @@ public:
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
inline void painted(bool is_painted)
|
inline void painted(bool is_painted) { painted_ = is_painted; }
|
||||||
{
|
|
||||||
painted_ = is_painted;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool painted() const
|
inline bool painted() const { return painted_; }
|
||||||
{
|
|
||||||
return painted_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string const& key_name() const
|
inline std::string const& key_name() const { return id_name_; }
|
||||||
{
|
|
||||||
return id_name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_feature(mapnik::feature_impl const& feature);
|
void add_feature(mapnik::feature_impl const& feature);
|
||||||
|
|
||||||
inline void add_field(std::string const& name)
|
inline void add_field(std::string const& name) { names_.insert(name); }
|
||||||
{
|
|
||||||
names_.insert(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::set<std::string> const& get_fields() const
|
inline std::set<std::string> const& get_fields() const { return names_; }
|
||||||
{
|
|
||||||
return names_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline feature_type const& get_grid_features() const
|
inline feature_type const& get_grid_features() const { return features_; }
|
||||||
{
|
|
||||||
return features_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline feature_key_type const& get_feature_keys() const
|
inline feature_key_type const& get_feature_keys() const { return f_keys_; }
|
||||||
{
|
|
||||||
return f_keys_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string const& get_key() const
|
inline std::string const& get_key() const { return key_; }
|
||||||
{
|
|
||||||
return key_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_key(std::string const& key)
|
inline void set_key(std::string const& key) { key_ = key; }
|
||||||
{
|
|
||||||
key_ = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline data_type const& data() const
|
inline data_type const& data() const { return data_; }
|
||||||
{
|
|
||||||
return data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline data_type& data()
|
inline data_type& data() { return data_; }
|
||||||
{
|
|
||||||
return data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline value_type const * raw_data() const
|
inline value_type const* raw_data() const { return data_.data(); }
|
||||||
{
|
|
||||||
return data_.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline value_type* raw_data()
|
inline value_type* raw_data() { return data_.data(); }
|
||||||
{
|
|
||||||
return data_.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline value_type const * get_row(std::size_t row) const
|
inline value_type const* get_row(std::size_t row) const { return data_.get_row(row); }
|
||||||
{
|
|
||||||
return data_.get_row(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline mapnik::grid_view get_view(std::size_t x, std::size_t y, std::size_t w, std::size_t h)
|
inline mapnik::grid_view get_view(std::size_t x, std::size_t y, std::size_t w, std::size_t h)
|
||||||
{
|
{
|
||||||
return mapnik::grid_view(x, y, w, h,
|
return mapnik::grid_view(x, y, w, h, data_, key_, id_name_, names_, f_keys_, features_);
|
||||||
data_, key_, id_name_, names_, f_keys_, features_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
inline bool checkBounds(std::size_t x, std::size_t y) const
|
inline bool checkBounds(std::size_t x, std::size_t y) const { return (x < width_ && y < height_); }
|
||||||
{
|
|
||||||
return (x < width_ && y < height_);
|
|
||||||
}
|
|
||||||
|
|
||||||
hit_grid& operator=(const hit_grid&);
|
hit_grid& operator=(const hit_grid&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline void setPixel(std::size_t x, std::size_t y, value_type feature_id)
|
inline void setPixel(std::size_t x, std::size_t y, value_type feature_id)
|
||||||
{
|
{
|
||||||
if (checkBounds(x, y))
|
if (checkBounds(x, y))
|
||||||
|
@ -174,15 +127,9 @@ public:
|
||||||
data_(x, y) = feature_id;
|
data_(x, y) = feature_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline std::size_t width() const
|
inline std::size_t width() const { return width_; }
|
||||||
{
|
|
||||||
return width_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::size_t height() const
|
inline std::size_t height() const { return height_; }
|
||||||
{
|
|
||||||
return height_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_rectangle(value_type id, image_rgba8 const& data, std::size_t x0, std::size_t y0)
|
inline void set_rectangle(value_type id, image_rgba8 const& data, std::size_t x0, std::size_t y0)
|
||||||
{
|
{
|
||||||
|
@ -199,7 +146,7 @@ public:
|
||||||
for (std::size_t y = miny; y < maxy; ++y)
|
for (std::size_t y = miny; y < maxy; ++y)
|
||||||
{
|
{
|
||||||
value_type* row_to = data_.get_row(y);
|
value_type* row_to = data_.get_row(y);
|
||||||
image_rgba8::pixel_type const * row_from = data.get_row(y - y0);
|
image_rgba8::pixel_type const* row_from = data.get_row(y - y0);
|
||||||
|
|
||||||
for (std::size_t x = minx; x < maxx; ++x)
|
for (std::size_t x = minx; x < maxx; ++x)
|
||||||
{
|
{
|
||||||
|
@ -219,5 +166,5 @@ public:
|
||||||
|
|
||||||
using grid = hit_grid<mapnik::value_integer_pixel>;
|
using grid = hit_grid<mapnik::value_integer_pixel>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
#endif //MAPNIK_GRID_HPP
|
#endif // MAPNIK_GRID_HPP
|
||||||
|
|
|
@ -25,21 +25,15 @@
|
||||||
|
|
||||||
#include "agg_basics.h"
|
#include "agg_basics.h"
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
//==================================================================gray16
|
//==================================================================gray16
|
||||||
struct gray16
|
struct gray16
|
||||||
{
|
{
|
||||||
using value_type = agg::int16u;
|
using value_type = agg::int16u;
|
||||||
using calc_type = agg::int32u;
|
using calc_type = agg::int32u;
|
||||||
using long_type = agg::int64 ;
|
using long_type = agg::int64;
|
||||||
enum base_scale_e
|
enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
|
||||||
{
|
|
||||||
base_shift = 16,
|
|
||||||
base_scale = 1 << base_shift,
|
|
||||||
base_mask = base_scale - 1
|
|
||||||
};
|
|
||||||
using self_type = gray16;
|
using self_type = gray16;
|
||||||
|
|
||||||
value_type v;
|
value_type v;
|
||||||
|
@ -49,18 +43,19 @@ struct gray16
|
||||||
gray16() {}
|
gray16() {}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
gray16(unsigned v_, unsigned a_=base_mask) :
|
gray16(unsigned v_, unsigned a_ = base_mask)
|
||||||
v(agg::int16u(v_)), a(agg::int16u(a_)) {}
|
: v(agg::int16u(v_))
|
||||||
|
, a(agg::int16u(a_))
|
||||||
|
{}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
gray16(const self_type& c, unsigned a_) :
|
gray16(const self_type& c, unsigned a_)
|
||||||
v(c.v), a(value_type(a_)) {}
|
: v(c.v)
|
||||||
|
, a(value_type(a_))
|
||||||
|
{}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void clear()
|
void clear() { v = a = 0; }
|
||||||
{
|
|
||||||
v = a = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& transparent()
|
const self_type& transparent()
|
||||||
|
@ -69,12 +64,12 @@ struct gray16
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& premultiply()
|
const self_type& premultiply()
|
||||||
{
|
{
|
||||||
if(a == base_mask) return *this;
|
if (a == base_mask)
|
||||||
if(a == 0)
|
return *this;
|
||||||
|
if (a == 0)
|
||||||
{
|
{
|
||||||
v = 0;
|
v = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -86,8 +81,9 @@ struct gray16
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& premultiply(unsigned a_)
|
const self_type& premultiply(unsigned a_)
|
||||||
{
|
{
|
||||||
if(a == base_mask && a_ >= base_mask) return *this;
|
if (a == base_mask && a_ >= base_mask)
|
||||||
if(a == 0 || a_ == 0)
|
return *this;
|
||||||
|
if (a == 0 || a_ == 0)
|
||||||
{
|
{
|
||||||
v = a = 0;
|
v = a = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -101,8 +97,9 @@ struct gray16
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& demultiply()
|
const self_type& demultiply()
|
||||||
{
|
{
|
||||||
if(a == base_mask) return *this;
|
if (a == base_mask)
|
||||||
if(a == 0)
|
return *this;
|
||||||
|
if (a == 0)
|
||||||
{
|
{
|
||||||
v = 0;
|
v = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -126,29 +123,31 @@ struct gray16
|
||||||
AGG_INLINE void add(const self_type& c, unsigned cover)
|
AGG_INLINE void add(const self_type& c, unsigned cover)
|
||||||
{
|
{
|
||||||
calc_type cv, ca;
|
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;
|
*this = c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
cv = v + c.v;
|
||||||
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
||||||
|
ca = a + c.a;
|
||||||
|
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cv = v + ((c.v * 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);
|
ca = a + ((c.a * cover + agg::cover_mask / 2) >> agg::cover_shift);
|
||||||
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
||||||
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
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
|
//==================================================================gray32
|
||||||
|
@ -156,18 +155,13 @@ struct gray32
|
||||||
{
|
{
|
||||||
using value_type = agg::int32;
|
using value_type = agg::int32;
|
||||||
using calc_type = agg::int64u;
|
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
|
// NOTE: don't touch this enum since enums cannot be
|
||||||
// 64 bit and we need to ensure that alpha = base_mask
|
// 64 bit and we need to ensure that alpha = base_mask
|
||||||
// in grid_pixfmt.hpp#blend_hiline#l256
|
// in grid_pixfmt.hpp#blend_hiline#l256
|
||||||
// otherwise code will get invoked that breaks
|
// otherwise code will get invoked that breaks
|
||||||
// with 32 bit or 64 bit ints (blender_gray::blend_pix)
|
// with 32 bit or 64 bit ints (blender_gray::blend_pix)
|
||||||
enum base_scale_e
|
enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
|
||||||
{
|
|
||||||
base_shift = 16,
|
|
||||||
base_scale = 1 << base_shift,
|
|
||||||
base_mask = base_scale - 1
|
|
||||||
};
|
|
||||||
using self_type = gray32;
|
using self_type = gray32;
|
||||||
|
|
||||||
value_type v;
|
value_type v;
|
||||||
|
@ -177,18 +171,19 @@ struct gray32
|
||||||
gray32() {}
|
gray32() {}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
gray32(value_type v_, unsigned a_=base_mask) :
|
gray32(value_type v_, unsigned a_ = base_mask)
|
||||||
v(v_), a(value_type(a_)) {}
|
: v(v_)
|
||||||
|
, a(value_type(a_))
|
||||||
|
{}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
gray32(const self_type& c, unsigned a_) :
|
gray32(const self_type& c, unsigned a_)
|
||||||
v(c.v), a(value_type(a_)) {}
|
: v(c.v)
|
||||||
|
, a(value_type(a_))
|
||||||
|
{}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void clear()
|
void clear() { v = a = 0; }
|
||||||
{
|
|
||||||
v = a = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& transparent()
|
const self_type& transparent()
|
||||||
|
@ -197,12 +192,12 @@ struct gray32
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& premultiply()
|
const self_type& premultiply()
|
||||||
{
|
{
|
||||||
if(a == base_mask) return *this;
|
if (a == base_mask)
|
||||||
if(a == 0)
|
return *this;
|
||||||
|
if (a == 0)
|
||||||
{
|
{
|
||||||
v = 0;
|
v = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -214,8 +209,9 @@ struct gray32
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& premultiply(unsigned a_)
|
const self_type& premultiply(unsigned a_)
|
||||||
{
|
{
|
||||||
if(a == base_mask && a_ >= base_mask) return *this;
|
if (a == base_mask && a_ >= base_mask)
|
||||||
if(a == 0 || a_ == 0)
|
return *this;
|
||||||
|
if (a == 0 || a_ == 0)
|
||||||
{
|
{
|
||||||
v = a = 0;
|
v = a = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -229,8 +225,9 @@ struct gray32
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& demultiply()
|
const self_type& demultiply()
|
||||||
{
|
{
|
||||||
if(a == base_mask) return *this;
|
if (a == base_mask)
|
||||||
if(a == 0)
|
return *this;
|
||||||
|
if (a == 0)
|
||||||
{
|
{
|
||||||
v = 0;
|
v = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -254,29 +251,31 @@ struct gray32
|
||||||
AGG_INLINE void add(const self_type& c, unsigned cover)
|
AGG_INLINE void add(const self_type& c, unsigned cover)
|
||||||
{
|
{
|
||||||
calc_type cv, ca;
|
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;
|
*this = c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
cv = v + c.v;
|
||||||
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
||||||
|
ca = a + c.a;
|
||||||
|
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cv = v + ((c.v * 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);
|
ca = a + ((c.a * cover + agg::cover_mask / 2) >> agg::cover_shift);
|
||||||
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
||||||
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
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
|
//==================================================================gray64
|
||||||
|
@ -284,18 +283,13 @@ struct gray64
|
||||||
{
|
{
|
||||||
using value_type = agg::int64;
|
using value_type = agg::int64;
|
||||||
using calc_type = agg::int64u;
|
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
|
// NOTE: don't touch this enum since enums cannot be
|
||||||
// 64 bit and we need to ensure that alpha = base_mask
|
// 64 bit and we need to ensure that alpha = base_mask
|
||||||
// in grid_pixfmt.hpp#blend_hiline#l256
|
// in grid_pixfmt.hpp#blend_hiline#l256
|
||||||
// otherwise code will get invoked that breaks
|
// otherwise code will get invoked that breaks
|
||||||
// with 32 bit or 64 bit ints (blender_gray::blend_pix)
|
// with 32 bit or 64 bit ints (blender_gray::blend_pix)
|
||||||
enum base_scale_e
|
enum base_scale_e { base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 };
|
||||||
{
|
|
||||||
base_shift = 16,
|
|
||||||
base_scale = 1 << base_shift,
|
|
||||||
base_mask = base_scale - 1
|
|
||||||
};
|
|
||||||
using self_type = gray64;
|
using self_type = gray64;
|
||||||
|
|
||||||
value_type v;
|
value_type v;
|
||||||
|
@ -305,18 +299,19 @@ struct gray64
|
||||||
gray64() {}
|
gray64() {}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
gray64(value_type v_, unsigned a_=base_mask) :
|
gray64(value_type v_, unsigned a_ = base_mask)
|
||||||
v(v_), a(value_type(a_)) {}
|
: v(v_)
|
||||||
|
, a(value_type(a_))
|
||||||
|
{}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
gray64(const self_type& c, unsigned a_) :
|
gray64(const self_type& c, unsigned a_)
|
||||||
v(c.v), a(value_type(a_)) {}
|
: v(c.v)
|
||||||
|
, a(value_type(a_))
|
||||||
|
{}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void clear()
|
void clear() { v = a = 0; }
|
||||||
{
|
|
||||||
v = a = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& transparent()
|
const self_type& transparent()
|
||||||
|
@ -325,12 +320,12 @@ struct gray64
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& premultiply()
|
const self_type& premultiply()
|
||||||
{
|
{
|
||||||
if(a == base_mask) return *this;
|
if (a == base_mask)
|
||||||
if(a == 0)
|
return *this;
|
||||||
|
if (a == 0)
|
||||||
{
|
{
|
||||||
v = 0;
|
v = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -342,8 +337,9 @@ struct gray64
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& premultiply(unsigned a_)
|
const self_type& premultiply(unsigned a_)
|
||||||
{
|
{
|
||||||
if(a == base_mask && a_ >= base_mask) return *this;
|
if (a == base_mask && a_ >= base_mask)
|
||||||
if(a == 0 || a_ == 0)
|
return *this;
|
||||||
|
if (a == 0 || a_ == 0)
|
||||||
{
|
{
|
||||||
v = a = 0;
|
v = a = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -357,8 +353,9 @@ struct gray64
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
const self_type& demultiply()
|
const self_type& demultiply()
|
||||||
{
|
{
|
||||||
if(a == base_mask) return *this;
|
if (a == base_mask)
|
||||||
if(a == 0)
|
return *this;
|
||||||
|
if (a == 0)
|
||||||
{
|
{
|
||||||
v = 0;
|
v = 0;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -382,31 +379,33 @@ struct gray64
|
||||||
AGG_INLINE void add(const self_type& c, unsigned cover)
|
AGG_INLINE void add(const self_type& c, unsigned cover)
|
||||||
{
|
{
|
||||||
calc_type cv, ca;
|
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;
|
*this = c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
cv = v + c.v;
|
||||||
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
||||||
|
ca = a + c.a;
|
||||||
|
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cv = v + ((c.v * 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);
|
ca = a + ((c.a * cover + agg::cover_mask / 2) >> agg::cover_shift);
|
||||||
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
|
||||||
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
|
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
|
#endif
|
||||||
|
|
|
@ -33,78 +33,70 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/grid/grid_pixel.hpp>
|
#include <mapnik/grid/grid_pixel.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
//============================================================blender_gray
|
//============================================================blender_gray
|
||||||
template<typename ColorT> struct blender_gray
|
template<typename ColorT>
|
||||||
|
struct blender_gray
|
||||||
{
|
{
|
||||||
using color_type = ColorT;
|
using color_type = ColorT;
|
||||||
using value_type = typename color_type::value_type;
|
using value_type = typename color_type::value_type;
|
||||||
using calc_type = typename color_type::calc_type;
|
using calc_type = typename color_type::calc_type;
|
||||||
enum base_scale_e { base_shift = color_type::base_shift };
|
enum base_scale_e { base_shift = color_type::base_shift };
|
||||||
|
|
||||||
static AGG_INLINE void blend_pix(value_type* p, unsigned cv,
|
static AGG_INLINE void blend_pix(value_type* p, unsigned cv, unsigned alpha, unsigned /*cover*/ = 0)
|
||||||
unsigned alpha, unsigned /*cover*/=0)
|
|
||||||
{
|
{
|
||||||
*p = (value_type)((((cv - calc_type(*p)) * alpha) + (calc_type(*p) << base_shift)) >> base_shift);
|
*p = (value_type)((((cv - calc_type(*p)) * alpha) + (calc_type(*p) << base_shift)) >> base_shift);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=====================================================apply_gamma_dir_gray
|
//=====================================================apply_gamma_dir_gray
|
||||||
template<typename ColorT, class GammaLut> class apply_gamma_dir_gray
|
template<typename ColorT, class GammaLut>
|
||||||
|
class apply_gamma_dir_gray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using value_type = typename ColorT::value_type;
|
using value_type = typename ColorT::value_type;
|
||||||
|
|
||||||
apply_gamma_dir_gray(const GammaLut& gamma) : m_gamma(gamma) {}
|
apply_gamma_dir_gray(const GammaLut& gamma)
|
||||||
|
: m_gamma(gamma)
|
||||||
|
{}
|
||||||
|
|
||||||
AGG_INLINE void operator () (value_type* p)
|
AGG_INLINE void operator()(value_type* p) { *p = m_gamma.dir(*p); }
|
||||||
{
|
|
||||||
*p = m_gamma.dir(*p);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const GammaLut& m_gamma;
|
const GammaLut& m_gamma;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=====================================================apply_gamma_inv_gray
|
//=====================================================apply_gamma_inv_gray
|
||||||
template<typename ColorT, class GammaLut> class apply_gamma_inv_gray
|
template<typename ColorT, class GammaLut>
|
||||||
|
class apply_gamma_inv_gray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using value_type = typename ColorT::value_type;
|
using value_type = typename ColorT::value_type;
|
||||||
|
|
||||||
apply_gamma_inv_gray(const GammaLut& gamma) : m_gamma(gamma) {}
|
apply_gamma_inv_gray(const GammaLut& gamma)
|
||||||
|
: m_gamma(gamma)
|
||||||
|
{}
|
||||||
|
|
||||||
AGG_INLINE void operator () (value_type* p)
|
AGG_INLINE void operator()(value_type* p) { *p = m_gamma.inv(*p); }
|
||||||
{
|
|
||||||
*p = m_gamma.inv(*p);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const GammaLut& m_gamma;
|
const GammaLut& m_gamma;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=================================================pixfmt_alpha_blend_gray
|
//=================================================pixfmt_alpha_blend_gray
|
||||||
template<typename Blender, class RenBuf, unsigned Step=1, unsigned Offset=0>
|
template<typename Blender, class RenBuf, unsigned Step = 1, unsigned Offset = 0>
|
||||||
class pixfmt_alpha_blend_gray
|
class pixfmt_alpha_blend_gray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using rbuf_type = RenBuf ;
|
using rbuf_type = RenBuf;
|
||||||
using row_data = typename rbuf_type::row_data;
|
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 color_type = typename blender_type::color_type;
|
||||||
using order_type = int ; // A fake one
|
using order_type = int; // A fake one
|
||||||
using value_type = typename color_type::value_type ;
|
using value_type = typename color_type::value_type;
|
||||||
using calc_type = typename color_type::calc_type ;
|
using calc_type = typename color_type::calc_type;
|
||||||
enum base_scale_e
|
enum base_scale_e {
|
||||||
{
|
|
||||||
base_shift = color_type::base_shift,
|
base_shift = color_type::base_shift,
|
||||||
base_scale = color_type::base_scale,
|
base_scale = color_type::base_scale,
|
||||||
base_mask = color_type::base_mask,
|
base_mask = color_type::base_mask,
|
||||||
|
@ -113,16 +105,14 @@ public:
|
||||||
pix_offset = Offset
|
pix_offset = Offset
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
static AGG_INLINE void copy_or_blend_pix(value_type* p,
|
static AGG_INLINE void copy_or_blend_pix(value_type* p, const color_type& c, unsigned cover)
|
||||||
const color_type& c,
|
|
||||||
unsigned cover)
|
|
||||||
{
|
{
|
||||||
if (c.a)
|
if (c.a)
|
||||||
{
|
{
|
||||||
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
|
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
|
||||||
if(alpha == base_mask)
|
if (alpha == base_mask)
|
||||||
{
|
{
|
||||||
*p = c.v;
|
*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)
|
||||||
{
|
{
|
||||||
if(c.a == base_mask)
|
if (c.a == base_mask)
|
||||||
{
|
{
|
||||||
*p = c.v;
|
*p = c.v;
|
||||||
}
|
}
|
||||||
|
@ -150,11 +138,10 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
public:
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
explicit pixfmt_alpha_blend_gray(rbuf_type& rb) :
|
explicit pixfmt_alpha_blend_gray(rbuf_type& rb)
|
||||||
m_rbuf(&rb)
|
: m_rbuf(&rb)
|
||||||
{}
|
{}
|
||||||
void attach(rbuf_type& rb) { m_rbuf = &rb; }
|
void attach(rbuf_type& rb) { m_rbuf = &rb; }
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
@ -163,13 +150,10 @@ public:
|
||||||
bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2)
|
bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2)
|
||||||
{
|
{
|
||||||
agg::rect_i r(x1, y1, x2, 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();
|
int stride = pixf.stride();
|
||||||
m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1),
|
m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1), (r.x2 - r.x1) + 1, (r.y2 - r.y1) + 1, stride);
|
||||||
(r.x2 - r.x1) + 1,
|
|
||||||
(r.y2 - r.y1) + 1,
|
|
||||||
stride);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -185,21 +169,12 @@ public:
|
||||||
const agg::int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); }
|
const agg::int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); }
|
||||||
row_data row(int y) const { return m_rbuf->row(y); }
|
row_data row(int y) const { return m_rbuf->row(y); }
|
||||||
|
|
||||||
const agg::int8u* pix_ptr(int x, int y) const
|
const agg::int8u* pix_ptr(int x, int y) const { return m_rbuf->row_ptr(y) + x * Step + Offset; }
|
||||||
{
|
|
||||||
return m_rbuf->row_ptr(y) + x * Step + Offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
agg::int8u* pix_ptr(int x, int y)
|
agg::int8u* pix_ptr(int x, int y) { return m_rbuf->row_ptr(y) + x * Step + Offset; }
|
||||||
{
|
|
||||||
return m_rbuf->row_ptr(y) + x * Step + Offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
AGG_INLINE static void make_pix(agg::int8u* p, const color_type& c)
|
AGG_INLINE static void make_pix(agg::int8u* p, const color_type& c) { *(value_type*)p = c.v; }
|
||||||
{
|
|
||||||
*(value_type*)p = c.v;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
AGG_INLINE color_type pixel(int x, int y) const
|
AGG_INLINE color_type pixel(int x, int y) const
|
||||||
|
@ -217,60 +192,41 @@ public:
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
AGG_INLINE void blend_pixel(int x, int y, const color_type& c, agg::int8u cover)
|
AGG_INLINE void blend_pixel(int x, int y, const color_type& c, agg::int8u cover)
|
||||||
{
|
{
|
||||||
copy_or_blend_pix((value_type*)
|
copy_or_blend_pix((value_type*)m_rbuf->row_ptr(x, y, 1) + x * Step + Offset, c, cover);
|
||||||
m_rbuf->row_ptr(x, y, 1) + x * Step + Offset,
|
|
||||||
c,
|
|
||||||
cover);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
AGG_INLINE void copy_hline(int x, int y,
|
AGG_INLINE void copy_hline(int x, int y, unsigned len, const color_type& c)
|
||||||
unsigned len,
|
|
||||||
const color_type& c)
|
|
||||||
{
|
{
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
*p = c.v;
|
*p = c.v;
|
||||||
p += Step;
|
p += Step;
|
||||||
|
} while (--len);
|
||||||
}
|
}
|
||||||
while(--len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
AGG_INLINE void copy_vline(int x, int y,
|
AGG_INLINE void copy_vline(int x, int y, unsigned len, const color_type& c)
|
||||||
unsigned len,
|
|
||||||
const color_type& c)
|
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
|
||||||
|
|
||||||
*p = c.v;
|
*p = c.v;
|
||||||
|
} while (--len);
|
||||||
}
|
}
|
||||||
while(--len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void blend_hline(int x, int y,
|
void blend_hline(int x, int y, unsigned len, const color_type& c, agg::int8u /*cover*/)
|
||||||
unsigned len,
|
|
||||||
const color_type& c,
|
|
||||||
agg::int8u /*cover*/)
|
|
||||||
{
|
{
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
*p = c.v;
|
*p = c.v;
|
||||||
p += Step;
|
p += Step;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
// We ignore alpha since grid_renderer is a binary renderer for now
|
// We ignore alpha since grid_renderer is a binary renderer for now
|
||||||
/*if (c.a)
|
/*if (c.a)
|
||||||
{
|
{
|
||||||
|
@ -299,58 +255,45 @@ public:
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void blend_vline(int x, int y,
|
void blend_vline(int x, int y, unsigned len, const color_type& c, agg::int8u cover)
|
||||||
unsigned len,
|
|
||||||
const color_type& c,
|
|
||||||
agg::int8u cover)
|
|
||||||
{
|
{
|
||||||
if (c.a)
|
if (c.a)
|
||||||
{
|
{
|
||||||
value_type* p;
|
value_type* p;
|
||||||
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
|
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
|
||||||
if(alpha == base_mask)
|
if (alpha == base_mask)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
p = (value_type*)
|
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
|
||||||
|
|
||||||
*p = c.v;
|
*p = c.v;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
p = (value_type*)
|
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
|
||||||
|
|
||||||
Blender::blend_pix(p, c.v, alpha, cover);
|
Blender::blend_pix(p, c.v, alpha, cover);
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void blend_solid_hspan(int x, int y,
|
void blend_solid_hspan(int x, int y, unsigned len, const color_type& c, const agg::int8u* covers)
|
||||||
unsigned len,
|
|
||||||
const color_type& c,
|
|
||||||
const agg::int8u* covers)
|
|
||||||
{
|
{
|
||||||
if (c.a)
|
if (c.a)
|
||||||
{
|
{
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
|
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
|
||||||
if(alpha == base_mask)
|
if (alpha == base_mask)
|
||||||
{
|
{
|
||||||
*p = c.v;
|
*p = c.v;
|
||||||
}
|
}
|
||||||
|
@ -360,17 +303,12 @@ public:
|
||||||
}
|
}
|
||||||
p += Step;
|
p += Step;
|
||||||
++covers;
|
++covers;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void blend_solid_vspan(int x, int y,
|
void blend_solid_vspan(int x, int y, unsigned len, const color_type& c, const agg::int8u* covers)
|
||||||
unsigned len,
|
|
||||||
const color_type& c,
|
|
||||||
const agg::int8u* covers)
|
|
||||||
{
|
{
|
||||||
if (c.a)
|
if (c.a)
|
||||||
{
|
{
|
||||||
|
@ -378,10 +316,9 @@ public:
|
||||||
{
|
{
|
||||||
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
|
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
|
||||||
|
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
|
||||||
|
|
||||||
if(alpha == base_mask)
|
if (alpha == base_mask)
|
||||||
{
|
{
|
||||||
*p = c.v;
|
*p = c.v;
|
||||||
}
|
}
|
||||||
|
@ -390,72 +327,59 @@ public:
|
||||||
Blender::blend_pix(p, c.v, alpha, *covers);
|
Blender::blend_pix(p, c.v, alpha, *covers);
|
||||||
}
|
}
|
||||||
++covers;
|
++covers;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void copy_color_hspan(int x, int y,
|
void copy_color_hspan(int x, int y, unsigned len, const color_type* colors)
|
||||||
unsigned len,
|
|
||||||
const color_type* colors)
|
|
||||||
{
|
{
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
*p = colors->v;
|
*p = colors->v;
|
||||||
p += Step;
|
p += Step;
|
||||||
++colors;
|
++colors;
|
||||||
|
} while (--len);
|
||||||
}
|
}
|
||||||
while(--len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void copy_color_vspan(int x, int y,
|
void copy_color_vspan(int x, int y, unsigned len, const color_type* colors)
|
||||||
unsigned len,
|
|
||||||
const color_type* colors)
|
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
|
||||||
*p = colors->v;
|
*p = colors->v;
|
||||||
++colors;
|
++colors;
|
||||||
|
} while (--len);
|
||||||
}
|
}
|
||||||
while(--len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void blend_color_hspan(int x, int y,
|
void blend_color_hspan(int x,
|
||||||
|
int y,
|
||||||
unsigned len,
|
unsigned len,
|
||||||
const color_type* colors,
|
const color_type* colors,
|
||||||
const agg::int8u* covers,
|
const agg::int8u* covers,
|
||||||
agg::int8u cover)
|
agg::int8u cover)
|
||||||
{
|
{
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
|
|
||||||
|
|
||||||
if(covers)
|
if (covers)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
copy_or_blend_pix(p, *colors++, *covers++);
|
copy_or_blend_pix(p, *colors++, *covers++);
|
||||||
p += Step;
|
p += Step;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(cover == 255)
|
if (cover == 255)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(colors->a == base_mask)
|
if (colors->a == base_mask)
|
||||||
{
|
{
|
||||||
*p = colors->v;
|
*p = colors->v;
|
||||||
}
|
}
|
||||||
|
@ -465,8 +389,7 @@ public:
|
||||||
}
|
}
|
||||||
p += Step;
|
p += Step;
|
||||||
++colors;
|
++colors;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -474,43 +397,38 @@ public:
|
||||||
{
|
{
|
||||||
copy_or_blend_pix(p, *colors++, cover);
|
copy_or_blend_pix(p, *colors++, cover);
|
||||||
p += Step;
|
p += Step;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void blend_color_vspan(int x, int y,
|
void blend_color_vspan(int x,
|
||||||
|
int y,
|
||||||
unsigned len,
|
unsigned len,
|
||||||
const color_type* colors,
|
const color_type* colors,
|
||||||
const agg::int8u* covers,
|
const agg::int8u* covers,
|
||||||
agg::int8u cover)
|
agg::int8u cover)
|
||||||
{
|
{
|
||||||
value_type* p;
|
value_type* p;
|
||||||
if(covers)
|
if (covers)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
p = (value_type*)
|
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
|
||||||
|
|
||||||
copy_or_blend_pix(p, *colors++, *covers++);
|
copy_or_blend_pix(p, *colors++, *covers++);
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(cover == 255)
|
if (cover == 255)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
p = (value_type*)
|
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
|
||||||
|
|
||||||
if(colors->a == base_mask)
|
if (colors->a == base_mask)
|
||||||
{
|
{
|
||||||
*p = colors->v;
|
*p = colors->v;
|
||||||
}
|
}
|
||||||
|
@ -519,72 +437,64 @@ public:
|
||||||
copy_or_blend_pix(p, *colors);
|
copy_or_blend_pix(p, *colors);
|
||||||
}
|
}
|
||||||
++colors;
|
++colors;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
p = (value_type*)
|
p = (value_type*)m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
||||||
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
|
|
||||||
|
|
||||||
copy_or_blend_pix(p, *colors++, cover);
|
copy_or_blend_pix(p, *colors++, cover);
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
template <typename Function>
|
template<typename Function>
|
||||||
void for_each_pixel(Function f)
|
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);
|
row_data r = m_rbuf->row(y);
|
||||||
if(r.ptr)
|
if (r.ptr)
|
||||||
{
|
{
|
||||||
unsigned len = r.x2 - r.x1 + 1;
|
unsigned len = r.x2 - r.x1 + 1;
|
||||||
|
|
||||||
value_type* p = (value_type*)
|
value_type* p = (value_type*)m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset;
|
||||||
m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
f(p);
|
f(p);
|
||||||
p += Step;
|
p += Step;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
template<typename GammaLut> void apply_gamma_dir(const GammaLut& g)
|
template<typename GammaLut>
|
||||||
|
void apply_gamma_dir(const GammaLut& g)
|
||||||
{
|
{
|
||||||
for_each_pixel(apply_gamma_dir_gray<color_type, GammaLut>(g));
|
for_each_pixel(apply_gamma_dir_gray<color_type, GammaLut>(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
template<typename GammaLut> void apply_gamma_inv(const GammaLut& g)
|
template<typename GammaLut>
|
||||||
|
void apply_gamma_inv(const GammaLut& g)
|
||||||
{
|
{
|
||||||
for_each_pixel(apply_gamma_inv_gray<color_type, GammaLut>(g));
|
for_each_pixel(apply_gamma_inv_gray<color_type, GammaLut>(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
template<typename RenBuf2>
|
template<typename RenBuf2>
|
||||||
void copy_from(const RenBuf2& from,
|
void copy_from(const RenBuf2& from, int xdst, int ydst, int xsrc, int ysrc, unsigned len)
|
||||||
int xdst, int ydst,
|
|
||||||
int xsrc, int ysrc,
|
|
||||||
unsigned len)
|
|
||||||
{
|
{
|
||||||
const agg::int8u* p = from.row_ptr(ysrc);
|
const agg::int8u* p = from.row_ptr(ysrc);
|
||||||
if(p)
|
if (p)
|
||||||
{
|
{
|
||||||
memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width,
|
memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width, p + xsrc * pix_width, len * pix_width);
|
||||||
p + xsrc * pix_width,
|
|
||||||
len * pix_width);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,26 +502,24 @@ public:
|
||||||
template<typename SrcPixelFormatRenderer>
|
template<typename SrcPixelFormatRenderer>
|
||||||
void blend_from_color(const SrcPixelFormatRenderer& from,
|
void blend_from_color(const SrcPixelFormatRenderer& from,
|
||||||
const color_type& color,
|
const color_type& color,
|
||||||
int xdst, int ydst,
|
int xdst,
|
||||||
int /*xsrc*/, int ysrc,
|
int ydst,
|
||||||
|
int /*xsrc*/,
|
||||||
|
int ysrc,
|
||||||
unsigned len,
|
unsigned len,
|
||||||
agg::int8u cover)
|
agg::int8u cover)
|
||||||
{
|
{
|
||||||
using src_value_type = typename SrcPixelFormatRenderer::value_type;
|
using src_value_type = typename SrcPixelFormatRenderer::value_type;
|
||||||
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
|
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
|
||||||
if(psrc)
|
if (psrc)
|
||||||
{
|
{
|
||||||
value_type* pdst =
|
value_type* pdst = (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
|
||||||
(value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
copy_or_blend_pix(pdst,
|
copy_or_blend_pix(pdst, color, (*psrc * cover + base_mask) >> base_shift);
|
||||||
color,
|
|
||||||
(*psrc * cover + base_mask) >> base_shift);
|
|
||||||
++psrc;
|
++psrc;
|
||||||
++pdst;
|
++pdst;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,28 +527,28 @@ public:
|
||||||
template<typename SrcPixelFormatRenderer>
|
template<typename SrcPixelFormatRenderer>
|
||||||
void blend_from_lut(const SrcPixelFormatRenderer& from,
|
void blend_from_lut(const SrcPixelFormatRenderer& from,
|
||||||
const color_type* color_lut,
|
const color_type* color_lut,
|
||||||
int xdst, int ydst,
|
int xdst,
|
||||||
int /*xsrc*/, int ysrc,
|
int ydst,
|
||||||
|
int /*xsrc*/,
|
||||||
|
int ysrc,
|
||||||
unsigned len,
|
unsigned len,
|
||||||
agg::int8u cover)
|
agg::int8u cover)
|
||||||
{
|
{
|
||||||
using src_value_type = typename SrcPixelFormatRenderer::value_type;
|
using src_value_type = typename SrcPixelFormatRenderer::value_type;
|
||||||
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
|
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
|
||||||
if(psrc)
|
if (psrc)
|
||||||
{
|
{
|
||||||
value_type* pdst =
|
value_type* pdst = (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
|
||||||
(value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
copy_or_blend_pix(pdst, color_lut[*psrc], cover);
|
copy_or_blend_pix(pdst, color_lut[*psrc], cover);
|
||||||
++psrc;
|
++psrc;
|
||||||
++pdst;
|
++pdst;
|
||||||
}
|
} while (--len);
|
||||||
while(--len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rbuf_type* m_rbuf;
|
rbuf_type* m_rbuf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -659,6 +567,6 @@ using blender_gray64 = blender_gray<gray64>;
|
||||||
using pixfmt_gray64 = pixfmt_alpha_blend_gray<blender_gray64,
|
using pixfmt_gray64 = pixfmt_alpha_blend_gray<blender_gray64,
|
||||||
mapnik::grid_rendering_buffer>; //----pixfmt_gray64
|
mapnik::grid_rendering_buffer>; //----pixfmt_gray64
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,8 +33,10 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
struct grid_rasterizer : agg::rasterizer_scanline_aa<>, util::noncopyable {};
|
struct grid_rasterizer : agg::rasterizer_scanline_aa<>,
|
||||||
|
util::noncopyable
|
||||||
|
{};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif //MAPNIK_AGG_RASTERIZER_HPP
|
#endif // MAPNIK_AGG_RASTERIZER_HPP
|
||||||
|
|
|
@ -40,9 +40,9 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename RendererType, typename RasterizerType>
|
template<typename RendererType, typename RasterizerType>
|
||||||
void render_raster_marker(RendererType ren,
|
void render_raster_marker(RendererType ren,
|
||||||
RasterizerType & ras,
|
RasterizerType& ras,
|
||||||
image_rgba8 const& src,
|
image_rgba8 const& src,
|
||||||
mapnik::feature_impl const& feature,
|
mapnik::feature_impl const& feature,
|
||||||
agg::trans_affine const& marker_tr,
|
agg::trans_affine const& marker_tr,
|
||||||
|
@ -53,22 +53,26 @@ void render_raster_marker(RendererType ren,
|
||||||
double width = src.width();
|
double width = src.width();
|
||||||
double height = src.height();
|
double height = src.height();
|
||||||
double p[8];
|
double p[8];
|
||||||
p[0] = 0; p[1] = 0;
|
p[0] = 0;
|
||||||
p[2] = width; p[3] = 0;
|
p[1] = 0;
|
||||||
p[4] = width; p[5] = height;
|
p[2] = width;
|
||||||
p[6] = 0; p[7] = height;
|
p[3] = 0;
|
||||||
|
p[4] = width;
|
||||||
|
p[5] = height;
|
||||||
|
p[6] = 0;
|
||||||
|
p[7] = height;
|
||||||
marker_tr.transform(&p[0], &p[1]);
|
marker_tr.transform(&p[0], &p[1]);
|
||||||
marker_tr.transform(&p[2], &p[3]);
|
marker_tr.transform(&p[2], &p[3]);
|
||||||
marker_tr.transform(&p[4], &p[5]);
|
marker_tr.transform(&p[4], &p[5]);
|
||||||
marker_tr.transform(&p[6], &p[7]);
|
marker_tr.transform(&p[6], &p[7]);
|
||||||
ras.move_to_d(p[0],p[1]);
|
ras.move_to_d(p[0], p[1]);
|
||||||
ras.line_to_d(p[2],p[3]);
|
ras.line_to_d(p[2], p[3]);
|
||||||
ras.line_to_d(p[4],p[5]);
|
ras.line_to_d(p[4], p[5]);
|
||||||
ras.line_to_d(p[6],p[7]);
|
ras.line_to_d(p[6], p[7]);
|
||||||
ren.color(color_type(feature.id()));
|
ren.color(color_type(feature.id()));
|
||||||
agg::render_scanlines(ras, sl, ren);
|
agg::render_scanlines(ras, sl, ren);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue