File: agg_rasterizer_integer_overflow_test.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 (72 lines) | stat: -rw-r--r-- 2,610 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
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include <mapnik/mapnik.hpp>
#include <mapnik/map.hpp>
#include <mapnik/memory_datasource.hpp>
#include <mapnik/json/feature_parser.hpp>
#include <mapnik/feature_type_style.hpp>
#include <mapnik/rule.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/agg_renderer.hpp>
#include <mapnik/debug.hpp>

#include <iostream>

// geojson box of the world
std::string const
  geojson("{ \"type\": \"Feature\", \"properties\": { }, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ "
          "-17963313.143242701888084, -6300857.11560364998877 ], [ -17963313.143242701888084, 13071343.332991421222687 "
          "], [ 7396658.353099936619401, 13071343.332991421222687 ], [ 7396658.353099936619401, "
          "-6300857.11560364998877 ], [ -17963313.143242701888084, -6300857.11560364998877 ] ] ] } }");

TEST_CASE("agg_rasterizer_integer_overflow")
{
    mapnik::setup();
    SECTION("coordinates_do_not_overflow_and_polygon_is_rendered")
    {
        auto expected_color = mapnik::color("white");

        mapnik::Map m(256, 256);
        m.set_background(mapnik::color("black"));

        mapnik::feature_type_style s;
        {
            mapnik::rule r;
            mapnik::polygon_symbolizer sym;
            mapnik::put(sym, mapnik::keys::fill, expected_color);
            mapnik::put(sym, mapnik::keys::clip, false);
            r.append(std::move(sym));
            s.add_rule(std::move(r));
        }
        m.insert_style("style", std::move(s));

        mapnik::layer lyr("Layer");
        lyr.styles().emplace_back("style");
        {
            auto ds = std::make_shared<mapnik::memory_datasource>(mapnik::parameters());
            auto context = std::make_shared<mapnik::context_type>();
            auto f = std::make_shared<mapnik::feature_impl>(context, 0);
            REQUIRE(mapnik::json::from_geojson(geojson, *f));
            ds->push(f);
            lyr.set_datasource(ds);
        }
        m.add_layer(std::move(lyr));

        // 17/20864/45265.png
        m.zoom_to_box(
          mapnik::box2d<double>(-13658379.710221574, 6197514.253362091, -13657768.213995293, 6198125.749588372));

        // works 15/5216/11316.png
        // m.zoom_to_box(mapnik::box2d<double>(-13658379.710221574,6195679.764683247,-13655933.72531645,6198125.749588372));

        mapnik::image_rgba8 im(256, 256);
        {
            mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
            ren.apply();
        }

        REQUIRE(im(128, 128) == expected_color.rgba());
    } // SECTION
} // TEST_CASE