Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@101
|
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@101
|
4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
|
Chris@101
|
5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
|
Chris@101
|
6
|
Chris@101
|
7 // This file was modified by Oracle on 2014.
|
Chris@101
|
8 // Modifications copyright (c) 2014, Oracle and/or its affiliates.
|
Chris@101
|
9
|
Chris@101
|
10 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
Chris@16
|
11
|
Chris@16
|
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
14
|
Chris@16
|
15 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
17 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
18
|
Chris@16
|
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_PERIMETER_HPP
|
Chris@16
|
20 #define BOOST_GEOMETRY_ALGORITHMS_PERIMETER_HPP
|
Chris@16
|
21
|
Chris@101
|
22 #include <boost/range/metafunctions.hpp>
|
Chris@16
|
23
|
Chris@101
|
24 #include <boost/variant/apply_visitor.hpp>
|
Chris@101
|
25 #include <boost/variant/static_visitor.hpp>
|
Chris@101
|
26 #include <boost/variant/variant_fwd.hpp>
|
Chris@101
|
27
|
Chris@16
|
28 #include <boost/geometry/algorithms/length.hpp>
|
Chris@16
|
29 #include <boost/geometry/algorithms/detail/calculate_null.hpp>
|
Chris@16
|
30 #include <boost/geometry/algorithms/detail/calculate_sum.hpp>
|
Chris@101
|
31 #include <boost/geometry/algorithms/detail/multi_sum.hpp>
|
Chris@16
|
32 // #include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
|
Chris@101
|
33 #include <boost/geometry/core/cs.hpp>
|
Chris@101
|
34 #include <boost/geometry/core/closure.hpp>
|
Chris@101
|
35 #include <boost/geometry/core/tags.hpp>
|
Chris@101
|
36 #include <boost/geometry/geometries/concepts/check.hpp>
|
Chris@101
|
37 #include <boost/geometry/strategies/default_length_result.hpp>
|
Chris@101
|
38 #include <boost/geometry/strategies/default_strategy.hpp>
|
Chris@16
|
39
|
Chris@16
|
40 namespace boost { namespace geometry
|
Chris@16
|
41 {
|
Chris@16
|
42
|
Chris@16
|
43 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@16
|
44 namespace dispatch
|
Chris@16
|
45 {
|
Chris@16
|
46
|
Chris@16
|
47 // Default perimeter is 0.0, specializations implement calculated values
|
Chris@16
|
48 template <typename Geometry, typename Tag = typename tag<Geometry>::type>
|
Chris@16
|
49 struct perimeter : detail::calculate_null
|
Chris@16
|
50 {
|
Chris@16
|
51 typedef typename default_length_result<Geometry>::type return_type;
|
Chris@16
|
52
|
Chris@16
|
53 template <typename Strategy>
|
Chris@16
|
54 static inline return_type apply(Geometry const& geometry, Strategy const& strategy)
|
Chris@16
|
55 {
|
Chris@16
|
56 return calculate_null::apply<return_type>(geometry, strategy);
|
Chris@16
|
57 }
|
Chris@16
|
58 };
|
Chris@16
|
59
|
Chris@16
|
60 template <typename Geometry>
|
Chris@16
|
61 struct perimeter<Geometry, ring_tag>
|
Chris@16
|
62 : detail::length::range_length
|
Chris@16
|
63 <
|
Chris@16
|
64 Geometry,
|
Chris@16
|
65 closure<Geometry>::value
|
Chris@16
|
66 >
|
Chris@16
|
67 {};
|
Chris@16
|
68
|
Chris@16
|
69 template <typename Polygon>
|
Chris@16
|
70 struct perimeter<Polygon, polygon_tag> : detail::calculate_polygon_sum
|
Chris@16
|
71 {
|
Chris@16
|
72 typedef typename default_length_result<Polygon>::type return_type;
|
Chris@16
|
73 typedef detail::length::range_length
|
Chris@16
|
74 <
|
Chris@16
|
75 typename ring_type<Polygon>::type,
|
Chris@16
|
76 closure<Polygon>::value
|
Chris@16
|
77 > policy;
|
Chris@16
|
78
|
Chris@16
|
79 template <typename Strategy>
|
Chris@16
|
80 static inline return_type apply(Polygon const& polygon, Strategy const& strategy)
|
Chris@16
|
81 {
|
Chris@16
|
82 return calculate_polygon_sum::apply<return_type, policy>(polygon, strategy);
|
Chris@16
|
83 }
|
Chris@16
|
84 };
|
Chris@16
|
85
|
Chris@101
|
86 template <typename MultiPolygon>
|
Chris@101
|
87 struct perimeter<MultiPolygon, multi_polygon_tag> : detail::multi_sum
|
Chris@101
|
88 {
|
Chris@101
|
89 typedef typename default_length_result<MultiPolygon>::type return_type;
|
Chris@101
|
90
|
Chris@101
|
91 template <typename Strategy>
|
Chris@101
|
92 static inline return_type apply(MultiPolygon const& multi, Strategy const& strategy)
|
Chris@101
|
93 {
|
Chris@101
|
94 return multi_sum::apply
|
Chris@101
|
95 <
|
Chris@101
|
96 return_type,
|
Chris@101
|
97 perimeter<typename boost::range_value<MultiPolygon>::type>
|
Chris@101
|
98 >(multi, strategy);
|
Chris@101
|
99 }
|
Chris@101
|
100 };
|
Chris@101
|
101
|
Chris@16
|
102
|
Chris@16
|
103 // box,n-sphere: to be implemented
|
Chris@16
|
104
|
Chris@16
|
105 } // namespace dispatch
|
Chris@16
|
106 #endif // DOXYGEN_NO_DISPATCH
|
Chris@16
|
107
|
Chris@16
|
108
|
Chris@101
|
109 namespace resolve_strategy {
|
Chris@101
|
110
|
Chris@101
|
111 struct perimeter
|
Chris@101
|
112 {
|
Chris@101
|
113 template <typename Geometry, typename Strategy>
|
Chris@101
|
114 static inline typename default_length_result<Geometry>::type
|
Chris@101
|
115 apply(Geometry const& geometry, Strategy const& strategy)
|
Chris@101
|
116 {
|
Chris@101
|
117 return dispatch::perimeter<Geometry>::apply(geometry, strategy);
|
Chris@101
|
118 }
|
Chris@101
|
119
|
Chris@101
|
120 template <typename Geometry>
|
Chris@101
|
121 static inline typename default_length_result<Geometry>::type
|
Chris@101
|
122 apply(Geometry const& geometry, default_strategy)
|
Chris@101
|
123 {
|
Chris@101
|
124 typedef typename strategy::distance::services::default_strategy
|
Chris@101
|
125 <
|
Chris@101
|
126 point_tag, point_tag, typename point_type<Geometry>::type
|
Chris@101
|
127 >::type strategy_type;
|
Chris@101
|
128
|
Chris@101
|
129 return dispatch::perimeter<Geometry>::apply(geometry, strategy_type());
|
Chris@101
|
130 }
|
Chris@101
|
131 };
|
Chris@101
|
132
|
Chris@101
|
133 } // namespace resolve_strategy
|
Chris@101
|
134
|
Chris@101
|
135
|
Chris@101
|
136 namespace resolve_variant {
|
Chris@101
|
137
|
Chris@101
|
138 template <typename Geometry>
|
Chris@101
|
139 struct perimeter
|
Chris@101
|
140 {
|
Chris@101
|
141 template <typename Strategy>
|
Chris@101
|
142 static inline typename default_length_result<Geometry>::type
|
Chris@101
|
143 apply(Geometry const& geometry, Strategy const& strategy)
|
Chris@101
|
144 {
|
Chris@101
|
145 concept::check<Geometry const>();
|
Chris@101
|
146 return resolve_strategy::perimeter::apply(geometry, strategy);
|
Chris@101
|
147 }
|
Chris@101
|
148 };
|
Chris@101
|
149
|
Chris@101
|
150 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
|
Chris@101
|
151 struct perimeter<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
|
Chris@101
|
152 {
|
Chris@101
|
153 typedef typename default_length_result
|
Chris@101
|
154 <
|
Chris@101
|
155 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>
|
Chris@101
|
156 >::type result_type;
|
Chris@101
|
157
|
Chris@101
|
158 template <typename Strategy>
|
Chris@101
|
159 struct visitor: boost::static_visitor<result_type>
|
Chris@101
|
160 {
|
Chris@101
|
161 Strategy const& m_strategy;
|
Chris@101
|
162
|
Chris@101
|
163 visitor(Strategy const& strategy): m_strategy(strategy) {}
|
Chris@101
|
164
|
Chris@101
|
165 template <typename Geometry>
|
Chris@101
|
166 typename default_length_result<Geometry>::type
|
Chris@101
|
167 operator()(Geometry const& geometry) const
|
Chris@101
|
168 {
|
Chris@101
|
169 return perimeter<Geometry>::apply(geometry, m_strategy);
|
Chris@101
|
170 }
|
Chris@101
|
171 };
|
Chris@101
|
172
|
Chris@101
|
173 template <typename Strategy>
|
Chris@101
|
174 static inline result_type
|
Chris@101
|
175 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
|
Chris@101
|
176 Strategy const& strategy)
|
Chris@101
|
177 {
|
Chris@101
|
178 return boost::apply_visitor(visitor<Strategy>(strategy), geometry);
|
Chris@101
|
179 }
|
Chris@101
|
180 };
|
Chris@101
|
181
|
Chris@101
|
182 } // namespace resolve_variant
|
Chris@101
|
183
|
Chris@101
|
184
|
Chris@16
|
185 /*!
|
Chris@16
|
186 \brief \brief_calc{perimeter}
|
Chris@16
|
187 \ingroup perimeter
|
Chris@16
|
188 \details The function perimeter returns the perimeter of a geometry,
|
Chris@16
|
189 using the default distance-calculation-strategy
|
Chris@16
|
190 \tparam Geometry \tparam_geometry
|
Chris@16
|
191 \param geometry \param_geometry
|
Chris@16
|
192 \return \return_calc{perimeter}
|
Chris@16
|
193
|
Chris@16
|
194 \qbk{[include reference/algorithms/perimeter.qbk]}
|
Chris@16
|
195 */
|
Chris@16
|
196 template<typename Geometry>
|
Chris@16
|
197 inline typename default_length_result<Geometry>::type perimeter(
|
Chris@16
|
198 Geometry const& geometry)
|
Chris@16
|
199 {
|
Chris@16
|
200 // detail::throw_on_empty_input(geometry);
|
Chris@101
|
201 return resolve_variant::perimeter<Geometry>::apply(geometry, default_strategy());
|
Chris@16
|
202 }
|
Chris@16
|
203
|
Chris@16
|
204 /*!
|
Chris@16
|
205 \brief \brief_calc{perimeter} \brief_strategy
|
Chris@16
|
206 \ingroup perimeter
|
Chris@16
|
207 \details The function perimeter returns the perimeter of a geometry,
|
Chris@16
|
208 using specified strategy
|
Chris@16
|
209 \tparam Geometry \tparam_geometry
|
Chris@16
|
210 \tparam Strategy \tparam_strategy{distance}
|
Chris@16
|
211 \param geometry \param_geometry
|
Chris@16
|
212 \param strategy strategy to be used for distance calculations.
|
Chris@16
|
213 \return \return_calc{perimeter}
|
Chris@16
|
214
|
Chris@16
|
215 \qbk{distinguish,with strategy}
|
Chris@16
|
216 \qbk{[include reference/algorithms/perimeter.qbk]}
|
Chris@16
|
217 */
|
Chris@16
|
218 template<typename Geometry, typename Strategy>
|
Chris@16
|
219 inline typename default_length_result<Geometry>::type perimeter(
|
Chris@16
|
220 Geometry const& geometry, Strategy const& strategy)
|
Chris@16
|
221 {
|
Chris@16
|
222 // detail::throw_on_empty_input(geometry);
|
Chris@101
|
223 return resolve_variant::perimeter<Geometry>::apply(geometry, strategy);
|
Chris@16
|
224 }
|
Chris@16
|
225
|
Chris@16
|
226 }} // namespace boost::geometry
|
Chris@16
|
227
|
Chris@16
|
228 #endif // BOOST_GEOMETRY_ALGORITHMS_PERIMETER_HPP
|
Chris@16
|
229
|