/usr/include/mapnik/path.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 | /*****************************************************************************
*
* 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_PATH_HPP
#define MAPNIK_PATH_HPP
// mapnik
#include <mapnik/vertex_vector.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/util/noncopyable.hpp>
namespace mapnik { namespace detail {
template <typename T, template <typename> class Container=vertex_vector>
class path : private util::noncopyable
{
public:
static const std::uint8_t geometry_bits = 7;
enum types : std::uint8_t
{
Unknown = 0x00,
Point = 0x01,
LineString = 0x02,
Polygon = 0x03,
PolygonExterior = Polygon,
PolygonInterior = Polygon | ( 1 << geometry_bits)
};
using coord_type = T;
using container_type = Container<coord_type>;
using value_type = typename container_type::value_type;
using size_type = typename container_type::size_type;
container_type cont_;
types type_;
public:
path()
: type_(Unknown)
{}
explicit path(types type)
: type_(type)
{}
types type() const
{
return static_cast<types>(type_ & types::Polygon);
}
bool interior() const
{
return static_cast<bool>(type_ >> geometry_bits);
}
void set_type(types type)
{
type_ = type;
}
container_type const& data() const
{
return cont_;
}
size_type size() const
{
return cont_.size();
}
void push_vertex(coord_type x, coord_type y, CommandType c)
{
cont_.push_back(x,y,c);
}
void line_to(coord_type x,coord_type y)
{
push_vertex(x,y,SEG_LINETO);
}
void move_to(coord_type x,coord_type y)
{
push_vertex(x,y,SEG_MOVETO);
}
void close_path()
{
push_vertex(0,0,SEG_CLOSE);
}
};
template <typename T>
struct vertex_adapter : private util::noncopyable
{
using path_type = T;
using size_type = typename path_type::size_type;
using value_type = typename path_type::value_type;
using types = typename path_type::types;
vertex_adapter(path_type const& path)
: path_(path),
itr_(0) {}
size_type size() const
{
return path_.size();
}
unsigned vertex(double* x, double* y) const
{
return path_.cont_.get_vertex(static_cast<unsigned>(itr_++),x,y);
}
unsigned vertex(std::size_t index, double* x, double* y) const
{
return path_.cont_.get_vertex(index, x, y);
}
void rewind(unsigned ) const
{
itr_ = 0;
}
types type() const
{
return path_.type();
}
box2d<double> envelope() const
{
box2d<double> result;
double x = 0;
double y = 0;
rewind(0);
size_type path_size = size();
for (size_type i = 0; i < path_size; ++i)
{
unsigned cmd = vertex(&x,&y);
if (cmd == SEG_CLOSE) continue;
if (i == 0)
{
result.init(x,y,x,y);
}
else
{
result.expand_to_include(x,y);
}
}
return result;
}
path_type const& path_;
mutable size_type itr_;
};
}
template <typename PathType>
box2d<double> envelope(PathType const& path)
{
detail::vertex_adapter<PathType> va(path);
return va.envelope();
}
using path_type = detail::path<double,vertex_vector>;
using vertex_adapter = detail::vertex_adapter<path_type>;
}
#endif // MAPNIK_PATH_HPP
|