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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
20 #ifndef BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP
21 #define BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP
26 #include <boost/numeric/conversion/cast.hpp>
28 #include <boost/geometry/core/access.hpp>
29 #include <boost/geometry/core/cs.hpp>
30 #include <boost/geometry/core/coordinate_type.hpp>
33 #include <boost/geometry/util/math.hpp>
37 namespace boost { namespace geometry
41 #ifndef DOXYGEN_NO_DETAIL
45 template<std::size_t Dimension, typename Geometry>
46 struct degree_radian_converter
48 typedef typename fp_coordinate_type<Geometry>::type coordinate_type;
50 static inline coordinate_type get(Geometry const& geometry)
52 return boost::numeric_cast
55 >(geometry::get<Dimension>(geometry)
56 * math::d2r<coordinate_type>());
59 static inline void set(Geometry& geometry, coordinate_type const& radians)
61 geometry::set<Dimension>(geometry, boost::numeric_cast
64 >(radians * math::r2d<coordinate_type>()));
70 // Default, radian (or any other coordinate system) just works like "get"
71 template <std::size_t Dimension, typename Geometry, typename DegreeOrRadian>
74 typedef typename fp_coordinate_type<Geometry>::type coordinate_type;
76 static inline coordinate_type get(Geometry const& geometry)
78 return geometry::get<Dimension>(geometry);
81 static inline void set(Geometry& geometry, coordinate_type const& radians)
83 geometry::set<Dimension>(geometry, radians);
87 // Specialize, any "degree" coordinate system will be converted to radian
88 // but only for dimension 0,1 (so: dimension 2 and heigher are untouched)
93 template<typename> class CoordinateSystem
95 struct radian_access<0, Geometry, CoordinateSystem<degree> >
96 : degree_radian_converter<0, Geometry>
103 template<typename> class CoordinateSystem
105 struct radian_access<1, Geometry, CoordinateSystem<degree> >
106 : degree_radian_converter<1, Geometry>
110 template<std::size_t Index, std::size_t Dimension, typename Geometry>
111 struct degree_radian_converter_box_segment
113 typedef typename fp_coordinate_type<Geometry>::type coordinate_type;
115 static inline coordinate_type get(Geometry const& geometry)
117 return boost::numeric_cast
120 >(geometry::get<Index, Dimension>(geometry)
121 * math::d2r<coordinate_type>());
124 static inline void set(Geometry& geometry, coordinate_type const& radians)
126 geometry::set<Index, Dimension>(geometry, boost::numeric_cast
129 >(radians * math::r2d<coordinate_type>()));
135 // Default, radian (or any other coordinate system) just works like "get"
136 template <std::size_t Index, std::size_t Dimension, typename Geometry, typename DegreeOrRadian>
137 struct radian_access_box_segment
139 typedef typename fp_coordinate_type<Geometry>::type coordinate_type;
141 static inline coordinate_type get(Geometry const& geometry)
143 return geometry::get<Index, Dimension>(geometry);
146 static inline void set(Geometry& geometry, coordinate_type const& radians)
148 geometry::set<Index, Dimension>(geometry, radians);
152 // Specialize, any "degree" coordinate system will be converted to radian
153 // but only for dimension 0,1 (so: dimension 2 and heigher are untouched)
158 template<typename> class CoordinateSystem,
161 struct radian_access_box_segment<Index, 0, Geometry, CoordinateSystem<degree> >
162 : degree_radian_converter_box_segment<Index, 0, Geometry>
169 template<typename> class CoordinateSystem,
172 struct radian_access_box_segment<Index, 1, Geometry, CoordinateSystem<degree> >
173 : degree_radian_converter_box_segment<Index, 1, Geometry>
176 } // namespace detail
177 #endif // DOXYGEN_NO_DETAIL
181 \brief get coordinate value of a point, result is in Radian
182 \details Result is in Radian, even if source coordinate system
184 \return coordinate value
186 \tparam Dimension dimension
187 \tparam Geometry geometry
188 \param geometry geometry to get coordinate value from
189 \note Only applicable to coordinate systems templatized by units,
190 e.g. spherical or geographic coordinate systems
192 template <std::size_t Dimension, typename Geometry>
193 inline typename fp_coordinate_type<Geometry>::type get_as_radian(Geometry const& geometry)
195 return detail::radian_access<Dimension, Geometry,
196 typename coordinate_system<Geometry>::type>::get(geometry);
200 \brief set coordinate value (in radian) to a point
201 \details Coordinate value will be set correctly, if coordinate system of
202 point is in Degree, Radian value will be converted to Degree
204 \tparam Dimension dimension
205 \tparam Geometry geometry
206 \param geometry geometry to assign coordinate to
207 \param radians coordinate value to assign
208 \note Only applicable to coordinate systems templatized by units,
209 e.g. spherical or geographic coordinate systems
211 template <std::size_t Dimension, typename Geometry>
212 inline void set_from_radian(Geometry& geometry,
213 typename fp_coordinate_type<Geometry>::type const& radians)
215 detail::radian_access<Dimension, Geometry,
216 typename coordinate_system<Geometry>::type>::set(geometry, radians);
220 \brief get coordinate value of a segment or box, result is in Radian
221 \details Result is in Radian, even if source coordinate system
223 \return coordinate value
226 \tparam Dimension dimension
227 \tparam Geometry geometry
228 \param geometry geometry to get coordinate value from
229 \note Only applicable to coordinate systems templatized by units,
230 e.g. spherical or geographic coordinate systems
232 template <std::size_t Index, std::size_t Dimension, typename Geometry>
233 inline typename fp_coordinate_type<Geometry>::type get_as_radian(Geometry const& geometry)
235 return detail::radian_access_box_segment<Index, Dimension, Geometry,
236 typename coordinate_system<Geometry>::type>::get(geometry);
240 \brief set coordinate value (in radian) to a segment or box
241 \details Coordinate value will be set correctly, if coordinate system of
242 point is in Degree, Radian value will be converted to Degree
245 \tparam Dimension dimension
246 \tparam Geometry geometry
247 \param geometry geometry to assign coordinate to
248 \param radians coordinate value to assign
249 \note Only applicable to coordinate systems templatized by units,
250 e.g. spherical or geographic coordinate systems
252 template <std::size_t Index, std::size_t Dimension, typename Geometry>
253 inline void set_from_radian(Geometry& geometry,
254 typename fp_coordinate_type<Geometry>::type const& radians)
256 detail::radian_access_box_segment<Index, Dimension, Geometry,
257 typename coordinate_system<Geometry>::type>::set(geometry, radians);
260 }} // namespace boost::geometry
263 #endif // BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP