File: buffer_size_scale_factor.cpp

package info (click to toggle)
mapnik 4.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 18,548 kB
  • sloc: cpp: 163,861; python: 1,190; sh: 690; xml: 161; makefile: 123; perl: 28; lisp: 13
file content (95 lines) | stat: -rw-r--r-- 3,313 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "catch.hpp"

#include <mapnik/memory_datasource.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_factory.hpp>
#include <mapnik/map.hpp>
#include <mapnik/params.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/rule.hpp>
#include <mapnik/feature_type_style.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/geometry/geometry_type.hpp>
#include <mapnik/agg_renderer.hpp>

class test_datasource : public mapnik::memory_datasource
{
  public:
    test_datasource(mapnik::box2d<double> const& expected_query_bbox)
        : mapnik::memory_datasource(prepare_params()),
          expected_query_bbox_(expected_query_bbox)
    {}

    virtual mapnik::featureset_ptr features(mapnik::query const& q) const
    {
        mapnik::box2d<double> 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<double> 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")
    {
        mapnik::box2d<double> const expected_query_bbox(-0.5, -0.5, 1.5, 1.5);

        using datasource_ptr = std::shared_ptr<test_datasource>;
        datasource_ptr datasource = std::make_shared<test_datasource>(expected_query_bbox);
        mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
        {
            mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx, 2));
            mapnik::geometry::line_string<double> 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);

        mapnik::box2d<double> const map_extent(0, 0, 1, 1);
        map.zoom_to_box(map_extent);

        {
            mapnik::image_rgba8 image(map.width(), map.height());
            mapnik::agg_renderer<mapnik::image_rgba8> 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<mapnik::image_rgba8> ren(map, image, 2.0);
            ren.apply();
        }
    }
}