1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
4 
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)
8 
9 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RING_HPP
10 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RING_HPP
11 
12 
13 #include <boost/assert.hpp>
14 #include <boost/range.hpp>
15 
16 
17 #include <boost/geometry/core/tags.hpp>
18 #include <boost/geometry/core/exterior_ring.hpp>
19 #include <boost/geometry/core/interior_rings.hpp>
20 #include <boost/geometry/algorithms/detail/ring_identifier.hpp>
21 
22 
23 namespace boost { namespace geometry
24 {
25 
26 
27 #ifndef DOXYGEN_NO_DETAIL
28 namespace detail { namespace overlay
29 {
30 
31 
32 template<typename Tag>
33 struct get_ring
34 {};
35 
36 // A container of rings (multi-ring but that does not exist)
37 // gets the "void" tag and is dispatched here.
38 template<>
39 struct get_ring<void>
40 {
41     template<typename Container>
42     static inline typename boost::range_value<Container>::type const&
applyboost::geometry::detail::overlay::get_ring43                 apply(ring_identifier const& id, Container const& container)
44     {
45         return container[id.multi_index];
46     }
47 };
48 
49 
50 
51 
52 template<>
53 struct get_ring<ring_tag>
54 {
55     template<typename Ring>
applyboost::geometry::detail::overlay::get_ring56     static inline Ring const& apply(ring_identifier const& , Ring const& ring)
57     {
58         return ring;
59     }
60 };
61 
62 
63 template<>
64 struct get_ring<box_tag>
65 {
66     template<typename Box>
applyboost::geometry::detail::overlay::get_ring67     static inline Box const& apply(ring_identifier const& ,
68                     Box const& box)
69     {
70         return box;
71     }
72 };
73 
74 
75 template<>
76 struct get_ring<polygon_tag>
77 {
78     template<typename Polygon>
applyboost::geometry::detail::overlay::get_ring79     static inline typename ring_return_type<Polygon const>::type const apply(
80                 ring_identifier const& id,
81                 Polygon const& polygon)
82     {
83         BOOST_ASSERT
84             (
85                 id.ring_index >= -1
86                 && id.ring_index < boost::size(interior_rings(polygon))
87             );
88         return id.ring_index < 0
89             ? exterior_ring(polygon)
90             : interior_rings(polygon)[id.ring_index];
91     }
92 };
93 
94 
95 }} // namespace detail::overlay
96 #endif // DOXYGEN_NO_DETAIL
97 
98 
99 }} // namespace boost::geometry
100 
101 
102 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RING_HPP
103