segment_concept.hpp 4.0 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. // 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_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP
  12. #include <boost/concept_check.hpp>
  13. #include <boost/core/ignore_unused.hpp>
  14. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  15. #include <boost/geometry/core/access.hpp>
  16. #include <boost/geometry/core/point_type.hpp>
  17. namespace boost { namespace geometry { namespace concepts
  18. {
  19. /*!
  20. \brief Segment concept.
  21. \ingroup concepts
  22. \details Formal definition:
  23. The segment concept is defined as following:
  24. - there must be a specialization of traits::tag defining segment_tag as type
  25. - there must be a specialization of traits::point_type to define the
  26. underlying point type (even if it does not consist of points, it should define
  27. this type, to indicate the points it can work with)
  28. - there must be a specialization of traits::indexed_access, per index
  29. and per dimension, with two functions:
  30. - get to get a coordinate value
  31. - set to set a coordinate value (this one is not checked for ConstSegment)
  32. \note The segment concept is similar to the box concept, defining another tag.
  33. However, the box concept assumes the index as min_corner, max_corner, while
  34. for the segment concept there is no assumption.
  35. */
  36. template <typename Geometry>
  37. class Segment
  38. {
  39. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  40. typedef typename point_type<Geometry>::type point_type;
  41. BOOST_CONCEPT_ASSERT( (concepts::Point<point_type>) );
  42. template <size_t Index, size_t Dimension, size_t DimensionCount>
  43. struct dimension_checker
  44. {
  45. static void apply()
  46. {
  47. Geometry* s = 0;
  48. geometry::set<Index, Dimension>(*s, geometry::get<Index, Dimension>(*s));
  49. dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
  50. }
  51. };
  52. template <size_t Index, size_t DimensionCount>
  53. struct dimension_checker<Index, DimensionCount, DimensionCount>
  54. {
  55. static void apply() {}
  56. };
  57. public :
  58. BOOST_CONCEPT_USAGE(Segment)
  59. {
  60. static const size_t n = dimension<point_type>::type::value;
  61. dimension_checker<0, 0, n>::apply();
  62. dimension_checker<1, 0, n>::apply();
  63. }
  64. #endif
  65. };
  66. /*!
  67. \brief Segment concept (const version).
  68. \ingroup const_concepts
  69. \details The ConstSegment concept verifies the same as the Segment concept,
  70. but does not verify write access.
  71. */
  72. template <typename Geometry>
  73. class ConstSegment
  74. {
  75. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  76. typedef typename point_type<Geometry>::type point_type;
  77. typedef typename coordinate_type<Geometry>::type coordinate_type;
  78. BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<point_type>) );
  79. template <size_t Index, size_t Dimension, size_t DimensionCount>
  80. struct dimension_checker
  81. {
  82. static void apply()
  83. {
  84. const Geometry* s = 0;
  85. coordinate_type coord(geometry::get<Index, Dimension>(*s));
  86. boost::ignore_unused(coord);
  87. dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
  88. }
  89. };
  90. template <size_t Index, size_t DimensionCount>
  91. struct dimension_checker<Index, DimensionCount, DimensionCount>
  92. {
  93. static void apply() {}
  94. };
  95. public :
  96. BOOST_CONCEPT_USAGE(ConstSegment)
  97. {
  98. static const size_t n = dimension<point_type>::type::value;
  99. dimension_checker<0, 0, n>::apply();
  100. dimension_checker<1, 0, n>::apply();
  101. }
  102. #endif
  103. };
  104. }}} // namespace boost::geometry::concepts
  105. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP