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/algorithms/detail/overlay/segment_identifier.hpp>
22 #include <boost/geometry/algorithms/num_points.hpp>
23 #include <boost/geometry/geometries/concepts/check.hpp>
24 #include <boost/geometry/util/range.hpp>
27 namespace boost { namespace geometry
31 #ifndef DOXYGEN_NO_DETAIL
32 namespace detail { namespace overlay
36 template<typename Tag>
40 // A range of rings (multi-ring but that does not exist)
41 // gets the "void" tag and is dispatched here.
45 template<typename Range>
46 static inline typename boost::range_value<Range>::type const&
47 apply(ring_identifier const& id, Range const& container)
49 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 template <typename Geometry>
117 inline std::size_t segment_count_on_ring(Geometry const& geometry,
118 segment_identifier const& seg_id)
120 typedef typename geometry::tag<Geometry>::type tag;
121 ring_identifier const rid(0, seg_id.multi_index, seg_id.ring_index);
122 // A closed polygon, a triangle of 4 points, including starting point,
123 // contains 3 segments. So handle as if closed and subtract one.
124 return geometry::num_points(detail::overlay::get_ring<tag>::apply(rid, geometry), true) - 1;
127 }} // namespace detail::overlay
128 #endif // DOXYGEN_NO_DETAIL
131 }} // namespace boost::geometry
134 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RING_HPP