1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 // This file was modified by Oracle on 2013, 2014.
11 // Modifications copyright (c) 2013, 2014, Oracle and/or its affiliates.
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_RANGE_BY_SECTION_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_RANGE_BY_SECTION_HPP
22 #include <boost/mpl/assert.hpp>
23 #include <boost/range.hpp>
25 #include <boost/geometry/core/access.hpp>
26 #include <boost/geometry/core/assert.hpp>
27 #include <boost/geometry/core/closure.hpp>
28 #include <boost/geometry/core/exterior_ring.hpp>
29 #include <boost/geometry/core/interior_rings.hpp>
30 #include <boost/geometry/core/ring_type.hpp>
31 #include <boost/geometry/core/tags.hpp>
32 #include <boost/geometry/geometries/concepts/check.hpp>
33 #include <boost/geometry/util/range.hpp>
36 namespace boost { namespace geometry
39 #ifndef DOXYGEN_NO_DETAIL
40 namespace detail { namespace section
44 template <typename Range, typename Section>
45 struct full_section_range
47 static inline Range const& apply(Range const& range, Section const& )
54 template <typename Polygon, typename Section>
55 struct full_section_polygon
57 static inline typename ring_return_type<Polygon const>::type apply(Polygon const& polygon, Section const& section)
59 return section.ring_id.ring_index < 0
60 ? geometry::exterior_ring(polygon)
61 : range::at(geometry::interior_rings(polygon),
62 static_cast<std::size_t>(section.ring_id.ring_index));
69 typename MultiGeometry,
73 struct full_section_multi
75 static inline typename ring_return_type<MultiGeometry const>::type apply(
76 MultiGeometry const& multi, Section const& section)
78 typedef typename boost::range_size<MultiGeometry>::type size_type;
82 section.ring_id.multi_index >= 0
83 && size_type(section.ring_id.multi_index) < boost::size(multi)
86 return Policy::apply(range::at(multi, size_type(section.ring_id.multi_index)), section);
91 }} // namespace detail::section
95 #ifndef DOXYGEN_NO_DISPATCH
106 struct range_by_section
110 false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
116 template <typename LineString, typename Section>
117 struct range_by_section<linestring_tag, LineString, Section>
118 : detail::section::full_section_range<LineString, Section>
122 template <typename Ring, typename Section>
123 struct range_by_section<ring_tag, Ring, Section>
124 : detail::section::full_section_range<Ring, Section>
128 template <typename Polygon, typename Section>
129 struct range_by_section<polygon_tag, Polygon, Section>
130 : detail::section::full_section_polygon<Polygon, Section>
134 template <typename MultiPolygon, typename Section>
135 struct range_by_section<multi_polygon_tag, MultiPolygon, Section>
136 : detail::section::full_section_multi
140 detail::section::full_section_polygon
142 typename boost::range_value<MultiPolygon>::type,
148 template <typename MultiLinestring, typename Section>
149 struct range_by_section<multi_linestring_tag, MultiLinestring, Section>
150 : detail::section::full_section_multi
154 detail::section::full_section_range
156 typename boost::range_value<MultiLinestring>::type,
163 } // namespace dispatch
168 \brief Get full ring (exterior, one of interiors, one from multi)
169 indicated by the specified section
170 \ingroup sectionalize
171 \tparam Geometry type
172 \tparam Section type of section to get from
173 \param geometry geometry to take section of
174 \param section structure with section
176 template <typename Geometry, typename Section>
177 inline typename ring_return_type<Geometry const>::type
178 range_by_section(Geometry const& geometry, Section const& section)
180 concepts::check<Geometry const>();
182 return dispatch::range_by_section
184 typename tag<Geometry>::type,
187 >::apply(geometry, section);
191 }} // namespace boost::geometry
193 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_RANGE_BY_SECTION_HPP