point.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Copyright 2005-2007 Adobe Systems Incorporated
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #ifndef BOOST_GIL_CONCEPTS_POINT_HPP
  9. #define BOOST_GIL_CONCEPTS_POINT_HPP
  10. #include <boost/gil/concepts/basic.hpp>
  11. #include <boost/gil/concepts/concept_check.hpp>
  12. #include <cstddef>
  13. #if defined(BOOST_CLANG)
  14. #pragma clang diagnostic push
  15. #pragma clang diagnostic ignored "-Wunknown-pragmas"
  16. #pragma clang diagnostic ignored "-Wunused-local-typedefs"
  17. #endif
  18. #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
  19. #pragma GCC diagnostic push
  20. #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
  21. #endif
  22. namespace boost { namespace gil {
  23. // Forward declarations
  24. template <typename T>
  25. class point;
  26. template <std::size_t K, typename T>
  27. T const& axis_value(point<T> const& p);
  28. template <std::size_t K, typename T>
  29. T& axis_value(point<T>& p);
  30. /// \brief N-dimensional point concept
  31. /// \code
  32. /// concept PointNDConcept<typename T> : Regular<T>
  33. /// {
  34. /// // the type of a coordinate along each axis
  35. /// template <size_t K>
  36. /// struct axis; where Metafunction<axis>;
  37. ///
  38. /// const size_t num_dimensions;
  39. ///
  40. /// // accessor/modifier of the value of each axis.
  41. ///
  42. /// template <size_t K>
  43. /// typename axis<K>::type const& T::axis_value() const;
  44. ///
  45. /// template <size_t K>
  46. /// typename axis<K>::type& T::axis_value();
  47. /// };
  48. /// \endcode
  49. /// \ingroup PointConcept
  50. ///
  51. template <typename P>
  52. struct PointNDConcept
  53. {
  54. void constraints()
  55. {
  56. gil_function_requires<Regular<P>>();
  57. using value_type = typename P::value_type;
  58. ignore_unused_variable_warning(value_type{});
  59. static const std::size_t N = P::num_dimensions;
  60. ignore_unused_variable_warning(N);
  61. using FT = typename P::template axis<0>::coord_t;
  62. using LT = typename P::template axis<N - 1>::coord_t;
  63. FT ft = gil::axis_value<0>(point);
  64. axis_value<0>(point) = ft;
  65. LT lt = axis_value<N - 1>(point);
  66. axis_value<N - 1>(point) = lt;
  67. //value_type v=point[0];
  68. //ignore_unused_variable_warning(v);
  69. }
  70. P point;
  71. };
  72. /// \brief 2-dimensional point concept
  73. /// \code
  74. /// concept Point2DConcept<typename T> : PointNDConcept<T>
  75. /// {
  76. /// where num_dimensions == 2;
  77. /// where SameType<axis<0>::type, axis<1>::type>;
  78. ///
  79. /// typename value_type = axis<0>::type;
  80. ///
  81. /// value_type const& operator[](T const&, size_t i);
  82. /// value_type& operator[](T&, size_t i);
  83. ///
  84. /// value_type x,y;
  85. /// };
  86. /// \endcode
  87. /// \ingroup PointConcept
  88. ///
  89. template <typename P>
  90. struct Point2DConcept
  91. {
  92. void constraints()
  93. {
  94. gil_function_requires<PointNDConcept<P>>();
  95. static_assert(P::num_dimensions == 2, "");
  96. point.x = point.y;
  97. point[0] = point[1];
  98. }
  99. P point;
  100. };
  101. }} // namespace boost::gil
  102. #if defined(BOOST_CLANG)
  103. #pragma clang diagnostic pop
  104. #endif
  105. #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
  106. #pragma GCC diagnostic pop
  107. #endif
  108. #endif