File: markers_point_placement.cpp

package info (click to toggle)
mapnik 4.2.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,656 kB
  • sloc: cpp: 163,870; python: 1,332; sh: 690; xml: 161; makefile: 123; perl: 28; lisp: 13
file content (141 lines) | stat: -rw-r--r-- 5,287 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

#include "catch.hpp"

#include <mapnik/vertex_adapters.hpp>
#include <mapnik/label_collision_detector.hpp>
#include <mapnik/markers_placements/point.hpp>

using namespace mapnik;

TEST_CASE("marker placement point")
{
    SECTION("empty geometry")
    {
        mapnik::geometry::line_string<double> g;
        using va_type = mapnik::geometry::line_string_vertex_adapter<double>;
        va_type va(g);

        using detector_type = mapnik::label_collision_detector4;
        detector_type detector(mapnik::box2d<double>(0, 0, 100, 100));

        using placement_type = mapnik::markers_point_placement<va_type, detector_type>;

        mapnik::markers_placement_params params{mapnik::box2d<double>(0, 0, 10, 10),
                                                agg::trans_affine(),
                                                0,
                                                NAN,
                                                0,
                                                false,
                                                false,
                                                direction_enum::DIRECTION_AUTO,
                                                1.0};

        placement_type placement(va, detector, params);

        double x, y, angle;
        CHECK(!placement.get_point(x, y, angle, true));
    }

    SECTION("point")
    {
        mapnik::geometry::point<double> g(2.0, 3.0);
        using va_type = mapnik::geometry::point_vertex_adapter<double>;
        va_type va(g);

        using detector_type = mapnik::label_collision_detector4;
        detector_type detector(mapnik::box2d<double>(0, 0, 100, 100));

        using placement_type = mapnik::markers_point_placement<va_type, detector_type>;

        mapnik::markers_placement_params params{mapnik::box2d<double>(0, 0, 10, 10),
                                                agg::trans_affine(),
                                                0,
                                                NAN,
                                                0,
                                                false,
                                                false,
                                                direction_enum::DIRECTION_AUTO,
                                                1.0};

        placement_type placement(va, detector, params);

        double x, y, angle;

        CHECK(placement.get_point(x, y, angle, true));
        CHECK(x == Approx(2.0));
        CHECK(y == Approx(3.0));
        CHECK(angle == Approx(0.0));

        CHECK(!placement.get_point(x, y, angle, true));
    }

    SECTION("line string")
    {
        mapnik::geometry::line_string<double> g;
        g.emplace_back(1.0, 1.0);
        g.emplace_back(2.0, 2.0);
        using va_type = mapnik::geometry::line_string_vertex_adapter<double>;
        va_type va(g);

        using detector_type = mapnik::label_collision_detector4;
        detector_type detector(mapnik::box2d<double>(0, 0, 100, 100));

        using placement_type = mapnik::markers_point_placement<va_type, detector_type>;

        mapnik::markers_placement_params params{mapnik::box2d<double>(0, 0, 10, 10),
                                                agg::trans_affine(),
                                                0,
                                                NAN,
                                                0,
                                                false,
                                                false,
                                                direction_enum::DIRECTION_AUTO,
                                                1.0};

        placement_type placement(va, detector, params);

        double x, y, angle;

        CHECK(placement.get_point(x, y, angle, true));
        CHECK(x == Approx(1.5));
        CHECK(y == Approx(1.5));
        CHECK(angle == Approx(0));

        CHECK(!placement.get_point(x, y, angle, true));
    }

    SECTION("line string zero length")
    {
        mapnik::geometry::line_string<double> g;
        g.emplace_back(1.0, 1.0);
        g.emplace_back(1.0, 1.0);
        using va_type = mapnik::geometry::line_string_vertex_adapter<double>;
        va_type va(g);

        using detector_type = mapnik::label_collision_detector4;
        detector_type detector(mapnik::box2d<double>(0, 0, 100, 100));

        using placement_type = mapnik::markers_point_placement<va_type, detector_type>;

        mapnik::markers_placement_params params{mapnik::box2d<double>(0, 0, 10, 10),
                                                agg::trans_affine(),
                                                0,
                                                NAN,
                                                0,
                                                false,
                                                false,
                                                direction_enum::DIRECTION_AUTO,
                                                1.0};

        placement_type placement(va, detector, params);

        double x, y, angle;

        CHECK(placement.get_point(x, y, angle, true));
        CHECK(x == Approx(1.0));
        CHECK(y == Approx(1.0));
        CHECK(angle == Approx(0));

        CHECK(!placement.get_point(x, y, angle, true));
    }
}