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 // Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France.
7 
8 // This file was modified by Oracle on 2015, 2016, 2017, 2018.
9 // Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
10 
11 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
12 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
13 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
14 
15 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
16 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
17 
18 // Distributed under the Boost Software License, Version 1.0.
19 // (See accompanying file LICENSE_1_0.txt or copy at
20 // http://www.boost.org/LICENSE_1_0.txt)
21 
22 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_INDEXED_HPP
23 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_INDEXED_HPP
24 
25 #include <cstddef>
26 #include <functional>
27 
28 #include <boost/geometry/core/access.hpp>
29 #include <boost/geometry/core/tags.hpp>
30 
31 #include <boost/geometry/util/select_coordinate_type.hpp>
32 
33 #include <boost/geometry/algorithms/dispatch/expand.hpp>
34 
35 
36 namespace boost { namespace geometry
37 {
38 
39 #ifndef DOXYGEN_NO_DETAIL
40 namespace detail { namespace expand
41 {
42 
43 
44 template
45 <
46     std::size_t Index,
47     std::size_t Dimension, std::size_t DimensionCount
48 >
49 struct indexed_loop
50 {
51     template <typename Box, typename Geometry>
applyboost::geometry::detail::expand::indexed_loop52     static inline void apply(Box& box, Geometry const& source)
53     {
54         typedef typename select_coordinate_type
55                 <
56                     Box,
57                     Geometry
58                 >::type coordinate_type;
59 
60         coordinate_type const coord = get<Index, Dimension>(source);
61 
62         std::less<coordinate_type> less;
63         std::greater<coordinate_type> greater;
64 
65         if (less(coord, get<min_corner, Dimension>(box)))
66         {
67             set<min_corner, Dimension>(box, coord);
68         }
69 
70         if (greater(coord, get<max_corner, Dimension>(box)))
71         {
72             set<max_corner, Dimension>(box, coord);
73         }
74 
75         indexed_loop
76             <
77                 Index, Dimension + 1, DimensionCount
78             >::apply(box, source);
79     }
80 };
81 
82 
83 template <std::size_t Index, std::size_t DimensionCount>
84 struct indexed_loop
85     <
86         Index, DimensionCount, DimensionCount
87     >
88 {
89     template <typename Box, typename Geometry>
applyboost::geometry::detail::expand::indexed_loop90     static inline void apply(Box&, Geometry const&) {}
91 };
92 
93 
94 
95 // Changes a box such that the other box is also contained by the box
96 template <std::size_t Dimension, std::size_t DimensionCount>
97 struct expand_indexed
98 {
99     template <typename Box, typename Geometry>
applyboost::geometry::detail::expand::expand_indexed100     static inline void apply(Box& box, Geometry const& geometry)
101     {
102         indexed_loop
103             <
104                 0, Dimension, DimensionCount
105             >::apply(box, geometry);
106 
107         indexed_loop
108             <
109                 1, Dimension, DimensionCount
110             >::apply(box, geometry);
111     }
112 };
113 
114 
115 }} // namespace detail::expand
116 #endif // DOXYGEN_NO_DETAIL
117 
118 
119 }} // namespace boost::geometry
120 
121 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_INDEXED_HPP
122