segment_concept.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  3. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2021.
  6. // Modifications copyright (c) 2021 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP
  14. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP
  15. #include <boost/concept_check.hpp>
  16. #include <boost/core/ignore_unused.hpp>
  17. #include <boost/geometry/core/access.hpp>
  18. #include <boost/geometry/core/point_type.hpp>
  19. #include <boost/geometry/geometries/concepts/concept_type.hpp>
  20. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  21. namespace boost { namespace geometry { namespace concepts
  22. {
  23. template <typename Geometry>
  24. class Segment
  25. {
  26. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  27. typedef typename point_type<Geometry>::type point_type;
  28. BOOST_CONCEPT_ASSERT( (concepts::Point<point_type>) );
  29. template <size_t Index, size_t Dimension, size_t DimensionCount>
  30. struct dimension_checker
  31. {
  32. static void apply()
  33. {
  34. Geometry* s = 0;
  35. geometry::set<Index, Dimension>(*s, geometry::get<Index, Dimension>(*s));
  36. dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
  37. }
  38. };
  39. template <size_t Index, size_t DimensionCount>
  40. struct dimension_checker<Index, DimensionCount, DimensionCount>
  41. {
  42. static void apply() {}
  43. };
  44. public :
  45. BOOST_CONCEPT_USAGE(Segment)
  46. {
  47. static const size_t n = dimension<point_type>::type::value;
  48. dimension_checker<0, 0, n>::apply();
  49. dimension_checker<1, 0, n>::apply();
  50. }
  51. #endif
  52. };
  53. /*!
  54. \brief Segment concept (const version).
  55. \ingroup const_concepts
  56. \details The ConstSegment concept verifies the same as the Segment concept,
  57. but does not verify write access.
  58. */
  59. template <typename Geometry>
  60. class ConstSegment
  61. {
  62. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  63. typedef typename point_type<Geometry>::type point_type;
  64. typedef typename coordinate_type<Geometry>::type coordinate_type;
  65. BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<point_type>) );
  66. template <size_t Index, size_t Dimension, size_t DimensionCount>
  67. struct dimension_checker
  68. {
  69. static void apply()
  70. {
  71. const Geometry* s = 0;
  72. coordinate_type coord(geometry::get<Index, Dimension>(*s));
  73. boost::ignore_unused(coord);
  74. dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
  75. }
  76. };
  77. template <size_t Index, size_t DimensionCount>
  78. struct dimension_checker<Index, DimensionCount, DimensionCount>
  79. {
  80. static void apply() {}
  81. };
  82. public :
  83. BOOST_CONCEPT_USAGE(ConstSegment)
  84. {
  85. static const size_t n = dimension<point_type>::type::value;
  86. dimension_checker<0, 0, n>::apply();
  87. dimension_checker<1, 0, n>::apply();
  88. }
  89. #endif
  90. };
  91. template <typename Geometry>
  92. struct concept_type<Geometry, segment_tag>
  93. {
  94. using type = Segment<Geometry>;
  95. };
  96. template <typename Geometry>
  97. struct concept_type<Geometry const, segment_tag>
  98. {
  99. using type = ConstSegment<Geometry>;
  100. };
  101. }}} // namespace boost::geometry::concepts
  102. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP