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 // 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)
16 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP
17 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP
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>
26 #include <boost/geometry/views/detail/indexed_point_view.hpp>
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>
32 #include <boost/geometry/algorithms/dispatch/envelope.hpp>
35 namespace boost { namespace geometry
38 #ifndef DOXYGEN_NO_DETAIL
39 namespace detail { namespace envelope
46 std::size_t Dimension,
47 std::size_t DimensionCount
49 struct envelope_indexed_box
51 template <typename BoxIn, typename BoxOut>
52 static inline void apply(BoxIn const& box_in, BoxOut& mbr)
54 detail::indexed_point_view<BoxIn const, Index> box_in_corner(box_in);
55 detail::indexed_point_view<BoxOut, Index> mbr_corner(mbr);
57 detail::conversion::point_to_point
59 detail::indexed_point_view<BoxIn const, Index>,
60 detail::indexed_point_view<BoxOut, Index>,
63 >::apply(box_in_corner, mbr_corner);
70 std::size_t DimensionCount
72 struct envelope_indexed_box_on_spheroid
74 template <typename BoxIn, typename BoxOut>
75 static inline void apply(BoxIn const& box_in, BoxOut& mbr)
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);
83 // first transform the units
84 transform_units(box_in_corner, mbr_corner);
86 // now transform the remaining coordinates
87 detail::conversion::point_to_point
89 detail::indexed_point_view<BoxIn const, Index>,
90 detail::indexed_point_view<BoxOut, Index>,
93 >::apply(box_in_corner, mbr_corner);
100 template<typename BoxIn, typename BoxOut>
101 static inline void apply(BoxIn const& box_in, BoxOut& mbr)
105 min_corner, 0, dimension<BoxIn>::value
106 >::apply(box_in, mbr);
110 max_corner, 0, dimension<BoxIn>::value
111 >::apply(box_in, mbr);
116 struct envelope_box_on_spheroid
118 template <typename BoxIn, typename BoxOut>
119 static inline void apply(BoxIn const& box_in, BoxOut& mbr)
121 BoxIn box_in_normalized = detail::return_normalized<BoxIn>(box_in);
123 envelope_indexed_box_on_spheroid
125 min_corner, dimension<BoxIn>::value
126 >::apply(box_in_normalized, mbr);
128 envelope_indexed_box_on_spheroid
130 max_corner, dimension<BoxIn>::value
131 >::apply(box_in_normalized, mbr);
136 }} // namespace detail::envelope
137 #endif // DOXYGEN_NO_DETAIL
139 #ifndef DOXYGEN_NO_DISPATCH
144 template <typename Box, typename CS_Tag>
145 struct envelope<Box, box_tag, CS_Tag>
146 : detail::envelope::envelope_box
150 template <typename Box>
151 struct envelope<Box, box_tag, spherical_equatorial_tag>
152 : detail::envelope::envelope_box_on_spheroid
156 template <typename Box>
157 struct envelope<Box, box_tag, geographic_tag>
158 : detail::envelope::envelope_box_on_spheroid
162 } // namespace dispatch
163 #endif // DOXYGEN_NO_DISPATCH
165 }} // namespace boost::geometry
167 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP