/usr/include/mapnik/geometry_strategy.hpp is in libmapnik-dev 3.0.12+ds-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | /*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_GEOMETRY_STRATEGY_HPP
#define MAPNIK_GEOMETRY_STRATEGY_HPP
#include <mapnik/geometry_adapters.hpp>
#include <mapnik/util/rounding_cast.hpp>
namespace mapnik {
namespace geometry {
namespace helper
{
template <std::size_t... Ts>
struct index {};
template <std::size_t N, std::size_t... Ts>
struct gen_seq : gen_seq<N - 1, N - 1, Ts...> {};
template <std::size_t... Ts>
struct gen_seq<0, Ts...> : index<Ts...> {};
}
// Groups a set of strategies at runtime, the conversion from P1 to P2 will take place on the LAST strategy.
template <typename... Strategies>
struct strategy_group
{
strategy_group(Strategies const& ... ops)
: ops_(ops ...) {}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
bool status = true;
p2 = execute_start<P1,P2>(p1, status, ops_);
return status;
}
template <typename P1, typename P2, typename... Args, std::size_t... Is>
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
{
return execute<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
}
template <typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
{
return execute_start<P1,P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)> {} );
}
template <typename P1, typename P2, typename T, typename ...Args>
inline P2 execute(P1 const& p, bool & status, T const& strat, Args const& ... args) const
{
return execute<P1,P2>(strat.template execute<P1,P1>(p, status), status, args...);
}
template <typename P1, typename P2, typename T>
inline P2 execute(P1 const& p, bool & status, T const& strat) const
{
return strat.template execute<P1,P2>(p, status);
}
private:
std::tuple<Strategies const& ...> ops_;
};
// The difference between this strategy group and the previous is that the conversion from P1 to P2 happens
// in the first strategy rather then the last strategy.
template <typename... Strategies>
struct strategy_group_first
{
strategy_group_first(Strategies const& ... ops)
: ops_(ops ...) {}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
bool status = true;
p2 = execute_start<P1,P2>(p1, status, ops_);
return status;
}
template <typename P1, typename P2, typename... Args, std::size_t... Is>
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
{
return execute_first<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
}
template <typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
{
return execute_start<P1,P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)> {} );
}
template <typename P1, typename P2, typename T, typename ...Args>
inline P2 execute_first(P1 const& p, bool & status, T const& strat, Args const& ... args) const
{
return execute<P2>(strat.template execute<P1,P2>(p, status), status, args...);
}
template <typename P2, typename T, typename ...Args>
inline P2 execute(P2 const& p, bool & status, T const& strat, Args const& ... args) const
{
return execute<P2>(strat.template execute<P2,P2>(p, status), status, args...);
}
template <typename P2, typename T>
inline P2 execute(P2 const& p, bool & status, T const& strat) const
{
return strat.template execute<P2,P2>(p, status);
}
template <typename P2>
inline P2 execute(P2 const& p, bool & status) const
{
return p;
}
private:
std::tuple<Strategies const& ...> ops_;
};
struct scale_strategy
{
scale_strategy(double scale, double offset = 0)
: scale_(scale), offset_(offset) {}
template <typename P1, typename P2>
inline bool apply(P1 const & p1, P2 & p2) const
{
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
boost::geometry::set<0>(p2, static_cast<p2_type>(x));
boost::geometry::set<1>(p2, static_cast<p2_type>(y));
return true;
}
template <typename P1, typename P2>
inline P2 execute(P1 const& p1, bool & status) const
{
P2 p2;
status = apply(p1, p2);
return p2;
}
private:
double scale_;
double offset_;
};
struct scale_rounding_strategy
{
scale_rounding_strategy(double scale, double offset = 0)
: scale_(scale), offset_(offset) {}
template <typename P1, typename P2>
inline bool apply(P1 const & p1, P2 & p2) const
{
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
boost::geometry::set<0>(p2, static_cast<p2_type>(std::round(x)));
boost::geometry::set<1>(p2, static_cast<p2_type>(std::round(y)));
return true;
}
template <typename P1, typename P2>
inline P2 execute(P1 const& p1, bool & status) const
{
P2 p2;
status = apply(p1, p2);
return p2;
}
private:
double scale_;
double offset_;
};
} // end geometry ns
} // end mapnik ns
#endif //MAPNIK_GEOMETRY_STRATEGY_HPP
|