Project revived from Feb2017
[EroSomnia.git] / deps / boost_1_63_0 / boost / geometry / algorithms / detail / envelope / range.hpp
blob63b518114b864d28bfdba23fdb2e5bf3023cdd77
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
7 // This file was modified by Oracle on 2015.
8 // Modifications copyright (c) 2015, Oracle and/or its affiliates.
10 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Distributed under the Boost Software License, Version 1.0.
16 // (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP
22 #include <iterator>
23 #include <vector>
25 #include <boost/range.hpp>
27 #include <boost/geometry/core/coordinate_dimension.hpp>
29 #include <boost/geometry/util/range.hpp>
31 #include <boost/geometry/algorithms/is_empty.hpp>
33 #include <boost/geometry/algorithms/detail/envelope/initialize.hpp>
34 #include <boost/geometry/algorithms/detail/envelope/range_of_boxes.hpp>
36 #include <boost/geometry/algorithms/detail/expand/box.hpp>
37 #include <boost/geometry/algorithms/detail/expand/point.hpp>
38 #include <boost/geometry/algorithms/detail/expand/segment.hpp>
40 #include <boost/geometry/algorithms/dispatch/envelope.hpp>
43 namespace boost { namespace geometry
46 #ifndef DOXYGEN_NO_DETAIL
47 namespace detail { namespace envelope
51 // implementation for simple ranges
52 struct envelope_range
54 template <typename Iterator, typename Box>
55 static inline void apply(Iterator first, Iterator last, Box& mbr)
57 typedef typename std::iterator_traits<Iterator>::value_type value_type;
59 // initialize MBR
60 initialize<Box, 0, dimension<Box>::value>::apply(mbr);
62 Iterator it = first;
63 if (it != last)
65 // initialize box with first element in range
66 dispatch::envelope<value_type>::apply(*it, mbr);
68 // consider now the remaining elements in the range (if any)
69 for (++it; it != last; ++it)
71 dispatch::expand<Box, value_type>::apply(mbr, *it);
76 template <typename Range, typename Box>
77 static inline void apply(Range const& range, Box& mbr)
79 return apply(boost::begin(range), boost::end(range), mbr);
84 // implementation for multi-ranges
85 template <typename EnvelopePolicy>
86 struct envelope_multi_range
88 template <typename MultiRange, typename Box>
89 static inline void apply(MultiRange const& multirange, Box& mbr)
91 typedef typename boost::range_iterator
93 MultiRange const
94 >::type iterator_type;
96 bool initialized = false;
97 for (iterator_type it = boost::begin(multirange);
98 it != boost::end(multirange);
99 ++it)
101 if (! geometry::is_empty(*it))
103 if (initialized)
105 Box helper_mbr;
106 EnvelopePolicy::apply(*it, helper_mbr);
108 dispatch::expand<Box, Box>::apply(mbr, helper_mbr);
110 else
112 // compute the initial envelope
113 EnvelopePolicy::apply(*it, mbr);
114 initialized = true;
119 if (! initialized)
121 // if not already initialized, initialize MBR
122 initialize<Box, 0, dimension<Box>::value>::apply(mbr);
128 // implementation for multi-range on a spheroid (longitude is periodic)
129 template <typename EnvelopePolicy>
130 struct envelope_multi_range_on_spheroid
132 template <typename MultiRange, typename Box>
133 static inline void apply(MultiRange const& multirange, Box& mbr)
135 typedef typename boost::range_iterator
137 MultiRange const
138 >::type iterator_type;
140 // due to the periodicity of longitudes we need to compute the boxes
141 // of all the single geometries and keep them in a container
142 std::vector<Box> boxes;
143 for (iterator_type it = boost::begin(multirange);
144 it != boost::end(multirange);
145 ++it)
147 if (! geometry::is_empty(*it))
149 Box helper_box;
150 EnvelopePolicy::apply(*it, helper_box);
151 boxes.push_back(helper_box);
155 // now we need to compute the envelope of the range of boxes
156 // (cannot be done in an incremental fashion as in the
157 // Cartesian coordinate system)
158 // if all single geometries are empty no boxes have been found
159 // and the MBR is simply initialized
160 if (! boxes.empty())
162 envelope_range_of_boxes::apply(boxes, mbr);
164 else
166 initialize<Box, 0, dimension<Box>::value>::apply(mbr);
173 }} // namespace detail::envelope
174 #endif // DOXYGEN_NO_DETAIL
177 }} // namespace boost::geometry
179 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP