// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP #define BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { template struct degree_radian_converter { typedef typename fp_coordinate_type::type coordinate_type; static inline coordinate_type get(Geometry const& geometry) { return boost::numeric_cast < coordinate_type >(geometry::get(geometry) * geometry::math::d2r); } static inline void set(Geometry& geometry, coordinate_type const& radians) { geometry::set(geometry, boost::numeric_cast < coordinate_type >(radians * geometry::math::r2d)); } }; // Default, radian (or any other coordinate system) just works like "get" template struct radian_access { typedef typename fp_coordinate_type::type coordinate_type; static inline coordinate_type get(Geometry const& geometry) { return geometry::get(geometry); } static inline void set(Geometry& geometry, coordinate_type const& radians) { geometry::set(geometry, radians); } }; // Specialize, any "degree" coordinate system will be converted to radian // but only for dimension 0,1 (so: dimension 2 and heigher are untouched) template < typename Geometry, template class CoordinateSystem > struct radian_access<0, Geometry, CoordinateSystem > : degree_radian_converter<0, Geometry> {}; template < typename Geometry, template class CoordinateSystem > struct radian_access<1, Geometry, CoordinateSystem > : degree_radian_converter<1, Geometry> {}; } // namespace detail #endif // DOXYGEN_NO_DETAIL /*! \brief get coordinate value of a point, result is in Radian \details Result is in Radian, even if source coordinate system is in Degrees \return coordinate value \ingroup get \tparam Dimension dimension \tparam Geometry geometry \param geometry geometry to get coordinate value from \note Only applicable to coordinate systems templatized by units, e.g. spherical or geographic coordinate systems */ template inline typename fp_coordinate_type::type get_as_radian(Geometry const& geometry) { return detail::radian_access::type>::get(geometry); } /*! \brief set coordinate value (in radian) to a point \details Coordinate value will be set correctly, if coordinate system of point is in Degree, Radian value will be converted to Degree \ingroup set \tparam Dimension dimension \tparam Geometry geometry \param geometry geometry to assign coordinate to \param radians coordinate value to assign \note Only applicable to coordinate systems templatized by units, e.g. spherical or geographic coordinate systems */ template inline void set_from_radian(Geometry& geometry, typename fp_coordinate_type::type const& radians) { detail::radian_access::type>::set(geometry, radians); } }} // namespace boost::geometry #endif // BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP