1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2015, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
10 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_NORMALIZE_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_NORMALIZE_HPP
15 #include <boost/numeric/conversion/cast.hpp>
17 #include <boost/geometry/core/access.hpp>
18 #include <boost/geometry/core/coordinate_system.hpp>
19 #include <boost/geometry/core/coordinate_type.hpp>
20 #include <boost/geometry/core/cs.hpp>
21 #include <boost/geometry/core/tag.hpp>
22 #include <boost/geometry/core/tags.hpp>
24 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
25 #include <boost/geometry/util/normalize_spheroidal_box_coordinates.hpp>
27 #include <boost/geometry/views/detail/indexed_point_view.hpp>
30 namespace boost { namespace geometry
33 #ifndef DOXYGEN_NO_DETAIL
34 namespace detail { namespace normalization
40 template <typename GeometryIn, typename GeometryOut>
41 static inline void apply(GeometryIn const&, GeometryOut&)
47 template <std::size_t Dimension, std::size_t DimensionCount>
50 template <typename CoordinateType, typename PointIn, typename PointOut>
51 static inline void apply(CoordinateType const& longitude,
52 CoordinateType const& latitude,
53 PointIn const& point_in,
56 geometry::set<Dimension>(point_out, boost::numeric_cast
58 typename coordinate_type<PointOut>::type
59 >(geometry::get<Dimension>(point_in)));
63 Dimension + 1, DimensionCount
64 >::apply(longitude, latitude, point_in, point_out);
68 template <std::size_t DimensionCount>
69 struct assign_loop<DimensionCount, DimensionCount>
71 template <typename CoordinateType, typename PointIn, typename PointOut>
72 static inline void apply(CoordinateType const&,
73 CoordinateType const&,
80 template <std::size_t DimensionCount>
81 struct assign_loop<0, DimensionCount>
83 template <typename CoordinateType, typename PointIn, typename PointOut>
84 static inline void apply(CoordinateType const& longitude,
85 CoordinateType const& latitude,
86 PointIn const& point_in,
89 geometry::set<0>(point_out, boost::numeric_cast
91 typename coordinate_type<PointOut>::type
97 >::apply(longitude, latitude, point_in, point_out);
101 template <std::size_t DimensionCount>
102 struct assign_loop<1, DimensionCount>
104 template <typename CoordinateType, typename PointIn, typename PointOut>
105 static inline void apply(CoordinateType const& longitude,
106 CoordinateType const& latitude,
107 PointIn const& point_in,
110 geometry::set<1>(point_out, boost::numeric_cast
112 typename coordinate_type<PointOut>::type
118 >::apply(longitude, latitude, point_in, point_out);
123 template <typename PointIn, typename PointOut>
124 struct normalize_point
126 static inline void apply(PointIn const& point_in, PointOut& point_out)
128 typedef typename coordinate_type<PointIn>::type in_coordinate_type;
130 in_coordinate_type longitude = geometry::get<0>(point_in);
131 in_coordinate_type latitude = geometry::get<1>(point_in);
133 math::normalize_spheroidal_coordinates
135 typename coordinate_system<PointIn>::type::units,
137 >(longitude, latitude);
141 0, dimension<PointIn>::value
142 >::apply(longitude, latitude, point_in, point_out);
147 template <typename BoxIn, typename BoxOut>
150 template <typename UnitsIn, typename UnitsOut, typename CoordinateInType>
151 static inline void apply_to_coordinates(CoordinateInType& lon_min,
152 CoordinateInType& lat_min,
153 CoordinateInType& lon_max,
154 CoordinateInType& lat_max,
158 detail::indexed_point_view<BoxOut, min_corner> p_min_out(box_out);
161 0, dimension<BoxIn>::value
164 detail::indexed_point_view
166 BoxIn const, min_corner
170 detail::indexed_point_view<BoxOut, max_corner> p_max_out(box_out);
173 0, dimension<BoxIn>::value
176 detail::indexed_point_view
178 BoxIn const, max_corner
184 static inline void apply(BoxIn const& box_in, BoxOut& box_out)
186 typedef typename coordinate_type<BoxIn>::type in_coordinate_type;
188 in_coordinate_type lon_min = geometry::get<min_corner, 0>(box_in);
189 in_coordinate_type lat_min = geometry::get<min_corner, 1>(box_in);
190 in_coordinate_type lon_max = geometry::get<max_corner, 0>(box_in);
191 in_coordinate_type lat_max = geometry::get<max_corner, 1>(box_in);
193 math::normalize_spheroidal_box_coordinates
195 typename coordinate_system<BoxIn>::type::units,
197 >(lon_min, lat_min, lon_max, lat_max);
201 typename coordinate_system<BoxIn>::type::units,
202 typename coordinate_system<BoxOut>::type::units
203 >(lon_min, lat_min, lon_max, lat_max, box_in, box_out);
208 }} // namespace detail::normalization
209 #endif // DOXYGEN_NO_DETAIL
211 #ifndef DOXYGEN_NO_DISPATCH
218 typename GeometryOut,
219 typename TagIn = typename tag<GeometryIn>::type,
220 typename TagOut = typename tag<GeometryOut>::type,
221 typename CSTagIn = typename cs_tag<GeometryIn>::type,
222 typename CSTagOut = typename cs_tag<GeometryOut>::type
224 struct normalize : detail::normalization::do_nothing
228 template <typename PointIn, typename PointOut>
231 PointIn, PointOut, point_tag, point_tag,
232 spherical_equatorial_tag, spherical_equatorial_tag
233 > : detail::normalization::normalize_point<PointIn, PointOut>
237 template <typename PointIn, typename PointOut>
240 PointIn, PointOut, point_tag, point_tag, geographic_tag, geographic_tag
241 > : detail::normalization::normalize_point<PointIn, PointOut>
245 template <typename BoxIn, typename BoxOut>
248 BoxIn, BoxOut, box_tag, box_tag,
249 spherical_equatorial_tag, spherical_equatorial_tag
250 > : detail::normalization::normalize_box<BoxIn, BoxOut>
254 template <typename BoxIn, typename BoxOut>
257 BoxIn, BoxOut, box_tag, box_tag, geographic_tag, geographic_tag
258 > : detail::normalization::normalize_box<BoxIn, BoxOut>
262 } // namespace dispatch
263 #endif // DOXYGEN_NO_DISPATCH
266 #ifndef DOXYGEN_NO_DETAIL
271 template <typename GeometryIn, typename GeometryOut>
272 inline void normalize(GeometryIn const& geometry_in, GeometryOut& geometry_out)
276 GeometryIn, GeometryOut
277 >::apply(geometry_in, geometry_out);
280 template <typename GeometryOut, typename GeometryIn>
281 inline GeometryOut return_normalized(GeometryIn const& geometry_in)
283 GeometryOut geometry_out;
284 detail::normalize(geometry_in, geometry_out);
289 } // namespace detail
290 #endif // DOXYGEN_NO_DETAIL
292 }} // namespace boost::geometry
294 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_NORMALIZE_HPP