Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@16
|
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
Chris@16
|
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
Chris@16
|
6
|
Chris@16
|
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
9
|
Chris@16
|
10 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
12 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
13
|
Chris@16
|
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_ENVELOPE_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_ALGORITHMS_ENVELOPE_HPP
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/range.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/numeric/conversion/cast.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #include <boost/geometry/algorithms/assign.hpp>
|
Chris@16
|
22 #include <boost/geometry/algorithms/expand.hpp>
|
Chris@16
|
23 #include <boost/geometry/algorithms/not_implemented.hpp>
|
Chris@16
|
24 #include <boost/geometry/core/cs.hpp>
|
Chris@16
|
25 #include <boost/geometry/core/exterior_ring.hpp>
|
Chris@16
|
26 #include <boost/geometry/geometries/concepts/check.hpp>
|
Chris@16
|
27
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost { namespace geometry
|
Chris@16
|
30 {
|
Chris@16
|
31
|
Chris@16
|
32 #ifndef DOXYGEN_NO_DETAIL
|
Chris@16
|
33 namespace detail { namespace envelope
|
Chris@16
|
34 {
|
Chris@16
|
35
|
Chris@16
|
36
|
Chris@16
|
37 /// Calculate envelope of an 2D or 3D segment
|
Chris@16
|
38 struct envelope_expand_one
|
Chris@16
|
39 {
|
Chris@16
|
40 template<typename Geometry, typename Box>
|
Chris@16
|
41 static inline void apply(Geometry const& geometry, Box& mbr)
|
Chris@16
|
42 {
|
Chris@16
|
43 assign_inverse(mbr);
|
Chris@16
|
44 geometry::expand(mbr, geometry);
|
Chris@16
|
45 }
|
Chris@16
|
46 };
|
Chris@16
|
47
|
Chris@16
|
48
|
Chris@16
|
49 /// Iterate through range (also used in multi*)
|
Chris@16
|
50 template<typename Range, typename Box>
|
Chris@16
|
51 inline void envelope_range_additional(Range const& range, Box& mbr)
|
Chris@16
|
52 {
|
Chris@16
|
53 typedef typename boost::range_iterator<Range const>::type iterator_type;
|
Chris@16
|
54
|
Chris@16
|
55 for (iterator_type it = boost::begin(range);
|
Chris@16
|
56 it != boost::end(range);
|
Chris@16
|
57 ++it)
|
Chris@16
|
58 {
|
Chris@16
|
59 geometry::expand(mbr, *it);
|
Chris@16
|
60 }
|
Chris@16
|
61 }
|
Chris@16
|
62
|
Chris@16
|
63
|
Chris@16
|
64
|
Chris@16
|
65 /// Generic range dispatching struct
|
Chris@16
|
66 struct envelope_range
|
Chris@16
|
67 {
|
Chris@16
|
68 /// Calculate envelope of range using a strategy
|
Chris@16
|
69 template <typename Range, typename Box>
|
Chris@16
|
70 static inline void apply(Range const& range, Box& mbr)
|
Chris@16
|
71 {
|
Chris@16
|
72 assign_inverse(mbr);
|
Chris@16
|
73 envelope_range_additional(range, mbr);
|
Chris@16
|
74 }
|
Chris@16
|
75 };
|
Chris@16
|
76
|
Chris@16
|
77 }} // namespace detail::envelope
|
Chris@16
|
78 #endif // DOXYGEN_NO_DETAIL
|
Chris@16
|
79
|
Chris@16
|
80 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@16
|
81 namespace dispatch
|
Chris@16
|
82 {
|
Chris@16
|
83
|
Chris@16
|
84
|
Chris@16
|
85 template
|
Chris@16
|
86 <
|
Chris@16
|
87 typename Geometry,
|
Chris@16
|
88 typename Tag = typename tag<Geometry>::type
|
Chris@16
|
89 >
|
Chris@16
|
90 struct envelope: not_implemented<Tag>
|
Chris@16
|
91 {};
|
Chris@16
|
92
|
Chris@16
|
93
|
Chris@16
|
94 template <typename Point>
|
Chris@16
|
95 struct envelope<Point, point_tag>
|
Chris@16
|
96 : detail::envelope::envelope_expand_one
|
Chris@16
|
97 {};
|
Chris@16
|
98
|
Chris@16
|
99
|
Chris@16
|
100 template <typename Box>
|
Chris@16
|
101 struct envelope<Box, box_tag>
|
Chris@16
|
102 : detail::envelope::envelope_expand_one
|
Chris@16
|
103 {};
|
Chris@16
|
104
|
Chris@16
|
105
|
Chris@16
|
106 template <typename Segment>
|
Chris@16
|
107 struct envelope<Segment, segment_tag>
|
Chris@16
|
108 : detail::envelope::envelope_expand_one
|
Chris@16
|
109 {};
|
Chris@16
|
110
|
Chris@16
|
111
|
Chris@16
|
112 template <typename Linestring>
|
Chris@16
|
113 struct envelope<Linestring, linestring_tag>
|
Chris@16
|
114 : detail::envelope::envelope_range
|
Chris@16
|
115 {};
|
Chris@16
|
116
|
Chris@16
|
117
|
Chris@16
|
118 template <typename Ring>
|
Chris@16
|
119 struct envelope<Ring, ring_tag>
|
Chris@16
|
120 : detail::envelope::envelope_range
|
Chris@16
|
121 {};
|
Chris@16
|
122
|
Chris@16
|
123
|
Chris@16
|
124 template <typename Polygon>
|
Chris@16
|
125 struct envelope<Polygon, polygon_tag>
|
Chris@16
|
126 : detail::envelope::envelope_range
|
Chris@16
|
127 {
|
Chris@16
|
128 template <typename Box>
|
Chris@16
|
129 static inline void apply(Polygon const& poly, Box& mbr)
|
Chris@16
|
130 {
|
Chris@16
|
131 // For polygon, inspecting outer ring is sufficient
|
Chris@16
|
132 detail::envelope::envelope_range::apply(exterior_ring(poly), mbr);
|
Chris@16
|
133 }
|
Chris@16
|
134
|
Chris@16
|
135 };
|
Chris@16
|
136
|
Chris@16
|
137
|
Chris@16
|
138 } // namespace dispatch
|
Chris@16
|
139 #endif
|
Chris@16
|
140
|
Chris@16
|
141
|
Chris@16
|
142 /*!
|
Chris@16
|
143 \brief \brief_calc{envelope}
|
Chris@16
|
144 \ingroup envelope
|
Chris@16
|
145 \details \details_calc{envelope,\det_envelope}.
|
Chris@16
|
146 \tparam Geometry \tparam_geometry
|
Chris@16
|
147 \tparam Box \tparam_box
|
Chris@16
|
148 \param geometry \param_geometry
|
Chris@16
|
149 \param mbr \param_box \param_set{envelope}
|
Chris@16
|
150
|
Chris@16
|
151 \qbk{[include reference/algorithms/envelope.qbk]}
|
Chris@16
|
152 \qbk{
|
Chris@16
|
153 [heading Example]
|
Chris@16
|
154 [envelope] [envelope_output]
|
Chris@16
|
155 }
|
Chris@16
|
156 */
|
Chris@16
|
157 template<typename Geometry, typename Box>
|
Chris@16
|
158 inline void envelope(Geometry const& geometry, Box& mbr)
|
Chris@16
|
159 {
|
Chris@16
|
160 concept::check<Geometry const>();
|
Chris@16
|
161 concept::check<Box>();
|
Chris@16
|
162
|
Chris@16
|
163 dispatch::envelope<Geometry>::apply(geometry, mbr);
|
Chris@16
|
164 }
|
Chris@16
|
165
|
Chris@16
|
166
|
Chris@16
|
167 /*!
|
Chris@16
|
168 \brief \brief_calc{envelope}
|
Chris@16
|
169 \ingroup envelope
|
Chris@16
|
170 \details \details_calc{return_envelope,\det_envelope}. \details_return{envelope}
|
Chris@16
|
171 \tparam Box \tparam_box
|
Chris@16
|
172 \tparam Geometry \tparam_geometry
|
Chris@16
|
173 \param geometry \param_geometry
|
Chris@16
|
174 \return \return_calc{envelope}
|
Chris@16
|
175
|
Chris@16
|
176 \qbk{[include reference/algorithms/envelope.qbk]}
|
Chris@16
|
177 \qbk{
|
Chris@16
|
178 [heading Example]
|
Chris@16
|
179 [return_envelope] [return_envelope_output]
|
Chris@16
|
180 }
|
Chris@16
|
181 */
|
Chris@16
|
182 template<typename Box, typename Geometry>
|
Chris@16
|
183 inline Box return_envelope(Geometry const& geometry)
|
Chris@16
|
184 {
|
Chris@16
|
185 concept::check<Geometry const>();
|
Chris@16
|
186 concept::check<Box>();
|
Chris@16
|
187
|
Chris@16
|
188 Box mbr;
|
Chris@16
|
189 dispatch::envelope<Geometry>::apply(geometry, mbr);
|
Chris@16
|
190 return mbr;
|
Chris@16
|
191 }
|
Chris@16
|
192
|
Chris@16
|
193 }} // namespace boost::geometry
|
Chris@16
|
194
|
Chris@16
|
195 #endif // BOOST_GEOMETRY_ALGORITHMS_ENVELOPE_HPP
|