|
| 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 |
0 commit comments