From 8a0dca38a3edd447a270a0eceff708f3375e6efc Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Tue, 31 Jul 2018 14:06:31 +0000 Subject: [PATCH] Fix buffer-size with scale-factor --- .../mapnik/feature_style_processor_impl.hpp | 2 +- .../renderer/buffer_size_scale_factor.cpp | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 test/unit/renderer/buffer_size_scale_factor.cpp diff --git a/include/mapnik/feature_style_processor_impl.hpp b/include/mapnik/feature_style_processor_impl.hpp index 278ea5463..f5e605d4b 100644 --- a/include/mapnik/feature_style_processor_impl.hpp +++ b/include/mapnik/feature_style_processor_impl.hpp @@ -260,7 +260,7 @@ void feature_style_processor::prepare_layer(layer_rendering_material box2d query_ext = extent; // unbuffered box2d buffered_query_ext(query_ext); // buffered - double buffer_padding = 2.0 * scale; + double buffer_padding = 2.0 * scale * p.scale_factor(); boost::optional layer_buffer_size = lay.buffer_size(); if (layer_buffer_size) // if layer overrides buffer size, use this value to compute buffered extent { diff --git a/test/unit/renderer/buffer_size_scale_factor.cpp b/test/unit/renderer/buffer_size_scale_factor.cpp new file mode 100644 index 000000000..ea36dc01a --- /dev/null +++ b/test/unit/renderer/buffer_size_scale_factor.cpp @@ -0,0 +1,100 @@ +#include "catch.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class test_datasource : public mapnik::memory_datasource +{ +public: + test_datasource(mapnik::box2d const& expected_query_bbox) + : expected_query_bbox_(expected_query_bbox), + mapnik::memory_datasource(prepare_params()) + { + } + + virtual mapnik::featureset_ptr features(mapnik::query const& q) const + { + mapnik::box2d const& actual_bbox = q.get_bbox(); + REQUIRE(actual_bbox.minx() == Approx(expected_query_bbox_.minx())); + REQUIRE(actual_bbox.miny() == Approx(expected_query_bbox_.miny())); + REQUIRE(actual_bbox.maxx() == Approx(expected_query_bbox_.maxx())); + REQUIRE(actual_bbox.maxy() == Approx(expected_query_bbox_.maxy())); + return mapnik::memory_datasource::features(q); + } + +private: + mapnik::parameters prepare_params() const + { + mapnik::parameters params; + params["type"] = "memory"; + return params; + } + + mapnik::box2d expected_query_bbox_; +}; + + +TEST_CASE("feature_style_processor: buffer-size with scale-factor") { + +SECTION("query extent with buffer-size should not be affected by scale-factor") { + + const mapnik::box2d expected_query_bbox(-0.5, -0.5, 1.5, 1.5); + + using datasource_ptr = std::shared_ptr; + datasource_ptr datasource = std::make_shared( + expected_query_bbox); + mapnik::context_ptr ctx = std::make_shared(); + { + mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx, 2)); + mapnik::geometry::line_string path; + path.emplace_back(-10, -10); + path.emplace_back(10, 10); + feature->set_geometry(std::move(path)); + datasource->push(feature); + } + + mapnik::Map map(256, 256); + map.set_buffer_size(128); + + mapnik::feature_type_style lines_style; + mapnik::rule rule; + mapnik::line_symbolizer line_sym; + rule.append(std::move(line_sym)); + lines_style.add_rule(std::move(rule)); + map.insert_style("lines", std::move(lines_style)); + + mapnik::layer lyr("layer"); + lyr.set_datasource(datasource); + lyr.add_style("lines"); + map.add_layer(lyr); + + const mapnik::box2d map_extent(0, 0, 1, 1); + map.zoom_to_box(map_extent); + + { + mapnik::image_rgba8 image(map.width(), map.height()); + mapnik::agg_renderer ren(map, image); + ren.apply(); + } + + { + // Rendering with scale-factor 2.0 should query data + // with the same extent as with scale-factor 1.0. + map.resize(map.width() * 2, map.height() * 2); + mapnik::image_rgba8 image(map.width(), map.height()); + mapnik::agg_renderer ren(map, image, 2.0); + ren.apply(); + } +} + +} +