1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2015-2020, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
11 #ifndef BOOST_GEOMETRY_STRATEGIES_NORMALIZE_HPP
12 #define BOOST_GEOMETRY_STRATEGIES_NORMALIZE_HPP
15 #include <type_traits>
17 #include <boost/numeric/conversion/cast.hpp>
19 #include <boost/geometry/core/access.hpp>
20 #include <boost/geometry/core/coordinate_system.hpp>
21 #include <boost/geometry/core/coordinate_type.hpp>
22 #include <boost/geometry/core/cs.hpp>
23 #include <boost/geometry/core/tag.hpp>
24 #include <boost/geometry/core/tags.hpp>
26 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
27 #include <boost/geometry/util/normalize_spheroidal_box_coordinates.hpp>
29 #include <boost/geometry/views/detail/indexed_point_view.hpp>
32 namespace boost { namespace geometry
35 namespace strategy { namespace normalize
38 #ifndef DOXYGEN_NO_DETAIL
44 template <typename GeometryIn, typename GeometryOut>
45 static inline void apply(GeometryIn const&, GeometryOut&)
51 template <std::size_t Dimension, std::size_t DimensionCount>
54 template <typename CoordinateType, typename PointIn, typename PointOut>
55 static inline void apply(CoordinateType const& longitude,
56 CoordinateType const& latitude,
57 PointIn const& point_in,
60 geometry::set<Dimension>(point_out, boost::numeric_cast
62 typename coordinate_type<PointOut>::type
63 >(geometry::get<Dimension>(point_in)));
67 Dimension + 1, DimensionCount
68 >::apply(longitude, latitude, point_in, point_out);
72 template <std::size_t DimensionCount>
73 struct assign_loop<DimensionCount, DimensionCount>
75 template <typename CoordinateType, typename PointIn, typename PointOut>
76 static inline void apply(CoordinateType const&,
77 CoordinateType const&,
84 template <std::size_t DimensionCount>
85 struct assign_loop<0, DimensionCount>
87 template <typename CoordinateType, typename PointIn, typename PointOut>
88 static inline void apply(CoordinateType const& longitude,
89 CoordinateType const& latitude,
90 PointIn const& point_in,
93 geometry::set<0>(point_out, boost::numeric_cast
95 typename coordinate_type<PointOut>::type
101 >::apply(longitude, latitude, point_in, point_out);
105 template <std::size_t DimensionCount>
106 struct assign_loop<1, DimensionCount>
108 template <typename CoordinateType, typename PointIn, typename PointOut>
109 static inline void apply(CoordinateType const& longitude,
110 CoordinateType const& latitude,
111 PointIn const& point_in,
114 geometry::set<1>(point_out, boost::numeric_cast
116 typename coordinate_type<PointOut>::type
122 >::apply(longitude, latitude, point_in, point_out);
127 template <typename PointIn, typename PointOut, bool IsEquatorial = true>
128 struct normalize_point
130 static inline void apply(PointIn const& point_in, PointOut& point_out)
132 typedef typename coordinate_type<PointIn>::type in_coordinate_type;
134 in_coordinate_type longitude = geometry::get<0>(point_in);
135 in_coordinate_type latitude = geometry::get<1>(point_in);
137 math::normalize_spheroidal_coordinates
139 typename geometry::detail::cs_angular_units<PointIn>::type,
142 >(longitude, latitude);
146 0, dimension<PointIn>::value
147 >::apply(longitude, latitude, point_in, point_out);
152 template <typename BoxIn, typename BoxOut, bool IsEquatorial = true>
155 template <typename UnitsIn, typename UnitsOut, typename CoordinateInType>
156 static inline void apply_to_coordinates(CoordinateInType& lon_min,
157 CoordinateInType& lat_min,
158 CoordinateInType& lon_max,
159 CoordinateInType& lat_max,
163 geometry::detail::indexed_point_view<BoxOut, min_corner> p_min_out(box_out);
166 0, dimension<BoxIn>::value
169 geometry::detail::indexed_point_view
171 BoxIn const, min_corner
175 geometry::detail::indexed_point_view<BoxOut, max_corner> p_max_out(box_out);
178 0, dimension<BoxIn>::value
181 geometry::detail::indexed_point_view
183 BoxIn const, max_corner
189 static inline void apply(BoxIn const& box_in, BoxOut& box_out)
191 typedef typename coordinate_type<BoxIn>::type in_coordinate_type;
193 in_coordinate_type lon_min = geometry::get<min_corner, 0>(box_in);
194 in_coordinate_type lat_min = geometry::get<min_corner, 1>(box_in);
195 in_coordinate_type lon_max = geometry::get<max_corner, 0>(box_in);
196 in_coordinate_type lat_max = geometry::get<max_corner, 1>(box_in);
198 math::normalize_spheroidal_box_coordinates
200 typename geometry::detail::cs_angular_units<BoxIn>::type,
203 >(lon_min, lat_min, lon_max, lat_max);
207 typename geometry::detail::cs_angular_units<BoxIn>::type,
208 typename geometry::detail::cs_angular_units<BoxOut>::type
209 >(lon_min, lat_min, lon_max, lat_max, box_in, box_out);
214 } // namespace detail
215 #endif // DOXYGEN_NO_DETAIL
217 struct cartesian_point
225 struct spherical_point
227 template <typename PointIn, typename PointOut>
228 static inline void apply(PointIn const& point_in, PointOut& point_out)
230 detail::normalize_point
235 typename cs_tag<PointIn>::type,
238 >::apply(point_in, point_out);
244 template <typename BoxIn, typename BoxOut>
245 static inline void apply(BoxIn const& box_in, BoxOut& box_out)
247 detail::normalize_box
252 typename cs_tag<BoxIn>::type,
255 >::apply(box_in, box_out);
259 }} // namespace strategy::normalize
261 }} // namespace boost::geometry
263 #endif // BOOST_GEOMETRY_STRATEGIES_NORMALIZE_HPP