indexed_point_view.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland
  6. // This file was modified by Oracle on 2015.
  7. // Modifications copyright (c) 2015, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Use, modification and distribution is subject to the Boost Software License,
  10. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #ifndef BOOST_GEOMETRY_VIEWS_DETAIL_INDEXED_POINT_VIEW_HPP
  13. #define BOOST_GEOMETRY_VIEWS_DETAIL_INDEXED_POINT_VIEW_HPP
  14. #include <cstddef>
  15. #include <boost/geometry/core/access.hpp>
  16. #include <boost/geometry/core/coordinate_type.hpp>
  17. #include <boost/geometry/core/coordinate_system.hpp>
  18. #include <boost/geometry/core/coordinate_dimension.hpp>
  19. #include <boost/geometry/util/math.hpp>
  20. namespace boost { namespace geometry
  21. {
  22. namespace detail
  23. {
  24. template <typename Geometry, std::size_t Index>
  25. class indexed_point_view
  26. {
  27. indexed_point_view & operator=(indexed_point_view const&);
  28. public:
  29. typedef typename geometry::point_type<Geometry>::type point_type;
  30. typedef typename geometry::coordinate_type<Geometry>::type coordinate_type;
  31. indexed_point_view(Geometry & geometry)
  32. : m_geometry(geometry)
  33. {}
  34. template <std::size_t Dimension>
  35. inline coordinate_type get() const
  36. {
  37. return geometry::get<Index, Dimension>(m_geometry);
  38. }
  39. template <std::size_t Dimension>
  40. inline void set(coordinate_type const& value)
  41. {
  42. geometry::set<Index, Dimension>(m_geometry, value);
  43. }
  44. private:
  45. Geometry & m_geometry;
  46. };
  47. }
  48. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  49. namespace traits
  50. {
  51. template <typename Geometry, std::size_t Index>
  52. struct tag< geometry::detail::indexed_point_view<Geometry, Index> >
  53. {
  54. typedef point_tag type;
  55. };
  56. template <typename Geometry, std::size_t Index>
  57. struct coordinate_type< geometry::detail::indexed_point_view<Geometry, Index> >
  58. {
  59. typedef typename geometry::coordinate_type<Geometry>::type type;
  60. };
  61. template <typename Geometry, std::size_t Index>
  62. struct coordinate_system
  63. <
  64. geometry::detail::indexed_point_view<Geometry, Index>
  65. >
  66. {
  67. typedef typename geometry::coordinate_system<Geometry>::type type;
  68. };
  69. template <typename Geometry, std::size_t Index>
  70. struct dimension< geometry::detail::indexed_point_view<Geometry, Index> >
  71. : geometry::dimension<Geometry>
  72. {};
  73. template<typename Geometry, std::size_t Index, std::size_t Dimension>
  74. struct access
  75. <
  76. geometry::detail::indexed_point_view<Geometry, Index>, Dimension
  77. >
  78. {
  79. typedef typename geometry::coordinate_type<Geometry>::type coordinate_type;
  80. static inline coordinate_type get(
  81. geometry::detail::indexed_point_view<Geometry, Index> const& p)
  82. {
  83. return p.template get<Dimension>();
  84. }
  85. static inline void set(
  86. geometry::detail::indexed_point_view<Geometry, Index> & p,
  87. coordinate_type const& value)
  88. {
  89. p.template set<Dimension>(value);
  90. }
  91. };
  92. } // namespace traits
  93. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  94. }} // namespace boost::geometry
  95. #endif // BOOST_GEOMETRY_VIEWS_DETAIL_INDEXED_POINT_VIEW_HPP