1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2015-2017, 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_ALGORITHMS_DETAIL_NORMALIZE_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_NORMALIZE_HPP
16 #include <boost/numeric/conversion/cast.hpp>
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/core/coordinate_system.hpp>
20 #include <boost/geometry/core/coordinate_type.hpp>
21 #include <boost/geometry/core/cs.hpp>
22 #include <boost/geometry/core/tag.hpp>
23 #include <boost/geometry/core/tags.hpp>
25 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
26 #include <boost/geometry/util/normalize_spheroidal_box_coordinates.hpp>
28 #include <boost/geometry/views/detail/indexed_point_view.hpp>
31 namespace boost { namespace geometry
34 #ifndef DOXYGEN_NO_DETAIL
35 namespace detail { namespace normalization
41 template <typename GeometryIn, typename GeometryOut>
42 static inline void apply(GeometryIn const&, GeometryOut&)
48 template <std::size_t Dimension, std::size_t DimensionCount>
51 template <typename CoordinateType, typename PointIn, typename PointOut>
52 static inline void apply(CoordinateType const& longitude,
53 CoordinateType const& latitude,
54 PointIn const& point_in,
57 geometry::set<Dimension>(point_out, boost::numeric_cast
59 typename coordinate_type<PointOut>::type
60 >(geometry::get<Dimension>(point_in)));
64 Dimension + 1, DimensionCount
65 >::apply(longitude, latitude, point_in, point_out);
69 template <std::size_t DimensionCount>
70 struct assign_loop<DimensionCount, DimensionCount>
72 template <typename CoordinateType, typename PointIn, typename PointOut>
73 static inline void apply(CoordinateType const&,
74 CoordinateType const&,
81 template <std::size_t DimensionCount>
82 struct assign_loop<0, DimensionCount>
84 template <typename CoordinateType, typename PointIn, typename PointOut>
85 static inline void apply(CoordinateType const& longitude,
86 CoordinateType const& latitude,
87 PointIn const& point_in,
90 geometry::set<0>(point_out, boost::numeric_cast
92 typename coordinate_type<PointOut>::type
98 >::apply(longitude, latitude, point_in, point_out);
102 template <std::size_t DimensionCount>
103 struct assign_loop<1, DimensionCount>
105 template <typename CoordinateType, typename PointIn, typename PointOut>
106 static inline void apply(CoordinateType const& longitude,
107 CoordinateType const& latitude,
108 PointIn const& point_in,
111 geometry::set<1>(point_out, boost::numeric_cast
113 typename coordinate_type<PointOut>::type
119 >::apply(longitude, latitude, point_in, point_out);
124 template <typename PointIn, typename PointOut, bool IsEquatorial = true>
125 struct normalize_point
127 static inline void apply(PointIn const& point_in, PointOut& point_out)
129 typedef typename coordinate_type<PointIn>::type in_coordinate_type;
131 in_coordinate_type longitude = geometry::get<0>(point_in);
132 in_coordinate_type latitude = geometry::get<1>(point_in);
134 math::normalize_spheroidal_coordinates
136 typename coordinate_system<PointIn>::type::units,
139 >(longitude, latitude);
143 0, dimension<PointIn>::value
144 >::apply(longitude, latitude, point_in, point_out);
149 template <typename BoxIn, typename BoxOut, bool IsEquatorial = true>
152 template <typename UnitsIn, typename UnitsOut, typename CoordinateInType>
153 static inline void apply_to_coordinates(CoordinateInType& lon_min,
154 CoordinateInType& lat_min,
155 CoordinateInType& lon_max,
156 CoordinateInType& lat_max,
160 detail::indexed_point_view<BoxOut, min_corner> p_min_out(box_out);
163 0, dimension<BoxIn>::value
166 detail::indexed_point_view
168 BoxIn const, min_corner
172 detail::indexed_point_view<BoxOut, max_corner> p_max_out(box_out);
175 0, dimension<BoxIn>::value
178 detail::indexed_point_view
180 BoxIn const, max_corner
186 static inline void apply(BoxIn const& box_in, BoxOut& box_out)
188 typedef typename coordinate_type<BoxIn>::type in_coordinate_type;
190 in_coordinate_type lon_min = geometry::get<min_corner, 0>(box_in);
191 in_coordinate_type lat_min = geometry::get<min_corner, 1>(box_in);
192 in_coordinate_type lon_max = geometry::get<max_corner, 0>(box_in);
193 in_coordinate_type lat_max = geometry::get<max_corner, 1>(box_in);
195 math::normalize_spheroidal_box_coordinates
197 typename coordinate_system<BoxIn>::type::units,
200 >(lon_min, lat_min, lon_max, lat_max);
204 typename coordinate_system<BoxIn>::type::units,
205 typename coordinate_system<BoxOut>::type::units
206 >(lon_min, lat_min, lon_max, lat_max, box_in, box_out);
211 }} // namespace detail::normalization
212 #endif // DOXYGEN_NO_DETAIL
214 #ifndef DOXYGEN_NO_DISPATCH
221 typename GeometryOut,
222 typename TagIn = typename tag<GeometryIn>::type,
223 typename TagOut = typename tag<GeometryOut>::type,
224 typename CSTagIn = typename cs_tag<GeometryIn>::type,
225 typename CSTagOut = typename cs_tag<GeometryOut>::type
227 struct normalize : detail::normalization::do_nothing
231 template <typename PointIn, typename PointOut>
234 PointIn, PointOut, point_tag, point_tag,
235 spherical_equatorial_tag, spherical_equatorial_tag
236 > : detail::normalization::normalize_point<PointIn, PointOut>
240 template <typename PointIn, typename PointOut>
243 PointIn, PointOut, point_tag, point_tag,
244 spherical_polar_tag, spherical_polar_tag
245 > : detail::normalization::normalize_point<PointIn, PointOut, false>
249 template <typename PointIn, typename PointOut>
252 PointIn, PointOut, point_tag, point_tag, geographic_tag, geographic_tag
253 > : detail::normalization::normalize_point<PointIn, PointOut>
257 template <typename BoxIn, typename BoxOut>
260 BoxIn, BoxOut, box_tag, box_tag,
261 spherical_equatorial_tag, spherical_equatorial_tag
262 > : detail::normalization::normalize_box<BoxIn, BoxOut>
266 template <typename BoxIn, typename BoxOut>
269 BoxIn, BoxOut, box_tag, box_tag,
270 spherical_polar_tag, spherical_polar_tag
271 > : detail::normalization::normalize_box<BoxIn, BoxOut, false>
275 template <typename BoxIn, typename BoxOut>
278 BoxIn, BoxOut, box_tag, box_tag, geographic_tag, geographic_tag
279 > : detail::normalization::normalize_box<BoxIn, BoxOut>
283 } // namespace dispatch
284 #endif // DOXYGEN_NO_DISPATCH
287 #ifndef DOXYGEN_NO_DETAIL
292 template <typename GeometryIn, typename GeometryOut>
293 inline void normalize(GeometryIn const& geometry_in, GeometryOut& geometry_out)
297 GeometryIn, GeometryOut
298 >::apply(geometry_in, geometry_out);
301 template <typename GeometryOut, typename GeometryIn>
302 inline GeometryOut return_normalized(GeometryIn const& geometry_in)
304 GeometryOut geometry_out;
305 detail::normalize(geometry_in, geometry_out);
310 } // namespace detail
311 #endif // DOXYGEN_NO_DETAIL
313 }} // namespace boost::geometry
315 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_NORMALIZE_HPP