1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RING_HPP
10 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RING_HPP
13 #include <boost/range.hpp>
15 #include <boost/geometry/core/assert.hpp>
16 #include <boost/geometry/core/exterior_ring.hpp>
17 #include <boost/geometry/core/interior_rings.hpp>
18 #include <boost/geometry/core/ring_type.hpp>
19 #include <boost/geometry/core/tags.hpp>
20 #include <boost/geometry/algorithms/detail/ring_identifier.hpp>
21 #include <boost/geometry/geometries/concepts/check.hpp>
22 #include <boost/geometry/util/range.hpp>
25 namespace boost { namespace geometry
29 #ifndef DOXYGEN_NO_DETAIL
30 namespace detail { namespace overlay
34 template<typename Tag>
38 // A range of rings (multi-ring but that does not exist)
39 // gets the "void" tag and is dispatched here.
43 template<typename Range>
44 static inline typename boost::range_value<Range>::type const&
45 apply(ring_identifier const& id, Range const& container)
47 return range::at(container, id.multi_index);
55 struct get_ring<ring_tag>
57 template<typename Ring>
58 static inline Ring const& apply(ring_identifier const& , Ring const& ring)
66 struct get_ring<box_tag>
68 template<typename Box>
69 static inline Box const& apply(ring_identifier const& ,
78 struct get_ring<polygon_tag>
80 template<typename Polygon>
81 static inline typename ring_return_type<Polygon const>::type const apply(
82 ring_identifier const& id,
83 Polygon const& polygon)
88 && id.ring_index < int(boost::size(interior_rings(polygon)))
90 return id.ring_index < 0
91 ? exterior_ring(polygon)
92 : range::at(interior_rings(polygon), id.ring_index);
98 struct get_ring<multi_polygon_tag>
100 template<typename MultiPolygon>
101 static inline typename ring_type<MultiPolygon>::type const& apply(
102 ring_identifier const& id,
103 MultiPolygon const& multi_polygon)
105 BOOST_GEOMETRY_ASSERT
108 && id.multi_index < int(boost::size(multi_polygon))
110 return get_ring<polygon_tag>::apply(id,
111 range::at(multi_polygon, id.multi_index));
116 }} // namespace detail::overlay
117 #endif // DOXYGEN_NO_DETAIL
120 }} // namespace boost::geometry
123 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RING_HPP