From fd961048eaec51363db9984f59eb494e6ce7962c Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Fri, 25 May 2018 17:12:05 +0200 Subject: [PATCH 1/2] Improve padding calculation --- include/mapnik/offset_converter.hpp | 4 +++- src/agg/process_line_pattern_symbolizer.cpp | 11 +++++----- src/agg/process_line_symbolizer.cpp | 20 ++++--------------- src/cairo/process_line_pattern_symbolizer.cpp | 12 +++++------ src/cairo/process_line_symbolizer.cpp | 12 +++++------ src/grid/process_line_pattern_symbolizer.cpp | 12 +++++------ src/grid/process_line_symbolizer.cpp | 12 +++++------ 7 files changed, 32 insertions(+), 51 deletions(-) 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 Date: Sun, 21 Oct 2018 19:54:36 +0000 Subject: [PATCH 2/2] Update visual tests --- test/data-visual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data-visual b/test/data-visual index 13163a419..0a804e64b 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 13163a419eec939d189a371427022402b98bb08a +Subproject commit 0a804e64beee9af6b1388f45d89554fddbba89c5