1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
7 // This file was modified by Oracle on 2014.
8 // Modifications copyright (c) 2014, Oracle and/or its affiliates.
10 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16 // Use, modification and distribution is subject to the Boost Software License,
17 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
20 #ifndef BOOST_GEOMETRY_ALGORITHMS_APPEND_HPP
21 #define BOOST_GEOMETRY_ALGORITHMS_APPEND_HPP
24 #include <boost/range.hpp>
26 #include <boost/variant/apply_visitor.hpp>
27 #include <boost/variant/static_visitor.hpp>
28 #include <boost/variant/variant_fwd.hpp>
30 #include <boost/geometry/algorithms/num_interior_rings.hpp>
31 #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
32 #include <boost/geometry/core/access.hpp>
33 #include <boost/geometry/core/mutable_range.hpp>
34 #include <boost/geometry/core/point_type.hpp>
35 #include <boost/geometry/core/tags.hpp>
36 #include <boost/geometry/geometries/concepts/check.hpp>
37 #include <boost/geometry/geometries/variant.hpp>
38 #include <boost/geometry/util/range.hpp>
41 namespace boost { namespace geometry
45 #ifndef DOXYGEN_NO_DETAIL
46 namespace detail { namespace append
49 template <typename Geometry, typename Point>
50 struct append_no_action
52 static inline void apply(Geometry& , Point const& ,
58 template <typename Geometry, typename Point>
61 static inline void apply(Geometry& geometry, Point const& point,
64 typename geometry::point_type<Geometry>::type copy;
65 geometry::detail::conversion::convert_point_to_point(point, copy);
66 traits::push_back<Geometry>::apply(geometry, copy);
71 template <typename Geometry, typename Range>
74 typedef typename boost::range_value<Range>::type point_type;
76 static inline void apply(Geometry& geometry, Range const& range,
79 for (typename boost::range_iterator<Range const>::type
80 it = boost::begin(range);
81 it != boost::end(range);
84 append_point<Geometry, point_type>::apply(geometry, *it);
90 template <typename Polygon, typename Point>
91 struct point_to_polygon
93 typedef typename ring_type<Polygon>::type ring_type;
95 static inline void apply(Polygon& polygon, Point const& point,
96 int ring_index, int = 0)
100 append_point<ring_type, Point>::apply(
101 exterior_ring(polygon), point);
103 else if (ring_index < int(num_interior_rings(polygon)))
105 append_point<ring_type, Point>::apply(
106 range::at(interior_rings(polygon), ring_index), point);
112 template <typename Polygon, typename Range>
113 struct range_to_polygon
115 typedef typename ring_type<Polygon>::type ring_type;
117 static inline void apply(Polygon& polygon, Range const& range,
118 int ring_index, int = 0)
120 if (ring_index == -1)
122 append_range<ring_type, Range>::apply(
123 exterior_ring(polygon), range);
125 else if (ring_index < int(num_interior_rings(polygon)))
127 append_range<ring_type, Range>::apply(
128 range::at(interior_rings(polygon), ring_index), range);
134 }} // namespace detail::append
135 #endif // DOXYGEN_NO_DETAIL
138 #ifndef DOXYGEN_NO_DISPATCH
142 namespace splitted_dispatch
145 template <typename Tag, typename Geometry, typename Point>
147 : detail::append::append_no_action<Geometry, Point>
150 template <typename Geometry, typename Point>
151 struct append_point<linestring_tag, Geometry, Point>
152 : detail::append::append_point<Geometry, Point>
155 template <typename Geometry, typename Point>
156 struct append_point<ring_tag, Geometry, Point>
157 : detail::append::append_point<Geometry, Point>
161 template <typename Polygon, typename Point>
162 struct append_point<polygon_tag, Polygon, Point>
163 : detail::append::point_to_polygon<Polygon, Point>
167 template <typename Tag, typename Geometry, typename Range>
169 : detail::append::append_no_action<Geometry, Range>
172 template <typename Geometry, typename Range>
173 struct append_range<linestring_tag, Geometry, Range>
174 : detail::append::append_range<Geometry, Range>
177 template <typename Geometry, typename Range>
178 struct append_range<ring_tag, Geometry, Range>
179 : detail::append::append_range<Geometry, Range>
183 template <typename Polygon, typename Range>
184 struct append_range<polygon_tag, Polygon, Range>
185 : detail::append::range_to_polygon<Polygon, Range>
188 } // namespace splitted_dispatch
191 // Default: append a range (or linestring or ring or whatever) to any geometry
194 typename Geometry, typename RangeOrPoint,
195 typename TagRangeOrPoint = typename tag<RangeOrPoint>::type
198 : splitted_dispatch::append_range<typename tag<Geometry>::type, Geometry, RangeOrPoint>
201 // Specialization for point to append a point to any geometry
202 template <typename Geometry, typename RangeOrPoint>
203 struct append<Geometry, RangeOrPoint, point_tag>
204 : splitted_dispatch::append_point<typename tag<Geometry>::type, Geometry, RangeOrPoint>
207 } // namespace dispatch
208 #endif // DOXYGEN_NO_DISPATCH
210 #ifndef DOXYGEN_NO_DETAIL
211 namespace detail { namespace append
214 template <typename MultiGeometry, typename RangeOrPoint>
215 struct append_to_multigeometry
217 static inline void apply(MultiGeometry& multigeometry,
218 RangeOrPoint const& range_or_point,
219 int ring_index, int multi_index)
224 typename boost::range_value<MultiGeometry>::type,
226 >::apply(range::at(multigeometry, multi_index), range_or_point, ring_index);
230 }} // namespace detail::append
231 #endif // DOXYGEN_NO_DETAIL
233 #ifndef DOXYGEN_NO_DISPATCH
237 namespace splitted_dispatch
240 template <typename Geometry, typename Point>
241 struct append_point<multi_point_tag, Geometry, Point>
242 : detail::append::append_point<Geometry, Point>
245 template <typename Geometry, typename Range>
246 struct append_range<multi_point_tag, Geometry, Range>
247 : detail::append::append_range<Geometry, Range>
250 template <typename MultiGeometry, typename RangeOrPoint>
251 struct append_point<multi_linestring_tag, MultiGeometry, RangeOrPoint>
252 : detail::append::append_to_multigeometry<MultiGeometry, RangeOrPoint>
255 template <typename MultiGeometry, typename RangeOrPoint>
256 struct append_range<multi_linestring_tag, MultiGeometry, RangeOrPoint>
257 : detail::append::append_to_multigeometry<MultiGeometry, RangeOrPoint>
260 template <typename MultiGeometry, typename RangeOrPoint>
261 struct append_point<multi_polygon_tag, MultiGeometry, RangeOrPoint>
262 : detail::append::append_to_multigeometry<MultiGeometry, RangeOrPoint>
265 template <typename MultiGeometry, typename RangeOrPoint>
266 struct append_range<multi_polygon_tag, MultiGeometry, RangeOrPoint>
267 : detail::append::append_to_multigeometry<MultiGeometry, RangeOrPoint>
270 } // namespace splitted_dispatch
272 } // namespace dispatch
273 #endif // DOXYGEN_NO_DISPATCH
276 namespace resolve_variant {
278 template <typename Geometry>
281 template <typename RangeOrPoint>
282 static inline void apply(Geometry& geometry,
283 RangeOrPoint const& range_or_point,
287 concepts::check<Geometry>();
288 dispatch::append<Geometry, RangeOrPoint>::apply(geometry,
296 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
297 struct append<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
299 template <typename RangeOrPoint>
300 struct visitor: boost::static_visitor<void>
302 RangeOrPoint const& m_range_or_point;
306 visitor(RangeOrPoint const& range_or_point,
309 m_range_or_point(range_or_point),
310 m_ring_index(ring_index),
311 m_multi_index(multi_index)
314 template <typename Geometry>
315 void operator()(Geometry& geometry) const
317 append<Geometry>::apply(geometry,
324 template <typename RangeOrPoint>
325 static inline void apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& variant_geometry,
326 RangeOrPoint const& range_or_point,
330 boost::apply_visitor(
331 visitor<RangeOrPoint>(
341 } // namespace resolve_variant;
345 \brief Appends one or more points to a linestring, ring, polygon, multi-geometry
347 \tparam Geometry \tparam_geometry
348 \tparam RangeOrPoint Either a range or a point, fullfilling Boost.Range concept or Boost.Geometry Point Concept
349 \param geometry \param_geometry
350 \param range_or_point The point or range to add
351 \param ring_index The index of the ring in case of a polygon:
352 exterior ring (-1, the default) or interior ring index
353 \param multi_index The index of the geometry to which the points are appended
355 \qbk{[include reference/algorithms/append.qbk]}
358 template <typename Geometry, typename RangeOrPoint>
359 inline void append(Geometry& geometry, RangeOrPoint const& range_or_point,
360 int ring_index = -1, int multi_index = 0)
362 resolve_variant::append<Geometry>
363 ::apply(geometry, range_or_point, ring_index, multi_index);
367 }} // namespace boost::geometry
370 #endif // BOOST_GEOMETRY_ALGORITHMS_APPEND_HPP