diff options
Diffstat (limited to 'boost/geometry/core/radian_access.hpp')
-rw-r--r-- | boost/geometry/core/radian_access.hpp | 107 |
1 files changed, 106 insertions, 1 deletions
diff --git a/boost/geometry/core/radian_access.hpp b/boost/geometry/core/radian_access.hpp index 374c2954a2..993a6cc4c4 100644 --- a/boost/geometry/core/radian_access.hpp +++ b/boost/geometry/core/radian_access.hpp @@ -107,6 +107,72 @@ struct radian_access<1, Geometry, CoordinateSystem<degree> > {}; +template<std::size_t Index, std::size_t Dimension, typename Geometry> +struct degree_radian_converter_box_segment +{ + typedef typename fp_coordinate_type<Geometry>::type coordinate_type; + + static inline coordinate_type get(Geometry const& geometry) + { + return boost::numeric_cast + < + coordinate_type + >(geometry::get<Index, Dimension>(geometry) + * math::d2r<coordinate_type>()); + } + + static inline void set(Geometry& geometry, coordinate_type const& radians) + { + geometry::set<Index, Dimension>(geometry, boost::numeric_cast + < + coordinate_type + >(radians * math::r2d<coordinate_type>())); + } + +}; + + +// Default, radian (or any other coordinate system) just works like "get" +template <std::size_t Index, std::size_t Dimension, typename Geometry, typename DegreeOrRadian> +struct radian_access_box_segment +{ + typedef typename fp_coordinate_type<Geometry>::type coordinate_type; + + static inline coordinate_type get(Geometry const& geometry) + { + return geometry::get<Index, Dimension>(geometry); + } + + static inline void set(Geometry& geometry, coordinate_type const& radians) + { + geometry::set<Index, Dimension>(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<typename> class CoordinateSystem, + std::size_t Index +> +struct radian_access_box_segment<Index, 0, Geometry, CoordinateSystem<degree> > + : degree_radian_converter_box_segment<Index, 0, Geometry> +{}; + + +template +< + typename Geometry, + template<typename> class CoordinateSystem, + std::size_t Index +> +struct radian_access_box_segment<Index, 1, Geometry, CoordinateSystem<degree> > + : degree_radian_converter_box_segment<Index, 1, Geometry> +{}; + } // namespace detail #endif // DOXYGEN_NO_DETAIL @@ -130,7 +196,6 @@ inline typename fp_coordinate_type<Geometry>::type get_as_radian(Geometry const& typename coordinate_system<Geometry>::type>::get(geometry); } - /*! \brief set coordinate value (in radian) to a point \details Coordinate value will be set correctly, if coordinate system of @@ -151,6 +216,46 @@ inline void set_from_radian(Geometry& geometry, typename coordinate_system<Geometry>::type>::set(geometry, radians); } +/*! +\brief get coordinate value of a segment or box, result is in Radian +\details Result is in Radian, even if source coordinate system + is in Degrees +\return coordinate value +\ingroup get +\tparam Index index +\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 <std::size_t Index, std::size_t Dimension, typename Geometry> +inline typename fp_coordinate_type<Geometry>::type get_as_radian(Geometry const& geometry) +{ + return detail::radian_access_box_segment<Index, Dimension, Geometry, + typename coordinate_system<Geometry>::type>::get(geometry); +} + +/*! +\brief set coordinate value (in radian) to a segment or box +\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 Index index +\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 <std::size_t Index, std::size_t Dimension, typename Geometry> +inline void set_from_radian(Geometry& geometry, + typename fp_coordinate_type<Geometry>::type const& radians) +{ + detail::radian_access_box_segment<Index, Dimension, Geometry, + typename coordinate_system<Geometry>::type>::set(geometry, radians); +} }} // namespace boost::geometry |