Skip to content

Commit ccca784

Browse files
committed
refactoring placement code
- all placement methods are supported by all relevant symbolizers
1 parent f47caec commit ccca784

File tree

94 files changed

+4651
-3433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+4651
-3433
lines changed

include/mapnik/agg_renderer.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>
183183
return false;
184184
}
185185

186+
template <typename Sym>
187+
void process_marker(
188+
Sym const& sym,
189+
mapnik::feature_impl & feature,
190+
proj_transform const& prj_trans);
191+
186192
void painted(bool painted);
187193
bool painted();
188194

include/mapnik/box2d.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ template <typename T> class MAPNIK_DECL box2d
116116
bool valid() const;
117117
void move(T x, T y);
118118
std::string to_string() const;
119+
T area() const;
119120

120121
// define some operators
121122
box2d_type& operator+=(box2d_type const& other);

include/mapnik/box2d_impl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ std::string box2d<T>::to_string() const
393393
return s.str();
394394
}
395395

396+
template <typename T>
397+
T box2d<T>::area() const
398+
{
399+
return width() * height();
400+
}
396401

397402
template <typename T>
398403
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)

include/mapnik/cairo/cairo_renderer.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer
141141
return false;
142142
}
143143

144+
template <typename Sym>
145+
void process_marker(
146+
Sym const& sym,
147+
mapnik::feature_impl & feature,
148+
proj_transform const& prj_trans);
149+
144150
bool painted()
145151
{
146152
return true;

include/mapnik/extend_converter.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ struct extend_converter
222222
extender_.start();
223223
}
224224

225+
unsigned type() const
226+
{
227+
return static_cast<unsigned>(geom_.type());
228+
}
229+
225230
private:
226231
Geometry & geom_;
227232
detail::extender extender_;

include/mapnik/geometry_cref.hpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*****************************************************************************
2+
*
3+
* This file is part of Mapnik (c++ mapping toolkit)
4+
*
5+
* Copyright (C) 2015 Artem Pavlenko
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2.1 of the License, or (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
*****************************************************************************/
22+
23+
#ifndef MAPNIK_GEOMETRY_CREF_HPP
24+
#define MAPNIK_GEOMETRY_CREF_HPP
25+
26+
#include <mapnik/geometry.hpp>
27+
#include <mapnik/geometry_type.hpp>
28+
#include <mapnik/geometry_envelope.hpp>
29+
#include <mapnik/box2d.hpp>
30+
31+
#include <functional>
32+
33+
namespace mapnik { namespace geometry {
34+
35+
template <typename T>
36+
struct cref_geometry
37+
{
38+
using empty_type = std::reference_wrapper<geometry_empty const>;
39+
using point_type = std::reference_wrapper<point<T> const>;
40+
using line_string_type = std::reference_wrapper<line_string<T> const>;
41+
using polygon_type = std::reference_wrapper<polygon<T> const>;
42+
using multi_point_type = std::reference_wrapper<multi_point<T> const>;
43+
using multi_line_string_type = std::reference_wrapper<multi_line_string<T> const>;
44+
using multi_polygon_type = std::reference_wrapper<multi_polygon<T> const>;
45+
using collection_type = std::reference_wrapper<geometry_collection<T> const>;
46+
using geometry_type = util::variant<
47+
empty_type,
48+
point_type,
49+
line_string_type,
50+
polygon_type,
51+
multi_point_type,
52+
multi_line_string_type,
53+
multi_polygon_type,
54+
collection_type>;
55+
};
56+
57+
template <typename T>
58+
struct cref_geometry_cast
59+
{
60+
using geometry_type = typename cref_geometry<T>::geometry_type;
61+
62+
template <typename Geometry>
63+
geometry_type operator() (Geometry const& geom) const
64+
{
65+
return std::cref(geom);
66+
}
67+
};
68+
69+
template <typename Geom, typename T = double>
70+
inline typename cref_geometry<T>::geometry_type to_cref(Geom const & geom)
71+
{
72+
cref_geometry_cast<T> visitor;
73+
return util::apply_visitor(visitor, geom);
74+
}
75+
76+
struct envelope_impl
77+
{
78+
box2d<double> operator() (geometry_empty const& ref) const
79+
{
80+
return box2d<double>();
81+
}
82+
83+
template <typename T>
84+
box2d<double> operator() (T const& ref) const
85+
{
86+
return envelope<T>(ref);
87+
}
88+
};
89+
90+
mapnik::box2d<double> envelope(cref_geometry<double>::geometry_type const& geom);
91+
92+
struct geometry_type_impl
93+
{
94+
template <typename T>
95+
auto operator() (T const& ref) const -> decltype(geometry_type<T>(ref))
96+
{
97+
return geometry_type<T>(ref);
98+
}
99+
};
100+
101+
mapnik::geometry::geometry_types geometry_type(cref_geometry<double>::geometry_type const& geom);
102+
103+
} }
104+
105+
#endif // MAPNIK_GEOMETRY_CREF_HPP
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*****************************************************************************
2+
*
3+
* This file is part of Mapnik (c++ mapping toolkit)
4+
*
5+
* Copyright (C) 2015 Artem Pavlenko
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2.1 of the License, or (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
*****************************************************************************/
22+
23+
#ifndef MAPNIK_GEOMETRY_SPLIT_MULTI_HPP
24+
#define MAPNIK_GEOMETRY_SPLIT_MULTI_HPP
25+
26+
#include <mapnik/geometry_cref.hpp>
27+
28+
namespace mapnik { namespace geometry {
29+
30+
template <typename T, typename Container>
31+
struct split_multi_geometries
32+
{
33+
using geometry_type = typename cref_geometry<T>::geometry_type;
34+
35+
split_multi_geometries(Container & cont)
36+
: cont_(cont) { }
37+
38+
void operator() (geometry_empty const&) const {}
39+
void operator() (multi_point<T> const& multi_pt) const
40+
{
41+
for (auto const& pt : multi_pt)
42+
{
43+
cont_.emplace_back(std::cref(pt));
44+
}
45+
}
46+
void operator() (line_string<T> const& line) const
47+
{
48+
cont_.emplace_back(std::cref(line));
49+
}
50+
51+
void operator() (multi_line_string<T> const& multi_line) const
52+
{
53+
for (auto const& line : multi_line)
54+
{
55+
(*this)(line);
56+
}
57+
}
58+
59+
void operator() (polygon<T> const& poly) const
60+
{
61+
cont_.emplace_back(std::cref(poly));
62+
}
63+
64+
void operator() (multi_polygon<T> const& multi_poly) const
65+
{
66+
for (auto const& poly : multi_poly)
67+
{
68+
(*this)(poly);
69+
}
70+
}
71+
72+
void operator() (geometry_collection<T> const& collection) const
73+
{
74+
for (auto const& geom : collection)
75+
{
76+
util::apply_visitor(*this, geom);
77+
}
78+
}
79+
80+
template <typename Geometry>
81+
void operator() (Geometry const& geom) const
82+
{
83+
cont_.emplace_back(std::cref(geom));
84+
}
85+
86+
Container & cont_;
87+
};
88+
89+
template <typename Geom, typename Container, typename T = double>
90+
inline void split(Geom const & geom, Container & container)
91+
{
92+
split_multi_geometries<T, Container> visitor(container);
93+
util::apply_visitor(visitor, geom);
94+
}
95+
96+
}}
97+
98+
#endif // MAPNIK_GEOMETRY_SPLIT_MULTI_HPP

include/mapnik/grid/grid_renderer.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ class MAPNIK_DECL grid_renderer : public feature_style_processor<grid_renderer<T
119119
return false;
120120
}
121121

122+
template <typename Sym>
123+
void process_marker(
124+
Sym const& sym,
125+
mapnik::feature_impl & feature,
126+
proj_transform const& prj_trans);
127+
122128
bool painted()
123129
{
124130
return pixmap_.painted();

0 commit comments

Comments
 (0)