pointing_segment.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2020, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP
  8. #define BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP
  9. #include <cstddef>
  10. #include <type_traits>
  11. #include <boost/concept/assert.hpp>
  12. #include <boost/core/addressof.hpp>
  13. #include <boost/geometry/core/access.hpp>
  14. #include <boost/geometry/core/assert.hpp>
  15. #include <boost/geometry/core/coordinate_type.hpp>
  16. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace model
  20. {
  21. // const or non-const segment type that is meant to be
  22. // * default constructible
  23. // * copy constructible
  24. // * assignable
  25. // referring_segment does not fit these requirements, hence the
  26. // pointing_segment class
  27. //
  28. // this class is used by the segment_iterator as its value type
  29. template <typename ConstOrNonConstPoint>
  30. class pointing_segment
  31. {
  32. BOOST_CONCEPT_ASSERT( (
  33. typename std::conditional
  34. <
  35. std::is_const<ConstOrNonConstPoint>::value,
  36. concepts::Point<ConstOrNonConstPoint>,
  37. concepts::ConstPoint<ConstOrNonConstPoint>
  38. >
  39. ) );
  40. typedef ConstOrNonConstPoint point_type;
  41. public:
  42. point_type* first;
  43. point_type* second;
  44. inline pointing_segment()
  45. : first(NULL)
  46. , second(NULL)
  47. {}
  48. inline pointing_segment(point_type const& p1, point_type const& p2)
  49. : first(boost::addressof(p1))
  50. , second(boost::addressof(p2))
  51. {}
  52. };
  53. } // namespace model
  54. // Traits specializations for segment above
  55. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  56. namespace traits
  57. {
  58. template <typename Point>
  59. struct tag<model::pointing_segment<Point> >
  60. {
  61. typedef segment_tag type;
  62. };
  63. template <typename Point>
  64. struct point_type<model::pointing_segment<Point> >
  65. {
  66. typedef Point type;
  67. };
  68. template <typename Point, std::size_t Dimension>
  69. struct indexed_access<model::pointing_segment<Point>, 0, Dimension>
  70. {
  71. typedef model::pointing_segment<Point> segment_type;
  72. typedef typename geometry::coordinate_type
  73. <
  74. segment_type
  75. >::type coordinate_type;
  76. static inline coordinate_type get(segment_type const& s)
  77. {
  78. BOOST_GEOMETRY_ASSERT( s.first != NULL );
  79. return geometry::get<Dimension>(*s.first);
  80. }
  81. static inline void set(segment_type& s, coordinate_type const& value)
  82. {
  83. BOOST_GEOMETRY_ASSERT( s.first != NULL );
  84. geometry::set<Dimension>(*s.first, value);
  85. }
  86. };
  87. template <typename Point, std::size_t Dimension>
  88. struct indexed_access<model::pointing_segment<Point>, 1, Dimension>
  89. {
  90. typedef model::pointing_segment<Point> segment_type;
  91. typedef typename geometry::coordinate_type
  92. <
  93. segment_type
  94. >::type coordinate_type;
  95. static inline coordinate_type get(segment_type const& s)
  96. {
  97. BOOST_GEOMETRY_ASSERT( s.second != NULL );
  98. return geometry::get<Dimension>(*s.second);
  99. }
  100. static inline void set(segment_type& s, coordinate_type const& value)
  101. {
  102. BOOST_GEOMETRY_ASSERT( s.second != NULL );
  103. geometry::set<Dimension>(*s.second, value);
  104. }
  105. };
  106. } // namespace traits
  107. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  108. }} // namespace boost::geometry
  109. #endif // BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP