]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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. | |
8 | // Modifications copyright (c) 2015, Oracle and/or its affiliates. | |
9 | ||
10 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
11 | ||
12 | // Distributed under the Boost Software License, Version 1.0. | |
13 | // (See accompanying file LICENSE_1_0.txt or copy at | |
14 | // http://www.boost.org/LICENSE_1_0.txt) | |
15 | ||
16 | #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP | |
17 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP | |
18 | ||
19 | #include <cstddef> | |
20 | ||
21 | #include <boost/geometry/core/cs.hpp> | |
22 | #include <boost/geometry/core/coordinate_dimension.hpp> | |
23 | #include <boost/geometry/core/coordinate_system.hpp> | |
24 | #include <boost/geometry/core/tags.hpp> | |
25 | ||
26 | #include <boost/geometry/views/detail/indexed_point_view.hpp> | |
27 | ||
28 | #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp> | |
29 | #include <boost/geometry/algorithms/detail/normalize.hpp> | |
30 | #include <boost/geometry/algorithms/detail/envelope/transform_units.hpp> | |
31 | ||
32 | #include <boost/geometry/algorithms/dispatch/envelope.hpp> | |
33 | ||
34 | ||
35 | namespace boost { namespace geometry | |
36 | { | |
37 | ||
38 | #ifndef DOXYGEN_NO_DETAIL | |
39 | namespace detail { namespace envelope | |
40 | { | |
41 | ||
42 | ||
43 | template | |
44 | < | |
45 | std::size_t Index, | |
46 | std::size_t Dimension, | |
47 | std::size_t DimensionCount | |
48 | > | |
49 | struct envelope_indexed_box | |
50 | { | |
51 | template <typename BoxIn, typename BoxOut> | |
52 | static inline void apply(BoxIn const& box_in, BoxOut& mbr) | |
53 | { | |
54 | detail::indexed_point_view<BoxIn const, Index> box_in_corner(box_in); | |
55 | detail::indexed_point_view<BoxOut, Index> mbr_corner(mbr); | |
56 | ||
57 | detail::conversion::point_to_point | |
58 | < | |
59 | detail::indexed_point_view<BoxIn const, Index>, | |
60 | detail::indexed_point_view<BoxOut, Index>, | |
61 | Dimension, | |
62 | DimensionCount | |
63 | >::apply(box_in_corner, mbr_corner); | |
64 | } | |
65 | }; | |
66 | ||
67 | template | |
68 | < | |
69 | std::size_t Index, | |
70 | std::size_t DimensionCount | |
71 | > | |
72 | struct envelope_indexed_box_on_spheroid | |
73 | { | |
74 | template <typename BoxIn, typename BoxOut> | |
75 | static inline void apply(BoxIn const& box_in, BoxOut& mbr) | |
76 | { | |
77 | // transform() does not work with boxes of dimension higher | |
78 | // than 2; to account for such boxes we transform the min/max | |
79 | // points of the boxes using the indexed_point_view | |
80 | detail::indexed_point_view<BoxIn const, Index> box_in_corner(box_in); | |
81 | detail::indexed_point_view<BoxOut, Index> mbr_corner(mbr); | |
82 | ||
83 | // first transform the units | |
84 | transform_units(box_in_corner, mbr_corner); | |
85 | ||
86 | // now transform the remaining coordinates | |
87 | detail::conversion::point_to_point | |
88 | < | |
89 | detail::indexed_point_view<BoxIn const, Index>, | |
90 | detail::indexed_point_view<BoxOut, Index>, | |
91 | 2, | |
92 | DimensionCount | |
93 | >::apply(box_in_corner, mbr_corner); | |
94 | } | |
95 | }; | |
96 | ||
97 | ||
98 | struct envelope_box | |
99 | { | |
100 | template<typename BoxIn, typename BoxOut> | |
101 | static inline void apply(BoxIn const& box_in, BoxOut& mbr) | |
102 | { | |
103 | envelope_indexed_box | |
104 | < | |
105 | min_corner, 0, dimension<BoxIn>::value | |
106 | >::apply(box_in, mbr); | |
107 | ||
108 | envelope_indexed_box | |
109 | < | |
110 | max_corner, 0, dimension<BoxIn>::value | |
111 | >::apply(box_in, mbr); | |
112 | } | |
113 | }; | |
114 | ||
115 | ||
116 | struct envelope_box_on_spheroid | |
117 | { | |
118 | template <typename BoxIn, typename BoxOut> | |
119 | static inline void apply(BoxIn const& box_in, BoxOut& mbr) | |
120 | { | |
121 | BoxIn box_in_normalized = detail::return_normalized<BoxIn>(box_in); | |
122 | ||
123 | envelope_indexed_box_on_spheroid | |
124 | < | |
125 | min_corner, dimension<BoxIn>::value | |
126 | >::apply(box_in_normalized, mbr); | |
127 | ||
128 | envelope_indexed_box_on_spheroid | |
129 | < | |
130 | max_corner, dimension<BoxIn>::value | |
131 | >::apply(box_in_normalized, mbr); | |
132 | } | |
133 | }; | |
134 | ||
135 | ||
136 | }} // namespace detail::envelope | |
137 | #endif // DOXYGEN_NO_DETAIL | |
138 | ||
139 | #ifndef DOXYGEN_NO_DISPATCH | |
140 | namespace dispatch | |
141 | { | |
142 | ||
143 | ||
144 | template <typename Box, typename CS_Tag> | |
145 | struct envelope<Box, box_tag, CS_Tag> | |
146 | : detail::envelope::envelope_box | |
147 | {}; | |
148 | ||
149 | ||
150 | template <typename Box> | |
151 | struct envelope<Box, box_tag, spherical_equatorial_tag> | |
152 | : detail::envelope::envelope_box_on_spheroid | |
153 | {}; | |
154 | ||
155 | ||
156 | template <typename Box> | |
157 | struct envelope<Box, box_tag, geographic_tag> | |
158 | : detail::envelope::envelope_box_on_spheroid | |
159 | {}; | |
160 | ||
161 | ||
162 | } // namespace dispatch | |
163 | #endif // DOXYGEN_NO_DISPATCH | |
164 | ||
165 | }} // namespace boost::geometry | |
166 | ||
167 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP |