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