diff --git a/include/mapnik/offset_converter.hpp b/include/mapnik/offset_converter.hpp index 8bbb9aa50..1ebf92b3c 100644 --- a/include/mapnik/offset_converter.hpp +++ b/include/mapnik/offset_converter.hpp @@ -40,6 +40,8 @@ namespace mapnik { +static constexpr double offset_converter_default_threshold = 5.0; + template struct offset_converter { @@ -48,7 +50,7 @@ struct offset_converter offset_converter(Geometry & geom) : geom_(geom) , offset_(0.0) - , threshold_(5.0) + , threshold_(offset_converter_default_threshold) , half_turn_segments_(16) , status_(initial) , pre_first_(vertex2d::no_init) diff --git a/src/agg/process_line_pattern_symbolizer.cpp b/src/agg/process_line_pattern_symbolizer.cpp index e8770e2cd..2033f1bf0 100644 --- a/src/agg/process_line_pattern_symbolizer.cpp +++ b/src/agg/process_line_pattern_symbolizer.cpp @@ -134,12 +134,11 @@ private: box2d clip_box = clipping_extent(common_); if (clip) { - double padding = (double)(common_.query_extent_.width()/pixmap_.width()); - if (half_stroke > 1) - padding *= half_stroke; - if (std::fabs(offset) > 0) - padding *= std::fabs(offset) * 1.2; - padding *= common_.scale_factor_; + double pad_per_pixel = static_cast(common_.query_extent_.width()/common_.width_); + double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset), + (std::fabs(offset) * offset_converter_default_threshold))); + double padding = pad_per_pixel * pixels * common_.scale_factor_; + clip_box.pad(padding); } using vertex_converter_type = vertex_converter::process(line_symbolizer const& sym, line_rasterizer_enum rasterizer_e = get(sym, feature, common_.vars_); if (clip) { - double padding = static_cast(common_.query_extent_.width()/pixmap_.width()); - double half_stroke = 0.5 * width; - if (half_stroke > 1) - { - padding *= half_stroke; - } - if (std::fabs(offset) > 0) - { - padding *= std::fabs(offset) * 1.2; - } - - padding *= common_.scale_factor_; + double pad_per_pixel = static_cast(common_.query_extent_.width()/common_.width_); + double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset), + (std::fabs(offset) * offset_converter_default_threshold))); + double padding = pad_per_pixel * pixels * common_.scale_factor_; clip_box.pad(padding); - // debugging - //box2d inverse = query_extent_; - //inverse.pad(-padding); - //draw_geo_extent(inverse,mapnik::color("red")); } if (rasterizer_e == RASTERIZER_FAST) diff --git a/src/cairo/process_line_pattern_symbolizer.cpp b/src/cairo/process_line_pattern_symbolizer.cpp index f53d850a6..1f457b845 100644 --- a/src/cairo/process_line_pattern_symbolizer.cpp +++ b/src/cairo/process_line_pattern_symbolizer.cpp @@ -131,13 +131,11 @@ void cairo_renderer::process(line_pattern_symbolizer const& sym, box2d clipping_extent = common_.query_extent_; if (clip) { - double padding = (double)(common_.query_extent_.width()/common_.width_); - double half_stroke = width/2.0; - if (half_stroke > 1) - padding *= half_stroke; - if (std::fabs(offset) > 0) - padding *= std::fabs(offset) * 1.2; - padding *= common_.scale_factor_; + double pad_per_pixel = static_cast(common_.query_extent_.width()/common_.width_); + double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset), + (std::fabs(offset) * offset_converter_default_threshold))); + double padding = pad_per_pixel * pixels * common_.scale_factor_; + clipping_extent.pad(padding); } diff --git a/src/cairo/process_line_symbolizer.cpp b/src/cairo/process_line_symbolizer.cpp index ed64d5c01..0e4bb3f49 100644 --- a/src/cairo/process_line_symbolizer.cpp +++ b/src/cairo/process_line_symbolizer.cpp @@ -73,13 +73,11 @@ void cairo_renderer::process(line_symbolizer const& sym, box2d clipping_extent = common_.query_extent_; if (clip) { - double padding = (double)(common_.query_extent_.width()/common_.width_); - double half_stroke = width/2.0; - if (half_stroke > 1) - padding *= half_stroke; - if (std::fabs(offset) > 0) - padding *= std::fabs(offset) * 1.2; - padding *= common_.scale_factor_; + double pad_per_pixel = static_cast(common_.query_extent_.width()/common_.width_); + double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset), + (std::fabs(offset) * offset_converter_default_threshold))); + double padding = pad_per_pixel * pixels * common_.scale_factor_; + clipping_extent.pad(padding); } using vertex_converter_type = vertex_converter::process(line_pattern_symbolizer const& sym, box2d clipping_extent = common_.query_extent_; if (clip) { - double padding = (double)(common_.query_extent_.width()/pixmap_.width()); - double half_stroke = stroke_width/2.0; - if (half_stroke > 1) - padding *= half_stroke; - if (std::fabs(offset) > 0) - padding *= std::fabs(offset) * 1.2; - padding *= common_.scale_factor_; + double pad_per_pixel = static_cast(common_.query_extent_.width()/common_.width_); + double pixels = std::ceil(std::max(stroke_width / 2.0 + std::fabs(offset), + (std::fabs(offset) * offset_converter_default_threshold))); + double padding = pad_per_pixel * pixels * common_.scale_factor_; + clipping_extent.pad(padding); } diff --git a/src/grid/process_line_symbolizer.cpp b/src/grid/process_line_symbolizer.cpp index b65dd8502..ca8cfb0ed 100644 --- a/src/grid/process_line_symbolizer.cpp +++ b/src/grid/process_line_symbolizer.cpp @@ -84,13 +84,11 @@ void grid_renderer::process(line_symbolizer const& sym, if (clip) { - double padding = (double)(common_.query_extent_.width()/pixmap_.width()); - double half_stroke = width/2.0; - if (half_stroke > 1) - padding *= half_stroke; - if (std::fabs(offset) > 0) - padding *= std::fabs(offset) * 1.2; - padding *= common_.scale_factor_; + double pad_per_pixel = static_cast(common_.query_extent_.width()/common_.width_); + double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset), + (std::fabs(offset) * offset_converter_default_threshold))); + double padding = pad_per_pixel * pixels * common_.scale_factor_; + clipping_extent.pad(padding); } using vertex_converter_type = vertex_converter