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, 2016.
8 // Modifications copyright (c) 2015-2016, Oracle and/or its affiliates.
10 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
11 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16 // Distributed under the Boost Software License, Version 1.0.
17 // (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
20 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP
21 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP
26 #include <boost/range.hpp>
28 #include <boost/geometry/core/coordinate_dimension.hpp>
30 #include <boost/geometry/util/range.hpp>
32 #include <boost/geometry/algorithms/is_empty.hpp>
34 #include <boost/geometry/algorithms/detail/envelope/initialize.hpp>
35 #include <boost/geometry/algorithms/detail/envelope/range_of_boxes.hpp>
37 #include <boost/geometry/algorithms/detail/expand/box.hpp>
38 #include <boost/geometry/algorithms/detail/expand/point.hpp>
39 #include <boost/geometry/algorithms/detail/expand/segment.hpp>
41 #include <boost/geometry/algorithms/dispatch/envelope.hpp>
44 namespace boost { namespace geometry
47 #ifndef DOXYGEN_NO_DETAIL
48 namespace detail { namespace envelope
52 // implementation for simple ranges
55 template <typename Iterator, typename Box, typename Strategy>
56 static inline void apply(Iterator first,
59 Strategy const& strategy)
61 typedef typename std::iterator_traits<Iterator>::value_type value_type;
64 initialize<Box, 0, dimension<Box>::value>::apply(mbr);
69 // initialize box with first element in range
70 dispatch::envelope<value_type>::apply(*it, mbr, strategy);
72 // consider now the remaining elements in the range (if any)
73 for (++it; it != last; ++it)
75 dispatch::expand<Box, value_type>::apply(mbr, *it, strategy);
80 template <typename Range, typename Box, typename Strategy>
81 static inline void apply(Range const& range, Box& mbr, Strategy const& strategy)
83 return apply(boost::begin(range), boost::end(range), mbr, strategy);
88 // implementation for multi-ranges
89 template <typename EnvelopePolicy>
90 struct envelope_multi_range
92 template <typename MultiRange, typename Box, typename Strategy>
93 static inline void apply(MultiRange const& multirange,
95 Strategy const& strategy)
97 typedef typename boost::range_iterator
100 >::type iterator_type;
102 bool initialized = false;
103 for (iterator_type it = boost::begin(multirange);
104 it != boost::end(multirange);
107 if (! geometry::is_empty(*it))
112 EnvelopePolicy::apply(*it, helper_mbr, strategy);
114 dispatch::expand<Box, Box>::apply(mbr, helper_mbr, strategy);
118 // compute the initial envelope
119 EnvelopePolicy::apply(*it, mbr, strategy);
127 // if not already initialized, initialize MBR
128 initialize<Box, 0, dimension<Box>::value>::apply(mbr);
134 // implementation for multi-range on a spheroid (longitude is periodic)
135 template <typename EnvelopePolicy>
136 struct envelope_multi_range_on_spheroid
138 template <typename MultiRange, typename Box, typename Strategy>
139 static inline void apply(MultiRange const& multirange,
141 Strategy const& strategy)
143 typedef typename boost::range_iterator
146 >::type iterator_type;
148 // due to the periodicity of longitudes we need to compute the boxes
149 // of all the single geometries and keep them in a container
150 std::vector<Box> boxes;
151 for (iterator_type it = boost::begin(multirange);
152 it != boost::end(multirange);
155 if (! geometry::is_empty(*it))
158 EnvelopePolicy::apply(*it, helper_box, strategy);
159 boxes.push_back(helper_box);
163 // now we need to compute the envelope of the range of boxes
164 // (cannot be done in an incremental fashion as in the
165 // Cartesian coordinate system)
166 // if all single geometries are empty no boxes have been found
167 // and the MBR is simply initialized
170 envelope_range_of_boxes::apply(boxes, mbr, strategy);
174 initialize<Box, 0, dimension<Box>::value>::apply(mbr);
181 }} // namespace detail::envelope
182 #endif // DOXYGEN_NO_DETAIL
185 }} // namespace boost::geometry
187 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP