pointing_segment.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. using type = segment_tag;
  62. };
  63. template <typename Point>
  64. struct point_type<model::pointing_segment<Point> >
  65. {
  66. using type = Point;
  67. };
  68. template <typename Point, std::size_t Dimension>
  69. struct indexed_access<model::pointing_segment<Point>, 0, Dimension>
  70. {
  71. using segment_type = model::pointing_segment<Point>;
  72. using coordinate_type = geometry::coordinate_type_t<segment_type>;
  73. static inline coordinate_type get(segment_type const& s)
  74. {
  75. BOOST_GEOMETRY_ASSERT( s.first != NULL );
  76. return geometry::get<Dimension>(*s.first);
  77. }
  78. static inline void set(segment_type& s, coordinate_type const& value)
  79. {
  80. BOOST_GEOMETRY_ASSERT( s.first != NULL );
  81. geometry::set<Dimension>(*s.first, value);
  82. }
  83. };
  84. template <typename Point, std::size_t Dimension>
  85. struct indexed_access<model::pointing_segment<Point>, 1, Dimension>
  86. {
  87. using segment_type = model::pointing_segment<Point>;
  88. using coordinate_type = geometry::coordinate_type_t<segment_type>;
  89. static inline coordinate_type get(segment_type const& s)
  90. {
  91. BOOST_GEOMETRY_ASSERT( s.second != NULL );
  92. return geometry::get<Dimension>(*s.second);
  93. }
  94. static inline void set(segment_type& s, coordinate_type const& value)
  95. {
  96. BOOST_GEOMETRY_ASSERT( s.second != NULL );
  97. geometry::set<Dimension>(*s.second, value);
  98. }
  99. };
  100. } // namespace traits
  101. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  102. }} // namespace boost::geometry
  103. #endif // BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP