Chris@102
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@102
|
2
|
Chris@102
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@102
|
4
|
Chris@102
|
5 // This file was modified by Oracle on 2013, 2014.
|
Chris@102
|
6 // Modifications copyright (c) 2013-2014, Oracle and/or its affiliates.
|
Chris@102
|
7
|
Chris@102
|
8 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@102
|
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
10 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
11
|
Chris@102
|
12 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
Chris@102
|
13
|
Chris@102
|
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SUB_RANGE_HPP
|
Chris@102
|
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SUB_RANGE_HPP
|
Chris@102
|
16
|
Chris@102
|
17 #include <boost/geometry/util/range.hpp>
|
Chris@102
|
18
|
Chris@102
|
19 namespace boost { namespace geometry {
|
Chris@102
|
20
|
Chris@102
|
21 #ifndef DOXYGEN_NO_DETAIL
|
Chris@102
|
22
|
Chris@102
|
23 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@102
|
24 namespace detail_dispatch {
|
Chris@102
|
25
|
Chris@102
|
26 template <typename Geometry,
|
Chris@102
|
27 typename Tag = typename geometry::tag<Geometry>::type,
|
Chris@102
|
28 bool IsMulti = boost::is_base_of<multi_tag, Tag>::value>
|
Chris@102
|
29 struct sub_range : not_implemented<Tag>
|
Chris@102
|
30 {};
|
Chris@102
|
31
|
Chris@102
|
32 template <typename Geometry, typename Tag>
|
Chris@102
|
33 struct sub_range<Geometry, Tag, false>
|
Chris@102
|
34 {
|
Chris@102
|
35 typedef Geometry & return_type;
|
Chris@102
|
36
|
Chris@102
|
37 template <typename Id> static inline
|
Chris@102
|
38 return_type apply(Geometry & geometry, Id const&)
|
Chris@102
|
39 {
|
Chris@102
|
40 return geometry;
|
Chris@102
|
41 }
|
Chris@102
|
42 };
|
Chris@102
|
43
|
Chris@102
|
44 template <typename Geometry>
|
Chris@102
|
45 struct sub_range<Geometry, polygon_tag, false>
|
Chris@102
|
46 {
|
Chris@102
|
47 typedef typename geometry::ring_return_type<Geometry>::type return_type;
|
Chris@102
|
48
|
Chris@102
|
49 template <typename Id> static inline
|
Chris@102
|
50 return_type apply(Geometry & geometry, Id const& id)
|
Chris@102
|
51 {
|
Chris@102
|
52 if ( id.ring_index < 0 )
|
Chris@102
|
53 {
|
Chris@102
|
54 return geometry::exterior_ring(geometry);
|
Chris@102
|
55 }
|
Chris@102
|
56 else
|
Chris@102
|
57 {
|
Chris@102
|
58 typedef typename boost::range_size
|
Chris@102
|
59 <
|
Chris@102
|
60 typename geometry::interior_type<Geometry>::type
|
Chris@102
|
61 >::type size_type;
|
Chris@102
|
62 size_type const ri = static_cast<size_type>(id.ring_index);
|
Chris@102
|
63 return range::at(geometry::interior_rings(geometry), ri);
|
Chris@102
|
64 }
|
Chris@102
|
65 }
|
Chris@102
|
66 };
|
Chris@102
|
67
|
Chris@102
|
68 template <typename Geometry, typename Tag>
|
Chris@102
|
69 struct sub_range<Geometry, Tag, true>
|
Chris@102
|
70 {
|
Chris@102
|
71 typedef typename boost::range_value<Geometry>::type value_type;
|
Chris@102
|
72 typedef typename boost::mpl::if_c
|
Chris@102
|
73 <
|
Chris@102
|
74 boost::is_const<Geometry>::value,
|
Chris@102
|
75 typename boost::add_const<value_type>::type,
|
Chris@102
|
76 value_type
|
Chris@102
|
77 >::type sub_type;
|
Chris@102
|
78
|
Chris@102
|
79 typedef detail_dispatch::sub_range<sub_type> sub_sub_range;
|
Chris@102
|
80
|
Chris@102
|
81 // TODO: shouldn't it be return_type?
|
Chris@102
|
82 typedef typename sub_sub_range::return_type return_type;
|
Chris@102
|
83
|
Chris@102
|
84 template <typename Id> static inline
|
Chris@102
|
85 return_type apply(Geometry & geometry, Id const& id)
|
Chris@102
|
86 {
|
Chris@102
|
87 BOOST_ASSERT(0 <= id.multi_index);
|
Chris@102
|
88 typedef typename boost::range_size<Geometry>::type size_type;
|
Chris@102
|
89 size_type const mi = static_cast<size_type>(id.multi_index);
|
Chris@102
|
90 return sub_sub_range::apply(range::at(geometry, mi), id);
|
Chris@102
|
91 }
|
Chris@102
|
92 };
|
Chris@102
|
93
|
Chris@102
|
94 } // namespace detail_dispatch
|
Chris@102
|
95 #endif // DOXYGEN_NO_DISPATCH
|
Chris@102
|
96
|
Chris@102
|
97 namespace detail {
|
Chris@102
|
98
|
Chris@102
|
99 template <typename Geometry>
|
Chris@102
|
100 struct sub_range_return_type
|
Chris@102
|
101 {
|
Chris@102
|
102 typedef typename detail_dispatch::sub_range<Geometry>::return_type type;
|
Chris@102
|
103 };
|
Chris@102
|
104
|
Chris@102
|
105 // This function also works for geometry::segment_identifier
|
Chris@102
|
106
|
Chris@102
|
107 template <typename Geometry, typename Id> inline
|
Chris@102
|
108 typename sub_range_return_type<Geometry>::type
|
Chris@102
|
109 sub_range(Geometry & geometry, Id const& id)
|
Chris@102
|
110 {
|
Chris@102
|
111 return detail_dispatch::sub_range<Geometry>::apply(geometry, id);
|
Chris@102
|
112 }
|
Chris@102
|
113
|
Chris@102
|
114 } // namespace detail
|
Chris@102
|
115 #endif // DOXYGEN_NO_DETAIL
|
Chris@102
|
116
|
Chris@102
|
117 }} // namespace boost::geometry
|
Chris@102
|
118
|
Chris@102
|
119 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SUB_RANGE_HPP
|