point.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "-Wunused-local-typedefs"
  16. #endif
  17. #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
  18. #pragma GCC diagnostic push
  19. #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
  20. #endif
  21. namespace boost { namespace gil {
  22. // Forward declarations
  23. template <typename T>
  24. class point;
  25. template <std::size_t K, typename T>
  26. T const& axis_value(point<T> const& p);
  27. template <std::size_t K, typename T>
  28. T& axis_value(point<T>& p);
  29. /// \brief N-dimensional point concept
  30. /// \code
  31. /// concept PointNDConcept<typename T> : Regular<T>
  32. /// {
  33. /// // the type of a coordinate along each axis
  34. /// template <size_t K>
  35. /// struct axis; where Metafunction<axis>;
  36. ///
  37. /// const size_t num_dimensions;
  38. ///
  39. /// // accessor/modifier of the value of each axis.
  40. ///
  41. /// template <size_t K>
  42. /// typename axis<K>::type const& T::axis_value() const;
  43. ///
  44. /// template <size_t K>
  45. /// typename axis<K>::type& T::axis_value();
  46. /// };
  47. /// \endcode
  48. /// \ingroup PointConcept
  49. ///
  50. template <typename P>
  51. struct PointNDConcept
  52. {
  53. void constraints()
  54. {
  55. gil_function_requires<Regular<P>>();
  56. using value_type = typename P::value_type;
  57. ignore_unused_variable_warning(value_type{});
  58. static const std::size_t N = P::num_dimensions;
  59. ignore_unused_variable_warning(N);
  60. using FT = typename P::template axis<0>::coord_t;
  61. using LT = typename P::template axis<N - 1>::coord_t;
  62. FT ft = gil::axis_value<0>(point);
  63. axis_value<0>(point) = ft;
  64. LT lt = axis_value<N - 1>(point);
  65. axis_value<N - 1>(point) = lt;
  66. //value_type v=point[0];
  67. //ignore_unused_variable_warning(v);
  68. }
  69. P point;
  70. };
  71. /// \brief 2-dimensional point concept
  72. /// \code
  73. /// concept Point2DConcept<typename T> : PointNDConcept<T>
  74. /// {
  75. /// where num_dimensions == 2;
  76. /// where SameType<axis<0>::type, axis<1>::type>;
  77. ///
  78. /// typename value_type = axis<0>::type;
  79. ///
  80. /// value_type const& operator[](T const&, size_t i);
  81. /// value_type& operator[](T&, size_t i);
  82. ///
  83. /// value_type x,y;
  84. /// };
  85. /// \endcode
  86. /// \ingroup PointConcept
  87. ///
  88. template <typename P>
  89. struct Point2DConcept
  90. {
  91. void constraints()
  92. {
  93. gil_function_requires<PointNDConcept<P>>();
  94. static_assert(P::num_dimensions == 2, "");
  95. point.x = point.y;
  96. point[0] = point[1];
  97. }
  98. P point;
  99. };
  100. }} // namespace boost::gil
  101. #if defined(BOOST_CLANG)
  102. #pragma clang diagnostic pop
  103. #endif
  104. #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
  105. #pragma GCC diagnostic pop
  106. #endif
  107. #endif