convert_point_to_point.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CONVERT_POINT_TO_POINT_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CONVERT_POINT_TO_POINT_HPP
  12. // Note: extracted from "convert.hpp" to avoid circular references convert/append
  13. #include <cstddef>
  14. #include <boost/geometry/core/access.hpp>
  15. #include <boost/geometry/core/coordinate_dimension.hpp>
  16. #include <boost/geometry/core/coordinate_type.hpp>
  17. #include <boost/geometry/util/numeric_cast.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. #ifndef DOXYGEN_NO_DETAIL
  21. namespace detail { namespace conversion
  22. {
  23. // TODO: Use assignment if possible.
  24. // WARNING: This utility is called in various places for a subset of dimensions.
  25. // In such cases only some of the coordinates should be copied. Alternatively
  26. // there should be a different utility for that called differently than
  27. // convert_xxx, e.g. set_coordinates.
  28. template <typename Source, typename Destination, std::size_t Dimension, std::size_t DimensionCount>
  29. struct point_to_point
  30. {
  31. static inline void apply(Source const& source, Destination& destination)
  32. {
  33. typedef typename coordinate_type<Destination>::type coordinate_type;
  34. set<Dimension>(destination, util::numeric_cast<coordinate_type>(get<Dimension>(source)));
  35. point_to_point<Source, Destination, Dimension + 1, DimensionCount>::apply(source, destination);
  36. }
  37. };
  38. template <typename Source, typename Destination, std::size_t DimensionCount>
  39. struct point_to_point<Source, Destination, DimensionCount, DimensionCount>
  40. {
  41. static inline void apply(Source const& , Destination& )
  42. {}
  43. };
  44. template <typename Source, typename Destination>
  45. inline void convert_point_to_point(Source const& source, Destination& destination)
  46. {
  47. point_to_point<Source, Destination, 0, dimension<Destination>::value>::apply(source, destination);
  48. }
  49. }} // namespace detail::conversion
  50. #endif // DOXYGEN_NO_DETAIL
  51. }} // namespace boost::geometry
  52. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CONVERT_POINT_TO_POINT_HPP