1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
6
7 // This file was modified by Oracle on 2015, 2016, 2017, 2018.
8 // Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
9
10 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
11 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
12 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16
17 // Distributed under the Boost Software License, Version 1.0.
18 // (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
20
21 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERFACE_HPP
22 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERFACE_HPP
23
24
25 #include <boost/variant/apply_visitor.hpp>
26 #include <boost/variant/static_visitor.hpp>
27 #include <boost/variant/variant_fwd.hpp>
28
29 #include <boost/geometry/algorithms/dispatch/envelope.hpp>
30
31 #include <boost/geometry/core/coordinate_system.hpp>
32 #include <boost/geometry/core/tag.hpp>
33 #include <boost/geometry/core/tags.hpp>
34
35 #include <boost/geometry/geometries/concepts/check.hpp>
36
37 #include <boost/geometry/strategies/default_strategy.hpp>
38 #include <boost/geometry/strategies/envelope.hpp>
39
40 #include <boost/geometry/util/select_most_precise.hpp>
41
42
43 namespace boost { namespace geometry
44 {
45
46 namespace resolve_strategy
47 {
48
49 template <typename Geometry>
50 struct envelope
51 {
52 template <typename Box, typename Strategy>
applyboost::geometry::resolve_strategy::envelope53 static inline void apply(Geometry const& geometry,
54 Box& box,
55 Strategy const& strategy)
56 {
57 dispatch::envelope<Geometry>::apply(geometry, box, strategy);
58 }
59
60 template <typename Box>
applyboost::geometry::resolve_strategy::envelope61 static inline void apply(Geometry const& geometry,
62 Box& box,
63 default_strategy)
64 {
65 typedef typename strategy::envelope::services::default_strategy
66 <
67 typename tag<Geometry>::type,
68 typename cs_tag<Geometry>::type,
69 typename select_most_precise
70 <
71 typename coordinate_type<Geometry>::type,
72 typename coordinate_type<Box>::type
73 >::type
74 >::type strategy_type;
75
76 dispatch::envelope<Geometry>::apply(geometry, box, strategy_type());
77 }
78 };
79
80 } // namespace resolve_strategy
81
82 namespace resolve_variant
83 {
84
85 template <typename Geometry>
86 struct envelope
87 {
88 template <typename Box, typename Strategy>
applyboost::geometry::resolve_variant::envelope89 static inline void apply(Geometry const& geometry,
90 Box& box,
91 Strategy const& strategy)
92 {
93 concepts::check<Geometry const>();
94 concepts::check<Box>();
95
96 resolve_strategy::envelope<Geometry>::apply(geometry, box, strategy);
97 }
98 };
99
100
101 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
102 struct envelope<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
103 {
104 template <typename Box, typename Strategy>
105 struct visitor: boost::static_visitor<void>
106 {
107 Box& m_box;
108 Strategy const& m_strategy;
109
visitorboost::geometry::resolve_variant::envelope::visitor110 visitor(Box& box, Strategy const& strategy)
111 : m_box(box)
112 , m_strategy(strategy)
113 {}
114
115 template <typename Geometry>
operator ()boost::geometry::resolve_variant::envelope::visitor116 void operator()(Geometry const& geometry) const
117 {
118 envelope<Geometry>::apply(geometry, m_box, m_strategy);
119 }
120 };
121
122 template <typename Box, typename Strategy>
123 static inline void
applyboost::geometry::resolve_variant::envelope124 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
125 Box& box,
126 Strategy const& strategy)
127 {
128 boost::apply_visitor(visitor<Box, Strategy>(box, strategy), geometry);
129 }
130 };
131
132 } // namespace resolve_variant
133
134 /*!
135 \brief \brief_calc{envelope (with strategy)}
136 \ingroup envelope
137 \details \details_calc{envelope,\det_envelope}.
138 \tparam Geometry \tparam_geometry
139 \tparam Box \tparam_box
140 \tparam Strategy \tparam_strategy{Envelope}
141 \param geometry \param_geometry
142 \param mbr \param_box \param_set{envelope}
143 \param strategy \param_strategy{envelope}
144
145 \qbk{distinguish,with strategy}
146 \qbk{[include reference/algorithms/envelope.qbk]}
147 \qbk{
148 [heading Example]
149 [envelope] [envelope_output]
150 }
151 */
152 template<typename Geometry, typename Box, typename Strategy>
envelope(Geometry const & geometry,Box & mbr,Strategy const & strategy)153 inline void envelope(Geometry const& geometry, Box& mbr, Strategy const& strategy)
154 {
155 resolve_variant::envelope<Geometry>::apply(geometry, mbr, strategy);
156 }
157
158 /*!
159 \brief \brief_calc{envelope}
160 \ingroup envelope
161 \details \details_calc{envelope,\det_envelope}.
162 \tparam Geometry \tparam_geometry
163 \tparam Box \tparam_box
164 \param geometry \param_geometry
165 \param mbr \param_box \param_set{envelope}
166
167 \qbk{[include reference/algorithms/envelope.qbk]}
168 \qbk{
169 [heading Example]
170 [envelope] [envelope_output]
171 }
172 */
173 template<typename Geometry, typename Box>
envelope(Geometry const & geometry,Box & mbr)174 inline void envelope(Geometry const& geometry, Box& mbr)
175 {
176 resolve_variant::envelope<Geometry>::apply(geometry, mbr, default_strategy());
177 }
178
179
180 /*!
181 \brief \brief_calc{envelope}
182 \ingroup envelope
183 \details \details_calc{return_envelope,\det_envelope}. \details_return{envelope}
184 \tparam Box \tparam_box
185 \tparam Geometry \tparam_geometry
186 \tparam Strategy \tparam_strategy{Envelope}
187 \param geometry \param_geometry
188 \param strategy \param_strategy{envelope}
189 \return \return_calc{envelope}
190
191 \qbk{distinguish,with strategy}
192 \qbk{[include reference/algorithms/envelope.qbk]}
193 \qbk{
194 [heading Example]
195 [return_envelope] [return_envelope_output]
196 }
197 */
198 template<typename Box, typename Geometry, typename Strategy>
return_envelope(Geometry const & geometry,Strategy const & strategy)199 inline Box return_envelope(Geometry const& geometry, Strategy const& strategy)
200 {
201 Box mbr;
202 resolve_variant::envelope<Geometry>::apply(geometry, mbr, strategy);
203 return mbr;
204 }
205
206 /*!
207 \brief \brief_calc{envelope}
208 \ingroup envelope
209 \details \details_calc{return_envelope,\det_envelope}. \details_return{envelope}
210 \tparam Box \tparam_box
211 \tparam Geometry \tparam_geometry
212 \param geometry \param_geometry
213 \return \return_calc{envelope}
214
215 \qbk{[include reference/algorithms/envelope.qbk]}
216 \qbk{
217 [heading Example]
218 [return_envelope] [return_envelope_output]
219 }
220 */
221 template<typename Box, typename Geometry>
return_envelope(Geometry const & geometry)222 inline Box return_envelope(Geometry const& geometry)
223 {
224 Box mbr;
225 resolve_variant::envelope<Geometry>::apply(geometry, mbr, default_strategy());
226 return mbr;
227 }
228
229 }} // namespace boost::geometry
230
231 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERFACE_HPP
232