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, 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_RANGE_HPP 22 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP 23 24 #include <iterator> 25 #include <vector> 26 27 #include <boost/range/begin.hpp> 28 #include <boost/range/end.hpp> 29 30 #include <boost/geometry/algorithms/is_empty.hpp> 31 32 #include <boost/geometry/algorithms/detail/envelope/initialize.hpp> 33 #include <boost/geometry/algorithms/detail/expand/box.hpp> 34 #include <boost/geometry/algorithms/detail/expand/point.hpp> 35 #include <boost/geometry/algorithms/detail/expand/segment.hpp> 36 37 #include <boost/geometry/core/coordinate_dimension.hpp> 38 39 namespace boost { namespace geometry 40 { 41 42 #ifndef DOXYGEN_NO_DETAIL 43 namespace detail { namespace envelope 44 { 45 46 47 // implementation for simple ranges 48 struct envelope_range 49 { 50 template <typename Iterator, typename Box, typename Strategy> applyboost::geometry::detail::envelope::envelope_range51 static inline void apply(Iterator it, 52 Iterator last, 53 Box& mbr, 54 Strategy const& strategy) 55 { 56 typedef typename std::iterator_traits<Iterator>::value_type value_type; 57 58 // initialize MBR 59 initialize<Box, 0, dimension<Box>::value>::apply(mbr); 60 61 if (it != last) 62 { 63 // initialize box with first element in range 64 dispatch::envelope 65 < 66 value_type 67 >::apply(*it, mbr, strategy.get_element_envelope_strategy()); 68 69 // consider now the remaining elements in the range (if any) 70 for (++it; it != last; ++it) 71 { 72 dispatch::expand 73 < 74 Box, value_type 75 >::apply(mbr, *it, strategy.get_element_expand_strategy()); 76 } 77 } 78 } 79 80 template <typename Range, typename Box, typename Strategy> applyboost::geometry::detail::envelope::envelope_range81 static inline void apply(Range const& range, Box& mbr, Strategy const& strategy) 82 { 83 return apply(Strategy::begin(range), Strategy::end(range), mbr, strategy); 84 } 85 }; 86 87 88 // implementation for multi-ranges 89 template <typename EnvelopePolicy> 90 struct envelope_multi_range 91 { 92 template <typename MultiRange, typename Box, typename Strategy> applyboost::geometry::detail::envelope::envelope_multi_range93 static inline void apply(MultiRange const& multirange, 94 Box& mbr, 95 Strategy const& strategy) 96 { 97 apply(boost::begin(multirange), boost::end(multirange), mbr, strategy); 98 } 99 100 template <typename Iter, typename Box, typename Strategy> applyboost::geometry::detail::envelope::envelope_multi_range101 static inline void apply(Iter it, 102 Iter last, 103 Box& mbr, 104 Strategy const& strategy) 105 { 106 typename Strategy::template multi_state<Box> state; 107 for (; it != last; ++it) 108 { 109 if (! geometry::is_empty(*it)) 110 { 111 Box helper_mbr; 112 EnvelopePolicy::apply(*it, helper_mbr, strategy); 113 state.apply(helper_mbr); 114 } 115 } 116 state.result(mbr); 117 } 118 }; 119 120 121 }} // namespace detail::envelope 122 #endif // DOXYGEN_NO_DETAIL 123 124 125 }} // namespace boost::geometry 126 127 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP 128